Loading Icons: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(Don't link to ancient version of stb_image that doesn't even have the functions this references.)
m (Bot: Replace deprecated source tag with syntaxhighlight)
Line 14:
===Targa===
A much better choice would be Targa format (.tga). It is a very very simple format, used by many game engines (like Quake) too. Essentially you can save uncompressed bitmap images with a 18 bytes header:
<sourcesyntaxhighlight lang="c">
typedef struct {
unsigned char magic1; // must be zero
Line 28:
unsigned char pixeltype; // must be 40
} __attribute__((packed)) tga_header_t;
</sourcesyntaxhighlight>This is followed by the data, each pixel on 4 bytes: blue, green, red, alpha channels in order. This simple. Many image editors support this format (like The GIMP), or you can use [https://imagemagick.org/index.php ImageMagick] CLI tool to convert any image format into .tga with a simple command (available in all Linux distributions).
<sourcesyntaxhighlight lang="bash">
$ convert image.png image.tga
</sourcesyntaxhighlight>When saving with The GIMP, first convert the image to RGB (Image / Mode / RGB). Then add Alpha channel (Layer / Transparency / Add Alpha Channel). If these options are inactive, that means your image is already RGB or has alpha. Finally choose Export As... and enter a filename ending with ".tga". In the popup, uncheck "RLE compression" and select origin "Top".
 
If you want to support all TGA options, including palette images and RLE compression, then that's still pretty simple. Just use the following code snippet: