| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
#include "bltInt.h" |
| 51 |
|
| 52 |
#ifndef NO_BITMAP |
| 53 |
#include "bltHash.h" |
| 54 |
#include <X11/Xutil.h> |
| 55 |
|
| 56 |
#define BITMAP_THREAD_KEY "BLT Bitmap Data" |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
typedef struct { |
| 68 |
Blt_HashTable bitmapTable; |
| 69 |
|
| 70 |
Tcl_Interp *interp; |
| 71 |
Display *display; |
| 72 |
Tk_Window tkwin; |
| 73 |
} BitmapInterpData; |
| 74 |
|
| 75 |
#define MAX_SIZE 255 |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
typedef struct { |
| 81 |
double rotate; |
| 82 |
double scale; |
| 83 |
Tk_Font font; |
| 84 |
Tk_Justify justify; |
| 85 |
Blt_Pad padX, padY; |
| 86 |
} BitmapInfo; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
typedef struct { |
| 92 |
int width, height; |
| 93 |
unsigned char *bits; |
| 94 |
int arraySize; |
| 95 |
} BitmapData; |
| 96 |
|
| 97 |
#define DEF_BITMAP_FONT STD_FONT |
| 98 |
#define DEF_BITMAP_PAD "4" |
| 99 |
#define DEF_BITMAP_ROTATE "0.0" |
| 100 |
#define DEF_BITMAP_SCALE "1.0" |
| 101 |
#define DEF_BITMAP_JUSTIFY "center" |
| 102 |
|
| 103 |
#define ROTATE_0 0 |
| 104 |
#define ROTATE_90 1 |
| 105 |
#define ROTATE_180 2 |
| 106 |
#define ROTATE_270 3 |
| 107 |
|
| 108 |
|
| 109 |
extern Tk_CustomOption bltPadOption; |
| 110 |
|
| 111 |
static Tk_ConfigSpec composeConfigSpecs[] = |
| 112 |
{ |
| 113 |
{TK_CONFIG_FONT, "-font", (char *)NULL, (char *)NULL, |
| 114 |
DEF_BITMAP_FONT, Tk_Offset(BitmapInfo, font), 0}, |
| 115 |
{TK_CONFIG_JUSTIFY, "-justify", (char *)NULL, (char *)NULL, |
| 116 |
DEF_BITMAP_JUSTIFY, Tk_Offset(BitmapInfo, justify), |
| 117 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 118 |
{TK_CONFIG_CUSTOM, "-padx", (char *)NULL, (char *)NULL, |
| 119 |
DEF_BITMAP_PAD, Tk_Offset(BitmapInfo, padX), |
| 120 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption}, |
| 121 |
{TK_CONFIG_CUSTOM, "-pady", (char *)NULL, (char *)NULL, |
| 122 |
DEF_BITMAP_PAD, Tk_Offset(BitmapInfo, padY), |
| 123 |
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption}, |
| 124 |
{TK_CONFIG_DOUBLE, "-rotate", (char *)NULL, (char *)NULL, |
| 125 |
DEF_BITMAP_ROTATE, Tk_Offset(BitmapInfo, rotate), |
| 126 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 127 |
{TK_CONFIG_DOUBLE, "-scale", (char *)NULL, (char *)NULL, |
| 128 |
DEF_BITMAP_SCALE, Tk_Offset(BitmapInfo, scale), |
| 129 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 130 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 131 |
(char *)NULL, 0, 0} |
| 132 |
}; |
| 133 |
|
| 134 |
static Tk_ConfigSpec defineConfigSpecs[] = |
| 135 |
{ |
| 136 |
{TK_CONFIG_DOUBLE, "-rotate", (char *)NULL, (char *)NULL, |
| 137 |
DEF_BITMAP_ROTATE, Tk_Offset(BitmapInfo, rotate), |
| 138 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 139 |
{TK_CONFIG_DOUBLE, "-scale", (char *)NULL, (char *)NULL, |
| 140 |
DEF_BITMAP_SCALE, Tk_Offset(BitmapInfo, scale), |
| 141 |
TK_CONFIG_DONT_SET_DEFAULT}, |
| 142 |
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL, |
| 143 |
(char *)NULL, 0, 0} |
| 144 |
}; |
| 145 |
|
| 146 |
|
| 147 |
static char hexTable[256]; |
| 148 |
static int initialized = 0; |
| 149 |
|
| 150 |
#define blt_width 40 |
| 151 |
#define blt_height 40 |
| 152 |
static unsigned char blt_bits[] = |
| 153 |
{ |
| 154 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x04, |
| 155 |
0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x02, 0x00, 0xe4, 0x33, 0x3f, |
| 156 |
0x01, 0x00, 0x64, 0x36, 0x0c, 0x01, 0x00, 0x64, 0x36, 0x8c, 0x00, 0x00, |
| 157 |
0xe4, 0x33, 0x8c, 0x00, 0x00, 0x64, 0x36, 0x8c, 0x00, 0x00, 0x64, 0x36, |
| 158 |
0x0c, 0x01, 0x00, 0xe4, 0xf3, 0x0d, 0x01, 0x00, 0x04, 0x00, 0x00, 0x02, |
| 159 |
0x00, 0x04, 0x00, 0x00, 0x02, 0x00, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x0c, |
| 160 |
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xf8, 0xff, |
| 161 |
0x03, 0x80, 0xed, 0x07, 0x00, 0x04, 0xe0, 0x0c, 0x00, 0x20, 0x09, 0x10, |
| 162 |
0x0c, 0x00, 0x00, 0x12, 0x10, 0x0c, 0x00, 0x00, 0x10, 0x30, 0x00, 0x00, |
| 163 |
0x00, 0x19, 0xd0, 0x03, 0x00, 0x00, 0x14, 0xb0, 0xfe, 0xff, 0xff, 0x1b, |
| 164 |
0x50, 0x55, 0x55, 0x55, 0x0d, 0xe8, 0xaa, 0xaa, 0xaa, 0x16, 0xe4, 0xff, |
| 165 |
0xff, 0xff, 0x2f, 0xf4, 0xff, 0xff, 0xff, 0x27, 0xd8, 0xae, 0xaa, 0xbd, |
| 166 |
0x2d, 0x6c, 0x5f, 0xd5, 0x67, 0x1b, 0xbc, 0xf3, 0x7f, 0xd0, 0x36, 0xf8, |
| 167 |
0x01, 0x10, 0xcc, 0x1f, 0xe0, 0x45, 0x8e, 0x92, 0x0f, 0xb0, 0x32, 0x41, |
| 168 |
0x43, 0x0b, 0xd0, 0xcf, 0x3c, 0x7c, 0x0d, 0xb0, 0xaa, 0xc2, 0xab, 0x0a, |
| 169 |
0x60, 0x55, 0x55, 0x55, 0x05, 0xc0, 0xff, 0xab, 0xaa, 0x03, 0x00, 0x00, |
| 170 |
0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 171 |
}; |
| 172 |
|
| 173 |
#define bigblt_width 64 |
| 174 |
#define bigblt_height 64 |
| 175 |
static unsigned char bigblt_bits[] = |
| 176 |
{ |
| 177 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 178 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x3f, 0x00, |
| 179 |
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 180 |
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, |
| 181 |
0x00, 0x00, 0xe2, 0x0f, 0xc7, 0xff, 0x10, 0x00, 0x00, 0x00, 0xe2, 0x1f, |
| 182 |
0xc7, 0xff, 0x10, 0x00, 0x00, 0x00, 0xe2, 0x38, 0x07, 0x1c, 0x08, 0x00, |
| 183 |
0x00, 0x00, 0xe2, 0x38, 0x07, 0x1c, 0x08, 0x00, 0x00, 0x00, 0xe2, 0x38, |
| 184 |
0x07, 0x1c, 0x08, 0x00, 0x00, 0x00, 0xe2, 0x1f, 0x07, 0x1c, 0x04, 0x00, |
| 185 |
0x00, 0x00, 0xe2, 0x1f, 0x07, 0x1c, 0x04, 0x00, 0x00, 0x00, 0xe2, 0x38, |
| 186 |
0x07, 0x1c, 0x08, 0x00, 0x00, 0x00, 0xe2, 0x38, 0x07, 0x1c, 0x08, 0x00, |
| 187 |
0x00, 0x00, 0xe2, 0x38, 0x07, 0x1c, 0x08, 0x00, 0x00, 0x00, 0xe2, 0x1f, |
| 188 |
0xff, 0x1c, 0x10, 0x00, 0x00, 0x00, 0xe2, 0x0f, 0xff, 0x1c, 0x10, 0x00, |
| 189 |
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, |
| 190 |
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, |
| 191 |
0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x06, 0x00, |
| 192 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 193 |
0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, |
| 194 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xc0, 0xff, 0xff, 0x07, 0x00, |
| 195 |
0x00, 0xe0, 0xf6, 0x3f, 0x00, 0x00, 0x38, 0x00, 0x00, 0x1c, 0x06, 0x00, |
| 196 |
0x00, 0x00, 0xc0, 0x00, 0x80, 0x03, 0x06, 0x00, 0x00, 0xc0, 0x08, 0x03, |
| 197 |
0x40, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x06, 0x00, |
| 198 |
0x00, 0x00, 0x40, 0x04, 0x40, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, |
| 199 |
0x40, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x04, 0xc0, 0x00, 0x00, 0x00, |
| 200 |
0x00, 0x00, 0x0c, 0x06, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, |
| 201 |
0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x06, 0x40, 0x55, 0xff, 0xff, |
| 202 |
0xff, 0xff, 0x7f, 0x05, 0x80, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x06, |
| 203 |
0x80, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x03, 0x40, 0xab, 0xaa, 0xaa, |
| 204 |
0xaa, 0xaa, 0xaa, 0x01, 0x70, 0x57, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x04, |
| 205 |
0x28, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0b, 0xd8, 0xff, 0xff, 0xff, |
| 206 |
0xff, 0xff, 0xff, 0x14, 0xd0, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0x13, |
| 207 |
0xf0, 0xda, 0xbf, 0xaa, 0xba, 0xfd, 0xd6, 0x0b, 0x70, 0xed, 0x77, 0x55, |
| 208 |
0x57, 0xe5, 0xad, 0x07, 0xb8, 0xf7, 0xab, 0xaa, 0xaa, 0xd2, 0x5b, 0x0f, |
| 209 |
0xf8, 0xfb, 0x54, 0x55, 0x75, 0x94, 0xf7, 0x1e, 0xf0, 0x7b, 0xfa, 0xff, |
| 210 |
0x9f, 0xa9, 0xef, 0x1f, 0xc0, 0xbf, 0x00, 0x20, 0x40, 0x54, 0xfe, 0x0f, |
| 211 |
0x00, 0x1f, 0x92, 0x00, 0x04, 0xa9, 0xfc, 0x01, 0xc0, 0x5f, 0x41, 0xf9, |
| 212 |
0x04, 0x21, 0xfd, 0x00, 0xc0, 0x9b, 0x28, 0x04, 0xd8, 0x0a, 0x9a, 0x03, |
| 213 |
0x40, 0x5d, 0x08, 0x40, 0x44, 0x44, 0x62, 0x03, 0xc0, 0xaa, 0x67, 0xe2, |
| 214 |
0x03, 0x64, 0xba, 0x02, 0x40, 0x55, 0xd5, 0x55, 0xfd, 0xdb, 0x55, 0x03, |
| 215 |
0x80, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x01, 0x00, 0x57, 0x55, 0x55, |
| 216 |
0x55, 0x55, 0xd5, 0x00, 0x00, 0xac, 0xaa, 0xaa, 0xaa, 0xaa, 0x2a, 0x00, |
| 217 |
0x00, 0xf0, 0xff, 0x57, 0x55, 0x55, 0x1d, 0x00, 0x00, 0x00, 0x00, 0xf8, |
| 218 |
0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 219 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 220 |
}; |
| 221 |
|
| 222 |
static Tcl_CmdProc BitmapCmd; |
| 223 |
static Tcl_InterpDeleteProc BitmapInterpDeleteProc; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
static int |
| 244 |
GetHexValue(interp, string, valuePtr) |
| 245 |
Tcl_Interp *interp; |
| 246 |
char *string; |
| 247 |
int *valuePtr; |
| 248 |
{ |
| 249 |
register int c; |
| 250 |
register char *s; |
| 251 |
register int value; |
| 252 |
|
| 253 |
s = string; |
| 254 |
if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) { |
| 255 |
s += 2; |
| 256 |
} |
| 257 |
if (s[0] == '\0') { |
| 258 |
Tcl_AppendResult(interp, "expecting hex value: got \"", string, "\"", |
| 259 |
(char *)NULL); |
| 260 |
return TCL_ERROR; |
| 261 |
} |
| 262 |
value = 0; |
| 263 |
for ( ; *s != '\0'; s++) { |
| 264 |
|
| 265 |
c = *s & 0xff; |
| 266 |
if (!isxdigit(c)) { |
| 267 |
Tcl_AppendResult(interp, "expecting hex value: got \"", string, |
| 268 |
"\"", (char *)NULL); |
| 269 |
return TCL_ERROR; |
| 270 |
} |
| 271 |
value = (value << 4) + hexTable[c]; |
| 272 |
} |
| 273 |
*valuePtr = value; |
| 274 |
return TCL_OK; |
| 275 |
} |
| 276 |
|
| 277 |
#ifdef WIN32 |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
static int |
| 295 |
BitmapToData( |
| 296 |
Tk_Window tkwin, |
| 297 |
Pixmap bitmap, |
| 298 |
int width, int height, |
| 299 |
unsigned char **bitsPtr) |
| 300 |
{ |
| 301 |
int value, bitMask; |
| 302 |
unsigned long pixel; |
| 303 |
register int x, y; |
| 304 |
int count; |
| 305 |
int arraySize, bytes_per_line; |
| 306 |
unsigned char *bits; |
| 307 |
unsigned char *srcPtr, *srcBits; |
| 308 |
int bytesPerRow; |
| 309 |
|
| 310 |
*bitsPtr = NULL; |
| 311 |
srcBits = Blt_GetBitmapData(Tk_Display(tkwin), bitmap, width, height, |
| 312 |
&bytesPerRow); |
| 313 |
if (srcBits == NULL) { |
| 314 |
OutputDebugString("BitmapToData: Can't get bitmap data"); |
| 315 |
return 0; |
| 316 |
} |
| 317 |
bytes_per_line = (width + 7) / 8; |
| 318 |
arraySize = height * bytes_per_line; |
| 319 |
bits = Blt_Malloc(sizeof(unsigned char) * arraySize); |
| 320 |
assert(bits); |
| 321 |
count = 0; |
| 322 |
for (y = height - 1; y >= 0; y--) { |
| 323 |
srcPtr = srcBits + (bytesPerRow * y); |
| 324 |
value = 0, bitMask = 1; |
| 325 |
for (x = 0; x < width; ) { |
| 326 |
pixel = (*srcPtr & (0x80 >> (x % 8))); |
| 327 |
if (pixel) { |
| 328 |
value |= bitMask; |
| 329 |
} |
| 330 |
bitMask <<= 1; |
| 331 |
x++; |
| 332 |
if (!(x & 7)) { |
| 333 |
bits[count++] = (unsigned char)value; |
| 334 |
value = 0, bitMask = 1; |
| 335 |
srcPtr++; |
| 336 |
} |
| 337 |
} |
| 338 |
if (x & 7) { |
| 339 |
bits[count++] = (unsigned char)value; |
| 340 |
} |
| 341 |
} |
| 342 |
*bitsPtr = bits; |
| 343 |
return count; |
| 344 |
} |
| 345 |
|
| 346 |
#else |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
static int |
| 365 |
BitmapToData(tkwin, bitmap, width, height, bitsPtr) |
| 366 |
Tk_Window tkwin; |
| 367 |
Pixmap bitmap; |
| 368 |
int width, height; |
| 369 |
unsigned char **bitsPtr; |
| 370 |
{ |
| 371 |
int value, bitMask; |
| 372 |
unsigned long pixel; |
| 373 |
register int x, y; |
| 374 |
int count; |
| 375 |
int arraySize, bytes_per_line; |
| 376 |
Display *display; |
| 377 |
XImage *imagePtr; |
| 378 |
unsigned char *bits; |
| 379 |
|
| 380 |
display = Tk_Display(tkwin); |
| 381 |
|
| 382 |
imagePtr = XGetImage(display, bitmap, 0, 0, width, height, 1L, XYPixmap); |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
bytes_per_line = (width + 7) / 8; |
| 387 |
arraySize = height * bytes_per_line; |
| 388 |
bits = Blt_Malloc(sizeof(unsigned char) * arraySize); |
| 389 |
assert(bits); |
| 390 |
count = 0; |
| 391 |
for (y = 0; y < height; y++) { |
| 392 |
value = 0, bitMask = 1; |
| 393 |
for (x = 0; x < width; ) { |
| 394 |
pixel = XGetPixel(imagePtr, x, y); |
| 395 |
if (pixel) { |
| 396 |
value |= bitMask; |
| 397 |
} |
| 398 |
bitMask <<= 1; |
| 399 |
x++; |
| 400 |
if (!(x & 7)) { |
| 401 |
bits[count++] = (unsigned char)value; |
| 402 |
value = 0, bitMask = 1; |
| 403 |
} |
| 404 |
} |
| 405 |
if (x & 7) { |
| 406 |
bits[count++] = (unsigned char)value; |
| 407 |
} |
| 408 |
} |
| 409 |
XDestroyImage(imagePtr); |
| 410 |
*bitsPtr = bits; |
| 411 |
return count; |
| 412 |
} |
| 413 |
|
| 414 |
#endif |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
static int |
| 433 |
AsciiToData(interp, elemList, width, height, bitsPtr) |
| 434 |
Tcl_Interp *interp; |
| 435 |
char *elemList; |
| 436 |
|
| 437 |
int width, height; |
| 438 |
unsigned char **bitsPtr; |
| 439 |
{ |
| 440 |
int arraySize; |
| 441 |
int value; |
| 442 |
int padding; |
| 443 |
int bytesPerLine; |
| 444 |
unsigned char *bits; |
| 445 |
register int count; |
| 446 |
enum Formats { |
| 447 |
V10, V11 |
| 448 |
} format; |
| 449 |
register int i; |
| 450 |
char **valueArr; |
| 451 |
int nValues; |
| 452 |
|
| 453 |
|
| 454 |
if (!initialized) { |
| 455 |
Blt_InitHexTable(hexTable); |
| 456 |
initialized = 1; |
| 457 |
} |
| 458 |
if (Tcl_SplitList(interp, elemList, &nValues, &valueArr) != TCL_OK) { |
| 459 |
return -1; |
| 460 |
} |
| 461 |
bytesPerLine = (width + 7) / 8; |
| 462 |
arraySize = bytesPerLine * height; |
| 463 |
if (nValues == arraySize) { |
| 464 |
format = V11; |
| 465 |
} else if (nValues == (arraySize / 2)) { |
| 466 |
format = V10; |
| 467 |
} else { |
| 468 |
Tcl_AppendResult(interp, "bitmap has wrong # of data values", |
| 469 |
(char *)NULL); |
| 470 |
goto error; |
| 471 |
} |
| 472 |
padding = 0; |
| 473 |
if (format == V10) { |
| 474 |
padding = ((width % 16) && ((width % 16) < 9)); |
| 475 |
if (padding) { |
| 476 |
bytesPerLine = (width + 7) / 8 + padding; |
| 477 |
arraySize = bytesPerLine * height; |
| 478 |
} |
| 479 |
} |
| 480 |
bits = Blt_Calloc(sizeof(unsigned char), arraySize); |
| 481 |
if (bits == NULL) { |
| 482 |
Tcl_AppendResult(interp, "can't allocate memory for bitmap", |
| 483 |
(char *)NULL); |
| 484 |
goto error; |
| 485 |
} |
| 486 |
count = 0; |
| 487 |
for (i = 0; i < nValues; i++) { |
| 488 |
if (GetHexValue(interp, valueArr[i], &value) != TCL_OK) { |
| 489 |
Blt_Free(bits); |
| 490 |
goto error; |
| 491 |
} |
| 492 |
bits[count++] = (unsigned char)value; |
| 493 |
if (format == V10) { |
| 494 |
if ((!padding) || (((i * 2) + 2) % bytesPerLine)) { |
| 495 |
bits[count++] = value >> 8; |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
Blt_Free(valueArr); |
| 500 |
*bitsPtr = bits; |
| 501 |
return count; |
| 502 |
error: |
| 503 |
Blt_Free(valueArr); |
| 504 |
return -1; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
static int |
| 509 |
ParseListData(interp, string, widthPtr, heightPtr, bitsPtr) |
| 510 |
Tcl_Interp *interp; |
| 511 |
char *string; |
| 512 |
int *widthPtr; |
| 513 |
int *heightPtr; |
| 514 |
unsigned char **bitsPtr; |
| 515 |
{ |
| 516 |
register char *p; |
| 517 |
char **elemArr; |
| 518 |
int nElem; |
| 519 |
int width, height; |
| 520 |
int result; |
| 521 |
int arraySize; |
| 522 |
|
| 523 |
arraySize = -1; |
| 524 |
if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) { |
| 525 |
return -1; |
| 526 |
} |
| 527 |
if (nElem == 2) { |
| 528 |
char **dimArr; |
| 529 |
int nDim; |
| 530 |
|
| 531 |
if (Tcl_SplitList(interp, elemArr[0], &nDim, &dimArr) != TCL_OK) { |
| 532 |
goto error; |
| 533 |
} |
| 534 |
if (nDim != 2) { |
| 535 |
Tcl_AppendResult(interp, "wrong # of bitmap dimensions: ", |
| 536 |
"should be \"width height\"", (char *)NULL); |
| 537 |
result = TCL_ERROR; |
| 538 |
} else { |
| 539 |
result = ((Tcl_GetInt(interp, dimArr[0], &width) == TCL_OK) && |
| 540 |
(Tcl_GetInt(interp, dimArr[1], &height) == TCL_OK)); |
| 541 |
} |
| 542 |
Blt_Free(dimArr); |
| 543 |
if (!result) { |
| 544 |
goto error; |
| 545 |
} |
| 546 |
string = elemArr[1]; |
| 547 |
} else if (nElem == 3) { |
| 548 |
if ((Tcl_GetInt(interp, elemArr[0], &width) != TCL_OK) || |
| 549 |
(Tcl_GetInt(interp, elemArr[1], &height) != TCL_OK)) { |
| 550 |
goto error; |
| 551 |
} |
| 552 |
string = elemArr[2]; |
| 553 |
} else { |
| 554 |
Tcl_AppendResult(interp, "wrong # of bitmap data components: ", |
| 555 |
"should be \"dimensions sourceData\"", (char *)NULL); |
| 556 |
goto error; |
| 557 |
} |
| 558 |
if ((width < 1) || (height < 1)) { |
| 559 |
Tcl_AppendResult(interp, "bad bitmap dimensions", (char *)NULL); |
| 560 |
goto error; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
for (p = string; *p != '\0'; p++) { |
| 565 |
if (*p == ',') { |
| 566 |
*p = ' '; |
| 567 |
} |
| 568 |
} |
| 569 |
arraySize = AsciiToData(interp, string, width, height, bitsPtr); |
| 570 |
*widthPtr = width; |
| 571 |
*heightPtr = height; |
| 572 |
error: |
| 573 |
Blt_Free(elemArr); |
| 574 |
return arraySize; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
static int |
| 595 |
ParseStructData(interp, string, widthPtr, heightPtr, bitsPtr) |
| 596 |
Tcl_Interp *interp; |
| 597 |
char *string; |
| 598 |
int *widthPtr; |
| 599 |
int *heightPtr; |
| 600 |
unsigned char **bitsPtr; |
| 601 |
{ |
| 602 |
int width, height; |
| 603 |
int hotX, hotY; |
| 604 |
char *line, *nextline; |
| 605 |
register char *p; |
| 606 |
Tcl_RegExp re; |
| 607 |
char *name, *value, *data; |
| 608 |
int len; |
| 609 |
int arraySize; |
| 610 |
|
| 611 |
width = height = 0; |
| 612 |
hotX = hotY = -1; |
| 613 |
data = NULL; |
| 614 |
nextline = string; |
| 615 |
for (line = string; nextline != NULL; line = nextline + 1) { |
| 616 |
nextline = strchr(line, '\n'); |
| 617 |
if ((nextline == NULL) || (line == nextline)) { |
| 618 |
continue; |
| 619 |
} |
| 620 |
*nextline = '\0'; |
| 621 |
re = Tcl_RegExpCompile(interp, " *# *define +"); |
| 622 |
if (Tcl_RegExpExec(interp, re, line, line)) { |
| 623 |
char *start, *end; |
| 624 |
|
| 625 |
Tcl_RegExpRange(re, 0, &start, &end); |
| 626 |
name = strtok(end, " \t"); |
| 627 |
value = strtok(NULL, " \t"); |
| 628 |
if ((name == NULL) || (value == NULL)) { |
| 629 |
return TCL_ERROR; |
| 630 |
} |
| 631 |
len = strlen(name); |
| 632 |
if ((len >= 6) && (name[len-6] == '_') && |
| 633 |
(strcmp(name+len-6, "_width") == 0)) { |
| 634 |
if (Tcl_GetInt(interp, value, &width) != TCL_OK) { |
| 635 |
return -1; |
| 636 |
} |
| 637 |
} else if ((len >= 7) && (name[len-7] == '_') && |
| 638 |
(strcmp(name+len-7, "_height") == 0)) { |
| 639 |
if (Tcl_GetInt(interp, value, &height) != TCL_OK) { |
| 640 |
return -1; |
| 641 |
} |
| 642 |
} else if ((len >= 6) && (name[len-6] == '_') && |
| 643 |
(strcmp(name+len-6, "_x_hot") == 0)) { |
| 644 |
if (Tcl_GetInt(interp, value, &hotX) != TCL_OK) { |
| 645 |
return -1; |
| 646 |
} |
| 647 |
} else if ((len >= 6) && (name[len-6] == '_') && |
| 648 |
(strcmp(name+len-6, "_y_hot") == 0)) { |
| 649 |
if (Tcl_GetInt(interp, value, &hotY) != TCL_OK) { |
| 650 |
return -1; |
| 651 |
} |
| 652 |
} |
| 653 |
} else { |
| 654 |
re = Tcl_RegExpCompile(interp, " *static +.*char +"); |
| 655 |
if (Tcl_RegExpExec(interp, re, line, line)) { |
| 656 |
|
| 657 |
|
| 658 |
*nextline = ' '; |
| 659 |
p = strchr(line, '{'); |
| 660 |
if (p == NULL) { |
| 661 |
return -1; |
| 662 |
} |
| 663 |
data = p + 1; |
| 664 |
break; |
| 665 |
} else { |
| 666 |
Tcl_AppendResult(interp, "unknown bitmap format: ", |
| 667 |
"obsolete X10 bitmap file?", (char *) NULL); |
| 668 |
return -1; |
| 669 |
} |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
if ((width <= 0) || (height <= 0)) { |
| 677 |
Tcl_AppendResult(interp, "invalid bitmap dimensions \"", (char *)NULL); |
| 678 |
Tcl_AppendResult(interp, Blt_Itoa(width), " x ", (char *)NULL); |
| 679 |
Tcl_AppendResult(interp, Blt_Itoa(height), "\"", (char *)NULL); |
| 680 |
return -1; |
| 681 |
} |
| 682 |
*widthPtr = width; |
| 683 |
*heightPtr = height; |
| 684 |
for (p = data; *p != '\0'; p++) { |
| 685 |
if ((*p == ',') || (*p == ';') || (*p == '}')) { |
| 686 |
*p = ' '; |
| 687 |
} |
| 688 |
} |
| 689 |
arraySize = AsciiToData(interp, data, width, height, bitsPtr); |
| 690 |
return arraySize; |
| 691 |
} |
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
static int |
| 713 |
ScaleRotateData( |
| 714 |
Tcl_Interp *interp, |
| 715 |
BitmapData *srcPtr, |
| 716 |
double theta, |
| 717 |
double scale, |
| 718 |
BitmapData *destPtr) |
| 719 |
{ |
| 720 |
register int x, y, sx, sy; |
| 721 |
double srcX, srcY, destX, destY; |
| 722 |
|
| 723 |
double dx, dy; |
| 724 |
double sinTheta, cosTheta; |
| 725 |
double rotWidth, rotHeight; |
| 726 |
double radians; |
| 727 |
unsigned char *bits; |
| 728 |
int arraySize; |
| 729 |
int pixel, ipixel; |
| 730 |
int srcBytesPerLine, destBytesPerLine; |
| 731 |
|
| 732 |
srcBytesPerLine = (srcPtr->width + 7) / 8; |
| 733 |
Blt_GetBoundingBox(srcPtr->width, srcPtr->height, theta, &rotWidth, |
| 734 |
&rotHeight, (Point2D *)NULL); |
| 735 |
destPtr->width = (int)(rotWidth * scale + 0.5) ; |
| 736 |
destPtr->height = (int)(rotHeight * scale + 0.5); |
| 737 |
|
| 738 |
destBytesPerLine = (destPtr->width + 7) / 8; |
| 739 |
arraySize = destPtr->height * destBytesPerLine; |
| 740 |
bits = Blt_Calloc(arraySize, sizeof(unsigned char)); |
| 741 |
if (bits == NULL) { |
| 742 |
Tcl_AppendResult(interp, "can't allocate bitmap data array", |
| 743 |
(char *)NULL); |
| 744 |
return TCL_ERROR; |
| 745 |
} |
| 746 |
scale = 1.0 / scale; |
| 747 |
destPtr->bits = bits; |
| 748 |
destPtr->arraySize = arraySize; |
| 749 |
|
| 750 |
radians = (theta / 180.0) * M_PI; |
| 751 |
sinTheta = sin(radians); |
| 752 |
cosTheta = cos(radians); |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
srcX = srcPtr->width * 0.5; |
| 758 |
srcY = srcPtr->height * 0.5; |
| 759 |
destX = rotWidth * 0.5; |
| 760 |
destY = rotHeight * 0.5; |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
for (y = 0; y < destPtr->height; y++) { |
| 766 |
for (x = 0; x < destPtr->width; x++) { |
| 767 |
dx = scale * (double)x; |
| 768 |
dy = scale * (double)y; |
| 769 |
if (theta == 270.0) { |
| 770 |
sx = (int)dy, sy = (int)(rotWidth - dx) - 1; |
| 771 |
} else if (theta == 180.0) { |
| 772 |
sx = (int)(rotWidth - dx) - 1, sy = (int)(rotHeight - dy) - 1; |
| 773 |
} else if (theta == 90.0) { |
| 774 |
sx = (int)(rotHeight - dy) - 1, sy = (int)dx; |
| 775 |
} else if (theta == 0.0) { |
| 776 |
sx = (int)dx, sy = (int)dy; |
| 777 |
} else { |
| 778 |
double transX, transY, rotX, rotY; |
| 779 |
|
| 780 |
|
| 781 |
transX = dx - destX; |
| 782 |
transY = dy - destY; |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
rotX = (transX * cosTheta) - (transY * sinTheta); |
| 787 |
rotY = (transX * sinTheta) + (transY * cosTheta); |
| 788 |
|
| 789 |
|
| 790 |
rotX += srcX; |
| 791 |
rotY += srcY; |
| 792 |
|
| 793 |
sx = ROUND(rotX); |
| 794 |
sy = ROUND(rotY); |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
if ((sx >= srcPtr->width) || (sx < 0) || |
| 802 |
(sy >= srcPtr->height) || (sy < 0)) { |
| 803 |
continue; |
| 804 |
} |
| 805 |
} |
| 806 |
ipixel = (srcBytesPerLine * sy) + (sx / 8); |
| 807 |
pixel = srcPtr->bits[ipixel] & (1 << (sx % 8)); |
| 808 |
if (pixel) { |
| 809 |
ipixel = (destBytesPerLine * y) + (x / 8); |
| 810 |
bits[ipixel] |= (1 << (x % 8)); |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
return TCL_OK; |
| 815 |
} |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
static void |
| 837 |
BitmapDataToString(tkwin, bitmap, resultPtr) |
| 838 |
Tk_Window tkwin; |
| 839 |
Pixmap bitmap; |
| 840 |
Tcl_DString *resultPtr; |
| 841 |
{ |
| 842 |
unsigned char *bits; |
| 843 |
char *separator; |
| 844 |
int arraySize; |
| 845 |
register int i; |
| 846 |
char string[200]; |
| 847 |
int width, height; |
| 848 |
|
| 849 |
|
| 850 |
Tk_SizeOfBitmap(Tk_Display(tkwin), bitmap, &width, &height); |
| 851 |
arraySize = BitmapToData(tkwin, bitmap, width, height, &bits); |
| 852 |
#define BYTES_PER_OUTPUT_LINE 24 |
| 853 |
for (i = 0; i < arraySize; i++) { |
| 854 |
separator = (i % BYTES_PER_OUTPUT_LINE) ? " " : "\n "; |
| 855 |
sprintf(string, "%s%02x", separator, bits[i]); |
| 856 |
Tcl_DStringAppend(resultPtr, string, -1); |
| 857 |
} |
| 858 |
if (bits != NULL) { |
| 859 |
Blt_Free(bits); |
| 860 |
} |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
static int |
| 886 |
ComposeOp(clientData, interp, argc, argv) |
| 887 |
ClientData clientData; |
| 888 |
Tcl_Interp *interp; |
| 889 |
int argc; |
| •890 |
CONST char **argv; |
| 891 |
{ |
| 892 |
BitmapInterpData *dataPtr = clientData; |
| 893 |
int width, height; |
| 894 |
Pixmap bitmap; |
| 895 |
unsigned char *bits; |
| 896 |
int arraySize; |
| 897 |
BitmapInfo info; |
| 898 |
int result; |
| 899 |
double theta; |
| 900 |
TextStyle ts; |
| 901 |
TextLayout *textPtr; |
| 902 |
Tk_Window tkwin; |
| 903 |
Blt_HashEntry *hPtr; |
| 904 |
int isNew; |
| 905 |
|
| 906 |
tkwin = dataPtr->tkwin; |
| 907 |
bitmap = Tk_GetBitmap(interp, tkwin, Tk_GetUid(argv[2])); |
| 908 |
Tcl_ResetResult(interp); |
| 909 |
if (bitmap != None) { |
| 910 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 911 |
return TCL_OK; |
| 912 |
} |
| 913 |
|
| 914 |
info.justify = TK_JUSTIFY_CENTER; |
| 915 |
info.rotate = 0.0; |
| 916 |
info.scale = 1.0; |
| 917 |
info.padLeft = info.padRight = 0; |
| 918 |
info.padTop = info.padBottom = 0; |
| 919 |
info.font = (Tk_Font)NULL; |
| •920 |
if (Blt_ConfigureWidget(interp, tkwin, composeConfigSpecs, |
| 921 |
argc - 4, argv + 4, (char *)&info, 0) != TCL_OK) { |
| 922 |
return TCL_ERROR; |
| 923 |
} |
| 924 |
theta = FMOD(info.rotate, (double)360.0); |
| 925 |
if (theta < 0.0) { |
| 926 |
theta += 360.0; |
| 927 |
} |
| 928 |
Blt_InitTextStyle(&ts); |
| 929 |
ts.font = info.font; |
| 930 |
ts.theta = 0.0; |
| 931 |
ts.justify = info.justify; |
| 932 |
ts.padX = info.padX; |
| 933 |
ts.padY = info.padY; |
| 934 |
ts.leader = 0; |
| 935 |
ts.anchor = TK_ANCHOR_CENTER; |
| 936 |
|
| •937 |
textPtr = Blt_GetTextLayout((char *)argv[3], &ts); |
| 938 |
bitmap = Blt_CreateTextBitmap(tkwin, textPtr, &ts, &width, &height); |
| 939 |
Blt_Free(textPtr); |
| 940 |
if (bitmap == None) { |
| 941 |
Tcl_AppendResult(interp, "can't create bitmap", (char *)NULL); |
| 942 |
return TCL_ERROR; |
| 943 |
} |
| 944 |
|
| 945 |
Tk_FreeOptions(composeConfigSpecs, (char *)&info, dataPtr->display, 0); |
| 946 |
|
| 947 |
|
| 948 |
arraySize = BitmapToData(tkwin, bitmap, width, height, &bits); |
| 949 |
Tk_FreePixmap(dataPtr->display, bitmap); |
| 950 |
if (arraySize == 0) { |
| 951 |
Tcl_AppendResult(interp, "can't get bitmap data", (char *)NULL); |
| 952 |
return TCL_ERROR; |
| 953 |
} |
| 954 |
|
| 955 |
if ((theta != 0.0) || (info.scale != 1.0)) { |
| 956 |
BitmapData srcData, destData; |
| 957 |
|
| 958 |
srcData.bits = bits; |
| 959 |
srcData.width = width; |
| 960 |
srcData.height = height; |
| 961 |
srcData.arraySize = arraySize; |
| 962 |
|
| 963 |
result = ScaleRotateData(interp, &srcData, theta, info.scale, |
| 964 |
&destData); |
| 965 |
Blt_Free(bits); |
| 966 |
if (result != TCL_OK) { |
| 967 |
return TCL_ERROR; |
| 968 |
} |
| 969 |
bits = destData.bits; |
| 970 |
width = destData.width; |
| 971 |
height = destData.height; |
| 972 |
} |
| 973 |
|
| 974 |
result = Tk_DefineBitmap(interp, Tk_GetUid(argv[2]), (char *)bits, |
| 975 |
width, height); |
| 976 |
if (result != TCL_OK) { |
| 977 |
Blt_Free(bits); |
| 978 |
} |
| 979 |
hPtr = Blt_CreateHashEntry(&(dataPtr->bitmapTable), argv[2], &isNew); |
| 980 |
Blt_SetHashValue(hPtr, bits); |
| 981 |
return result; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
static int |
| 1002 |
DefineOp(clientData, interp, argc, argv) |
| 1003 |
ClientData clientData; |
| 1004 |
Tcl_Interp *interp; |
| 1005 |
int argc; |
| •1006 |
CONST char **argv; |
| 1007 |
{ |
| 1008 |
BitmapInterpData *dataPtr = clientData; |
| 1009 |
int width, height; |
| 1010 |
unsigned char *bits; |
| 1011 |
register char *p; |
| 1012 |
char *defn; |
| 1013 |
BitmapInfo info; |
| 1014 |
int arraySize; |
| 1015 |
int result; |
| 1016 |
double theta; |
| 1017 |
Pixmap bitmap; |
| 1018 |
Blt_HashEntry *hPtr; |
| 1019 |
int isNew; |
| 1020 |
|
| 1021 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1022 |
Tcl_ResetResult(interp); |
| 1023 |
if (bitmap != None) { |
| 1024 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1025 |
return TCL_OK; |
| 1026 |
} |
| 1027 |
|
| 1028 |
info.rotate = 0.0; |
| 1029 |
info.scale = 1.0; |
| •1030 |
if (Blt_ConfigureWidget(interp, dataPtr->tkwin, defineConfigSpecs, |
| 1031 |
argc - 4, argv + 4, (char *)&info, 0) != TCL_OK) { |
| 1032 |
return TCL_ERROR; |
| 1033 |
} |
| 1034 |
|
| •1035 |
for (p = (char *)argv[3]; isspace(UCHAR(*p)); p++) { |
| 1036 |
|
| 1037 |
} |
| 1038 |
defn = Blt_Strdup(p); |
| 1039 |
bits = NULL; |
| 1040 |
if (*p == '#') { |
| 1041 |
arraySize = ParseStructData(interp, defn, &width, &height, &bits); |
| 1042 |
} else { |
| 1043 |
arraySize = ParseListData(interp, defn, &width, &height, &bits); |
| 1044 |
} |
| 1045 |
Blt_Free(defn); |
| 1046 |
if (arraySize <= 0) { |
| 1047 |
return TCL_ERROR; |
| 1048 |
} |
| 1049 |
theta = FMOD(info.rotate, 360.0); |
| 1050 |
if (theta < 0.0) { |
| 1051 |
theta += 360.0; |
| 1052 |
} |
| 1053 |
|
| 1054 |
if ((theta != 0.0) || (info.scale != 1.0)) { |
| 1055 |
BitmapData srcData, destData; |
| 1056 |
|
| 1057 |
srcData.bits = bits; |
| 1058 |
srcData.width = width; |
| 1059 |
srcData.height = height; |
| 1060 |
srcData.arraySize = arraySize; |
| 1061 |
|
| 1062 |
result = ScaleRotateData(interp, &srcData, theta, info.scale, |
| 1063 |
&destData); |
| 1064 |
Blt_Free(bits); |
| 1065 |
if (result != TCL_OK) { |
| 1066 |
return TCL_ERROR; |
| 1067 |
} |
| 1068 |
bits = destData.bits; |
| 1069 |
width = destData.width; |
| 1070 |
height = destData.height; |
| 1071 |
} |
| 1072 |
result = Tk_DefineBitmap(interp, Tk_GetUid(argv[2]), (char *)bits, |
| 1073 |
width, height); |
| 1074 |
if (result != TCL_OK) { |
| 1075 |
Blt_Free(bits); |
| 1076 |
} |
| 1077 |
hPtr = Blt_CreateHashEntry(&(dataPtr->bitmapTable), argv[2], &isNew); |
| 1078 |
Blt_SetHashValue(hPtr, bits); |
| 1079 |
return result; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
static int |
| 1093 |
ExistsOp(clientData, interp, argc, argv) |
| 1094 |
ClientData clientData; |
| 1095 |
Tcl_Interp *interp; |
| 1096 |
int argc; |
| 1097 |
char **argv; |
| 1098 |
{ |
| 1099 |
BitmapInterpData *dataPtr = clientData; |
| 1100 |
Pixmap bitmap; |
| 1101 |
|
| 1102 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1103 |
Tcl_ResetResult(interp); |
| 1104 |
if (bitmap != None) { |
| 1105 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1106 |
} |
| 1107 |
Blt_SetBooleanResult(interp, (bitmap != None)); |
| 1108 |
return TCL_OK; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
static int |
| 1122 |
HeightOp(clientData, interp, argc, argv) |
| 1123 |
ClientData clientData; |
| 1124 |
Tcl_Interp *interp; |
| 1125 |
int argc; |
| 1126 |
char **argv; |
| 1127 |
{ |
| 1128 |
BitmapInterpData *dataPtr = clientData; |
| 1129 |
int width, height; |
| 1130 |
Pixmap bitmap; |
| 1131 |
|
| 1132 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1133 |
if (bitmap == None) { |
| 1134 |
return TCL_ERROR; |
| 1135 |
} |
| 1136 |
Tk_SizeOfBitmap(dataPtr->display, bitmap, &width, &height); |
| 1137 |
Tcl_SetResult(interp, Blt_Itoa(height), TCL_VOLATILE); |
| 1138 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1139 |
return TCL_OK; |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
static int |
| 1153 |
WidthOp(clientData, interp, argc, argv) |
| 1154 |
ClientData clientData; |
| 1155 |
Tcl_Interp *interp; |
| 1156 |
int argc; |
| 1157 |
char **argv; |
| 1158 |
{ |
| 1159 |
BitmapInterpData *dataPtr = clientData; |
| 1160 |
int width, height; |
| 1161 |
Pixmap bitmap; |
| 1162 |
|
| 1163 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1164 |
if (bitmap == None) { |
| 1165 |
return TCL_ERROR; |
| 1166 |
} |
| 1167 |
Tk_SizeOfBitmap(dataPtr->display, bitmap, &width, &height); |
| 1168 |
Tcl_SetResult(interp, Blt_Itoa(width), TCL_VOLATILE); |
| 1169 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1170 |
return TCL_OK; |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
static int |
| 1185 |
SourceOp(clientData, interp, argc, argv) |
| 1186 |
ClientData clientData; |
| 1187 |
Tcl_Interp *interp; |
| 1188 |
int argc; |
| 1189 |
char **argv; |
| 1190 |
{ |
| 1191 |
BitmapInterpData *dataPtr = clientData; |
| 1192 |
Pixmap bitmap; |
| 1193 |
Tcl_DString dString; |
| 1194 |
|
| 1195 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1196 |
if (bitmap == None) { |
| 1197 |
return TCL_ERROR; |
| 1198 |
} |
| 1199 |
Tcl_DStringInit(&dString); |
| 1200 |
BitmapDataToString(dataPtr->tkwin, bitmap, &dString); |
| 1201 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1202 |
Tcl_DStringResult(interp, &dString); |
| 1203 |
return TCL_OK; |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
static int |
| 1218 |
DataOp(clientData, interp, argc, argv) |
| 1219 |
ClientData clientData; |
| 1220 |
Tcl_Interp *interp; |
| 1221 |
int argc; |
| 1222 |
char **argv; |
| 1223 |
{ |
| 1224 |
BitmapInterpData *dataPtr = clientData; |
| 1225 |
Pixmap bitmap; |
| 1226 |
int width, height; |
| 1227 |
Tcl_DString dString; |
| 1228 |
|
| 1229 |
bitmap = Tk_GetBitmap(interp, dataPtr->tkwin, Tk_GetUid(argv[2])); |
| 1230 |
if (bitmap == None) { |
| 1231 |
return TCL_ERROR; |
| 1232 |
} |
| 1233 |
Tk_SizeOfBitmap(dataPtr->display, bitmap, &width, &height); |
| 1234 |
Tcl_DStringInit(&dString); |
| 1235 |
Tcl_DStringAppendElement(&dString, Blt_Itoa(width)); |
| 1236 |
Tcl_DStringAppendElement(&dString, Blt_Itoa(height)); |
| 1237 |
Tcl_DStringStartSublist(&dString); |
| 1238 |
BitmapDataToString(dataPtr->tkwin, bitmap, &dString); |
| 1239 |
Tcl_DStringEndSublist(&dString); |
| 1240 |
Tk_FreeBitmap(dataPtr->display, bitmap); |
| 1241 |
Tcl_DStringResult(interp, &dString); |
| 1242 |
return TCL_OK; |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
static Blt_OpSpec bitmapOps[] = |
| 1261 |
{ |
| 1262 |
{"compose", 1, (Blt_Op)ComposeOp, 4, 0, "bitmapName text ?flags?",}, |
| 1263 |
{"data", 2, (Blt_Op)DataOp, 3, 3, "bitmapName",}, |
| 1264 |
{"define", 2, (Blt_Op)DefineOp, 4, 0, "bitmapName data ?flags?",}, |
| 1265 |
{"exists", 1, (Blt_Op)ExistsOp, 3, 3, "bitmapName",}, |
| 1266 |
{"height", 1, (Blt_Op)HeightOp, 3, 3, "bitmapName",}, |
| 1267 |
{"source", 1, (Blt_Op)SourceOp, 3, 3, "bitmapName",}, |
| 1268 |
{"width", 1, (Blt_Op)WidthOp, 3, 3, "bitmapName",}, |
| 1269 |
}; |
| 1270 |
static int nBitmapOps = sizeof(bitmapOps) / sizeof(Blt_OpSpec); |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
static int |
| 1291 |
BitmapCmd(clientData, interp, argc, argv) |
| 1292 |
ClientData clientData; |
| 1293 |
Tcl_Interp *interp; |
| 1294 |
int argc; |
| 1295 |
char **argv; |
| 1296 |
{ |
| 1297 |
Blt_Op proc; |
| 1298 |
int result; |
| 1299 |
|
| 1300 |
proc = Blt_GetOp(interp, nBitmapOps, bitmapOps, BLT_OP_ARG1, argc, argv,0); |
| 1301 |
if (proc == NULL) { |
| 1302 |
return TCL_ERROR; |
| 1303 |
} |
| 1304 |
result = (*proc) (clientData, interp, argc, argv); |
| 1305 |
return result; |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
static void |
| 1326 |
BitmapInterpDeleteProc(clientData, interp) |
| 1327 |
ClientData clientData; |
| 1328 |
Tcl_Interp *interp; |
| 1329 |
{ |
| 1330 |
BitmapInterpData *dataPtr = clientData; |
| 1331 |
Blt_HashEntry *hPtr; |
| 1332 |
unsigned char *bits; |
| 1333 |
Blt_HashSearch cursor; |
| 1334 |
|
| 1335 |
for (hPtr = Blt_FirstHashEntry(&(dataPtr->bitmapTable), &cursor); |
| 1336 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 1337 |
bits = (unsigned char *)Blt_GetHashValue(hPtr); |
| 1338 |
Blt_Free(bits); |
| 1339 |
} |
| 1340 |
Blt_DeleteHashTable(&(dataPtr->bitmapTable)); |
| 1341 |
Tcl_DeleteAssocData(interp, BITMAP_THREAD_KEY); |
| 1342 |
Blt_Free(dataPtr); |
| 1343 |
} |
| 1344 |
|
| 1345 |
static BitmapInterpData * |
| 1346 |
GetBitmapInterpData(interp) |
| 1347 |
Tcl_Interp *interp; |
| 1348 |
{ |
| 1349 |
BitmapInterpData *dataPtr; |
| 1350 |
Tcl_InterpDeleteProc *proc; |
| 1351 |
|
| 1352 |
dataPtr = (BitmapInterpData *) |
| 1353 |
Tcl_GetAssocData(interp, BITMAP_THREAD_KEY, &proc); |
| 1354 |
if (dataPtr == NULL) { |
| 1355 |
dataPtr = Blt_Malloc(sizeof(BitmapInterpData)); |
| 1356 |
assert(dataPtr); |
| 1357 |
dataPtr->interp = interp; |
| 1358 |
dataPtr->tkwin = Tk_MainWindow(interp); |
| 1359 |
dataPtr->display = Tk_Display(dataPtr->tkwin); |
| 1360 |
Tcl_SetAssocData(interp, BITMAP_THREAD_KEY, BitmapInterpDeleteProc, |
| 1361 |
dataPtr); |
| 1362 |
Blt_InitHashTable(&(dataPtr->bitmapTable), BLT_STRING_KEYS); |
| 1363 |
} |
| 1364 |
return dataPtr; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
int |
| 1384 |
Blt_BitmapInit(interp) |
| 1385 |
Tcl_Interp *interp; |
| 1386 |
{ |
| 1387 |
BitmapInterpData *dataPtr; |
| 1388 |
static Blt_CmdSpec cmdSpec = |
| 1389 |
{"bitmap", BitmapCmd}; |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
dataPtr = GetBitmapInterpData(interp); |
| 1394 |
cmdSpec.clientData = dataPtr; |
| 1395 |
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) { |
| 1396 |
return TCL_ERROR; |
| 1397 |
} |
| 1398 |
Tk_DefineBitmap(interp, Tk_GetUid("bigBLT"), (char *)bigblt_bits, |
| 1399 |
bigblt_width, bigblt_height); |
| 1400 |
Tk_DefineBitmap(interp, Tk_GetUid("BLT"), (char *)blt_bits, |
| 1401 |
blt_width, blt_height); |
| 1402 |
Tcl_ResetResult(interp); |
| 1403 |
return TCL_OK; |
| 1404 |
} |
| 1405 |
|
| 1406 |
#endif |