ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.101 by root, Mon Jul 2 03:57:53 2012 UTC vs.
Revision 1.108 by sf-exg, Fri Nov 7 13:45:55 2014 UTC

6 * Copyright (c) 2012 Marc Lehmann <schmorp@schmorp.de> 6 * Copyright (c) 2012 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2012 Emanuele Giaquinta <e.giaquinta@glauco.it> 7 * Copyright (c) 2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
13 * 13 *
14 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
188 } 188 }
189 189
190 // CreateSolidFill creates a very very very weird picture 190 // CreateSolidFill creates a very very very weird picture
191 void mask (const rgba &c) 191 void mask (const rgba &c)
192 { 192 {
193 // the casts are needed in C++11 (see 8.5.1)
193 XRenderColor rc = { 194 XRenderColor rc = {
194 c.r * c.a / 65535, 195 (unsigned short)(c.r * c.a / 65535),
195 c.g * c.a / 65535, 196 (unsigned short)(c.g * c.a / 65535),
196 c.b * c.a / 65535, 197 (unsigned short)(c.b * c.a / 65535),
197 c.a 198 c.a
198 }; 199 };
199 msk = XRenderCreateSolidFill (dpy, &rc); 200 msk = XRenderCreateSolidFill (dpy, &rc);
200 ecb_assume (msk); 201 ecb_assume (msk);
201 } 202 }
202 203
203 void fill (const rgba &c) 204 void fill (const rgba &c)
204 { 205 {
205 XRenderColor rc = { 206 XRenderColor rc = {
206 c.r * c.a / 65535, 207 (unsigned short)(c.r * c.a / 65535),
207 c.g * c.a / 65535, 208 (unsigned short)(c.g * c.a / 65535),
208 c.b * c.a / 65535, 209 (unsigned short)(c.b * c.a / 65535),
209 c.a 210 c.a
210 }; 211 };
211 212
212 XRenderFillRectangle (dpy, PictOpSrc, msk, &rc, 0, 0, 1, 1); 213 XRenderFillRectangle (dpy, PictOpSrc, msk, &rc, 0, 0, 1, 1);
213 } 214 }
214 215
349 for (int y = 0; y < height; y++) 350 for (int y = 0; y < height; y++)
350 { 351 {
351 unsigned char *src = row; 352 unsigned char *src = row;
352 uint32_t *dst = (uint32_t *)line; 353 uint32_t *dst = (uint32_t *)line;
353 354
354 if (!pb_has_alpha)
355 for (int x = 0; x < width; x++) 355 for (int x = 0; x < width; x++)
356 { 356 {
357 uint8_t r = *src++; 357 uint8_t r = *src++;
358 uint8_t g = *src++; 358 uint8_t g = *src++;
359 uint8_t b = *src++; 359 uint8_t b = *src++;
360 uint8_t a = *src;
360 361
362 // this is done so it can be jump-free, but newer gcc's clone inner the loop
363 a = pb_has_alpha ? a : 255;
364 src += pb_has_alpha;
365
366 r = (r * a + 127) / 255;
367 g = (g * a + 127) / 255;
368 b = (b * a + 127) / 255;
369
361 uint32_t v = (255 << 24) | (r << 16) | (g << 8) | b; 370 uint32_t v = (a << 24) | (r << 16) | (g << 8) | b;
362 371
363 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch) 372 if (ecb_big_endian () ? !byte_order_mismatch : byte_order_mismatch)
364 v = ecb_bswap32 (v); 373 v = ecb_bswap32 (v);
365 374
366 *dst++ = v; 375 *dst++ = v;
367 } 376 }
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 377
384 row += rowstride; 378 row += rowstride;
385 line += xi.bytes_per_line; 379 line += xi.bytes_per_line;
386 } 380 }
387 381
540 return clone (); 534 return clone ();
541 535
542 Display *dpy = s->dpy; 536 Display *dpy = s->dpy;
543 int size = max (rh, rv) * 2 + 1; 537 int size = max (rh, rv) * 2 + 1;
544 nv *kernel = (nv *)malloc (size * sizeof (nv)); 538 nv *kernel = (nv *)malloc (size * sizeof (nv));
545 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 539 XFixed *params = rxvt_temp_buf<XFixed> (size + 2);
546 rxvt_img *img = new_empty (); 540 rxvt_img *img = new_empty ();
547 541
548 XRenderPictureAttributes pa; 542 XRenderPictureAttributes pa;
549 pa.repeat = RepeatPad; 543 pa.repeat = RepeatPad;
550 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 544 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
585 0, 0, 579 0, 0,
586 w, h); 580 w, h);
587 } 581 }
588 582
589 free (kernel); 583 free (kernel);
590 free (params);
591 584
592 XRenderFreePicture (dpy, src); 585 XRenderFreePicture (dpy, src);
593 XRenderFreePicture (dpy, dst); 586 XRenderFreePicture (dpy, dst);
594 XRenderFreePicture (dpy, tmp); 587 XRenderFreePicture (dpy, tmp);
595 588
604 composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat)); 597 composer cc (this, new rxvt_img (s, format, 0, 0, w * 2, h, repeat));
605 598
606 // why the hell does XRenderSetPictureTransform want a writable matrix :( 599 // why the hell does XRenderSetPictureTransform want a writable matrix :(
607 // that keeps us from just static const'ing this matrix. 600 // that keeps us from just static const'ing this matrix.
608 XTransform h_double = { 601 XTransform h_double = {
609 32768, 0, 0, 602 0x08000, 0, 0,
610 0, 65536, 0, 603 0, 0x10000, 0,
611 0, 0, 65536 604 0, 0, 0x10000
612 }; 605 };
613 606
614 XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0); 607 XRenderSetPictureFilter (cc.dpy, cc.src, "nearest", 0, 0);
615 XRenderSetPictureTransform (cc.dpy, cc.src, &h_double); 608 XRenderSetPictureTransform (cc.dpy, cc.src, &h_double);
616 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h); 609 XRenderComposite (cc.dpy, PictOpSrc, cc.src, None, cc.dst, 0, 0, 0, 0, 0, 0, w * 2, h);
638 XDoubleToFixed (3), XDoubleToFixed (1), 631 XDoubleToFixed (3), XDoubleToFixed (1),
639 XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add) 632 XDoubleToFixed (0), XDoubleToFixed (mul), XDoubleToFixed (add)
640 }; 633 };
641 634
642 XTransform h_halve = { 635 XTransform h_halve = {
643 131072, 0, 0, 636 0x20000, 0, 0,
644 0, 65536, 0, 637 0, 0x10000, 0,
645 0, 0, 65536 638 0, 0, 0x10000
646 }; 639 };
647 640
648 XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0); 641 XRenderSetPictureFilter (cc.dpy, cc2.src, "nearest", 0, 0);
649 XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve); 642 XRenderSetPictureTransform (cc.dpy, cc2.src, &h_halve);
650 XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel)); 643 XRenderSetPictureFilter (cc.dpy, cc2.src, FilterConvolution, kernel, ecb_array_length (kernel));
765rxvt_img::reify () 758rxvt_img::reify ()
766{ 759{
767 if (x == 0 && y == 0 && w == ref->w && h == ref->h) 760 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
768 return clone (); 761 return clone ();
769 762
770 Display *dpy = s->dpy;
771
772 // add an alpha channel if... 763 // add an alpha channel if...
773 bool alpha = !format->direct.alphaMask // pixmap has none yet 764 bool alpha = !format->direct.alphaMask // pixmap has none yet
774 && (x || y) // we need one because of non-zero offset 765 && (x || y) // we need one because of non-zero offset
775 && repeat == RepeatNone; // and we have no good pixels to fill with 766 && repeat == RepeatNone; // and we have no good pixels to fill with
776 767
777 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,
778 0, 0, w, h, repeat)); 769 0, 0, w, h, repeat));
779 770
780 if (alpha) 771 if (repeat == RepeatNone)
781 { 772 {
782 XRenderColor rc = { 0, 0, 0, 0 }; 773 XRenderColor rc = { 0, 0, 0, 0 };
783 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
784 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);
785 } 776 }
924 915
925 return cc; 916 return cc;
926} 917}
927 918
928rxvt_img * 919rxvt_img *
920rxvt_img::shade (nv factor, rgba c)
921{
922 clamp_it (factor, -1., 1.);
923 factor++;
924
925 if (factor > 1)
926 {
927 c.r = c.r * (2 - factor);
928 c.g = c.g * (2 - factor);
929 c.b = c.b * (2 - factor);
930 }
931 else
932 {
933 c.r = c.r * factor;
934 c.g = c.g * factor;
935 c.b = c.b * factor;
936 }
937
938 rxvt_img *img = this->tint (c);
939
940 if (factor > 1)
941 {
942 c.a = 0xffff;
943 c.r =
944 c.g =
945 c.b = 0xffff * (factor - 1);
946
947 img->brightness (c.r, c.g, c.b, c.a);
948 }
949
950 return img;
951}
952
953rxvt_img *
929rxvt_img::filter (const char *name, int nparams, nv *params) 954rxvt_img::filter (const char *name, int nparams, nv *params)
930{ 955{
931 composer cc (this); 956 composer cc (this);
932 957
933 XFixed *xparams = rxvt_temp_buf<XFixed> (nparams); 958 XFixed *xparams = rxvt_temp_buf<XFixed> (nparams);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines