in: Adam7 interlaced image, with no padding bits between scanlines, but between reduced images so that each reduced image starts at a byte. out: the same pixels, but re-ordered so that they're now a non-interlaced image with size w*h bpp: bits per pixel out has the following size in bits: w * h * bpp. in is possibly bigger due to padding bits between reduced images. out must be big enough AND mus
| 3976 | NOTE: comments about padding bits are only relevant if bpp < 8 |
| 3977 | */ |
| 3978 | static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) |
| 3979 | { |
| 3980 | unsigned passw[7], passh[7]; |
| 3981 | size_t filter_passstart[8], padded_passstart[8], passstart[8]; |
| 3982 | unsigned i; |
| 3983 | |
| 3984 | Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp); |
| 3985 | |
| 3986 | if(bpp >= 8) |
| 3987 | { |
| 3988 | for(i = 0; i < 7; i++) |
| 3989 | { |
| 3990 | unsigned x, y, b; |
| 3991 | size_t bytewidth = bpp / 8; |
| 3992 | for(y = 0; y < passh[i]; y++) |
| 3993 | for(x = 0; x < passw[i]; x++) |
| 3994 | { |
| 3995 | size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth; |
| 3996 | size_t pixeloutstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth; |
| 3997 | for(b = 0; b < bytewidth; b++) |
| 3998 | { |
| 3999 | out[pixeloutstart + b] = in[pixelinstart + b]; |
| 4000 | } |
| 4001 | } |
| 4002 | } |
| 4003 | } |
| 4004 | else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ |
| 4005 | { |
| 4006 | for(i = 0; i < 7; i++) |
| 4007 | { |
| 4008 | unsigned x, y, b; |
| 4009 | unsigned ilinebits = bpp * passw[i]; |
| 4010 | unsigned olinebits = bpp * w; |
| 4011 | size_t obp, ibp; /*bit pointers (for out and in buffer)*/ |
| 4012 | for(y = 0; y < passh[i]; y++) |
| 4013 | for(x = 0; x < passw[i]; x++) |
| 4014 | { |
| 4015 | ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp); |
| 4016 | obp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp; |
| 4017 | for(b = 0; b < bpp; b++) |
| 4018 | { |
| 4019 | unsigned char bit = readBitFromReversedStream(&ibp, in); |
| 4020 | /*note that this function assumes the out buffer is completely 0, use setBitOfReversedStream otherwise*/ |
| 4021 | setBitOfReversedStream0(&obp, out, bit); |
| 4022 | } |
| 4023 | } |
| 4024 | } |
| 4025 | } |
| 4026 | } |
| 4027 | |
| 4028 | static void removePaddingBits(unsigned char* out, const unsigned char* in, |
| 4029 | size_t olinebits, size_t ilinebits, unsigned h) |
no test coverage detected