decoder.h
Go to the documentation of this file.
1 #ifndef IZ_DECODER_H
2 #define IZ_DECODER_H 1
3 
4 #include <cstring>
5 
6 #include "iz_p.h"
7 
8 namespace IZ {
9 
10 #define decodePixel(predictor) \
11 { \
12  Pixel<> pix, pp; \
13  \
14  this->fillCache(); \
15  int nl = decodeTable[pl][this->peekBits(MAX_CODE_LENGTH)]; \
16  this->skipBits(dCount[(pl << CONTEXT_BITS) + nl]); \
17  pl = nl; \
18  pix.readBits(*this, nl); \
19  \
20  pp.predict(p, bpp, bpr, predictor::predict); \
21  pix.toSigned(); \
22  pix.reverseTransform(); \
23  pix += pp; \
24  pix.writeTo(p); \
25  p += bpp; \
26 }
27 
28 template <
29  int bpp = 3,
30  typename Predictor = Predictor3avgplane<>,
31  typename Code = U32
32 >
33 class ImageDecoder : public BitDecoder<Code>
34 {
35 public:
37  memcpy(dCount, staticdCount, sizeof(dCount));
38  }
39 
40  void decodeImagePixels(Image<> &im) __attribute__((always_inline)) {
41  unsigned char *p = (unsigned char *) im.data();
42  const int bpr = bpp * im.width();
43  im.setSamplesPerLine(bpr);
44  const int size = im.width() * im.height();
45  unsigned char *pend = p + bpp * size;
46  int pl = 7;
47 
48  /* first pixel in first line */
50  /* remaining pixels in first line */
51  const unsigned char *endline = p + bpr - bpp;
52  while (p != endline) {
54  }
55  while (p != pend) {
56  /* first pixel in remaining lines */
58  /* remaining pixels in remaining lines */
59  const unsigned char *endline = p + bpr - bpp;
60  while (p != endline) {
61  decodePixel(Predictor);
62  }
63  }
64  }
65 
67  this->fillCache();
68  int b = this->readBits(4);
69  int w = this->readBits(b) + 1;
70  int h = this->readBits(b) + 1;
71  im.setWidth(w);
72  im.setHeight(h);
73  }
74 
75  void skipImageSize() {
76  this->fillCache();
77  int b = this->readBits(4);
78  this->skipBits(2 * b);
79  }
80 
81 private:
82  unsigned int dCount[1 << (2 * CONTEXT_BITS)];
83 };
84 
85 } // namespace IZ
86 
87 #endif
void skipBits(unsigned int count)
Definition: bitcoder.h:105
void decodeImageSize(Image<> &im)
Definition: decoder.h:66
Definition: bitcoder.h:6
unsigned int U32
Definition: bitcoder.h:24
void setWidth(int width)
Definition: image.h:20
#define decodePixel(predictor)
Definition: decoder.h:10
const unsigned int staticdCount[1<< (2 *CONTEXT_BITS)]
Definition: table.cpp:9
void decodeImagePixels(Image<> &im) __attribute__((always_inline))
Definition: decoder.h:40
const int CONTEXT_BITS
Definition: iz_p.h:12
void setHeight(int height)
Definition: image.h:21
unsigned int dCount[1<< (2 *CONTEXT_BITS)]
Definition: decoder.h:82
const Code * p
Definition: bitcoder.h:134
void skipImageSize()
Definition: decoder.h:75
unsigned int readBits(unsigned int count)
Definition: bitcoder.h:113
void fillCache()
Definition: bitcoder.h:84


imagezero
Author(s):
autogenerated on Wed Jun 5 2019 22:02:47