MCPcopy Create free account
hub / github.com/creatale/node-dv / preProcessScanlines

Function preProcessScanlines

deps/lodepng/lodepng.cpp:5582–5667  ·  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

5580/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
5581return value is error**/
5582static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const unsigned char* in,
5583 unsigned w, unsigned h,
5584 const LodePNGInfo* info_png, const LodePNGEncoderSettings* settings)
5585{
5586 /*
5587 This function converts the pure 2D image with the PNG's colortype, into filtered-padded-interlaced data. Steps:
5588 *) if no Adam7: 1) add padding bits (= posible extra bits per scanline if bpp < 8) 2) filter
5589 *) if adam7: 1) Adam7_interlace 2) 7x add padding bits 3) 7x filter
5590 */
5591 unsigned bpp = lodepng_get_bpp(&info_png->color);
5592 unsigned error = 0;
5593
5594 if(info_png->interlace_method == 0)
5595 {
5596 *outsize = h + (h * ((w * bpp + 7) / 8)); /*image size plus an extra byte per scanline + possible padding bits*/
5597 *out = (unsigned char*)lodepng_malloc(*outsize);
5598 if(!(*out) && (*outsize)) error = 83; /*alloc fail*/
5599
5600 if(!error)
5601 {
5602 /*non multiple of 8 bits per scanline, padding bits needed per scanline*/
5603 if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
5604 {
5605 unsigned char* padded = (unsigned char*)lodepng_malloc(h * ((w * bpp + 7) / 8));
5606 if(!padded) error = 83; /*alloc fail*/
5607 if(!error)
5608 {
5609 addPaddingBits(padded, in, ((w * bpp + 7) / 8) * 8, w * bpp, h);
5610 error = filter(*out, padded, w, h, &info_png->color, settings);
5611 }
5612 lodepng_free(padded);
5613 }
5614 else
5615 {
5616 /*we can immediately filter into the out buffer, no other steps needed*/
5617 error = filter(*out, in, w, h, &info_png->color, settings);
5618 }
5619 }
5620 }
5621 else /*interlace_method is 1 (Adam7)*/
5622 {
5623 unsigned passw[7], passh[7];
5624 size_t filter_passstart[8], padded_passstart[8], passstart[8];
5625 unsigned char* adam7;
5626
5627 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
5628
5629 *outsize = filter_passstart[7]; /*image size plus an extra byte per scanline + possible padding bits*/
5630 *out = (unsigned char*)lodepng_malloc(*outsize);
5631 if(!(*out)) error = 83; /*alloc fail*/
5632
5633 adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
5634 if(!adam7 && passstart[7]) error = 83; /*alloc fail*/
5635
5636 if(!error)
5637 {
5638 unsigned i;
5639

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