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