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