author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (side-by-side diff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/Palm2QImage.cpp | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/Palm2QImage.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/Palm2QImage.cpp | 134 |
1 files changed, 57 insertions, 77 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,10 +1,3 @@ /* -*- mode: c; indent-tabs-mode: nil; -*- */ - -/* OPIE */ -#include <opie2/odebug.h> - -/* QT */ -#include <qimage.h> - -/* STD */ +#include "useqpe.h" #include <stdio.h> @@ -19,2 +12,3 @@ +#include <qimage.h> @@ -51,6 +45,6 @@ typedef struct { static ColorMapEntry Palm8BitColormap[] = { - { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, - { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, - { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, - { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, + { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, + { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, + { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, + { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, @@ -148,7 +142,5 @@ QImage* Palm2QImage /* 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 @@ -156,3 +148,3 @@ QImage* Palm2QImage 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; @@ -161,3 +153,3 @@ QImage* Palm2QImage (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; @@ -166,3 +158,3 @@ QImage* Palm2QImage /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: - + 1, 2, or 4 bit grayscale @@ -171,6 +163,6 @@ QImage* Palm2QImage 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue - + Each of these can be compressed with one of four compression schemes, "RLE", "Scanline", "PackBits", or none. - + We begin by constructing the colormap. @@ -179,3 +171,3 @@ QImage* Palm2QImage 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; @@ -198,6 +190,5 @@ QImage* Palm2QImage 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; @@ -205,4 +196,3 @@ QImage* Palm2QImage 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; @@ -211,3 +201,3 @@ QImage* Palm2QImage } 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; @@ -226,4 +216,3 @@ QImage* Palm2QImage 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); @@ -232,6 +221,6 @@ QImage* Palm2QImage for (j = 0; j < bytes_per_row; ) { - incount = *palm_ptr++; - inval = *palm_ptr++; - memset(rowbuf + j, inval, incount); - j += incount; + incount = *palm_ptr++; + inval = *palm_ptr++; + memset(rowbuf + j, inval, incount); + j += incount; } @@ -239,10 +228,10 @@ QImage* Palm2QImage for (j = 0; j < bytes_per_row; j += 8) { - incount = *palm_ptr++; - inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; - for (inbit = 0; inbit < inval; inbit += 1) { - if (incount & (1 << (7 - inbit))) - rowbuf[j + inbit] = *palm_ptr++; - else - rowbuf[j + inbit] = lastrow[j + inbit]; - } + incount = *palm_ptr++; + inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; + for (inbit = 0; inbit < inval; inbit += 1) { + if (incount & (1 << (7 - inbit))) + rowbuf[j + inbit] = *palm_ptr++; + else + rowbuf[j + inbit] = lastrow[j + inbit]; + } } @@ -257,8 +246,8 @@ QImage* Palm2QImage 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); @@ -270,14 +259,14 @@ QImage* Palm2QImage for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { - inval = ((*inbyte) & (mask << inbit)) >> inbit; - /* correct for oddity of the 8-bit color Palm pixmap... */ - if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; - /* now lookup the correct color and set the pixel in the GTK bitmap */ - QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); + inval = ((*inbyte) & (mask << inbit)) >> inbit; + /* correct for oddity of the 8-bit color Palm pixmap... */ + if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; + /* now lookup the correct color and set the pixel in the GTK bitmap */ + QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); qimage->setPixel(j, i, colour); - if (!inbit) { - ++inbyte; - inbit = 8 - bits_per_pixel; - } else { - inbit -= bits_per_pixel; - } + if (!inbit) { + ++inbyte; + inbit = 8 - bits_per_pixel; + } else { + inbit -= bits_per_pixel; + } } @@ -286,12 +275,13 @@ QImage* Palm2QImage for (inbyte = rowbuf, j = 0; j < width; ++j) { - inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; + 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), + 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), @@ -299,3 +289,3 @@ QImage* Palm2QImage qimage->setPixel(j, i, colour); - inbyte += 2; + inbyte += 2; } @@ -309,11 +299 @@ QImage* Palm2QImage } - -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; -} |