Go to the documentation of this file.00001 #ifndef IZ_DECODER_H
00002 #define IZ_DECODER_H 1
00003
00004 #include <cstring>
00005
00006 #include "iz_p.h"
00007
00008 namespace IZ {
00009
00010 #define decodePixel(predictor) \
00011 { \
00012 Pixel<> pix, pp; \
00013 \
00014 this->fillCache(); \
00015 int nl = decodeTable[pl][this->peekBits(MAX_CODE_LENGTH)]; \
00016 this->skipBits(dCount[(pl << CONTEXT_BITS) + nl]); \
00017 pl = nl; \
00018 pix.readBits(*this, nl); \
00019 \
00020 pp.predict(p, bpp, bpr, predictor::predict); \
00021 pix.toSigned(); \
00022 pix.reverseTransform(); \
00023 pix += pp; \
00024 pix.writeTo(p); \
00025 p += bpp; \
00026 }
00027
00028 template <
00029 int bpp = 3,
00030 typename Predictor = Predictor3avgplane<>,
00031 typename Code = U32
00032 >
00033 class ImageDecoder : public BitDecoder<Code>
00034 {
00035 public:
00036 ImageDecoder() {
00037 memcpy(dCount, staticdCount, sizeof(dCount));
00038 }
00039
00040 void decodeImagePixels(Image<> &im) __attribute__((always_inline)) {
00041 unsigned char *p = (unsigned char *) im.data();
00042 const int bpr = bpp * im.width();
00043 im.setSamplesPerLine(bpr);
00044 const int size = im.width() * im.height();
00045 unsigned char *pend = p + bpp * size;
00046 int pl = 7;
00047
00048
00049 decodePixel(Predictor0<>);
00050
00051 const unsigned char *endline = p + bpr - bpp;
00052 while (p != endline) {
00053 decodePixel(Predictor1x<>);
00054 }
00055 while (p != pend) {
00056
00057 decodePixel(Predictor1y<>);
00058
00059 const unsigned char *endline = p + bpr - bpp;
00060 while (p != endline) {
00061 decodePixel(Predictor);
00062 }
00063 }
00064 }
00065
00066 void decodeImageSize(Image<> &im) {
00067 this->fillCache();
00068 int b = this->readBits(4);
00069 int w = this->readBits(b) + 1;
00070 int h = this->readBits(b) + 1;
00071 im.setWidth(w);
00072 im.setHeight(h);
00073 }
00074
00075 void skipImageSize() {
00076 this->fillCache();
00077 int b = this->readBits(4);
00078 this->skipBits(2 * b);
00079 }
00080
00081 private:
00082 unsigned int dCount[1 << (2 * CONTEXT_BITS)];
00083 };
00084
00085 }
00086
00087 #endif