[Bf-committers] Patch for auto-identation in text editor

Douglas Toltzman bf-committers@blender.org
Wed, 14 Jul 2004 09:29:31 -0400 (EDT)


What Ton is saying is that there are 4, 8 bit components stored in a 32
bit, unsigned value.  I'm not sure of the order of components, but if Ton
says "ABGR", then I'd presume the following would be correct;

unsigned int packed_color_val;
unsigned char *packed_color_array;

unsigned char red, green, blue, alpha;

packed_color_array = (unsigned char *) &packed_color_val;
alpha = packed_color_array[0];
blue = packed_color_array[1];
green = packed_color_array[2];
red = packed_color_array[3];

/* Finally, to just mask out the alpha */
unsigned int RGBval = packed_color_val & 0xffffff00; /* little endian */
RGBval = packed_color_val & 0x00ffffff; /* big endian */

---end code---
The masking will work differently on little endian vs. big endian systems,
so you may want to experiment a little, or avoid it altogether.  Although
it will give you a faster comparison of RGB values, it will have to take
the processor endianness into account.

Finally, I just invented this code as a tutorial.  Use it as a starting
point, and sanity check the values.  If the RGBA values are in a different
order, then adjust accordingly.

Best regards,
Douglas Toltzman
Hubert, NC USA

On Wed, 14 Jul 2004, Campbell Barton wrote:

> Sorry but I dont quite get how I should go about getting this working, 
> could you show me how Id change this line?
> active_tface[0].col[0] == tface[0].col[0]
> ...to work to compare the red/green/blue of both colours.
> Thanks
> - Cam
> 
> Ton Roosendaal wrote:
> 
> > Hi,
> >
> > Colors are 'packed' in an int, denoting bytes for ABGR respectively.
> > Put a char pointer to the color, and read the color components  
> > individually. Alpha is by default 255.
> >
> > -Ton-
> >
> >
> > On Wednesday, Jul 14, 2004, at 05:31 Europe/Amsterdam, Campbell 
> > Barton  wrote:
> >
> >> Hi, Im having trouble comparing the colours of 2 faces- to break it  
> >> down All I need to do is compare the colour of 2 faces verts, as 
> >> shown  below.
> >>
> >> - Comparing the red of the first vert of 2 faces.
> >> active_tface[0].col[0] <= tface[0].col[0]+limit_int &&  
> >> active_tface[0].col[0]+limit_int >= tface[0].col[0]
> >>
> >> As you can see Im using a limit to make its possible to have some  
> >> fuzzyness.
> >>
> >> One problem I have is Im not sure whats white and whats black
> >>
> >> from doing a ...
> >>   printf("u%", active_tface[0].col[0])
> >>
> >> the col is an unsigned int from 255 to 4294967295
> >>
> >> The problem is that the races that are selected seem random and I 
> >> was  windering if there was a better way to compare the colours of 2 
> >> faces.
> >>
> >> - Cam
> >>
> >> --  Campbell J Barton
> >>
> >> 133 Hope Street
> >> Geelong West, Victoria 3218 Australia
> >>
> >> URL:    http://www.metavr.com
> >> e-mail: cbarton@metavr.com
> >> phone: AU (03) 5229 0241
> >>
> >> _______________________________________________
> >> Bf-committers mailing list
> >> Bf-committers@blender.org
> >> http://www.blender.org/mailman/listinfo/bf-committers
> >>
> >>
> > ------------------------------------------------------------------------ 
> > -- 
> > Ton Roosendaal  Blender Foundation ton@blender.org  
> > http://www.blender.org
> >
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers@blender.org
> > http://www.blender.org/mailman/listinfo/bf-committers
> >
> >
> 
> 
> -- 
> Campbell J Barton
> 
> 133 Hope Street
> Geelong West, Victoria 3218 Australia
> 
> URL:    http://www.metavr.com
> e-mail: cbarton@metavr.com
> phone: AU (03) 5229 0241