| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include "tk.h" |
| 15 |
#include "tkVMacro.h" |
| 16 |
#include "imgInt.h" |
| 17 |
#include <string.h> |
| 18 |
#include <ctype.h> |
| 19 |
#include <stdlib.h> |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#define MAX_BUFFER 4096 |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#define MAX_WORD_LENGTH 100 |
| 32 |
typedef struct ParseInfo { |
| 33 |
MFile handle; |
| 34 |
char word[MAX_WORD_LENGTH+2]; |
| 35 |
|
| 36 |
|
| 37 |
int wordLength; |
| 38 |
} ParseInfo; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
static int ChnMatchXBM _ANSI_ARGS_((Tcl_Channel chan, |
| 45 |
Tcl_Obj *fileName, Tcl_Obj *format, int *widthPtr, |
| 46 |
int *heightPtr, Tcl_Interp *interp)); |
| 47 |
static int ObjMatchXBM _ANSI_ARGS_((Tcl_Obj *data, |
| 48 |
Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp)); |
| 49 |
static int ChnReadXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 50 |
Tcl_Channel chan, Tcl_Obj *fileName, |
| 51 |
Tcl_Obj *format, Tk_PhotoHandle imageHandle, |
| 52 |
int destX, int destY, int width, int height, |
| 53 |
int srcX, int srcY)); |
| 54 |
static int ObjReadXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 55 |
Tcl_Obj *dataObj, Tcl_Obj *format, |
| 56 |
Tk_PhotoHandle imageHandle, int destX, int destY, |
| 57 |
int width, int height, int srcX, int srcY)); |
| 58 |
static int ChnWriteXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 59 |
char *fileName, Tcl_Obj *format, |
| 60 |
Tk_PhotoImageBlock *blockPtr)); |
| 61 |
static int StringWriteXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 62 |
Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr)); |
| 63 |
|
| 64 |
static int CommonReadXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 65 |
ParseInfo *parseInfo, |
| 66 |
Tcl_Obj *format, Tk_PhotoHandle imageHandle, |
| 67 |
int destX, int destY, int width, int height, |
| 68 |
int srcX, int srcY)); |
| 69 |
static int CommonWriteXBM _ANSI_ARGS_((Tcl_Interp *interp, |
| 70 |
CONST char *fileName, Tcl_DString *dataPtr, |
| 71 |
Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr)); |
| 72 |
|
| 73 |
Tk_PhotoImageFormat imgFmtXBM = { |
| 74 |
"xbm", |
| 75 |
ChnMatchXBM, |
| 76 |
ObjMatchXBM, |
| 77 |
ChnReadXBM, |
| 78 |
ObjReadXBM, |
| 79 |
ChnWriteXBM, |
| 80 |
StringWriteXBM |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
static int ReadXBMFileHeader _ANSI_ARGS_((ParseInfo *parseInfo, |
| 88 |
int *widthPtr, int *heightPtr)); |
| 89 |
static int NextBitmapWord _ANSI_ARGS_((ParseInfo *parseInfoPtr)); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static int |
| 109 |
ObjMatchXBM(data, format, widthPtr, heightPtr, interp) |
| 110 |
Tcl_Obj *data; |
| 111 |
Tcl_Obj *format; |
| 112 |
int *widthPtr, *heightPtr; |
| 113 |
|
| 114 |
|
| 115 |
Tcl_Interp *interp; |
| 116 |
{ |
| 117 |
ParseInfo parseInfo; |
| 118 |
|
| 119 |
ImgFixObjMatchProc(&interp, &data, &format, &widthPtr, &heightPtr); |
| 120 |
|
| 121 |
parseInfo.handle.data = ImgGetStringFromObj(data, &parseInfo.handle.length); |
| 122 |
parseInfo.handle.state = IMG_STRING; |
| 123 |
|
| 124 |
return ReadXBMFileHeader(&parseInfo, widthPtr, heightPtr); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
static int |
| 147 |
ChnMatchXBM(chan, fileName, format, widthPtr, heightPtr, interp) |
| 148 |
Tcl_Channel chan; |
| 149 |
Tcl_Obj *fileName; |
| 150 |
Tcl_Obj *format; |
| 151 |
int *widthPtr, *heightPtr; |
| 152 |
|
| 153 |
|
| 154 |
Tcl_Interp *interp; |
| 155 |
{ |
| 156 |
ParseInfo parseInfo; |
| 157 |
|
| 158 |
ImgFixChanMatchProc(&interp, &chan, &fileName, &format, &widthPtr, &heightPtr); |
| 159 |
|
| 160 |
parseInfo.handle.data = (char *) chan; |
| 161 |
parseInfo.handle.state = IMG_CHAN; |
| 162 |
|
| 163 |
return ReadXBMFileHeader(&parseInfo, widthPtr, heightPtr); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
typedef struct myblock { |
| 188 |
Tk_PhotoImageBlock ck; |
| 189 |
int dummy; |
| 190 |
|
| 191 |
} myblock; |
| 192 |
|
| 193 |
#define block bl.ck |
| 194 |
|
| 195 |
static int |
| 196 |
CommonReadXBM(interp, parseInfo, format, imageHandle, destX, destY, |
| 197 |
width, height, srcX, srcY) |
| 198 |
Tcl_Interp *interp; |
| 199 |
ParseInfo *parseInfo; |
| 200 |
Tcl_Obj *format; |
| 201 |
Tk_PhotoHandle imageHandle; |
| 202 |
int destX, destY; |
| 203 |
|
| 204 |
int width, height; |
| 205 |
|
| 206 |
int srcX, srcY; |
| 207 |
|
| 208 |
{ |
| 209 |
myblock bl; |
| 210 |
int fileWidth, fileHeight; |
| 211 |
int numBytes, row, col, value, i; |
| 212 |
unsigned char *data, *pixelPtr; |
| 213 |
char *end; |
| 214 |
|
| 215 |
ReadXBMFileHeader(parseInfo, &fileWidth, &fileHeight); |
| 216 |
|
| 217 |
if ((srcX + width) > fileWidth) { |
| 218 |
width = fileWidth - srcX; |
| 219 |
} |
| 220 |
if ((srcY + height) > fileHeight) { |
| 221 |
height = fileHeight - srcY; |
| 222 |
} |
| 223 |
if ((width <= 0) || (height <= 0) |
| 224 |
|| (srcX >= fileWidth) || (srcY >= fileHeight)) { |
| 225 |
return TCL_OK; |
| 226 |
} |
| 227 |
|
| 228 |
Tk_PhotoExpand(imageHandle, destX + width, destY + height); |
| 229 |
|
| 230 |
numBytes = ((fileWidth+7)/8)*32; |
| 231 |
block.width = fileWidth; |
| 232 |
block.height = 1; |
| 233 |
block.pixelSize = 4; |
| 234 |
block.offset[0] = 0; |
| 235 |
block.offset[1] = 1; |
| 236 |
block.offset[2] = 2; |
| 237 |
block.offset[3] = 3; |
| 238 |
|
| 239 |
data = (unsigned char *) ckalloc((unsigned) numBytes); |
| 240 |
block.pixelPtr = data + srcX*4; |
| 241 |
for (row = 0; row < srcY + height; row++) { |
| 242 |
pixelPtr = data; |
| 243 |
for (col = 0; col<(numBytes/32); col++) { |
| 244 |
if (NextBitmapWord(parseInfo) != TCL_OK) { |
| 245 |
ckfree((char *) data); |
| 246 |
return TCL_ERROR; |
| 247 |
} |
| 248 |
value = (int) strtol(parseInfo->word, &end, 0); |
| 249 |
if (end == parseInfo->word) { |
| 250 |
ckfree((char *) data); |
| 251 |
return TCL_ERROR; |
| 252 |
} |
| 253 |
for (i=0; i<8; i++) { |
| 254 |
*pixelPtr++ = 0; |
| 255 |
*pixelPtr++ = 0; |
| 256 |
*pixelPtr++ = 0; |
| 257 |
*pixelPtr++ = (value & 0x1)? 255:0; |
| 258 |
value >>= 1; |
| 259 |
} |
| 260 |
} |
| 261 |
if (row >= srcY) { |
| 262 |
ImgPhotoPutBlock(imageHandle, &block, destX, destY++, width, 1); |
| 263 |
} |
| 264 |
} |
| 265 |
ckfree((char *) data); |
| 266 |
return TCL_OK; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
static int |
| 291 |
ChnReadXBM(interp, chan, fileName, format, imageHandle, destX, destY, |
| 292 |
width, height, srcX, srcY) |
| 293 |
Tcl_Interp *interp; |
| 294 |
Tcl_Channel chan; |
| 295 |
Tcl_Obj *fileName; |
| 296 |
Tcl_Obj *format; |
| 297 |
Tk_PhotoHandle imageHandle; |
| 298 |
int destX, destY; |
| 299 |
|
| 300 |
int width, height; |
| 301 |
|
| 302 |
int srcX, srcY; |
| 303 |
|
| 304 |
{ |
| 305 |
ParseInfo parseInfo; |
| 306 |
|
| 307 |
parseInfo.handle.data = (char *) chan; |
| 308 |
parseInfo.handle.state = IMG_CHAN; |
| 309 |
|
| 310 |
return CommonReadXBM(interp, &parseInfo, format, imageHandle, |
| 311 |
destX, destY, width, height, srcX, srcY); |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
static int |
| 334 |
ObjReadXBM(interp, data, format, imageHandle, destX, destY, |
| 335 |
width, height, srcX, srcY) |
| 336 |
Tcl_Interp *interp; |
| 337 |
Tcl_Obj *data; |
| 338 |
Tcl_Obj *format; |
| 339 |
Tk_PhotoHandle imageHandle; |
| 340 |
int destX, destY; |
| 341 |
|
| 342 |
int width, height; |
| 343 |
|
| 344 |
int srcX, srcY; |
| 345 |
|
| 346 |
{ |
| 347 |
ParseInfo parseInfo; |
| 348 |
parseInfo.handle.data = ImgGetStringFromObj(data, &parseInfo.handle.length); |
| 349 |
parseInfo.handle.state = IMG_STRING; |
| 350 |
|
| 351 |
return CommonReadXBM(interp, &parseInfo, format, imageHandle, |
| 352 |
destX, destY, width, height, srcX, srcY); |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
#define UCHAR(c) ((unsigned char) (c)) |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
static int |
| 398 |
NextBitmapWord(parseInfoPtr) |
| 399 |
ParseInfo *parseInfoPtr; |
| 400 |
|
| 401 |
{ |
| 402 |
char *dst, buf; |
| 403 |
int num; |
| 404 |
|
| 405 |
parseInfoPtr->wordLength = 0; |
| 406 |
dst = parseInfoPtr->word; |
| 407 |
|
| 408 |
for (num=ImgRead(&parseInfoPtr->handle,&buf,1); isspace(UCHAR(buf)) || (buf == ','); |
| 409 |
num=ImgRead(&parseInfoPtr->handle,&buf,1)) { |
| 410 |
if (num == 0 || buf == EOF) { |
| 411 |
return TCL_ERROR; |
| 412 |
} |
| 413 |
} |
| 414 |
for ( ; !isspace(UCHAR(buf)) && (buf != ',') && (num != 0); |
| 415 |
num=ImgRead(&parseInfoPtr->handle,&buf,1)) { |
| 416 |
if (UCHAR(buf) < ' ' || UCHAR(buf) > '~') { |
| 417 |
return TCL_ERROR; |
| 418 |
} |
| 419 |
*dst = buf; |
| 420 |
dst++; |
| 421 |
parseInfoPtr->wordLength++; |
| 422 |
if (num == 0 || parseInfoPtr->wordLength > MAX_WORD_LENGTH) { |
| 423 |
return TCL_ERROR; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
if (parseInfoPtr->wordLength == 0) { |
| 428 |
return TCL_ERROR; |
| 429 |
} |
| 430 |
parseInfoPtr->word[parseInfoPtr->wordLength] = 0; |
| 431 |
return TCL_OK; |
| 432 |
} |
| 433 |
|
| 434 |
static int |
| 435 |
ReadXBMFileHeader(pi, widthPtr, heightPtr) |
| 436 |
ParseInfo *pi; |
| 437 |
int *widthPtr, *heightPtr; |
| 438 |
|
| 439 |
{ |
| 440 |
int width, height, hotX, hotY; |
| 441 |
char *end; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
width = 0; |
| 461 |
height = 0; |
| 462 |
hotX = -1; |
| 463 |
hotY = -1; |
| 464 |
while (1) { |
| 465 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 466 |
return 0; |
| 467 |
} |
| 468 |
if ((pi->wordLength >= 6) && (pi->word[pi->wordLength-6] == '_') |
| 469 |
&& (strcmp(pi->word+pi->wordLength-6, "_width") == 0)) { |
| 470 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 471 |
return 0; |
| 472 |
} |
| 473 |
width = strtol(pi->word, &end, 0); |
| 474 |
if ((end == pi->word) || (*end != 0)) { |
| 475 |
return 0; |
| 476 |
} |
| 477 |
} else if ((pi->wordLength >= 7) && (pi->word[pi->wordLength-7] == '_') |
| 478 |
&& (strcmp(pi->word+pi->wordLength-7, "_height") == 0)) { |
| 479 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 480 |
return 0; |
| 481 |
} |
| 482 |
height = strtol(pi->word, &end, 0); |
| 483 |
if ((end == pi->word) || (*end != 0)) { |
| 484 |
return 0; |
| 485 |
} |
| 486 |
} else if ((pi->wordLength >= 6) && (pi->word[pi->wordLength-6] == '_') |
| 487 |
&& (strcmp(pi->word+pi->wordLength-6, "_x_hot") == 0)) { |
| 488 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 489 |
return 0; |
| 490 |
} |
| 491 |
hotX = strtol(pi->word, &end, 0); |
| 492 |
if ((end == pi->word) || (*end != 0)) { |
| 493 |
return 0; |
| 494 |
} |
| 495 |
} else if ((pi->wordLength >= 6) && (pi->word[pi->wordLength-6] == '_') |
| 496 |
&& (strcmp(pi->word+pi->wordLength-6, "_y_hot") == 0)) { |
| 497 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 498 |
return 0; |
| 499 |
} |
| 500 |
hotY = strtol(pi->word, &end, 0); |
| 501 |
if ((end == pi->word) || (*end != 0)) { |
| 502 |
return 0; |
| 503 |
} |
| 504 |
} else if ((pi->word[0] == 'c') && (strcmp(pi->word, "char") == 0)) { |
| 505 |
while (1) { |
| 506 |
if (NextBitmapWord(pi) != TCL_OK) { |
| 507 |
return 0; |
| 508 |
} |
| 509 |
if ((pi->word[0] == '{') && (pi->word[1] == 0)) { |
| 510 |
goto getData; |
| 511 |
} |
| 512 |
} |
| 513 |
} else if ((pi->word[0] == '{') && (pi->word[1] == 0)) { |
| 514 |
return 0; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
getData: |
| 519 |
*widthPtr = width; |
| 520 |
*heightPtr = height; |
| 521 |
return 1; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
static int |
| 542 |
ChnWriteXBM(interp, fileName, format, blockPtr) |
| 543 |
Tcl_Interp *interp; |
| 544 |
char *fileName; |
| 545 |
Tcl_Obj *format; |
| 546 |
Tk_PhotoImageBlock *blockPtr; |
| 547 |
{ |
| 548 |
return CommonWriteXBM(interp, fileName, (Tcl_DString *)NULL, format, blockPtr); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
static int |
| 569 |
StringWriteXBM(interp, format, blockPtr) |
| 570 |
Tcl_Interp *interp; |
| 571 |
Tcl_Obj *format; |
| 572 |
Tk_PhotoImageBlock *blockPtr; |
| 573 |
{ |
| 574 |
int result; |
| 575 |
Tcl_DString data; |
| 576 |
Tcl_DString *dataPtr; |
| 577 |
|
| 578 |
ImgFixStringWriteProc(&data, &interp, &dataPtr, &format, &blockPtr); |
| 579 |
|
| 580 |
result = CommonWriteXBM(interp, (CONST char *) NULL, dataPtr, format, blockPtr); |
| 581 |
|
| 582 |
if ((result == TCL_OK) && (dataPtr == &data)) { |
| 583 |
Tcl_DStringResult(interp, dataPtr); |
| 584 |
} |
| 585 |
return result; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
#define WRITE(buf) { if (chan) Tcl_Write(chan, buf, -1); else Tcl_DStringAppend(dataPtr, buf, -1);} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
static int |
| 611 |
CommonWriteXBM(interp, fileName, dataPtr, format, blockPtr) |
| 612 |
Tcl_Interp *interp; |
| 613 |
CONST char *fileName; |
| 614 |
Tcl_DString *dataPtr; |
| 615 |
Tcl_Obj *format; |
| 616 |
Tk_PhotoImageBlock *blockPtr; |
| 617 |
{ |
| 618 |
Tcl_Channel chan = (Tcl_Channel) NULL; |
| 619 |
char buffer[256]; |
| 620 |
unsigned char *pp; |
| 621 |
int x, y, value, mask; |
| 622 |
int sep = ' '; |
| 623 |
int alphaOffset; |
| 624 |
char *p = NULL; |
| 625 |
static CONST char header[] = |
| 626 |
"#define %s_width %d\n\ |
| 627 |
#define %s_height %d\n\ |
| 628 |
static char %s_bits[] = {\n"; |
| 629 |
|
| 630 |
alphaOffset = blockPtr->offset[0]; |
| 631 |
if (alphaOffset < blockPtr->offset[1]) alphaOffset = blockPtr->offset[1]; |
| 632 |
if (alphaOffset < blockPtr->offset[2]) alphaOffset = blockPtr->offset[2]; |
| 633 |
if (++alphaOffset < blockPtr->pixelSize) { |
| 634 |
alphaOffset -= blockPtr->offset[0]; |
| 635 |
} else { |
| 636 |
alphaOffset = 0; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
if (fileName) { |
| 642 |
chan = Tcl_OpenFileChannel(interp, (char *) fileName, "w", 0644); |
| 643 |
if (!chan) { |
| 644 |
return TCL_ERROR; |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
if (chan) { |
| 650 |
p = strrchr(fileName, '/'); |
| 651 |
if (p) { |
| 652 |
fileName = p+1; |
| 653 |
} |
| 654 |
p = strrchr(fileName, '\\'); |
| 655 |
if (p) { |
| 656 |
fileName = p+1; |
| 657 |
} |
| 658 |
p = strrchr(fileName, ':'); |
| 659 |
if (p) { |
| 660 |
fileName = p+1; |
| 661 |
} |
| 662 |
p = strchr(fileName, '.'); |
| 663 |
if (p) { |
| 664 |
*(char *)p = 0; |
| 665 |
} |
| 666 |
} else { |
| 667 |
fileName = "unknown"; |
| 668 |
} |
| 669 |
|
| 670 |
sprintf(buffer, header, fileName, blockPtr->width, fileName, |
| 671 |
blockPtr->height, fileName); |
| 672 |
if (p) { |
| 673 |
*p = '.'; |
| 674 |
} |
| 675 |
WRITE(buffer); |
| 676 |
|
| 677 |
|
| 678 |
pp = blockPtr->pixelPtr + blockPtr->offset[0]; |
| 679 |
sep = ' '; |
| 680 |
for (y = 0; y < blockPtr->height; y++) { |
| 681 |
value = 0; |
| 682 |
mask = 1; |
| 683 |
for (x = 0; x < blockPtr->width; x++) { |
| 684 |
if (!alphaOffset || pp[alphaOffset]) { |
| 685 |
value |= mask; |
| 686 |
} else { |
| 687 |
|
| 688 |
} |
| 689 |
pp += blockPtr->pixelSize; |
| 690 |
mask <<= 1; |
| 691 |
if (mask >= 256) |
| 692 |
{ |
| 693 |
sprintf(buffer,"%c 0x%02x",sep,value); |
| 694 |
WRITE(buffer); |
| 695 |
value = 0; |
| 696 |
mask = 1; |
| 697 |
sep = ','; |
| 698 |
} |
| 699 |
} |
| 700 |
if (mask != 1) { |
| 701 |
sprintf(buffer,"%c 0x%02x",sep, value); |
| 702 |
WRITE(buffer); |
| 703 |
} |
| 704 |
|
| 705 |
if (y == blockPtr->height - 1) { |
| 706 |
WRITE("};\n"); |
| 707 |
} else { |
| 708 |
WRITE(",\n"); |
| 709 |
sep = ' '; |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
if (chan) { |
| 715 |
Tcl_Close(interp, chan); |
| 716 |
} |
| 717 |
return TCL_OK; |
| 718 |
} |