| @@ -3,8 +3,6 @@ · 2 unmodified lines |
| 3 | #include <draw.h> | 3 | #include <draw.h> |
| 4 | #include <memdraw.h> | 4 | #include <memdraw.h> |
| 5 | | 5 | |
| 6 | int drawdebug; | | |
| 7 | | | |
| 8 | /* perfect approximation to NTSC = .299r+.587g+.114b when 0 ≤ r,g,b < 256 */ | 6 | /* perfect approximation to NTSC = .299r+.587g+.114b when 0 ≤ r,g,b < 256 */ |
| 9 | #define RGB2K(r,g,b) ((156763*(r)+307758*(g)+59769*(b))>>19) | 7 | #define RGB2K(r,g,b) ((156763*(r)+307758*(g)+59769*(b))>>19) |
| 10 | | 8 | |
| @@ -91,7 +89,6 @@ static ulong imgtorgba(Memimage*, ulong); · 80 unmodified lines |
| 91 | static ulong rgbatoimg(Memimage*, ulong); | 89 | static ulong rgbatoimg(Memimage*, ulong); |
| 92 | static ulong pixelbits(Memimage*, Point); | 90 | static ulong pixelbits(Memimage*, Point); |
| 93 | | 91 | |
| 94 | #define DBG if(0) | | |
| 95 | void | 92 | void |
| 96 | memimagedraw(Memimage *dst, Rectangle r, Memimage *src, Point p0, Memimage *mask, Point p1, int op) | 93 | memimagedraw(Memimage *dst, Rectangle r, Memimage *src, Point p0, Memimage *mask, Point p1, int op) |
| 97 | { | 94 | { |
| @@ -100,19 +97,11 @@ memimagedraw(Memimage *dst, Rectangle r, Memimage *src, Point p0, Memimage *mask · 2 unmodified lines |
| 100 | if(mask == nil) | 97 | if(mask == nil) |
| 101 | mask = memopaque; | 98 | mask = memopaque; |
| 102 | | 99 | |
| 103 | DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->chan, r, dst->data->bdata, src, src->chan, p0, mask, mask->chan, p1); | 100 | if(drawclip(dst, &r, src, &p0, mask, &p1, &par.sr, &par.mr) == 0) |
| 104 | | | |
| 105 | if(drawclip(dst, &r, src, &p0, mask, &p1, &par.sr, &par.mr) == 0){ | | |
| 106 | // if(drawdebug) | | |
| 107 | // iprint("empty clipped rectangle\n"); | | |
| 108 | return; | 101 | return; |
| 109 | } | | |
| 110 | | 102 | |
| 111 | if(op < Clear || op > SoverD){ | 103 | if(op < Clear || op > SoverD) |
| 112 | // if(drawdebug) | | |
| 113 | // iprint("op out of range: %d\n", op); | | |
| 114 | return; | 104 | return; |
| 115 | } | | |
| 116 | | 105 | |
| 117 | par.op = op; | 106 | par.op = op; |
| 118 | par.dst = dst; | 107 | par.dst = dst; |
| @@ -130,10 +119,8 @@ DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->ch · 11 unmodified lines |
| 130 | par.state |= Simplesrc; | 119 | par.state |= Simplesrc; |
| 131 | par.srgba = imgtorgba(src, par.sval); | 120 | par.srgba = imgtorgba(src, par.sval); |
| 132 | par.sdval = rgbatoimg(dst, par.srgba); | 121 | par.sdval = rgbatoimg(dst, par.srgba); |
| 133 | if((par.srgba&0xFF) == 0 && (op&DoutS)){ | 122 | if((par.srgba&0xFF) == 0 && (op&DoutS)) |
| 134 | // if (drawdebug) iprint("fill with transparent source\n"); | | |
| 135 | return; /* no-op successfully handled */ | 123 | return; /* no-op successfully handled */ |
| 136 | } | | |
| 137 | } | 124 | } |
| 138 | } | 125 | } |
| 139 | | 126 | |
| @@ -141,10 +128,8 @@ DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->ch · 1 unmodified line |
| 141 | par.state |= Replmask; | 128 | par.state |= Replmask; |
| 142 | if(Dx(mask->r)==1 && Dy(mask->r)==1){ | 129 | if(Dx(mask->r)==1 && Dy(mask->r)==1){ |
| 143 | par.mval = pixelbits(mask, mask->r.min); | 130 | par.mval = pixelbits(mask, mask->r.min); |
| 144 | if(par.mval == 0 && (op&DoutS)){ | 131 | if(par.mval == 0 && (op&DoutS)) |
| 145 | // if(drawdebug) iprint("fill with zero mask\n"); | | |
| 146 | return; /* no-op successfully handled */ | 132 | return; /* no-op successfully handled */ |
| 147 | } | | |
| 148 | par.state |= Simplemask; | 133 | par.state |= Simplemask; |
| 149 | if(par.mval == ~0) | 134 | if(par.mval == ~0) |
| 150 | par.state |= Fullmask; | 135 | par.state |= Fullmask; |
| @@ -152,10 +137,6 @@ DBG print("memimagedraw %p/%luX %R @ %p %p/%luX %P %p/%luX %P... ", dst, dst->ch · 1 unmodified line |
| 152 | } | 137 | } |
| 153 | } | 138 | } |
| 154 | | 139 | |
| 155 | // if(drawdebug) | | |
| 156 | // iprint("dr %R sr %R mr %R...", r, par.sr, par.mr); | | |
| 157 | DBG print("draw dr %R sr %R mr %R %lux\n", r, par.sr, par.mr, par.state); | | |
| 158 | | | |
| 159 | /* | 140 | /* |
| 160 | * Now that we've clipped the parameters down to be consistent, we | 141 | * Now that we've clipped the parameters down to be consistent, we |
| 161 | * simply try sub-drawing routines in order until we find one that was able | 142 | * simply try sub-drawing routines in order until we find one that was able |
| @@ -168,42 +149,27 @@ DBG print("draw dr %R sr %R mr %R %lux\n", r, par.sr, par.mr, par.state); · 6 unmodified lines |
| 168 | * which checks to see if there is anything it can help with. | 149 | * which checks to see if there is anything it can help with. |
| 169 | * There could be an if around this checking to see if dst is in video memory. | 150 | * There could be an if around this checking to see if dst is in video memory. |
| 170 | */ | 151 | */ |
| 171 | DBG print("test hwdraw\n"); | 152 | if(hwdraw(&par)) |
| 172 | if(hwdraw(&par)){ | | |
| 173 | //if(drawdebug) iprint("hw handled\n"); | | |
| 174 | DBG print("hwdraw handled\n"); | | |
| 175 | return; | 153 | return; |
| 176 | } | 154 | |
| 177 | /* | 155 | /* |
| 178 | * Optimizations using memmove and memset. | 156 | * Optimizations using memmove and memset. |
| 179 | */ | 157 | */ |
| 180 | DBG print("test memoptdraw\n"); | 158 | if(memoptdraw(&par)) |
| 181 | if(memoptdraw(&par)){ | | |
| 182 | //if(drawdebug) iprint("memopt handled\n"); | | |
| 183 | DBG print("memopt handled\n"); | | |
| 184 | return; | 159 | return; |
| 185 | } | | |
| 186 | | 160 | |
| 187 | /* | 161 | /* |
| 188 | * Character drawing. | 162 | * Character drawing. |
| 189 | * Solid source color being painted through a boolean mask onto a high res image. | 163 | * Solid source color being painted through a boolean mask onto a high res image. |
| 190 | */ | 164 | */ |
| 191 | DBG print("test chardraw\n"); | 165 | if(chardraw(&par)) |
| 192 | if(chardraw(&par)){ | | |
| 193 | //if(drawdebug) iprint("chardraw handled\n"); | | |
| 194 | DBG print("chardraw handled\n"); | | |
| 195 | return; | 166 | return; |
| 196 | } | | |
| 197 | | 167 | |
| 198 | /* | 168 | /* |
| 199 | * General calculation-laden case that does alpha for each pixel. | 169 | * General calculation-laden case that does alpha for each pixel. |
| 200 | */ | 170 | */ |
| 201 | DBG print("do alphadraw\n"); | | |
| 202 | alphadraw(&par); | 171 | alphadraw(&par); |
| 203 | //if(drawdebug) iprint("alphadraw handled\n"); | | |
| 204 | DBG print("alphadraw handled\n"); | | |
| 205 | } | 172 | } |
| 206 | #undef DBG | | |
| 207 | | 173 | |
| 208 | | 174 | |
| 209 | /* | 175 | /* |
| @@ -573,40 +539,6 @@ clipy(Memimage *img, int *y) · 363 unmodified lines |
| 573 | assert(0 <= *y && *y < dy); | 539 | assert(0 <= *y && *y < dy); |
| 574 | } | 540 | } |
| 575 | | 541 | |
| 576 | static void | | |
| 577 | dumpbuf(char *s, Buffer b, int n) | | |
| 578 | { | | |
| 579 | int i; | | |
| 580 | uchar *p; | | |
| 581 | | | |
| 582 | print("%s", s); | | |
| 583 | for(i=0; i<n; i++){ | | |
| 584 | print(" "); | | |
| 585 | if(p=b.grey){ | | |
| 586 | print(" k%.2uX", *p); | | |
| 587 | b.grey += b.delta; | | |
| 588 | }else{ | | |
| 589 | if(p=b.red){ | | |
| 590 | print(" r%.2uX", *p); | | |
| 591 | b.red += b.delta; | | |
| 592 | } | | |
| 593 | if(p=b.grn){ | | |
| 594 | print(" g%.2uX", *p); | | |
| 595 | b.grn += b.delta; | | |
| 596 | } | | |
| 597 | if(p=b.blu){ | | |
| 598 | print(" b%.2uX", *p); | | |
| 599 | b.blu += b.delta; | | |
| 600 | } | | |
| 601 | } | | |
| 602 | if((p=b.alpha) != &ones){ | | |
| 603 | print(" α%.2uX", *p); | | |
| 604 | b.alpha += b.delta; | | |
| 605 | } | | |
| 606 | } | | |
| 607 | print("\n"); | | |
| 608 | } | | |
| 609 | | | |
| 610 | /* | 542 | /* |
| 611 | * For each scan line, we expand the pixels from source, mask, and destination | 543 | * For each scan line, we expand the pixels from source, mask, and destination |
| 612 | * into byte-aligned red, green, blue, alpha, and grey channels. If buffering is not | 544 | * into byte-aligned red, green, blue, alpha, and grey channels. If buffering is not |
| @@ -622,7 +554,6 @@ dumpbuf(char *s, Buffer b, int n) · 9 unmodified lines |
| 622 | * the calculator, and that buffer is passed to a function to write it to the destination. | 554 | * the calculator, and that buffer is passed to a function to write it to the destination. |
| 623 | * If the buffer is already pointing at the destination, the writing function is a no-op. | 555 | * If the buffer is already pointing at the destination, the writing function is a no-op. |
| 624 | */ | 556 | */ |
| 625 | #define DBG if(0) | | |
| 626 | static int | 557 | static int |
| 627 | alphadraw(Memdrawparam *par) | 558 | alphadraw(Memdrawparam *par) |
| 628 | { | 559 | { |
| @@ -686,9 +617,7 @@ alphadraw(Memdrawparam *par) · 57 unmodified lines |
| 686 | * but it avoids a fair amount of code duplication to make this a case here | 617 | * but it avoids a fair amount of code duplication to make this a case here |
| 687 | * rather than have a separate booldraw. | 618 | * rather than have a separate booldraw. |
| 688 | */ | 619 | */ |
| 689 | //if(drawdebug) iprint("flag %lud mchan %lux=?%x dd %d\n", src->flags&Falpha, mask->chan, GREY1, dst->depth); | | |
| 690 | if(!(src->flags&Falpha) && mask->chan == GREY1 && dst->depth >= 8 && op == SoverD){ | 620 | if(!(src->flags&Falpha) && mask->chan == GREY1 && dst->depth >= 8 && op == SoverD){ |
| 691 | //if(drawdebug) iprint("boolcopy..."); | | |
| 692 | rdsrc = convfn(dst, &z->dpar, src, &z->spar, &ndrawbuf); | 621 | rdsrc = convfn(dst, &z->dpar, src, &z->spar, &ndrawbuf); |
| 693 | rddst = readptr; | 622 | rddst = readptr; |
| 694 | rdmask = readfn(mask); | 623 | rdmask = readfn(mask); |
| @@ -788,13 +717,8 @@ alphadraw(Memdrawparam *par) · 93 unmodified lines |
| 788 | clipy(mask, &masky); | 717 | clipy(mask, &masky); |
| 789 | | 718 | |
| 790 | bsrc = rdsrc(&z->spar, z->spar.bufbase, srcy); | 719 | bsrc = rdsrc(&z->spar, z->spar.bufbase, srcy); |
| 791 | DBG print("["); | | |
| 792 | bmask = rdmask(&z->mpar, z->mpar.bufbase, masky); | 720 | bmask = rdmask(&z->mpar, z->mpar.bufbase, masky); |
| 793 | DBG print("]\n"); | | |
| 794 | bdst = rddst(&z->dpar, z->dpar.bufbase, dsty); | 721 | bdst = rddst(&z->dpar, z->dpar.bufbase, dsty); |
| 795 | DBG dumpbuf("src", bsrc, dx); | | |
| 796 | DBG dumpbuf("mask", bmask, dx); | | |
| 797 | DBG dumpbuf("dst", bdst, dx); | | |
| 798 | bdst = calc(bdst, bsrc, bmask, dx, isgrey, op); | 722 | bdst = calc(bdst, bsrc, bmask, dx, isgrey, op); |
| 799 | wrdst(&z->dpar, z->dpar.bytermin+dsty*z->dpar.bwidth, bdst); | 723 | wrdst(&z->dpar, z->dpar.bytermin+dsty*z->dpar.bwidth, bdst); |
| 800 | } | 724 | } |
| @@ -802,7 +726,6 @@ DBG dumpbuf("dst", bdst, dx); · 1 unmodified line |
| 802 | z->inuse = 0; | 726 | z->inuse = 0; |
| 803 | return 1; | 727 | return 1; |
| 804 | } | 728 | } |
| 805 | #undef DBG | | |
| 806 | | 729 | |
| 807 | static Buffer | 730 | static Buffer |
| 808 | alphacalc0(Buffer bdst, Buffer b1, Buffer b2, int dx, int grey, int op) | 731 | alphacalc0(Buffer bdst, Buffer b1, Buffer b2, int dx, int grey, int op) |
| @@ -1329,7 +1252,6 @@ greymaskread(Param *p, uchar *buf, int y) · 520 unmodified lines |
| 1329 | return b; | 1252 | return b; |
| 1330 | } | 1253 | } |
| 1331 | | 1254 | |
| 1332 | #define DBG if(0) | | |
| 1333 | static Buffer | 1255 | static Buffer |
| 1334 | readnbit(Param *p, uchar *buf, int y) | 1256 | readnbit(Param *p, uchar *buf, int y) |
| 1335 | { | 1257 | { |
| @@ -1358,22 +1280,18 @@ readnbit(Param *p, uchar *buf, int y) · 22 unmodified lines |
| 1358 | n = p->img->r.max.x - x; | 1280 | n = p->img->r.max.x - x; |
| 1359 | | 1281 | |
| 1360 | r = p->bytermin + y*p->bwidth; | 1282 | r = p->bytermin + y*p->bwidth; |
| 1361 | DBG print("readnbit dx %d %p=%p+%d*%d, *r=%d fetch %d ", dx, r, p->bytermin, y, p->bwidth, *r, n); | | |
| 1362 | bits = *r++; | 1283 | bits = *r++; |
| 1363 | nbits = 8; | 1284 | nbits = 8; |
| 1364 | if(i=x&(npack-1)){ | 1285 | if(i=x&(npack-1)){ |
| 1365 | DBG print("throwaway %d...", i); | | |
| 1366 | bits <<= depth*i; | 1286 | bits <<= depth*i; |
| 1367 | nbits -= depth*i; | 1287 | nbits -= depth*i; |
| 1368 | } | 1288 | } |
| 1369 | for(i=0; i<n; i++){ | 1289 | for(i=0; i<n; i++){ |
| 1370 | if(nbits == 0){ | 1290 | if(nbits == 0){ |
| 1371 | DBG print("(%.2ux)...", *r); | | |
| 1372 | bits = *r++; | 1291 | bits = *r++; |
| 1373 | nbits = 8; | 1292 | nbits = 8; |
| 1374 | } | 1293 | } |
| 1375 | *w++ = repl[bits>>sh]; | 1294 | *w++ = repl[bits>>sh]; |
| 1376 | DBG print("bit %x...", repl[bits>>sh]); | | |
| 1377 | bits <<= depth; | 1295 | bits <<= depth; |
| 1378 | nbits -= depth; | 1296 | nbits -= depth; |
| 1379 | } | 1297 | } |
| @@ -1390,24 +1308,20 @@ DBG print("bit %x...", repl[bits>>sh]); · 10 unmodified lines |
| 1390 | n = p->r.min.x - x; | 1308 | n = p->r.min.x - x; |
| 1391 | | 1309 | |
| 1392 | r = p->bytey0s + y*p->bwidth; | 1310 | r = p->bytey0s + y*p->bwidth; |
| 1393 | DBG print("x=%d r=%p...", x, r); | | |
| 1394 | bits = *r++; | 1311 | bits = *r++; |
| 1395 | nbits = 8; | 1312 | nbits = 8; |
| 1396 | if(i=x&(npack-1)){ | 1313 | if(i=x&(npack-1)){ |
| 1397 | bits <<= depth*i; | 1314 | bits <<= depth*i; |
| 1398 | nbits -= depth*i; | 1315 | nbits -= depth*i; |
| 1399 | } | 1316 | } |
| 1400 | DBG print("nbits=%d...", nbits); | | |
| 1401 | for(i=0; i<n; i++){ | 1317 | for(i=0; i<n; i++){ |
| 1402 | if(nbits == 0){ | 1318 | if(nbits == 0){ |
| 1403 | bits = *r++; | 1319 | bits = *r++; |
| 1404 | nbits = 8; | 1320 | nbits = 8; |
| 1405 | } | 1321 | } |
| 1406 | *w++ = repl[bits>>sh]; | 1322 | *w++ = repl[bits>>sh]; |
| 1407 | DBG print("bit %x...", repl[bits>>sh]); | | |
| 1408 | bits <<= depth; | 1323 | bits <<= depth; |
| 1409 | nbits -= depth; | 1324 | nbits -= depth; |
| 1410 | DBG print("bits %x nbits %d...", bits, nbits); | | |
| 1411 | } | 1325 | } |
| 1412 | dx -= n; | 1326 | dx -= n; |
| 1413 | if(dx == 0) | 1327 | if(dx == 0) |
| @@ -1421,9 +1335,7 @@ DBG print("bits %x nbits %d...", bits, nbits); · 7 unmodified lines |
| 1421 | | 1335 | |
| 1422 | return b; | 1336 | return b; |
| 1423 | } | 1337 | } |
| 1424 | #undef DBG | | |
| 1425 | | 1338 | |
| 1426 | #define DBG if(0) | | |
| 1427 | static void | 1339 | static void |
| 1428 | writenbit(Param *p, uchar *w, Buffer src) | 1340 | writenbit(Param *p, uchar *w, Buffer src) |
| 1429 | { | 1341 | { |
| @@ -1446,7 +1358,6 @@ writenbit(Param *p, uchar *w, Buffer src) · 16 unmodified lines |
| 1446 | | 1358 | |
| 1447 | for(; x<ex; x++){ | 1359 | for(; x<ex; x++){ |
| 1448 | bits <<= depth; | 1360 | bits <<= depth; |
| 1449 | DBG print(" %x", *r); | | |
| 1450 | bits |= (*r++ >> sh); | 1361 | bits |= (*r++ >> sh); |
| 1451 | nbits += depth; | 1362 | nbits += depth; |
| 1452 | if(nbits == 8){ | 1363 | if(nbits == 8){ |
| @@ -1461,10 +1372,8 @@ DBG print(" %x", *r); · 8 unmodified lines |
| 1461 | bits |= *w & ((1<<sh)-1); | 1372 | bits |= *w & ((1<<sh)-1); |
| 1462 | *w = bits; | 1373 | *w = bits; |
| 1463 | } | 1374 | } |
| 1464 | DBG print("\n"); | | |
| 1465 | return; | 1375 | return; |
| 1466 | } | 1376 | } |
| 1467 | #undef DBG | | |
| 1468 | | 1377 | |
| 1469 | static Buffer | 1378 | static Buffer |
| 1470 | readcmap(Param *p, uchar *buf, int y) | 1379 | readcmap(Param *p, uchar *buf, int y) |
| @@ -1562,7 +1471,6 @@ writecmap(Param *p, uchar *w, Buffer src) · 91 unmodified lines |
| 1562 | } | 1471 | } |
| 1563 | } | 1472 | } |
| 1564 | | 1473 | |
| 1565 | #define DBG if(0) | | |
| 1566 | static Buffer | 1474 | static Buffer |
| 1567 | readbyte(Param *p, uchar *buf, int y) | 1475 | readbyte(Param *p, uchar *buf, int y) |
| 1568 | { | 1476 | { |
| @@ -1587,7 +1495,6 @@ readbyte(Param *p, uchar *buf, int y) · 18 unmodified lines |
| 1587 | alphaonly = p->alphaonly; | 1495 | alphaonly = p->alphaonly; |
| 1588 | copyalpha = (img->flags&Falpha) != 0; | 1496 | copyalpha = (img->flags&Falpha) != 0; |
| 1589 | | 1497 | |
| 1590 | DBG print("copyalpha %d alphaonly %d convgrey %d isgrey %d\n", copyalpha, alphaonly, convgrey, isgrey); | | |
| 1591 | /* if we can, avoid processing everything */ | 1498 | /* if we can, avoid processing everything */ |
| 1592 | if(!(img->flags&Frepl) && !convgrey && (img->flags&Fbytes)){ | 1499 | if(!(img->flags&Frepl) && !convgrey && (img->flags&Fbytes)){ |
| 1593 | memset(&b, 0, sizeof b); | 1500 | memset(&b, 0, sizeof b); |
| @@ -1612,7 +1519,6 @@ DBG print("copyalpha %d alphaonly %d convgrey %d isgrey %d\n", copyalpha, alphao · 18 unmodified lines |
| 1612 | return b; | 1519 | return b; |
| 1613 | } | 1520 | } |
| 1614 | | 1521 | |
| 1615 | DBG print("2\n"); | | |
| 1616 | rrepl = replbit[img->nbits[CRed]]; | 1522 | rrepl = replbit[img->nbits[CRed]]; |
| 1617 | grepl = replbit[img->nbits[CGreen]]; | 1523 | grepl = replbit[img->nbits[CGreen]]; |
| 1618 | brepl = replbit[img->nbits[CBlue]]; | 1524 | brepl = replbit[img->nbits[CBlue]]; |
| @@ -1623,7 +1529,6 @@ DBG print("2\n"); · 4 unmodified lines |
| 1623 | u = r[0] | (r[1]<<8) | (r[2]<<16) | (r[3]<<24); | 1529 | u = r[0] | (r[1]<<8) | (r[2]<<16) | (r[3]<<24); |
| 1624 | if(copyalpha) { | 1530 | if(copyalpha) { |
| 1625 | *w++ = arepl[(u>>img->shift[CAlpha]) & img->mask[CAlpha]]; | 1531 | *w++ = arepl[(u>>img->shift[CAlpha]) & img->mask[CAlpha]]; |
| 1626 | DBG print("a %x\n", w[-1]); | | |
| 1627 | } | 1532 | } |
| 1628 | | 1533 | |
| 1629 | if(isgrey) | 1534 | if(isgrey) |
| @@ -1633,9 +1538,7 @@ DBG print("a %x\n", w[-1]); · 3 unmodified lines |
| 1633 | ugrn = grepl[(u >> img->shift[CGreen]) & img->mask[CGreen]]; | 1538 | ugrn = grepl[(u >> img->shift[CGreen]) & img->mask[CGreen]]; |
| 1634 | ublu = brepl[(u >> img->shift[CBlue]) & img->mask[CBlue]]; | 1539 | ublu = brepl[(u >> img->shift[CBlue]) & img->mask[CBlue]]; |
| 1635 | if(convgrey){ | 1540 | if(convgrey){ |
| 1636 | DBG print("g %x %x %x\n", ured, ugrn, ublu); | | |
| 1637 | *w++ = RGB2K(ured, ugrn, ublu); | 1541 | *w++ = RGB2K(ured, ugrn, ublu); |
| 1638 | DBG print("%x\n", w[-1]); | | |
| 1639 | }else{ | 1542 | }else{ |
| 1640 | w[0] = ublu; | 1543 | w[0] = ublu; |
| 1641 | w[1] = ugrn; | 1544 | w[1] = ugrn; |
| @@ -1659,7 +1562,6 @@ DBG print("%x\n", w[-1]); · 17 unmodified lines |
| 1659 | b.grey = buf+copyalpha; | 1562 | b.grey = buf+copyalpha; |
| 1660 | b.red = b.grn = b.blu = buf+copyalpha; | 1563 | b.red = b.grn = b.blu = buf+copyalpha; |
| 1661 | b.delta = copyalpha+1; | 1564 | b.delta = copyalpha+1; |
| 1662 | DBG print("alpha %x grey %x\n", *b.alpha, *b.grey); | | |
| 1663 | }else{ | 1565 | }else{ |
| 1664 | b.blu = buf+copyalpha; | 1566 | b.blu = buf+copyalpha; |
| 1665 | b.grn = buf+copyalpha+1; | 1567 | b.grn = buf+copyalpha+1; |
| @@ -1669,9 +1571,7 @@ DBG print("alpha %x grey %x\n", *b.alpha, *b.grey); · 3 unmodified lines |
| 1669 | } | 1571 | } |
| 1670 | return b; | 1572 | return b; |
| 1671 | } | 1573 | } |
| 1672 | #undef DBG | | |
| 1673 | | 1574 | |
| 1674 | #define DBG if(0) | | |
| 1675 | static void | 1575 | static void |
| 1676 | writebyte(Param *p, uchar *w, Buffer src) | 1576 | writebyte(Param *p, uchar *w, Buffer src) |
| 1677 | { | 1577 | { |
| @@ -1732,12 +1632,9 @@ writebyte(Param *p, uchar *w, Buffer src) · 54 unmodified lines |
| 1732 | mask = (nb==4) ? 0 : ~((1<<img->depth)-1); | 1632 | mask = (nb==4) ? 0 : ~((1<<img->depth)-1); |
| 1733 | for(i=0; i<dx; i++){ | 1633 | for(i=0; i<dx; i++){ |
| 1734 | u = w[0] | (w[1]<<8) | (w[2]<<16) | (w[3]<<24); | 1634 | u = w[0] | (w[1]<<8) | (w[2]<<16) | (w[3]<<24); |
| 1735 | DBG print("u %.8lux...", u); | | |
| 1736 | u &= mask; | 1635 | u &= mask; |
| 1737 | DBG print("&mask %.8lux...", u); | | |
| 1738 | if(isgrey){ | 1636 | if(isgrey){ |
| 1739 | u |= ((*grey >> (8-img->nbits[CGrey])) & img->mask[CGrey]) << img->shift[CGrey]; | 1637 | u |= ((*grey >> (8-img->nbits[CGrey])) & img->mask[CGrey]) << img->shift[CGrey]; |
| 1740 | DBG print("|grey %.8lux...", u); | | |
| 1741 | grey += delta; | 1638 | grey += delta; |
| 1742 | }else{ | 1639 | }else{ |
| 1743 | u |= ((*red >> (8-img->nbits[CRed])) & img->mask[CRed]) << img->shift[CRed]; | 1640 | u |= ((*red >> (8-img->nbits[CRed])) & img->mask[CRed]) << img->shift[CRed]; |
| @@ -1746,13 +1643,11 @@ DBG print("|grey %.8lux...", u); · 2 unmodified lines |
| 1746 | red += delta; | 1643 | red += delta; |
| 1747 | grn += delta; | 1644 | grn += delta; |
| 1748 | blu += delta; | 1645 | blu += delta; |
| 1749 | DBG print("|rgb %.8lux...", u); | | |
| 1750 | } | 1646 | } |
| 1751 | | 1647 | |
| 1752 | if(isalpha){ | 1648 | if(isalpha){ |
| 1753 | u |= ((*alpha >> (8-img->nbits[CAlpha])) & img->mask[CAlpha]) << img->shift[CAlpha]; | 1649 | u |= ((*alpha >> (8-img->nbits[CAlpha])) & img->mask[CAlpha]) << img->shift[CAlpha]; |
| 1754 | alpha += adelta; | 1650 | alpha += adelta; |
| 1755 | DBG print("|alpha %.8lux...", u); | | |
| 1756 | } | 1651 | } |
| 1757 | | 1652 | |
| 1758 | w[0] = u; | 1653 | w[0] = u; |
| @@ -1762,7 +1657,6 @@ DBG print("|alpha %.8lux...", u); · 3 unmodified lines |
| 1762 | w += nb; | 1657 | w += nb; |
| 1763 | } | 1658 | } |
| 1764 | } | 1659 | } |
| 1765 | #undef DBG | | |
| 1766 | | 1660 | |
| 1767 | static Readfn* | 1661 | static Readfn* |
| 1768 | readfn(Memimage *img) | 1662 | readfn(Memimage *img) |
| @@ -1935,14 +1829,11 @@ genconv(Param *p, uchar *buf, int y) · 166 unmodified lines |
| 1935 | static Readfn* | 1829 | static Readfn* |
| 1936 | convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar, int *ndrawbuf) | 1830 | convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar, int *ndrawbuf) |
| 1937 | { | 1831 | { |
| 1938 | if(dst->chan == src->chan && !(src->flags&Frepl)){ | 1832 | if(dst->chan == src->chan && !(src->flags&Frepl)) |
| 1939 | //if(drawdebug) iprint("readptr..."); | | |
| 1940 | return readptr; | 1833 | return readptr; |
| 1941 | } | | |
| 1942 | | 1834 | |
| 1943 | if(dst->chan==CMAP8 && (src->chan==GREY1||src->chan==GREY2||src->chan==GREY4)){ | 1835 | if(dst->chan==CMAP8 && (src->chan==GREY1||src->chan==GREY2||src->chan==GREY4)){ |
| 1944 | /* cheat because we know the replicated value is exactly the color map entry. */ | 1836 | /* cheat because we know the replicated value is exactly the color map entry. */ |
| 1945 | //if(drawdebug) iprint("Readnbit..."); | | |
| 1946 | return readnbit; | 1837 | return readnbit; |
| 1947 | } | 1838 | } |
| 1948 | | 1839 | |
| @@ -1959,7 +1850,6 @@ convfn(Memimage *dst, Param *dpar, Memimage *src, Param *spar, int *ndrawbuf) · 10 unmodified lines |
| 1959 | spar->dx = Dx(spar->img->r); | 1850 | spar->dx = Dx(spar->img->r); |
| 1960 | } | 1851 | } |
| 1961 | | 1852 | |
| 1962 | //if(drawdebug) iprint("genconv..."); | | |
| 1963 | return genconv; | 1853 | return genconv; |
| 1964 | } | 1854 | } |
| 1965 | | 1855 | |
| @@ -2170,11 +2060,9 @@ rgbatoimg(Memimage *img, ulong rgba) · 204 unmodified lines |
| 2170 | } | 2060 | } |
| 2171 | d += nb; | 2061 | d += nb; |
| 2172 | } | 2062 | } |
| 2173 | // print("rgba2img %.8lux = %.*lux\n", rgba, 2*d/8, v); | | |
| 2174 | return v; | 2063 | return v; |
| 2175 | } | 2064 | } |
| 2176 | | 2065 | |
| 2177 | #define DBG if(0) | | |
| 2178 | static int | 2066 | static int |
| 2179 | memoptdraw(Memdrawparam *par) | 2067 | memoptdraw(Memdrawparam *par) |
| 2180 | { | 2068 | { |
| @@ -2189,7 +2077,6 @@ memoptdraw(Memdrawparam *par) · 8 unmodified lines |
| 2189 | dst = par->dst; | 2077 | dst = par->dst; |
| 2190 | op = par->op; | 2078 | op = par->op; |
| 2191 | | 2079 | |
| 2192 | DBG print("state %lux mval %lux dd %d\n", par->state, par->mval, dst->depth); | | |
| 2193 | /* | 2080 | /* |
| 2194 | * If we have an opaque mask and source is one opaque pixel we can convert to the | 2081 | * If we have an opaque mask and source is one opaque pixel we can convert to the |
| 2195 | * destination format and just replicate with memset. | 2082 | * destination format and just replicate with memset. |
| @@ -2199,11 +2086,9 @@ DBG print("state %lux mval %lux dd %d\n", par->state, par->mval, dst->depth); · 3 unmodified lines |
| 2199 | int d, dwid, ppb, np, nb; | 2086 | int d, dwid, ppb, np, nb; |
| 2200 | uchar *dp, lm, rm; | 2087 | uchar *dp, lm, rm; |
| 2201 | | 2088 | |
| 2202 | DBG print("memopt, dst %p, dst->data->bdata %p\n", dst, dst->data->bdata); | | |
| 2203 | dwid = dst->width*sizeof(ulong); | 2089 | dwid = dst->width*sizeof(ulong); |
| 2204 | dp = byteaddr(dst, par->r.min); | 2090 | dp = byteaddr(dst, par->r.min); |
| 2205 | v = par->sdval; | 2091 | v = par->sdval; |
| 2206 | DBG print("sdval %lud, depth %d\n", v, dst->depth); | | |
| 2207 | switch(dst->depth){ | 2092 | switch(dst->depth){ |
| 2208 | case 1: | 2093 | case 1: |
| 2209 | case 2: | 2094 | case 2: |
| @@ -2217,16 +2102,13 @@ DBG print("sdval %lud, depth %d\n", v, dst->depth); · 7 unmodified lines |
| 2217 | dx -= (ppb-np); | 2102 | dx -= (ppb-np); |
| 2218 | nb = 8 - np * dst->depth; /* no. bits used on right side of word */ | 2103 | nb = 8 - np * dst->depth; /* no. bits used on right side of word */ |
| 2219 | lm = (1<<nb)-1; | 2104 | lm = (1<<nb)-1; |
| 2220 | DBG print("np %d x %d nb %d lm %ux ppb %d m %ux\n", np, par->r.min.x, nb, lm, ppb, m); | | |
| 2221 | | 2105 | |
| 2222 | /* right edge */ | 2106 | /* right edge */ |
| 2223 | np = par->r.max.x&m; /* no. pixels used on left side of word */ | 2107 | np = par->r.max.x&m; /* no. pixels used on left side of word */ |
| 2224 | dx -= np; | 2108 | dx -= np; |
| 2225 | nb = 8 - np * dst->depth; /* no. bits unused on right side of word */ | 2109 | nb = 8 - np * dst->depth; /* no. bits unused on right side of word */ |
| 2226 | rm = ~((1<<nb)-1); | 2110 | rm = ~((1<<nb)-1); |
| 2227 | DBG print("np %d x %d nb %d rm %ux ppb %d m %ux\n", np, par->r.max.x, nb, rm, ppb, m); | | |
| 2228 | | 2111 | |
| 2229 | DBG print("dx %d Dx %d\n", dx, Dx(par->r)); | | |
| 2230 | /* lm, rm are masks that are 1 where we should touch the bits */ | 2112 | /* lm, rm are masks that are 1 where we should touch the bits */ |
| 2231 | if(dx < 0){ /* just one byte */ | 2113 | if(dx < 0){ /* just one byte */ |
| 2232 | lm &= rm; | 2114 | lm &= rm; |
| @@ -2238,7 +2120,6 @@ DBG print("dx %d Dx %d\n", dx, Dx(par->r)); · 5 unmodified lines |
| 2238 | | 2120 | |
| 2239 | for(y=0; y<dy; y++, dp+=dwid){ | 2121 | for(y=0; y<dy; y++, dp+=dwid){ |
| 2240 | if(lm){ | 2122 | if(lm){ |
| 2241 | DBG print("dp %p v %lux lm %ux (v ^ *dp) & lm %lux\n", dp, v, lm, (v^*dp)&lm); | | |
| 2242 | *dp ^= (v ^ *dp) & lm; | 2123 | *dp ^= (v ^ *dp) & lm; |
| 2243 | dp++; | 2124 | dp++; |
| 2244 | } | 2125 | } |
| @@ -2412,13 +2293,11 @@ DBG print("dp %p v %lux lm %ux (v ^ *dp) & lm %lux\n", dp, v, lm, (v^*dp)&lm); · 167 unmodified lines |
| 2412 | } | 2293 | } |
| 2413 | return 0; | 2294 | return 0; |
| 2414 | } | 2295 | } |
| 2415 | #undef DBG | | |
| 2416 | | 2296 | |
| 2417 | /* | 2297 | /* |
| 2418 | * Boolean character drawing. | 2298 | * Boolean character drawing. |
| 2419 | * Solid opaque color through a 1-bit greyscale mask. | 2299 | * Solid opaque color through a 1-bit greyscale mask. |
| 2420 | */ | 2300 | */ |
| 2421 | #define DBG if(0) | | |
| 2422 | static int | 2301 | static int |
| 2423 | chardraw(Memdrawparam *par) | 2302 | chardraw(Memdrawparam *par) |
| 2424 | { | 2303 | { |
| @@ -2431,10 +2310,6 @@ chardraw(Memdrawparam *par) · 6 unmodified lines |
| 2431 | Rectangle r, mr; | 2310 | Rectangle r, mr; |
| 2432 | Memimage *mask, *src, *dst; | 2311 | Memimage *mask, *src, *dst; |
| 2433 | | 2312 | |
| 2434 | if(0) if(drawdebug) iprint("chardraw? mf %lux md %d sf %lux dxs %d dys %d dd %d ddat %p sdat %p\n", | | |
| 2435 | par->mask->flags, par->mask->depth, par->src->flags, | | |
| 2436 | Dx(par->src->r), Dy(par->src->r), par->dst->depth, par->dst->data, par->src->data); | | |
| 2437 | | | |
| 2438 | mask = par->mask; | 2313 | mask = par->mask; |
| 2439 | src = par->src; | 2314 | src = par->src; |
| 2440 | dst = par->dst; | 2315 | dst = par->dst; |
| @@ -2447,8 +2322,6 @@ if(0) if(drawdebug) iprint("chardraw? mf %lux md %d sf %lux dxs %d dys %d dd %d · 6 unmodified lines |
| 2447 | || op != SoverD) | 2322 | || op != SoverD) |
| 2448 | return 0; | 2323 | return 0; |
| 2449 | | 2324 | |
| 2450 | //if(drawdebug) iprint("chardraw..."); | | |
| 2451 | | | |
| 2452 | depth = mask->depth; | 2325 | depth = mask->depth; |
| 2453 | maskwid = mask->width*sizeof(ulong); | 2326 | maskwid = mask->width*sizeof(ulong); |
| 2454 | rp = byteaddr(mask, mr.min); | 2327 | rp = byteaddr(mask, mr.min); |
| @@ -2457,7 +2330,6 @@ if(0) if(drawdebug) iprint("chardraw? mf %lux md %d sf %lux dxs %d dys %d dd %d · 2 unmodified lines |
| 2457 | | 2330 | |
| 2458 | wp = byteaddr(dst, r.min); | 2331 | wp = byteaddr(dst, r.min); |
| 2459 | dstwid = dst->width*sizeof(ulong); | 2332 | dstwid = dst->width*sizeof(ulong); |
| 2460 | DBG print("bsh %d\n", bsh); | | |
| 2461 | dy = Dy(r); | 2333 | dy = Dy(r); |
| 2462 | dx = Dx(r); | 2334 | dx = Dx(r); |
| 2463 | | 2335 | |
| @@ -2483,20 +2355,17 @@ DBG print("bsh %d\n", bsh); · 19 unmodified lines |
| 2483 | sp[2] = v>>16; | 2355 | sp[2] = v>>16; |
| 2484 | sp[3] = v>>24; | 2356 | sp[3] = v>>24; |
| 2485 | | 2357 | |
| 2486 | //print("sp %x %x %x %x\n", sp[0], sp[1], sp[2], sp[3]); | | |
| 2487 | for(y=0; y<dy; y++, rp+=maskwid, wp+=dstwid){ | 2358 | for(y=0; y<dy; y++, rp+=maskwid, wp+=dstwid){ |
| 2488 | q = rp; | 2359 | q = rp; |
| 2489 | if(bsh) | 2360 | if(bsh) |
| 2490 | bits = *q++; | 2361 | bits = *q++; |
| 2491 | switch(ddepth){ | 2362 | switch(ddepth){ |
| 2492 | case 8: | 2363 | case 8: |
| 2493 | //if(drawdebug) iprint("8loop..."); | | |
| 2494 | wc = wp; | 2364 | wc = wp; |
| 2495 | for(x=bx; x>ex; x--, wc++){ | 2365 | for(x=bx; x>ex; x--, wc++){ |
| 2496 | i = x&7; | 2366 | i = x&7; |
| 2497 | if(i == 8-1) | 2367 | if(i == 8-1) |
| 2498 | bits = *q++; | 2368 | bits = *q++; |
| 2499 | DBG print("bits %lux sh %d...", bits, i); | | |
| 2500 | if((bits>>i)&1) | 2369 | if((bits>>i)&1) |
| 2501 | *wc = v; | 2370 | *wc = v; |
| 2502 | } | 2371 | } |
| @@ -2508,7 +2377,6 @@ DBG print("bits %lux sh %d...", bits, i); · 5 unmodified lines |
| 2508 | i = x&7; | 2377 | i = x&7; |
| 2509 | if(i == 8-1) | 2378 | if(i == 8-1) |
| 2510 | bits = *q++; | 2379 | bits = *q++; |
| 2511 | DBG print("bits %lux sh %d...", bits, i); | | |
| 2512 | if((bits>>i)&1) | 2380 | if((bits>>i)&1) |
| 2513 | *ws = v; | 2381 | *ws = v; |
| 2514 | } | 2382 | } |
| @@ -2519,7 +2387,6 @@ DBG print("bits %lux sh %d...", bits, i); · 4 unmodified lines |
| 2519 | i = x&7; | 2387 | i = x&7; |
| 2520 | if(i == 8-1) | 2388 | if(i == 8-1) |
| 2521 | bits = *q++; | 2389 | bits = *q++; |
| 2522 | DBG print("bits %lux sh %d...", bits, i); | | |
| 2523 | if((bits>>i)&1){ | 2390 | if((bits>>i)&1){ |
| 2524 | wc[0] = sp[0]; | 2391 | wc[0] = sp[0]; |
| 2525 | wc[1] = sp[1]; | 2392 | wc[1] = sp[1]; |
| @@ -2534,18 +2401,14 @@ DBG print("bits %lux sh %d...", bits, i); · 8 unmodified lines |
| 2534 | i = x&7; | 2401 | i = x&7; |
| 2535 | if(i == 8-1) | 2402 | if(i == 8-1) |
| 2536 | bits = *q++; | 2403 | bits = *q++; |
| 2537 | DBG iprint("bits %lux sh %d...", bits, i); | | |
| 2538 | if((bits>>i)&1) | 2404 | if((bits>>i)&1) |
| 2539 | *wl = v; | 2405 | *wl = v; |
| 2540 | } | 2406 | } |
| 2541 | break; | 2407 | break; |
| 2542 | } | 2408 | } |
| 2543 | } | 2409 | } |
| 2544 | | | |
| 2545 | DBG print("\n"); | | |
| 2546 | return 1; | 2410 | return 1; |
| 2547 | } | 2411 | } |
| 2548 | #undef DBG | | |
| 2549 | | 2412 | |
| 2550 | | 2413 | |
| 2551 | void | 2414 | void |