summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-11-25 05:24:36 +0100
committerKim Woelders <kim@woelders.dk>2021-11-25 09:16:54 +0100
commit4019015a479af82eea129271022dc4292dcc9dd9 (patch)
tree87f190281f6451539d8540884e35acb66eaeff27
parenteebe5a274765dfda7ba809de08692a7d6319e966 (diff)
Revert "Refactor imlib_create_scaled_image_from_drawable()"
This reverts commit eebe5a274765dfda7ba809de08692a7d6319e966. Got source/destination mixed up.
-rw-r--r--src/lib/api.c121
-rw-r--r--src/lib/x11_grab.c98
-rw-r--r--src/lib/x11_grab.h8
3 files changed, 111 insertions, 116 deletions
diff --git a/src/lib/api.c b/src/lib/api.c
index cae0d34..5f22ea7 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -3,6 +3,11 @@
3#include <math.h> 3#include <math.h>
4#include <string.h> 4#include <string.h>
5#include <stdarg.h> 5#include <stdarg.h>
6#ifdef BUILD_X11
7#include <X11/Xlib.h>
8#include <X11/Xutil.h>
9#include <X11/extensions/shape.h>
10#endif
6 11
7#include "Imlib2.h" 12#include "Imlib2.h"
8#include "blend.h" 13#include "blend.h"
@@ -2310,28 +2315,124 @@ imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x,
2310 char get_mask_from_shape) 2315 char get_mask_from_shape)
2311{ 2316{
2312 ImlibImage *im; 2317 ImlibImage *im;
2313 char domask; 2318 char domask = 0, tmpmask = 0;
2319 int x, xx;
2320 XGCValues gcv;
2321 GC gc = 0, mgc = 0;
2322 Pixmap p, m;
2314 2323
2315 CHECK_CONTEXT(ctx); 2324 CHECK_CONTEXT(ctx);
2316 if (!IMAGE_DIMENSIONS_OK(source_width, source_height)) 2325 if (!IMAGE_DIMENSIONS_OK(source_width, source_height))
2317 return NULL; 2326 return NULL;
2318 if (!IMAGE_DIMENSIONS_OK(destination_width, destination_height)) 2327 if (!IMAGE_DIMENSIONS_OK(destination_width, destination_height))
2319 return NULL; 2328 return NULL;
2329 if ((mask) || (get_mask_from_shape))
2330 domask = 1;
2320 2331
2321 domask = mask != 0 || get_mask_from_shape; 2332 p = XCreatePixmap(ctx->display, ctx->drawable, destination_width,
2333 source_height, ctx->depth);
2322 2334
2323 im = __imlib_CreateImage(destination_width, destination_height, NULL); 2335 gcv.foreground = 0;
2324 im->data = malloc(destination_width * destination_height * sizeof(DATA32)); 2336 gcv.subwindow_mode = IncludeInferiors;
2337 gcv.graphics_exposures = False;
2338 gc = XCreateGC(ctx->display, ctx->drawable,
2339 GCSubwindowMode | GCGraphicsExposures, &gcv);
2340
2341 if ((domask) && (!mask))
2342 {
2343 XRectangle *rect;
2344 int rect_num, rect_ord;
2345
2346 rect = XShapeGetRectangles(ctx->display, ctx->drawable, ShapeBounding,
2347 &rect_num, &rect_ord);
2348
2349 if (rect && (rect_num == 1 &&
2350 rect[0].x == 0 && rect[0].y == 0 &&
2351 rect[0].width == source_width &&
2352 rect[0].height == source_height))
2353 {
2354 domask = 0;
2355 XFree(rect);
2356 }
2357 else
2358 {
2359 tmpmask = 1;
2360 mask =
2361 XCreatePixmap(ctx->display, ctx->drawable, source_width,
2362 source_height, 1);
2363 mgc = XCreateGC(ctx->display, mask,
2364 GCForeground | GCGraphicsExposures, &gcv);
2365 XFillRectangle(ctx->display, mask, mgc, 0, 0, source_width,
2366 source_height);
2367 if (rect)
2368 {
2369 XSetForeground(ctx->display, mgc, 1);
2370 for (x = 0; x < rect_num; x++)
2371 XFillRectangle(ctx->display, mask, mgc, rect[x].x,
2372 rect[x].y, rect[x].width, rect[x].height);
2373 XFree(rect);
2374 }
2375 }
2376 }
2325 2377
2326 __imlib_GrabDrawableScaledToRGBA(im->data, source_x, source_y, 2378 if ((destination_width == source_width) &&
2327 source_width, source_height, 2379 (destination_height == source_height))
2328 ctx->display, ctx->drawable, mask, 2380 {
2329 ctx->visual, ctx->colormap, ctx->depth, 0, 2381 XCopyArea(ctx->display, ctx->drawable, p, gc, source_x, source_y,
2330 0, destination_width, destination_height, 2382 source_width, source_height, 0, 0);
2331 &domask, need_to_grab_x); 2383 m = mask;
2384 }
2385 else
2386 {
2387 if (domask)
2388 {
2389 m = XCreatePixmap(ctx->display, ctx->drawable, destination_width,
2390 source_height, 1);
2391 if (!mgc)
2392 mgc = XCreateGC(ctx->display, m,
2393 GCForeground | GCGraphicsExposures, &gcv);
2394 }
2395 else
2396 m = None;
2397
2398 for (x = 0; x < destination_width; x++)
2399 {
2400 xx = (source_width * x) / destination_width;
2401 XCopyArea(ctx->display, ctx->drawable, p, gc,
2402 source_x + xx, source_y, 1, source_height, x, 0);
2403 if (m != None)
2404 XCopyArea(ctx->display, mask, m, mgc,
2405 xx, 0, 1, source_height, x, 0);
2406 }
2407 for (x = 0; x < destination_height; x++)
2408 {
2409 xx = (source_height * x) / destination_height;
2410 XCopyArea(ctx->display, p, p, gc,
2411 0, xx, destination_width, 1, 0, x);
2412 if (m != None)
2413 XCopyArea(ctx->display, m, m, mgc,
2414 0, xx, destination_width, 1, 0, x);
2415 }
2416 }
2332 2417
2418 im = __imlib_CreateImage(destination_width, destination_height, NULL);
2419 im->data = malloc(destination_width * destination_height * sizeof(DATA32));
2420 __imlib_GrabDrawableToRGBA(im->data, 0, 0, destination_width,
2421 source_height, ctx->display, p, m,
2422 ctx->visual, ctx->colormap, ctx->depth, 0, 0,
2423 destination_width, destination_height, &domask,
2424 need_to_grab_x);
2333 UPDATE_FLAG(im->flags, F_HAS_ALPHA, domask); 2425 UPDATE_FLAG(im->flags, F_HAS_ALPHA, domask);
2334 2426
2427 if (mgc)
2428 XFreeGC(ctx->display, mgc);
2429 if (m != None && m != mask)
2430 XFreePixmap(ctx->display, m);
2431 if (tmpmask)
2432 XFreePixmap(ctx->display, mask);
2433 XFreeGC(ctx->display, gc);
2434 XFreePixmap(ctx->display, p);
2435
2335 return (Imlib_Image) im; 2436 return (Imlib_Image) im;
2336} 2437}
2337 2438
diff --git a/src/lib/x11_grab.c b/src/lib/x11_grab.c
index 8b31b92..709bdbe 100644
--- a/src/lib/x11_grab.c
+++ b/src/lib/x11_grab.c
@@ -829,101 +829,3 @@ __imlib_GrabDrawableToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
829 829
830 return 1; 830 return 1;
831} 831}
832
833int
834__imlib_GrabDrawableScaledToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
835 Display * d, Drawable p, Pixmap m, Visual * v,
836 Colormap cm, int depth, int x, int y,
837 int w, int h, char *pdomask, int grab)
838{
839 int rc;
840 int tmpmask = 0;
841 int i, xx;
842 XGCValues gcv;
843 GC gc = 0, mgc = 0;
844 Pixmap psc, msc;
845
846 psc = XCreatePixmap(d, p, w, oh, depth);
847
848 gcv.foreground = 0;
849 gcv.subwindow_mode = IncludeInferiors;
850 gcv.graphics_exposures = False;
851 gc = XCreateGC(d, p, GCSubwindowMode | GCGraphicsExposures, &gcv);
852
853 if (*pdomask && !m)
854 {
855 XRectangle *rect;
856 int rect_num, rect_ord;
857
858 rect = XShapeGetRectangles(d, p, ShapeBounding, &rect_num, &rect_ord);
859
860 if (rect && (rect_num == 1 && rect[0].x == 0 && rect[0].y == 0 &&
861 rect[0].width == ow && rect[0].height == oh))
862 {
863 *pdomask = 0;
864 XFree(rect);
865 }
866 else
867 {
868 tmpmask = 1;
869 m = XCreatePixmap(d, p, ow, oh, 1);
870 mgc = XCreateGC(d, m, GCForeground | GCGraphicsExposures, &gcv);
871 XFillRectangle(d, m, mgc, 0, 0, ow, oh);
872 if (rect)
873 {
874 XSetForeground(d, mgc, 1);
875 for (i = 0; i < rect_num; i++)
876 XFillRectangle(d, m, mgc, rect[i].x, rect[i].y,
877 rect[i].width, rect[i].height);
878 XFree(rect);
879 }
880 }
881 }
882
883 if (w == ow && h == oh)
884 {
885 XCopyArea(d, p, psc, gc, ox, oy, ow, oh, 0, 0);
886 msc = m;
887 }
888 else
889 {
890 if (*pdomask)
891 {
892 msc = XCreatePixmap(d, p, w, oh, 1);
893 if (!mgc)
894 mgc =
895 XCreateGC(d, msc, GCForeground | GCGraphicsExposures, &gcv);
896 }
897 else
898 msc = None;
899
900 for (i = 0; i < w; i++)
901 {
902 xx = (ow * i) / w;
903 XCopyArea(d, p, psc, gc, ox + xx, oy, 1, oh, i, 0);
904 if (msc != None)
905 XCopyArea(d, m, msc, mgc, xx, 0, 1, oh, i, 0);
906 }
907 for (i = 0; i < h; i++)
908 {
909 xx = (oh * i) / h;
910 XCopyArea(d, psc, psc, gc, 0, xx, w, 1, 0, i);
911 if (msc != None)
912 XCopyArea(d, msc, msc, mgc, 0, xx, w, 1, 0, i);
913 }
914 }
915
916 rc = __imlib_GrabDrawableToRGBA(data, 0, 0, w, oh, d, psc, msc,
917 v, cm, depth, 0, 0, w, h, pdomask, grab);
918
919 if (mgc)
920 XFreeGC(d, mgc);
921 if (msc != None && msc != m)
922 XFreePixmap(d, msc);
923 if (tmpmask)
924 XFreePixmap(d, m);
925 XFreeGC(d, gc);
926 XFreePixmap(d, psc);
927
928 return rc;
929}
diff --git a/src/lib/x11_grab.h b/src/lib/x11_grab.h
index b6f3ad6..b37804b 100644
--- a/src/lib/x11_grab.h
+++ b/src/lib/x11_grab.h
@@ -10,14 +10,6 @@ int __imlib_GrabDrawableToRGBA(DATA32 * data, int ox, int oy,
10 int y, int w, int h, 10 int y, int w, int h,
11 char *domask, int grab); 11 char *domask, int grab);
12 12
13int __imlib_GrabDrawableScaledToRGBA(DATA32 * data, int ox,
14 int oy, int ow, int oh,
15 Display * d, Drawable p,
16 Pixmap m, Visual * v,
17 Colormap cm, int depth,
18 int x, int y, int w, int h,
19 char *pdomask, int grab);
20
21void __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, 13void __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy,
22 int ow, int oh, Display * d, 14 int ow, int oh, Display * d,
23 XImage * xim, XImage * mxim, 15 XImage * xim, XImage * mxim,