| 5815 | } |
| 5816 | |
| 5817 | static int stbi__tga_test(stbi__context *s) |
| 5818 | { |
| 5819 | int res = 0; |
| 5820 | int sz, tga_color_type; |
| 5821 | stbi__get8(s); // discard Offset |
| 5822 | tga_color_type = stbi__get8(s); // color type |
| 5823 | if ( tga_color_type > 1 ) goto errorEnd; // only RGB or indexed allowed |
| 5824 | sz = stbi__get8(s); // image type |
| 5825 | if ( tga_color_type == 1 ) { // colormapped (paletted) image |
| 5826 | if (sz != 1 && sz != 9) goto errorEnd; // colortype 1 demands image type 1 or 9 |
| 5827 | stbi__skip(s,4); // skip index of first colormap entry and number of entries |
| 5828 | sz = stbi__get8(s); // check bits per palette color entry |
| 5829 | if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; |
| 5830 | stbi__skip(s,4); // skip image x and y origin |
| 5831 | } else { // "normal" image w/o colormap |
| 5832 | if ( (sz != 2) && (sz != 3) && (sz != 10) && (sz != 11) ) goto errorEnd; // only RGB or grey allowed, +/- RLE |
| 5833 | stbi__skip(s,9); // skip colormap specification and image x/y origin |
| 5834 | } |
| 5835 | if ( stbi__get16le(s) < 1 ) goto errorEnd; // test width |
| 5836 | if ( stbi__get16le(s) < 1 ) goto errorEnd; // test height |
| 5837 | sz = stbi__get8(s); // bits per pixel |
| 5838 | if ( (tga_color_type == 1) && (sz != 8) && (sz != 16) ) goto errorEnd; // for colormapped images, bpp is size of an index |
| 5839 | if ( (sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32) ) goto errorEnd; |
| 5840 | |
| 5841 | res = 1; // if we got this far, everything's good and we can return 1 instead of 0 |
| 5842 | |
| 5843 | errorEnd: |
| 5844 | stbi__rewind(s); |
| 5845 | return res; |
| 5846 | } |
| 5847 | |
| 5848 | // read 16bit value and convert to 24bit RGB |
| 5849 | static void stbi__tga_read_rgb16(stbi__context *s, stbi_uc* out) |
no test coverage detected