… | |
… | |
170 | src = srcimg->picture (); |
170 | src = srcimg->picture (); |
171 | dst = this->dstimg->picture (); |
171 | dst = this->dstimg->picture (); |
172 | } |
172 | } |
173 | |
173 | |
174 | ecb_noinline |
174 | ecb_noinline |
175 | void mask (bool rgb = true, int x = 1, int y = 1) |
175 | void mask (bool rgb = true, int w = 1, int h = 1) |
176 | { |
176 | { |
177 | Pixmap pixmap = XCreatePixmap (dpy, srcimg->pm, x, y, rgb ? 32 : 8); |
177 | Pixmap pixmap = XCreatePixmap (dpy, srcimg->pm, w, h, rgb ? 32 : 8); |
178 | |
178 | |
179 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, rgb ? PictStandardARGB32 : PictStandardA8); |
179 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, rgb ? PictStandardARGB32 : PictStandardA8); |
180 | XRenderPictureAttributes pa; |
180 | XRenderPictureAttributes pa; |
181 | pa.repeat = RepeatNormal; |
181 | pa.repeat = RepeatNormal; |
182 | pa.component_alpha = rgb; |
182 | pa.component_alpha = rgb; |
… | |
… | |
349 | for (int y = 0; y < height; y++) |
349 | for (int y = 0; y < height; y++) |
350 | { |
350 | { |
351 | unsigned char *src = row; |
351 | unsigned char *src = row; |
352 | uint32_t *dst = (uint32_t *)line; |
352 | uint32_t *dst = (uint32_t *)line; |
353 | |
353 | |
354 | if (!pb_has_alpha) |
|
|
355 | for (int x = 0; x < width; x++) |
354 | for (int x = 0; x < width; x++) |
356 | { |
355 | { |
357 | uint8_t r = *src++; |
356 | uint8_t r = *src++; |
358 | uint8_t g = *src++; |
357 | uint8_t g = *src++; |
359 | uint8_t b = *src++; |
358 | uint8_t b = *src++; |
|
|
359 | uint8_t a = *src; |
360 | |
360 | |
|
|
361 | // this is done so it can be jump-free, but newer gcc's clone inner the loop |
|
|
362 | a = pb_has_alpha ? a : 255; |
|
|
363 | src += pb_has_alpha; |
|
|
364 | |
|
|
365 | r = (r * a + 127) / 255; |
|
|
366 | g = (g * a + 127) / 255; |
|
|
367 | b = (b * a + 127) / 255; |
|
|
368 | |
361 | uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; |
369 | uint32_t v = (a << 24) | (r << 16) | (g << 8) | b; |
362 | |
370 | |
363 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
371 | if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) |
364 | v = ecb_bswap32 (v); |
372 | v = ecb_bswap32 (v); |
365 | |
373 | |
366 | *dst++ = v; |
374 | *dst++ = v; |
367 | } |
375 | } |
368 | else |
|
|
369 | for (int x = 0; x < width; x++) |
|
|
370 | { |
|
|
371 | uint32_t v = *(uint32_t *)src; src += 4; |
|
|
372 | |
|
|
373 | if (ecb_big_endian ()) |
|
|
374 | v = ecb_bswap32 (v); |
|
|
375 | |
|
|
376 | v = ecb_rotl32 (v, 8); // abgr to bgra |
|
|
377 | |
|
|
378 | if (!byte_order_mismatch) |
|
|
379 | v = ecb_bswap32 (v); |
|
|
380 | |
|
|
381 | *dst++ = v; |
|
|
382 | } |
|
|
383 | |
376 | |
384 | row += rowstride; |
377 | row += rowstride; |
385 | line += xi.bytes_per_line; |
378 | line += xi.bytes_per_line; |
386 | } |
379 | } |
387 | |
380 | |
… | |
… | |
476 | pm = pm2; |
469 | pm = pm2; |
477 | ref = new pixref (ref->w, ref->h); |
470 | ref = new pixref (ref->w, ref->h); |
478 | } |
471 | } |
479 | |
472 | |
480 | void |
473 | void |
481 | rxvt_img::fill (const rgba &c) |
474 | rxvt_img::fill (const rgba &c, int x, int y, int w, int h) |
482 | { |
475 | { |
483 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
476 | XRenderColor rc = { c.r, c.g, c.b, c.a }; |
484 | |
477 | |
485 | Display *dpy = s->dpy; |
478 | Display *dpy = s->dpy; |
486 | Picture src = picture (); |
479 | Picture src = picture (); |
487 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, 0, 0, w, h); |
480 | XRenderFillRectangle (dpy, PictOpSrc, src, &rc, x, y, w, h); |
488 | XRenderFreePicture (dpy, src); |
481 | XRenderFreePicture (dpy, src); |
|
|
482 | } |
|
|
483 | |
|
|
484 | void |
|
|
485 | rxvt_img::fill (const rgba &c) |
|
|
486 | { |
|
|
487 | fill (c, 0, 0, w, h); |
489 | } |
488 | } |
490 | |
489 | |
491 | void |
490 | void |
492 | rxvt_img::add_alpha () |
491 | rxvt_img::add_alpha () |
493 | { |
492 | { |
… | |
… | |
586 | XRenderFreePicture (dpy, src); |
585 | XRenderFreePicture (dpy, src); |
587 | XRenderFreePicture (dpy, dst); |
586 | XRenderFreePicture (dpy, dst); |
588 | XRenderFreePicture (dpy, tmp); |
587 | XRenderFreePicture (dpy, tmp); |
589 | |
588 | |
590 | return img; |
589 | return img; |
|
|
590 | } |
|
|
591 | |
|
|
592 | rxvt_img * |
|
|
593 | rxvt_img::muladd (nv mul, nv add) |
|
|
594 | { |
|
|
595 | // STEP 1: double the image width, fill all odd columns with white (==1) |
|
|
596 | |
|
|
597 | composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat)); |
|
|
598 | |
|
|
599 | // why the hell does XRenderSetPictureTransform want a writable matrix :( |
|
|
600 | // that keeps us from just static const'ing this matrix. |
|
|
601 | XTransform h_double = { |
|
|
602 | 0x08000, 0, 0, |
|
|
603 | 0, 0x10000, 0, |
|
|
604 | 0, 0, 0x10000 |
|
|
605 | }; |
|
|
606 | |
|
|
607 | XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0); |
|
|
608 | XRenderSetPictureTransform (cc.dpy, cc.src, &h_double); |
|
|
609 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
|
|
610 | |
|
|
611 | cc.mask (false, 2, 1); |
|
|
612 | |
|
|
613 | static const XRenderColor c0 = { 0, 0, 0, 0 }; |
|
|
614 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &c0, 0, 0, 1, 1); |
|
|
615 | static const XRenderColor c1 = { 65535, 65535, 65535, 65535 }; |
|
|
616 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.msk, &c1, 1, 0, 1, 1); |
|
|
617 | |
|
|
618 | Picture white = XRenderCreateSolidFill (cc.dpy, &c1); |
|
|
619 | |
|
|
620 | XRenderComposite (cc.dpy, PictOpOver, white, cc.msk, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
|
|
621 | |
|
|
622 | XRenderFreePicture (cc.dpy, white); |
|
|
623 | |
|
|
624 | // STEP 2: convolve the image with a 3x1 filter |
|
|
625 | // a 2x1 filter would obviously suffice, but given the total lack of specification |
|
|
626 | // for xrender, I expect different xrender implementations to randomly diverge. |
|
|
627 | // we also halve the image, and hope for the best (again, for lack of specs). |
|
|
628 | composer cc2 (cc.dstimg); |
|
|
629 | |
|
|
630 | XFixed kernel [] = { |
|
|
631 | XDoubleToFixed (3), XDoubleToFixed (1), |
|
|
632 | XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add) |
|
|
633 | }; |
|
|
634 | |
|
|
635 | XTransform h_halve = { |
|
|
636 | 0x20000, 0, 0, |
|
|
637 | 0, 0x10000, 0, |
|
|
638 | 0, 0, 0x10000 |
|
|
639 | }; |
|
|
640 | |
|
|
641 | XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0); |
|
|
642 | XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve); |
|
|
643 | XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel)); |
|
|
644 | |
|
|
645 | XRenderComposite (cc.dpy, PictOpSrc, cc2.src, None, cc2.dst, 0, 0, 0, 0, 0, 0, w * 2, h); |
|
|
646 | |
|
|
647 | return cc2; |
591 | } |
648 | } |
592 | |
649 | |
593 | ecb_noinline static void |
650 | ecb_noinline static void |
594 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
651 | extract (int32_t cl0, int32_t cl1, int32_t &c, unsigned short &xc) |
595 | { |
652 | { |
… | |
… | |
701 | rxvt_img::reify () |
758 | rxvt_img::reify () |
702 | { |
759 | { |
703 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
760 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
704 | return clone (); |
761 | return clone (); |
705 | |
762 | |
706 | Display *dpy = s->dpy; |
|
|
707 | |
|
|
708 | // add an alpha channel if... |
763 | // add an alpha channel if... |
709 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
764 | bool alpha = !format->direct.alphaMask // pixmap has none yet |
710 | && (x || y) // we need one because of non-zero offset |
765 | && (x || y) // we need one because of non-zero offset |
711 | && repeat == RepeatNone; // and we have no good pixels to fill with |
766 | && repeat == RepeatNone; // and we have no good pixels to fill with |
712 | |
767 | |
713 | composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, |
768 | composer cc (this, new rxvt_img (s, alpha ? find_alpha_format_for (s->dpy, format) : format, |
714 | 0, 0, w, h, repeat)); |
769 | 0, 0, w, h, repeat)); |
715 | |
770 | |
716 | if (alpha) |
771 | if (repeat == RepeatNone) |
717 | { |
772 | { |
718 | XRenderColor rc = { 0, 0, 0, 0 }; |
773 | XRenderColor rc = { 0, 0, 0, 0 }; |
719 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
774 | XRenderFillRectangle (cc.dpy, PictOpSrc, cc.dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles |
720 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
775 | XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, x, y, ref->w, ref->h); |
721 | } |
776 | } |