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

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.204 by sf-exg, Tue Apr 10 15:19:22 2012 UTC vs.
Revision 1.207 by sf-exg, Thu May 10 21:48:55 2012 UTC

123 123
124# ifdef BG_IMAGE_FROM_FILE 124# ifdef BG_IMAGE_FROM_FILE
125static inline int 125static inline int
126make_align_position (int align, int window_size, int image_size) 126make_align_position (int align, int window_size, int image_size)
127{ 127{
128 int diff = window_size - image_size;
129 int smaller = min (image_size, window_size);
130
131 if (align >= 0 && align <= 100) 128 if (align >= 0 && align <= 100)
132 return diff * align / 100; 129 return lerp (0, window_size - image_size, align);
133 else if (align > 100 && align <= 200) 130 else if (align > 100)
134 return (align - 100) * smaller / 100 + window_size - smaller; 131 return lerp (window_size - image_size, window_size, align - 100);
135 else if (align >= -100 && align < 0) 132 else
136 return (align + 100) * smaller / 100 - image_size; 133 return lerp (-image_size, 0, align + 100);
137 return 0;
138} 134}
139 135
140static inline int 136static inline int
141make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 137make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
142{ 138{
352 unsigned int width, unsigned int height) 348 unsigned int width, unsigned int height)
353{ 349{
354 XImage *ximage; 350 XImage *ximage;
355 char *data, *line; 351 char *data, *line;
356 int bytes_per_pixel; 352 int bytes_per_pixel;
357 int width_r, width_g, width_b; 353 int width_r, width_g, width_b, width_a;
358 int sh_r, sh_g, sh_b; 354 int sh_r, sh_g, sh_b, sh_a;
355 uint32_t alpha_mask;
359 int rowstride; 356 int rowstride;
360 int channels; 357 int channels;
361 unsigned char *row; 358 unsigned char *row;
362 359
363 if (visual->c_class != TrueColor) 360 if (visual->c_class != TrueColor)
364 return false; 361 return false;
362
363#if XRENDER
364 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
365 if (format)
366 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
367 else
368#endif
369 alpha_mask = 0;
365 370
366 if (depth == 24 || depth == 32) 371 if (depth == 24 || depth == 32)
367 bytes_per_pixel = 4; 372 bytes_per_pixel = 4;
368 else if (depth == 15 || depth == 16) 373 else if (depth == 15 || depth == 16)
369 bytes_per_pixel = 2; 374 bytes_per_pixel = 2;
371 return false; 376 return false;
372 377
373 width_r = ecb_popcount32 (visual->red_mask); 378 width_r = ecb_popcount32 (visual->red_mask);
374 width_g = ecb_popcount32 (visual->green_mask); 379 width_g = ecb_popcount32 (visual->green_mask);
375 width_b = ecb_popcount32 (visual->blue_mask); 380 width_b = ecb_popcount32 (visual->blue_mask);
381 width_a = ecb_popcount32 (alpha_mask);
376 382
377 if (width_r > 8 || width_g > 8 || width_b > 8) 383 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
378 return false; 384 return false;
379 385
380 sh_r = ecb_ctz32 (visual->red_mask); 386 sh_r = ecb_ctz32 (visual->red_mask);
381 sh_g = ecb_ctz32 (visual->green_mask); 387 sh_g = ecb_ctz32 (visual->green_mask);
382 sh_b = ecb_ctz32 (visual->blue_mask); 388 sh_b = ecb_ctz32 (visual->blue_mask);
389 sh_a = ecb_ctz32 (alpha_mask);
383 390
384 if (width > INT_MAX / height / bytes_per_pixel) 391 if (width > INT_MAX / height / bytes_per_pixel)
385 return false; 392 return false;
386 393
387 data = (char *)malloc (width * height * bytes_per_pixel); 394 data = (char *)malloc (width * height * bytes_per_pixel);
401 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 408 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
402 channels = gdk_pixbuf_get_n_channels (pixbuf); 409 channels = gdk_pixbuf_get_n_channels (pixbuf);
403 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 410 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
404 line = data; 411 line = data;
405 412
413 rgba c (0, 0, 0);
414
415 if (channels == 4 && alpha_mask == 0)
416 {
417 pix_colors[Color_bg].get (c);
418 c.r >>= 8;
419 c.g >>= 8;
420 c.b >>= 8;
421 }
422
406 for (int y = 0; y < height; y++) 423 for (int y = 0; y < height; y++)
407 { 424 {
408 for (int x = 0; x < width; x++) 425 for (int x = 0; x < width; x++)
409 { 426 {
410 unsigned char *pixel = row + x * channels; 427 unsigned char *pixel = row + x * channels;
411 uint32_t value; 428 uint32_t value;
429 unsigned char r, g, b, a;
412 430
431 if (channels == 4)
432 {
433 a = pixel[3];
434 r = (pixel[0] * a + c.r * (0xff - a)) / 0xff;
435 g = (pixel[1] * a + c.g * (0xff - a)) / 0xff;
436 b = (pixel[2] * a + c.b * (0xff - a)) / 0xff;
437 }
438 else
439 {
440 a = 0xff;
441 r = pixel[0];
442 g = pixel[1];
443 b = pixel[2];
444 }
445
413 value = ((pixel[0] >> (8 - width_r)) << sh_r) 446 value = ((r >> (8 - width_r)) << sh_r)
414 | ((pixel[1] >> (8 - width_g)) << sh_g) 447 | ((g >> (8 - width_g)) << sh_g)
415 | ((pixel[2] >> (8 - width_b)) << sh_b); 448 | ((b >> (8 - width_b)) << sh_b)
449 | ((a >> (8 - width_a)) << sh_a);
416 450
417 if (bytes_per_pixel == 4) 451 if (bytes_per_pixel == 4)
418 ((uint32_t *)line)[x] = value; 452 ((uint32_t *)line)[x] = value;
419 else 453 else
420 ((uint16_t *)line)[x] = value; 454 ((uint16_t *)line)[x] = value;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines