--- rxvt-unicode/src/background.C 2011/08/13 09:05:44 1.163 +++ rxvt-unicode/src/background.C 2011/12/24 09:44:23 1.180 @@ -34,22 +34,6 @@ #define FilterConvolution "convolution" #endif -/* - * Pixmap geometry string interpretation : - * Each geometry string contains zero or one scale/position - * adjustment and may optionally be followed by a colon and one or more - * colon-delimited pixmap operations. - * The following table shows the valid geometry strings and their - * effects on the background image : - * - * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. - * W and H are percentages of the terminal window size. - * X and Y are also percentages; e.g., +50+50 centers - * the image in the window. - * - * Pixmap Operations : (should be prepended by a colon) - */ - #ifdef HAVE_BG_PIXMAP void rxvt_term::bg_destroy () @@ -168,9 +152,9 @@ if (align >= 0 && align <= 100) return diff * align / 100; else if (align > 100 && align <= 200) - return ((align - 100) * smaller / 100) + window_size - smaller; + return (align - 100) * smaller / 100 + window_size - smaller; else if (align >= -100 && align < 0) - return ((align + 100) * smaller / 100) - image_size; + return (align + 100) * smaller / 100 - image_size; return 0; } @@ -199,7 +183,7 @@ int geom_flags = 0; int x = 0, y = 0; unsigned int w = 0, h = 0; - unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); + unsigned long new_flags = bg_flags & ~BG_GEOMETRY_FLAGS; if (geom == NULL) return false; @@ -208,7 +192,7 @@ { char **arr = rxvt_strsplit (':', geom); - for (int i = 0; arr[i]; i++) + for (int i = 0; arr[i]; i++) { if (!strcasecmp (arr[i], "style=tiled")) { @@ -219,9 +203,10 @@ } else if (!strcasecmp (arr[i], "style=aspect-stretched")) { - new_flags = BG_PROP_SCALE; + new_flags = BG_KEEP_ASPECT; + w = h = windowScale; x = y = centerAlign; - geom_flags = XValue|YValue; + geom_flags = WidthValue|HeightValue|XValue|YValue; } else if (!strcasecmp (arr[i], "style=stretched")) { @@ -244,9 +229,9 @@ } else if (!strcasecmp (arr[i], "op=tile")) new_flags |= BG_TILE; - else if (!strcasecmp (arr[i], "op=pscale")) - new_flags |= BG_PROP_SCALE; - else if (!strcasecmp (arr[i], "op=root")) + else if (!strcasecmp (arr[i], "op=keep-aspect")) + new_flags |= BG_KEEP_ASPECT; + else if (!strcasecmp (arr[i], "op=root-align")) new_flags |= BG_ROOT_ALIGN; // deprecated @@ -258,7 +243,9 @@ } else if (!strcasecmp (arr[i], "propscale")) { - new_flags |= BG_PROP_SCALE; + new_flags |= BG_KEEP_ASPECT; + w = h = windowScale; + geom_flags |= WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "hscale")) { @@ -336,18 +323,16 @@ int target_width = szHint.width; int target_height = szHint.height; - if (bg_flags & BG_PROP_SCALE) + w = h_scale * target_width / 100; + h = v_scale * target_height / 100; + + if (bg_flags & BG_KEEP_ASPECT) { - float scale = (float)target_width / image_width; - min_it (scale, (float)target_height / image_height); + float scale = (float)w / image_width; + min_it (scale, (float)h / image_height); w = image_width * scale + 0.5; h = image_height * scale + 0.5; } - else - { - w = h_scale * target_width / 100; - h = v_scale * target_height / 100; - } if (!w) w = image_width; if (!h) h = image_height; @@ -365,7 +350,7 @@ bg_flags &= ~BG_IS_SIZE_SENSITIVE; if (!(bg_flags & BG_TILE) - || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale + || h_scale || v_scale || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) || w > target_width || h > target_height) bg_flags |= BG_IS_SIZE_SENSITIVE; @@ -402,7 +387,7 @@ if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) { ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, - (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, + ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) { @@ -431,8 +416,8 @@ || (!(bg_flags & BG_ROOT_ALIGN) && (x >= target_width || y >= target_height - || (x + w <= 0) - || (y + h <= 0)))) + || x + w <= 0 + || y + h <= 0))) { if (background) { @@ -456,12 +441,12 @@ { result = original_asim; - if ((w != original_asim->width) - || (h != original_asim->height)) + if (w != original_asim->width + || h != original_asim->height) { result = scale_asimage (asv, original_asim, w, h, - background ? ASA_ASImage : ASA_XImage, + ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); } @@ -721,14 +706,14 @@ if (!(bg_flags & BG_ROOT_ALIGN) && (x >= target_width || y >= target_height - || (x + w <= 0) - || (y + h <= 0))) + || x + w <= 0 + || y + h <= 0)) return false; result = pixbuf; - if ((w != image_width) - || (h != image_height)) + if (w != image_width + || h != image_height) { result = gdk_pixbuf_scale_simple (pixbuf, w, h, @@ -867,7 +852,10 @@ if (!file || !*file) return false; - if (const char *p = strchr (file, ';')) + bool ret = false; + const char *p = strchr (file, ';'); + + if (p) { size_t len = p - file; char *f = rxvt_temp_buf (len + 1); @@ -886,7 +874,7 @@ safe_asimage_destroy (original_asim); original_asim = image; bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; - return true; + ret = true; } # endif @@ -898,11 +886,19 @@ g_object_unref (pixbuf); pixbuf = image; bg_flags |= BG_IS_FROM_FILE; - return true; + ret = true; } # endif - return false; + if (ret) + { + if (p) + bg_set_geometry (p + 1); + else + bg_set_default_geometry (); + } + + return ret; } # endif /* BG_IMAGE_FROM_FILE */ @@ -1283,8 +1279,8 @@ } /* straightforward pixmap copy */ - while (sx < 0) sx += root_width; - while (sy < 0) sy += root_height; + while (sx < 0) sx += root_pmap_width; + while (sy < 0) sy += root_pmap_height; gcv.tile = recoded_root_pmap; gcv.fill_style = FillTiled; @@ -1349,8 +1345,7 @@ tr_flags = make_transparency_pixmap (); if (tr_flags == 0) return false; - else if (!(tr_flags & BG_EFFECTS_FLAGS)) - bg_flags |= BG_IS_VALID; + bg_flags |= BG_IS_VALID; } # endif @@ -1366,7 +1361,7 @@ # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) XImage *result = NULL; - if (tr_flags && !(bg_flags & BG_IS_VALID)) + if (tr_flags & BG_NEEDS_TINT) { result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); } @@ -1374,7 +1369,8 @@ if (result) { /* our own client-side tinting */ - if (tr_flags & BG_NEEDS_TINT) + //if (tr_flags & BG_NEEDS_TINT) + if (1) { rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); if (bg_flags & BG_TINT_SET) @@ -1389,7 +1385,6 @@ XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); XFreeGC (dpy, gc); - bg_flags |= BG_IS_VALID; } XDestroyImage (result); @@ -1440,7 +1435,19 @@ #endif /* HAVE_BG_PIXMAP */ #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) -/* taken from aterm-0.4.2 */ +/* based on code from aterm-0.4.2 */ + +static inline void +fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) +{ + for (int i = 0; i <= mask >> sh; i++) + { + uint32_t tmp; + tmp = i * high; + tmp += (mask >> sh) * low; + lookup[i] = (tmp / 0xffff) << sh; + } +} static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) @@ -1448,9 +1455,8 @@ int sh_r, sh_g, sh_b; uint32_t mask_r, mask_g, mask_b; uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; - rgba low; + unsigned short low; rgba high; - int i; int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; @@ -1528,9 +1534,7 @@ high.g = c.g * shade / 100; high.b = c.b * shade / 100; - low.r = 65535 * (100 - shade) / 100; - low.g = 65535 * (100 - shade) / 100; - low.b = 65535 * (100 - shade) / 100; + low = 0xffff * (100 - shade) / 100; } else { @@ -1538,31 +1542,13 @@ high.g = c.g * shade / 100; high.b = c.b * shade / 100; - low.r = low.g = low.b = 0; + low = 0; } /* fill our lookup tables */ - for (i = 0; i <= mask_r>>sh_r; i++) - { - uint32_t tmp; - tmp = i * high.r; - tmp += (mask_r>>sh_r) * low.r; - lookup_r[i] = (tmp/65535)<>sh_g; i++) - { - uint32_t tmp; - tmp = i * high.g; - tmp += (mask_g>>sh_g) * low.g; - lookup_g[i] = (tmp/65535)<>sh_b; i++) - { - uint32_t tmp; - tmp = i * high.b; - tmp += (mask_b>>sh_b) * low.b; - lookup_b[i] = (tmp/65535)<bits_per_pixel == 32