Board index » delphi » convert 16 bit colors to 24 bit colors

convert 16 bit colors to 24 bit colors

- How can I convert a 16 bit color value (5-6-5) to a 24 bit color value
(8-8-8) ? Is there anybody in this whole world who already wrote a good
algorithm for this purpose ?
- The Windows API says that 16 bit bitmaps are supported in Windows 9x but
they're not shown correctly on my system. I also tried it on another system
with the same result ! Is this a video driver bug ?

Thanks, DPR

 

Re:convert 16 bit colors to 24 bit colors


Quote
"DPR" <hw.del...@gmx.de> wrote in message news:8ntos6$lpq3@bornews.borland.com...
> - How can I convert a 16 bit color value (5-6-5) to a 24 bit color value
> (8-8-8) ? Is there anybody in this whole world who already wrote a good
> algorithm for this purpose ?

Just set the TBitmap.PixelFormat to pf24bit.

--
efg
Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:convert 16 bit colors to 24 bit colors


Quote
> Just set the TBitmap.PixelFormat to pf24bit.

Ehh - I don't use and don't want to use the TBitmap class. I'm writing my
own algorithms. So how can I convert the hexadecimal value ?

DPR

Re:convert 16 bit colors to 24 bit colors


Hello DPR.

Quote
>- How can I convert a 16 bit color value (5-6-5) to a 24 bit color value

Are you sure it is (5-6-5)? I always thought it is (5-5-5) and the
result looks very correct to me.

Quote
>(8-8-8) ? Is there anybody in this whole world who already wrote a good
>algorithm for this purpose ?

This really should be no problem: Use Scanline and the appropriate bit
shifting operation:
bRed := Byte((wSrc and $F800) shr 8);
bGreen := Byte((wSrc and $7E) shr 3);
bBlue := Byte(wSrc and $1F) shl 3);

Peter

Re:convert 16 bit colors to 24 bit colors


Quote
"DPR" <hw.del...@gmx.de> wrote in message news:8nu1v7$lms31@bornews.borland.com...
> > Just set the TBitmap.PixelFormat to pf24bit.
> Ehh - I don't use and don't want to use the TBitmap class. I'm writing my
> own algorithms. So how can I convert the hexadecimal value ?

Do you have 15-bit color (5-bits R, 5-bits G, 5-bits B), or 16-bit color (5-bits R, 6-bits G, 5-bits
B)?
Many may say that 15-bit color is 16-bit color since it's stored in a 16-bit word.   Here's the
packing
for either:

pf15bit: 0 rrrrr ggggg bbbbb
pf16bit: rrrrr gggggg bbbbb

 (Likewise, some may think 32-bit color has more color, but it's just 24-bit color packaged
differently.)

While you're not using TBitmaps or Scanlines, the packing of pf15bit and pf16bit pixels is
also described in the Scanline TechNote:
http://www.efg2.com/Lab/ImageProcessing/Scanline.htm

You are aware that conversion from 15/16-bit color to 24-bit color results in no color info loss,
but color information is lost in the reverse conversion from 24-bit color back to 15/16-bit color?

--
efg

Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:convert 16 bit colors to 24 bit colors


Quote
> Are you sure it is (5-6-5)? I always thought it is (5-5-5) and the
> result looks very correct to me.

Yes, I am sure. It's definitely 5-6-5 (16 bits), you're talking about 15
bits. The 15th bit of a 15 bit color value is always ignored whereas a 16
bit value has got 5 bits for red, 6 bits for green and 5 bits for blue
values.
Quote
> This really should be no problem: Use Scanline and the appropriate bit
> shifting operation:
> bRed := Byte((wSrc and $F800) shr 8);
> bGreen := Byte((wSrc and $7E) shr 3);
> bBlue := Byte(wSrc and $1F) shl 3);

Nice, but I already knew this way to convert a 15 bit color value, I need an
algorithm to convert a 16 bit color value.

Bye, DPR

Re:convert 16 bit colors to 24 bit colors


Quote
> Do you have 15-bit color (5-bits R, 5-bits G, 5-bits B), or 16-bit color

(5-bits R, 6-bits G, 5-bits
Quote
> B)?
> Many may say that 15-bit color is 16-bit color since it's stored in a

16-bit word.   Here's the
Quote
> packing
> for either:

> pf15bit: 0 rrrrr ggggg bbbbb
> pf16bit: rrrrr gggggg bbbbb

I'm really talking about 16 bit color values and I already wrote in my first
post that I'm talking about 5-6-5 values.

Quote
>  (Likewise, some may think 32-bit color has more color, but it's just

24-bit color packaged
Quote
> differently.)

I first (a few months ago) thought that too (that 32-bit color values are
CMYK values) - but I (very fast) found out that that's not the case. Besides
there's no sense at all to use 32-bpp bitmaps !!!

Quote
> While you're not using TBitmaps or Scanlines, the packing of pf15bit and
pf16bit pixels is
> also described in the Scanline TechNote:
> http://www.efg2.com/Lab/ImageProcessing/Scanline.htm

Thanks, Earl - I already knew this link (since you're a very active person
in this newsgroup) and I'll have a closer look on it now, I just thougt that
I can't find it there.

Quote
> You are aware that conversion from 15/16-bit color to 24-bit color results

in no color info loss,
Quote
> but color information is lost in the reverse conversion from 24-bit color

back to 15/16-bit color?
Yes I know that.

Thanks for your answer, DPR

Re:convert 16 bit colors to 24 bit colors


Quote
On Tue, 22 Aug 2000 13:52:18 +0200, "DPR" <hw.del...@gmx.de> wrote:
>- The Windows API says that 16 bit bitmaps are supported in Windows 9x but
>they're not shown correctly on my system. I also tried it on another system
>with the same result ! Is this a video driver bug ?

Take a look at the info about BITMAPINFOHEADER. It says that 16bit may
actually be 15bit if the driver doesnt support 16bit:

First:
"The bitmap has a maximum of 2^16 colors. If the biCompression member
of the BITMAPINFOHEADER is BI_RGB, the bmiColors member is NULL. Each
WORD in the bitmap array represents a single pixel. The relative
intensities of red, green, and blue are represented with five bits for
each color component. The value for blue is in the least significant
five bits, followed by five bits each for green and red. The most
significant bit is not used."
Well, id say that would be 2^15 but...

Then:
"Windows 95/98: When the biCompression member is BI_BITFIELDS, the
system supports only the following 16bpp color masks: A 5-5-5 16-bit
image, where the blue mask is 0x001F, the green mask is 0x03E0, and
the red mask is 0x7C00; and a 5-6-5 16-bit image, where the blue mask
is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800."

I just thought i should say that in win2k, i do get a full 5-6-5
bitmap by setting the TBitmap.PixelFormat:= pf16bit;

Not trying to prove anything else than that im a bit confused about
the whole deal :)

My source: http://msdn.microsoft.com/library/psdk/gdi/bitmaps_1rw2.htm

Quote
>- How can I convert a 16 bit color value (5-6-5) to a 24 bit color value
>(8-8-8) ? Is there anybody in this whole world who already wrote a good
>algorithm for this purpose ?

   red8:= ((SourceColor and RedMask) shr RedPos) shl 3;
   green8:= ((SourceColor and GreenMask) shr GreenPos) shl 2;
   blue8:= ((SourceColor and BlueMask) shr BluePos) shl 3;

The mask's are the ones from above, and the positions are of cource
red=11 green=5, blue=0.

Works for both 15 and 16bit if you detect the masks first..

- Asbj?rn

Re:convert 16 bit colors to 24 bit colors


ok, do this....

you want to convert from 16 -> 24 bit.

this is slow, but it work :)  (i think)

// code  (not tested..)

p1 = @Picture16bit.data    { or something like that }    (^word)

p2 = @NewPicture24bit,data   {idem...  ^byte   i use a byte because there's
not type for 24bit.. so split in 3bytes each...}

// make sure you created enough memory 4 the dest picture.....

for i = 0 to Picture16bit.data.count-1 do
begin
    p2^ := (p1 AND $20 ) shl 3;   {red}
    inc(p2);  // increase dest. pointer...

    p2^ := ( (p1 shr 5) AND $40 ) shl 2;   {green}
    inc(p2);

    p2^ := ( (p1 shr 11) AND $20 ) shl 3;   {blue}
    inc(p2);

    inc(p1);
end;

greatz, limbique,!

Re:convert 16 bit colors to 24 bit colors


Quote
> Take a look at the info about BITMAPINFOHEADER. It says that 16bit may
> actually be 15bit if the driver doesnt support 16bit:

So how can I detect if my driver supports 16 bit ??

Quote
> Not trying to prove anything else than that im a bit confused about
> the whole deal :)

... who's not ?

Quote
>    red8:= ((SourceColor and RedMask) shr RedPos) shl 3;
>    green8:= ((SourceColor and GreenMask) shr GreenPos) shl 2;
>    blue8:= ((SourceColor and BlueMask) shr BluePos) shl 3;

> The mask's are the ones from above, and the positions are of cource
> red=11 green=5, blue=0.

> Works for both 15 and 16bit if you detect the masks first..

Many Thanks, I'll try this
DPR

Re:convert 16 bit colors to 24 bit colors


Thanks, I'll try your method,

DPR

Re:convert 16 bit colors to 24 bit colors


Quote
On Wed, 23 Aug 2000 13:46:55 +0200, "DPR" <hw.del...@gmx.de> wrote:
>> Take a look at the info about BITMAPINFOHEADER. It says that 16bit may
>> actually be 15bit if the driver doesnt support 16bit:
>So how can I detect if my driver supports 16 bit ??

Oh thats easy ;)

heh, no actually ive never done it, but i did some poking, and found
what might be a possible way: use GetObject on the DIB handle...

this gives you (apparently) a DIBSECTION structure which has a nice
dsBitfields structure where you can detect the bits, and what to shift
where :)

- Asbj?rn

Re:convert 16 bit colors to 24 bit colors


Quote
"Lord Crc" <lord...@hotmail.com> wrote in message news:39a300b7.45393890@forums.inprise.com...
> On Tue, 22 Aug 2000 13:52:18 +0200, "DPR" <hw.del...@gmx.de> wrote:

> >- The Windows API says that 16 bit bitmaps are supported in Windows 9x but
> >they're not shown correctly on my system. I also tried it on another system
> >with the same result ! Is this a video driver bug ?

See the Scanline Technote and the pf15bit/pf16bit section:

"Not all PixelFormats may be available on every machine.  For example, pf15bit bitmaps
are not possible on some machines because of limitations in the video adapters/video drivers"

--
efg

Earl F. Glynn     E-mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:convert 16 bit colors to 24 bit colors


Sorry to shout, but shifting is simply not correct.

If you want to convert a 5bit color channel value (range 0-31) to a 8bit
value (range 0-255), simply shifting left 3 bits is not correct since it
results in a range 0-248. The error isn't just the loss of some extreme
values, it's wrong for smaller values to, you simply map to an incorrect
range.

For the same reason shifting right when trying to reduce the color
bitdepth is also incorrect.

The correct way to do it, in this example, is dividing by 31,
subsequently multiplying by 255, and finaly rounding to the nearest
integer value. This can be translated into integer arithmatic, but even
than it is too slow for practical purposes. Fortunately, you can use a
simple and very small LUT for this.

Joris Van Damme

Go to page: [1] [2] [3] [4]

Other Threads