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.208 by sf-exg, Fri May 11 08:16:58 2012 UTC vs.
Revision 1.209 by sf-exg, Fri May 11 12:21:22 2012 UTC

3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> 6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> 8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
1182} 1182}
1183 1183
1184void 1184void
1185rxvt_term::tint_ximage (Visual *visual, XImage *ximage) 1185rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1186{ 1186{
1187 unsigned int size_r, size_g, size_b;
1187 int sh_r, sh_g, sh_b; 1188 int sh_r, sh_g, sh_b;
1188 uint32_t mask_r, mask_g, mask_b; 1189 uint32_t mask_r, mask_g, mask_b;
1189 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1190 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1190 unsigned short low; 1191 unsigned short low;
1191 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1192 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1196 mask_r = visual->red_mask; 1197 mask_r = visual->red_mask;
1197 mask_g = visual->green_mask; 1198 mask_g = visual->green_mask;
1198 mask_b = visual->blue_mask; 1199 mask_b = visual->blue_mask;
1199 1200
1200 /* boring lookup table pre-initialization */ 1201 /* boring lookup table pre-initialization */
1201 switch (ximage->depth) 1202 sh_r = ecb_ctz32 (mask_r);
1202 { 1203 sh_g = ecb_ctz32 (mask_g);
1203 case 15: 1204 sh_b = ecb_ctz32 (mask_b);
1204 if ((mask_r != 0x7c00) || 1205
1205 (mask_g != 0x03e0) || 1206 size_r = mask_r >> sh_r;
1206 (mask_b != 0x001f)) 1207 size_g = mask_g >> sh_g;
1208 size_b = mask_b >> sh_b;
1209
1210 if (size_r++ > 255 || size_g++ > 255 || size_b++ > 255)
1207 return; 1211 return;
1208 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); 1212
1213 lookup = (uint32_t *)malloc (sizeof (uint32_t) * (size_r + size_g + size_b));
1209 lookup_r = lookup; 1214 lookup_r = lookup;
1210 lookup_g = lookup+32; 1215 lookup_g = lookup + size_r;
1211 lookup_b = lookup+32+32; 1216 lookup_b = lookup + size_r + size_g;
1212 sh_r = 10;
1213 sh_g = 5;
1214 sh_b = 0;
1215 break;
1216 case 16:
1217 if ((mask_r != 0xf800) ||
1218 (mask_g != 0x07e0) ||
1219 (mask_b != 0x001f))
1220 return;
1221 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1222 lookup_r = lookup;
1223 lookup_g = lookup+32;
1224 lookup_b = lookup+32+64;
1225 sh_r = 11;
1226 sh_g = 5;
1227 sh_b = 0;
1228 break;
1229 case 24:
1230 if ((mask_r != 0xff0000) ||
1231 (mask_g != 0x00ff00) ||
1232 (mask_b != 0x0000ff))
1233 return;
1234 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1235 lookup_r = lookup;
1236 lookup_g = lookup+256;
1237 lookup_b = lookup+256+256;
1238 sh_r = 16;
1239 sh_g = 8;
1240 sh_b = 0;
1241 break;
1242 case 32:
1243 if ((mask_r != 0xff0000) ||
1244 (mask_g != 0x00ff00) ||
1245 (mask_b != 0x0000ff))
1246 return;
1247 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1248 lookup_r = lookup;
1249 lookup_g = lookup+256;
1250 lookup_b = lookup+256+256;
1251 sh_r = 16;
1252 sh_g = 8;
1253 sh_b = 0;
1254 break;
1255 default:
1256 return; /* we do not support this color depth */
1257 }
1258 1217
1259 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1218 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1260 1219
1261 if (bg_flags & BG_TINT_SET) 1220 if (bg_flags & BG_TINT_SET)
1262 tint.get (c); 1221 tint.get (c);
1284 fill_lut (lookup_g, mask_g, sh_g, low, c.g); 1243 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1285 fill_lut (lookup_b, mask_b, sh_b, low, c.b); 1244 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1286 1245
1287 /* apply table to input image (replacing colors by newly calculated ones) */ 1246 /* apply table to input image (replacing colors by newly calculated ones) */
1288 if (ximage->bits_per_pixel == 32 1247 if (ximage->bits_per_pixel == 32
1289 && (ximage->depth == 24 || ximage->depth == 32)
1290 && ximage->byte_order == host_byte_order) 1248 && ximage->byte_order == host_byte_order)
1291 { 1249 {
1292 char *line = ximage->data; 1250 char *line = ximage->data;
1293 1251
1294 for (int y = 0; y < ximage->height; y++) 1252 for (int y = 0; y < ximage->height; y++)
1295 { 1253 {
1296 uint32_t *p = (uint32_t *)line; 1254 uint32_t *p = (uint32_t *)line;
1297 for (int x = 0; x < ximage->width; x++) 1255 for (int x = 0; x < ximage->width; x++)
1298 { 1256 {
1299 *p = lookup_r[(*p & 0xff0000) >> 16] | 1257 *p = lookup_r[(*p & mask_r) >> sh_r] |
1300 lookup_g[(*p & 0x00ff00) >> 8] | 1258 lookup_g[(*p & mask_g) >> sh_g] |
1301 lookup_b[(*p & 0x0000ff)] | 1259 lookup_b[(*p & mask_b) >> sh_b];
1302 (*p & 0xff000000);
1303 p++; 1260 p++;
1304 } 1261 }
1305 line += ximage->bytes_per_line; 1262 line += ximage->bytes_per_line;
1306 } 1263 }
1307 } 1264 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines