… | |
… | |
428 | { |
428 | { |
429 | flags = new_flags; |
429 | flags = new_flags; |
430 | changed++; |
430 | changed++; |
431 | } |
431 | } |
432 | |
432 | |
433 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
|
|
434 | // flags, h_scale, v_scale, h_align, v_align); |
|
|
435 | return (changed > 0); |
433 | return (changed > 0); |
436 | } |
434 | } |
437 | |
435 | |
438 | void |
436 | void |
439 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
437 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
… | |
… | |
529 | |
527 | |
530 | int x = 0; |
528 | int x = 0; |
531 | int y = 0; |
529 | int y = 0; |
532 | int w = 0; |
530 | int w = 0; |
533 | int h = 0; |
531 | int h = 0; |
534 | |
|
|
535 | TIMING_TEST_START (asim); |
|
|
536 | |
532 | |
537 | if (original_asim) |
533 | if (original_asim) |
538 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
534 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
539 | |
535 | |
540 | if (!original_asim |
536 | if (!original_asim |
… | |
… | |
657 | } |
653 | } |
658 | |
654 | |
659 | free (layers); |
655 | free (layers); |
660 | } |
656 | } |
661 | } |
657 | } |
662 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
663 | |
658 | |
664 | bool ret = false; |
659 | bool ret = false; |
665 | |
660 | |
666 | if (result) |
661 | if (result) |
667 | { |
662 | { |
… | |
… | |
713 | |
708 | |
714 | if (result != background && result != original_asim) |
709 | if (result != background && result != original_asim) |
715 | destroy_asimage (&result); |
710 | destroy_asimage (&result); |
716 | |
711 | |
717 | XFreeGC (target->dpy, gc); |
712 | XFreeGC (target->dpy, gc); |
718 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
719 | |
713 | |
720 | ret = true; |
714 | ret = true; |
721 | } |
715 | } |
722 | |
716 | |
723 | if (background) |
717 | if (background) |
… | |
… | |
735 | return false; |
729 | return false; |
736 | |
730 | |
737 | if (!pixbuf) |
731 | if (!pixbuf) |
738 | return false; |
732 | return false; |
739 | |
733 | |
740 | #if !XFT |
|
|
741 | if (background_flags) |
734 | if (background_flags |
|
|
735 | && !(flags & HAS_RENDER)) |
742 | return false; |
736 | return false; |
743 | #endif |
|
|
744 | |
737 | |
745 | GdkPixbuf *result; |
738 | GdkPixbuf *result; |
746 | |
739 | |
747 | int image_width = gdk_pixbuf_get_width (pixbuf); |
740 | int image_width = gdk_pixbuf_get_width (pixbuf); |
748 | int image_height = gdk_pixbuf_get_height (pixbuf); |
741 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
862 | dst_width, dst_height, |
855 | dst_width, dst_height, |
863 | XLIB_RGB_DITHER_NONE, |
856 | XLIB_RGB_DITHER_NONE, |
864 | 0, 0); |
857 | 0, 0); |
865 | } |
858 | } |
866 | |
859 | |
867 | #if XFT |
860 | #if XRENDER |
868 | if (background_flags) |
861 | if (background_flags) |
869 | { |
862 | { |
870 | Display *dpy = target->dpy; |
863 | Display *dpy = target->dpy; |
871 | XRenderPictureAttributes pa; |
864 | XRenderPictureAttributes pa; |
872 | |
865 | |
873 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
866 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
874 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
867 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
875 | |
868 | |
876 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
869 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
877 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
870 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
878 | |
871 | |
… | |
… | |
915 | # endif /* HAVE_PIXBUF */ |
908 | # endif /* HAVE_PIXBUF */ |
916 | |
909 | |
917 | bool |
910 | bool |
918 | bgPixmap_t::set_file (const char *file) |
911 | bgPixmap_t::set_file (const char *file) |
919 | { |
912 | { |
920 | assert (file); |
913 | if (!file || !*file) |
|
|
914 | return false; |
921 | |
915 | |
922 | if (*file) |
|
|
923 | { |
|
|
924 | if (const char *p = strchr (file, ';')) |
916 | if (const char *p = strchr (file, ';')) |
925 | { |
917 | { |
926 | size_t len = p - file; |
918 | size_t len = p - file; |
927 | char *f = rxvt_temp_buf<char> (len + 1); |
919 | char *f = rxvt_temp_buf<char> (len + 1); |
928 | memcpy (f, file, len); |
920 | memcpy (f, file, len); |
929 | f[len] = '\0'; |
921 | f[len] = '\0'; |
930 | file = f; |
922 | file = f; |
931 | } |
923 | } |
932 | |
924 | |
933 | # ifdef HAVE_AFTERIMAGE |
925 | # ifdef HAVE_AFTERIMAGE |
934 | if (!target->asimman) |
926 | if (!target->asimman) |
935 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
927 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
936 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
928 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
937 | if (image) |
929 | if (image) |
938 | { |
930 | { |
939 | if (original_asim) |
931 | if (original_asim) |
940 | safe_asimage_destroy (original_asim); |
932 | safe_asimage_destroy (original_asim); |
941 | original_asim = image; |
933 | original_asim = image; |
942 | have_image = true; |
934 | have_image = true; |
943 | return true; |
935 | return true; |
944 | } |
936 | } |
945 | # endif |
937 | # endif |
946 | |
938 | |
947 | # ifdef HAVE_PIXBUF |
939 | # ifdef HAVE_PIXBUF |
948 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
940 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
949 | if (image) |
941 | if (image) |
950 | { |
942 | { |
951 | if (pixbuf) |
943 | if (pixbuf) |
952 | g_object_unref (pixbuf); |
944 | g_object_unref (pixbuf); |
953 | pixbuf = image; |
945 | pixbuf = image; |
954 | have_image = true; |
946 | have_image = true; |
955 | return true; |
947 | return true; |
956 | } |
948 | } |
957 | # endif |
949 | # endif |
958 | } |
|
|
959 | |
950 | |
960 | return false; |
951 | return false; |
961 | } |
952 | } |
962 | |
953 | |
963 | # endif /* BG_IMAGE_FROM_FILE */ |
954 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
1005 | |
996 | |
1006 | if (v_blurRadius == 0 && h_blurRadius == 0) |
997 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1007 | flags &= ~blurNeeded; |
998 | flags &= ~blurNeeded; |
1008 | else |
999 | else |
1009 | flags |= blurNeeded; |
1000 | flags |= blurNeeded; |
1010 | |
|
|
1011 | #if XFT |
|
|
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
|
|
1013 | if (filters) |
|
|
1014 | { |
|
|
1015 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1017 | flags |= bgPixmap_t::blurServerSide; |
|
|
1018 | |
|
|
1019 | XFree (filters); |
|
|
1020 | } |
|
|
1021 | #endif |
|
|
1022 | |
1001 | |
1023 | return (changed > 0); |
1002 | return (changed > 0); |
1024 | } |
1003 | } |
1025 | |
1004 | |
1026 | static inline unsigned long |
1005 | static inline unsigned long |
… | |
… | |
1050 | { |
1029 | { |
1051 | flags |= bgPixmap_t::tintNeeded; |
1030 | flags |= bgPixmap_t::tintNeeded; |
1052 | } |
1031 | } |
1053 | } |
1032 | } |
1054 | |
1033 | |
1055 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1056 | { |
|
|
1057 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1058 | flags |= bgPixmap_t::tintServerSide; |
|
|
1059 | else |
|
|
1060 | { |
|
|
1061 | #if XFT |
|
|
1062 | flags |= bgPixmap_t::tintServerSide; |
|
|
1063 | #endif |
|
|
1064 | } |
|
|
1065 | } |
|
|
1066 | |
|
|
1067 | return flags; |
1034 | return flags; |
1068 | } |
1035 | } |
1069 | |
1036 | |
1070 | bool |
1037 | bool |
1071 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1038 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
… | |
… | |
1113 | } |
1080 | } |
1114 | |
1081 | |
1115 | return false; |
1082 | return false; |
1116 | } |
1083 | } |
1117 | |
1084 | |
1118 | #if XFT |
1085 | #if XRENDER |
1119 | static void |
1086 | static void |
1120 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1087 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1121 | { |
1088 | { |
1122 | double sigma = radius / 2.0; |
1089 | double sigma = radius / 2.0; |
1123 | double scale = sqrt (2.0 * M_PI) * sigma; |
1090 | double scale = sqrt (2.0 * M_PI) * sigma; |
1124 | double sum = 0.0; |
1091 | double sum = 0.0; |
1125 | |
1092 | |
1126 | for (int i = 0; i < width; i++) |
1093 | for (int i = 0; i < width; i++) |
1127 | { |
1094 | { |
1128 | double x = i - width / 2; |
1095 | double x = i - width / 2; |
1129 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1096 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1130 | sum += kernel[i]; |
1097 | sum += kernel[i]; |
1131 | } |
1098 | } |
1132 | |
1099 | |
1133 | params[0] = XDoubleToFixed (width); |
1100 | params[0] = XDoubleToFixed (width); |
1134 | params[1] = XDoubleToFixed (1); |
1101 | params[1] = XDoubleToFixed (1); |
1135 | |
1102 | |
1136 | for (int i = 0; i < width; i++) |
1103 | for (int i = 0; i < width; i++) |
1137 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1104 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1138 | } |
1105 | } |
1139 | #endif |
1106 | #endif |
1140 | |
1107 | |
1141 | bool |
1108 | bool |
1142 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1109 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1143 | { |
1110 | { |
1144 | bool ret = false; |
1111 | bool ret = false; |
1145 | #if XFT |
1112 | #if XRENDER |
1146 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1113 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1147 | double *kernel = (double *)malloc (size * sizeof (double)); |
1114 | double *kernel = (double *)malloc (size * sizeof (double)); |
1148 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1115 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1149 | |
1116 | |
1150 | Display *dpy = target->dpy; |
1117 | Display *dpy = target->dpy; |
1151 | XRenderPictureAttributes pa; |
1118 | XRenderPictureAttributes pa; |
1152 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); |
1119 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1153 | |
1120 | |
1154 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1121 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1155 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1122 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1156 | |
1123 | |
1157 | if (kernel && params && src && dst) |
1124 | if (kernel && params && src && dst) |
… | |
… | |
1227 | XFreeGC (dpy, gc); |
1194 | XFreeGC (dpy, gc); |
1228 | } |
1195 | } |
1229 | } |
1196 | } |
1230 | else |
1197 | else |
1231 | { |
1198 | { |
1232 | # if XFT |
1199 | # if XRENDER |
1233 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1200 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1234 | |
1201 | |
1235 | if (flags & tintSet) |
1202 | if (flags & tintSet) |
1236 | tint.get (c); |
1203 | tint.get (c); |
1237 | |
1204 | |
… | |
… | |
1283 | } |
1250 | } |
1284 | |
1251 | |
1285 | XRenderFreePicture (dpy, mask_pic); |
1252 | XRenderFreePicture (dpy, mask_pic); |
1286 | XRenderFreePicture (dpy, overlay_pic); |
1253 | XRenderFreePicture (dpy, overlay_pic); |
1287 | XRenderFreePicture (dpy, back_pic); |
1254 | XRenderFreePicture (dpy, back_pic); |
1288 | # if DO_TIMING_TEST |
|
|
1289 | XSync (dpy, False); |
|
|
1290 | # endif |
|
|
1291 | # endif |
1255 | # endif |
1292 | } |
1256 | } |
1293 | |
1257 | |
1294 | return ret; |
1258 | return ret; |
1295 | } |
1259 | } |
1296 | |
1260 | |
1297 | /* make_transparency_pixmap() |
1261 | /* make_transparency_pixmap() |
1298 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1262 | * Builds a pixmap of the same size as the terminal window that contains |
1299 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
1263 | * the tiled portion of the root pixmap that is supposed to be covered by |
1300 | * our window. |
1264 | * our window. |
1301 | */ |
1265 | */ |
1302 | unsigned long |
1266 | unsigned long |
1303 | bgPixmap_t::make_transparency_pixmap () |
1267 | bgPixmap_t::make_transparency_pixmap () |
1304 | { |
1268 | { |
… | |
… | |
1308 | return 0; |
1272 | return 0; |
1309 | |
1273 | |
1310 | /* root dimensions may change from call to call - but Display structure should |
1274 | /* root dimensions may change from call to call - but Display structure should |
1311 | * be always up-to-date, so let's use it : |
1275 | * be always up-to-date, so let's use it : |
1312 | */ |
1276 | */ |
1313 | Window root = target->display->root; |
|
|
1314 | int screen = target->display->screen; |
1277 | int screen = target->display->screen; |
1315 | Display *dpy = target->dpy; |
1278 | Display *dpy = target->dpy; |
|
|
1279 | int root_depth = DefaultDepth (dpy, screen); |
1316 | int root_width = DisplayWidth (dpy, screen); |
1280 | int root_width = DisplayWidth (dpy, screen); |
1317 | int root_height = DisplayHeight (dpy, screen); |
1281 | int root_height = DisplayHeight (dpy, screen); |
1318 | unsigned int root_pmap_width, root_pmap_height; |
1282 | unsigned int root_pmap_width, root_pmap_height; |
1319 | int window_width = target->szHint.width; |
1283 | int window_width = target->szHint.width; |
1320 | int window_height = target->szHint.height; |
1284 | int window_height = target->szHint.height; |
1321 | int sx, sy; |
1285 | int sx, sy; |
1322 | XGCValues gcv; |
1286 | XGCValues gcv; |
1323 | GC gc; |
1287 | GC gc; |
1324 | |
1288 | |
1325 | TIMING_TEST_START (tp); |
|
|
1326 | target->get_window_origin (sx, sy); |
1289 | target->get_window_origin (sx, sy); |
1327 | |
1290 | |
1328 | /* check if we are outside of the visible part of the virtual screen : */ |
1291 | /* check if we are outside of the visible part of the virtual screen : */ |
1329 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1292 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1330 | || sx >= root_width || sy >= root_height) |
1293 | || sx >= root_width || sy >= root_height) |
1331 | return 0; |
1294 | return 0; |
1332 | |
1295 | |
|
|
1296 | // validate root pixmap and get its size |
1333 | if (root_pixmap != None) |
1297 | if (root_pixmap != None) |
1334 | { |
1298 | { |
1335 | /* we want to validate the pixmap and get its size at the same time : */ |
1299 | Window wdummy; |
1336 | int junk; |
1300 | int idummy; |
1337 | unsigned int ujunk; |
1301 | unsigned int udummy; |
1338 | /* root pixmap may be bad - allow a error */ |
1302 | |
1339 | target->allowedxerror = -1; |
1303 | target->allowedxerror = -1; |
1340 | |
1304 | |
1341 | if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) |
1305 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1342 | root_pixmap = None; |
1306 | root_pixmap = None; |
1343 | |
1307 | |
1344 | target->allowedxerror = 0; |
1308 | target->allowedxerror = 0; |
|
|
1309 | } |
|
|
1310 | |
|
|
1311 | Pixmap recoded_root_pmap = root_pixmap; |
|
|
1312 | |
|
|
1313 | if (root_pixmap != None && root_depth != target->depth) |
|
|
1314 | { |
|
|
1315 | #if XRENDER |
|
|
1316 | if (flags & HAS_RENDER) |
|
|
1317 | { |
|
|
1318 | XRenderPictureAttributes pa; |
|
|
1319 | |
|
|
1320 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
|
|
1321 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
|
|
1322 | |
|
|
1323 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
|
|
1324 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1325 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
|
|
1326 | |
|
|
1327 | if (src && dst) |
|
|
1328 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
|
|
1329 | else |
|
|
1330 | { |
|
|
1331 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1332 | root_pixmap = None; |
|
|
1333 | } |
|
|
1334 | |
|
|
1335 | XRenderFreePicture (dpy, src); |
|
|
1336 | XRenderFreePicture (dpy, dst); |
|
|
1337 | } |
|
|
1338 | else |
|
|
1339 | #endif |
|
|
1340 | root_pixmap = None; |
1345 | } |
1341 | } |
1346 | |
1342 | |
1347 | if (root_pixmap == None) |
1343 | if (root_pixmap == None) |
1348 | return 0; |
1344 | return 0; |
1349 | |
1345 | |
1350 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1346 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1351 | |
1347 | |
1352 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1348 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1353 | return 0; |
1349 | return 0; |
1354 | |
1350 | |
1355 | /* straightforward pixmap copy */ |
1351 | /* straightforward pixmap copy */ |
1356 | gcv.tile = root_pixmap; |
1352 | gcv.tile = recoded_root_pmap; |
1357 | gcv.fill_style = FillTiled; |
1353 | gcv.fill_style = FillTiled; |
1358 | |
1354 | |
1359 | while (sx < 0) sx += (int)root_width; |
1355 | while (sx < 0) sx += (int)root_width; |
1360 | while (sy < 0) sy += (int)root_height; |
1356 | while (sy < 0) sy += (int)root_height; |
1361 | |
1357 | |
1362 | gcv.ts_x_origin = -sx; |
1358 | gcv.ts_x_origin = -sx; |
1363 | gcv.ts_y_origin = -sy; |
1359 | gcv.ts_y_origin = -sy; |
1364 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1360 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1365 | |
1361 | |
1366 | if (gc) |
1362 | if (gc) |
1367 | { |
1363 | { |
1368 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1364 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1369 | result |= transpPmapTiled; |
1365 | result |= transpPmapTiled; |
1370 | XFreeGC (dpy, gc); |
1366 | XFreeGC (dpy, gc); |
1371 | } |
1367 | } |
1372 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1373 | |
1368 | |
1374 | if (tiled_root_pmap != None) |
1369 | if (tiled_root_pmap != None) |
1375 | { |
1370 | { |
1376 | if (!need_client_side_rendering ()) |
1371 | if (!need_client_side_rendering ()) |
1377 | { |
1372 | { |
1378 | if (flags & (blurNeeded | blurServerSide)) |
1373 | if ((flags & blurNeeded) |
|
|
1374 | && (flags & HAS_RENDER_CONV)) |
1379 | { |
1375 | { |
1380 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1376 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1381 | result |= transpPmapBlurred; |
1377 | result |= transpPmapBlurred; |
1382 | } |
1378 | } |
1383 | if (flags & (tintNeeded | tintServerSide)) |
1379 | if ((flags & tintNeeded) |
|
|
1380 | && (flags & (tintWholesome | HAS_RENDER))) |
1384 | { |
1381 | { |
1385 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1382 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1386 | result |= transpPmapTinted; |
1383 | result |= transpPmapTinted; |
1387 | } |
1384 | } |
1388 | } /* server side rendering completed */ |
1385 | } /* server side rendering completed */ |
1389 | |
1386 | |
1390 | if (pixmap) |
1387 | if (pixmap) |
1391 | XFreePixmap (dpy, pixmap); |
1388 | XFreePixmap (dpy, pixmap); |
1392 | |
1389 | |
1393 | pixmap = tiled_root_pmap; |
1390 | pixmap = tiled_root_pmap; |
1394 | pmap_width = window_width; |
1391 | pmap_width = window_width; |
1395 | pmap_height = window_height; |
1392 | pmap_height = window_height; |
1396 | pmap_depth = root_depth; |
1393 | pmap_depth = target->depth; |
1397 | } |
1394 | } |
1398 | |
1395 | |
1399 | TIMING_TEST_PRINT_RESULT (tp); |
1396 | if (recoded_root_pmap != root_pixmap) |
|
|
1397 | XFreePixmap (dpy, recoded_root_pmap); |
1400 | |
1398 | |
1401 | return result; |
1399 | return result; |
1402 | } |
1400 | } |
1403 | |
1401 | |
1404 | bool |
1402 | void |
1405 | bgPixmap_t::set_root_pixmap () |
1403 | bgPixmap_t::set_root_pixmap () |
1406 | { |
1404 | { |
1407 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1405 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1408 | if (new_root_pixmap == None) |
1406 | if (new_root_pixmap == None) |
1409 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1407 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1410 | |
1408 | |
1411 | if (new_root_pixmap != root_pixmap) |
|
|
1412 | { |
|
|
1413 | root_pixmap = new_root_pixmap; |
1409 | root_pixmap = new_root_pixmap; |
1414 | return true; |
|
|
1415 | } |
|
|
1416 | |
|
|
1417 | return false; |
|
|
1418 | } |
1410 | } |
1419 | # endif /* ENABLE_TRANSPARENCY */ |
1411 | # endif /* ENABLE_TRANSPARENCY */ |
1420 | |
1412 | |
1421 | # ifndef HAVE_AFTERIMAGE |
1413 | # ifndef HAVE_AFTERIMAGE |
1422 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1414 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1423 | # endif |
1415 | # endif |
1424 | |
1416 | |
1425 | bool |
1417 | bool |
1426 | bgPixmap_t::render () |
1418 | bgPixmap_t::render () |
1427 | { |
1419 | { |
1428 | unsigned long background_flags = 0; |
1420 | unsigned long background_flags = 0; |
1429 | |
1421 | |
1430 | if (target == NULL) |
1422 | if (target == NULL) |
1431 | return false; |
1423 | return false; |
1432 | |
|
|
1433 | TIMING_TEST_START (tp); |
|
|
1434 | |
1424 | |
1435 | invalidate (); |
1425 | invalidate (); |
1436 | # ifdef ENABLE_TRANSPARENCY |
1426 | # ifdef ENABLE_TRANSPARENCY |
1437 | if (flags & isTransparent) |
1427 | if (flags & isTransparent) |
1438 | { |
1428 | { |
1439 | /* we need to re-generate transparency pixmap in that case ! */ |
1429 | /* we need to re-generate transparency pixmap in that case ! */ |
1440 | background_flags = make_transparency_pixmap (); |
1430 | background_flags = make_transparency_pixmap (); |
1441 | if (background_flags == 0) |
1431 | if (background_flags == 0) |
1442 | return false; |
1432 | return false; |
1443 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1433 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1444 | && pmap_depth == target->depth) |
|
|
1445 | flags = flags & ~isInvalid; |
1434 | flags = flags & ~isInvalid; |
1446 | } |
1435 | } |
1447 | # endif |
1436 | # endif |
1448 | |
1437 | |
1449 | # ifdef BG_IMAGE_FROM_FILE |
1438 | # ifdef BG_IMAGE_FROM_FILE |
… | |
… | |
1462 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1451 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1463 | } |
1452 | } |
1464 | |
1453 | |
1465 | if (result) |
1454 | if (result) |
1466 | { |
1455 | { |
1467 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1456 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
1468 | /* our own client-side tinting */ |
1457 | /* our own client-side tinting */ |
1469 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
|
|
1470 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
|
|
1471 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1458 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1472 | { |
1459 | { |
1473 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1460 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1474 | if (flags & tintSet) |
1461 | if (flags & tintSet) |
1475 | tint.get (c); |
1462 | tint.get (c); |
1476 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1463 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1477 | } |
1464 | } |
1478 | # endif |
1465 | # endif |
1479 | |
1466 | |
1480 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1467 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1481 | |
1468 | |
1482 | if (gc) |
1469 | if (gc) |
1483 | { |
1470 | { |
1484 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
|
|
1485 | { |
|
|
1486 | XFreePixmap (target->dpy, pixmap); |
|
|
1487 | pixmap = None; |
|
|
1488 | } |
|
|
1489 | |
|
|
1490 | if (pixmap == None) |
|
|
1491 | { |
|
|
1492 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
|
|
1493 | pmap_width = result->width; |
|
|
1494 | pmap_height = result->height; |
|
|
1495 | pmap_depth = target->depth; |
|
|
1496 | } |
|
|
1497 | |
|
|
1498 | if (pmap_depth != result->depth) |
|
|
1499 | { |
|
|
1500 | /* Bad Match error will ensue ! stupid X !!!! */ |
|
|
1501 | if (result->depth == 24 && pmap_depth == 32) |
|
|
1502 | result->depth = 32; |
|
|
1503 | else if (result->depth == 32 && pmap_depth == 24) |
|
|
1504 | result->depth = 24; |
|
|
1505 | else |
|
|
1506 | { |
|
|
1507 | /* TODO: implement image recoding */ |
|
|
1508 | } |
|
|
1509 | } |
|
|
1510 | |
|
|
1511 | if (pmap_depth == result->depth) |
|
|
1512 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1471 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1513 | |
1472 | |
1514 | XFreeGC (target->dpy, gc); |
1473 | XFreeGC (target->dpy, gc); |
1515 | flags = flags & ~isInvalid; |
1474 | flags = flags & ~isInvalid; |
1516 | } |
1475 | } |
1517 | |
1476 | |
… | |
… | |
1527 | } |
1486 | } |
1528 | } |
1487 | } |
1529 | |
1488 | |
1530 | apply (); |
1489 | apply (); |
1531 | |
1490 | |
1532 | XSync (target->dpy, False); |
|
|
1533 | valid_since = ev::now (); |
1491 | valid_since = ev::now (); |
1534 | |
1492 | |
1535 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1536 | |
|
|
1537 | return true; |
1493 | return true; |
1538 | } |
1494 | } |
1539 | |
1495 | |
1540 | bool |
1496 | void |
1541 | bgPixmap_t::set_target (rxvt_term *new_target) |
1497 | bgPixmap_t::set_target (rxvt_term *new_target) |
1542 | { |
1498 | { |
1543 | if (new_target) |
|
|
1544 | if (target != new_target) |
|
|
1545 | { |
|
|
1546 | target = new_target; |
1499 | target = new_target; |
1547 | # ifdef ENABLE_TRANSPARENCY |
1500 | |
1548 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1501 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
|
|
1502 | #if XRENDER |
|
|
1503 | int major, minor; |
|
|
1504 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
|
|
1505 | flags |= HAS_RENDER; |
|
|
1506 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1507 | if (filters) |
|
|
1508 | { |
|
|
1509 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1510 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1511 | flags |= HAS_RENDER_CONV; |
|
|
1512 | |
|
|
1513 | XFree (filters); |
|
|
1514 | } |
1549 | # endif |
1515 | #endif |
1550 | return true; |
|
|
1551 | } |
|
|
1552 | |
|
|
1553 | return false; |
|
|
1554 | } |
1516 | } |
1555 | |
1517 | |
1556 | void |
1518 | void |
1557 | bgPixmap_t::apply () |
1519 | bgPixmap_t::apply () |
1558 | { |
1520 | { |
1559 | if (target) |
1521 | if (target == NULL) |
1560 | { |
1522 | return; |
1561 | flags &= ~isVtOrigin; |
|
|
1562 | |
1523 | |
1563 | if (pixmap != None) |
1524 | if (pixmap != None) |
1564 | { |
1525 | { |
1565 | /* set target's background to pixmap */ |
1526 | /* set target's background to pixmap */ |
1566 | # ifdef ENABLE_TRANSPARENCY |
1527 | # ifdef ENABLE_TRANSPARENCY |
1567 | if (flags & isTransparent) |
1528 | if (flags & isTransparent) |
1568 | { |
1529 | { |
1569 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1530 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1570 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1531 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1571 | |
1532 | |
1572 | if (target->scrollBar.win) |
1533 | if (target->scrollBar.win) |
1573 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1534 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1574 | } |
1535 | } |
1575 | else |
1536 | else |
1576 | # endif |
1537 | # endif |
1577 | { |
1538 | { |
1578 | flags |= isVtOrigin; |
|
|
1579 | /* force old pixmap dereference in case it was transparent before :*/ |
1539 | /* force old pixmap dereference in case it was transparent before :*/ |
1580 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1581 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1582 | /* do we also need to set scrollbar's background here ? */ |
|
|
1583 | |
|
|
1584 | if (target->scrollBar.win) |
|
|
1585 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1586 | } |
|
|
1587 | } |
|
|
1588 | else |
|
|
1589 | { |
|
|
1590 | /* set target background to a pixel */ |
|
|
1591 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1540 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1592 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1541 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1593 | /* do we also need to set scrollbar's background here ? */ |
1542 | /* do we also need to set scrollbar's background here ? */ |
|
|
1543 | |
1594 | if (target->scrollBar.win) |
1544 | if (target->scrollBar.win) |
1595 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1545 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1596 | } |
1546 | } |
|
|
1547 | } |
|
|
1548 | else |
|
|
1549 | { |
|
|
1550 | /* set target background to a pixel */ |
|
|
1551 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1552 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1553 | /* do we also need to set scrollbar's background here ? */ |
|
|
1554 | if (target->scrollBar.win) |
|
|
1555 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1556 | } |
1597 | |
1557 | |
1598 | /* don't want Expose on the parent or vt. It is better to use |
1558 | /* don't want Expose on the parent or vt. It is better to use |
1599 | scr_touch or we get a great deal of flicker otherwise: */ |
1559 | scr_touch or we get a great deal of flicker otherwise: */ |
1600 | XClearWindow (target->dpy, target->parent[0]); |
1560 | XClearWindow (target->dpy, target->parent[0]); |
1601 | |
1561 | |
1602 | if (target->scrollBar.state && target->scrollBar.win) |
1562 | if (target->scrollBar.state && target->scrollBar.win) |
1603 | { |
1563 | { |
1604 | target->scrollBar.state = STATE_IDLE; |
1564 | target->scrollBar.state = STATE_IDLE; |
1605 | target->scrollBar.show (0); |
1565 | target->scrollBar.show (0); |
1606 | } |
1566 | } |
1607 | |
1567 | |
1608 | target->want_refresh = 1; |
1568 | target->want_refresh = 1; |
1609 | flags |= hasChanged; |
1569 | flags |= hasChanged; |
1610 | } |
|
|
1611 | } |
1570 | } |
1612 | |
1571 | |
1613 | #endif /* HAVE_BG_PIXMAP */ |
1572 | #endif /* HAVE_BG_PIXMAP */ |
1614 | |
1573 | |
1615 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1574 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1616 | /* taken from aterm-0.4.2 */ |
1575 | /* taken from aterm-0.4.2 */ |
1617 | |
1576 | |
1618 | typedef uint32_t RUINT32T; |
|
|
1619 | |
|
|
1620 | static void |
1577 | static void |
1621 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1578 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1622 | { |
1579 | { |
1623 | int sh_r, sh_g, sh_b; |
1580 | int sh_r, sh_g, sh_b; |
1624 | RUINT32T mask_r, mask_g, mask_b; |
1581 | uint32_t mask_r, mask_g, mask_b; |
1625 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1582 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1626 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1583 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1627 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1584 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1628 | int i; |
1585 | int i; |
1629 | |
1586 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1630 | Visual *visual = term->visual; |
|
|
1631 | |
1587 | |
1632 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1588 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1633 | |
1589 | |
1634 | /* for convenience */ |
1590 | /* for convenience */ |
1635 | mask_r = visual->red_mask; |
1591 | mask_r = visual->red_mask; |
1636 | mask_g = visual->green_mask; |
1592 | mask_g = visual->green_mask; |
1637 | mask_b = visual->blue_mask; |
1593 | mask_b = visual->blue_mask; |
1638 | |
1594 | |
1639 | /* boring lookup table pre-initialization */ |
1595 | /* boring lookup table pre-initialization */ |
1640 | switch (srcImage->bits_per_pixel) |
1596 | switch (srcImage->depth) |
1641 | { |
1597 | { |
1642 | case 15: |
1598 | case 15: |
1643 | if ((mask_r != 0x7c00) || |
1599 | if ((mask_r != 0x7c00) || |
1644 | (mask_g != 0x03e0) || |
1600 | (mask_g != 0x03e0) || |
1645 | (mask_b != 0x001f)) |
1601 | (mask_b != 0x001f)) |
1646 | return; |
1602 | return; |
1647 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
1603 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1648 | lookup_r = lookup; |
1604 | lookup_r = lookup; |
1649 | lookup_g = lookup+32; |
1605 | lookup_g = lookup+32; |
1650 | lookup_b = lookup+32+32; |
1606 | lookup_b = lookup+32+32; |
1651 | sh_r = 10; |
1607 | sh_r = 10; |
1652 | sh_g = 5; |
1608 | sh_g = 5; |
… | |
… | |
1655 | case 16: |
1611 | case 16: |
1656 | if ((mask_r != 0xf800) || |
1612 | if ((mask_r != 0xf800) || |
1657 | (mask_g != 0x07e0) || |
1613 | (mask_g != 0x07e0) || |
1658 | (mask_b != 0x001f)) |
1614 | (mask_b != 0x001f)) |
1659 | return; |
1615 | return; |
1660 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
1616 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32)); |
1661 | lookup_r = lookup; |
1617 | lookup_r = lookup; |
1662 | lookup_g = lookup+32; |
1618 | lookup_g = lookup+32; |
1663 | lookup_b = lookup+32+64; |
1619 | lookup_b = lookup+32+64; |
1664 | sh_r = 11; |
1620 | sh_r = 11; |
1665 | sh_g = 5; |
1621 | sh_g = 5; |
… | |
… | |
1668 | case 24: |
1624 | case 24: |
1669 | if ((mask_r != 0xff0000) || |
1625 | if ((mask_r != 0xff0000) || |
1670 | (mask_g != 0x00ff00) || |
1626 | (mask_g != 0x00ff00) || |
1671 | (mask_b != 0x0000ff)) |
1627 | (mask_b != 0x0000ff)) |
1672 | return; |
1628 | return; |
1673 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1629 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1674 | lookup_r = lookup; |
1630 | lookup_r = lookup; |
1675 | lookup_g = lookup+256; |
1631 | lookup_g = lookup+256; |
1676 | lookup_b = lookup+256+256; |
1632 | lookup_b = lookup+256+256; |
1677 | sh_r = 16; |
1633 | sh_r = 16; |
1678 | sh_g = 8; |
1634 | sh_g = 8; |
… | |
… | |
1681 | case 32: |
1637 | case 32: |
1682 | if ((mask_r != 0xff0000) || |
1638 | if ((mask_r != 0xff0000) || |
1683 | (mask_g != 0x00ff00) || |
1639 | (mask_g != 0x00ff00) || |
1684 | (mask_b != 0x0000ff)) |
1640 | (mask_b != 0x0000ff)) |
1685 | return; |
1641 | return; |
1686 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1642 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1687 | lookup_r = lookup; |
1643 | lookup_r = lookup; |
1688 | lookup_g = lookup+256; |
1644 | lookup_g = lookup+256; |
1689 | lookup_b = lookup+256+256; |
1645 | lookup_b = lookup+256+256; |
1690 | sh_r = 16; |
1646 | sh_r = 16; |
1691 | sh_g = 8; |
1647 | sh_g = 8; |
… | |
… | |
1702 | |
1658 | |
1703 | lower_lim_r = 65535-rm; |
1659 | lower_lim_r = 65535-rm; |
1704 | lower_lim_g = 65535-gm; |
1660 | lower_lim_g = 65535-gm; |
1705 | lower_lim_b = 65535-bm; |
1661 | lower_lim_b = 65535-bm; |
1706 | |
1662 | |
1707 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
1663 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1708 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1664 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1709 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1665 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1710 | |
1666 | |
1711 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1667 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1712 | } |
1668 | } |
1713 | else |
1669 | else |
1714 | { |
1670 | { |
1715 | |
1671 | |
1716 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1672 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1717 | |
1673 | |
1718 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1674 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
1719 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1675 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
1720 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1676 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
1721 | } |
|
|
1722 | |
|
|
1723 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
|
|
1724 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000)) |
|
|
1725 | { |
|
|
1726 | unsigned int tmp; |
|
|
1727 | |
|
|
1728 | tmp = lower_lim_r; |
|
|
1729 | lower_lim_r = lower_lim_b; |
|
|
1730 | lower_lim_b = tmp; |
|
|
1731 | |
|
|
1732 | tmp = upper_lim_r; |
|
|
1733 | upper_lim_r = upper_lim_b; |
|
|
1734 | upper_lim_b = tmp; |
|
|
1735 | } |
1677 | } |
1736 | |
1678 | |
1737 | /* fill our lookup tables */ |
1679 | /* fill our lookup tables */ |
1738 | for (i = 0; i <= mask_r>>sh_r; i++) |
1680 | for (i = 0; i <= mask_r>>sh_r; i++) |
1739 | { |
1681 | { |
1740 | RUINT32T tmp; |
1682 | uint32_t tmp; |
1741 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1683 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1742 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
1684 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1743 | lookup_r[i] = (tmp/65535)<<sh_r; |
1685 | lookup_r[i] = (tmp/65535)<<sh_r; |
1744 | } |
1686 | } |
1745 | for (i = 0; i <= mask_g>>sh_g; i++) |
1687 | for (i = 0; i <= mask_g>>sh_g; i++) |
1746 | { |
1688 | { |
1747 | RUINT32T tmp; |
1689 | uint32_t tmp; |
1748 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
1690 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1749 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
1691 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1750 | lookup_g[i] = (tmp/65535)<<sh_g; |
1692 | lookup_g[i] = (tmp/65535)<<sh_g; |
1751 | } |
1693 | } |
1752 | for (i = 0; i <= mask_b>>sh_b; i++) |
1694 | for (i = 0; i <= mask_b>>sh_b; i++) |
1753 | { |
1695 | { |
1754 | RUINT32T tmp; |
1696 | uint32_t tmp; |
1755 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
1697 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1756 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1698 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1757 | lookup_b[i] = (tmp/65535)<<sh_b; |
1699 | lookup_b[i] = (tmp/65535)<<sh_b; |
1758 | } |
1700 | } |
1759 | |
1701 | |
1760 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1702 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1761 | switch (srcImage->bits_per_pixel) |
1703 | if (srcImage->bits_per_pixel == 32 |
|
|
1704 | && (srcImage->depth == 24 || srcImage->depth == 32) |
|
|
1705 | && srcImage->byte_order == host_byte_order) |
1762 | { |
1706 | { |
1763 | case 15: |
1707 | uint32_t *p1, *pf, *p, *pl; |
1764 | { |
|
|
1765 | unsigned short *p1, *pf, *p, *pl; |
|
|
1766 | p1 = (unsigned short *) srcImage->data; |
1708 | p1 = (uint32_t *) srcImage->data; |
1767 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1709 | pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1710 | |
1768 | while (p1 < pf) |
1711 | while (p1 < pf) |
1769 | { |
1712 | { |
1770 | p = p1; |
1713 | p = p1; |
1771 | pl = p1 + srcImage->width; |
1714 | pl = p1 + srcImage->width; |
1772 | for (; p < pl; p++) |
1715 | for (; p < pl; p++) |
1773 | { |
|
|
1774 | *p = lookup_r[(*p & 0x7c00)>>10] | |
|
|
1775 | lookup_g[(*p & 0x03e0)>> 5] | |
|
|
1776 | lookup_b[(*p & 0x001f)]; |
|
|
1777 | } |
|
|
1778 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1779 | } |
1716 | { |
1780 | break; |
|
|
1781 | } |
|
|
1782 | case 16: |
|
|
1783 | { |
|
|
1784 | unsigned short *p1, *pf, *p, *pl; |
|
|
1785 | p1 = (unsigned short *) srcImage->data; |
|
|
1786 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1787 | while (p1 < pf) |
|
|
1788 | { |
|
|
1789 | p = p1; |
|
|
1790 | pl = p1 + srcImage->width; |
|
|
1791 | for (; p < pl; p++) |
|
|
1792 | { |
|
|
1793 | *p = lookup_r[(*p & 0xf800)>>11] | |
|
|
1794 | lookup_g[(*p & 0x07e0)>> 5] | |
|
|
1795 | lookup_b[(*p & 0x001f)]; |
|
|
1796 | } |
|
|
1797 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1798 | } |
|
|
1799 | break; |
|
|
1800 | } |
|
|
1801 | case 24: |
|
|
1802 | { |
|
|
1803 | unsigned char *p1, *pf, *p, *pl; |
|
|
1804 | p1 = (unsigned char *) srcImage->data; |
|
|
1805 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1806 | while (p1 < pf) |
|
|
1807 | { |
|
|
1808 | p = p1; |
|
|
1809 | pl = p1 + srcImage->width * 3; |
|
|
1810 | for (; p < pl; p += 3) |
|
|
1811 | { |
|
|
1812 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
|
|
1813 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
|
|
1814 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
|
|
1815 | } |
|
|
1816 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1817 | } |
|
|
1818 | break; |
|
|
1819 | } |
|
|
1820 | case 32: |
|
|
1821 | { |
|
|
1822 | RUINT32T *p1, *pf, *p, *pl; |
|
|
1823 | p1 = (RUINT32T *) srcImage->data; |
|
|
1824 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1825 | |
|
|
1826 | while (p1 < pf) |
|
|
1827 | { |
|
|
1828 | p = p1; |
|
|
1829 | pl = p1 + srcImage->width; |
|
|
1830 | for (; p < pl; p++) |
|
|
1831 | { |
|
|
1832 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1717 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1833 | lookup_g[(*p & 0x00ff00)>> 8] | |
1718 | lookup_g[(*p & 0x00ff00) >> 8] | |
1834 | lookup_b[(*p & 0x0000ff)] | |
1719 | lookup_b[(*p & 0x0000ff)] | |
1835 | (*p & ~0xffffff); |
1720 | (*p & 0xff000000); |
1836 | } |
1721 | } |
1837 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
1722 | p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1723 | } |
|
|
1724 | } |
|
|
1725 | else |
|
|
1726 | { |
|
|
1727 | for (int y = 0; y < srcImage->height; y++) |
|
|
1728 | for (int x = 0; x < srcImage->width; x++) |
|
|
1729 | { |
|
|
1730 | unsigned long pixel = XGetPixel (srcImage, x, y); |
|
|
1731 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
|
|
1732 | lookup_g[(pixel & mask_g) >> sh_g] | |
|
|
1733 | lookup_b[(pixel & mask_b) >> sh_b]; |
|
|
1734 | XPutPixel (srcImage, x, y, pixel); |
1838 | } |
1735 | } |
1839 | break; |
|
|
1840 | } |
|
|
1841 | } |
1736 | } |
1842 | |
1737 | |
1843 | free (lookup); |
1738 | free (lookup); |
1844 | } |
1739 | } |
1845 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1740 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |