Re: 8bit pixel -> 16bits pixel -> 8bit pixel
- From: "mlimber" <mlimber@xxxxxxxxx>
- Date: 23 Nov 2005 11:10:06 -0800
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
.
- References:
- 8bit pixel -> 16bits pixel -> 8bit pixel
- From: flagos
- 8bit pixel -> 16bits pixel -> 8bit pixel
- Prev by Date: Re: Digital Watermarking in Analog Medium
- Next by Date: 90 Rotation in one buffer only
- Previous by thread: 8bit pixel -> 16bits pixel -> 8bit pixel
- Next by thread: 90 Rotation in one buffer only
- Index(es):
Relevant Pages
|