summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Palm2QImage.cpp
Side-by-side diff
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 @@
/* -*- mode: c; indent-tabs-mode: nil; -*- */
-
-/* OPIE */
-#include <opie2/odebug.h>
-
-/* QT */
-#include <qimage.h>
-
-/* STD */
+#include "useqpe.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _WINDOWS
#include <unistd.h> /* for link */
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
+#include <qimage.h>
/***********************************************************************/
/***********************************************************************/
/***** *****/
/***** Code to decode the Palm image format to JPEG *****/
/***** *****/
@@ -145,24 +139,22 @@ QImage* Palm2QImage
next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
transparent_index = palmimage[12];
compression_type = palmimage[13];
/* bytes 14 and 15 are reserved by Palm and always 0 */
#if 0
-// odebug << "Palm image is " << width << "x" << height
-// << ", " << bits_per_pixel << " bpp, version " << version
-// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
+// qDebug ("Palm image is %dx%d, %d bpp, version %d, flags 0x%x, compression %d", width, height, bits_per_pixel, version, flags, compression_type);
#endif
if (compression_type == PALM_COMPRESSION_PACKBITS) {
-// odebug << "Image uses packbits compression; not yet supported" << oendl;
+// qDebug ("Image uses packbits compression; not yet supported");
return NULL;
} else if ((compression_type != PALM_COMPRESSION_NONE) &&
(compression_type != PALM_COMPRESSION_RLE) &&
(compression_type != PALM_COMPRESSION_SCANLINE)) {
-// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl;
+// qDebug ("Image uses unknown compression, code 0x%x", compression_type);
return NULL;
}
/* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
1, 2, or 4 bit grayscale
@@ -174,13 +166,13 @@ QImage* Palm2QImage
"RLE", "Scanline", "PackBits", or none.
We begin by constructing the colormap.
*/
if (flags & PALM_HAS_COLORMAP_FLAG) {
-// odebug << "Palm images with custom colormaps are not currently supported." << oendl;
+// qDebug("Palm images with custom colormaps are not currently supported.\n");
return NULL;
} else if (bits_per_pixel == 1) {
colormap = Palm1BitColormap;
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 2) {
colormap = Palm2BitColormap;
@@ -193,26 +185,24 @@ QImage* Palm2QImage
imagedatastart = palmimage + 16;
} else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
colormap = NULL;
palm_red_bits = palmimage[16];
palm_green_bits = palmimage[17];
palm_blue_bits = palmimage[18];
-// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl;
+// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits);
if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
-// odebug << "Can't handle this format DirectColor image -- too wide in some color ("
-// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
+// 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);
return NULL;
}
if (bits_per_pixel > (8 * sizeof(unsigned long))) {
-// odebug << "Can't handle this format DirectColor image -- too many bits per pixel ("
-// << bits_per_pixel << ")" << oendl;
+// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel);
return NULL;
}
imagedatastart = palmimage + 24;
} else {
-// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl;
+// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel);
return NULL;
}
#ifndef USEQPE
QImage* qimage = new QImage(width, height, 32);
#else
@@ -221,14 +211,13 @@ QImage* Palm2QImage
/* row by row, uncompress the Palm image and copy it to the JPEG buffer */
rowbuf = new unsigned char[bytes_per_row * width];
lastrow = new unsigned char[bytes_per_row * width];
for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) {
-// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr
-// << " bpr:" << bytes_per_row << oendl;
+// qDebug("inval:%x palm_ptr:%x x_ptr:%x bpr:%x", inval, palm_ptr, x_ptr, bytes_per_row);
/* first, uncompress the Palm image */
if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
for (j = 0; j < bytes_per_row; ) {
incount = *palm_ptr++;
inval = *palm_ptr++;
@@ -252,18 +241,18 @@ QImage* Palm2QImage
((flags & PALM_IS_COMPRESSED_FLAG) == 0))
{
memcpy (rowbuf, palm_ptr, bytes_per_row);
palm_ptr += bytes_per_row;
}
else {
- odebug << "Case 4" << oendl;
- odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl;
- odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl;
- odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl;
- odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl;
- odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl;
+ qDebug("Case 4");
+ qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true");
+ qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true");
+ qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true");
+ qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true");
+ qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true");
memcpy (rowbuf, palm_ptr, bytes_per_row);
palm_ptr += bytes_per_row;
}
/* next, write it to the GDK bitmap */
if (colormap) {
mask = (1 << bits_per_pixel) - 1;
@@ -284,16 +273,17 @@ QImage* Palm2QImage
} else if (!colormap &&
bits_per_pixel == 16) {
for (inbyte = rowbuf, j = 0; j < width; ++j) {
inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
/*
- odebug << "pixel is " << j << "," << i << " ("
- << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":"
- << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":"
- << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl;
+ qDebug ("pixel is %d,%d (%d:%d:%d)",
+ j, i,
+ ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
+ ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
+ ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
*/
QRgb colour = qRgb(
((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
qimage->setPixel(j, i, colour);
@@ -304,16 +294,6 @@ QImage* Palm2QImage
delete [] rowbuf;
delete [] lastrow;
return qimage;
}
-
-QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
-{
-// odebug << "hrule [" << w << ", " << h << "]" << oendl;
- QPixmap* qimage = new QPixmap(w, h);
- qimage->fill(QColor(r,g,b));
- QImage* ret = new QImage(qimage->convertToImage());
- delete qimage;
- return ret;
-}