MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__pic_load_core

Function stbi__pic_load_core

Source/Utils/stb_image.h:6387–6495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6385}
6386
6387static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *comp, stbi_uc *result)
6388{
6389 int act_comp=0,num_packets=0,y,chained;
6390 stbi__pic_packet packets[10];
6391
6392 // this will (should...) cater for even some bizarre stuff like having data
6393 // for the same channel in multiple packets.
6394 do {
6395 stbi__pic_packet *packet;
6396
6397 if (num_packets==sizeof(packets)/sizeof(packets[0]))
6398 return stbi__errpuc("bad format","too many packets");
6399
6400 packet = &packets[num_packets++];
6401
6402 chained = stbi__get8(s);
6403 packet->size = stbi__get8(s);
6404 packet->type = stbi__get8(s);
6405 packet->channel = stbi__get8(s);
6406
6407 act_comp |= packet->channel;
6408
6409 if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (reading packets)");
6410 if (packet->size != 8) return stbi__errpuc("bad format","packet isn't 8bpp");
6411 } while (chained);
6412
6413 *comp = (act_comp & 0x10 ? 4 : 3); // has alpha channel?
6414
6415 for(y=0; y<height; ++y) {
6416 int packet_idx;
6417
6418 for(packet_idx=0; packet_idx < num_packets; ++packet_idx) {
6419 stbi__pic_packet *packet = &packets[packet_idx];
6420 stbi_uc *dest = result+y*width*4;
6421
6422 switch (packet->type) {
6423 default:
6424 return stbi__errpuc("bad format","packet has bad compression type");
6425
6426 case 0: {//uncompressed
6427 int x;
6428
6429 for(x=0;x<width;++x, dest+=4)
6430 if (!stbi__readval(s,packet->channel,dest))
6431 return 0;
6432 break;
6433 }
6434
6435 case 1://Pure RLE
6436 {
6437 int left=width, i;
6438
6439 while (left>0) {
6440 stbi_uc count,value[4];
6441
6442 count=stbi__get8(s);
6443 if (stbi__at_eof(s)) return stbi__errpuc("bad file","file too short (pure read count)");
6444

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