Loading Icons: Difference between revisions

Jump to navigation Jump to search
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 34:
 
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:
<sourcesyntaxhighlight lang="c">
/**
* Parse TGA format into pixels. Returns NULL or error, otherwise the returned data looks like
Line 124:
return data;
}
</sourcesyntaxhighlight>This will decode the most common TGA variants according to the Targa specification. It will return pixels in a format that's most common for frame buffers.
 
===PNG, JPEG and other "professional" formats===
Line 130:
 
Instead, use [https://github.com/nothings/stb/blob/master/stb_image.h stb_image.h]. This is a single header file (no library linking needed, just libc), which is easy to use, for example the code to load PNG images looks like this:
<sourcesyntaxhighlight lang="c">
#define STBI_IMPLEMENTATION
#define STBI_ONLYPNG
Line 166:
return data;
}
</sourcesyntaxhighlight>One downside is, stb_image.h doesn't return pixels in the same format as the typical frame buffer expects. You must convert those into 32 bit ARGB pixels.
 
==See Also==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu