| 4196 | } |
| 4197 | |
| 4198 | static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) { |
| 4199 | /* |
| 4200 | For PNG filter method 0 |
| 4201 | this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 seven times) |
| 4202 | out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline |
| 4203 | w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel |
| 4204 | in and out are allowed to be the same memory address (but aren't the same size since in has the extra filter bytes) |
| 4205 | */ |
| 4206 | |
| 4207 | unsigned y; |
| 4208 | unsigned char* prevline = 0; |
| 4209 | |
| 4210 | /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ |
| 4211 | size_t bytewidth = (bpp + 7u) / 8u; |
| 4212 | /*the width of a scanline in bytes, not including the filter type*/ |
| 4213 | size_t linebytes = lodepng_get_raw_size_idat(w, 1, bpp) - 1u; |
| 4214 | |
| 4215 | for(y = 0; y < h; ++y) { |
| 4216 | size_t outindex = linebytes * y; |
| 4217 | size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ |
| 4218 | unsigned char filterType = in[inindex]; |
| 4219 | |
| 4220 | CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); |
| 4221 | |
| 4222 | prevline = &out[outindex]; |
| 4223 | } |
| 4224 | |
| 4225 | return 0; |
| 4226 | } |
| 4227 | |
| 4228 | /* |
| 4229 | in: Adam7 interlaced image, with no padding bits between scanlines, but between |
no test coverage detected