Author Topic: Need help understanding the help  (Read 9611 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5247
Re: Need help understanding the help
« Reply #15 on: October 15, 2010, 02:57:57 PM »
Jeff,

Here are some of the base information that I've seen.

    ; -1040187392 = 0,0,0
    ; -1040187391 = 0,0,1
    ; -1040187136 = 0,1,0
    ; -1040121856 = 1,0,0
    ; -1023410177 = 255,255,255
    ; -1023410175 = 1 ( autocad standard color )

I haven't looked into the color books too much, as that seems hidden.


Tim,

Some of the codes in there are good, but they don't show how to get the color from the overrides though, as nothing does.  Thanks for sharing it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5247
Re: Need help understanding the help
« Reply #16 on: October 15, 2010, 04:36:41 PM »
Well the ADN was really helpful, and maybe the information might be helpful to others.  Here is the code they provided ' trueColorToRGB ', with comments from the email about what is happening.

Code: [Select]
(defun trueColorToRGB (tcol)
    ;|
        From: Wayne Brill ( ADN )
       
        My Colleague Adam Nagy has this suggestion:
        >> >> >>
        In that case the top byte is not 0 as the DevNote says, but it’s 1100 0010...
        just like when using ActiveX API to get the color value for Hatch gradients.
        Also, in that case when returning the r value the top byte needs to be cleared
        just like in case of getting the other values..
        So the
        (setq r (lsh tcol -16))
        In the trueColorToRGB function should be changed to
        (setq r (lsh (lsh tcol 8) -24))
        Not sure what that top byte means exactly, but it’s the exact value that you get in case of the hatch gradient through ActiveX
        << << <<
    |;

    ;(setq r (lsh tcol -16))
    (setq r (lsh (lsh tcol 8) -24))
    (setq g (lsh (lsh tcol 16) -24))
    (setq b (lsh (lsh tcol 24) -24))
    ;(princ (list r g b))
)
(defun c:Test ( / Data )
   
    (setq Data (entget (tblobjname "layer" "0")))
    ;(setq Data (entget (cdr (assoc 360 Data))))
    (setq Data (dictsearch (cdr (assoc 360 Data)) "ADSK_XREC_LAYER_COLOR_OVR"))
    (while (setq Data (member '(102 . "{ADSK_LYR_COLOR_OVERRIDE") Data))
        (prompt
            (strcat
                "\n Viewport handle: "
                (cdr (assoc 5 (entget (cdr (assoc 335 Data)))))
                "  Color code: " (rtos (cdr (assoc 420 Data)) 2 0)
                " "
                (vl-princ-to-string (trueColorToRGB (cdr (assoc 420 Data))))
            )
        )
        (if (equal (car (cadddr Data)) 430)
            (princ (strcat "  Color book: " (cdr (cadddr Data))))
        )
        (setq Data (cdr Data))
    )
    (princ)
)

It now prints the correct value for RGB colors.  I'll have to change it a little to accommodate standard colors.  Now I have to study ' byte ' and ' bit ' a little more, so that I can understand what is happening.

Example:
 Viewport handle: 112  Color code: -1036733749 (52 178 203)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12526
  • London, England
Re: Need help understanding the help
« Reply #17 on: October 24, 2010, 03:24:15 PM »
Hi Tim,

I found this thread really interesting and spent some time attempting to understand the arrangement of the 24-bit RGB integer, and how the various values are calculated from it.

Here is my take on it:

The RGB value is a 24-bit integer (i.e. composed of 3-bytes, the first being blue, then green, and the highest being red). To understand it, I created this diagram (using the RGB value from your first example).

When calculating the values, here was the previous function, as supplied by Tim's post:

Code: [Select]
(defun TrueColor-split ( c / )
  (list (lsh (fix c) -16)
        (lsh (lsh (fix c) 16) -24)
        (lsh (lsh (fix c) 24) -24)
  )
)

Hence to obtain, say, the Green value we use:

Code: [Select]
(lsh (lsh (fix c) 16) -24)
Here, all the bit-values are shifted 16 bits to the left, and being in a 32-bit environment the Red bits are consequently discarded and the Green bits occupy the 4th byte (located above the previous red byte), with the Blue bits occupying the 3rd byte (previously Red).

All the values are then shifted 24 bits to the right, and hence the green bits now occupy the first byte (previously blue), and the blue values are discarded, leaving just the green value which is returned.

Notice that, when calculating the Red value, the bits are only shifted down by 16 bits (discarding the green/blue bits) - this method hence assumes the 4th byte is empty and so doesn't bother to discard any possible values in the 4th byte.

However, in your override example, the 4th byte has value, and hence the assumption is not valid.

The correction, as supplied in your last post corrects this by first shifting the Red bits left by 8-bits, discarding any values that may be in the 4th byte, before shifting all the bits back down by 24 bits (3 bytes), meaning the Red values are now sitting in the 1st byte.

I hope my reasoning has been somewhat clear, and please don't take this that I'm teaching you to suck eggs, this was more for my own understanding that I thought I'd share. And, of course, if you see something wrong with the above, please do let me know.

Lee

Lee Mac

  • Seagull
  • Posts: 12526
  • London, England
Re: Need help understanding the help
« Reply #18 on: October 24, 2010, 07:51:48 PM »
As an extension of the idea - how about encoding in an n-bit integer (0 < n < 32)

Lets say, just as an extension of the concept, that the RGB value was encoded in a 6-bit integer, hence each colour spanned 2-bits (meaning that each colour took 22 values: 0,1,2,3)

Diagrammatically, it might look like this:

Code: [Select]
;;   RGB                |  Red  |Green | Blue |   ;;
;;   ------------------------------------------   ;;
;;   3 x 2 bits         |  2  1 | 2  1 | 2  1 |   ;;
;;   ------------------------------------------   ;;
;;   6-bit integer      | 32 16 | 8  4 | 2  1 |   ;;
;;   ------------------------------------------   ;;
;;                                                ;;
;;   ------------------------------------------   ;;
;;   Example: 45        |  1  0   1  1   0  1 |   ;;
;;   ------------------------------------------   ;;
;;                      |   2   |   3  |   1  |   ;;
;;                      -----------------------   ;;

And, so we might construct a splitting function, using the logic in my post above:

Code: [Select]
(defun 6bit-split ( c )
  (list (lsh (lsh (fix c) 26) -30)
        (lsh (lsh (fix c) 28) -30)
        (lsh (lsh (fix c) 30) -30)
  )
)

Code: [Select]
_$ (6bit-split 45)
(2 3 1)

We could also extend this function to operate on an 'n'-bit integer, by specifying the number of elements encoded [or the bit-width of each element] (as, in the above example we could also have 2 elements, 3-bits wide).

Perhaps such a function may look like this:

Code: [Select]
(defun nbit-split ( c n i / w l ) (setq w (/ n i))
  (repeat i
    (setq l (cons (lsh (lsh (fix c) (- 32 (* w i))) (- w 32)) l)
          i (1- i)
    )
  )
  (reverse l)
)

Where 'c' is the integer to split, 'n' is the bit-width of the integer, and 'i' is the number of elements (must evenly divide 'n').

So, in our 6-bit example above:

Code: [Select]
_$ (nbit-split 45 6 3)
(2 3 1)

And in the earlier example, with our 24-bit RGB value:

Code: [Select]
_$ (nbit-split 13132850 24 3)
(200 100 50)

This is really interesting, Thanks Tim for this thread!  :-)

Interestingly, there is a 6-bit RGB representation!

http://en.wikipedia.org/wiki/List_of_monochrome_and_RGB_palettes#6-bit_RGB
« Last Edit: October 24, 2010, 08:05:20 PM by Lee Mac »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12526
  • London, England
Re: Need help understanding the help
« Reply #20 on: October 25, 2010, 06:07:06 AM »
Wow - I have a lot to learn! - it's going to take me a while to study those :-)

Many thanks Michael, very interesting indeed!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Need help understanding the help
« Reply #21 on: October 25, 2010, 08:26:00 AM »
Very gracious of you to say Lee, any one of you could could pen the same in a similar nerd fest, but thanks -- hope its useful some way. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5247
Re: Need help understanding the help
« Reply #22 on: October 25, 2010, 11:18:59 AM »
I haven't had the time to try and understand this, so it's nice to have what you posted Lee.  I think it will help me get a greater grasp on the idea.  Then maybe I'll be able to understand the threads MP linked to.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.