BackColor with Truecolor Reds

Started by honkinberry, July 23, 2015, 03:44:51 PM

Previous topic - Next topic

honkinberry

I am having a doozie of a time with some Truecolor Reds, I must be missing something simple.

When I fire SetBackColor with (dcl-getOLEColorValue (list 119 0 0)), it is definitely not Red, as the OLE Color Value of that hue is 119, so OpenDCL displays that Indexed color instead.
So I see in the documentation that I should be able to do a SetBackColor with just (list 119 0 0), but that keeps giving me an Invalid Argument Type.
What am I missing?

--J

honkinberry

In the meantime I've found this workaround:

Code (autolisp) Select

(if (and (> r 0) (zerop g) (zerop b))
(dcl-Control-SetBackColor image1 (+ (lsh 1 24) r))
; otherwise, situation normal
(dcl-Control-SetBackColor image1 (dcl-getOLEColorValue (list r g b)))
) ; if


--J

owenwengerd

#2
The (dcl-GetOLECOlorValue) returns color in a format used with OLE controls, so you cannot use the return value of the function when an AutoCAD color is expected.

EDIT: Actually, I think an OLE color should be acceptable for background color. See if it works when you specify the first argument as a float instead of integer:
Code (autolisp) Select
(dcl-getOLEColorValue (list (float r) g b))

honkinberry

(dcl-getolecolorvalue (list 119.0 0 0)) -- returns 119

So I've been using variation of the Lee Mac conversion colors:
http://www.lee-mac.com/colourconversion.html

--J

owenwengerd

You might try this:
Code (autolisp) Select
(dcl-Control-SetBackColor image1 (list 119.0 0 0))

honkinberry

That gives an invalid argument type error.

--J

owenwengerd

I finally had some time to investigate this more closely. It is possible to do what you originally tried, but there is a trick needed. As mentioned in the documentation, passing an OLEColor is allowed when a Color argument is expected, but only when the OLEColor value is greater than 256 (see the last row in the color value table here).

The RGB color red with zero values for blue and green will always be less than 256, so it cannot be passed as a Color argument. But there is a trick. OLECOlor values are 4-byte values (ranging from -2147483648 to 2147483647). However, only the lower three bytes are used for representing an RGB color. The trick is to set a bit in the high byte. The high byte will be ignored, but it makes the OLEColor value greater than 256.

Therefore, something like this works fine (16777216 is 0x01000000 in hexadecimal):
Code (autolisp) Select
(dcl-Control-SetBackColor image1 (logior 16777216 (dcl-GetOLEColorValue (list r g b))))

honkinberry

Nice!

Thanks for your time on this.

--J

honkinberry

Oh, one tiny addendum:

Code (autolisp) Select
(dcl-Control-SetBackColor image1 (logior 16777216 (dcl-GetOLEColorValue (list (float r) g b))))

--J

honkinberry

Okay, and yet one more, sorry.  :)
I like this to make it more clear where that number comes from:

Code (autolisp) Select
(dcl-Control-SetBackColor image1 (logior (expt 2 24) (dcl-GetOLEColorValue (list (float r) g b))))

--J