set_color_conversion(3)
β¨ NAME β¨
set_color_conversion β the function that tells Allegro how it's allowed to convert your images while they're being loaded. π
(oh also hiii this is a page from the Allegro manual, bestie, come sit with me π)
πΈ SYNOPSIS πΈ
#include <allegro.h>
void set_color_conversion(int mode);
π DESCRIPTION π
Okay so picture this: Allegro is reading a bitmap off your disk, or out of a datafile, and the image on disk is in some color depth, and your current video mode is in some other color depth. This function is the one that decides whether Allegro is allowed to just handle that glow-up for you, or whether it leaves the data exactly as it found it. π
mode is a bitmask β so it's not one setting, it's a whole little bouquet of "yes you may do this" flags. If the appropriate bit is set, the data gets converted into the current pixel format (the one you picked by calling set_color_depth()), and if it's not set, the data just stays in the same format as the disk file. Which meansβ¦ yeah, you're converting it manually before it can be displayed, bestie. Your problem now. π
The default mode is total conversion, so all images get loaded in the appropriate format for the current video mode. Periodt.
Valid bit flags, and yes there are a LOT of them, she contains multitudes:
COLORCONV_NONEβ disable all format conversions. literally none of them. nope. πCOLORCONV_8_TO_15β expand 8-bit to 15-bitCOLORCONV_8_TO_16β expand 8-bit to 16-bitCOLORCONV_8_TO_24β expand 8-bit to 24-bitCOLORCONV_8_TO_32β expand 8-bit to 32-bitCOLORCONV_15_TO_8β reduce 15-bit to 8-bitCOLORCONV_15_TO_16β expand 15-bit to 16-bitCOLORCONV_15_TO_24β expand 15-bit to 24-bitCOLORCONV_15_TO_32β expand 15-bit to 32-bitCOLORCONV_16_TO_8β reduce 16-bit to 8-bitCOLORCONV_16_TO_15β reduce 16-bit to 15-bitCOLORCONV_16_TO_24β expand 16-bit to 24-bitCOLORCONV_16_TO_32β expand 16-bit to 32-bitCOLORCONV_24_TO_8β reduce 24-bit to 8-bitCOLORCONV_24_TO_15β reduce 24-bit to 15-bitCOLORCONV_24_TO_16β reduce 24-bit to 16-bitCOLORCONV_24_TO_32β expand 24-bit to 32-bitCOLORCONV_32_TO_8β reduce 32-bit RGB to 8-bitCOLORCONV_32_TO_15β reduce 32-bit RGB to 15-bitCOLORCONV_32_TO_16β reduce 32-bit RGB to 16-bitCOLORCONV_32_TO_24β reduce 32-bit RGB to 24-bitCOLORCONV_32A_TO_8β reduce 32-bit RGBA to 8-bitCOLORCONV_32A_TO_15β reduce 32-bit RGBA to 15-bitCOLORCONV_32A_TO_16β reduce 32-bit RGBA to 16-bitCOLORCONV_32A_TO_24β reduce 32-bit RGBA to 24-bitCOLORCONV_DITHER_PALβ dither when reducing to 8-bitCOLORCONV_DITHER_HIβ dither when reducing to hicolorCOLORCONV_KEEP_TRANSβ keep original transparency
π¦ the convenience macros π¦
Because typing all of that out is so much, Allegro ships some macros that bundle up the common combos for you. Slay:
COLORCONV_EXPAND_256β expand 256-color to hi/truecolorCOLORCONV_REDUCE_TO_256β reduce hi/truecolor to 256-colorCOLORCONV_EXPAND_15_TO_16β expand 15-bit hicolor to 16-bitCOLORCONV_REDUCE_16_TO_15β reduce 16-bit hicolor to 15-bitCOLORCONV_EXPAND_HI_TO_TRUEβ expand 15/16-bit to 24/32-bitCOLORCONV_REDUCE_TRUE_TO_HIβ reduce 24/32-bit to 15/16-bitCOLORCONV_24_EQUALS_32β convert between 24- and 32-bitCOLORCONV_TOTALβ everything to current formatCOLORCONV_PARTIALβ convert 15 <-> 16-bit and 24 <-> 32-bitCOLORCONV_MOSTβ all but hi/truecolor <-> 256COLORCONV_DITHERβ dither during all color reductionsCOLORCONV_KEEP_ALPHAβ convert everything to current format unless it would lose alpha information
π₯ the dithering tea π₯
So if you turn on the COLORCONV_DITHER flag, dithering happens whenever truecolor graphics get converted into a hicolor or paletted format. And bestie, that's not just at load time β it also includes conversions done by the blit() function, plus any automatic conversions that happen while reading graphics from disk. β¨
It can produce much better looking results, but it is obviously slower than a direct conversion. You are paying for that glow-up in frames, and that's just the deal. π
π the transparency situation π
If you're planning to use your converted bitmaps with stuff like masked_blit() or draw_sprite(), you want to specify the COLORCONV_KEEP_TRANS flag. Here's why it's iconic: it makes sure the masked areas in the bitmap stay exactly the same before and after the conversion. How? By mapping transparent colors to each other, and by adjusting colors that would otherwise get converted into the transparent color. π«Ά
Heads up: it affects every blit() operation between distinct pixel formats, and every automatic conversion. So it's not a sometimes-thing, it's an always-thing. π§
π SEE ALSO π
set_color_depth(3), load_bitmap(3), load_datafile(3), fixup_datafile(3), makecol15_dither(3), get_color_conversion(3), exalpha(3), exblend(3), exdata(3), exexedat(3), exlights(3), exrotscl(3), exxfade(3)
okay that's the whole page, bestie, you ate that π this was brought to you by the Allegro manual, version 4.4.3 β and yes that's the version, she's vintage, she's timeless, she's lowkey iconic for it. now go convert something. periodt. π πβ
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms