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.cpp125
1 files changed, 68 insertions, 57 deletions
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
index 9339595..b0d4e00 100644
--- a/noncore/apps/opie-reader/Palm2QImage.cpp
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -1,72 +1,79 @@
1/* -*- mode: c; indent-tabs-mode: nil; -*- */ 1/* -*- mode: c; indent-tabs-mode: nil; -*- */
2
3/* OPIE */
4#include <opie2/odebug.h>
5
6/* QT */
7#include <qimage.h>
8
9/* STD */
2#include <stdio.h> 10#include <stdio.h>
3#include <stdlib.h> 11#include <stdlib.h>
4#include <string.h> 12#include <string.h>
5#ifndef _WINDOWS 13#ifndef _WINDOWS
6#include <unistd.h> /* for link */ 14#include <unistd.h> /* for link */
7#endif 15#endif
8#include <sys/types.h> 16#include <sys/types.h>
9#include <sys/stat.h> 17#include <sys/stat.h>
10#include <stdarg.h> 18#include <stdarg.h>
11 19
12#include <qimage.h>
13 20
14/***********************************************************************/ 21/***********************************************************************/
15/***********************************************************************/ 22/***********************************************************************/
16/***** *****/ 23/***** *****/
17/***** Code to decode the Palm image format to JPEG *****/ 24/***** Code to decode the Palm image format to JPEG *****/
18/***** *****/ 25/***** *****/
19/***********************************************************************/ 26/***********************************************************************/
20/***********************************************************************/ 27/***********************************************************************/
21 28
22#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1])) 29#define READ_BIGENDIAN_SHORT(p) (((p)[0] << 8)|((p)[1]))
23#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3])) 30#define READ_BIGENDIAN_LONG(p) (((p)[0] << 24)|((p)[1] << 16)|((p)[2] << 8)|((p)[3]))
24 31
25#define PALM_IS_COMPRESSED_FLAG 0x8000 32#define PALM_IS_COMPRESSED_FLAG 0x8000
26#define PALM_HAS_COLORMAP_FLAG 0x4000 33#define PALM_HAS_COLORMAP_FLAG 0x4000
27#define PALM_HAS_TRANSPARENCY_FLAG 0x2000 34#define PALM_HAS_TRANSPARENCY_FLAG 0x2000
28#define PALM_DIRECT_COLOR_FLAG 0x0400 35#define PALM_DIRECT_COLOR_FLAG 0x0400
29#define PALM_4_BYTE_FIELD_FLAG 0x0200 36#define PALM_4_BYTE_FIELD_FLAG 0x0200
30 37
31#define PALM_COMPRESSION_SCANLINE 0x00 38#define PALM_COMPRESSION_SCANLINE 0x00
32#define PALM_COMPRESSION_RLE 0x01 39#define PALM_COMPRESSION_RLE 0x01
33#define PALM_COMPRESSION_PACKBITS 0x02 40#define PALM_COMPRESSION_PACKBITS 0x02
34#define PALM_COMPRESSION_NONE 0xFF 41#define PALM_COMPRESSION_NONE 0xFF
35 42
36#define PALM_COLORMAP_SIZE 232 43#define PALM_COLORMAP_SIZE 232
37 44
38typedef struct { 45typedef struct {
39 unsigned char red; 46 unsigned char red;
40 unsigned char green; 47 unsigned char green;
41 unsigned char blue; 48 unsigned char blue;
42} ColorMapEntry; 49} ColorMapEntry;
43 50
44static ColorMapEntry Palm8BitColormap[] = { 51static ColorMapEntry Palm8BitColormap[] = {
45 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 }, 52 { 255, 255, 255 }, { 255, 204, 255 }, { 255, 153, 255 }, { 255, 102, 255 },
46 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 }, 53 { 255, 51, 255 }, { 255, 0, 255 }, { 255, 255, 204 }, { 255, 204, 204 },
47 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 }, 54 { 255, 153, 204 }, { 255, 102, 204 }, { 255, 51, 204 }, { 255, 0, 204 },
48 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 }, 55 { 255, 255, 153 }, { 255, 204, 153 }, { 255, 153, 153 }, { 255, 102, 153 },
49 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 }, 56 { 255, 51, 153 }, { 255, 0, 153 }, { 204, 255, 255 }, { 204, 204, 255 },
50 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 }, 57 { 204, 153, 255 }, { 204, 102, 255 }, { 204, 51, 255 }, { 204, 0, 255 },
51 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 }, 58 { 204, 255, 204 }, { 204, 204, 204 }, { 204, 153, 204 }, { 204, 102, 204 },
52 { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 }, 59 { 204, 51, 204 }, { 204, 0, 204 }, { 204, 255, 153 }, { 204, 204, 153 },
53 { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 }, 60 { 204, 153, 153 }, { 204, 102, 153 }, { 204, 51, 153 }, { 204, 0, 153 },
54 { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 }, 61 { 153, 255, 255 }, { 153, 204, 255 }, { 153, 153, 255 }, { 153, 102, 255 },
55 { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 }, 62 { 153, 51, 255 }, { 153, 0, 255 }, { 153, 255, 204 }, { 153, 204, 204 },
56 { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 }, 63 { 153, 153, 204 }, { 153, 102, 204 }, { 153, 51, 204 }, { 153, 0, 204 },
57 { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 }, 64 { 153, 255, 153 }, { 153, 204, 153 }, { 153, 153, 153 }, { 153, 102, 153 },
58 { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 }, 65 { 153, 51, 153 }, { 153, 0, 153 }, { 102, 255, 255 }, { 102, 204, 255 },
59 { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 }, 66 { 102, 153, 255 }, { 102, 102, 255 }, { 102, 51, 255 }, { 102, 0, 255 },
60 { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 }, 67 { 102, 255, 204 }, { 102, 204, 204 }, { 102, 153, 204 }, { 102, 102, 204 },
61 { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 }, 68 { 102, 51, 204 }, { 102, 0, 204 }, { 102, 255, 153 }, { 102, 204, 153 },
62 { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 }, 69 { 102, 153, 153 }, { 102, 102, 153 }, { 102, 51, 153 }, { 102, 0, 153 },
63 { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 }, 70 { 51, 255, 255 }, { 51, 204, 255 }, { 51, 153, 255 }, { 51, 102, 255 },
64 { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 }, 71 { 51, 51, 255 }, { 51, 0, 255 }, { 51, 255, 204 }, { 51, 204, 204 },
65 { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 }, 72 { 51, 153, 204 }, { 51, 102, 204 }, { 51, 51, 204 }, { 51, 0, 204 },
66 { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 }, 73 { 51, 255, 153 }, { 51, 204, 153 }, { 51, 153, 153 }, { 51, 102, 153 },
67 { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 }, 74 { 51, 51, 153 }, { 51, 0, 153 }, { 0, 255, 255 }, { 0, 204, 255 },
68 { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 }, 75 { 0, 153, 255 }, { 0, 102, 255 }, { 0, 51, 255 }, { 0, 0, 255 },
69 { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 }, 76 { 0, 255, 204 }, { 0, 204, 204 }, { 0, 153, 204 }, { 0, 102, 204 },
70 { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 }, 77 { 0, 51, 204 }, { 0, 0, 204 }, { 0, 255, 153 }, { 0, 204, 153 },
71 { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 }, 78 { 0, 153, 153 }, { 0, 102, 153 }, { 0, 51, 153 }, { 0, 0, 153 },
72 { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 }, 79 { 255, 255, 102 }, { 255, 204, 102 }, { 255, 153, 102 }, { 255, 102, 102 },
@@ -118,191 +125,195 @@ static ColorMapEntry Palm4BitColormap[] = {
118 { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 }, 125 { 119, 119, 119 }, { 102, 102, 102 }, { 85, 85, 85 }, { 68, 68, 68 },
119 { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }}; 126 { 51, 51, 51 }, { 34, 34, 34 }, { 17, 17, 17 }, { 0, 0, 0 }};
120 127
121QImage* Palm2QImage 128QImage* Palm2QImage
122 (unsigned char *image_bytes_in, int byte_count_in) 129 (unsigned char *image_bytes_in, int byte_count_in)
123{ 130{
124 unsigned int width, height, bytes_per_row, flags, next_depth_offset; 131 unsigned int width, height, bytes_per_row, flags, next_depth_offset;
125 unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount; 132 unsigned int bits_per_pixel, version, transparent_index, compression_type, i, j, inval, inbit, mask, incount;
126 unsigned int palm_red_bits, palm_green_bits, palm_blue_bits; 133 unsigned int palm_red_bits, palm_green_bits, palm_blue_bits;
127 unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow, 134 unsigned char *palm_ptr, *x_ptr, *imagedata, *inbyte, *rowbuf, *lastrow,
128 *imagedatastart, *palmimage; 135 *imagedatastart, *palmimage;
129 ColorMapEntry *colormap; 136 ColorMapEntry *colormap;
130 137
131 palmimage = image_bytes_in; 138 palmimage = image_bytes_in;
132 width = READ_BIGENDIAN_SHORT(palmimage + 0); 139 width = READ_BIGENDIAN_SHORT(palmimage + 0);
133 height = READ_BIGENDIAN_SHORT(palmimage + 2); 140 height = READ_BIGENDIAN_SHORT(palmimage + 2);
134 bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4); 141 bytes_per_row = READ_BIGENDIAN_SHORT(palmimage + 4);
135 flags = READ_BIGENDIAN_SHORT(palmimage + 6); 142 flags = READ_BIGENDIAN_SHORT(palmimage + 6);
136 bits_per_pixel = palmimage[8]; 143 bits_per_pixel = palmimage[8];
137 version = palmimage[9]; 144 version = palmimage[9];
138 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10); 145 next_depth_offset = READ_BIGENDIAN_SHORT(palmimage + 10);
139 transparent_index = palmimage[12]; 146 transparent_index = palmimage[12];
140 compression_type = palmimage[13]; 147 compression_type = palmimage[13];
141 /* bytes 14 and 15 are reserved by Palm and always 0 */ 148 /* bytes 14 and 15 are reserved by Palm and always 0 */
142 149
143#if 0 150#if 0
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); 151// odebug << "Palm image is " << width << "x" << height
152// << ", " << bits_per_pixel << " bpp, version " << version
153// << ", flags 0x" << flags << ", compression " << compression_type << oendl;
145#endif 154#endif
146 155
147 if (compression_type == PALM_COMPRESSION_PACKBITS) { 156 if (compression_type == PALM_COMPRESSION_PACKBITS) {
148// qDebug ("Image uses packbits compression; not yet supported"); 157// odebug << "Image uses packbits compression; not yet supported" << oendl;
149 return NULL; 158 return NULL;
150 } else if ((compression_type != PALM_COMPRESSION_NONE) && 159 } else if ((compression_type != PALM_COMPRESSION_NONE) &&
151 (compression_type != PALM_COMPRESSION_RLE) && 160 (compression_type != PALM_COMPRESSION_RLE) &&
152 (compression_type != PALM_COMPRESSION_SCANLINE)) { 161 (compression_type != PALM_COMPRESSION_SCANLINE)) {
153// qDebug ("Image uses unknown compression, code 0x%x", compression_type); 162// odebug << "Image uses unknown compression, code 0x" << compression_type << oendl;
154 return NULL; 163 return NULL;
155 } 164 }
156 165
157 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps: 166 /* as of PalmOS 4.0, there are 6 different kinds of Palm pixmaps:
158 167
159 1, 2, or 4 bit grayscale 168 1, 2, or 4 bit grayscale
160 8-bit StaticColor using the Palm standard colormap 169 8-bit StaticColor using the Palm standard colormap
161 8-bit PseudoColor using a user-specified colormap 170 8-bit PseudoColor using a user-specified colormap
162 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue 171 16-bit DirectColor using 5 bits for red, 6 for green, and 5 for blue
163 172
164 Each of these can be compressed with one of four compression schemes, 173 Each of these can be compressed with one of four compression schemes,
165 "RLE", "Scanline", "PackBits", or none. 174 "RLE", "Scanline", "PackBits", or none.
166 175
167 We begin by constructing the colormap. 176 We begin by constructing the colormap.
168 */ 177 */
169 178
170 if (flags & PALM_HAS_COLORMAP_FLAG) { 179 if (flags & PALM_HAS_COLORMAP_FLAG) {
171// qDebug("Palm images with custom colormaps are not currently supported.\n"); 180// odebug << "Palm images with custom colormaps are not currently supported." << oendl;
172 return NULL; 181 return NULL;
173 } else if (bits_per_pixel == 1) { 182 } else if (bits_per_pixel == 1) {
174 colormap = Palm1BitColormap; 183 colormap = Palm1BitColormap;
175 imagedatastart = palmimage + 16; 184 imagedatastart = palmimage + 16;
176 } else if (bits_per_pixel == 2) { 185 } else if (bits_per_pixel == 2) {
177 colormap = Palm2BitColormap; 186 colormap = Palm2BitColormap;
178 imagedatastart = palmimage + 16; 187 imagedatastart = palmimage + 16;
179 } else if (bits_per_pixel == 4) { 188 } else if (bits_per_pixel == 4) {
180 colormap = Palm4BitColormap; 189 colormap = Palm4BitColormap;
181 imagedatastart = palmimage + 16; 190 imagedatastart = palmimage + 16;
182 } else if (bits_per_pixel == 8) { 191 } else if (bits_per_pixel == 8) {
183 colormap = Palm8BitColormap; 192 colormap = Palm8BitColormap;
184 imagedatastart = palmimage + 16; 193 imagedatastart = palmimage + 16;
185 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) { 194 } else if (bits_per_pixel == 16 && (flags & PALM_DIRECT_COLOR_FLAG)) {
186 colormap = NULL; 195 colormap = NULL;
187 palm_red_bits = palmimage[16]; 196 palm_red_bits = palmimage[16];
188 palm_green_bits = palmimage[17]; 197 palm_green_bits = palmimage[17];
189 palm_blue_bits = palmimage[18]; 198 palm_blue_bits = palmimage[18];
190// qDebug("Bits:%d, %d, %d", palm_red_bits, palm_green_bits, palm_blue_bits); 199// odebug << "Bits:" << palm_red_bits << ", " << palm_green_bits << ", " << palm_blue_bits << oendl;
191 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) { 200 if (palm_blue_bits > 8 || palm_green_bits > 8 || palm_red_bits > 8) {
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); 201// odebug << "Can't handle this format DirectColor image -- too wide in some color ("
202// << palm_red_bits << ":" << palm_green_bits << ":" << palm_blue_bits << oendl;
193 return NULL; 203 return NULL;
194 } 204 }
195 if (bits_per_pixel > (8 * sizeof(unsigned long))) { 205 if (bits_per_pixel > (8 * sizeof(unsigned long))) {
196// qDebug ("Can't handle this format DirectColor image -- too many bits per pixel (%d)\n", bits_per_pixel); 206// odebug << "Can't handle this format DirectColor image -- too many bits per pixel ("
207// << bits_per_pixel << ")" << oendl;
197 return NULL; 208 return NULL;
198 } 209 }
199 imagedatastart = palmimage + 24; 210 imagedatastart = palmimage + 24;
200 } else { 211 } else {
201// qDebug("Unknown bits-per-pixel of %d encountered.\n", bits_per_pixel); 212// odebug << "Unknown bits-per-pixel of " << bits_per_pixel << " encountered" << oendl;
202 return NULL; 213 return NULL;
203 } 214 }
204 215
205#ifndef USEQPE 216#ifndef USEQPE
206 QImage* qimage = new QImage(width, height, 32); 217 QImage* qimage = new QImage(width, height, 32);
207#else 218#else
208 QImage* qimage = new QImage(width, height, 16); 219 QImage* qimage = new QImage(width, height, 16);
209#endif 220#endif
210 221
211 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */ 222 /* row by row, uncompress the Palm image and copy it to the JPEG buffer */
212 rowbuf = new unsigned char[bytes_per_row * width]; 223 rowbuf = new unsigned char[bytes_per_row * width];
213 lastrow = new unsigned char[bytes_per_row * width]; 224 lastrow = new unsigned char[bytes_per_row * width];
214 225
215 for (i=0, palm_ptr = imagedatastart , x_ptr = imagedata; i < height; ++i) { 226 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); 227// odebug << "inval:" << inval << " palm_ptr:" << palm_ptr << " x_ptr:" << x_ptr
228// << " bpr:" << bytes_per_row << oendl;
217 229
218 /* first, uncompress the Palm image */ 230 /* first, uncompress the Palm image */
219 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) { 231 if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_RLE)) {
220 for (j = 0; j < bytes_per_row; ) { 232 for (j = 0; j < bytes_per_row; ) {
221 incount = *palm_ptr++; 233 incount = *palm_ptr++;
222 inval = *palm_ptr++; 234 inval = *palm_ptr++;
223 memset(rowbuf + j, inval, incount); 235 memset(rowbuf + j, inval, incount);
224 j += incount; 236 j += incount;
225 } 237 }
226 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) { 238 } else if ((flags & PALM_IS_COMPRESSED_FLAG) && (compression_type == PALM_COMPRESSION_SCANLINE)) {
227 for (j = 0; j < bytes_per_row; j += 8) { 239 for (j = 0; j < bytes_per_row; j += 8) {
228 incount = *palm_ptr++; 240 incount = *palm_ptr++;
229 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8; 241 inval = ((bytes_per_row - j) < 8) ? (bytes_per_row - j) : 8;
230 for (inbit = 0; inbit < inval; inbit += 1) { 242 for (inbit = 0; inbit < inval; inbit += 1) {
231 if (incount & (1 << (7 - inbit))) 243 if (incount & (1 << (7 - inbit)))
232 rowbuf[j + inbit] = *palm_ptr++; 244 rowbuf[j + inbit] = *palm_ptr++;
233 else 245 else
234 rowbuf[j + inbit] = lastrow[j + inbit]; 246 rowbuf[j + inbit] = lastrow[j + inbit];
235 } 247 }
236 } 248 }
237 memcpy (lastrow, rowbuf, bytes_per_row); 249 memcpy (lastrow, rowbuf, bytes_per_row);
238 } else if (((flags & PALM_IS_COMPRESSED_FLAG) && 250 } else if (((flags & PALM_IS_COMPRESSED_FLAG) &&
239 (compression_type == PALM_COMPRESSION_NONE)) || 251 (compression_type == PALM_COMPRESSION_NONE)) ||
240 ((flags & PALM_IS_COMPRESSED_FLAG) == 0)) 252 ((flags & PALM_IS_COMPRESSED_FLAG) == 0))
241 { 253 {
242 memcpy (rowbuf, palm_ptr, bytes_per_row); 254 memcpy (rowbuf, palm_ptr, bytes_per_row);
243 palm_ptr += bytes_per_row; 255 palm_ptr += bytes_per_row;
244 } 256 }
245 else { 257 else {
246 qDebug("Case 4"); 258 odebug << "Case 4" << oendl;
247 qDebug("Is compressed:%s", ((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true"); 259 odebug << "Is compressed:" << (((flags & PALM_IS_COMPRESSED_FLAG) == 0) ? "false" : "true") << oendl;
248 qDebug("Has colourmap:%s", ((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true"); 260 odebug << "Has colourmap:" << (((flags & PALM_HAS_COLORMAP_FLAG) == 0) ? "false" : "true") << oendl;
249 qDebug("Has transparency:%s", ((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true"); 261 odebug << "Has transparency:" << (((flags & PALM_HAS_TRANSPARENCY_FLAG) == 0) ? "false" : "true") << oendl;
250 qDebug("Direct colour:%s", ((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true"); 262 odebug << "Direct colour:" << (((flags & PALM_DIRECT_COLOR_FLAG) == 0) ? "false" : "true") << oendl;
251 qDebug("four byte field:%s", ((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true"); 263 odebug << "four byte field:" << (((flags & PALM_4_BYTE_FIELD_FLAG) == 0) ? "false" : "true") << oendl;
252 memcpy (rowbuf, palm_ptr, bytes_per_row); 264 memcpy (rowbuf, palm_ptr, bytes_per_row);
253 palm_ptr += bytes_per_row; 265 palm_ptr += bytes_per_row;
254 } 266 }
255 /* next, write it to the GDK bitmap */ 267 /* next, write it to the GDK bitmap */
256 if (colormap) { 268 if (colormap) {
257 mask = (1 << bits_per_pixel) - 1; 269 mask = (1 << bits_per_pixel) - 1;
258 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) { 270 for (inbit = 8 - bits_per_pixel, inbyte = rowbuf, j = 0; j < width; ++j) {
259 inval = ((*inbyte) & (mask << inbit)) >> inbit; 271 inval = ((*inbyte) & (mask << inbit)) >> inbit;
260 /* correct for oddity of the 8-bit color Palm pixmap... */ 272 /* correct for oddity of the 8-bit color Palm pixmap... */
261 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231; 273 if ((bits_per_pixel == 8) && (inval == 0xFF)) inval = 231;
262 /* now lookup the correct color and set the pixel in the GTK bitmap */ 274 /* now lookup the correct color and set the pixel in the GTK bitmap */
263 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue); 275 QRgb colour = qRgb(colormap[inval].red, colormap[inval].green, colormap[inval].blue);
264 qimage->setPixel(j, i, colour); 276 qimage->setPixel(j, i, colour);
265 if (!inbit) { 277 if (!inbit) {
266 ++inbyte; 278 ++inbyte;
267 inbit = 8 - bits_per_pixel; 279 inbit = 8 - bits_per_pixel;
268 } else { 280 } else {
269 inbit -= bits_per_pixel; 281 inbit -= bits_per_pixel;
270 } 282 }
271 } 283 }
272 } else if (!colormap && 284 } else if (!colormap &&
273 bits_per_pixel == 16) { 285 bits_per_pixel == 16) {
274 for (inbyte = rowbuf, j = 0; j < width; ++j) { 286 for (inbyte = rowbuf, j = 0; j < width; ++j) {
275 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1]; 287 inval = ((unsigned short)inbyte[0] << (unsigned short)8) | inbyte[1];
276 288
277/* 289/*
278 qDebug ("pixel is %d,%d (%d:%d:%d)", 290 odebug << "pixel is " << j << "," << i << " ("
279 j, i, 291 << (((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits)) << ":"
280 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 292 << (((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits)) << ":"
281 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 293 << (((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)) << ")" << oendl;
282 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
283*/ 294*/
284 QRgb colour = qRgb( 295 QRgb colour = qRgb(
285 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits), 296 ((inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1)) << (8-palm_red_bits),
286 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits), 297 ((inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1)) << (8-palm_green_bits),
287 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits)); 298 ((inval >> 0) & ((1 << palm_blue_bits) - 1)) << (8-palm_blue_bits));
288 qimage->setPixel(j, i, colour); 299 qimage->setPixel(j, i, colour);
289 inbyte += 2; 300 inbyte += 2;
290 } 301 }
291 } 302 }
292 } 303 }
293 304
294 delete [] rowbuf; 305 delete [] rowbuf;
295 delete [] lastrow; 306 delete [] lastrow;
296 307
297 return qimage; 308 return qimage;
298} 309}
299 310
300QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b) 311QImage* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
301{ 312{
302//// qDebug("hrule [%d, %d]", w, h); 313// odebug << "hrule [" << w << ", " << h << "]" << oendl;
303 QPixmap* qimage = new QPixmap(w, h); 314 QPixmap* qimage = new QPixmap(w, h);
304 qimage->fill(QColor(r,g,b)); 315 qimage->fill(QColor(r,g,b));
305 QImage* ret = new QImage(qimage->convertToImage()); 316 QImage* ret = new QImage(qimage->convertToImage());
306 delete qimage; 317 delete qimage;
307 return ret; 318 return ret;
308} 319}