MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / preProcessScanlines

Function preProcessScanlines

src/lodepng.cpp:5535–5620  ·  view source on GitHub ↗

out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image. return value is error**/

Source from the content-addressed store, hash-verified

5533/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
5534return value is error**/
5535static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in,
5536 unsigned w, unsigned h,
5537 const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings)
5538{
5539 /*
5540 This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
5541 *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter
5542 *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
5543 */
5544 unsigned bpp = lodepng_get_bpp(&info_png->color);
5545 unsigned error = 0;
5546
5547 if(info_png->interlace_method == 0)
5548 {
5549 *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
5550 *out = (unsigned char*)lodepng_malloc(*outsize);
5551 if(!(*out) && (*outsize)) error = 83; /*alloc fail*/
5552
5553 if(!error)
5554 {
5555 /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
5556 if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
5557 {
5558 unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8));
5559 if(!padded) error = 83; /*alloc fail*/
5560 if(!error)
5561 {
5562 addPaddingBits(padded, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
5563 error = filter(*out, padded, w, h, &info_png->color, settings);
5564 }
5565 lodepng_free(padded);
5566 }
5567 else
5568 {
5569 /*we can immediatly filter into the out buffer, no other steps needed*/
5570 error = filter(*out, in, w, h, &info_png->color, settings);
5571 }
5572 }
5573 }
5574 else /*interlace_method is 1 (Adam7)*/
5575 {
5576 unsigned passw[7], passh[7];
5577 size_t filter_passstart[8], padded_passstart[8], passstart[8];
5578 unsigned char* adam7;
5579
5580 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
5581
5582 *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
5583 *out = (unsigned char*)lodepng_malloc(*outsize);
5584 if(!(*out)) error = 83; /*alloc fail*/
5585
5586 adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
5587 if(!adam7 && passstart[7]) error = 83; /*alloc fail*/
5588
5589 if(!error)
5590 {
5591 unsigned i;
5592

Callers 1

lodepng_encodeFunction · 0.85

Calls 7

lodepng_get_bppFunction · 0.85
lodepng_mallocFunction · 0.85
addPaddingBitsFunction · 0.85
filterFunction · 0.85
lodepng_freeFunction · 0.85
Adam7_getpassvaluesFunction · 0.85
Adam7_interlaceFunction · 0.85

Tested by

no test coverage detected