summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Palm2QImage.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/Palm2QImage.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp64
1 files changed, 22 insertions, 42 deletions
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index b0d4e00..c1b7b7a 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,25 +1,19 @@
1/* -*- mode: c; indent-tabs-mode: nil; -*- */ 1/* -*- mode: c; indent-tabs-mode: nil; -*- */
2 2#include "useqpe.h"
3/* OPIE */
4#include <opie2/odebug.h>
5
6/* QT */
7#include <qimage.h>
8
9/* STD */
10#include <stdio.h> 3#include <stdio.h>
11#include <stdlib.h> 4#include <stdlib.h>
12#include <string.h> 5#include <string.h>
13#ifndef _WINDOWS 6#ifndef _WINDOWS
14#include <unistd.h> /* for link */ 7#include <unistd.h> /* for link */
15#endif 8#endif
16#include <sys/types.h> 9#include <sys/types.h>
17#include <sys/stat.h> 10#include <sys/stat.h>
18#include <stdarg.h> 11#include <stdarg.h>
19 12
13#include <qimage.h>
20 14
21/***********************************************************************/ 15/***********************************************************************/
22/***********************************************************************/ 16/***********************************************************************/
23/***** *****/ 17/***** *****/
24/***** Code to decode the Palm image format to JPEG *****/ 18/***** Code to decode the Palm image format to JPEG *****/
25/***** *****/ 19/***** *****/
@@ -145,24 +139,22 @@ QImage* Palm2QImage
145 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10); 139 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
146 transparent_index = palmimage[12]; 140 transparent_index = palmimage[12];
147 compression_type = palmimage[13]; 141 compression_type = palmimage[13];
148 /* bytes 14 and 15 are reserved by Palm and always 0 */ 142 /* bytes 14 and 15 are reserved by Palm and always 0 */
149 143
150#if 0 144#if 0
151// odebug << "Palm image is " << width << "x" << height 145// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type);
152// << ", " << bits_per_pixel << " bpp, version " << version
153// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
154#endif 146#endif
155 147
156 if (compression_type == PALM_COMPRESSION_PACKBITS) { 148 if (compression_type == PALM_COMPRESSION_PACKBITS) {
157// odebug << "Image uses packbits compression; not yet supported" << oendl; 149// qDebug ("Image uses packbits compression; not yet supported");
158 return NULL; 150 return NULL;
159 } else if ((compression_type != PALM_COMPRESSION_NONE) && 151 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
160 (compression_type != PALM_COMPRESSION_RLE) && 152 (compression_type != PALM_COMPRESSION_RLE) &&
161 (compression_type != PALM_COMPRESSION_SCANLINE)) { 153 (compression_type != PALM_COMPRESSION_SCANLINE)) {
162// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl; 154// qDebug ("Image uses unknown compression, code 0x%x", compression_type);
163 return NULL; 155 return NULL;
164 } 156 }
165 157
166 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 158 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
167 159
168 1, 2, or 4 bit grayscale 160 1, 2, or 4 bit grayscale
@@ -174,13 +166,13 @@ QImage* Palm2QImage
174 "RLE", "Scanline", "PackBits", or none. 166 "RLE", "Scanline", "PackBits", or none.
175 167
176 We begin by constructing the colormap. 168 We begin by constructing the colormap.
177 */ 169 */
178 170
179 if (flags & PALM_HAS_COLORMAP_FLAG) { 171 if (flags & PALM_HAS_COLORMAP_FLAG) {
180// odebug << "Palm images with custom colormaps are not currently supported." << oendl; 172// qDebug("Palm images with custom colormaps are not currently supported.\n");
181 return NULL; 173 return NULL;
182 } else if (bits_per_pixel == 1) { 174 } else if (bits_per_pixel == 1) {
183 colormap = Palm1BitColormap; 175 colormap = Palm1BitColormap;
184 imagedatastart = palmimage + 16; 176 imagedatastart = palmimage + 16;
185 } else if (bits_per_pixel == 2) { 177 } else if (bits_per_pixel == 2) {
186 colormap = Palm2BitColormap; 178 colormap = Palm2BitColormap;
@@ -193,26 +185,24 @@ QImage* Palm2QImage
193 imagedatastart = palmimage + 16; 185 imagedatastart = palmimage + 16;
194 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { 186 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
195 colormap = NULL; 187 colormap = NULL;
196 palm_red_bits = palmimage[16]; 188 palm_red_bits = palmimage[16];
197 palm_green_bits = palmimage[17]; 189 palm_green_bits = palmimage[17];
198 palm_blue_bits = palmimage[18]; 190 palm_blue_bits = palmimage[18];
199// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl; 191// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits);
200 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) {
201// odebug << "Can't handle this format DirectColor image -- too wide in some color (" 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);
202// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
203 return NULL; 194 return NULL;
204 } 195 }
205 if (bits_per_pixel > (8 * sizeof(unsigned long))) { 196 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
206// odebug << "Can't handle this format DirectColor image -- too many bits per pixel (" 197// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel);
207// << bits_per_pixel << ")" << oendl;
208 return NULL; 198 return NULL;
209 } 199 }
210 imagedatastart = palmimage + 24; 200 imagedatastart = palmimage + 24;
211 } else { 201 } else {
212// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl; 202// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
213 return NULL; 203 return NULL;
214 } 204 }
215 205
216#ifndef USEQPE 206#ifndef USEQPE
217 QImage* qimage = new QImage(width, height, 32); 207 QImage* qimage = new QImage(width, height, 32);
218#else 208#else
@@ -221,14 +211,13 @@ QImage* Palm2QImage
221 211
222 /* 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 */
223 rowbuf = new unsigned char[bytes_per_row * width]; 213 rowbuf = new unsigned char[bytes_per_row * width];
224 lastrow = new unsigned char[bytes_per_row * width]; 214 lastrow = new unsigned char[bytes_per_row * width];
225 215
226 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) {
227// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr 217// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row);
228// << " bpr:" << bytes_per_row << oendl;
229 218
230 /* first, uncompress the Palm image */ 219 /* first, uncompress the Palm image */
231 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { 220 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
232 for (j = 0; j < bytes_per_row; ) { 221 for (j = 0; j < bytes_per_row; ) {
233 incount = *palm_ptr++; 222 incount = *palm_ptr++;
234 inval = *palm_ptr++; 223 inval = *palm_ptr++;
@@ -252,18 +241,18 @@ QImage* Palm2QImage
252 ((flags & PALM_IS_COMPRESSED_FLAG) == 0)) 241 ((flags & PALM_IS_COMPRESSED_FLAG) == 0))
253 { 242 {
254 memcpy (rowbuf, palm_ptr, bytes_per_row); 243 memcpy (rowbuf, palm_ptr, bytes_per_row);
255 palm_ptr += bytes_per_row; 244 palm_ptr += bytes_per_row;
256 } 245 }
257 else { 246 else {
258 odebug << "Case 4" << oendl; 247 qDebug("Case 4");
259 odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl; 248 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true");
260 odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl; 249 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true");
261 odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl; 250 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true");
262 odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl; 251 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true");
263 odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl; 252 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true");
264 memcpy (rowbuf, palm_ptr, bytes_per_row); 253 memcpy (rowbuf, palm_ptr, bytes_per_row);
265 palm_ptr += bytes_per_row; 254 palm_ptr += bytes_per_row;
266 } 255 }
267 /* next, write it to the GDK bitmap */ 256 /* next, write it to the GDK bitmap */
268 if (colormap) { 257 if (colormap) {
269 mask = (1 << bits_per_pixel) - 1; 258 mask = (1 << bits_per_pixel) - 1;
@@ -284,16 +273,17 @@ QImage* Palm2QImage
284 } else if (!colormap && 273 } else if (!colormap &&
285 bits_per_pixel == 16) { 274 bits_per_pixel == 16) {
286 for (inbyte = rowbuf, j = 0; j < width; ++j) { 275 for (inbyte = rowbuf, j = 0; j < width; ++j) {
287 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; 276 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
288 277
289/* 278/*
290 odebug << "pixel is " << j << "," << i << " (" 279 qDebug ("pixel is %d,%d (%d:%d:%d)",
291 << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":" 280 j, i,
292 << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":" 281 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
293 << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl; 282 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
283 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
294*/ 284*/
295 QRgb colour = qRgb( 285 QRgb colour = qRgb(
296 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 286 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
297 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 287 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
298 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); 288 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
299 qimage->setPixel(j, i, colour); 289 qimage->setPixel(j, i, colour);
@@ -304,16 +294,6 @@ QImage* Palm2QImage
304 294
305 delete [] rowbuf; 295 delete [] rowbuf;
306 delete [] lastrow; 296 delete [] lastrow;
307 297
308 return qimage; 298 return qimage;
309} 299}
310
311QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
312{
313// odebug << "hrule [" << w << ", " << h << "]" << oendl;
314 QPixmap* qimage = new QPixmap(w, h);
315 qimage->fill(QColor(r,g,b));
316 QImage* ret = new QImage(qimage->convertToImage());
317 delete qimage;
318 return ret;
319}