MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__tga_load

Function stbi__tga_load

include/stb/stb_image.h:5871–6074  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5869}
5870
5871static void *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri)
5872{
5873 // read in the TGA header stuff
5874 int tga_offset = stbi__get8(s);
5875 int tga_indexed = stbi__get8(s);
5876 int tga_image_type = stbi__get8(s);
5877 int tga_is_RLE = 0;
5878 int tga_palette_start = stbi__get16le(s);
5879 int tga_palette_len = stbi__get16le(s);
5880 int tga_palette_bits = stbi__get8(s);
5881 int tga_x_origin = stbi__get16le(s);
5882 int tga_y_origin = stbi__get16le(s);
5883 int tga_width = stbi__get16le(s);
5884 int tga_height = stbi__get16le(s);
5885 int tga_bits_per_pixel = stbi__get8(s);
5886 int tga_comp, tga_rgb16=0;
5887 int tga_inverted = stbi__get8(s);
5888 // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?)
5889 // image data
5890 unsigned char *tga_data;
5891 unsigned char *tga_palette = NULL;
5892 int i, j;
5893 unsigned char raw_data[4] = {0};
5894 int RLE_count = 0;
5895 int RLE_repeating = 0;
5896 int read_next_pixel = 1;
5897 STBI_NOTUSED(ri);
5898 STBI_NOTUSED(tga_x_origin); // @TODO
5899 STBI_NOTUSED(tga_y_origin); // @TODO
5900
5901 if (tga_height > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
5902 if (tga_width > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
5903
5904 // do a tiny bit of precessing
5905 if ( tga_image_type >= 8 )
5906 {
5907 tga_image_type -= 8;
5908 tga_is_RLE = 1;
5909 }
5910 tga_inverted = 1 - ((tga_inverted >> 5) & 1);
5911
5912 // If I'm paletted, then I'll use the number of bits from the palette
5913 if ( tga_indexed ) tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16);
5914 else tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16);
5915
5916 if(!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured basic consistency
5917 return stbi__errpuc("bad format", "Can't find out TGA pixelformat");
5918
5919 // tga info
5920 *x = tga_width;
5921 *y = tga_height;
5922 if (comp) *comp = tga_comp;
5923
5924 if (!stbi__mad3sizes_valid(tga_width, tga_height, tga_comp, 0))
5925 return stbi__errpuc("too large", "Corrupt TGA");
5926
5927 tga_data = (unsigned char*)stbi__malloc_mad3(tga_width, tga_height, tga_comp, 0);
5928 if (!tga_data) return stbi__errpuc("outofmem", "Out of memory");

Callers 1

stbi__load_mainFunction · 0.85

Calls 10

stbi__get8Function · 0.85
stbi__get16leFunction · 0.85
stbi__tga_get_compFunction · 0.85
stbi__mad3sizes_validFunction · 0.85
stbi__malloc_mad3Function · 0.85
stbi__skipFunction · 0.85
stbi__getnFunction · 0.85
stbi__malloc_mad2Function · 0.85
stbi__tga_read_rgb16Function · 0.85
stbi__convert_formatFunction · 0.85

Tested by

no test coverage detected