atom feed14 messages in at.iem.pd-listRe: [PD] Extracting RGB components of...
FromSent OnAttachments
Chris McCormickJul 3, 2011 8:49 am 
Mario MeyJul 3, 2011 8:55 am 
John HarrisonJul 3, 2011 8:59 am 
Mario MeyJul 3, 2011 9:18 am 
batinsteJul 3, 2011 10:07 am 
Mathieu BouchardJul 3, 2011 10:36 am 
Chris McCormickJul 3, 2011 5:55 pm 
Hans-Christoph SteinerJul 3, 2011 9:24 pm 
Mathieu BouchardJul 4, 2011 10:43 am 
batinsteJul 4, 2011 2:04 pm 
batinsteJul 4, 2011 11:57 pm 
batinsteJul 5, 2011 7:05 am 
Hans-Christoph SteinerJul 5, 2011 9:04 am 
batinsteJul 5, 2011 10:43 am 
Subject:Re: [PD] Extracting RGB components of iemgui's
From:Mathieu Bouchard (mat@artengine.ca)
Date:Jul 3, 2011 10:36:27 am
List:at.iem.pd-list

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)