MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__tga_info

Function stbi__tga_info

Source/Utils/stb_image.h:5752–5815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5750}
5751
5752static int stbi__tga_info(stbi__context *s, int *x, int *y, int *comp)
5753{
5754 int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp;
5755 int sz, tga_colormap_type;
5756 stbi__get8(s); // discard Offset
5757 tga_colormap_type = stbi__get8(s); // colormap type
5758 if( tga_colormap_type > 1 ) {
5759 stbi__rewind(s);
5760 return 0; // only RGB or indexed allowed
5761 }
5762 tga_image_type = stbi__get8(s); // image type
5763 if ( tga_colormap_type == 1 ) { // colormapped (paletted) image
5764 if (tga_image_type != 1 && tga_image_type != 9) {
5765 stbi__rewind(s);
5766 return 0;
5767 }
5768 stbi__skip(s,4); // skip index of first colormap entry and number of entries
5769 sz = stbi__get8(s); // check bits per palette color entry
5770 if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) {
5771 stbi__rewind(s);
5772 return 0;
5773 }
5774 stbi__skip(s,4); // skip image x and y origin
5775 tga_colormap_bpp = sz;
5776 } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE
5777 if ( (tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) && (tga_image_type != 11) ) {
5778 stbi__rewind(s);
5779 return 0; // only RGB or grey allowed, +/- RLE
5780 }
5781 stbi__skip(s,9); // skip colormap specification and image x/y origin
5782 tga_colormap_bpp = 0;
5783 }
5784 tga_w = stbi__get16le(s);
5785 if( tga_w < 1 ) {
5786 stbi__rewind(s);
5787 return 0; // test width
5788 }
5789 tga_h = stbi__get16le(s);
5790 if( tga_h < 1 ) {
5791 stbi__rewind(s);
5792 return 0; // test height
5793 }
5794 tga_bits_per_pixel = stbi__get8(s); // bits per pixel
5795 stbi__get8(s); // ignore alpha bits
5796 if (tga_colormap_bpp != 0) {
5797 if((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) {
5798 // when using a colormap, tga_bits_per_pixel is the size of the indexes
5799 // I don't think anything but 8 or 16bit indexes makes sense
5800 stbi__rewind(s);
5801 return 0;
5802 }
5803 tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL);
5804 } else {
5805 tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL);
5806 }
5807 if(!tga_comp) {
5808 stbi__rewind(s);
5809 return 0;

Callers 1

stbi__info_mainFunction · 0.85

Calls 5

stbi__get8Function · 0.85
stbi__rewindFunction · 0.85
stbi__skipFunction · 0.85
stbi__get16leFunction · 0.85
stbi__tga_get_compFunction · 0.85

Tested by

no test coverage detected