- if(img_set_pixels(img, x, y, rdalpha ? IMG_FMT_RGBA32 : IMG_FMT_RGB24, 0) == -1) {
+ if(hdr.img_type == IMG_CMAP || hdr.img_type == IMG_RLE_CMAP) {
+ if(hdr.img_bpp != 8) {
+ fprintf(stderr, "read_tga: indexed images with more than 8bpp not supported\n");
+ return -1;
+ }
+ pixel_bytes = 1;
+ fmt = IMG_FMT_IDX8;
+ } else {
+ int alpha = hdr.img_desc & 0xf;
+ pixel_bytes = alpha ? 4 : 3;
+ fmt = alpha ? IMG_FMT_RGBA32 : IMG_FMT_RGB24;
+ }
+
+ if(img_set_pixels(img, x, y, fmt, 0) == -1) {