News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Color_izer my ChooseColor replacement

Started by ramguru, November 12, 2005, 09:24:07 PM

Previous topic - Next topic

ramguru

I don't know if color dialog is a custom control, but I try my luck...
So why would I need onother color dialog, if there already exists one and very good (ChooseColor).
Personally I'm able to concentrate better on small place...(ChooseColor dialog is too large for me :))
System colors values are absent from standard dialog...
Standard palette is messed up
..So here comes my color dialog
+with tonning palette
+small-sized
+with system colors
this is "color_izer" screentshot
http://img261.imageshack.us/img261/9616/colorizer5gf.png
P.S. I've used WinXP icons (with alpha). So don't bother trying to run it on 98
There is something missing in my dialog .. hope you can suggest something...
Maybe you already have implemented your own color dialogs, please share them with all :)
;updated 2 time(s)

[attachment deleted by admin]

KetilO

Very nice :U

Suggestion, Initial color:

invoke Color_izer, hWin,0FFFFFFh


Also, is it not some kind of standard to return system colors as 800000xxh ?

KetilO

ramguru

Thanks, KetilO
I've fixed some bugs and added initial color feature.
The reason I decided to write 10000xx instead of something else was lamer's GColor.dll dialog. If I choose ScrollBar (system_color), it returns 1000001h (btw COLOR_SCROLLBAR equ 0 :) ). So my desicion was 10000xx instead of lamer's 10000xx+1. But I've changed that aswell... (if really exists such standard so it was a must)

ramguru


six_L

 :U
Beautiful GUI!
Could you share the code of color_izer.dll ?

regards
regards

ramguru

No problem this isn't my biggest project :) of course I can... Now "try_color_izer.zip" contains full source... BTW I've eliminated one memory leak and some bugs... If you have any questions concerning dll source - just ask :)

six_L

regards

lamer

Why haven't I seen it before?
Nice!  :U
P.S.
Don't be confused with GColor - it returns result in structure, wher one of members is crColor of CHOOSECOLOR. I created it specialy for MenuWOW project.

Mark Jones

Cool Ramguru! :)

May I request the addition of Hue-Saturation-Luminance (HSL) adjusters? Here's how the math works from RGB: http://en.wikipedia.org/wiki/HSL_color_space
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

ramguru

Thanks for request, Mark Jones! Will be soon implemented... not instantly but soon :)

ramguru

I need help  :red ! ...with HSL
First of all the formula in wiki is very vague f.e. (let max & min be 255, conversion from 0ffffffh RGB to HSL) in H step there is stated: if max = R (this formula will be used) if max = G (this..) if max = B (this..) but in my case all three are max so which one I'm supposed to choose (first one ?) ? In S step there is stated if L >= 1/2 (use this for.) if L <= 1/2 (use this), but what if L = 1/2 ? OK this is just formulas...but
I managed to find two apps that use HSL in their color dialogs and guess what result in every app differs...
white (RGB - 0ffffffh) HSL in:
"MS Office 12" color dialog: H-170 S-0 L-255 (this one is very buggy)
"Secret Color Picker" color dialog: H-160 S-0 L-240

Mark Jones

 Heheh yes I remember trying to make the conversion work in some obscure scripting language. The trick was to use "greater/less than OR EQUAL TO" in the three Hue calculations, so that if R == B == MAX, both are computed. Or maybe I just got lucky. :) Also this algorithm produces a Hue of 0-360 degrees rather than 0-255. It does seem like there is no "standard" HSL...  :naughty:

Using >= or <= in the saturation algorithm never did seem to produce the same saturation as Paint Shop Pro though. (You could try the free demo at www.jasc.com/ to compare results.) I figured that Paint Shop would have the best HSL accuracy around. Hope this helps. :)

Here's a rough draft of what the script did, I think:


// determine minColor from RGB component first
If R == G == B                   // if RGB values are equal (greyscale)
  H = 0
  S = 0
  L = R
  Return
End If

// RGB unequal, continue processing minColor
If R <= G <= B then
  minColor = R
Elseif G <= R <= B then
  minColor = G
Elseif B <= R <= G then
  minColor = B
End If



// define maxColor from RGB and calculate Hue
If R >= G >= B                   // if red is maximum
  maxColor = R                   // set maxColor
  temp1 = G - B                  // green - blue
  temp2 = maxColor - minColor    // max - min
  H = temp1 / temp2              // float divide
  H = H * 60                     // multiply by 60
  H = H + 0                      // add zero
End If

If G >= B >= R                   // if green is maximum
  maxColor = G                   // set maxColor
  temp1 = B - R                  // blue - red
  temp2 = maxColor - minColor    // max - min
  H = temp1 / temp2              // float divide
  H = H * 60                     // multiply by 60
  H = H + 120                    // add 120
End If

If B >= R >= G                   // if blue is maximum
  maxColor = B                   // set maxColor
  temp1 = R - G                  // red - green
  temp2 = maxColor - minColor    // max - min
  H = temp1 / temp2              // float divide
  H = H * 60                     // multiply by 60
  H = H + 240                    // add 240
End If

Round H to Integer

// if hue degree is negative, make positive
If H < 0
  H = H + 360
End If



// calculate Luminance L as 0.5 * (MIN + MAX)
temp1 = minColor + maxColor
temp1 = temp1 / 2
Round temp1 to Integer
L = temp1



// calculate Saturation S depending on Luminance L being >=128
temp2 = maxColor - minColor
temp1 = maxColor + minColor
If L >= 128
  // S = (maxColor - minColor) / (2 - (maxColor + minColor))
  // ((maxColor + minColor) - 2) produces a positive, equal-magnitude result.
  temp1 = temp1 - 2.00000000
Else
  // S = (maxColor - minColor) / (maxColor + minColor), does not need -2
End If
temp1 = temp2 / temp1         // divide divisor by dividend, result as float
temp1 = temp1 * 256           // scale result to 0-255 range
Round temp1 to Integer
S = temp1
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

ramguru

#12
Hi, all
Thanks for help, Mark Jones
Sorry for delay. I tried to avoid fpu, but didn't succeed.
I have rewritten all source of the control, and "COLOR_IZER-2" is ready.
What's new:
+ability to choose RGB or HSL color model:
...RGB range [0..255,0..255,0..255] in hex 0..00ffffff
...HSL range [0..360,0..100,0..100] in hex 0..64640168
+sliders now are smoother
+dynamic palette (accor. to H value) in HSL mode
+replaced some elements that caused flicker

I have changed the design so if you like COLOR_IZER-1 more - use it...

...and .. yes .. a screenshot http://img452.imageshack.us/img452/4537/colorizer21yp.png

[attachment deleted by admin]

ramguru

New bugfix release (attachment iin previous post) in addition now you can toggle hex or dec mode (just call popup by pressing on color value right mouse button) screenshot with dec mode in HSL color model http://img294.imageshack.us/img294/3518/col20kd.png

Mark Jones

#14
Hi Ramguru, you got it working! Nice job. :)

Edit: Hmmm, chosen HSL colors do not seem to change the control colors. Maybe the RGB equivalent is not being passed to the control? :wink
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08