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.174 by sf-exg, Wed Nov 23 16:53:53 2011 UTC vs.
Revision 1.187 by sf-exg, Wed Dec 28 13:13:33 2011 UTC

181{ 181{
182 bool changed = false; 182 bool changed = false;
183 int geom_flags = 0; 183 int geom_flags = 0;
184 int x = 0, y = 0; 184 int x = 0, y = 0;
185 unsigned int w = 0, h = 0; 185 unsigned int w = 0, h = 0;
186 unsigned long new_flags = bg_flags & ~BG_GEOMETRY_FLAGS; 186 unsigned long new_flags = 0;
187 187
188 if (geom == NULL) 188 if (geom == NULL)
189 return false; 189 return false;
190 190
191 if (geom[0]) 191 if (geom[0])
201 x = y = 0; 201 x = y = 0;
202 geom_flags = WidthValue|HeightValue|XValue|YValue; 202 geom_flags = WidthValue|HeightValue|XValue|YValue;
203 } 203 }
204 else if (!strcasecmp (arr[i], "style=aspect-stretched")) 204 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
205 { 205 {
206 new_flags = BG_PROP_SCALE; 206 new_flags = BG_KEEP_ASPECT;
207 w = h = windowScale; 207 w = h = windowScale;
208 x = y = centerAlign; 208 x = y = centerAlign;
209 geom_flags = WidthValue|HeightValue|XValue|YValue; 209 geom_flags = WidthValue|HeightValue|XValue|YValue;
210 } 210 }
211 else if (!strcasecmp (arr[i], "style=stretched")) 211 else if (!strcasecmp (arr[i], "style=stretched"))
227 w = h = noScale; 227 w = h = noScale;
228 geom_flags = WidthValue|HeightValue; 228 geom_flags = WidthValue|HeightValue;
229 } 229 }
230 else if (!strcasecmp (arr[i], "op=tile")) 230 else if (!strcasecmp (arr[i], "op=tile"))
231 new_flags |= BG_TILE; 231 new_flags |= BG_TILE;
232 else if (!strcasecmp (arr[i], "op=pscale")) 232 else if (!strcasecmp (arr[i], "op=keep-aspect"))
233 new_flags |= BG_PROP_SCALE; 233 new_flags |= BG_KEEP_ASPECT;
234 else if (!strcasecmp (arr[i], "op=root")) 234 else if (!strcasecmp (arr[i], "op=root-align"))
235 new_flags |= BG_ROOT_ALIGN; 235 new_flags |= BG_ROOT_ALIGN;
236 236
237 // deprecated 237 // deprecated
238 else if (!strcasecmp (arr[i], "tile")) 238 else if (!strcasecmp (arr[i], "tile"))
239 { 239 {
241 w = h = noScale; 241 w = h = noScale;
242 geom_flags |= WidthValue|HeightValue; 242 geom_flags |= WidthValue|HeightValue;
243 } 243 }
244 else if (!strcasecmp (arr[i], "propscale")) 244 else if (!strcasecmp (arr[i], "propscale"))
245 { 245 {
246 new_flags |= BG_PROP_SCALE; 246 new_flags |= BG_KEEP_ASPECT;
247 w = h = windowScale;
248 geom_flags |= WidthValue|HeightValue;
247 } 249 }
248 else if (!strcasecmp (arr[i], "hscale")) 250 else if (!strcasecmp (arr[i], "hscale"))
249 { 251 {
250 new_flags |= BG_TILE; 252 new_flags |= BG_TILE;
251 w = windowScale; 253 w = windowScale;
281 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); 283 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
282 } /* done parsing ops */ 284 } /* done parsing ops */
283 285
284 rxvt_free_strsplit (arr); 286 rxvt_free_strsplit (arr);
285 } 287 }
288
289 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
286 290
287 if (!update) 291 if (!update)
288 { 292 {
289 if (!(geom_flags & XValue)) 293 if (!(geom_flags & XValue))
290 x = y = defaultAlign; 294 x = y = defaultAlign;
299 w = h; 303 w = h;
300 304
301 geom_flags |= WidthValue|HeightValue|XValue|YValue; 305 geom_flags |= WidthValue|HeightValue|XValue|YValue;
302 } 306 }
303 307
304 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w) 308 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
305 || check_set_scale_value (geom_flags, HeightValue, v_scale, h) 309 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
306 || check_set_align_value (geom_flags, XValue, h_align, x) 310 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
307 || check_set_align_value (geom_flags, YValue, v_align, y)) 311 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
308 changed = true;
309 312
310 if (new_flags != bg_flags) 313 if (new_flags != bg_flags)
311 { 314 {
312 bg_flags = new_flags; 315 bg_flags = new_flags;
313 changed = true; 316 changed = true;
323 int target_height = szHint.height; 326 int target_height = szHint.height;
324 327
325 w = h_scale * target_width / 100; 328 w = h_scale * target_width / 100;
326 h = v_scale * target_height / 100; 329 h = v_scale * target_height / 100;
327 330
328 if (bg_flags & BG_PROP_SCALE) 331 if (bg_flags & BG_KEEP_ASPECT)
329 { 332 {
330 float scale = (float)w / image_width; 333 float scale = (float)w / image_width;
331 min_it (scale, (float)h / image_height); 334 min_it (scale, (float)h / image_height);
332 w = image_width * scale + 0.5; 335 w = image_width * scale + 0.5;
333 h = image_height * scale + 0.5; 336 h = image_height * scale + 0.5;
371 if (tr_flags & BG_NEEDS_TINT) 374 if (tr_flags & BG_NEEDS_TINT)
372 { 375 {
373 ShadingInfo as_shade; 376 ShadingInfo as_shade;
374 as_shade.shading = shade; 377 as_shade.shading = shade;
375 378
376 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 379 rgba c;
377 if (bg_flags & BG_TINT_SET)
378 tint.get (c); 380 tint.get (c);
379 as_shade.tintColor.red = c.r; 381 as_shade.tintColor.red = c.r;
380 as_shade.tintColor.green = c.g; 382 as_shade.tintColor.green = c.g;
381 as_shade.tintColor.blue = c.b; 383 as_shade.tintColor.blue = c.b;
382 384
383 background_tint = shading2tint32 (&as_shade); 385 background_tint = shading2tint32 (&as_shade);
952} 954}
953 955
954void 956void
955rxvt_term::set_tint_shade_flags () 957rxvt_term::set_tint_shade_flags ()
956{ 958{
957 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 959 rgba c;
958 bool has_shade = shade != 100; 960 bool has_shade = shade != 100;
959 961
960 bg_flags &= ~BG_TINT_FLAGS; 962 bg_flags &= ~BG_TINT_FLAGS;
961 963
962 if (bg_flags & BG_TINT_SET)
963 {
964 tint.get (c); 964 tint.get (c);
965
965 if (!has_shade 966 if (!has_shade
966 && (c.r <= 0x00ff || c.r >= 0xff00) 967 && (c.r <= 0x00ff || c.r >= 0xff00)
967 && (c.g <= 0x00ff || c.g >= 0xff00) 968 && (c.g <= 0x00ff || c.g >= 0xff00)
968 && (c.b <= 0x00ff || c.b >= 0xff00)) 969 && (c.b <= 0x00ff || c.b >= 0xff00))
969 bg_flags |= BG_TINT_BITAND; 970 bg_flags |= BG_TINT_BITAND;
970 }
971 971
972 if (has_shade || (bg_flags & BG_TINT_SET)) 972 if (has_shade
973 || c.r < 0xff00
974 || c.g < 0xff00
975 || c.b < 0xff00)
973 bg_flags |= BG_NEEDS_TINT; 976 bg_flags |= BG_NEEDS_TINT;
974} 977}
975 978
976bool 979bool
977rxvt_term::bg_set_tint (rxvt_color &new_tint) 980rxvt_term::bg_set_tint (rxvt_color &new_tint)
978{ 981{
979 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 982 if (tint != new_tint)
980 { 983 {
981 tint = new_tint; 984 tint = new_tint;
982 bg_flags |= BG_TINT_SET;
983 set_tint_shade_flags (); 985 set_tint_shade_flags ();
984 return true; 986 return true;
985 } 987 }
986 988
987 return false; 989 return false;
988} 990}
989 991
990bool 992bool
991rxvt_term::bg_set_shade (const char *shade_str) 993rxvt_term::bg_set_shade (const char *shade_str)
992{ 994{
993 int new_shade = (shade_str) ? atoi (shade_str) : 100; 995 int new_shade = atoi (shade_str);
994 996
995 clamp_it (new_shade, -100, 200); 997 clamp_it (new_shade, -100, 200);
996 if (new_shade < 0) 998 if (new_shade < 0)
997 new_shade = 200 - (100 + new_shade); 999 new_shade = 200 - (100 + new_shade);
998 1000
1032bool 1034bool
1033rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1035rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1034{ 1036{
1035 bool ret = false; 1037 bool ret = false;
1036#if XRENDER 1038#if XRENDER
1039 if (!(bg_flags & BG_HAS_RENDER_CONV))
1040 return false;
1041
1037 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1042 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1038 double *kernel = (double *)malloc (size * sizeof (double)); 1043 double *kernel = (double *)malloc (size * sizeof (double));
1039 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1044 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1040 1045
1041 XRenderPictureAttributes pa; 1046 XRenderPictureAttributes pa;
1114 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1119 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1115 ret = true; 1120 ret = true;
1116 XFreeGC (dpy, gc); 1121 XFreeGC (dpy, gc);
1117 } 1122 }
1118 } 1123 }
1119 else
1120 {
1121# if XRENDER 1124# if XRENDER
1122 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1125 else if (bg_flags & BG_HAS_RENDER)
1126 {
1127 rgba c;
1123 1128
1124 if (bg_flags & BG_TINT_SET)
1125 tint.get (c); 1129 tint.get (c);
1126 1130
1127 if (shade <= 100) 1131 if (shade <= 100)
1128 { 1132 {
1129 c.r = c.r * shade / 100; 1133 c.r = c.r * shade / 100;
1130 c.g = c.g * shade / 100; 1134 c.g = c.g * shade / 100;
1181 ret = true; 1185 ret = true;
1182 1186
1183 XRenderFreePicture (dpy, mask_pic); 1187 XRenderFreePicture (dpy, mask_pic);
1184 XRenderFreePicture (dpy, overlay_pic); 1188 XRenderFreePicture (dpy, overlay_pic);
1185 XRenderFreePicture (dpy, back_pic); 1189 XRenderFreePicture (dpy, back_pic);
1190 }
1186# endif 1191# endif
1187 }
1188 1192
1189 return ret; 1193 return ret;
1190} 1194}
1191 1195
1192/* 1196/*
1276 bg_pmap_width = window_width; 1280 bg_pmap_width = window_width;
1277 bg_pmap_height = window_height; 1281 bg_pmap_height = window_height;
1278 } 1282 }
1279 1283
1280 /* straightforward pixmap copy */ 1284 /* straightforward pixmap copy */
1281 while (sx < 0) sx += root_width; 1285 while (sx < 0) sx += root_pmap_width;
1282 while (sy < 0) sy += root_height; 1286 while (sy < 0) sy += root_pmap_height;
1283 1287
1284 gcv.tile = recoded_root_pmap; 1288 gcv.tile = recoded_root_pmap;
1285 gcv.fill_style = FillTiled; 1289 gcv.fill_style = FillTiled;
1286 gcv.ts_x_origin = -sx; 1290 gcv.ts_x_origin = -sx;
1287 gcv.ts_y_origin = -sy; 1291 gcv.ts_y_origin = -sy;
1293 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1297 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1294 XFreeGC (dpy, gc); 1298 XFreeGC (dpy, gc);
1295 1299
1296 if (!(bg_flags & BG_CLIENT_RENDER)) 1300 if (!(bg_flags & BG_CLIENT_RENDER))
1297 { 1301 {
1298 if ((bg_flags & BG_NEEDS_BLUR) 1302 if (bg_flags & BG_NEEDS_BLUR)
1299 && (bg_flags & BG_HAS_RENDER_CONV))
1300 { 1303 {
1301 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1304 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1302 result &= ~BG_NEEDS_BLUR; 1305 result &= ~BG_NEEDS_BLUR;
1303 } 1306 }
1304 if ((bg_flags & BG_NEEDS_TINT) 1307 if (bg_flags & BG_NEEDS_TINT)
1305 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1306 { 1308 {
1307 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1309 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1308 result &= ~BG_NEEDS_TINT; 1310 result &= ~BG_NEEDS_TINT;
1309 } 1311 }
1310 } /* server side rendering completed */ 1312 } /* server side rendering completed */
1324 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1326 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1325 1327
1326 root_pixmap = new_root_pixmap; 1328 root_pixmap = new_root_pixmap;
1327} 1329}
1328# endif /* ENABLE_TRANSPARENCY */ 1330# endif /* ENABLE_TRANSPARENCY */
1329
1330#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1331static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1332# endif
1333 1331
1334bool 1332bool
1335rxvt_term::bg_render () 1333rxvt_term::bg_render ()
1336{ 1334{
1337 unsigned long tr_flags = 0; 1335 unsigned long tr_flags = 0;
1368 if (result) 1366 if (result)
1369 { 1367 {
1370 /* our own client-side tinting */ 1368 /* our own client-side tinting */
1371 //if (tr_flags & BG_NEEDS_TINT) 1369 //if (tr_flags & BG_NEEDS_TINT)
1372 if (1) 1370 if (1)
1373 {
1374 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1375 if (bg_flags & BG_TINT_SET)
1376 tint.get (c);
1377 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); 1371 tint_ximage (DefaultVisual (dpy, display->screen), result);
1378 }
1379 1372
1380 GC gc = XCreateGC (dpy, vt, 0UL, NULL); 1373 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1381 1374
1382 if (gc) 1375 if (gc)
1383 { 1376 {
1409 1402
1410void 1403void
1411rxvt_term::bg_init () 1404rxvt_term::bg_init ()
1412{ 1405{
1413#ifdef ENABLE_TRANSPARENCY 1406#ifdef ENABLE_TRANSPARENCY
1407 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1408 tint.set (this, c);
1414 shade = 100; 1409 shade = 100;
1415#endif 1410#endif
1416 1411
1417 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1412 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1418#if XRENDER 1413#if XRENDER
1434#endif /* HAVE_BG_PIXMAP */ 1429#endif /* HAVE_BG_PIXMAP */
1435 1430
1436#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1431#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1437/* based on code from aterm-0.4.2 */ 1432/* based on code from aterm-0.4.2 */
1438 1433
1439static void 1434static inline void
1440shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1435fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1436{
1437 for (int i = 0; i <= mask >> sh; i++)
1438 {
1439 uint32_t tmp;
1440 tmp = i * high;
1441 tmp += (mask >> sh) * low;
1442 lookup[i] = (tmp / 0xffff) << sh;
1443 }
1444}
1445
1446void
1447rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1441{ 1448{
1442 int sh_r, sh_g, sh_b; 1449 int sh_r, sh_g, sh_b;
1443 uint32_t mask_r, mask_g, mask_b; 1450 uint32_t mask_r, mask_g, mask_b;
1444 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1451 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1445 rgba low; 1452 unsigned short low;
1446 rgba high;
1447 int i;
1448 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1453 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1449 1454
1450 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1455 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1451 1456
1452 /* for convenience */ 1457 /* for convenience */
1511 break; 1516 break;
1512 default: 1517 default:
1513 return; /* we do not support this color depth */ 1518 return; /* we do not support this color depth */
1514 } 1519 }
1515 1520
1521 rgba c;
1522
1523 tint.get (c);
1524
1516 /* prepare limits for color transformation (each channel is handled separately) */ 1525 /* prepare limits for color transformation (each channel is handled separately) */
1517 if (shade > 100) 1526 if (shade > 100)
1518 { 1527 {
1519 shade = 200 - shade;
1520
1521 high.r = c.r * shade / 100;
1522 high.g = c.g * shade / 100;
1523 high.b = c.b * shade / 100;
1524
1525 low.r = 65535 * (100 - shade) / 100; 1528 c.r = c.r * (200 - shade) / 100;
1526 low.g = 65535 * (100 - shade) / 100; 1529 c.g = c.g * (200 - shade) / 100;
1527 low.b = 65535 * (100 - shade) / 100; 1530 c.b = c.b * (200 - shade) / 100;
1531
1532 low = 0xffff * (shade - 100) / 100;
1528 } 1533 }
1529 else 1534 else
1530 { 1535 {
1531 high.r = c.r * shade / 100; 1536 c.r = c.r * shade / 100;
1532 high.g = c.g * shade / 100; 1537 c.g = c.g * shade / 100;
1533 high.b = c.b * shade / 100; 1538 c.b = c.b * shade / 100;
1534 1539
1535 low.r = low.g = low.b = 0; 1540 low = 0;
1536 } 1541 }
1537 1542
1538 /* fill our lookup tables */ 1543 /* fill our lookup tables */
1539 for (i = 0; i <= mask_r>>sh_r; i++) 1544 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1540 { 1545 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1541 uint32_t tmp; 1546 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1542 tmp = i * high.r;
1543 tmp += (mask_r>>sh_r) * low.r;
1544 lookup_r[i] = (tmp/65535)<<sh_r;
1545 }
1546 for (i = 0; i <= mask_g>>sh_g; i++)
1547 {
1548 uint32_t tmp;
1549 tmp = i * high.g;
1550 tmp += (mask_g>>sh_g) * low.g;
1551 lookup_g[i] = (tmp/65535)<<sh_g;
1552 }
1553 for (i = 0; i <= mask_b>>sh_b; i++)
1554 {
1555 uint32_t tmp;
1556 tmp = i * high.b;
1557 tmp += (mask_b>>sh_b) * low.b;
1558 lookup_b[i] = (tmp/65535)<<sh_b;
1559 }
1560 1547
1561 /* apply table to input image (replacing colors by newly calculated ones) */ 1548 /* apply table to input image (replacing colors by newly calculated ones) */
1562 if (ximage->bits_per_pixel == 32 1549 if (ximage->bits_per_pixel == 32
1563 && (ximage->depth == 24 || ximage->depth == 32) 1550 && (ximage->depth == 24 || ximage->depth == 32)
1564 && ximage->byte_order == host_byte_order) 1551 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines