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*/
| 4157 | the IDAT chunks (with filter index bytes and possible padding bits) |
| 4158 | return value is error*/ |
| 4159 | static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, |
| 4160 | unsigned w, unsigned h, const LodePNGInfo* info_png) |
| 4161 | { |
| 4162 | /* |
| 4163 | This function converts the filtered-padded-interlaced data into pure 2D image buffer with the PNG's colortype. |
| 4164 | Steps: |
| 4165 | *) if no Adam7: 1) unfilter 2) remove padding bits (= posible extra bits per scanline if bpp < 8) |
| 4166 | *) if adam7: 1) 7x unfilter 2) 7x remove padding bits 3) Adam7_deinterlace |
| 4167 | NOTE: the in buffer will be overwritten with intermediate data! |
| 4168 | */ |
| 4169 | unsigned bpp = lodepng_get_bpp(&info_png->color); |
| 4170 | if(bpp == 0) return 31; /*error: invalid colortype*/ |
| 4171 | |
| 4172 | if(info_png->interlace_method == 0) |
| 4173 | { |
| 4174 | if(bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8) |
| 4175 | { |
| 4176 | CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp)); |
| 4177 | removePaddingBits(out, in, w * bpp, ((w * bpp + 7) / 8) * 8, h); |
| 4178 | } |
| 4179 | /*we can immediately filter into the out buffer, no other steps needed*/ |
| 4180 | else CERROR_TRY_RETURN(unfilter(out, in, w, h, bpp)); |
| 4181 | } |
| 4182 | else /*interlace_method is 1 (Adam7)*/ |
| 4183 | { |
| 4184 | unsigned passw[7], passh[7]; size_t filter_passstart[8], padded_passstart[8], passstart[8]; |
| 4185 | unsigned i; |
| 4186 | |
| 4187 | Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); |
| 4188 | |
| 4189 | for(i = 0; i != 7; ++i) |
| 4190 | { |
| 4191 | CERROR_TRY_RETURN(unfilter(&in[padded_passstart[i]], &in[filter_passstart[i]], passw[i], passh[i], bpp)); |
| 4192 | /*TODO: possible efficiency improvement: if in this reduced image the bits fit nicely in 1 scanline, |
| 4193 | move bytes instead of bits or move not at all*/ |
| 4194 | if(bpp < 8) |
| 4195 | { |
| 4196 | /*remove padding bits in scanlines; after this there still may be padding |
| 4197 | bits between the different reduced images: each reduced image still starts nicely at a byte*/ |
| 4198 | removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]], passw[i] * bpp, |
| 4199 | ((passw[i] * bpp + 7) / 8) * 8, passh[i]); |
| 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | Adam7_deinterlace(out, in, w, h, bpp); |
| 4204 | } |
| 4205 | |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
| 4209 | static unsigned readChunk_PLTE(LodePNGColorMode* color, const unsigned char* data, size_t chunkLength) |
| 4210 | { |
no test coverage detected