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

Function stbi__tga_info

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

Source from the content-addressed store, hash-verified

6356}
6357
6358static int stbi__tga_info(stbi__context* s, int* x, int* y, int* comp) {
6359 int tga_w, tga_h, tga_comp, tga_image_type, tga_bits_per_pixel, tga_colormap_bpp;
6360 int sz, tga_colormap_type;
6361 stbi__get8(s); // discard Offset
6362 tga_colormap_type = stbi__get8(s); // colormap type
6363 if (tga_colormap_type > 1) {
6364 stbi__rewind(s);
6365 return 0; // only RGB or indexed allowed
6366 }
6367 tga_image_type = stbi__get8(s); // image type
6368 if (tga_colormap_type == 1) { // colormapped (paletted) image
6369 if (tga_image_type != 1 && tga_image_type != 9) {
6370 stbi__rewind(s);
6371 return 0;
6372 }
6373 stbi__skip(s, 4); // skip index of first colormap entry and number of entries
6374 sz = stbi__get8(s); // check bits per palette color entry
6375 if ((sz != 8) && (sz != 15) && (sz != 16) && (sz != 24) && (sz != 32)) {
6376 stbi__rewind(s);
6377 return 0;
6378 }
6379 stbi__skip(s, 4); // skip image x and y origin
6380 tga_colormap_bpp = sz;
6381 } else { // "normal" image w/o colormap - only RGB or grey allowed, +/- RLE
6382 if ((tga_image_type != 2) && (tga_image_type != 3) && (tga_image_type != 10) &&
6383 (tga_image_type != 11)) {
6384 stbi__rewind(s);
6385 return 0; // only RGB or grey allowed, +/- RLE
6386 }
6387 stbi__skip(s, 9); // skip colormap specification and image x/y origin
6388 tga_colormap_bpp = 0;
6389 }
6390 tga_w = stbi__get16le(s);
6391 if (tga_w < 1) {
6392 stbi__rewind(s);
6393 return 0; // test width
6394 }
6395 tga_h = stbi__get16le(s);
6396 if (tga_h < 1) {
6397 stbi__rewind(s);
6398 return 0; // test height
6399 }
6400 tga_bits_per_pixel = stbi__get8(s); // bits per pixel
6401 stbi__get8(s); // ignore alpha bits
6402 if (tga_colormap_bpp != 0) {
6403 if ((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16)) {
6404 // when using a colormap, tga_bits_per_pixel is the size of the indexes
6405 // I don't think anything but 8 or 16bit indexes makes sense
6406 stbi__rewind(s);
6407 return 0;
6408 }
6409 tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL);
6410 } else {
6411 tga_comp = stbi__tga_get_comp(
6412 tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11),
6413 NULL);
6414 }
6415 if (!tga_comp) {

Callers 1

stbi__info_mainFunction · 0.85

Calls 5

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

Tested by

no test coverage detected