MCPcopy Create free account
hub / github.com/cjcliffe/CubicSDR / postProcessScanlines

Function postProcessScanlines

external/lodepng/lodepng.cpp:4381–4429  ·  view source on GitHub ↗

out must be buffer big enough to contain full image, and in must contain the full decompressed data from the IDAT chunks (with filter index bytes and possible padding bits) return value is error*/

Source from the content-addressed store, hash-verified

4379the IDAT chunks (with filter index bytes and possible padding bits)
4380return value is error*/
4381static unsigned postProcessScanlines(unsigned char* out, unsigned char* in,
4382 unsigned w, unsigned h, const LodePNGInfo* info_png)
4383{
4384 /*
4385 This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype.
4386 Steps:
4387 *) if no Adam7: 1) unfilter 2) remove padding bits (= posible extra bits per scanline if bpp < 8)
4388 *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace
4389 NOTE: the in buffer will be overwritten with intermediate data!
4390 */
4391 unsigned bpp = lodepng_get_bpp(&info_png->color);
4392 if(bpp == 0) return 31; /*error: invalid colortype*/
4393
4394 if(info_png->interlace_method == 0)
4395 {
4396 if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
4397 {
4398 CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp));
4399 removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h);
4400 }
4401 /*we can immediately filter into the out buffer, no other steps needed*/
4402 else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp));
4403 }
4404 else /*interlace_method is 1 (Adam7)*/
4405 {
4406 unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8];
4407 unsigned i;
4408
4409 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
4410
4411 for(i = 0; i != 7; ++i)
4412 {
4413 CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp));
4414 /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline,
4415 move bytes instead of bits or move not at all*/
4416 if(bpp < 8)
4417 {
4418 /*remove padding bits in scanlines; after this there still may be padding
4419 bits between the different reduced images: each reduced image still starts nicely at a byte*/
4420 removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp,
4421 ((passw[i] * bpp + 7) / 8) * 8, passh[i]);
4422 }
4423 }
4424
4425 Adam7_deinterlace(out, in, w, h, bpp);
4426 }
4427
4428 return 0;
4429}
4430
4431static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength)
4432{

Callers 1

lodepng.cppFile · 0.85

Calls 5

lodepng_get_bppFunction · 0.85
unfilterFunction · 0.85
removePaddingBitsFunction · 0.85
Adam7_getpassvaluesFunction · 0.85
Adam7_deinterlaceFunction · 0.85

Tested by

no test coverage detected