24bit to 16bit conversion

Started by
8 comments, last by DragonRider 23 years, 10 months ago
Hi! I am now loading 24bit bmp onto 16bit surfaces, and sometimes that look ugly, especially when the image is composed mainly of tones of one color. Does anybody knows a way to convert the colors more nicely than letting the win32 API doing it automatically? and btw, why when I check those same 24bit bmps on my desktop, they display a lot better, even if my desktop color depht is 16bpp ? Thank you for any help you could bring me!!
Advertisement
This code comes from windows game programming for dummies but I''m a bit uncertain if it does what you wan''t but I think it does (I hope).

#define _RGB16BIT(r,g,b) ((b%32) + ((g%32) << 5) + ((r%32) << 10)) 


HTH
Well they above macro works, but diffrent graphic cards works diffrently, some uses 15bit insted of 16 bit. The macro from Mr Cucumber is for 15bit which I think it is not so much used as true 16bit, in 16bit 5bits are assigned to RED and BLUE each and since the eye is more sencetive to GREEN 6bits are assigned to it.

So, the two macros would be:
#define _RGB16BIT555(r,g,b) ((b%32)+((g%32<&lt5)+(r%32)<&lt10))
#define _RGB16BIT565(r,g,b) ((b%32)+((g%32&t&lt6)+(r%32)<&lt11))
Remember this has to be done on each and every pixel...

But bitmaps won''t look perfect anyway, I mean a 24bit image uses up to 16M colours, so a 16BIT image has to, in theory, fit all those colours in 65K colours insted, you can really see this one a lot of diffrent shades of one colour is used.

(sorry about my language and spelling, I''m really tired right now )

-------
Padrino
-------
-------Padrino-------
Load up the image in a program like Paint Shop Pro 6, and you can do a Reduce Color Depth, and can reduce it down to 16bit color even though the image will still be 24bit color, it just reduces the number of colors to 65k, 32k, 256, 16 or 2. And you can select ways to do the color count reduction so the image basically looks unchanged.

Possibility
Salut DragonRider,

C''est normal que les images 24 bits sorte un peu mal lorsqu''affiche sur une surface 16 bits, voici pourquoi.

Le seul moyen de convertir de 24 bits a 16 bits est la reduction de couleur. Je sais pas si tu fais ca pour quelque chose de RealTime ou non, mais je fais te donner les 2 methodes que je vois.

Normalement 24 bits est compose comme suit (R: 8, V: 8, B: 8)
& les modes 16 bits est compose comme suit (R: 4, V: 4, B: 4, A: 4). Je ne dis pas qu''il n''y a pas d''autre possibilite.

Comme tu vois, dans les modes 24bits, 8 bits sont utilise pour chaque niveau de Rouge, Vert, Bleu; Dans les mode 16bits, cest seulement 4 bits. Alors le moyen est simple, il s''agit de rammener les 8 bits sur 4 bits.

8 bits (0 - 255) , 4 bits (0 - 15)
- T''a juste a diviser par 16 ...

De cette maniere, lorsque tu vas avoir de beau degrader en 24 bits, ca risque de cause des distorsions de couleurs en 16 bits.
Si la Vistesse n''importe peu, si t''e pas en RealTime, tu peux retravaille les couleurs avec les moyennes des pixels avoisinants. (genre de Blur).


Happy Coding,

LowRad.



ex :

Yeah, thank you all for your help.
I realised that I need a color reduction algorithm, such as "Error Diffusion" method used in Paint Shop Pro and Photoshop.

Could anyone help me with that? Can I find an explanation of this somewhere, or do I have to write this all by myself? (duh)

Thank you again, and see ya
Nevermind, I just tried the method Possiblity suggested and it works really fine!! No need to do these endless pixel conversions all by myself

Thank you all
Hey DragonRider, where are you from? Quebec City? Canada?
Hey LowRad, where are you from? Quebec City? Canada?
(( Ok I missed some originality here... ))

DragonRiderIf you want to do it yourself, so players may put their own pictures or stuff, just use the division method (or >>3). I don''t know why modulo would work, I think it would mix all the picture...



I''m from Quebec City. If we could meet that would be cool, don''t you think so?

LowRad, je sais pas s''il t''a compris J''imagine que oui, mais il en a tellement pas fait de cas, alors...

Programming is:A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Now I know what I'm made of, and I'm afraid of it...
Salut, en fait je suis de sept-iles, c''est un peu loin de québec.
Hé pas de problème!
Je voulais savoir, juste au cas où! C''est toujours bon de savoir que le Québec (comme province) se tiens toujours sur la map quelque part. Longue vie au jeux Québécois!

(( C''est nous de toute facon qui avons trouvé la première solution au bug de l''an 2000... Et Copernic, c''est nous aussi... Et bien d''autres dont je ne me souviens plus, qui ont été acheté par l''empire américain. J''ai rien contre ca, j''aime ca le cash et je trouve qu''on se fait manger la laine sur le dos, mais je ne partirai pas un débat sur la politique ))

Programming is:A.The art of debugging a blank sheet of paper (or an empty file).B.A pastime similar to banging one's head against a wall, but with fewer opportunities for reward.C.The most fun you can have with your clothes on (although clothes are not mandatory).
Now I know what I'm made of, and I'm afraid of it...

This topic is closed to new replies.

Advertisement