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

Function Adam7_interlace

depends/lodepng/lodepng.cpp:5668–5705  ·  view source on GitHub ↗

in: non-interlaced image with size w*h out: the same pixels, but re-ordered according to PNG's Adam7 interlacing, with no padding bits between scanlines, but between reduced images so that each reduced image starts at a byte. bpp: bits per pixel there are no padding bits, not between scanlines, not between reduced images in has the following size in bits: w * h * bpp. out is possibly bigger due

Source from the content-addressed store, hash-verified

5666NOTE: comments about padding bits are only relevant if bpp < 8
5667*/
5668static void Adam7_interlace(unsigned char* out, const unsigned char* in, unsigned w, unsigned h, unsigned bpp) {
5669 unsigned passw[7], passh[7];
5670 size_t filter_passstart[8], padded_passstart[8], passstart[8];
5671 unsigned i;
5672
5673 Adam7_getpassvalues(passw, passh, filter_passstart, padded_passstart, passstart, w, h, bpp);
5674
5675 if(bpp >= 8) {
5676 for(i = 0; i != 7; ++i) {
5677 unsigned x, y, b;
5678 size_t bytewidth = bpp / 8u;
5679 for(y = 0; y < passh[i]; ++y)
5680 for(x = 0; x < passw[i]; ++x) {
5681 size_t pixelinstart = ((ADAM7_IY[i] + y * ADAM7_DY[i]) * w + ADAM7_IX[i] + x * ADAM7_DX[i]) * bytewidth;
5682 size_t pixeloutstart = passstart[i] + (y * passw[i] + x) * bytewidth;
5683 for(b = 0; b < bytewidth; ++b) {
5684 out[pixeloutstart + b] = in[pixelinstart + b];
5685 }
5686 }
5687 }
5688 } else /*bpp < 8: Adam7 with pixels < 8 bit is a bit trickier: with bit pointers*/ {
5689 for(i = 0; i != 7; ++i) {
5690 unsigned x, y, b;
5691 unsigned ilinebits = bpp * passw[i];
5692 unsigned olinebits = bpp * w;
5693 size_t obp, ibp; /*bit pointers (for out and in buffer)*/
5694 for(y = 0; y < passh[i]; ++y)
5695 for(x = 0; x < passw[i]; ++x) {
5696 ibp = (ADAM7_IY[i] + y * ADAM7_DY[i]) * olinebits + (ADAM7_IX[i] + x * ADAM7_DX[i]) * bpp;
5697 obp = (8 * passstart[i]) + (y * ilinebits + x * bpp);
5698 for(b = 0; b < bpp; ++b) {
5699 unsigned char bit = readBitFromReversedStream(&ibp, in);
5700 setBitOfReversedStream(&obp, out, bit);
5701 }
5702 }
5703 }
5704 }
5705}
5706
5707/*out must be buffer big enough to contain uncompressed IDAT chunk data, and in must contain the full image.
5708return value is error**/

Callers 1

preProcessScanlinesFunction · 0.85

Calls 3

Adam7_getpassvaluesFunction · 0.85
setBitOfReversedStreamFunction · 0.85

Tested by

no test coverage detected