| 3934 | } |
| 3935 | |
| 3936 | static unsigned unfilter(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) |
| 3937 | { |
| 3938 | /* |
| 3939 | For PNG filter method 0 |
| 3940 | this function unfilters a single image (e.g. without interlacing this is called once, with Adam7 seven times) |
| 3941 | out must have enough bytes allocated already, in must have the scanlines + 1 filtertype byte per scanline |
| 3942 | w and h are image dimensions or dimensions of reduced image, bpp is bits per pixel |
| 3943 | in and out are allowed to be the same memory address (but aren't the same size since in has the extra filter bytes) |
| 3944 | */ |
| 3945 | |
| 3946 | unsigned y; |
| 3947 | unsigned char* prevline = 0; |
| 3948 | |
| 3949 | /*bytewidth is used for filtering, is 1 when bpp < 8, number of bytes per pixel otherwise*/ |
| 3950 | size_t bytewidth = (bpp + 7) / 8; |
| 3951 | size_t linebytes = (w * bpp + 7) / 8; |
| 3952 | |
| 3953 | for(y = 0; y < h; y++) |
| 3954 | { |
| 3955 | size_t outindex = linebytes * y; |
| 3956 | size_t inindex = (1 + linebytes) * y; /*the extra filterbyte added to each row*/ |
| 3957 | unsigned char filterType = in[inindex]; |
| 3958 | |
| 3959 | CERROR_TRY_RETURN(unfilterScanline(&out[outindex], &in[inindex + 1], prevline, bytewidth, filterType, linebytes)); |
| 3960 | |
| 3961 | prevline = &out[outindex]; |
| 3962 | } |
| 3963 | |
| 3964 | return 0; |
| 3965 | } |
| 3966 | |
| 3967 | /* |
| 3968 | in: Adam7 interlaced image, with no padding bits between scanlines, but between |
no test coverage detected