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

Function stbi__pic_load_core

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

Source from the content-addressed store, hash-verified

7008}
7009
7010static stbi_uc* stbi__pic_load_core(
7011 stbi__context* s, int width, int height, int* comp, stbi_uc* result) {
7012 int act_comp = 0, num_packets = 0, y, chained;
7013 stbi__pic_packet packets[10];
7014
7015 // this will (should...) cater for even some bizarre stuff like having data
7016 // for the same channel in multiple packets.
7017 do {
7018 stbi__pic_packet* packet;
7019
7020 if (num_packets == sizeof(packets) / sizeof(packets[0]))
7021 return stbi__errpuc("bad format", "too many packets");
7022
7023 packet = &packets[num_packets++];
7024
7025 chained = stbi__get8(s);
7026 packet->size = stbi__get8(s);
7027 packet->type = stbi__get8(s);
7028 packet->channel = stbi__get8(s);
7029
7030 act_comp |= packet->channel;
7031
7032 if (stbi__at_eof(s))
7033 return stbi__errpuc("bad file", "file too short (reading packets)");
7034 if (packet->size != 8)
7035 return stbi__errpuc("bad format", "packet isn't 8bpp");
7036 } while (chained);
7037
7038 *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel?
7039
7040 for (y = 0; y < height; ++y) {
7041 int packet_idx;
7042
7043 for (packet_idx = 0; packet_idx < num_packets; ++packet_idx) {
7044 stbi__pic_packet* packet = &packets[packet_idx];
7045 stbi_uc* dest = result + y * width * 4;
7046
7047 switch (packet->type) {
7048 default:
7049 return stbi__errpuc(
7050 "bad format", "packet has bad compression type");
7051
7052 case 0: { // uncompressed
7053 int x;
7054
7055 for (x = 0; x < width; ++x, dest += 4)
7056 if (!stbi__readval(s, packet->channel, dest))
7057 return 0;
7058 break;
7059 }
7060
7061 case 1: // Pure RLE
7062 {
7063 int left = width, i;
7064
7065 while (left > 0) {
7066 stbi_uc count, value[4];
7067

Callers 1

stbi__pic_loadFunction · 0.85

Calls 5

stbi__get8Function · 0.85
stbi__at_eofFunction · 0.85
stbi__readvalFunction · 0.85
stbi__copyvalFunction · 0.85
stbi__get16beFunction · 0.85

Tested by

no test coverage detected