| 6484 | } |
| 6485 | |
| 6486 | static void* stbi__tga_load( |
| 6487 | stbi__context* s, int* x, int* y, int* comp, int req_comp, |
| 6488 | stbi__result_info* ri) { |
| 6489 | // read in the TGA header stuff |
| 6490 | int tga_offset = stbi__get8(s); |
| 6491 | int tga_indexed = stbi__get8(s); |
| 6492 | int tga_image_type = stbi__get8(s); |
| 6493 | int tga_is_RLE = 0; |
| 6494 | int tga_palette_start = stbi__get16le(s); |
| 6495 | int tga_palette_len = stbi__get16le(s); |
| 6496 | int tga_palette_bits = stbi__get8(s); |
| 6497 | int tga_x_origin = stbi__get16le(s); |
| 6498 | int tga_y_origin = stbi__get16le(s); |
| 6499 | int tga_width = stbi__get16le(s); |
| 6500 | int tga_height = stbi__get16le(s); |
| 6501 | int tga_bits_per_pixel = stbi__get8(s); |
| 6502 | int tga_comp, tga_rgb16 = 0; |
| 6503 | int tga_inverted = stbi__get8(s); |
| 6504 | // int tga_alpha_bits = tga_inverted & 15; // the 4 lowest bits - unused (useless?) |
| 6505 | // image data |
| 6506 | unsigned char* tga_data; |
| 6507 | unsigned char* tga_palette = NULL; |
| 6508 | int i, j; |
| 6509 | unsigned char raw_data[4] = {0}; |
| 6510 | int RLE_count = 0; |
| 6511 | int RLE_repeating = 0; |
| 6512 | int read_next_pixel = 1; |
| 6513 | STBI_NOTUSED(ri); |
| 6514 | STBI_NOTUSED(tga_x_origin); // @TODO |
| 6515 | STBI_NOTUSED(tga_y_origin); // @TODO |
| 6516 | |
| 6517 | if (tga_height > STBI_MAX_DIMENSIONS) |
| 6518 | return stbi__errpuc("too large", "Very large image (corrupt?)"); |
| 6519 | if (tga_width > STBI_MAX_DIMENSIONS) |
| 6520 | return stbi__errpuc("too large", "Very large image (corrupt?)"); |
| 6521 | |
| 6522 | // do a tiny bit of precessing |
| 6523 | if (tga_image_type >= 8) { |
| 6524 | tga_image_type -= 8; |
| 6525 | tga_is_RLE = 1; |
| 6526 | } |
| 6527 | tga_inverted = 1 - ((tga_inverted >> 5) & 1); |
| 6528 | |
| 6529 | // If I'm paletted, then I'll use the number of bits from the palette |
| 6530 | if (tga_indexed) |
| 6531 | tga_comp = stbi__tga_get_comp(tga_palette_bits, 0, &tga_rgb16); |
| 6532 | else |
| 6533 | tga_comp = stbi__tga_get_comp( |
| 6534 | tga_bits_per_pixel, (tga_image_type == 3), &tga_rgb16); |
| 6535 | |
| 6536 | if (!tga_comp) // shouldn't really happen, stbi__tga_test() should have ensured |
| 6537 | // basic consistency |
| 6538 | return stbi__errpuc("bad format", "Can't find out TGA pixelformat"); |
| 6539 | |
| 6540 | // tga info |
| 6541 | *x = tga_width; |
| 6542 | *y = tga_height; |
| 6543 | if (comp) |
no test coverage detected