MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__tga_test

Function stbi__tga_test

lite/example/cpp_example/mge/cv/stb_image.h:6428–6464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6426}
6427
6428static int stbi__tga_test(stbi__context* s) {
6429 int res = 0;
6430 int sz, tga_color_type;
6431 stbi__get8(s); // discard Offset
6432 tga_color_type = stbi__get8(s); // color type
6433 if (tga_color_type > 1)
6434 goto errorEnd; // only RGB or indexed allowed
6435 sz = stbi__get8(s); // image type
6436 if (tga_color_type == 1) { // colormapped (paletted) image
6437 if (sz != 1 && sz != 9)
6438 goto errorEnd; // colortype 1 demands image type 1 or 9
6439 stbi__skip(s, 4); // skip index of first colormap entry and number of entries
6440 sz = stbi__get8(s); // check bits per palette color entry
6441 if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32))
6442 goto errorEnd;
6443 stbi__skip(s, 4); // skip image x and y origin
6444 } else { // "normal" image w/o colormap
6445 if ((sz != 2) && (sz != 3) && (sz != 10) && (sz != 11))
6446 goto errorEnd; // only RGB or grey allowed, +/- RLE
6447 stbi__skip(s, 9); // skip colormap specification and image x/y origin
6448 }
6449 if (stbi__get16le(s) < 1)
6450 goto errorEnd; // test width
6451 if (stbi__get16le(s) < 1)
6452 goto errorEnd; // test height
6453 sz = stbi__get8(s); // bits per pixel
6454 if ((tga_color_type == 1) && (sz != 8) && (sz != 16))
6455 goto errorEnd; // for colormapped images, bpp is size of an index
6456 if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32))
6457 goto errorEnd;
6458
6459 res = 1; // if we got this far, everything's good and we can return 1 instead of 0
6460
6461errorEnd:
6462 stbi__rewind(s);
6463 return res;
6464}
6465
6466// read 16bit value and convert to 24bit RGB
6467static void stbi__tga_read_rgb16(stbi__context* s, stbi_uc* out) {

Callers 1

stbi__load_mainFunction · 0.85

Calls 4

stbi__get8Function · 0.85
stbi__skipFunction · 0.85
stbi__get16leFunction · 0.85
stbi__rewindFunction · 0.85

Tested by

no test coverage detected