Diffstat (limited to 'noncore/apps/opie-reader/Palm2QImage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Palm2QImage.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp index 9603877..bf5ece3 100644 --- a/noncore/apps/opie-reader/Palm2QImage.cpp +++ b/noncore/apps/opie-reader/Palm2QImage.cpp | |||
@@ -1,30 +1,31 @@ | |||
1 | /* -*- mode: c; indent-tabs-mode: nil; -*- */ | 1 | /* -*- mode: c; indent-tabs-mode: nil; -*- */ |
2 | #include "useqpe.h" | ||
2 | #include <stdio.h> | 3 | #include <stdio.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #ifndef WINDOWS | 6 | #ifndef _WINDOWS |
6 | #include <unistd.h> /* for link */ | 7 | #include <unistd.h> /* for link */ |
7 | #endif | 8 | #endif |
8 | #include <sys/types.h> | 9 | #include <sys/types.h> |
9 | #include <sys/stat.h> | 10 | #include <sys/stat.h> |
10 | #include <stdarg.h> | 11 | #include <stdarg.h> |
11 | 12 | ||
12 | #include <qimage.h> | 13 | #include <qimage.h> |
13 | 14 | ||
14 | /***********************************************************************/ | 15 | /***********************************************************************/ |
15 | /***********************************************************************/ | 16 | /***********************************************************************/ |
16 | /***** *****/ | 17 | /***** *****/ |
17 | /***** Code to decode the Palm image format to JPEG *****/ | 18 | /***** Code to decode the Palm image format to JPEG *****/ |
18 | /***** *****/ | 19 | /***** *****/ |
19 | /***********************************************************************/ | 20 | /***********************************************************************/ |
20 | /***********************************************************************/ | 21 | /***********************************************************************/ |
21 | 22 | ||
22 | #define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) | 23 | #define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) |
23 | #define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) | 24 | #define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) |
24 | 25 | ||
25 | #define PALM_IS_COMPRESSED_FLAG 0x8000 | 26 | #define PALM_IS_COMPRESSED_FLAG 0x8000 |
26 | #define PALM_HAS_COLORMAP_FLAG 0x4000 | 27 | #define PALM_HAS_COLORMAP_FLAG 0x4000 |
27 | #define PALM_HAS_TRANSPARENCY_FLAG 0x2000 | 28 | #define PALM_HAS_TRANSPARENCY_FLAG 0x2000 |
28 | #define PALM_DIRECT_COLOR_FLAG 0x0400 | 29 | #define PALM_DIRECT_COLOR_FLAG 0x0400 |
29 | #define PALM_4_BYTE_FIELD_FLAG 0x0200 | 30 | #define PALM_4_BYTE_FIELD_FLAG 0x0200 |
30 | 31 | ||
@@ -181,53 +182,53 @@ QImage* Palm2QImage | |||
181 | imagedatastart = palmimage + 16; | 182 | imagedatastart = palmimage + 16; |
182 | } else if (bits_per_pixel == 8) { | 183 | } else if (bits_per_pixel == 8) { |
183 | colormap = Palm8BitColormap; | 184 | colormap = Palm8BitColormap; |
184 | imagedatastart = palmimage + 16; | 185 | imagedatastart = palmimage + 16; |
185 | } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { | 186 | } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { |
186 | colormap = NULL; | 187 | colormap = NULL; |
187 | palm_red_bits = palmimage[16]; | 188 | palm_red_bits = palmimage[16]; |
188 | palm_green_bits = palmimage[17]; | 189 | palm_green_bits = palmimage[17]; |
189 | palm_blue_bits = palmimage[18]; | 190 | palm_blue_bits = palmimage[18]; |
190 | // qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); | 191 | // qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); |
191 | if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { | 192 | if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { |
192 | // qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", palm_red_bits, palm_green_bits, palm_blue_bits); | 193 | // qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", palm_red_bits, palm_green_bits, palm_blue_bits); |
193 | return NULL; | 194 | return NULL; |
194 | } | 195 | } |
195 | if (bits_per_pixel > (8 * sizeof(unsigned long))) { | 196 | if (bits_per_pixel > (8 * sizeof(unsigned long))) { |
196 | // qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); | 197 | // qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); |
197 | return NULL; | 198 | return NULL; |
198 | } | 199 | } |
199 | imagedatastart = palmimage + 24; | 200 | imagedatastart = palmimage + 24; |
200 | } else { | 201 | } else { |
201 | // qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); | 202 | // qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); |
202 | return NULL; | 203 | return NULL; |
203 | } | 204 | } |
204 | 205 | ||
205 | #ifdef WINDOWS | 206 | #ifndef USEQPE |
206 | QImage* qimage = new QImage(width, height, 32); | 207 | QImage* qimage = new QImage(width, height, 32); |
207 | #else | 208 | #else |
208 | QImage* qimage = new QImage(width, height, 16); | 209 | QImage* qimage = new QImage(width, height, 16); |
209 | #endif | 210 | #endif |
210 | 211 | ||
211 | /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ | 212 | /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ |
212 | rowbuf = new unsigned char[bytes_per_row * width]; | 213 | rowbuf = new unsigned char[bytes_per_row * width]; |
213 | lastrow = new unsigned char[bytes_per_row * width]; | 214 | lastrow = new unsigned char[bytes_per_row * width]; |
214 | 215 | ||
215 | for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { | 216 | for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { |
216 | // qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); | 217 | // qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row); |
217 | 218 | ||
218 | /* first, uncompress the Palm image */ | 219 | /* first, uncompress the Palm image */ |
219 | if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { | 220 | if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { |
220 | for (j = 0; j < bytes_per_row; ) { | 221 | for (j = 0; j < bytes_per_row; ) { |
221 | incount = *palm_ptr++; | 222 | incount = *palm_ptr++; |
222 | inval = *palm_ptr++; | 223 | inval = *palm_ptr++; |
223 | memset(rowbuf + j, inval, incount); | 224 | memset(rowbuf + j, inval, incount); |
224 | j += incount; | 225 | j += incount; |
225 | } | 226 | } |
226 | } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { | 227 | } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { |
227 | for (j = 0; j < bytes_per_row; j += 8) { | 228 | for (j = 0; j < bytes_per_row; j += 8) { |
228 | incount = *palm_ptr++; | 229 | incount = *palm_ptr++; |
229 | inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; | 230 | inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; |
230 | for (inbit = 0; inbit < inval; inbit += 1) { | 231 | for (inbit = 0; inbit < inval; inbit += 1) { |
231 | if (incount & (1 << (7 - inbit))) | 232 | if (incount & (1 << (7 - inbit))) |
232 | rowbuf[j + inbit] = *palm_ptr++; | 233 | rowbuf[j + inbit] = *palm_ptr++; |
233 | else | 234 | else |