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 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
|
/*
* plotPixels.c --
*
* This file contains the procedures that generate pix files. each file is
* a sequence of unsigned chars, each triplet of chars representing a red,
* green and blue value between 0 and 255 for a pixel. Pixels go across left
* to right, and down the image.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/plot/plotPixels.c,v 1.2 2008/06/01 18:37:45 tim Exp $";
#endif /* not lint */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "utils/magic.h"
#include "utils/geometry.h"
#include "utils/geofast.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"
#include "dbwind/dbwtech.h"
#include "utils/malloc.h"
#include "plot/plotInt.h"
#include "windows/windows.h"
#include "commands/commands.h"
#include "textio/textio.h"
#include "utils/utils.h"
#include "utils/tech.h"
#include "utils/signals.h"
#include "utils/styles.h"
#include "graphics/graphics.h"
#include "dbwind/dbwind.h"
#ifdef LLNL
/* forward declarations */
void PlotPixFatLine();
/*
* ----------------------------------------------------------------------------
* The parameters below control various aspects of the plotting
* process. The initial values are defaults for the pixels
* printer. However, many of them can be modified by users
* with the "plot option" command.
* ----------------------------------------------------------------------------
*/
int PlotPixWidth = 512; /* Number of dots across image.
*/
int PlotPixHeight = 512; /* Height of swath to generate at one time,
* in dots.
*/
/* Directory in which to create temporary file to hold raster: */
static char *defaultDirectory = "/usr/tmp";
extern char *PlotTempDirectory;
/*
* ----------------------------------------------------------------------------
* The variables below are shared between the top-level pixels
* plotting procedure and the lower-level search functions. They
* contain specific information about how to generate the current
* plot. There area three coordinate systems of interest here:
*
* 1. Magic root coordinates.
* 2. Raster coordinates: based on printer pixels, one unit per pixel,
* where (0,0) corresponds to the lower-leftmost dot that will be
* printed.
* 3. Swath coordinates: the raster will be much too large to keep in
* memory all at once, so it's generated in a series of horizontal
* swaths. The stippling routines all work in swath-relative
* coordinates, which are the same as raster coordinates except for
* a y-displacement (swathY below).
* ----------------------------------------------------------------------------
*/
static PixRaster *pixRasterSwath = NULL; /* Raster used to hold current swath. */
extern Point plotLL; /* Point in root Magic coords that corresponds
* to (0,0) in raster coordinates.
*/
extern int swathY; /* The y-coordinate in raster coordinates that
* corresponds to (0,0) in swath coords. It's
* always >= 0.
*/
int scale; /* How many (2**scaleShift)-ths of a pixel
* correspond to one Magic unit.
*/
extern int scaleShift; /* The idea is that one Magic unit is equal
* to scale/(2**scaleShift) pixels.
*/
static Rect rootClip; /* Total root area of the plot. Used for
* clipping.
*/
static Rect swathClip; /* Rectangle used for clipping to the area of
* the current swath. This is in swath
* coordinates.
*/
static int curStyle; /* Current style being processed. */
static TileTypeBitMask *curMask; /* Mask of layers currently being stippled.
* This is the AND of the mask from curStyle
* and the layers that the user wants plotted.
*/
static int crossSize; /* Length of each arm of the crosses used
* to draw labels, in pixel units.
*/
static RasterFont *labelPixFont; /* Font to use when rendering labels. */
static RasterFont *cellNamePixFont; /* Font to use when rendering cell names. */
static RasterFont *cellIdPixFont; /* Font to use when rendering cell ids. */
#endif /* LLNL */
/*
* ----------------------------------------------------------------------------
* PlotPixTechInit --
*
* Called once at beginning of technology file read-in to initialize
* data structures.
*
* Results:
* None.
*
* Side effects:
* Clears out the list of things to plot.
* ----------------------------------------------------------------------------
*/
void
PlotPixTechInit()
{
/* most intersting stuff is done by PlotVersTechInit -- setting default
* plot directory, default font names, etc.
*/
}
/*
* ----------------------------------------------------------------------------
* PlotPixTechLine --
*
* This procedure is invoked by the technology module once for
* each line in the "pixels" subsection of the "plot" section
* of the technology file.
*
* Results:
* Always returns TRUE (otherwise the technology module would
* abort Magic with a fatal error).
*
* Side effects:
* Builds up the table of pixels styles.
* ----------------------------------------------------------------------------
*/
/* ARGSUSED */
bool
PlotPixTechLine(sectionName, argc, argv)
char *sectionName; /* Name of this section (unused). */
int argc; /* Number of arguments on line. */
char *argv[]; /* Pointers to fields of line. */
{
return TRUE;
}
#ifdef LLNL
/*
* ----------------------------------------------------------------------------
*
* PlotPixPoint --
*
* Sets a particular pixel of a PixRaster.
*
* Results:
* None.
*
* Side effects:
* If x and y lie inside the raster then the pixel that they select
* is set to 1. If x or y is outside the raster area then nothing
* happens.
*
* ----------------------------------------------------------------------------
*/
void
PlotPixPoint(raster, x, y, style)
PixRaster *raster; /* Raster containing pixel to be
* filled.
*/
int x, y; /* Coordinates of pixel. */
int style; /* style to render the pixel with. */
{
char *rp; /* ptr to pixel to change. */
if ((x < 0) || (x >= raster->pix_width)) return;
y = (raster->pix_height - 1) - y;
if ((y < 0) || (y >= raster->pix_height)) return;
rp = raster->pix_pixels + x + y*raster->pix_width;
*rp = (*rp & ~(GrStyleTable[style].mask)) |
(GrStyleTable[style].color & GrStyleTable[style].mask);
}
/*
* ----------------------------------------------------------------------------
*
* PlotPixArbLine --
*
* Draws a one-pixel-wide line between two points.
*
* Results:
* None.
*
* Side effects:
* A line is drawn between pixels src and dst. Only the portion
* of the line that lies inside the raster is drawn; the endpoints
* may lie outside the raster (this feature is necessary to draw
* straight lines that cross multiple swaths).
*
* ----------------------------------------------------------------------------
*/
void
PlotPixArbLine(raster, src, dst, style)
Raster *raster; /* Where to render the line. */
Point *src; /* One endpoint of line, in raster coords. */
Point *dst; /* The other endpoint, in raster coords. */
int style; /* Display style to render this line in */
{
int x, y, dx, dy, xinc, incr1, incr2, d, done;
/* Compute the total x- and y-motions, and arrange for the line to be
* drawn in increasing order of y-coordinate.
*/
dx = dst->p_x - src->p_x;
dy = dst->p_y - src->p_y;
if (dy < 0)
{
dy = -dy;
dx = -dx;
x = dst->p_x;
y = dst->p_y;
dst = src;
}
else
{
x = src->p_x;
y = src->p_y;
}
/* The code below is just the Bresenham algorithm from Foley and
* Van Dam (pp. 435), modified slightly so that it can work in
* all directions.
*/
if (dx < 0)
{
xinc = -1;
dx = -dx;
}
else xinc = 1;
if (dx >= dy)
{
d = 2*dy - dx;
incr1 = 2*dy;
incr2 = 2*(dy - dx);
done = dst->p_x;
for ( ; x != done ; x += xinc)
{
PlotPixPoint(raster, x, y, style);
if (d < 0)
d += incr1;
else
{
d += incr2;
y += 1;
}
}
}
else
{
d = 2*dx - dy;
incr1 = 2*dx;
incr2 = 2*(dx - dy);
done = dst->p_y;
for ( ; y != done ; y += 1)
{
PlotPixPoint(raster, x, y, style);
if (d < 0)
d += incr1;
else
{
d += incr2;
x += xinc;
}
}
}
PlotPixPoint(raster, x, y, style);
}
/*
* ----------------------------------------------------------------------------
*
* plotPixLine --
*
* This procedure plots a line of a given thickness.
*
* Results:
* None.
*
* Side effects:
* The current raster is modified.
*
* ----------------------------------------------------------------------------
*/
void
plotPixLine(area, widen, style)
Rect *area; /* The "corner" points of this rectangle
* give the endpoints of the line, in
* Magic root coordinates.
*/
int widen; /* Amount by which to widen line. 0 means
* line is drawn one pixel wide, 1 means 3
* pixels wide, etc.
*/
int style; /* style in which to render the line */
{
Rect swathArea;
plotTransToSwath(area, &swathArea);
/* Handle Manhattan lines using rectangle-drawing, since it's faster. */
if ((swathArea.r_xbot == swathArea.r_xtop) ||
(swathArea.r_ybot == swathArea.r_ytop))
{
GEO_EXPAND(&swathArea, widen, &swathArea);
GEOCLIP(&swathArea, &swathClip);
if ((swathArea.r_xbot <= swathArea.r_xtop) &&
(swathArea.r_ybot <= swathArea.r_ytop))
plotFillPixRaster(pixRasterSwath, &swathArea,style, GR_STSOLID);
}
else
PlotPixFatLine(pixRasterSwath,
&swathArea.r_ll, &swathArea.r_ur,
widen, curStyle);
}
/*
* ----------------------------------------------------------------------------
*
* PlotPixFatLine --
*
* Draws a line many pixels wide between two points.
*
* Results:
* None.
*
* Side effects:
* A line is drawn between pixels src and dst. Only the portion
* of the line that lies inside the raster is drawn; the endpoints
* may lie outside the raster (this feature is necessary to draw
* straight lines that cross multiple swaths). The line is drawn
* several pixels wide, as determined by the "widen" parameter.
* The ends of the line are square, not rounded, which may cause
* upleasant effects for some uses. If the line is Manhattan,
* this procedure is very inefficient: it's better to use the
* PlotFillPixRaster procedure.
*
* ----------------------------------------------------------------------------
*/
void
PlotPixFatLine(raster, src, dst, widen, style)
PixRaster *raster; /* Where to render the line. */
Point *src; /* One endpoint of line, in raster coords. */
Point *dst; /* The other endpoint, in raster coords. */
int widen; /* How much to widen the line. 0 means the
* line is one pixel wide, 1 means it's 3
* pixels wide, and so on.
*/
int style;
{
double dx, dy, x, y;
int nLines;
/* Just draw (2*widen) + 1 lines spaced about one pixel apart.
* The first lines here compute how far apart to space the lines.
*/
nLines = (2*widen) + 1;
x = dst->p_x - src->p_x;
y = dst->p_y - src->p_y;
dy = sqrt(x*x + y*y);
dx = y/dy;
dy = -x/dy;
x = -dy*(widen);
y = dx*(widen);
for (x = -dx*widen, y = -dy*widen;
nLines > 0;
nLines -= 1, x += dx, y += dy)
{
Point newSrc, newDst;
if (x > 0)
newSrc.p_x = (x + .5);
else newSrc.p_x = (x - .5);
if (y > 0)
newSrc.p_y = (y + .5);
else newSrc.p_y = (y - .5);
newDst.p_x = dst->p_x + newSrc.p_x;
newDst.p_y = dst->p_y + newSrc.p_y;
newSrc.p_x += src->p_x;
newSrc.p_y += src->p_y;
PlotPixArbLine(raster, &newSrc, &newDst, style);
}
}
/*
* ----------------------------------------------------------------------------
*
* plotPixRect --
*
* This procedure takes a rectangular area, given in Magic root
* coordinates, and draws it as an outline of a given thickness.
*
* Results:
* None.
*
* Side effects:
* Modifies raster.
*
* ----------------------------------------------------------------------------
*/
void
plotPixRect(area, widen, style)
Rect *area; /* Rectangular area to draw, in root
* coordinates.
*/
int widen; /* If zero, rectangular outline is drawn
* one pixel wide. If non-zero, the outline
* is widened by this many units on each
* side.
*/
int style; /* style in which to render the rect */
{
Rect side;
/* First, the bottom side. */
if (area->r_xbot != area->r_xtop)
{
side = *area;
side.r_ytop = side.r_ybot;
plotPixLine(&side, widen,style);
/* Now the top side, if it doesn't coincide with the bottom. */
if (area->r_ybot != area->r_ytop)
{
side = *area;
side.r_ybot = side.r_ytop;
plotPixLine(&side, widen, style);
}
}
/* Now do the left side. */
if (area->r_ybot != area->r_ytop)
{
side = *area;
side.r_xtop = side.r_xbot;
plotPixLine(&side, widen, style);
/* Now the right side, if it doesn't coincide with the left. */
if (area->r_xbot != area->r_xtop)
{
side = *area;
side.r_xbot = side.r_xtop;
plotPixLine(&side, widen, style);
}
}
}
/*
* ----------------------------------------------------------------------------
*
* plotPixTile --
*
* This procedure is called for paint tiles. It renders each tile
* in the current style, in the current swath.
*
* Results:
* Always returns 0 to keep the search alive.
*
* Side effects:
* Modifies the raster area.
*
* ----------------------------------------------------------------------------
*/
int
plotPixTile(tile, cxp)
Tile *tile; /* Tile that's of type to be output. */
TreeContext *cxp; /* Describes search in progress. */
{
Rect tileArea, rootArea, swathArea;
Transform *trans = &cxp->tc_scx->scx_trans;
/* Transform tile coords to root coords and then to swath coords. */
TITORECT(tile, &tileArea);
#ifdef DEBUG
TxPrintf("PlotPixTile: (%d,%d)(%d,%d) ",
tileArea.r_xbot,
tileArea.r_ybot,
tileArea.r_xtop,
tileArea.r_ytop);
#endif
GEOTRANSRECT(trans, &tileArea, &rootArea);
plotTransToSwath(&rootArea, &swathArea);
/* Clip and then fill with the color. */
GEOCLIP(&swathArea, &swathClip);
if (swathArea.r_xbot > swathArea.r_xtop) return 0;
if (swathArea.r_ybot > swathArea.r_ytop) return 0;
#ifdef DEBUG
TxPrintf(">> (%d,%d)(%d,%d)\n",
swathArea.r_xbot,
swathArea.r_ybot,
swathArea.r_xtop,
swathArea.r_ytop);
#endif
/* if the current style's fill-mode is GR_STOUTLINE or GR_STCROSS
* we cannot let plotFillPixRaster render the tile, since we get
* extra horizontal lines at swath boundaries. Too bad, it was a
* neat idea, but we cannot force the user to render the entire
* image at once (*sigh*)
*/
if((GrStyleTable[curStyle].fill == GR_STOUTLINE) ||
(GrStyleTable[curStyle].fill == GR_STCROSS))
{ /* draw the outline */
plotPixRect(&tileArea, 1, curStyle);
}
if (GrStyleTable[curStyle].fill == GR_STCROSS)
{ /* draw the cross */
Point src, dst;
src = swathArea.r_ll;
dst = swathArea.r_ur;
PlotPixFatLine(pixRasterSwath, &src, &dst, 1, curStyle);
src.p_y = swathArea.r_ytop;
dst.p_y = swathArea.r_ybot;
PlotPixFatLine(pixRasterSwath, &src, &dst, 1, curStyle);
}
plotFillPixRaster(pixRasterSwath, &swathArea, curStyle, -1);
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPixLabel --
*
* This procedure is invoked for labels. It generates bits to
* display the label in the current raster swath.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
* Modifies the raster.
*
* ----------------------------------------------------------------------------
*/
int
plotPixLabel(scx, label)
SearchContext *scx; /* Describes state of search when label
* was found.
*/
Label *label; /* Label that was found. */
{
Rect rootArea, swathArea, labelSize;
Point point;
int pos;
/* Translate the label's area and relative position to root
* coordinates and then to swath coordinates. Figure out
* the point relative to which the label is to be positioned.
*/
GeoTransRect(&scx->scx_trans, &label->lab_rect, &rootArea);
plotTransToSwath(&rootArea, &swathArea);
pos = GeoTransPos(&scx->scx_trans, label->lab_just);
PlotTextSize(labelPixFont, label->lab_text, &labelSize);
switch (pos)
{
case GEO_NORTH:
case GEO_NORTHEAST:
case GEO_NORTHWEST:
point.p_y = swathArea.r_ytop + crossSize + 2 - labelSize.r_ybot;
break;
case GEO_CENTER:
case GEO_WEST:
case GEO_EAST:
point.p_y = (swathArea.r_ytop + swathArea.r_ybot)/2;
point.p_y -= (labelSize.r_ytop + labelSize.r_ybot)/2;
break;
case GEO_SOUTH:
case GEO_SOUTHEAST:
case GEO_SOUTHWEST:
point.p_y = swathArea.r_ybot - crossSize - 2 - labelSize.r_ytop;
break;
}
switch (pos)
{
case GEO_WEST:
case GEO_NORTHWEST:
case GEO_SOUTHWEST:
point.p_x = swathArea.r_xbot - crossSize - 2 - labelSize.r_xtop;
break;
case GEO_CENTER:
case GEO_NORTH:
case GEO_SOUTH:
point.p_x = (swathArea.r_xtop + swathArea.r_xbot)/2;
point.p_x -= (labelSize.r_xtop + labelSize.r_xbot)/2;
break;
case GEO_EAST:
case GEO_NORTHEAST:
case GEO_SOUTHEAST:
point.p_x = swathArea.r_xtop + crossSize + 2 - labelSize.r_xbot;
break;
}
/* Output lines marking the label's area. Different things are
* done depending on whether the label is a point, a line, or an
* area.
*/
if ((rootArea.r_xbot == rootArea.r_xtop) &&
(rootArea.r_ybot == rootArea.r_ytop))
{
Rect tmp;
/* Point label. Output a cross. */
tmp = swathArea;
tmp.r_ytop += crossSize;
tmp.r_ybot -= crossSize;
GEO_EXPAND(&tmp, 1, &tmp);
GEOCLIP(&tmp, &swathClip);
if ((tmp.r_xbot <= tmp.r_xtop) &&
(tmp.r_ybot <= tmp.r_ytop))
plotFillPixRaster(pixRasterSwath, &tmp, STYLE_LABEL, GR_STSOLID);
tmp = swathArea;
tmp.r_xtop += crossSize;
tmp.r_xbot -= crossSize;
GEO_EXPAND(&tmp, 1, &tmp);
GEOCLIP(&tmp, &swathClip);
if ((tmp.r_xbot <= tmp.r_xtop) &&
(tmp.r_ybot <= tmp.r_ytop))
plotFillPixRaster(pixRasterSwath, &tmp,STYLE_LABEL, GR_STSOLID);
}
else
{
/* Line or rectangle. Draw outline.
* plotFillPixRaster will outline the area if STYLE_LABEL has
* fill mode GR_STOUTLINE.
* Cute, berry, but it loses when the rect crosses a swath boundary.
*/
GEOCLIP(&swathArea, &swathClip);
plotPixRect(&rootArea, 1, STYLE_LABEL);
/* plotFillPixRaster(pixRasterSwath, &swathArea, STYLE_LABEL, -1); */
}
/* Output the text for the label. */
labelSize.r_xbot += point.p_x - 1;
labelSize.r_xtop += point.p_x + 1;
labelSize.r_ybot += point.p_y - 1;
labelSize.r_ytop += point.p_y + 1;
PlotPixRasterText(pixRasterSwath, &swathClip,
labelPixFont, label->lab_text, &point, STYLE_LABEL);
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPixCell --
*
* This procedure is invoked for unexpanded cells.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
* The raster is modified to depict the cell's boundary,
* name, and instance id.
*
* ----------------------------------------------------------------------------
*/
int
plotPixCell(scx)
SearchContext *scx; /* Describes cell whose bbox is to
* be plotted.
*/
{
char idName[100];
Rect rootArea, swathArea, textSize;
Point point;
CellDef *def;
/* Convert the cell's bounding box to root coordinates and then
* draw the outline.
*/
def = scx->scx_use->cu_def;
GeoTransRect(&scx->scx_trans, &def->cd_bbox, &rootArea);
plotPixRect(&rootArea, 1, STYLE_BLACK);
if (!PlotShowCellNames)
return (0);
/* Output the cell's name and id text. */
plotTransToSwath(&rootArea, &swathArea);
PlotTextSize(cellNamePixFont, def->cd_name, &textSize);
point.p_x = (swathArea.r_xtop + swathArea.r_xbot)/2;
point.p_x -= (textSize.r_xtop + textSize.r_xbot)/2;
point.p_y = (2*swathArea.r_ytop + swathArea.r_ybot)/3;
point.p_y -= (textSize.r_ytop + textSize.r_ybot)/2;
PlotPixRasterText(pixRasterSwath, &swathClip,
cellNamePixFont, def->cd_name, &point, STYLE_BBOX);
(void) DBPrintUseId(scx, idName, 100, TRUE);
PlotTextSize(cellIdPixFont, idName, &textSize);
point.p_x = (swathArea.r_xtop + swathArea.r_xbot)/2;
point.p_x -= (textSize.r_xtop + textSize.r_xbot)/2;
point.p_y = (swathArea.r_ytop + 2*swathArea.r_ybot)/3;
point.p_y -= (textSize.r_ytop + textSize.r_ybot)/2;
PlotPixRasterText(pixRasterSwath, &swathClip,
cellIdPixFont, idName, &point, STYLE_BBOX);
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* Plotpixels --
*
* This procedure generates a pix file usable by various programs
* that produce images on Dicomed cameras and so on.
*
* Results:
* None.
*
* Side effects:
* Lots and lots of disk space is chewed up by the file.
*
* ----------------------------------------------------------------------------
*/
void
PlotPixels(scx, layers, xMask, width)
SearchContext *scx; /* The use and area and transformation
* in this describe what to plot.
*/
TileTypeBitMask *layers; /* Tells what layers to plot. Only
* paint layers in this mask, and also
* expanded according to xMask, are
* plotted. If L_LABELS is set, then
* labels on the layers are also
* plotted, if expanded according to
* xMask. If L_CELL is set, then
* subcells that are unexpanded
* according to xMask are plotted as
* bounding boxes.
*/
int xMask; /* An expansion mask, used to indicate
* the window whose expansion status
* will be used to determine
* visibility. Zero means treat
* everything as expanded.
*/
int width; /* How many pixels across the plot
* should be.
*/
{
static char *yesNo[] = {"no", "yes", NULL};
int dotsAcross, dotsDown, swathsDown, scaleDown;
char fileName[200], answer[32];
float mBytes;
Transform tinv;
int action, result;
FILE *file;
/*
* check to make sure that the swath height is a multiple of 8 so that stipples
* will look correct across swath boundaries.
*/
if (PlotPixHeight & 007) {
TxPrintf("Warning: plot parameter \"pixheight\" is not a multiple of 8. It\n");
TxPrintf("will be rounded from %d to %d.\n", PlotPixHeight, (PlotPixHeight&(~007))+8);
PlotPixHeight = (PlotPixHeight&(~007))+8;
}
/* did the user specify an explicit width? */
if (width != 0)
PlotPixWidth = width;
GeoTransRect(&scx->scx_trans, &scx->scx_area, &rootClip);
GEO_EXPAND(&rootClip, 1, &rootClip);
dotsAcross = width;
if (dotsAcross <= 0)
dotsAcross = PlotPixWidth;
/*
* Compute the number of pixels per magic unit.
* This number will be the fraction: scale / (1 << scaleShift).
* In order to be reasonably sure that we have enough precision
* in the numerator of the fraction, require that scale have at
* least three bits (i.e., be greater than or equal to 4).
*/
for (scale = 0, scaleShift = 4; ; scaleShift++)
{
scaleDown = 1 << scaleShift;
scale = (scaleDown * dotsAcross) / (rootClip.r_xtop - rootClip.r_xbot);
if (scaleShift >= 8 * sizeof (int))
{
TxError("The area selected is too many lambda wide to plot.\n");
TxError("(There are numerical problems with rasterizing it).\n");
TxError("Try selecting a smaller area, or else asking for ");
TxError("a wider plot.\n");
return;
}
if (scale >= 4)
break;
}
/*
* Compute scaling information, and tell the user how big the
* plot will be.
*/
dotsDown = ((rootClip.r_ytop - rootClip.r_ybot)*scale) >> scaleShift;
swathsDown = (dotsDown + PlotPixHeight - 1)/PlotPixHeight;
dotsDown = swathsDown * PlotPixHeight;
mBytes = (double)(PlotPixWidth*dotsDown)*3.0/1000000.0;
TxPrintf("Plot will take %.2f Megabytes in \"%s\".\n",
mBytes, PlotTempDirectory);
do
{
TxPrintf("Do you still want the plot? [yes] ");
if (TxGetLine(answer, sizeof answer) == NULL || answer[0] == '\0')
{
action = 1;
break;
}
} while ((action = Lookup(answer, yesNo)) < 0);
if (action == 0) return;
/* The plot has been "approved". Now obtain swath rasters if
* we don't already have them. If the swath size has changed,
* recycle the rasters for new ones.
*/
if (pixRasterSwath == NULL)
pixRasterSwath = PlotNewPixRaster(PlotPixHeight, PlotPixWidth);
else
{
if ((pixRasterSwath->pix_width != PlotPixWidth)
|| (pixRasterSwath->pix_height != PlotPixHeight))
{
PlotFreePixRaster(pixRasterSwath);
pixRasterSwath = PlotNewPixRaster(PlotPixHeight, PlotPixWidth);
}
}
/* Load font information for the plot, if it isn't already
* loaded. We use the "versatec" fonts for convenience.
*/
labelPixFont = PlotLoadFont(PlotVersLabelFont);
cellNamePixFont = PlotLoadFont(PlotVersNameFont);
cellIdPixFont = PlotLoadFont(PlotVersIdFont);
if ((labelPixFont == NULL) ||
(cellNamePixFont == NULL) ||
(cellIdPixFont == NULL))
{
TxPrintf("PlotPixels: can't load fonts\n");
return;
}
/* Compute the name of the file to use for output, and open it. */
sprintf(fileName, "%s/magicPlot-%d-%d-XXXXXX", PlotTempDirectory,
PlotPixWidth, PlotPixHeight*swathsDown);
result = mkstemp(fileName);
if (result == -1)
{
TxError("Couldn't create temporary filename for %s\n", fileName);
return;
}
file = PaOpen(fileName, "w", (char *) NULL, (char *) NULL, (char *) NULL,
(char **) NULL);
if (file == NULL)
{
TxError("Couldn't open file \"%s\" to write plot.\n", fileName);
return;
}
/* Set up the rest of the transformation variables.
* Arrange for the plot to be centered on the page.
*/
plotLL.p_y = rootClip.r_ybot;
plotLL.p_x = (rootClip.r_xtop+rootClip.r_xbot)/2 - (PlotPixWidth*8)/scale;
if (plotLL.p_x > rootClip.r_xbot)
plotLL.p_x = rootClip.r_xbot;
/* Compute a distance equal to 1/8th the size of a typical wire
* (max of thicknesses of routing layers). This is used to offset
* text from labels and to compute cross size for point labels.
*/
if (RtrMetalWidth > RtrPolyWidth)
crossSize = (RtrMetalWidth*scale)/(scaleDown*8);
else crossSize = (RtrPolyWidth*scale)/(scaleDown*8);
if (crossSize < 2) crossSize = 2;
/* Step down the page one swath at a time, rasterizing everything
* that overlaps the current swath, then outputting the swath.
*/
GeoInvertTrans(&scx->scx_trans, &tinv);
for (swathsDown -= 1; swathsDown >= 0; swathsDown -= 1)
{
SearchContext scx2;
Rect root, labelArea;
int labelHeight;
swathY = swathsDown * PlotPixHeight;
PlotClearPixRaster(pixRasterSwath, (Rect *) NULL);
/* Compute the area of the swath that overlaps the portion of
* the layout we're plotting.
*/
plotTransToSwath(&rootClip, &swathClip);
if (swathClip.r_xbot < 0) swathClip.r_xbot = 0;
if (swathClip.r_ybot < 0) swathClip.r_ybot = 0;
if (swathClip.r_xtop >= PlotPixWidth)
swathClip.r_xtop = PlotPixWidth - 1;
if (swathClip.r_ytop >= PlotPixHeight)
swathClip.r_ytop = PlotPixHeight - 1;
/* Compute the area of layout that overlaps this swath. This is
* done twice, once for mask material and once for labels. The
* separate computation for labels is because labels stick out
* from their positioning points. We may have to search a larger
* area than just the swath in order to find all the labels that
* must be drawn in this swath. Only the y-direction needs to
* be expanded this way, since we're only swathing in y. Even
* non-label stuff has to be expanded slightly, because lines
* are drawn more than 1 pixel thick.
*/
scx2 = *scx;
root.r_xbot = (scaleDown*swathClip.r_xbot)/scale + plotLL.p_x;
root.r_xtop = (scaleDown*swathClip.r_xtop)/scale + plotLL.p_x;
root.r_ybot = (scaleDown*(swathY-4))/scale + plotLL.p_y;
root.r_ytop = (scaleDown*(swathY+swathClip.r_ytop+4))/scale+plotLL.p_y;
GEO_EXPAND(&root, 1, &root);
GeoTransRect(&tinv, &root, &scx2.scx_area);
labelArea.r_xbot = root.r_xbot;
labelArea.r_xtop = root.r_xtop;
labelHeight =
(labelPixFont->fo_bbox.r_ytop - labelPixFont->fo_bbox.r_ybot) + 2;
labelArea.r_ybot =
(scaleDown*(swathY-crossSize-labelHeight))/scale
+ plotLL.p_y;
labelArea.r_ytop =
(scaleDown*(swathY+swathClip.r_ytop+crossSize+labelHeight))/scale
+ plotLL.p_y;
GEO_EXPAND(&labelArea, 1, &labelArea);
/* For each style, output areas for all the tiles
* requested by the style.
*/
for (curStyle = 0; curStyle < DBWNumStyles; curStyle++)
{
/* visit all the tiles in this swath */
curMask = DBWStyleToTypes(curStyle);
(void) DBTreeSrTiles(&scx2, curMask, xMask, plotPixTile,
(ClientData) NULL);
}
/* Output labels, if they are wanted. */
if (TTMaskHasType(layers, L_LABEL))
{
curMask = layers;
TTMaskSetType(curMask, TT_SPACE);
GeoTransRect(&tinv, &labelArea, &scx2.scx_area);
(void)DBTreeSrLabels(&scx2, curMask, xMask, (TerminalPath *) NULL,
TF_LABEL_ATTACH, plotPixLabel, (ClientData) NULL);
}
/* Output subcell bounding boxes, if they are wanted. */
if (TTMaskHasType(layers, L_CELL))
{
(void) DBTreeSrCells(&scx2, xMask, plotPixCell, (ClientData) NULL);
}
TxPrintf("#");
TxFlush();
if (PlotDumpPixRaster(pixRasterSwath,file)!= 0)
goto error;
if (SigInterruptPending)
goto error;
}
/* Close the file and tell the user where it is */
fclose(file);
TxPrintf("\nPlot complete. pix file is \"%s\"\n", fileName);
return;
error:
TxError("\npixel plot aborted.\n");
fclose(file);
unlink(fileName);
}
/*
* ----------------------------------------------------------------------------
*
* PlotNewPixRaster --
*
* Allocate and initialize a new raster structure.
*
* Results:
* The return value is a pointer to the new PixRaster object.
*
* Side effects:
* Memory is allocated.
*
* ----------------------------------------------------------------------------
*/
PixRaster *
PlotNewPixRaster(height, width)
int height; /* PixRaster's height in pixels.*/
int width; /* PixRaster's width in pixels.*/
{
PixRaster *new;
new = (PixRaster *) mallocMagic(sizeof(PixRaster));
new->pix_width = width;
new->pix_height = height;
new->pix_pixels = (char *) mallocMagic((unsigned) (height * width));
return new;
}
/*
* ----------------------------------------------------------------------------
*
* PlotFreePixRaster --
*
* Frees up the memory associated with an existing PixRaster structure.
*
* Results:
* None.
*
* Side effects:
* The storage associated with PixRaster is returned to the allocator.
*
* ----------------------------------------------------------------------------
*/
void
PlotFreePixRaster(pr)
PixRaster *pr; /* PixRaster whose memory is to be freed.
* Should have been created with
* PlotNewPixRaster.
*/
{
freeMagic((char *) pr->pix_pixels);
freeMagic((char *) pr);
}
/*
* ----------------------------------------------------------------------------
*
* PlotClearPixRaster --
*
* This procedure clears out an area of the PixRaster.
*
* Results:
* None.
*
* Side effects:
* The area of the PixRaster indicated by "area" is set to all zeroes.
*
* ----------------------------------------------------------------------------
*/
void
PlotClearPixRaster(pr, area)
PixRaster *pr; /* PixRaster that's to be cleared. */
Rect *area; /* Area to be cleared, in PixRaster
* coords. NULL means clear the
* whole PixRaster.
*/
{
char *left, *right, *cur;
int line;
if (area == NULL)
{
bzero((char *) pr->pix_pixels,
pr->pix_height*pr->pix_width);
return;
}
/* Compute the address of the leftmost word in the topmost line
* to be cleared, and the rightmost word in the topmost line to
* be cleared.
*/
left = pr->pix_pixels +
((pr->pix_height-1) - area->r_ytop)* pr->pix_width;
right = left + area->r_xtop;
left += area->r_xbot;
/* Clear the area one PixRaster line at a time, top to bottom. */
for (line = area->r_ytop; line >= area->r_ybot; line -= 1)
{
/* Clear the line. */
for (cur = left; cur <= right; cur += 1)
*cur = 0;
left += pr->pix_width;
right += pr->pix_width;
}
}
/*
* ----------------------------------------------------------------------------
*
* plotFillPixRaster --
*
* Given a PixRaster and an area, this procedure renders the given area
* of the PixRaster with a particular stipple pattern or other
* appropriate style.
*
* Results:
* None.
*
* Side effects:
* The current PixRaster is modified..
*
* ----------------------------------------------------------------------------
*/
void
plotFillPixRaster(pr, area, style, fill)
PixRaster *pr; /* Pointer to PixRaster whose bits are
* to be filled in.
*/
Rect *area; /* Area to be filled in pixel coords.
* This is an inclusive area: it
* includes the boundary pixels. The
* caller must ensure that it is
* clipped to the PixRaster area.
*/
int style; /* index of style to be used */
int fill; /* if >0, override GrStyleTable fill mode */
{
char *left, *cur;
int line;
char *right;
int curStipple, curColor, curMask; /* local copies so we don't have to
* continually indirect through
* GrStyleTable
*/
Rect r; /* for passing to plotPixLine */
#ifdef DEBUG
TxPrintf("plotFillPixRaster: raster buffer@0x%x : ", pr->pix_pixels);
TxPrintf(" (%d,%d)(%d,%d)\n",
area->r_xbot,
area->r_ybot,
area->r_xtop,
area->r_ytop);
#endif
/* Compute the address of the leftmost word in the topmost line
* to be filled, and the rightmost word in the topmost line to
* be filled.
*/
/* find beginning of first swath line that is affected */
left = pr->pix_pixels +
((pr->pix_height-1) - area->r_ytop)*pr->pix_width;
right = left + area->r_xtop; /* right edge */
left += area->r_xbot; /* left edge */
/* Process the area one PixRaster line at a time, top to bottom. */
curStipple = GrStyleTable[style].stipple;
curColor = GrStyleTable[style].color;
curMask = GrStyleTable[style].mask;
/*
* now select the appropriate rendering style
* and render the area. If we were passed a non-negative fill argument,
* let it override the fill mode from GrStyleTable. Otherwise, use the
* mode from the table. This is so we can make solid areas in STYLE_LABEL,
* for example, instead of getting the arms of the crosses hollow.
*/
if (fill < 0)
fill = GrStyleTable[style].fill;
switch (fill)
{
case GR_STSTIPPLE:
#ifdef DEBUG
TxPrintf ("Stipple: %d %d %d %d %d %d %d %d \n",
GrStippleTable[curStipple][0],
GrStippleTable[curStipple][1],
GrStippleTable[curStipple][2],
GrStippleTable[curStipple][3],
GrStippleTable[curStipple][4],
GrStippleTable[curStipple][5],
GrStippleTable[curStipple][6],
GrStippleTable[curStipple][7]);
#endif
for (line = area->r_ytop; line >= area->r_ybot; line -= 1)
{
for (cur = left; cur <= right; cur += 1)
/* select "line" of stipple pattern and AND it with the bitmask
* for the bit in the line
* x&07 == x % 8 and is faster
*/
if(GrStippleTable[curStipple][line&07] &
1<<(int)((7-(cur-pr->pix_pixels)%
pr->pix_width)&07))
*cur = (*cur & ~curMask) | (curColor & curMask);
left += pr->pix_width;
right += pr->pix_width;
}
break;
case GR_STGRID:
/* not implemented */
break;
/* cross and outline are handled at a higher level */
case GR_STCROSS:
/* can't do it here due to swath boundary problems. */
break;
case GR_STOUTLINE:
break;
case GR_STSOLID:
default:
for (line = area->r_ytop; line >= area->r_ybot; line -= 1)
{
for (cur = left; cur <= right; cur += 1)
*cur = (*cur & ~curMask) | (curColor & curMask);
left += pr->pix_width;
right += pr->pix_width;
}
break;
}
}
/*
* ----------------------------------------------------------------------------
*
* PlotDumpPixRaster --
*
* Writes out the contents of the given PixRaster to the given file,
* in binary format. Goes trhough color map table to get the values for
* each pixel.
*
* Results:
* Returns 0 if all was well. Returns non-zero if there was
* an I/O error. In this event, this procedure prints an
* error message before returning.
*
* Side effects:
* Information is added to file.
*
* ----------------------------------------------------------------------------
*/
int
PlotDumpPixRaster(pr, file)
PixRaster *pr; /* PixRaster to be dumped. */
FILE *file; /* File stream on which to dump it. */
{
int i;
int r, g, b;
for (i = 0; i < (pr->pix_width) * (pr->pix_height); i++)
{
GrGetColor(pr->pix_pixels[i], &r, &g, &b);
if (putc(r, file) == EOF) /* red */
{
TxError("I/O error in writing PixRaster file: %s.\n",
strerror(errno));
return 1;
}
if (putc(g, file) == EOF) /* green */
{
TxError("I/O error in writing PixRaster file: %s.\n",
strerror(errno));
return 1;
}
if (putc(b, file) == EOF) /* blue */
{
TxError("I/O error in writing PixRaster file: %s.\n",
strerror(errno));
return 1;
}
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* PlotPixRasterText --
*
* Given a text string and a font, this procedure scan-converts
* the string and writespixels in the current raster that correspond
* to on-bits in the text.
*
* Results:
* None.
*
* Side effects:
* Bits are modified in the raster.
*
* ----------------------------------------------------------------------------
*/
void
PlotPixRasterText(raster, clip, font, string, point, style)
PixRaster *raster; /* Raster whose bits are to be filled in. */
Rect *clip; /* Area to which to clip the text. Must be
* entirely within the area of the raster.
*/
RasterFont *font; /* Font to use for rasterizing string. Must
* have been obtained by calling PlotLoadFont.
*/
char *string; /* String of text to rasterize. */
Point *point; /* X-Y coordinates of origin of text. The
* origin need not be inside the area of
* the raster, but only raster points inside
* the area will be modified.
*/
int style; /* style for the text to be rendered in --
* used only for the correct color.
*/
{
int xOrig; /* X-origin for current character. */
int color;
color = GrStyleTable[style].color;
/* Outer loop: process each character. */
xOrig = point->p_x;
for (; *string != 0; string++)
{
int cBytesPerLine, i;
struct dispatch *d; /* Descriptor for current character. */
/* Handle spaces and tabs specially by just spacing over. */
if ((*string == ' ') || (*string == '\t'))
{
xOrig += font->fo_chars['t'].width;
continue;
}
/* Middle loop: render each character one raster line at a
* time, from top to bottom. Skip rows that are outside the
* area of the raster.
*/
d = &font->fo_chars[*string];
cBytesPerLine = (d->left + d->right + 7) >> 3;
for (i = 0; i < d->up + d->down; i++)
{
int y, j;
char *charBitPtr;
y = point->p_y + d->up - 1 - i;
if (y < clip->r_ybot) break;
if (y > clip->r_ytop) continue;
/* Inner loop: process a series of bytes in a row to
* render one raster line of one character. Be sure
* to skip areas that fall outside the raster to the
* left or right.
*/
for (j = -d->left,
charBitPtr = font->fo_bits + d->addr + i*cBytesPerLine;
j < d->right;
j += 8, charBitPtr++)
{
char *rPtr;
int charBits, x, k;
x = xOrig + j;
if (x > clip->r_xtop) break;
if (x < clip->r_xbot - 7) continue;
rPtr = (char *) raster->pix_pixels;
rPtr += (raster->pix_height - 1 - y)*raster->pix_width + x;
charBits = *charBitPtr & 0xff;
/* Inner inner loop: process the bytes worth of bits, setting
* pixels in the raster to the current color
*/
for(k=7;k>=0;k--)
{
if(charBits&(1<<k))
*rPtr |= color;
rPtr++;
}
}
}
xOrig += d->width;
}
}
#endif /* LLNL */
|