Non-SIMD subtract w/saturation... 
Author Message
 Non-SIMD subtract w/saturation...

    I'm looking for code to subtract 4, 8-bit, numbers in a way such that if
a value wraps around (ie: 100 - 200), it does not interfere with the other
bytes.
    If sign matters, then I'm looking for an unsigned solution.

See ya!
Orlando



Mon, 21 Mar 2005 03:56:06 GMT  
 Non-SIMD subtract w/saturation...

Quote:

>     I'm looking for code to subtract 4, 8-bit, numbers in a way such that if
> a value wraps around (ie: 100 - 200), it does not interfere with the other
> bytes.
>     If sign matters, then I'm looking for an unsigned solution.

I use this code in FBlend:

For a better description, see:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/fblend/fble...

/* Compute saturation of difference */
/* color1 and color2 are 32-bit RGBA colors */
temp1 = (color2 & 0x80808080) ^ 0x80808080;
temp2 =  color1 & 0x80808080;
color1 = (color2 | 0x80808080) - (color1 & 0x7F7F7F7F);
color2 = temp1;
temp1 = temp1 | temp2;
temp2 = color2 & temp2;
color2 = temp1 & (color1 ^ 0x80808080);
temp2 = (temp2 | color2) >> 7; /* Make sure it's unsigned shift */

temp2 = ((temp2 + 0x7F7F7F7F) ^ 0x80808080);
color1 = temp2 & (temp1 ^ color1);

/* color1 has the saturated difference */

You can put 0x80808080 in memory to save code space. It can also dual as
0x7F7F7F7F if you 'not' it.



Fri, 25 Mar 2005 15:07:32 GMT  
 Non-SIMD subtract w/saturation...

Quote:

> I use this code in FBlend:
> ...
> 0x7F7F7F7F if you 'not' it.

    Thanks! :)

See ya!
Orlando



Tue, 29 Mar 2005 01:23:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Change Brightness, Contrast and Saturation of an image

2. Change Brightness, Contrast and Saturation of an image

3. Fastest possible saturation ???

4. Help: Add with 31 saturation

5. saturation

6. subtracting lines of column data

7. Adding / Subtracting Time...

8. adding and subtracting

9. Testing a subtracted sum against user input

10. I need to pass my variable into the subtract function

11. "Subtract C, add Ada"

12. subtract

 

 
Powered by phpBB® Forum Software