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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 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 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
|
/****************************************************************************
* NCSA Mosaic for the X Window System *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* 605 E. Springfield, Champaign IL 61820 *
* mosaic@ncsa.uiuc.edu *
* *
* Copyright (C) 1993, Board of Trustees of the University of Illinois *
* *
* NCSA Mosaic software, both binary and source (hereafter, Software) is *
* copyrighted by The Board of Trustees of the University of Illinois *
* (UI), and ownership remains with the UI. *
* *
* The UI grants you (hereafter, Licensee) a license to use the Software *
* for academic, research and internal business purposes only, without a *
* fee. Licensee may distribute the binary and source code (if released) *
* to third parties provided that the copyright notice and this statement *
* appears on all copies and that no charge is associated with such *
* copies. *
* *
* Licensee may make derivative works. However, if Licensee distributes *
* any derivative work based on or derived from the Software, then *
* Licensee will (1) notify NCSA regarding its distribution of the *
* derivative work, and (2) clearly notify users that such derivative *
* work is a modified version and not the original NCSA Mosaic *
* distributed by the UI. *
* *
* Any Licensee wishing to make commercial use of the Software should *
* contact the UI, c/o NCSA, to negotiate an appropriate license for such *
* commercial use. Commercial use includes (1) integration of all or *
* part of the source code into a product for sale or license by or on *
* behalf of Licensee to third parties, or (2) distribution of the binary *
* code or source code to third parties that need it to utilize a *
* commercial product sold or licensed by or on behalf of Licensee. *
* *
* UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR *
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED *
* WARRANTY. THE UI SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY THE *
* USERS OF THIS SOFTWARE. *
* *
* By using or copying this Software, Licensee agrees to abide by the *
* copyright law and all other applicable laws of the U.S. including, but *
* not limited to, export control laws, and the terms of this license. *
* UI shall have the right to terminate this license immediately by *
* written notice upon Licensee's breach of, or non-compliance with, any *
* of its terms. Licensee may be held legally responsible for any *
* copyright infringement that is caused or encouraged by Licensee's *
* failure to abide by the terms of this license. *
* *
* Comments and questions are welcome and can be sent to *
* mosaic-x@ncsa.uiuc.edu. *
****************************************************************************/
#include "../config.h"
#include <stdio.h>
#include <ctype.h>
#include "HTMLP.h"
#include "NoImage.xbm"
#include "DelayedImage.xbm"
#include "AnchoredImage.xbm"
/* SWP -- Now use eptr->bwidth -- 02/08/96
#define IMAGE_BORDER 2 */
#define IMAGE_DEFAULT_BORDER 2
ImageInfo no_image;
ImageInfo delayed_image;
ImageInfo anchored_image;
static int allocation_index[256];
#ifndef DISABLE_TRACE
extern int htmlwTrace;
#endif
extern int installed_colormap;
extern Colormap installed_cmap;
void CreateOrNotGC(HTMLWidget w);
/*
* Free all the colors in the default colormap that we have allocated so far.
*/
void
FreeColors(dsp, colormap)
Display *dsp;
Colormap colormap;
{
int i, j;
unsigned long pix;
for (i=0; i<256; i++)
{
if (allocation_index[i])
{
pix = (unsigned long)i;
/*
* Because X is stupid, we have to Free the color
* once for each time we've allocated it.
*/
for (j=0; j<allocation_index[i]; j++)
{
XFreeColors(dsp, colormap, &pix, 1, 0L);
}
}
allocation_index[i] = 0;
}
}
void
FreeBodyImages(hw)
HTMLWidget hw;
{
if (hw->html.bgmap_SAVE!=None) {
XFreePixmap(XtDisplay(hw),
hw->html.bgmap_SAVE);
hw->html.bgmap_SAVE=None;
}
if (hw->html.bgclip_SAVE!=None) {
XFreePixmap(XtDisplay(hw),
hw->html.bgclip_SAVE);
hw->html.bgclip_SAVE=None;
}
return;
}
/*
* Free up all the pixmaps allocated for this document.
*/
void
FreeImages(hw)
HTMLWidget hw;
{
struct ele_rec *eptr;
eptr = hw->html.formatted_elements;
while (eptr != NULL)
{
if ((eptr->type == E_IMAGE)&&(eptr->pic_data != NULL))
{
/*
* Don't free the no_image default image
*/
if ((eptr->pic_data->image != None)&&
(eptr->pic_data->image != delayed_image.image)&&
(eptr->pic_data->image != anchored_image.image)&&
(eptr->pic_data->image != no_image.image))
{
/*
* Don't free internal images
*/
if ((eptr->edata != NULL)&&
(strncmp(eptr->edata, INTERNAL_IMAGE,
strlen(INTERNAL_IMAGE)) == 0))
{
}
else
{
if (eptr->pic_data->image!=None) {
XFreePixmap(XtDisplay(hw),
eptr->pic_data->image);
eptr->pic_data->image = None;
}
if (eptr->pic_data->transparent && eptr->pic_data->clip!=None) {
XFreePixmap(XtDisplay(hw),
eptr->pic_data->clip);
eptr->pic_data->clip = None;
}
}
}
}
eptr = eptr->next;
}
/* Now take care of the background image! -- SWP */
if (hw->html.bgmap_SAVE!=None) {
XFreePixmap(XtDisplay(hw),
hw->html.bgmap_SAVE);
hw->html.bgmap_SAVE=None;
}
if (hw->html.bgclip_SAVE!=None) {
XFreePixmap(XtDisplay(hw),
hw->html.bgclip_SAVE);
hw->html.bgclip_SAVE=None;
}
}
/*
* Find the closest color by allocating it, or picking an already allocated
* color
*/
void
FindColor(dsp, colormap, colr)
Display *dsp;
Colormap colormap;
XColor *colr;
{
int i, match;
#ifdef MORE_ACCURATE
double rd, gd, bd, dist, mindist;
#else
int rd, gd, bd, dist, mindist;
#endif /* MORE_ACCURATE */
int cindx;
XColor tempcolr;
static XColor def_colrs[256];
static int have_colors = 0;
int NumCells;
tempcolr.pixel=colr->pixel;
tempcolr.red=colr->red;
tempcolr.green=colr->green;
tempcolr.blue=colr->blue;
tempcolr.flags=colr->flags;
tempcolr.pad=colr->pad;
match = XAllocColor(dsp, colormap, colr);
if (match == 0)
{
colr->pixel=tempcolr.pixel;
colr->red=tempcolr.red;
colr->green=tempcolr.green;
colr->blue=tempcolr.blue;
colr->flags=tempcolr.flags;
colr->pad=tempcolr.pad;
NumCells = DisplayCells(dsp, DefaultScreen(dsp));
if (!have_colors)
{
for (i=0; i<NumCells; i++)
{
def_colrs[i].pixel = i;
}
XQueryColors(dsp, colormap, def_colrs, NumCells);
have_colors = 1;
}
#ifdef MORE_ACCURATE
mindist = 196608.0; /* 256.0 * 256.0 * 3.0 */
cindx = (-1);
for (i=0; i<NumCells; i++)
{
rd = (def_colrs[i].red - colr->red) / 256.0;
gd = (def_colrs[i].green - colr->green) / 256.0;
bd = (def_colrs[i].blue - colr->blue) / 256.0;
dist = (rd * rd) +
(gd * gd) +
(bd * bd);
if (dist < mindist)
{
mindist = dist;
cindx = def_colrs[i].pixel;
if (dist == 0.0)
{
break;
}
}
}
#else
mindist = 196608; /* 256 * 256 * 3 */
cindx = (-1);
for (i=0; i<NumCells; i++)
{
rd = ((int)(def_colrs[i].red >> 8) -
(int)(colr->red >> 8));
gd = ((int)(def_colrs[i].green >> 8) -
(int)(colr->green >> 8));
bd = ((int)(def_colrs[i].blue >> 8) -
(int)(colr->blue >> 8));
dist = (rd * rd) +
(gd * gd) +
(bd * bd);
if (dist < mindist)
{
mindist = dist;
cindx = def_colrs[i].pixel;
if (dist == 0)
{
break;
}
}
}
#endif /* MORE_ACCURATE */
if (cindx==(-1)) {
colr->pixel=BlackPixel(dsp,
DefaultScreen(dsp));
colr->red = colr->green = colr->blue = 0;
}
else {
colr->pixel = cindx;
colr->red = def_colrs[cindx].red;
colr->green = def_colrs[cindx].green;
colr->blue = def_colrs[cindx].blue;
}
}
else
{
/*
* Keep a count of how many times we have allocated the
* same color, so we can properly free them later.
*/
allocation_index[colr->pixel]++;
/*
* If this is a new color, we've actually changed the default
* colormap, and may have to re-query it later.
*/
if (allocation_index[colr->pixel] == 1)
{
have_colors = 0;
}
}
}
static int
highbit(ul)
unsigned long ul;
{
/*
* returns position of highest set bit in 'ul' as an integer (0-31),
* or -1 if none.
*/
int i;
for (i=31; ((ul&0x80000000) == 0) && i>=0; i--, ul<<=1);
return i;
}
/*
#ifndef NEW
#define NEW
#endif
*/
#ifdef NEW
extern int bits_per_pixel(int dpy, int depth); /*this is in ../src/pixmaps.c*/
#endif
/*
* Make am image of appropriate depth for display from image data.
*/
XImage *
MakeImage(dsp, data, width, height, depth, img_info, clip)
Display *dsp;
unsigned char *data;
int width, height;
int depth;
ImageInfo *img_info;
int clip;
{
int linepad, shiftnum;
int shiftstart, shiftstop, shiftinc;
int bytesperline,bpp;
int temp;
int w, h;
XImage *newimage;
unsigned char *bit_data, *bitp, *datap;
Visual *theVisual;
int bmap_order;
unsigned long c;
int rshift, gshift, bshift;
#ifdef NEW
switch(bpp=bits_per_pixel(dsp,depth))
#else
switch(depth)
#endif
{
case 6:
case 8:
bit_data = (unsigned char *)malloc(width * height);
/*
bcopy(data, bit_data, (width * height));
*/
memcpy(bit_data, data, (width * height));
bytesperline = width;
if (clip) {
depth = 1;
}
newimage = XCreateImage(dsp,
DefaultVisual(dsp, DefaultScreen(dsp)),
depth, ZPixmap, 0, (char *)bit_data,
width, height, 8, bytesperline);
break;
case 1:
case 2:
case 4:
if (BitmapBitOrder(dsp) == LSBFirst)
{
shiftstart = 0;
shiftstop = 8;
#ifndef NEW
shiftinc = depth;
#else
shiftinc = bpp;
#endif
}
else
{
#ifndef NEW
shiftstart = 8 - depth;
shiftstop = -depth;
shiftinc = -depth;
#else
shiftstart = 8 - bpp;
shiftstop = -bpp;
shiftinc = -bpp;
#endif
}
linepad = 8 - (width % 8);
bit_data = (unsigned char *)malloc(((width + linepad) * height)
+ 1);
bitp = bit_data;
datap = data;
*bitp = 0;
shiftnum = shiftstart;
for (h=0; h<height; h++)
{
for (w=0; w<width; w++)
{
temp = *datap++ << shiftnum;
*bitp = *bitp | temp;
shiftnum = shiftnum + shiftinc;
if (shiftnum == shiftstop)
{
shiftnum = shiftstart;
bitp++;
*bitp = 0;
}
}
for (w=0; w<linepad; w++)
{
shiftnum = shiftnum + shiftinc;
if (shiftnum == shiftstop)
{
shiftnum = shiftstart;
bitp++;
*bitp = 0;
}
}
}
#ifndef NEW
bytesperline = (width + linepad) * depth / 8;
#else
bytesperline = (width + linepad) * bpp / 8;
#endif
newimage = XCreateImage(dsp,
DefaultVisual(dsp, DefaultScreen(dsp)),
depth, ZPixmap, 0, (char *)bit_data,
(width + linepad), height, 8, bytesperline);
break;
/*
* WARNING: This depth 16 code is donated code for 16 but
* TrueColor displays. I have no access to such displays, so I
* can't really test it.
* Donated by - nosmo@ximage.com
*/
case 16:
bit_data = (unsigned char *)malloc(width * height * 2);
bitp = bit_data;
datap = data;
theVisual = DefaultVisual(dsp, DefaultScreen(dsp));
rshift = 15 - highbit(theVisual->red_mask);
gshift = 15 - highbit(theVisual->green_mask);
bshift = 15 - highbit(theVisual->blue_mask);
bmap_order = BitmapBitOrder(dsp);
for (w = (width * height); w > 0; w--)
{
temp = (((img_info->reds[(int)*datap] >> rshift) &
theVisual->red_mask) |
((img_info->greens[(int)*datap] >> gshift) &
theVisual->green_mask) |
((img_info->blues[(int)*datap] >> bshift) &
theVisual->blue_mask));
if (bmap_order == MSBFirst)
{
*bitp++ = (temp >> 8) & 0xff;
*bitp++ = temp & 0xff;
}
else
{
*bitp++ = temp & 0xff;
*bitp++ = (temp >> 8) & 0xff;
}
datap++;
}
newimage = XCreateImage(dsp,
DefaultVisual(dsp, DefaultScreen(dsp)),
depth, ZPixmap, 0, (char *)bit_data,
width, height, 16, 0);
break;
case 24:
#ifdef NEW
case 32:
#endif
bit_data = (unsigned char *)malloc(width * height * 4);
theVisual = DefaultVisual(dsp, DefaultScreen(dsp));
rshift = highbit(theVisual->red_mask) - 7;
gshift = highbit(theVisual->green_mask) - 7;
bshift = highbit(theVisual->blue_mask) - 7;
bmap_order = BitmapBitOrder(dsp);
bitp = bit_data;
datap = data;
for (w = (width * height); w > 0; w--)
{
c =
(((img_info->reds[(int)*datap] >> 8) & 0xff) << rshift) |
(((img_info->greens[(int)*datap] >> 8) & 0xff) << gshift) |
(((img_info->blues[(int)*datap] >> 8) & 0xff) << bshift);
datap++;
if (bmap_order == MSBFirst)
{
*bitp++ = (unsigned char)((c >> 24) & 0xff);
*bitp++ = (unsigned char)((c >> 16) & 0xff);
*bitp++ = (unsigned char)((c >> 8) & 0xff);
*bitp++ = (unsigned char)(c & 0xff);
}
else
{
*bitp++ = (unsigned char)(c & 0xff);
*bitp++ = (unsigned char)((c >> 8) & 0xff);
*bitp++ = (unsigned char)((c >> 16) & 0xff);
*bitp++ = (unsigned char)((c >> 24) & 0xff);
}
}
newimage = XCreateImage(dsp,
DefaultVisual(dsp, DefaultScreen(dsp)),
depth, ZPixmap, 0, (char *)bit_data,
width, height, 32, 0);
break;
default:
#ifndef DISABLE_TRACE
if (htmlwTrace) {
fprintf(stderr, "Don't know how to format image for display of depth %d\n", depth);
}
#endif
return(NULL);
}
return(newimage);
}
int
AnchoredHeight(hw)
HTMLWidget hw;
{
return((int)(AnchoredImage_height + IMAGE_DEFAULT_BORDER));
}
char *
IsMapForm(hw)
HTMLWidget hw;
{
char *str;
str = (char *)malloc(strlen("ISMAP Form") + 1);
if (str != NULL)
{
strcpy(str, "ISMAP Form");
}
return(str);
}
int
IsIsMapForm(hw, href)
HTMLWidget hw;
char *href;
{
if ((href != NULL)&&(strcmp(href, "ISMAP Form") == 0))
{
return(1);
}
else
{
return(0);
}
}
char *
DelayedHRef(hw)
HTMLWidget hw;
{
char *str;
str = (char *)malloc(strlen("Delayed Image") + 1);
if (str != NULL)
{
strcpy(str, "Delayed Image");
}
return(str);
}
int
IsDelayedHRef(hw, href)
HTMLWidget hw;
char *href;
{
if ((href != NULL)&&(strcmp(href, "Delayed Image") == 0))
{
return(1);
}
else
{
return(0);
}
}
Pixmap
DelayedImage(hw, anchored)
HTMLWidget hw;
Boolean anchored;
{
if (delayed_image.image == None)
{
delayed_image.transparent=0;
delayed_image.image = XCreatePixmapFromBitmapData(
XtDisplay(hw->html.view),
XtWindow(hw->html.view), DelayedImage_bits,
DelayedImage_width, DelayedImage_height,
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
#ifdef MOTIF
hw->manager.foreground,
#else
hw->html.foreground,
#endif /* MOTIF */
hw->core.background_pixel,
DefaultDepthOfScreen(XtScreen(hw)));
}
if ((anchored == True)&&(anchored_image.image == None))
{
Pixmap pix;
anchored_image.transparent=0;
anchored_image.image = XCreatePixmapFromBitmapData(
XtDisplay(hw->html.view),
XtWindow(hw->html.view), AnchoredImage_bits,
AnchoredImage_width, AnchoredImage_height,
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
#ifdef MOTIF
hw->manager.foreground,
#else
hw->html.foreground,
#endif /* MOTIF */
hw->core.background_pixel,
DefaultDepthOfScreen(XtScreen(hw)));
pix = XCreatePixmap(
XtDisplay(hw->html.view),
XtWindow(hw->html.view),
DelayedImage_width,
(DelayedImage_height + AnchoredImage_height +
IMAGE_DEFAULT_BORDER),
DefaultDepthOfScreen(XtScreen(hw)));
XSetForeground(XtDisplay(hw), hw->html.drawGC,
hw->core.background_pixel);
XFillRectangle(XtDisplay(hw->html.view), pix,
hw->html.drawGC, 0, 0,
DelayedImage_width,
(DelayedImage_height + AnchoredImage_height +
IMAGE_DEFAULT_BORDER));
XCopyArea(XtDisplay(hw->html.view),
anchored_image.image, pix, hw->html.drawGC,
0, 0, AnchoredImage_width, AnchoredImage_height,
0, 0);
XCopyArea(XtDisplay(hw->html.view),
delayed_image.image, pix, hw->html.drawGC,
0, 0, DelayedImage_width, DelayedImage_height,
0, (AnchoredImage_height + IMAGE_DEFAULT_BORDER));
XFreePixmap(XtDisplay(hw->html.view), anchored_image.image);
anchored_image.image = pix;
return(anchored_image.image);
}
return(delayed_image.image);
}
ImageInfo *
DelayedImageData(hw, anchored)
HTMLWidget hw;
Boolean anchored;
{
delayed_image.delayed = 1;
delayed_image.internal = 0;
delayed_image.fetched = 0;
delayed_image.width = DelayedImage_width;
delayed_image.height = DelayedImage_height;
delayed_image.num_colors = 0;
delayed_image.reds = NULL;
delayed_image.greens = NULL;
delayed_image.blues = NULL;
delayed_image.image_data = NULL;
delayed_image.clip_data = NULL;
delayed_image.image = None;
delayed_image.clip = None;
delayed_image.transparent = 0;
if (anchored == True)
{
anchored_image.delayed = 0;
anchored_image.internal = 0;
anchored_image.fetched = 0;
anchored_image.width = DelayedImage_width;
anchored_image.height = DelayedImage_height +
AnchoredImage_height + IMAGE_DEFAULT_BORDER;
anchored_image.num_colors = 0;
anchored_image.reds = NULL;
anchored_image.greens = NULL;
anchored_image.blues = NULL;
anchored_image.image_data = NULL;
anchored_image.image = None;
anchored_image.clip_data = NULL;
anchored_image.clip = None;
anchored_image.transparent = 0;
return(&anchored_image);
}
return(&delayed_image);
}
Pixmap
NoImage(hw)
HTMLWidget hw;
{
if (no_image.image == None)
{
no_image.transparent=0;
no_image.image = XCreatePixmapFromBitmapData(
XtDisplay(hw),
XtWindow(hw->html.view), NoImage_bits,
NoImage_width, NoImage_height,
/*
* Without motif we use our own foreground resource instead of
* using the manager's
*/
#ifdef MOTIF
hw->manager.foreground,
#else
hw->html.foreground,
#endif /* MOTIF */
hw->core.background_pixel,
DefaultDepthOfScreen(XtScreen(hw)));
}
return(no_image.image);
}
ImageInfo *
NoImageData(hw)
HTMLWidget hw;
{
no_image.delayed = 0;
no_image.internal = 0;
no_image.fetched = 0;
no_image.width = NoImage_width;
no_image.height = NoImage_height;
no_image.num_colors = 0;
no_image.reds = NULL;
no_image.greens = NULL;
no_image.blues = NULL;
no_image.image_data = NULL;
no_image.clip_data = NULL;
no_image.image = None;
no_image.clip = None;
no_image.transparent=0;
return(&no_image);
}
Pixmap
InfoToImage(hw, img_info, clip)
HTMLWidget hw;
ImageInfo *img_info;
int clip;
{
int i, size;
int delta, not_right_col, not_last_row;
Pixmap Img;
XImage *tmpimage;
XColor tmpcolr;
int *Mapping;
unsigned char *tmpdata;
unsigned char *ptr;
unsigned char *ptr2;
int Vclass;
XVisualInfo vinfo, *vptr;
Boolean need_to_dither;
unsigned long black_pixel;
unsigned long white_pixel;
int depth;
CreateOrNotGC(hw);
/* find the visual class. */
vinfo.visualid = XVisualIDFromVisual(DefaultVisual(XtDisplay(hw),
DefaultScreen(XtDisplay(hw))));
vptr = XGetVisualInfo(XtDisplay(hw), VisualIDMask, &vinfo, &i);
Vclass = vptr->class;
depth=vptr->depth;
if (clip) {
need_to_dither = False;
}
else if (vptr->depth == 1)
{
need_to_dither = True;
black_pixel = BlackPixel(XtDisplay(hw),
DefaultScreen(XtDisplay(hw)));
white_pixel = WhitePixel(XtDisplay(hw),
DefaultScreen(XtDisplay(hw)));
}
else
{
need_to_dither = False;
}
XFree((char *)vptr);
Mapping = (int *)malloc(img_info->num_colors * sizeof(int));
if (!clip) {
for (i=0; i < img_info->num_colors; i++)
{
tmpcolr.red = img_info->reds[i];
tmpcolr.green = img_info->greens[i];
tmpcolr.blue = img_info->blues[i];
tmpcolr.flags = DoRed|DoGreen|DoBlue;
if ((Vclass == TrueColor) || (Vclass == DirectColor))
{
Mapping[i] = i;
}
else if (need_to_dither == True)
{
Mapping[i] = ((tmpcolr.red>>5)*11 +
(tmpcolr.green>>5)*16 +
(tmpcolr.blue>>5)*5) / (65504/64);
}
else
{
FindColor(XtDisplay(hw),
(installed_colormap ?
installed_cmap :
DefaultColormapOfScreen(XtScreen(hw))),
&tmpcolr);
Mapping[i] = tmpcolr.pixel;
}
}
}
/*
* Special case: For 2 color non-black&white images, instead
* of 2 dither patterns, we will always drop them to be
* black on white.
*/
if ((need_to_dither == True)&&(img_info->num_colors == 2))
{
if (Mapping[0] < Mapping[1])
{
Mapping[0] = 0;
Mapping[1] = 64;
}
else
{
Mapping[0] = 64;
Mapping[1] = 0;
}
}
size = img_info->width * img_info->height;
if (size == 0)
{
tmpdata = NULL;
}
else
{
tmpdata = (unsigned char *)malloc(size);
}
if (tmpdata == NULL)
{
tmpimage = NULL;
Img = None;
}
else
{
if (clip) {
ptr = img_info->clip_data;
}
else {
ptr = img_info->image_data;
}
ptr2 = tmpdata;
if (need_to_dither == True)
{
int cx, cy;
if (clip) {
for (ptr2 = tmpdata, ptr = img_info->clip_data;
ptr2 < tmpdata+(size-1); ptr2++, ptr++) {
*ptr2 = Mapping[(int)*ptr];
}
}
else {
for (ptr2 = tmpdata, ptr = img_info->image_data;
ptr2 < tmpdata+(size-1); ptr2++, ptr++) {
*ptr2 = Mapping[(int)*ptr];
}
}
ptr2 = tmpdata;
for (cy=0; cy < img_info->height; cy++)
{
for (cx=0; cx < img_info->width; cx++)
{
/*
* Assume high numbers are
* really negative.
*/
if (*ptr2 > 128)
{
*ptr2 = 0;
}
if (*ptr2 > 64)
{
*ptr2 = 64;
}
/*
* Traditional Floyd-Steinberg
*/
if (*ptr2 < 32)
{
delta = *ptr2;
*ptr2 = black_pixel;
}
else
{
delta = *ptr2 - 64;
*ptr2 = white_pixel;
}
if (not_right_col =
(cx < (img_info->width-1)))
{
*(ptr2+1) += delta*7 >> 4;
}
if (not_last_row =
(cy < (img_info->height-1)))
{
(*(ptr2+img_info->width)) +=
delta*5 >> 4;
}
if (not_right_col && not_last_row)
{
(*(ptr2+img_info->width+1)) +=
delta >> 4;
}
if (cx && not_last_row)
{
(*(ptr2+img_info->width-1)) +=
delta*3 >> 4;
}
ptr2++;
}
}
} /* end if (need_to_dither==True) */
else
{
for (i=0; i < size; i++)
{
if (clip) {
*ptr2++ = *ptr;
}
else {
*ptr2++ = (unsigned char)Mapping[(int)*ptr];
}
ptr++;
}
}
depth=DefaultDepthOfScreen(XtScreen(hw));
tmpimage = MakeImage(XtDisplay(hw), tmpdata,
img_info->width, img_info->height,
depth, img_info, clip);
/* Caught by Purify; should be OK. */
free (tmpdata);
Img = XCreatePixmap(XtDisplay(hw),
XtWindow(hw->html.view),
img_info->width, img_info->height,
depth);
}
if ((tmpimage == NULL)||(Img == None))
{
if (tmpimage != NULL)
{
XDestroyImage(tmpimage);
}
if (Img != None)
{
XFreePixmap(XtDisplay(hw), Img);
}
img_info->width = NoImage_width;
img_info->height = NoImage_height;
Img = NoImage(hw);
}
else
{
XPutImage(XtDisplay(hw), Img, hw->html.drawGC, tmpimage, 0, 0,
0, 0, img_info->width, img_info->height);
XDestroyImage(tmpimage);
}
/* Caught by Purify; should be OK. */
free((char *)Mapping);
return(Img);
}
|