Shop OBEX P1 Docs P2 Docs Learn Events
Very Slightly OT: Help Recaclulating HEX color codes? — Parallax Forums

Very Slightly OT: Help Recaclulating HEX color codes?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2008-03-20 18:54 in Propeller 1
I'm working with a spin program which reads .XPM files which contain color entries that
look like this: #000080800000", #0000FFFF0000", #000080808080" (Hex RGB)
I'm failing to come up with a reducer calculation which would lump all shades of
white as #FFFFFFFFFFFF.

Without letting too much out of the bag, I have 64 colors to get to.

Has any done other work with RGB colors to have a decent solution I
could implement in spin?

Thanks
OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Getting started with the Protoboard? - Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)

Comments

  • big_markbig_mark Posts: 49
    edited 2008-03-20 15:33
    The quick way of doing it would be to take just the two most significant bits of your red, green, and blue values, and combine them into the lower 6 bits of one byte. To do this do the following
    For the red component :
      Read the most significant byte (we don't need the least significant byte at all)
      AND it with 0x11000000 to get just the two most significant bits
      Shift the result right by two places
    
    For the green component :
      Read the most significant byte 
      AND it with 0x11000000 
      Shift the result right by four places, not two!
      OR the result with the red value
    
    For the blue component :
      Read the most significant byte 
      AND it with 0x11000000 
      Shift the result right by six places, not two or four!
      OR the result with the combined red/green value
    
    


    This will give you a six-bit value for your RGB colour and it assumes that your palette is set to match it (e.g. 0x00110000 gives full red, and 0x00111100 gives yellow, etc)

    If you must keep your 'two-bytes-per-component' structure, then instead of shifting and OR'ing your results do the following :
    For each component :
      Read the most significant byte 
      AND the MSB with 0x10000000 
      If the result is 0x10000000 
        then set the high byte of the component to #FFFF 
        else set it to #0000
      AND the MSB with 0x01000000 
      If the result is 0x01000000 
        then set the low byte of the component to #FFFF 
        else set it to #0000
    
    


    Hope this helps

    Edit : Since you are reducing from over 281 trillion colours to just 64, expect some loss of detail!

    Post Edited (big_mark) : 3/20/2008 3:53:03 PM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-03-20 18:54
    Wow.. You've got my head spinning.. [noparse]:)[/noparse]

    I've managed to reduce the source codes to three hex digits,
    which should help. white is now #FFFFFF instead of #FFFFFFFFFFFF.

    Thank should help... Just looking for a big glass of watch to
    swallow that explanation with.. [noparse]:)[/noparse]

    Thanks!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    A Living Propeller FAQ - The Propeller Wiki
    (Got the Knowledge? Got a Moment? Add something today!)

    Post Edited (Oldbitcollector) : 3/20/2008 8:36:41 PM GMT

Sign In or Register to comment.