This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 1fd61bb25d5480efbb738b60ad2d5dc9e19c2963
Author: Kim Woelders <[email protected]>
AuthorDate: Fri Jul 22 18:29:19 2022 +0200

    api: Move X11 related functions to separate file
---
 src/lib/Makefile.am |  15 +-
 src/lib/api.c       | 593 +---------------------------------------------------
 src/lib/api.h       |  68 ++++++
 src/lib/api_x11.c   | 525 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 605 insertions(+), 596 deletions(-)

diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index e68ba86..ffd6671 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -11,8 +11,11 @@ AM_CCASFLAGS = -I$(top_builddir)
 lib_LTLIBRARIES      = libImlib2.la
 include_HEADERS      = Imlib2.h Imlib2_Loader.h
 
+libImlib2_la_LIBADD  =
+
 libImlib2_la_SOURCES = \
-api.c 		api_obsolete.c	\
+api.c 		api.h		\
+api_obsolete.c	\
 asm.h \
 asm_c.c		asm_c.h		\
 blend.c		blend.h		\
@@ -47,6 +50,8 @@ strutils.c	strutils.h	\
 types.h	\
 updates.c	updates.h
 
+libImlib2_la_LIBADD += $(FREETYPE_LIBS)
+
 MMX_SRCS = \
 asm_blend.S \
 asm_blend_cmod.S \
@@ -60,9 +65,9 @@ amd64_blend_cmod.S
 
 EXTRA_DIST = $(MMX_SRCS) $(AMD64_SRCS) asm_loadimmq.S
 
-MY_LIBS = $(FREETYPE_LIBS) $(DLOPEN_LIBS) -lm
 if BUILD_X11
 libImlib2_la_SOURCES += \
+api_x11.c	\
 x11_color.c	x11_color.h	\
 x11_context.c	x11_context.h	\
 x11_grab.c	x11_grab.h	\
@@ -70,10 +75,10 @@ x11_pixmap.c	x11_pixmap.h	\
 x11_rend.c	x11_rend.h	\
 x11_rgba.c	x11_rgba.h	\
 x11_ximage.c	x11_ximage.h
-MY_LIBS += -lXext -lX11 @X_SHM_FD_LIBS@
+libImlib2_la_LIBADD += -lXext -lX11 $(X_SHM_FD_LIBS)
 endif
 if BUILD_DEBUG
-MY_LIBS += $(CLOCK_LIBS)
+libImlib2_la_LIBADD += $(CLOCK_LIBS)
 endif
 
 if BUILD_MMX
@@ -83,5 +88,5 @@ if BUILD_AMD64
 libImlib2_la_SOURCES += $(AMD64_SRCS)
 endif
 
-libImlib2_la_LIBADD  = $(MY_LIBS)
+libImlib2_la_LIBADD += $(DLOPEN_LIBS) -lm
 libImlib2_la_LDFLAGS = -version-info @lt_version@
diff --git a/src/lib/api.c b/src/lib/api.c
index 7f0dbc8..7eed2a2 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "api.h"
 #include "blend.h"
 #include "colormod.h"
 #include "color_helpers.h"
@@ -25,82 +26,14 @@
 #include "script.h"
 #include "updates.h"
 #ifdef BUILD_X11
-#include "x11_color.h"
-#include "x11_grab.h"
 #include "x11_pixmap.h"
-#include "x11_rend.h"
-#include "x11_ximage.h"
 #endif
 
-/* convenience macros */
-#define   CAST_IMAGE(im, image) (im) = (ImlibImage *)(image)
-#define   CHECK_PARAM_POINTER_RETURN(sparam, param, ret) \
-if (!(param)) \
-{ \
-  fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
-                  "\tThis program is calling the Imlib call:\n\n" \
-                  "\t%s();\n\n" \
-                  "\tWith the parameter:\n\n" \
-                  "\t%s\n\n" \
-                  "\tbeing NULL. Please fix your program.\n", __func__, sparam); \
-  return ret; \
-}
-
-#define   CHECK_PARAM_POINTER(sparam, param) \
-if (!(param)) \
-{ \
-  fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
-                  "\tThis program is calling the Imlib call:\n\n" \
-                  "\t%s();\n\n" \
-                  "\tWith the parameter:\n\n" \
-                  "\t%s\n\n" \
-                  "\tbeing NULL. Please fix your program.\n", __func__, sparam); \
-  return; \
-}
-
 #define ILA0(ctx, imm, noc) \
    .pfunc = (ImlibProgressFunction)(ctx)->progress_func, \
    .pgran = (ctx)->progress_granularity, \
    .immed = imm, .nocache = noc
 
-/* internal typedefs for function pointers */
-typedef void        (*Imlib_Internal_Progress_Function)(void *, char, int, int,
-                                                        int, int);
-typedef void        (*Imlib_Internal_Data_Destructor_Function)(void *, void *);
-
-typedef struct {
-#ifdef BUILD_X11
-   Display            *display;
-   Visual             *visual;
-   Colormap            colormap;
-   int                 depth;
-   Drawable            drawable;
-   Pixmap              mask;
-#endif
-   char                anti_alias;
-   char                dither;
-   char                blend;
-   Imlib_Color_Modifier color_modifier;
-   ImlibOp             operation;
-   Imlib_Font          font;
-   Imlib_Text_Direction direction;
-   double              angle;
-   Imlib_Color         color;
-   uint32_t            pixel;
-   Imlib_Color_Range   color_range;
-   Imlib_Image         image;
-   Imlib_Image_Data_Memory_Function image_data_memory_func;
-   Imlib_Progress_Function progress_func;
-   char                progress_granularity;
-   char                dither_mask;
-   int                 mask_alpha_threshold;
-   Imlib_Filter        filter;
-   Imlib_Rectangle     cliprect;
-
-   int                 references;
-   char                dirty;
-} ImlibContext;
-
 typedef struct _ImlibContextItem {
    ImlibContext       *context;
    struct _ImlibContextItem *below;
@@ -128,7 +61,7 @@ static const ImlibContext ctx_default = DefaultContext;
 static ImlibContext ctx0 = DefaultContext;
 
 /* Current context */
-static ImlibContext *ctx = &ctx0;
+ImlibContext       *ctx = &ctx0;
 
 /* a stack of contexts -- only used by context-handling functions. */
 static ImlibContextItem contexts0 = {.context = &ctx0 };
@@ -313,138 +246,6 @@ imlib_context_get_cliprect(int *x, int *y, int *w, int *h)
    *h = ctx->cliprect.h;
 }
 
-#ifdef BUILD_X11
-EAPI void
-imlib_context_set_display(Display * display)
-{
-   ctx->display = display;
-}
-
-EAPI Display       *
-imlib_context_get_display(void)
-{
-   return ctx->display;
-}
-
-EAPI void
-imlib_context_disconnect_display(void)
-{
-   if (!ctx->display)
-      return;
-   __imlib_RenderDisconnect(ctx->display);
-   ctx->display = NULL;
-}
-
-EAPI void
-imlib_context_set_visual(Visual * visual)
-{
-   ctx->visual = visual;
-   ctx->depth = imlib_get_visual_depth(ctx->display, ctx->visual);
-}
-
-EAPI Visual        *
-imlib_context_get_visual(void)
-{
-   return ctx->visual;
-}
-
-EAPI void
-imlib_context_set_colormap(Colormap colormap)
-{
-   ctx->colormap = colormap;
-}
-
-EAPI                Colormap
-imlib_context_get_colormap(void)
-{
-   return ctx->colormap;
-}
-
-EAPI void
-imlib_context_set_drawable(Drawable drawable)
-{
-   ctx->drawable = drawable;
-}
-
-EAPI                Drawable
-imlib_context_get_drawable(void)
-{
-   return ctx->drawable;
-}
-
-EAPI void
-imlib_context_set_mask(Pixmap mask)
-{
-   ctx->mask = mask;
-}
-
-EAPI                Pixmap
-imlib_context_get_mask(void)
-{
-   return ctx->mask;
-}
-
-EAPI void
-imlib_context_set_dither_mask(char dither_mask)
-{
-   ctx->dither_mask = dither_mask;
-}
-
-EAPI char
-imlib_context_get_dither_mask(void)
-{
-   return ctx->dither_mask;
-}
-
-EAPI void
-imlib_context_set_mask_alpha_threshold(int mask_alpha_threshold)
-{
-   ctx->mask_alpha_threshold = mask_alpha_threshold;
-}
-
-EAPI int
-imlib_context_get_mask_alpha_threshold(void)
-{
-   return ctx->mask_alpha_threshold;
-}
-
-EAPI int
-imlib_get_ximage_cache_count_used(void)
-{
-   return __imlib_GetXImageCacheCountUsed(ctx->display);
-}
-
-EAPI int
-imlib_get_ximage_cache_count_max(void)
-{
-   return __imlib_GetXImageCacheCountMax(ctx->display);
-}
-
-EAPI void
-imlib_set_ximage_cache_count_max(int count)
-{
-   __imlib_SetXImageCacheCountMax(ctx->display, count);
-}
-
-EAPI int
-imlib_get_ximage_cache_size_used(void)
-{
-   return __imlib_GetXImageCacheSizeUsed(ctx->display);
-}
-
-EAPI int
-imlib_get_ximage_cache_size_max(void)
-{
-   return __imlib_GetXImageCacheSizeMax(ctx->display);
-}
-
-EAPI void
-imlib_set_ximage_cache_size_max(int bytes)
-{
-   __imlib_SetXImageCacheSizeMax(ctx->display, bytes);
-}
-#endif
-
 EAPI void
 imlib_context_set_anti_alias(char anti_alias)
 {
@@ -722,40 +523,6 @@ imlib_set_cache_size(int bytes)
    __imlib_SetCacheSize(bytes);
 }
 
-#ifdef BUILD_X11
-EAPI int
-imlib_get_color_usage(void)
-{
-   return (int)_max_colors;
-}
-
-EAPI void
-imlib_set_color_usage(int max)
-{
-   if (max < 2)
-      max = 2;
-   else if (max > 256)
-      max = 256;
-   _max_colors = max;
-}
-
-EAPI int
-imlib_get_visual_depth(Display * display, Visual * visual)
-{
-   CHECK_PARAM_POINTER_RETURN("display", display, 0);
-   CHECK_PARAM_POINTER_RETURN("visual", visual, 0);
-   return __imlib_XActualDepth(display, visual);
-}
-
-EAPI Visual        *
-imlib_get_best_visual(Display * display, int screen, int *depth_return)
-{
-   CHECK_PARAM_POINTER_RETURN("display", display, NULL);
-   CHECK_PARAM_POINTER_RETURN("depth_return", depth_return, NULL);
-   return __imlib_BestVisual(display, screen, depth_return);
-}
-#endif
-
 EAPI void
 imlib_flush_loaders(void)
 {
@@ -1143,116 +910,6 @@ imlib_image_set_has_alpha(char has_alpha)
    im->has_alpha = has_alpha;
 }
 
-#ifdef BUILD_X11
-EAPI void
-imlib_render_pixmaps_for_whole_image(Pixmap * pixmap_return,
-                                     Pixmap * mask_return)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CHECK_PARAM_POINTER("pixmap_return", pixmap_return);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
-                                 ctx->depth, ctx->colormap, im, pixmap_return,
-                                 mask_return, 0, 0, im->w, im->h, im->w,
-                                 im->h, 0, ctx->dither, ctx->dither_mask,
-                                 ctx->mask_alpha_threshold,
-                                 ctx->color_modifier);
-}
-
-EAPI void
-imlib_render_pixmaps_for_whole_image_at_size(Pixmap * pixmap_return,
-                                             Pixmap * mask_return, int width,
-                                             int height)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CHECK_PARAM_POINTER("pixmap_return", pixmap_return);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
-                                 ctx->depth, ctx->colormap, im, pixmap_return,
-                                 mask_return, 0, 0, im->w, im->h, width,
-                                 height, ctx->anti_alias, ctx->dither,
-                                 ctx->dither_mask, ctx->mask_alpha_threshold,
-                                 ctx->color_modifier);
-}
-
-EAPI void
-imlib_free_pixmap_and_mask(Pixmap pixmap)
-{
-   __imlib_FreePixmap(ctx->display, pixmap);
-}
-
-EAPI void
-imlib_render_image_on_drawable(int x, int y)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
-                       ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
-                       im->h, x, y, im->w, im->h, 0, ctx->dither, ctx->blend,
-                       ctx->dither_mask, ctx->mask_alpha_threshold,
-                       ctx->color_modifier, ctx->operation);
-}
-
-EAPI void
-imlib_render_image_on_drawable_at_size(int x, int y, int width, int height)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
-                       ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
-                       im->h, x, y, width, height, ctx->anti_alias,
-                       ctx->dither, ctx->blend, ctx->dither_mask,
-                       ctx->mask_alpha_threshold, ctx->color_modifier,
-                       ctx->operation);
-}
-
-EAPI void
-imlib_render_image_part_on_drawable_at_size(int source_x, int source_y,
-                                            int source_width,
-                                            int source_height, int x, int y,
-                                            int width, int height)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
-                       ctx->colormap, ctx->depth, source_x, source_y,
-                       source_width, source_height, x, y, width, height,
-                       ctx->anti_alias, ctx->dither, ctx->blend, 0,
-                       0, ctx->color_modifier, ctx->operation);
-}
-
-EAPI                uint32_t
-imlib_render_get_pixel_color(void)
-{
-   return __imlib_RenderGetPixel(ctx->display, ctx->drawable, ctx->visual,
-                                 ctx->colormap, ctx->depth,
-                                 (uint8_t) ctx->color.red,
-                                 (uint8_t) ctx->color.green,
-                                 (uint8_t) ctx->color.blue);
-}
-
-#endif
-
 EAPI void
 imlib_blend_image_onto_image(Imlib_Image source_image, char merge_alpha,
                              int source_x, int source_y, int source_width,
@@ -1351,176 +1008,6 @@ imlib_create_image_using_copied_data(int width, int height, uint32_t * data)
    return NULL;
 }
 
-#ifdef BUILD_X11
-EAPI                Imlib_Image
-imlib_create_image_from_drawable(Pixmap mask, int x, int y, int width,
-                                 int height, char need_to_grab_x)
-{
-   ImlibImage         *im;
-   char                domask = 0;
-
-   if (!IMAGE_DIMENSIONS_OK(width, height))
-      return NULL;
-   if (mask)
-     {
-        domask = 1;
-        if (mask == (Pixmap) 1)
-           mask = None;
-     }
-   im = __imlib_CreateImage(width, height, NULL);
-   if (!im)
-      return NULL;
-   im->data = "" * height * sizeof(uint32_t));
-   if (im->data &&
-       __imlib_GrabDrawableToRGBA(im->data, 0, 0, width, height, ctx->display,
-                                  ctx->drawable, mask, ctx->visual,
-                                  ctx->colormap, ctx->depth, x, y, width,
-                                  height, &domask, need_to_grab_x))
-     {
-        im->has_alpha = domask;
-     }
-   else
-     {
-        __imlib_FreeImage(im);
-        im = NULL;
-     }
-
-   return im;
-}
-
-EAPI                Imlib_Image
-imlib_create_image_from_ximage(XImage * image, XImage * mask, int x, int y,
-                               int width, int height, char need_to_grab_x)
-{
-   ImlibImage         *im;
-
-   if (!IMAGE_DIMENSIONS_OK(width, height))
-      return NULL;
-   im = __imlib_CreateImage(width, height, NULL);
-   if (!im)
-      return NULL;
-   im->data = "" * height * sizeof(uint32_t));
-   if (!im->data)
-     {
-        __imlib_FreeImage(im);
-        return NULL;
-     }
-   __imlib_GrabXImageToRGBA(im->data, 0, 0, width, height,
-                            ctx->display, image, mask, ctx->visual,
-                            ctx->depth, x, y, width, height, need_to_grab_x);
-   return im;
-}
-
-EAPI                Imlib_Image
-imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x,
-                                        int source_y, int source_width,
-                                        int source_height,
-                                        int destination_width,
-                                        int destination_height,
-                                        char need_to_grab_x,
-                                        char get_mask_from_shape)
-{
-   ImlibImage         *im;
-   char                domask;
-
-   if (!IMAGE_DIMENSIONS_OK(source_width, source_height))
-      return NULL;
-   if (!IMAGE_DIMENSIONS_OK(destination_width, destination_height))
-      return NULL;
-
-   domask = mask != 0 || get_mask_from_shape;
-
-   im = __imlib_CreateImage(destination_width, destination_height, NULL);
-   if (!im)
-      return NULL;
-   im->data = "" * destination_height * sizeof(uint32_t));
-   if (!im->data)
-     {
-        __imlib_FreeImage(im);
-        return NULL;
-     }
-
-   __imlib_GrabDrawableScaledToRGBA(im->data, 0, 0,
-                                    destination_width, destination_height,
-                                    ctx->display, ctx->drawable, mask,
-                                    ctx->visual, ctx->colormap, ctx->depth,
-                                    source_x, source_y,
-                                    source_width, source_height,
-                                    &domask, need_to_grab_x);
-
-   im->has_alpha = domask;
-
-   return im;
-}
-
-EAPI char
-imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int width, int height,
-                             int destination_x, int destination_y,
-                             char need_to_grab_x)
-{
-   ImlibImage         *im;
-   char                domask = 0;
-   int                 pre_adj;
-
-   CHECK_PARAM_POINTER_RETURN("image", ctx->image, 0);
-   if (mask)
-     {
-        domask = 1;
-        if (mask == (Pixmap) 1)
-           mask = None;
-     }
-   CAST_IMAGE(im, ctx->image);
-
-   if (__imlib_LoadImageData(im))
-      return 0;
-
-   pre_adj = 0;
-   if (x < 0)
-     {
-        width += x;
-        pre_adj = x;
-        x = 0;
-     }
-   if (width < 0)
-      width = 0;
-   if (destination_x < 0)
-     {
-        width += destination_x;
-        x -= destination_x - pre_adj;
-        destination_x = 0;
-     }
-   if ((destination_x + width) >= im->w)
-      width = im->w - destination_x;
-
-   pre_adj = 0;
-   if (y < 0)
-     {
-        height += y;
-        pre_adj = y;
-        y = 0;
-     }
-   if (height < 0)
-      height = 0;
-   if (destination_y < 0)
-     {
-        height += destination_y;
-        y -= destination_y - pre_adj;
-        destination_y = 0;
-     }
-   if ((destination_y + height) >= im->h)
-      height = im->h - destination_y;
-
-   if ((width <= 0) || (height <= 0))
-      return 0;
-   __imlib_DirtyImage(im);
-   return __imlib_GrabDrawableToRGBA(im->data, destination_x, destination_y,
-                                     im->w, im->h, ctx->display,
-                                     ctx->drawable, mask, ctx->visual,
-                                     ctx->colormap, ctx->depth, x, y, width,
-                                     height, &domask, need_to_grab_x);
-}
-#endif
-
 EAPI                Imlib_Image
 imlib_clone_image(void)
 {
@@ -1725,36 +1212,6 @@ imlib_updates_set_coordinates(Imlib_Updates updates, int x, int y, int width,
    u->h = height;
 }
 
-#ifdef BUILD_X11
-EAPI void
-imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y)
-{
-   ImlibUpdate        *u;
-   ImlibImage         *im;
-   int                 ximcs;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   u = (ImlibUpdate *) updates;
-   if (!updates)
-      return;
-   if (__imlib_LoadImageData(im))
-      return;
-   ximcs = __imlib_GetXImageCacheCountMax(ctx->display);        /* Save */
-   if (ximcs == 0)              /* Only if we don't set this up elsewhere */
-      __imlib_SetXImageCacheCountMax(ctx->display, 10);
-   for (; u; u = u->next)
-     {
-        __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
-                            ctx->colormap, ctx->depth, u->x, u->y, u->w, u->h,
-                            x + u->x, y + u->y, u->w, u->h, 0, ctx->dither, 0,
-                            0, 0, ctx->color_modifier, OP_COPY);
-     }
-   if (ximcs == 0)
-      __imlib_SetXImageCacheCountMax(ctx->display, ximcs);
-}
-#endif
-
 EAPI                Imlib_Updates
 imlib_updates_init(void)
 {
@@ -3108,52 +2565,6 @@ imlib_blend_image_onto_image_skewed(Imlib_Image source_image,
                                    ctx->cliprect.w, ctx->cliprect.h);
 }
 
-#ifdef BUILD_X11
-EAPI void
-imlib_render_image_on_drawable_skewed(int source_x, int source_y,
-                                      int source_width, int source_height,
-                                      int destination_x, int destination_y,
-                                      int h_angle_x, int h_angle_y,
-                                      int v_angle_x, int v_angle_y)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
-                             ctx->visual, ctx->colormap, ctx->depth, source_x,
-                             source_y, source_width, source_height,
-                             destination_x, destination_y, h_angle_x,
-                             h_angle_y, v_angle_x, v_angle_y, ctx->anti_alias,
-                             ctx->dither, ctx->blend, ctx->dither_mask,
-                             ctx->mask_alpha_threshold, ctx->color_modifier,
-                             ctx->operation);
-}
-
-EAPI void
-imlib_render_image_on_drawable_at_angle(int source_x, int source_y,
-                                        int source_width, int source_height,
-                                        int destination_x, int destination_y,
-                                        int angle_x, int angle_y)
-{
-   ImlibImage         *im;
-
-   CHECK_PARAM_POINTER("image", ctx->image);
-   CAST_IMAGE(im, ctx->image);
-   if (__imlib_LoadImageData(im))
-      return;
-   __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
-                             ctx->visual, ctx->colormap, ctx->depth, source_x,
-                             source_y, source_width, source_height,
-                             destination_x, destination_y, angle_x, angle_y,
-                             0, 0, ctx->anti_alias, ctx->dither, ctx->blend,
-                             ctx->dither_mask, ctx->mask_alpha_threshold,
-                             ctx->color_modifier, ctx->operation);
-}
-#endif
-
 EAPI void
 imlib_image_filter(void)
 {
diff --git a/src/lib/api.h b/src/lib/api.h
new file mode 100644
index 0000000..435a7f0
--- /dev/null
+++ b/src/lib/api.h
@@ -0,0 +1,68 @@
+
+#include "rgbadraw.h"
+
+/* convenience macros */
+#define   CAST_IMAGE(im, image) (im) = (ImlibImage *)(image)
+#define   CHECK_PARAM_POINTER_RETURN(sparam, param, ret) \
+if (!(param)) \
+{ \
+  fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
+                  "\tThis program is calling the Imlib call:\n\n" \
+                  "\t%s();\n\n" \
+                  "\tWith the parameter:\n\n" \
+                  "\t%s\n\n" \
+                  "\tbeing NULL. Please fix your program.\n", __func__, sparam); \
+  return ret; \
+}
+
+#define   CHECK_PARAM_POINTER(sparam, param) \
+if (!(param)) \
+{ \
+  fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
+                  "\tThis program is calling the Imlib call:\n\n" \
+                  "\t%s();\n\n" \
+                  "\tWith the parameter:\n\n" \
+                  "\t%s\n\n" \
+                  "\tbeing NULL. Please fix your program.\n", __func__, sparam); \
+  return; \
+}
+
+/* internal typedefs for function pointers */
+typedef void        (*Imlib_Internal_Progress_Function)(void *, char, int, int,
+                                                        int, int);
+typedef void        (*Imlib_Internal_Data_Destructor_Function)(void *, void *);
+
+typedef struct {
+#ifdef BUILD_X11
+   Display            *display;
+   Visual             *visual;
+   Colormap            colormap;
+   int                 depth;
+   Drawable            drawable;
+   Pixmap              mask;
+#endif
+   char                anti_alias;
+   char                dither;
+   char                blend;
+   Imlib_Color_Modifier color_modifier;
+   ImlibOp             operation;
+   Imlib_Font          font;
+   Imlib_Text_Direction direction;
+   double              angle;
+   Imlib_Color         color;
+   uint32_t            pixel;
+   Imlib_Color_Range   color_range;
+   Imlib_Image         image;
+   Imlib_Image_Data_Memory_Function image_data_memory_func;
+   Imlib_Progress_Function progress_func;
+   char                progress_granularity;
+   char                dither_mask;
+   int                 mask_alpha_threshold;
+   Imlib_Filter        filter;
+   Imlib_Rectangle     cliprect;
+
+   int                 references;
+   char                dirty;
+} ImlibContext;
+
+extern ImlibContext *ctx;
diff --git a/src/lib/api_x11.c b/src/lib/api_x11.c
new file mode 100644
index 0000000..a66d033
--- /dev/null
+++ b/src/lib/api_x11.c
@@ -0,0 +1,525 @@
+#include "config.h"
+#include <Imlib2.h>
+#include "common.h"
+
+#include <stdio.h>
+
+#include "api.h"
+#include "blend.h"
+#include "image.h"
+#include "updates.h"
+
+#include "x11_color.h"
+#include "x11_grab.h"
+#include "x11_pixmap.h"
+#include "x11_rend.h"
+#include "x11_ximage.h"
+
+EAPI void
+imlib_context_set_display(Display * display)
+{
+   ctx->display = display;
+}
+
+EAPI Display       *
+imlib_context_get_display(void)
+{
+   return ctx->display;
+}
+
+EAPI void
+imlib_context_disconnect_display(void)
+{
+   if (!ctx->display)
+      return;
+   __imlib_RenderDisconnect(ctx->display);
+   ctx->display = NULL;
+}
+
+EAPI void
+imlib_context_set_visual(Visual * visual)
+{
+   ctx->visual = visual;
+   ctx->depth = imlib_get_visual_depth(ctx->display, ctx->visual);
+}
+
+EAPI Visual        *
+imlib_context_get_visual(void)
+{
+   return ctx->visual;
+}
+
+EAPI void
+imlib_context_set_colormap(Colormap colormap)
+{
+   ctx->colormap = colormap;
+}
+
+EAPI                Colormap
+imlib_context_get_colormap(void)
+{
+   return ctx->colormap;
+}
+
+EAPI void
+imlib_context_set_drawable(Drawable drawable)
+{
+   ctx->drawable = drawable;
+}
+
+EAPI                Drawable
+imlib_context_get_drawable(void)
+{
+   return ctx->drawable;
+}
+
+EAPI void
+imlib_context_set_mask(Pixmap mask)
+{
+   ctx->mask = mask;
+}
+
+EAPI                Pixmap
+imlib_context_get_mask(void)
+{
+   return ctx->mask;
+}
+
+EAPI void
+imlib_context_set_dither_mask(char dither_mask)
+{
+   ctx->dither_mask = dither_mask;
+}
+
+EAPI char
+imlib_context_get_dither_mask(void)
+{
+   return ctx->dither_mask;
+}
+
+EAPI void
+imlib_context_set_mask_alpha_threshold(int mask_alpha_threshold)
+{
+   ctx->mask_alpha_threshold = mask_alpha_threshold;
+}
+
+EAPI int
+imlib_context_get_mask_alpha_threshold(void)
+{
+   return ctx->mask_alpha_threshold;
+}
+
+EAPI int
+imlib_get_ximage_cache_count_used(void)
+{
+   return __imlib_GetXImageCacheCountUsed(ctx->display);
+}
+
+EAPI int
+imlib_get_ximage_cache_count_max(void)
+{
+   return __imlib_GetXImageCacheCountMax(ctx->display);
+}
+
+EAPI void
+imlib_set_ximage_cache_count_max(int count)
+{
+   __imlib_SetXImageCacheCountMax(ctx->display, count);
+}
+
+EAPI int
+imlib_get_ximage_cache_size_used(void)
+{
+   return __imlib_GetXImageCacheSizeUsed(ctx->display);
+}
+
+EAPI int
+imlib_get_ximage_cache_size_max(void)
+{
+   return __imlib_GetXImageCacheSizeMax(ctx->display);
+}
+
+EAPI void
+imlib_set_ximage_cache_size_max(int bytes)
+{
+   __imlib_SetXImageCacheSizeMax(ctx->display, bytes);
+}
+
+EAPI int
+imlib_get_color_usage(void)
+{
+   return (int)_max_colors;
+}
+
+EAPI void
+imlib_set_color_usage(int max)
+{
+   if (max < 2)
+      max = 2;
+   else if (max > 256)
+      max = 256;
+   _max_colors = max;
+}
+
+EAPI int
+imlib_get_visual_depth(Display * display, Visual * visual)
+{
+   CHECK_PARAM_POINTER_RETURN("display", display, 0);
+   CHECK_PARAM_POINTER_RETURN("visual", visual, 0);
+   return __imlib_XActualDepth(display, visual);
+}
+
+EAPI Visual        *
+imlib_get_best_visual(Display * display, int screen, int *depth_return)
+{
+   CHECK_PARAM_POINTER_RETURN("display", display, NULL);
+   CHECK_PARAM_POINTER_RETURN("depth_return", depth_return, NULL);
+   return __imlib_BestVisual(display, screen, depth_return);
+}
+
+EAPI void
+imlib_render_pixmaps_for_whole_image(Pixmap * pixmap_return,
+                                     Pixmap * mask_return)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CHECK_PARAM_POINTER("pixmap_return", pixmap_return);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
+                                 ctx->depth, ctx->colormap, im, pixmap_return,
+                                 mask_return, 0, 0, im->w, im->h, im->w,
+                                 im->h, 0, ctx->dither, ctx->dither_mask,
+                                 ctx->mask_alpha_threshold,
+                                 ctx->color_modifier);
+}
+
+EAPI void
+imlib_render_pixmaps_for_whole_image_at_size(Pixmap * pixmap_return,
+                                             Pixmap * mask_return, int width,
+                                             int height)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CHECK_PARAM_POINTER("pixmap_return", pixmap_return);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
+                                 ctx->depth, ctx->colormap, im, pixmap_return,
+                                 mask_return, 0, 0, im->w, im->h, width,
+                                 height, ctx->anti_alias, ctx->dither,
+                                 ctx->dither_mask, ctx->mask_alpha_threshold,
+                                 ctx->color_modifier);
+}
+
+EAPI void
+imlib_free_pixmap_and_mask(Pixmap pixmap)
+{
+   __imlib_FreePixmap(ctx->display, pixmap);
+}
+
+EAPI void
+imlib_render_image_on_drawable(int x, int y)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
+                       ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
+                       im->h, x, y, im->w, im->h, 0, ctx->dither, ctx->blend,
+                       ctx->dither_mask, ctx->mask_alpha_threshold,
+                       ctx->color_modifier, ctx->operation);
+}
+
+EAPI void
+imlib_render_image_on_drawable_at_size(int x, int y, int width, int height)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
+                       ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
+                       im->h, x, y, width, height, ctx->anti_alias,
+                       ctx->dither, ctx->blend, ctx->dither_mask,
+                       ctx->mask_alpha_threshold, ctx->color_modifier,
+                       ctx->operation);
+}
+
+EAPI void
+imlib_render_image_part_on_drawable_at_size(int source_x, int source_y,
+                                            int source_width,
+                                            int source_height, int x, int y,
+                                            int width, int height)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
+                       ctx->colormap, ctx->depth, source_x, source_y,
+                       source_width, source_height, x, y, width, height,
+                       ctx->anti_alias, ctx->dither, ctx->blend, 0,
+                       0, ctx->color_modifier, ctx->operation);
+}
+
+EAPI                uint32_t
+imlib_render_get_pixel_color(void)
+{
+   return __imlib_RenderGetPixel(ctx->display, ctx->drawable, ctx->visual,
+                                 ctx->colormap, ctx->depth,
+                                 (uint8_t) ctx->color.red,
+                                 (uint8_t) ctx->color.green,
+                                 (uint8_t) ctx->color.blue);
+}
+
+EAPI                Imlib_Image
+imlib_create_image_from_drawable(Pixmap mask, int x, int y, int width,
+                                 int height, char need_to_grab_x)
+{
+   ImlibImage         *im;
+   char                domask = 0;
+
+   if (!IMAGE_DIMENSIONS_OK(width, height))
+      return NULL;
+   if (mask)
+     {
+        domask = 1;
+        if (mask == (Pixmap) 1)
+           mask = None;
+     }
+   im = __imlib_CreateImage(width, height, NULL);
+   if (!im)
+      return NULL;
+   im->data = "" * height * sizeof(uint32_t));
+   if (im->data &&
+       __imlib_GrabDrawableToRGBA(im->data, 0, 0, width, height, ctx->display,
+                                  ctx->drawable, mask, ctx->visual,
+                                  ctx->colormap, ctx->depth, x, y, width,
+                                  height, &domask, need_to_grab_x))
+     {
+        im->has_alpha = domask;
+     }
+   else
+     {
+        __imlib_FreeImage(im);
+        im = NULL;
+     }
+
+   return im;
+}
+
+EAPI                Imlib_Image
+imlib_create_image_from_ximage(XImage * image, XImage * mask, int x, int y,
+                               int width, int height, char need_to_grab_x)
+{
+   ImlibImage         *im;
+
+   if (!IMAGE_DIMENSIONS_OK(width, height))
+      return NULL;
+   im = __imlib_CreateImage(width, height, NULL);
+   if (!im)
+      return NULL;
+   im->data = "" * height * sizeof(uint32_t));
+   if (!im->data)
+     {
+        __imlib_FreeImage(im);
+        return NULL;
+     }
+   __imlib_GrabXImageToRGBA(im->data, 0, 0, width, height,
+                            ctx->display, image, mask, ctx->visual,
+                            ctx->depth, x, y, width, height, need_to_grab_x);
+   return im;
+}
+
+EAPI                Imlib_Image
+imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x,
+                                        int source_y, int source_width,
+                                        int source_height,
+                                        int destination_width,
+                                        int destination_height,
+                                        char need_to_grab_x,
+                                        char get_mask_from_shape)
+{
+   ImlibImage         *im;
+   char                domask;
+
+   if (!IMAGE_DIMENSIONS_OK(source_width, source_height))
+      return NULL;
+   if (!IMAGE_DIMENSIONS_OK(destination_width, destination_height))
+      return NULL;
+
+   domask = mask != 0 || get_mask_from_shape;
+
+   im = __imlib_CreateImage(destination_width, destination_height, NULL);
+   if (!im)
+      return NULL;
+   im->data = "" * destination_height * sizeof(uint32_t));
+   if (!im->data)
+     {
+        __imlib_FreeImage(im);
+        return NULL;
+     }
+
+   __imlib_GrabDrawableScaledToRGBA(im->data, 0, 0,
+                                    destination_width, destination_height,
+                                    ctx->display, ctx->drawable, mask,
+                                    ctx->visual, ctx->colormap, ctx->depth,
+                                    source_x, source_y,
+                                    source_width, source_height,
+                                    &domask, need_to_grab_x);
+
+   im->has_alpha = domask;
+
+   return im;
+}
+
+EAPI char
+imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int width, int height,
+                             int destination_x, int destination_y,
+                             char need_to_grab_x)
+{
+   ImlibImage         *im;
+   char                domask = 0;
+   int                 pre_adj;
+
+   CHECK_PARAM_POINTER_RETURN("image", ctx->image, 0);
+   if (mask)
+     {
+        domask = 1;
+        if (mask == (Pixmap) 1)
+           mask = None;
+     }
+   CAST_IMAGE(im, ctx->image);
+
+   if (__imlib_LoadImageData(im))
+      return 0;
+
+   pre_adj = 0;
+   if (x < 0)
+     {
+        width += x;
+        pre_adj = x;
+        x = 0;
+     }
+   if (width < 0)
+      width = 0;
+   if (destination_x < 0)
+     {
+        width += destination_x;
+        x -= destination_x - pre_adj;
+        destination_x = 0;
+     }
+   if ((destination_x + width) >= im->w)
+      width = im->w - destination_x;
+
+   pre_adj = 0;
+   if (y < 0)
+     {
+        height += y;
+        pre_adj = y;
+        y = 0;
+     }
+   if (height < 0)
+      height = 0;
+   if (destination_y < 0)
+     {
+        height += destination_y;
+        y -= destination_y - pre_adj;
+        destination_y = 0;
+     }
+   if ((destination_y + height) >= im->h)
+      height = im->h - destination_y;
+
+   if ((width <= 0) || (height <= 0))
+      return 0;
+   __imlib_DirtyImage(im);
+   return __imlib_GrabDrawableToRGBA(im->data, destination_x, destination_y,
+                                     im->w, im->h, ctx->display,
+                                     ctx->drawable, mask, ctx->visual,
+                                     ctx->colormap, ctx->depth, x, y, width,
+                                     height, &domask, need_to_grab_x);
+}
+
+EAPI void
+imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y)
+{
+   ImlibUpdate        *u;
+   ImlibImage         *im;
+   int                 ximcs;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   u = (ImlibUpdate *) updates;
+   if (!updates)
+      return;
+   if (__imlib_LoadImageData(im))
+      return;
+   ximcs = __imlib_GetXImageCacheCountMax(ctx->display);        /* Save */
+   if (ximcs == 0)              /* Only if we don't set this up elsewhere */
+      __imlib_SetXImageCacheCountMax(ctx->display, 10);
+   for (; u; u = u->next)
+     {
+        __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
+                            ctx->colormap, ctx->depth, u->x, u->y, u->w, u->h,
+                            x + u->x, y + u->y, u->w, u->h, 0, ctx->dither, 0,
+                            0, 0, ctx->color_modifier, OP_COPY);
+     }
+   if (ximcs == 0)
+      __imlib_SetXImageCacheCountMax(ctx->display, ximcs);
+}
+
+EAPI void
+imlib_render_image_on_drawable_skewed(int source_x, int source_y,
+                                      int source_width, int source_height,
+                                      int destination_x, int destination_y,
+                                      int h_angle_x, int h_angle_y,
+                                      int v_angle_x, int v_angle_y)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
+                             ctx->visual, ctx->colormap, ctx->depth, source_x,
+                             source_y, source_width, source_height,
+                             destination_x, destination_y, h_angle_x,
+                             h_angle_y, v_angle_x, v_angle_y, ctx->anti_alias,
+                             ctx->dither, ctx->blend, ctx->dither_mask,
+                             ctx->mask_alpha_threshold, ctx->color_modifier,
+                             ctx->operation);
+}
+
+EAPI void
+imlib_render_image_on_drawable_at_angle(int source_x, int source_y,
+                                        int source_width, int source_height,
+                                        int destination_x, int destination_y,
+                                        int angle_x, int angle_y)
+{
+   ImlibImage         *im;
+
+   CHECK_PARAM_POINTER("image", ctx->image);
+   CAST_IMAGE(im, ctx->image);
+   if (__imlib_LoadImageData(im))
+      return;
+   __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
+                             ctx->visual, ctx->colormap, ctx->depth, source_x,
+                             source_y, source_width, source_height,
+                             destination_x, destination_y, angle_x, angle_y,
+                             0, 0, ctx->anti_alias, ctx->dither, ctx->blend,
+                             ctx->dither_mask, ctx->mask_alpha_threshold,
+                             ctx->color_modifier, ctx->operation);
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to