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.7 by sf-exg, Sun Jun 3 20:34:25 2012 UTC vs.
Revision 1.12 by root, Mon Jun 4 15:28:49 2012 UTC

18} 18}
19 19
20rxvt_img * 20rxvt_img *
21rxvt_img::new_from_file (rxvt_screen *s, const char *filename) 21rxvt_img::new_from_file (rxvt_screen *s, const char *filename)
22{ 22{
23 GError *err; 23 GError *err = 0;
24 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); 24 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err);
25 25
26 if (!pb) 26 if (!pb)
27 return 0; 27 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
28 28
29 rxvt_img *img = new rxvt_img ( 29 rxvt_img *img = new rxvt_img (
30 s, 30 s,
31 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 31 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
32 gdk_pixbuf_get_width (pb), 32 gdk_pixbuf_get_width (pb),
43 if (!shared) 43 if (!shared)
44 XFreePixmap (s->display->dpy, pm); 44 XFreePixmap (s->display->dpy, pm);
45} 45}
46 46
47void 47void
48rxvt_img::unshare ()
49{
50 if (!shared)
51 return;
52
53 rxvt_img *img = clone ();
54
55 ::swap (pm , img->pm);
56 ::swap (shared, img->shared);
57
58 delete img;
59}
60
61void
48rxvt_img::fill (const rxvt_color &c) 62rxvt_img::fill (const rxvt_color &c)
49{ 63{
50 XGCValues gcv; 64 XGCValues gcv;
51 gcv.foreground = c; 65 gcv.foreground = c;
52 GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv); 66 GC gc = XCreateGC (s->display->dpy, pm, GCForeground, &gcv);
191{ 205{
192 //TODO 206 //TODO
193} 207}
194 208
195rxvt_img * 209rxvt_img *
196rxvt_img::copy () 210rxvt_img::clone ()
197{ 211{
198 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 212 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
199 Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth); 213 Pixmap pm2 = XCreatePixmap (s->display->dpy, pm, w, h, format->depth);
200 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); 214 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0);
201 XFreeGC (s->display->dpy, gc); 215 XFreeGC (s->display->dpy, gc);
202 return new rxvt_img (s, format, w, h, pm2); 216 return new rxvt_img (s, format, w, h, pm2);
203} 217}
204 218
205rxvt_img * 219rxvt_img *
206rxvt_img::transform (int new_width, int new_height, double matrix[16]) 220rxvt_img::transform (int new_width, int new_height, int repeat, double matrix[9])
207{ 221{
208 //TODO 222 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
209}
210 223
211rxvt_img *
212rxvt_img::scale (int new_width, int new_height)
213{
214 // use transform
215 //TODO
216}
217
218rxvt_img *
219rxvt_img::convert_to (XRenderPictFormat *new_format)
220{
221 Display *dpy = s->display->dpy; 224 Display *dpy = s->display->dpy;
222 Pixmap new_pm = XCreatePixmap (dpy, pm, w, h, new_format->depth);
223 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 225 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
224 Picture dst = XRenderCreatePicture (dpy, new_pm, new_format, 0, 0); 226 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
225 227
228 XTransform xfrm;
229
230 for (int i = 0; i < 3; ++i)
231 for (int j = 0; j < 3; ++j)
232 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
233
234 XRenderSetPictureTransform (dpy, src, &xfrm);
226 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h); 235 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
227 236
228 XRenderFreePicture (dpy, src); 237 XRenderFreePicture (dpy, src);
229 XRenderFreePicture (dpy, dst); 238 XRenderFreePicture (dpy, dst);
230 239
231 rxvt_img *img = new rxvt_img (
232 s,
233 new_format,
234 w,
235 h,
236 new_pm
237 );
238
239 return img; 240 return img;
240} 241}
241 242
243rxvt_img *
244rxvt_img::scale (int new_width, int new_height)
245{
246 double matrix[9] = {
247 new_width / (double)w, 0, 0,
248 0, new_height / (double)h, 0,
249 0, 0, 1
250 };
251
252 return transform (new_width, new_height, RepeatNormal, matrix);
253}
254
255rxvt_img *
256rxvt_img::convert_to (XRenderPictFormat *new_format)
257{
258 rxvt_img *img = new rxvt_img (s, new_format, w, h);
259
260 Display *dpy = s->display->dpy;
261 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
262 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
263
264 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, w, h);
265
266 XRenderFreePicture (dpy, src);
267 XRenderFreePicture (dpy, dst);
268
269 return img;
270}
271
242#endif 272#endif
243 273

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines