]> git.imager.perl.org - imager.git/commitdiff
WIP, OMG it works
authorTony Cook <tony@develop-help.com>
Sun, 10 Jun 2012 14:03:53 +0000 (00:03 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 24 Nov 2012 03:59:15 +0000 (14:59 +1100)
Imager.xs
context.c
imager.h
imext.h
immacros.h

index f2e13576505630a68fd2c18a1f038591a27b3d28..bc9507208a51504bd39085f62ff577d28371a7f9 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -29,6 +29,13 @@ extern "C" {
 
 #include "imperl.h"
 
+static im_context_t work_context;
+
+static im_context_t
+perl_get_context(void) {
+  return work_context;
+}
+
 /* used to represent channel lists parameters */
 typedef struct i_channel_list_tag {
   int *channels;
@@ -3996,3 +4003,5 @@ i_int_hlines_CLONE_SKIP(cls)
 BOOT:
         PERL_SET_GLOBAL_CALLBACKS;
        PERL_PL_SET_GLOBAL_CALLBACKS;
+       work_context = im_context_new();
+       im_get_context = perl_get_context;
index 8845722b70ca0dd7522bf0740aa4140526cbb6c3..9967c66b683bc312ed870b863291e7ee8e12b7c6 100644 (file)
--- a/context.c
+++ b/context.c
@@ -10,9 +10,12 @@ Create a new Imager context object.
 
 im_context_t
 im_context_new(void) {
-  im_context_t ctx = mymalloc(sizeof(im_context_struct));
+  im_context_t ctx = malloc(sizeof(im_context_struct));
   int i;
 
+  if (!ctx)
+    return NULL;
+  
   ctx->error_sp = IM_ERROR_COUNT-1;
   for (i = 0; i < IM_ERROR_COUNT; ++i) {
     ctx->error_alloc[i] = 0;
@@ -25,7 +28,7 @@ im_context_new(void) {
 #endif
   ctx->max_width = 0;
   ctx->max_height = 0;
-  ctx->max_bytes = 0;
+  ctx->max_bytes = DEF_BYTES_LIMIT;
 
   return ctx;
 }
@@ -50,6 +53,8 @@ im_context_delete(im_context_t ctx) {
   if (ctx->lg_file)
     fclose(ctx->lg_file);
 #endif
+
+  free(ctx);
 }
 
 /*
@@ -62,9 +67,12 @@ Clone an Imager context object, returning the result.
 
 im_context_t
 im_context_clone(im_context_t ctx) {
-  im_context_t nctx = mymalloc(sizeof(im_context_struct));
+  im_context_t nctx = malloc(sizeof(im_context_struct));
   int i;
 
+  if (!nctx)
+    return NULL;
+
   nctx->error_sp = ctx->error_sp;
   for (i = 0; i < IM_ERROR_COUNT; ++i) {
     if (ctx->error_stack[i].msg) {
index 0260d2452b9fa2d244e5d5116dcc277feff83504..cb38a145eddf3e9327d8ae9260e40de763e66613 100644 (file)
--- a/imager.h
+++ b/imager.h
@@ -71,74 +71,36 @@ i_img_dim i_img_get_height(i_img *im);
 
 /* Base functions */
 
-extern int i_ppix(i_img *im,i_img_dim x,i_img_dim y, const i_color *val);
-extern int i_gpix(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
-extern int i_ppixf(i_img *im,i_img_dim x,i_img_dim y, const i_fcolor *val);
-extern int i_gpixf(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val);
-
-#define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
-#define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
-#define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val)))
-#define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val)))
-
-extern i_img_dim i_plin(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_color *vals);
-extern i_img_dim i_glin(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_color *vals);
-extern i_img_dim i_plinf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, const i_fcolor *vals);
-extern i_img_dim i_glinf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fcolor *vals);
-extern i_img_dim i_gsamp(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_sample_t *samp, 
-                   const int *chans, int chan_count);
-extern i_img_dim i_gsampf(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp, 
-                   const int *chans, int chan_count);
-extern i_img_dim i_gpal(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
-extern i_img_dim i_ppal(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
-extern int i_addcolors(i_img *im, const i_color *colors, int count);
-extern int i_getcolors(i_img *im, int i, i_color *, int count);
-extern int i_colorcount(i_img *im);
-extern int i_maxcolors(i_img *im);
-extern int i_findcolor(i_img *im, const i_color *color, i_palidx *entry);
-extern int i_setcolors(i_img *im, int index, const i_color *colors, 
+extern int (i_ppix)(i_img *im,i_img_dim x,i_img_dim y, const i_color *val);
+extern int (i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
+extern int (i_ppixf)(i_img *im,i_img_dim x,i_img_dim y, const i_fcolor *val);
+extern int (i_gpixf)(i_img *im,i_img_dim x,i_img_dim y,i_fcolor *val);
+
+extern i_img_dim (i_plin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
+                         const i_color *vals);
+extern i_img_dim (i_glin)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
+                         i_color *vals);
+extern i_img_dim (i_plinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
+                          const i_fcolor *vals);
+extern i_img_dim (i_glinf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, 
+                          i_fcolor *vals);
+extern i_img_dim (i_gsamp)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y,
+                          i_sample_t *samp, const int *chans, int chan_count);
+extern i_img_dim
+(i_gsampf)(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samp,
+          const int *chans, int chan_count);
+extern i_img_dim
+(i_gpal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, i_palidx *vals);
+extern i_img_dim
+(i_ppal)(i_img *im, i_img_dim x, i_img_dim r, i_img_dim y, const i_palidx *vals);
+extern int (i_addcolors)(i_img *im, const i_color *colors, int count);
+extern int (i_getcolors)(i_img *im, int i, i_color *, int count);
+extern int (i_colorcount)(i_img *im);
+extern int (i_maxcolors)(i_img *im);
+extern int (i_findcolor)(i_img *im, const i_color *color, i_palidx *entry);
+extern int (i_setcolors)(i_img *im, int index, const i_color *colors, 
                        int count);
 
-#define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
-#define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
-#define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
-#define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
-
-#define i_gsamp(im, l, r, y, samps, chans, count) \
-  (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
-#define i_gsampf(im, l, r, y, samps, chans, count) \
-  (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
-
-#define i_gsamp_bits(im, l, r, y, samps, chans, count, bits) \
-  (((im)->i_f_gsamp_bits) ? ((im)->i_f_gsamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
-#define i_psamp_bits(im, l, r, y, samps, chans, count, bits) \
-  (((im)->i_f_psamp_bits) ? ((im)->i_f_psamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
-
-#define i_findcolor(im, color, entry) \
-  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
-
-#define i_gpal(im, l, r, y, vals) \
-  (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
-#define i_ppal(im, l, r, y, vals) \
-  (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
-#define i_addcolors(im, colors, count) \
-  (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
-#define i_getcolors(im, index, color, count) \
-  (((im)->i_f_getcolors) ? \
-   ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
-#define i_setcolors(im, index, color, count) \
-  (((im)->i_f_setcolors) ? \
-   ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
-#define i_colorcount(im) \
-  (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
-#define i_maxcolors(im) \
-  (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
-#define i_findcolor(im, color, entry) \
-  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
-
-#define i_img_virtual(im) ((im)->virtual)
-#define i_img_type(im) ((im)->type)
-#define i_img_bits(im) ((im)->bits)
 
 extern i_fill_t *i_new_fill_solidf(const i_fcolor *c, int combine);
 extern i_fill_t *i_new_fill_solid(const i_color *c, int combine);
@@ -419,6 +381,11 @@ extern int
 i_gsampf_bg(i_img *im, i_img_dim l, i_img_dim r, i_img_dim y, i_fsample_t *samples, 
           int out_channels, i_fcolor const *bg);
 
+/* context object management */
+extern im_context_t im_context_new(void);
+extern void im_context_delete(im_context_t ctx);
+extern im_context_t im_context_clone(im_context_t ctx);
+
 extern im_context_t (*im_get_context)(void);
 
 #include "imio.h"
diff --git a/imext.h b/imext.h
index 2bb7a70bddf3e230c98d223f909bffef520372a9..c0f57ed17b1793bc57d7f2a4ce948516b84a1800 100644 (file)
--- a/imext.h
+++ b/imext.h
@@ -60,43 +60,8 @@ extern im_ext_funcs *imager_function_ext_table;
 #define IMAGER_DIRECT_IMAGE_CALLS 1
 #endif
 
-#if IMAGER_DIRECT_IMAGE_CALLS
-#define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
-#define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
-#define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val)))
-#define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val)))
-#define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
-#define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
-#define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
-#define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
+#if !IMAGER_DIRECT_IMAGE_CALLS
 
-#define i_gsamp(im, l, r, y, samps, chans, count) \
-  (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
-#define i_gsampf(im, l, r, y, samps, chans, count) \
-  (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
-
-#define i_findcolor(im, color, entry) \
-  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
-
-#define i_gpal(im, l, r, y, vals) \
-  (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
-#define i_ppal(im, l, r, y, vals) \
-  (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
-#define i_addcolors(im, colors, count) \
-  (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
-#define i_getcolors(im, index, color, count) \
-  (((im)->i_f_getcolors) ? \
-   ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
-#define i_setcolors(im, index, color, count) \
-  (((im)->i_f_setcolors) ? \
-   ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
-#define i_colorcount(im) \
-  (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
-#define i_maxcolors(im) \
-  (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
-#define i_findcolor(im, color, entry) \
-  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
-#else
 #define i_ppix(im, x, y, val) ((im_extt->f_i_ppix)((im), (x), (y), (val)))
 #define i_gpix(im, x, y, val) ((im_extt->f_i_gpix)((im), (x), (y), (val)))
 #define i_ppixf(im, x, y, val) ((im_extt->f_i_ppixf)((im), (x), (y), (val)))
index e970f9045da54912052e067d7672ef669012e21f..6d7cc75bea30d307feb1031d0f7be3fb1be565b2 100644 (file)
@@ -75,6 +75,59 @@ returns -1 and pushes an error.
 #define i_psampf(im, l, r, y, samps, chans, count) \
   (((im)->i_f_psampf)((im), (l), (r), (y), (samps), (chans), (count)))
 
+#ifndef IMAGER_DIRECT_IMAGE_CALLS
+#define IMAGER_DIRECT_IMAGE_CALLS 1
+#endif
+
+#if IMAGER_DIRECT_IMAGE_CALLS
+
+#define i_ppix(im, x, y, val) (((im)->i_f_ppix)((im), (x), (y), (val)))
+#define i_gpix(im, x, y, val) (((im)->i_f_gpix)((im), (x), (y), (val)))
+#define i_ppixf(im, x, y, val) (((im)->i_f_ppixf)((im), (x), (y), (val)))
+#define i_gpixf(im, x, y, val) (((im)->i_f_gpixf)((im), (x), (y), (val)))
+#define i_plin(im, l, r, y, val) (((im)->i_f_plin)(im, l, r, y, val))
+#define i_glin(im, l, r, y, val) (((im)->i_f_glin)(im, l, r, y, val))
+#define i_plinf(im, l, r, y, val) (((im)->i_f_plinf)(im, l, r, y, val))
+#define i_glinf(im, l, r, y, val) (((im)->i_f_glinf)(im, l, r, y, val))
+
+#define i_gsamp(im, l, r, y, samps, chans, count) \
+  (((im)->i_f_gsamp)((im), (l), (r), (y), (samps), (chans), (count)))
+#define i_gsampf(im, l, r, y, samps, chans, count) \
+  (((im)->i_f_gsampf)((im), (l), (r), (y), (samps), (chans), (count)))
+
+#endif
+
+#define i_gsamp_bits(im, l, r, y, samps, chans, count, bits) \
+       (((im)->i_f_gsamp_bits) ? ((im)->i_f_gsamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
+#define i_psamp_bits(im, l, r, y, samps, chans, count, bits) \
+       (((im)->i_f_psamp_bits) ? ((im)->i_f_psamp_bits)((im), (l), (r), (y), (samps), (chans), (count), (bits)) : -1)
+
+#define i_findcolor(im, color, entry) \
+  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
+
+#define i_gpal(im, l, r, y, vals) \
+  (((im)->i_f_gpal) ? ((im)->i_f_gpal)((im), (l), (r), (y), (vals)) : 0)
+#define i_ppal(im, l, r, y, vals) \
+  (((im)->i_f_ppal) ? ((im)->i_f_ppal)((im), (l), (r), (y), (vals)) : 0)
+#define i_addcolors(im, colors, count) \
+  (((im)->i_f_addcolors) ? ((im)->i_f_addcolors)((im), (colors), (count)) : -1)
+#define i_getcolors(im, index, color, count) \
+  (((im)->i_f_getcolors) ? \
+   ((im)->i_f_getcolors)((im), (index), (color), (count)) : 0)
+#define i_setcolors(im, index, color, count) \
+  (((im)->i_f_setcolors) ? \
+   ((im)->i_f_setcolors)((im), (index), (color), (count)) : 0)
+#define i_colorcount(im) \
+  (((im)->i_f_colorcount) ? ((im)->i_f_colorcount)(im) : -1)
+#define i_maxcolors(im) \
+  (((im)->i_f_maxcolors) ? ((im)->i_f_maxcolors)(im) : -1)
+#define i_findcolor(im, color, entry) \
+  (((im)->i_f_findcolor) ? ((im)->i_f_findcolor)((im), (color), (entry)) : 0)
+
+#define i_img_virtual(im) ((im)->virtual)
+#define i_img_type(im) ((im)->type)
+#define i_img_bits(im) ((im)->bits)
+
 #ifdef IMAGER_NO_CONTEXT
 #define dIMCTX im_context_t my_im_ctx = im_get_context()
 #define dIMCTXa(a) im_context_t my_im_ctx = im_get_context()