MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / preProcessScanlines

Function preProcessScanlines

dependency/densecrf/examples/lodepng.cpp:5507–5592  ·  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

5505/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
5506 return value is error**/
5507static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in,
5508 unsigned w, unsigned h,
5509 const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings)
5510{
5511 /*
5512 This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
5513 *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter
5514 *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
5515 */
5516 unsigned bpp = lodepng_get_bpp(&info_png->color);
5517 unsigned error = 0;
5518
5519 if(info_png->interlace_method == 0)
5520 {
5521 *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
5522 *out = (unsigned char*)lodepng_malloc(*outsize);
5523 if(!(*out) && (*outsize)) error = 83; /*alloc fail*/
5524
5525 if(!error)
5526 {
5527 /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
5528 if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
5529 {
5530 unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8));
5531 if(!padded) error = 83; /*alloc fail*/
5532 if(!error)
5533 {
5534 addPaddingBits(padded, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
5535 error = filter(*out, padded, w, h, &info_png->color, settings);
5536 }
5537 lodepng_free(padded);
5538 }
5539 else
5540 {
5541 /*we can immediately filter into the out buffer, no other steps needed*/
5542 error = filter(*out, in, w, h, &info_png->color, settings);
5543 }
5544 }
5545 }
5546 else /*interlace_method is 1 (Adam7)*/
5547 {
5548 unsigned passw[7], passh[7];
5549 size_t filter_passstart[8], padded_passstart[8], passstart[8];
5550 unsigned char* adam7;
5551
5552 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
5553
5554 *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
5555 *out = (unsigned char*)lodepng_malloc(*outsize);
5556 if(!(*out)) error = 83; /*alloc fail*/
5557
5558 adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
5559 if(!adam7 && passstart[7]) error = 83; /*alloc fail*/
5560
5561 if(!error)
5562 {
5563 unsigned i;
5564

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