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

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.54 by ayin, Thu Aug 2 00:09:54 2007 UTC vs.
Revision 1.55 by sasha, Fri Aug 3 05:33:04 2007 UTC

95 else 95 else
96 { 96 {
97 bgpixmap->auto_resize = False ; 97 bgpixmap->auto_resize = False ;
98 flags = XParseGeometry (str, &x, &y, &w, &h); 98 flags = XParseGeometry (str, &x, &y, &w, &h);
99 } 99 }
100 100/* code below is garbage and needs to be rewritten */
101 if (!flags) 101 if (!flags)
102 { 102 {
103 flags |= WidthValue; 103 flags |= WidthValue;
104 w = 0; 104 w = 0;
105 } /* default is tile */ 105 } /* default is tile */
151 { 151 {
152 x += bgpixmap->x; 152 x += bgpixmap->x;
153 y += bgpixmap->y; 153 y += bgpixmap->y;
154 } 154 }
155 155
156 if (xpmAttr.width && xpmAttr.height)
157 {
158 x = MOD(x, xpmAttr.width);
159 y = MOD(y, xpmAttr.height);
160 }
161
162 if (bgpixmap->x != x) 156 if (bgpixmap->x != x)
163 { 157 {
164 bgpixmap->x = x; 158 bgpixmap->x = x;
165 changed++; 159 changed++;
166 } 160 }
178void 172void
179rxvt_term::resize_pixmap () 173rxvt_term::resize_pixmap ()
180{ 174{
181 XGCValues gcvalue; 175 XGCValues gcvalue;
182 GC gc; 176 GC gc;
177 unsigned int w = bgPixmap.w, h = bgPixmap.h;
178 unsigned int x = bgPixmap.x, y = bgPixmap.y;
179 ASImage *im = bgPixmap.original_asim;
183 180
184 if (pixmap != None) 181/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
185 {
186 XFreePixmap (dpy, pixmap);
187 pixmap = None ;
188 }
189
190 if (bgPixmap.pixmap == None) 182 if (bgPixmap.pixmap != None)
183 {
184 XFreePixmap (dpy, bgPixmap.pixmap);
185 bgPixmap.pixmap = None ;
186 }
187#ifdef ENABLE_TRANSPARENCY
188 if (option(Opt_transparent) && am_transparent)
189 {
190 /* we need to re-generate transparency pixmap in that case ! */
191 check_our_parents ();
192 return;
193 }
194#endif
195
196 if (bgPixmap.original_asim == NULL)
191 { /* So be it: I'm not using pixmaps */ 197 { /* So be it: I'm not using pixmaps */
192 pixmap = None;
193
194#ifdef ENABLE_TRANSPARENCY
195 if (!option (Opt_transparent) || !am_transparent)
196#endif
197 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 198 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
198
199 return; 199 return;
200 } 200 }
201 201
202 gcvalue.foreground = pix_colors[Color_bg]; 202 gcvalue.foreground = pix_colors[Color_bg];
203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); 203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
204 204
205 if (bgPixmap.pixmap != None)
206 { /* we have a specified pixmap */
207 unsigned int w = bgPixmap.w, h = bgPixmap.h,
208 x = bgPixmap.x, y = bgPixmap.y;
209 unsigned int xpmh = xpmAttr.height,
210 xpmw = xpmAttr.width;
211
212 if (bgPixmap.auto_resize) 205 if (bgPixmap.auto_resize)
213 { 206 {
214 w = szHint.width ; 207 w = szHint.width;
215 h = szHint.height ; 208 h = szHint.height;
216 } 209 }
217 /* 210 else
218 * don't zoom pixmap too much nor expand really small pixmaps 211 { /* don't zoom pixmap too much nor expand really small pixmaps */
219 */ 212 if (w > 16000)
220 if (w > 32767 || h > 32767)
221 w = 1; 213 w = 1;
222 else if (width > (10 * xpmw) 214 if (h > 16000)
223 || height > (10 * xpmh)) 215 h = 1;
224 w = 0; /* tile */ 216 }
217 if (w == 0) w = im->width;
218 else if (w < 10) w *= im->width;
219 if (h == 0) h = im->height;
220 else if (w < 10) h *= im->height;
225 221
226 if (!w) 222 if (w != im->width || h != im->height)
227 { 223 {
228 /* basic X tiling - let the X server do it */ 224 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
229 pixmap = XCreatePixmap (dpy, vt, xpmw, xpmh, depth); 225 if (tmp != NULL)
230 226 im = tmp;
231 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0); 227 }
232 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); 228 if (x != 0 || y != 0)
233 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); 229 {
234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); 230 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
231 if (tmp != NULL)
235 } 232 {
236 else 233 if (im != bgPixmap.original_asim)
237#ifdef ENABLE_TRANSPARENCY 234 destroy_asimage (&im);
238 if (!option(Opt_transparent) || !am_transparent) 235 im = tmp;
239 /* will do that in check_our_parents otherwise */
240#endif
241 { 236 }
242 ASImage *scaled_im = scale_asimage (asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 237 }
243 if (scaled_im) 238 bgPixmap.pixmap = XCreatePixmap (dpy, vt, w, h, depth);
244 { 239 bgPixmap.pmap_width = w;
245 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True); 240 bgPixmap.pmap_height = h;
241 bgPixmap.pmap_depth = depth;
242
243 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, w, h, True);
244
245 if (im != bgPixmap.original_asim)
246 destroy_asimage (&scaled_im); 246 destroy_asimage (&im);
247 }
248 }
249 }
250 247
251 XSetWindowBackgroundPixmap (dpy, vt, pixmap); 248 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
252 249
253 XFreeGC (dpy, gc); 250 XFreeGC (dpy, gc);
254#ifdef ENABLE_TRANSPARENCY
255 am_transparent = 0;
256#endif
257} 251}
258 252
259Pixmap 253void
260rxvt_term::set_bgPixmap (const char *file) 254rxvt_term::set_bgPixmap (const char *file)
261{ 255{
262 char *f; 256 char *f;
263 257
264 assert (file != NULL); 258 assert (file != NULL);
271 265
272 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 266 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
273 267
274 if (*file != '\0') 268 if (*file != '\0')
275 { 269 {
276 /* XWindowAttributes attr; */
277
278 /*
279 * we already have the required attributes
280 */
281 /* XGetWindowAttributes (dpy, vt, &attr); */
282
283 if (asimman == NULL) 270 if (asimman == NULL)
284 asimman = create_generic_imageman(rs[Rs_path]); 271 asimman = create_generic_imageman(rs[Rs_path]);
285 if ((f = strchr (file, ';')) == NULL) 272 if ((f = strchr (file, ';')) == NULL)
286 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 273 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
287 else 274 else
288 { 275 {
289 size_t len = f - file; 276 size_t len = f - file;
290 f = (char *)malloc (len + 1); 277 f = (char *)malloc (len + 1);
291 strncpy (f, file, len); 278 strncpy (f, file, len);
292 f[len] = '\0'; 279 f[len] = '\0';
293 original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 280 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
294 free( f ); 281 free( f );
295 } 282 }
296 if (original_asim)
297 {
298 bgPixmap.pixmap = asimage2pixmap (asv, display->root, original_asim, NULL, True);
299 xpmAttr.width = original_asim->width ;
300 xpmAttr.height = original_asim->height ;
301 }
302 } 283 }
303 284
304 resize_pixmap (); 285 resize_pixmap ();
305 return bgPixmap.pixmap;
306} 286}
307 287
308#endif /* XPM_BACKGROUND */ 288#endif /* XPM_BACKGROUND */
309 289
310#ifdef ENABLE_TRANSPARENCY 290#ifdef ENABLE_TRANSPARENCY
627 /* TODO: the below logic needs to be cleaned up */ 607 /* TODO: the below logic needs to be cleaned up */
628 if (!i || prop == NULL 608 if (!i || prop == NULL
629#if TINTING 609#if TINTING
630 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL 610 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
631#ifdef HAVE_AFTERIMAGE 611#ifdef HAVE_AFTERIMAGE
632 && original_asim == NULL && rs[Rs_blurradius] == NULL 612 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
633#endif 613#endif
634 ) 614 )
635#endif 615#endif
636 ) 616 )
637 rootpixmap = None; 617 rootpixmap = None;
674 && IS_COMPONENT_WHOLESOME(c.b)); 654 && IS_COMPONENT_WHOLESOME(c.b));
675 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 655 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
676#undef IS_COMPONENT_WHOLESOME 656#undef IS_COMPONENT_WHOLESOME
677#endif /* TINTING */ 657#endif /* TINTING */
678 /* theer are no performance advantages to reusing same pixmap */ 658 /* theer are no performance advantages to reusing same pixmap */
679 if (pixmap != None) 659 if (bgPixmap.pixmap != None)
680 XFreePixmap (dpy, pixmap); 660 XFreePixmap (dpy, bgPixmap.pixmap);
681 pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth); 661 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
662 bgPixmap.pmap_width = szHint.width;
663 bgPixmap.pmap_height = szHint.height;
664 bgPixmap.pmap_depth = rootdepth;
682 665
683#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 666#if 0 /* TODO : identify cases where this will be detrimental to performance : */
684 /* we want to tile root pixmap into our own pixmap in this cases : 667 /* we want to tile root pixmap into our own pixmap in this cases :
685 * 1) rootpixmap does not cover our window entirely 668 * 1) rootpixmap does not cover our window entirely
686 * 2) whole_tint - we can use server-side tinting or tinting disabled 669 * 2) whole_tint - we can use server-side tinting or tinting disabled
692 gcvalue.tile = rootpixmap; 675 gcvalue.tile = rootpixmap;
693 gcvalue.fill_style = FillTiled; 676 gcvalue.fill_style = FillTiled;
694 gcvalue.ts_x_origin = -sx; 677 gcvalue.ts_x_origin = -sx;
695 gcvalue.ts_y_origin = -sy; 678 gcvalue.ts_y_origin = -sy;
696 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue); 679 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
697 XFillRectangle (dpy, pixmap, gc, 0, 0, szHint.width, szHint.height); 680 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
698 681
699#if TINTING 682#if TINTING
700 if (whole_tint && !no_tint) 683 if (whole_tint && !no_tint)
701 { 684 {
702 /* In this case we can tint image server-side getting significant 685 /* In this case we can tint image server-side getting significant
704 */ 687 */
705 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); 688 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
706 gcvalue.function = GXand; 689 gcvalue.function = GXand;
707 gcvalue.fill_style = FillSolid; 690 gcvalue.fill_style = FillSolid;
708 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); 691 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
709 XFillRectangle (dpy, pixmap, gc, 0, 0, szHint.width, szHint.height); 692 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
710 } 693 }
711#endif 694#endif
712 success = True; 695 success = True;
713#ifdef HAVE_AFTERIMAGE 696#ifdef HAVE_AFTERIMAGE
714 if (rs[Rs_blurradius] || original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 697 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
715 { 698 {
716 ARGB32 tint = TINT_LEAVE_SAME; 699 ARGB32 tint = TINT_LEAVE_SAME;
717 ASImage *back_im = NULL; 700 ASImage *back_im = NULL;
718 701
719 back_im = pixmap2ximage (asv, pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100); 702 back_im = pixmap2ximage (asv, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100);
720 if (back_im != NULL) 703 if (back_im != NULL)
721 { 704 {
722 if (!whole_tint && (!no_tint || shade !=100)) 705 if (!whole_tint && (!no_tint || shade !=100))
723 { 706 {
724 ShadingInfo as_shade; 707 ShadingInfo as_shade;
738 if (!(flags&WidthValue)) 721 if (!(flags&WidthValue))
739 hr = 1; 722 hr = 1;
740 if (!(flags&HeightValue)) 723 if (!(flags&HeightValue))
741 vr = hr; 724 vr = hr;
742 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF, 725 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF,
743 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 726 (bgPixmap.original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
744 100, ASIMAGE_QUALITY_DEFAULT); 727 100, ASIMAGE_QUALITY_DEFAULT);
745 if (tmp) 728 if (tmp)
746 { 729 {
747 destroy_asimage (&back_im); 730 destroy_asimage (&back_im);
748 back_im = tmp; 731 back_im = tmp;
749 } 732 }
750 } 733 }
751 734
752 if (original_asim != NULL) 735 if (bgPixmap.original_asim != NULL)
753 { 736 {
754 ASImageLayer *layers = create_image_layers (2); 737 ASImageLayer *layers = create_image_layers (2);
755 ASImage *merged_im = NULL; 738 ASImage *merged_im = NULL;
756 int fore_w, fore_h; 739 int fore_w, fore_h;
757 740
758 layers[0].im = back_im; 741 layers[0].im = back_im;
759 layers[0].clip_width = szHint.width; 742 layers[0].clip_width = szHint.width;
760 layers[0].clip_height = szHint.height; 743 layers[0].clip_height = szHint.height;
761 layers[0].tint = tint; 744 layers[0].tint = tint;
762 layers[1].im = original_asim; 745 layers[1].im = bgPixmap.original_asim;
763 if (bgPixmap.auto_resize) 746 if (bgPixmap.auto_resize)
764 { 747 {
765 fore_w = szHint.width; 748 fore_w = szHint.width;
766 fore_h = szHint.height; 749 fore_h = szHint.height;
767 } 750 }
768 else 751 else
769 { 752 {
770 fore_w = bgPixmap.w; 753 fore_w = (bgPixmap.w == 0) ? bgPixmap.original_asim->width : bgPixmap.w;
771 fore_h = bgPixmap.h; 754 fore_h = (bgPixmap.h == 0) ? bgPixmap.original_asim->height : bgPixmap.h;
772 } 755 }
773 if (fore_w != original_asim->width 756 if (fore_w != bgPixmap.original_asim->width
774 || fore_h != original_asim->height) 757 || fore_h != bgPixmap.original_asim->height)
775 { 758 {
776 layers[1].im = scale_asimage (asv, 759 layers[1].im = scale_asimage (asv,
777 original_asim, 760 bgPixmap.original_asim,
778 fore_w, fore_h, 761 fore_w, fore_h,
779 ASA_ASImage, 100, 762 ASA_ASImage, 100,
780 ASIMAGE_QUALITY_DEFAULT); 763 ASIMAGE_QUALITY_DEFAULT);
781 } 764 }
782 layers[1].clip_width = szHint.width; 765 layers[1].clip_width = szHint.width;
789 layers[1].merge_scanlines = alphablend_scanlines; 772 layers[1].merge_scanlines = alphablend_scanlines;
790 } 773 }
791 PRINT_BACKGROUND_OP_TIME; 774 PRINT_BACKGROUND_OP_TIME;
792 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, 775 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
793 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 776 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
794 if (layers[1].im != original_asim) 777 if (layers[1].im != bgPixmap.original_asim)
795 destroy_asimage (&(layers[1].im)); 778 destroy_asimage (&(layers[1].im));
796 free (layers); 779 free (layers);
797 780
798 if (merged_im != NULL) 781 if (merged_im != NULL)
799 { 782 {
810 destroy_asimage (&back_im); 793 destroy_asimage (&back_im);
811 back_im = tmp; 794 back_im = tmp;
812 } 795 }
813 PRINT_BACKGROUND_OP_TIME; 796 PRINT_BACKGROUND_OP_TIME;
814 } 797 }
815 asimage2drawable (asv, pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); 798 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
816 destroy_asimage (&back_im); 799 destroy_asimage (&back_im);
817 } /* back_im != NULL */ 800 } /* back_im != NULL */
818 else 801 else
819 success = False; 802 success = False;
820 } 803 }
821#else /* HAVE_AFTERIMAGE */ 804#else /* HAVE_AFTERIMAGE */
822#if TINTING 805#if TINTING
823 if (!whole_tint && (!no_tint || shade !=100)) 806 if (!whole_tint && (!no_tint || shade !=100))
824 { 807 {
825 XImage *image = XGetImage (dpy, pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap); 808 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
826 success = False; 809 success = False;
827 if (image != NULL) 810 if (image != NULL)
828 { 811 {
829 PRINT_BACKGROUND_OP_TIME; 812 PRINT_BACKGROUND_OP_TIME;
830 if (gc == NULL) 813 if (gc == NULL)
831 gc = XCreateGC (dpy, vt, 0UL, &gcvalue); 814 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
832 if (ISSET_PIXCOLOR (Color_tint) || shade != 100) 815 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
833 ShadeXImage (this, image, shade, c.r, c.g, c.b); 816 ShadeXImage (this, image, shade, c.r, c.g, c.b);
834 XPutImage (dpy, pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); 817 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
835 XDestroyImage (image); 818 XDestroyImage (image);
836 success = True; 819 success = True;
837 } 820 }
838 } 821 }
839#endif 822#endif
846 if (!success) 829 if (!success)
847 { 830 {
848 if (am_transparent && am_pixmap_trans) 831 if (am_transparent && am_pixmap_trans)
849 { 832 {
850 pchanged = 1; 833 pchanged = 1;
851 if (pixmap != None) 834 if (bgPixmap.pixmap != None)
852 { 835 {
853 XFreePixmap (dpy, pixmap); 836 XFreePixmap (dpy, bgPixmap.pixmap);
854 pixmap = None; 837 bgPixmap.pixmap = None;
855 } 838 }
856 } 839 }
857 840
858 am_pixmap_trans = 0; 841 am_pixmap_trans = 0;
859 } 842 }
860 else 843 else
861 { 844 {
862 XSetWindowBackgroundPixmap (dpy, parent[0], pixmap); 845 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
863 XClearWindow (dpy, parent[0]); 846 XClearWindow (dpy, parent[0]);
864 847
865 if (!am_transparent || !am_pixmap_trans) 848 if (!am_transparent || !am_pixmap_trans)
866 pchanged = 1; 849 pchanged = 1;
867 850

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines