pixel.h
Go to the documentation of this file.
1 #ifndef IZ_PIXEL_H
2 #define IZ_PIXEL_H 1
3 
4 #include "intmacros.h"
5 #include "predict.h"
6 
7 namespace IZ
8 {
9  template<typename U = unsigned char>
10  class Pixel
11  {
13  {
14  R = 0,
15  G = 1,
16  B = 2,
17  Count = 3,
18  C0 = G,
19  C1 = R,
20  C2 = B
21  };
22 
23  public:
24  void readFrom(const U* p)
25  {
26  c[0] = p[C0];
27  c[1] = p[C1];
28  c[2] = p[C2];
29  }
30 
31  void writeTo(U* p) const
32  {
33  p[C0] = c[0];
34  p[C1] = c[1];
35  p[C2] = c[2];
36  }
37 
38  void predict(const U* p, int bpp, int bpr, int (* predictor)(int, int, int)) __attribute__((always_inline))
39  {
40  c[0] = predictor(p[C0 - bpp], p[C0 - bpr], p[C0 - bpp - bpr]);
41  c[1] = predictor(p[C1 - bpp], p[C1 - bpr], p[C1 - bpp - bpr]);
42  c[2] = predictor(p[C2 - bpp], p[C2 - bpr], p[C2 - bpp - bpr]);
43  }
44 
45  void operator-=(const Pixel<U>& other)
46  {
47  c[0] -= other.c[0];
48  c[1] -= other.c[1];
49  c[2] -= other.c[2];
50  }
51 
52  void operator+=(const Pixel<U>& other)
53  {
54  c[0] += other.c[0];
55  c[1] += other.c[1];
56  c[2] += other.c[2];
57  }
58 
59  bool operator==(const Pixel<U>& other) const
60  {
61  return c[0] == other.c[0] && c[1] == other.c[1] && c[2] == other.c[2];
62  }
63 
65  {
66  c[1] -= c[0];
67  c[2] -= c[0];
68  }
69 
71  {
72  c[1] += c[0];
73  c[2] += c[0];
74  }
75 
76  void toUnsigned()
77  {
78  if (sizeof(U) == sizeof(signed char))
79  {
80  c[0] = s2u((signed char) c[0]);
81  c[1] = s2u((signed char) c[1]);
82  c[2] = s2u((signed char) c[2]);
83  }
84  else if (sizeof(U) == sizeof(signed short))
85  {
86  c[0] = s2u((signed short) c[0]);
87  c[1] = s2u((signed short) c[1]);
88  c[2] = s2u((signed short) c[2]);
89  }
90  else
91  {
92  c[0] = s2u(c[0]);
93  c[1] = s2u(c[1]);
94  c[2] = s2u(c[2]);
95  }
96  }
97 
98  void toSigned()
99  {
100  c[0] = u2s(c[0]);
101  c[1] = u2s(c[1]);
102  c[2] = u2s(c[2]);
103  }
104 
105  unsigned int numBits() const
106  {
107  return IZ::numBits(c[0] | c[1] | c[2]);
108  }
109 
110  void writeBits(BitEncoder<>& bc, int numBits) const
111  {
112  bc.writeBits(c[0], numBits);
113  bc.writeBits(c[1], numBits);
114  bc.writeBits(c[2], numBits);
115  bc.flushCache();
116  }
117 
119  {
120  c[0] = bc.readBits(numBits);
121  c[1] = bc.readBits(numBits);
122  c[2] = bc.readBits(numBits);
123  }
124 
125  int c[Count];
126  };
127 
128 } // namespace IZ
129 
130 #endif
static unsigned int numBits(unsigned int v)
Definition: intmacros.h:89
void readBits(BitDecoder<> &bc, int numBits)
Definition: pixel.h:118
void reverseTransform()
Definition: pixel.h:70
static int u2s(unsigned int u)
Definition: intmacros.h:104
void predict(const U *p, int bpp, int bpr, int(*predictor)(int, int, int)) __attribute__((always_inline))
Definition: pixel.h:38
Definition: bitcoder.h:6
unsigned int numBits() const
Definition: pixel.h:105
void writeTo(U *p) const
Definition: pixel.h:31
void operator+=(const Pixel< U > &other)
Definition: pixel.h:52
void writeBits(unsigned int bits, unsigned int count)
Definition: bitcoder.h:170
void writeBits(BitEncoder<> &bc, int numBits) const
Definition: pixel.h:110
void toUnsigned()
Definition: pixel.h:76
void readFrom(const U *p)
Definition: pixel.h:24
bool operator==(const Pixel< U > &other) const
Definition: pixel.h:59
Components
Definition: pixel.h:12
unsigned int readBits(unsigned int count)
Definition: bitcoder.h:113
void flushCache()
Definition: bitcoder.h:159
void forwardTransform()
Definition: pixel.h:64
void operator-=(const Pixel< U > &other)
Definition: pixel.h:45
static unsigned int s2u(int s)
Definition: intmacros.h:97
void toSigned()
Definition: pixel.h:98
int c[Count]
Definition: pixel.h:125


imagezero
Author(s):
autogenerated on Mon Jun 10 2019 13:37:22