[PD] Extracting RGB components of iemgui's

Mathieu Bouchard matju at artengine.ca
Sun Jul 3 19:36:50 CEST 2011


On Sun, 3 Jul 2011, Chris McCormick wrote:

> Despite reading several posts in the archive and the source code in 
> g_all_guis.c I am embarrassed to say that I am completely stumped by the 
> problem of extracting the individual RGB components from the IEM saved 
> color value in the .pd file, as ints between 0 and 255.

as a reference, [#to_iem] supports both iem colour formats, the 18-bit 
format for files, and the 24-bit format for messages. Such a patch is very 
simple :

   http://gridflow.ca/svn/trunk/abstractions/%23to_iem.pd
   http://gridflow.ca/help/%23to_iem-help.html

But it does the opposite conversion of what you are trying to do.

> What I am doing (in the case where the saved value is negative) is:
> 	iemcolor = -1 - iemcolor;
> 	r = (iemcolor & 0x3f000) >> 14;
> 	g = (iemcolor & 0xfc0) >> 4;
> 	b = (iemcolor & 0x3f) << 2;

this is the 18 bit iem format that you are trying to convert to a 3*8 bit 
component format. You are correctly extracting blue and green, where the 
shift is 0*6-2 for blue, 1*6-2 for green, but it has to be 2*6-2 for red.

For the 24 bit iem format, instead, you have to shift by 0*8, 1*8, 2*8.

-2 is the difference between 6 bits per component and 8 bits per 
component.

Note that those conversions scale in a crude way, such that 63 is scaled 
to 252, instead of the maximum 255. If you want to scale more 
appropriately to fill the whole range, you need to post-process those 
components a little bit(s) :

r = r | (r>>6)
g = g | (g>>6)
b = b | (b>>6)

  _______________________________________________________________________
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC


More information about the Pd-list mailing list