41 for (
int y = 0; y < height; y++) {
46 for (
int x = 0; x < width; x++) {
47 int v = getPixel(x, y) / 85;
74 int rawLen = rawBuf.
getLen();
76 int lastByte = rawBuf.
getByte(0);
79 for (
int i = 1; i <= rawLen; i++) {
104 if ((diBuf.
getLen() > 0x7f) || (i == rawLen)) {
119#define splitByte(v) \
123 if (x < bytesPerLine) \
124 for (j = 0; j < pixelsPerByte; j++) { \
125 if (j && ((oidx % xPixels) == 0)) \
128 if (oidx >= picsize) \
131 out.addByte((v & mask) * grayVal); \
132 v >>= bitsPerPixel; \
136 if (++x >= linelen) \
143 uint32_t totlen = *((
const uint32_t*)p); p += 4;
144 uint32_t hdrlen = *((
const uint32_t*)p); p += 4;
145 uint32_t datlen = totlen - hdrlen;
146 uint32_t xPixels = *((
const uint32_t*)p); p += 4;
147 uint32_t yPixels = *((
const uint32_t*)p); p += 4;
148 uint32_t xTwips = *((
const uint32_t*)p); p += 4;
149 uint32_t yTwips = *((
const uint32_t*)p); p += 4;
150 uint32_t bitsPerPixel = *((
const uint32_t*)p); p += 4;
151 uint32_t unknown1 = *((
const uint32_t*)p); p += 4;
152 uint32_t unknown2 = *((
const uint32_t*)p); p += 4;
153 uint32_t RLEflag = *((
const uint32_t*)p); p += 4;
158 uint32_t picsize = xPixels * yPixels;
160 int pixelsPerByte = (8 / bitsPerPixel);
161 int nColors = 1 << bitsPerPixel;
162 int grayVal = 255 / (nColors - 1);
163 int bytesPerLine = (xPixels + pixelsPerByte - 1) / pixelsPerByte;
164 int mask = (bitsPerPixel << 1) - 1;
173 while (offset < datlen) {
174 unsigned char b = *(p + offset);
176 offset += 0x100 - b + 1;
183 linelen = i / yPixels;
185 while (offset < datlen) {
186 unsigned char b = *(p + offset++);
188 for (i = 0; i < 0x100 - b; i++, offset++) {
189 if (offset >= datlen)
191 unsigned char b2 = *(p + offset);
195 if (offset >= datlen)
198 unsigned char b2 = *(p + offset);
199 unsigned char bs = b2;
200 for (i = 0; i <= b; i++) {
209 linelen = datlen / yPixels;
210 while (offset < datlen) {
211 unsigned char b = *(p + offset++);
A generic container for an array of bytes.
void init()
Initializes the bufferStore.
void addBuff(const bufferStore &b, long maxLen=-1)
Appends data to the content of this instance.
void addByte(unsigned char c)
Appends a byte to the content of this instance.
void addDWord(long dw)
Appends a dword to the content of this instance.
unsigned long getLen() const
Retrieves the length of a bufferStore.
unsigned char getByte(long pos=0) const
Retrieves the byte at index pos.
void encodeBitmap(int width, int height, getPixelFunction_t getPixel, bool, bufferStore &out)
Convert an image into a bitmap in Psion format.
bool decodeBitmap(const unsigned char *p, int &width, int &height, bufferStore &out)
Convert a Psion bitmap to a 8bit/pixel grayscale image.
int(* getPixelFunction_t)(int x, int y)
This function is used by encodeBitmap for retrieving image data.