MCPcopy Create free account
hub / github.com/DFHack/dfhack / Adam7_deinterlace

Function Adam7_deinterlace

depends/lodepng/lodepng.cpp:4239–4277  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

4237NOTE: comments about padding bits are only relevant if bpp < 8
4238*/
4239static void Adam7_deinterlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) {
4240 unsigned passw[7], passh[7];
4241 size_t filter_passstart[8], padded_passstart[8], passstart[8];
4242 unsigned i;
4243
4244 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
4245
4246 if(bpp >= 8) {
4247 for(i = 0; i != 7; ++i) {
4248 unsigned x, y, b;
4249 size_t bytewidth = bpp / 8u;
4250 for(y = 0; y < passh[i]; ++y)
4251 for(x = 0; x < passw[i]; ++x) {
4252 size_t pixelinstart = passstart[i] + (y * passw[i] + x) * bytewidth;
4253 size_t pixeloutstart = ((ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * (size_t)w
4254 + ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bytewidth;
4255 for(b = 0; b < bytewidth; ++b) {
4256 out[pixeloutstart + b] = in[pixelinstart + b];
4257 }
4258 }
4259 }
4260 } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ {
4261 for(i = 0; i != 7; ++i) {
4262 unsigned x, y, b;
4263 unsigned ilinebits = bpp * passw[i];
4264 unsigned olinebits = bpp * w;
4265 size_t obp, ibp; /*bit pointers (for out and in buffer)*/
4266 for(y = 0; y < passh[i]; ++y)
4267 for(x = 0; x < passw[i]; ++x) {
4268 ibp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
4269 obp = (ADAM7_IY[i] + (size_t)y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + (size_t)x * ADAM7_DX[i]) * bpp;
4270 for(b = 0; b < bpp; ++b) {
4271 unsigned char bit = readBitFromReversedStream(&ibp, in);
4272 setBitOfReversedStream(&obp, out, bit);
4273 }
4274 }
4275 }
4276 }
4277}
4278
4279static void removePaddingBits(unsigned char* out, const unsigned char* in,
4280 size_t olinebits, size_t ilinebits, unsigned h) {

Callers 1

postProcessScanlinesFunction · 0.85

Calls 3

Adam7_getpassvaluesFunction · 0.85
setBitOfReversedStreamFunction · 0.85

Tested by

no test coverage detected