Diffstat (limited to 'noncore/apps/opie-reader/Palm2QImage.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Palm2QImage.cpp | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp index 9339595..b0d4e00 100644 --- a/noncore/apps/opie-reader/Palm2QImage.cpp +++ b/noncore/apps/opie-reader/Palm2QImage.cpp | |||
@@ -1,4 +1,12 @@ | |||
1 | /* -*- mode: c; indent-tabs-mode: nil; -*- */ | 1 | /* -*- mode: c; indent-tabs-mode: nil; -*- */ |
2 | |||
3 | /* OPIE */ | ||
4 | #include <opie2/odebug.h> | ||
5 | |||
6 | /* QT */ | ||
7 | #include <qimage.h> | ||
8 | |||
9 | /* STD */ | ||
2 | #include <stdio.h> | 10 | #include <stdio.h> |
3 | #include <stdlib.h> | 11 | #include <stdlib.h> |
4 | #include <string.h> | 12 | #include <string.h> |
@@ -9,7 +17,6 @@ | |||
9 | #include <sys/stat.h> | 17 | #include <sys/stat.h> |
10 | #include <stdarg.h> | 18 | #include <stdarg.h> |
11 | 19 | ||
12 | #include <qimage.h> | ||
13 | 20 | ||
14 | /***********************************************************************/ | 21 | /***********************************************************************/ |
15 | /***********************************************************************/ | 22 | /***********************************************************************/ |
@@ -141,16 +148,18 @@ QImage* Palm2QImage | |||
141 | /* bytes 14 and 15 are reserved by Palm and always 0 */ | 148 | /* bytes 14 and 15 are reserved by Palm and always 0 */ |
142 | 149 | ||
143 | #if 0 | 150 | #if 0 |
144 | // qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type); | 151 | // odebug << "Palm image is " << width << "x" << height |
152 | // << ", " << bits_per_pixel << " bpp, version " << version | ||
153 | // << ", flags 0x" << flags << ", compression " << compression_type << oendl; | ||
145 | #endif | 154 | #endif |
146 | 155 | ||
147 | if (compression_type == PALM_COMPRESSION_PACKBITS) { | 156 | if (compression_type == PALM_COMPRESSION_PACKBITS) { |
148 | // qDebug ("Image uses packbits compression; not yet supported"); | 157 | // odebug << "Image uses packbits compression; not yet supported" << oendl; |
149 | return NULL; | 158 | return NULL; |
150 | } else if ((compression_type != PALM_COMPRESSION_NONE) && | 159 | } else if ((compression_type != PALM_COMPRESSION_NONE) && |
151 | (compression_type != PALM_COMPRESSION_RLE) && | 160 | (compression_type != PALM_COMPRESSION_RLE) && |
152 | (compression_type != PALM_COMPRESSION_SCANLINE)) { | 161 | (compression_type != PALM_COMPRESSION_SCANLINE)) { |
153 | // qDebug ("Image uses unknown compression, code 0x%x", compression_type); | 162 | // odebug << "Image uses unknown compression, code 0x" << compression_type << oendl; |
154 | return NULL; | 163 | return NULL; |
155 | } | 164 | } |
156 | 165 | ||
@@ -168,7 +177,7 @@ QImage* Palm2QImage | |||
168 | */ | 177 | */ |
169 | 178 | ||
170 | if (flags & PALM_HAS_COLORMAP_FLAG) { | 179 | if (flags & PALM_HAS_COLORMAP_FLAG) { |
171 | // qDebug("Palm images with custom colormaps are not currently supported.\n"); | 180 | // odebug << "Palm images with custom colormaps are not currently supported." << oendl; |
172 | return NULL; | 181 | return NULL; |
173 | } else if (bits_per_pixel == 1) { | 182 | } else if (bits_per_pixel == 1) { |
174 | colormap = Palm1BitColormap; | 183 | colormap = Palm1BitColormap; |
@@ -187,18 +196,20 @@ QImage* Palm2QImage | |||
187 | palm_red_bits = palmimage[16]; | 196 | palm_red_bits = palmimage[16]; |
188 | palm_green_bits = palmimage[17]; | 197 | palm_green_bits = palmimage[17]; |
189 | palm_blue_bits = palmimage[18]; | 198 | palm_blue_bits = palmimage[18]; |
190 | // qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); | 199 | // odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl; |
191 | if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { | 200 | 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); | 201 | // odebug << "Can't handle this format DirectColor image -- too wide in some color (" |
202 | // << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl; | ||
193 | return NULL; | 203 | return NULL; |
194 | } | 204 | } |
195 | if (bits_per_pixel > (8 * sizeof(unsigned long))) { | 205 | 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); | 206 | // odebug << "Can't handle this format DirectColor image -- too many bits per pixel (" |
207 | // << bits_per_pixel << ")" << oendl; | ||
197 | return NULL; | 208 | return NULL; |
198 | } | 209 | } |
199 | imagedatastart = palmimage + 24; | 210 | imagedatastart = palmimage + 24; |
200 | } else { | 211 | } else { |
201 | // qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); | 212 | // odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl; |
202 | return NULL; | 213 | return NULL; |
203 | } | 214 | } |
204 | 215 | ||
@@ -213,7 +224,8 @@ QImage* Palm2QImage | |||
213 | lastrow = new unsigned char[bytes_per_row * width]; | 224 | lastrow = new unsigned char[bytes_per_row * width]; |
214 | 225 | ||
215 | for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { | 226 | 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); | 227 | // odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr |
228 | // << " bpr:" << bytes_per_row << oendl; | ||
217 | 229 | ||
218 | /* first, uncompress the Palm image */ | 230 | /* first, uncompress the Palm image */ |
219 | if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { | 231 | if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { |
@@ -243,12 +255,12 @@ QImage* Palm2QImage | |||
243 | palm_ptr += bytes_per_row; | 255 | palm_ptr += bytes_per_row; |
244 | } | 256 | } |
245 | else { | 257 | else { |
246 | qDebug("Case 4"); | 258 | odebug << "Case 4" << oendl; |
247 | qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); | 259 | odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl; |
248 | qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); | 260 | odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl; |
249 | qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); | 261 | odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl; |
250 | qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); | 262 | odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl; |
251 | qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); | 263 | odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl; |
252 | memcpy (rowbuf, palm_ptr, bytes_per_row); | 264 | memcpy (rowbuf, palm_ptr, bytes_per_row); |
253 | palm_ptr += bytes_per_row; | 265 | palm_ptr += bytes_per_row; |
254 | } | 266 | } |
@@ -275,11 +287,10 @@ QImage* Palm2QImage | |||
275 | inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; | 287 | inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; |
276 | 288 | ||
277 | /* | 289 | /* |
278 | qDebug ("pixel is %d,%d (%d:%d:%d)", | 290 | odebug << "pixel is " << j << "," << i << " (" |
279 | j, i, | 291 | << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":" |
280 | ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), | 292 | << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":" |
281 | ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), | 293 | << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl; |
282 | ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); | ||
283 | */ | 294 | */ |
284 | QRgb colour = qRgb( | 295 | QRgb colour = qRgb( |
285 | ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), | 296 | ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), |
@@ -299,7 +310,7 @@ QImage* Palm2QImage | |||
299 | 310 | ||
300 | QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b) | 311 | QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b) |
301 | { | 312 | { |
302 | //// qDebug("hrule [%d, %d]", w, h); | 313 | // odebug << "hrule [" << w << ", " << h << "]" << oendl; |
303 | QPixmap* qimage = new QPixmap(w, h); | 314 | QPixmap* qimage = new QPixmap(w, h); |
304 | qimage->fill(QColor(r,g,b)); | 315 | qimage->fill(QColor(r,g,b)); |
305 | QImage* ret = new QImage(qimage->convertToImage()); | 316 | QImage* ret = new QImage(qimage->convertToImage()); |