summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-03-02 19:31:31 (UTC)
committer llornkcor <llornkcor>2003-03-02 19:31:31 (UTC)
commitab5f21907fb482d35f8aebe4505e954d3c22f3c7 (patch) (unidiff)
treec85adac27fa84a25ef49bdb23bf050c43979617d
parent6657040ae54afb2f2378f4db7bfc9e616e6d7b83 (diff)
downloadopie-ab5f21907fb482d35f8aebe4505e954d3c22f3c7.zip
opie-ab5f21907fb482d35f8aebe4505e954d3c22f3c7.tar.gz
opie-ab5f21907fb482d35f8aebe4505e954d3c22f3c7.tar.bz2
patch sneaked by me
Diffstat (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
@@ -2,7 +2,9 @@
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
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>
7#include <sys/stat.h> 9#include <sys/stat.h>
8#include <stdarg.h> 10#include <stdarg.h>
@@ -139,17 +141,16 @@ QImage* Palm2QImage
139 /* bytes 14 and 15 are reserved by Palm and always 0 */ 141 /* bytes 14 and 15 are reserved by Palm and always 0 */
140 142
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
145 146
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;
149 } else if ((compression_type != PALM_COMPRESSION_NONE) && 150 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
150 (compression_type != PALM_COMPRESSION_RLE) && 151 (compression_type != PALM_COMPRESSION_RLE) &&
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;
154 } 155 }
155 156
@@ -167,7 +168,7 @@ QImage* Palm2QImage
167 */ 168 */
168 169
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;
172 } else if (bits_per_pixel == 1) { 173 } else if (bits_per_pixel == 1) {
173 colormap = Palm1BitColormap; 174 colormap = Palm1BitColormap;
@@ -186,29 +187,33 @@ QImage* Palm2QImage
186 palm_red_bits = palmimage[16]; 187 palm_red_bits = palmimage[16];
187 palm_green_bits = palmimage[17]; 188 palm_green_bits = palmimage[17];
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;
193 } 194 }
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;
198 } 198 }
199 imagedatastart = palmimage + 24; 199 imagedatastart = palmimage + 24;
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;
203 } 203 }
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
207 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ 211 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */
208 rowbuf = new unsigned char[bytes_per_row * width]; 212 rowbuf = new unsigned char[bytes_per_row * width];
209 lastrow = new unsigned char[bytes_per_row * width]; 213 lastrow = new unsigned char[bytes_per_row * width];
210 214
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
213 /* first, uncompress the Palm image */ 218 /* first, uncompress the Palm image */
214 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { 219 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
@@ -231,12 +236,22 @@ QImage* Palm2QImage
231 } 236 }
232 memcpy (lastrow, rowbuf, bytes_per_row); 237 memcpy (lastrow, rowbuf, bytes_per_row);
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);
237 palm_ptr += bytes_per_row; 253 palm_ptr += bytes_per_row;
238 } 254 }
239
240 /* next, write it to the GDK bitmap */ 255 /* next, write it to the GDK bitmap */
241 if (colormap) { 256 if (colormap) {
242 mask = (1 << bits_per_pixel) - 1; 257 mask = (1 << bits_per_pixel) - 1;
@@ -257,18 +272,19 @@ QImage* Palm2QImage
257 } else if (!colormap && 272 } else if (!colormap &&
258 bits_per_pixel == 16) { 273 bits_per_pixel == 16) {
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);
273 inbyte += 2; 289 inbyte += 2;
274 } 290 }
@@ -281,10 +297,12 @@ QImage* Palm2QImage
281 return qimage; 297 return qimage;
282} 298}
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}