Re: 8bit pixel -> 16bits pixel -> 8bit pixel



flagos wrote:
> Hi:
>
> I need to convert from 8 bit pixel
>
> my_pixel_8
> {
> u_char r;
> u_char g;
> u_char b;
> u_char a;
> }
>
> to 16 bit pixel
>
> my_pixel_16
> {
> u_short r;
> u_short g;
> u_short b;
> u_short a;
> }
>
> and viceversa. Is there any source code to do this correctly ?
>
> Thanks in advance.

Just scale it up or down... in C++:

my_pixel_8 Convert( const my_pixel_16& p16 )
{
my_pixel_8 p8 = {
unsigned(p16.r * MAX_CHAR) / MAX_SHORT,
// ...
};
return p8;
}

my_pixel_16 Convert( const my_pixel_8& p8 )
{
my_pixel_16 p16 = {
unsigned(p8.r * MAX_SHORT) / MAX_CHAR,
// ...
}
return p16;
}

Depending on your platform, you might need to make it into something
other than an unsigned int so that the multiplication does not exceed
the range of an unsigned int.

Cheers! --M

.



Relevant Pages

  • Re: AAAAARGGGHHH !!!
    ... > A me ha rianimato un pixel sull'iMac. ... ciao, f. ... Cujo ... Prev by Date: ...
    (it.comp.macintosh)
  • Re: help with rotation issue
    ... Interesting; I wasn't aware that ACDSee rotate was lossy; I thought it ... just remapped each pixel in the image to the new orientation. ... Prev by Date: ...
    (rec.photo.digital)
  • Re: TV Logos
    ... As in a repair? ... Was it an older model or relatively new with the pixel ... Prev by Date: ...
    (alt.tv.tech.hdtv)
  • IE Print Margins
    ... both body and html doesn't fix the issue (nor does settting a pixel width) ... Thx in advance for your help ... Prev by Date: ...
    (alt.html)
  • Re: In-camera image rotation
    ... My G3 provides 2 pictures when downloading verticals. ... be identical (same pixel count, ... Prev by Date: ...
    (rec.photo.digital)