summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Palm2QImage.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Palm2QImage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp74
1 files changed, 46 insertions, 28 deletions
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index ef88cc5..9603877 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -4,3 +4,5 @@
4#include <string.h> 4#include <string.h>
5#include <unistd.h> /* for link */ 5#ifndef WINDOWS
6#include <unistd.h> /* for link */
7#endif
6#include <sys/types.h> 8#include <sys/types.h>
@@ -141,4 +143,3 @@ QImage* Palm2QImage
141#if 0 143#if 0
142 qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", 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);
143 width, height, bits_per_pixel, version, flags, compression_type);
144#endif 145#endif
@@ -146,3 +147,3 @@ QImage* Palm2QImage
146 if (compression_type == PALM_COMPRESSION_PACKBITS) { 147 if (compression_type == PALM_COMPRESSION_PACKBITS) {
147 qDebug ("Image uses packbits compression; not yet supported"); 148// qDebug ("Image uses packbits compression; not yet supported");
148 return NULL; 149 return NULL;
@@ -151,3 +152,3 @@ QImage* Palm2QImage
151 (compression_type != PALM_COMPRESSION_SCANLINE)) { 152 (compression_type != PALM_COMPRESSION_SCANLINE)) {
152 qDebug ("Image uses unknown compression, code 0x%x", compression_type); 153// qDebug ("Image uses unknown compression, code 0x%x", compression_type);
153 return NULL; 154 return NULL;
@@ -169,3 +170,3 @@ QImage* Palm2QImage
169 if (flags & PALM_HAS_COLORMAP_FLAG) { 170 if (flags & PALM_HAS_COLORMAP_FLAG) {
170 qDebug("Palm images with custom colormaps are not currently supported.\n"); 171// qDebug("Palm images with custom colormaps are not currently supported.\n");
171 return NULL; 172 return NULL;
@@ -188,5 +189,5 @@ QImage* Palm2QImage
188 palm_blue_bits = palmimage[18]; 189 palm_blue_bits = palmimage[18];
190// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits);
189 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { 191 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
190 qDebug("Can't handle this format DirectColor image -- too wide in some color (%d:%d:%d)\n", 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);
191 palm_red_bits, palm_green_bits, palm_blue_bits);
192 return NULL; 193 return NULL;
@@ -194,4 +195,3 @@ QImage* Palm2QImage
194 if (bits_per_pixel > (8 * sizeof(unsigned long))) { 195 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
195 qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", 196// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel);
196 bits_per_pixel);
197 return NULL; 197 return NULL;
@@ -200,3 +200,3 @@ QImage* Palm2QImage
200 } else { 200 } else {
201 qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); 201// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
202 return NULL; 202 return NULL;
@@ -204,3 +204,7 @@ QImage* Palm2QImage
204 204
205 QImage* qimage = new QImage(width, height, 16); 205#ifdef WINDOWS
206 QImage* qimage = new QImage(width, height, 32);
207#else
208 QImage* qimage = new QImage(width, height, 16);
209#endif
206 210
@@ -211,2 +215,3 @@ QImage* Palm2QImage
211 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { 215 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);
212 217
@@ -233,4 +238,15 @@ QImage* Palm2QImage
233 } else if (((flags & PALM_IS_COMPRESSED_FLAG) && 238 } else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
234 (compression_type == PALM_COMPRESSION_NONE)) || 239 (compression_type == PALM_COMPRESSION_NONE)) ||
235 (flags && PALM_IS_COMPRESSED_FLAG) == 0) { 240 ((flags & PALM_IS_COMPRESSED_FLAG) == 0))
241 {
242 memcpy (rowbuf, palm_ptr, bytes_per_row);
243 palm_ptr += bytes_per_row;
244 }
245 else {
246 qDebug("Case 4");
247 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true");
248 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true");
249 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true");
250 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true");
251 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true");
236 memcpy (rowbuf, palm_ptr, bytes_per_row); 252 memcpy (rowbuf, palm_ptr, bytes_per_row);
@@ -238,3 +254,2 @@ QImage* Palm2QImage
238 } 254 }
239
240 /* next, write it to the GDK bitmap */ 255 /* next, write it to the GDK bitmap */
@@ -259,14 +274,15 @@ QImage* Palm2QImage
259 for (inbyte = rowbuf, j = 0; j < width; ++j) { 274 for (inbyte = rowbuf, j = 0; j < width; ++j) {
260 inval = (inbyte[0] << 8) | inbyte[1]; 275 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
261#if 0 276
262 qDebug ("pixel is %d,%d (%02x:%02x:%02x)", 277/*
278 qDebug ("pixel is %d,%d (%d:%d:%d)",
263 j, i, 279 j, i,
264 (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1), 280 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
265 (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1), 281 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
266 (inval >> 0) & ((1 << palm_blue_bits) - 1)); 282 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
267#endif 283*/
268 QRgb colour = qRgb( 284 QRgb colour = qRgb(
269 (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1), 285 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
270 (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1), 286 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
271 (inval >> 0) & ((1 << palm_blue_bits) - 1)); 287 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
272 qimage->setPixel(j, i, colour); 288 qimage->setPixel(j, i, colour);
@@ -283,8 +299,10 @@ QImage* Palm2QImage
283 299
284QPixmap* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b) 300QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
285{ 301{
286// qDebug("hrule [%d, %d]", w, h); 302//// qDebug("hrule [%d, %d]", w, h);
287 QPixmap* qimage = new QPixmap(w, h); 303 QPixmap* qimage = new QPixmap(w, h);
288 qimage->fill(QColor(r,g,b)); 304 qimage->fill(QColor(r,g,b));
289 return qimage; 305 QImage* ret = new QImage(qimage->convertToImage());
306 delete qimage;
307 return ret;
290} 308}