]> git.imager.perl.org - imager.git/commitdiff
WIP, it compiles
authorTony Cook <tony@develop-help.com>
Mon, 6 Aug 2012 13:39:12 +0000 (23:39 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 24 Nov 2012 03:59:15 +0000 (14:59 +1100)
17 files changed:
context.c
dynaload.c
error.c
ext.h
image.c
imager.h
imageri.h
imerror.h
imext.c
imext.h
imexttypes.h
immacros.h
lib/Imager/APIRef.pod
limits.c
log.c
log.h
plug.h

index f4e7e2ac2a9a09da173332d9e5babaddda5952a3..8845722b70ca0dd7522bf0740aa4140526cbb6c3 100644 (file)
--- a/context.c
+++ b/context.c
@@ -23,6 +23,9 @@ im_context_new(void) {
   ctx->log_level = 0;
   ctx->lg_file = NULL;
 #endif
+  ctx->max_width = 0;
+  ctx->max_height = 0;
+  ctx->max_bytes = 0;
 
   return ctx;
 }
@@ -88,9 +91,12 @@ im_context_clone(im_context_t ctx) {
       setvbuf(nctx->lg_file, NULL, _IONBF, 0);
   }
   else {
-    ctx->lg_file = NULL;
+    nctx->lg_file = NULL;
   }
 #endif
+  nctx->max_width = ctx->max_width;
+  nctx->max_height = ctx->max_height;
+  nctx->max_bytes = ctx->max_bytes;
 
   return ctx;
 }
index 8a12de25e9ea7d59866ee84368091c73972abfb8..faa605daa68b2cee038fa38a7472d6b40c40a0f0 100644 (file)
@@ -35,7 +35,6 @@ static symbol_table_t symbol_table=
     ICL_set_internal,
     ICL_info,
     do_get_context,
-    i_img_empty,
     im_img_empty_ch,
     i_img_exorcise,
     i_img_info,
diff --git a/error.c b/error.c
index a5f97b87d5339fac3da05a50f3c2492502403425..4b3faf2c9918d2fafdba2bd5e09b0027efc924d0 100644 (file)
--- a/error.c
+++ b/error.c
@@ -281,7 +281,7 @@ im_push_errorvf(im_context_t ctx, int code, char const *fmt, va_list ap) {
 }
 
 void
-i_push_errorvf(int code, char const *fmt, va_list ap) {
+(i_push_errorvf)(int code, char const *fmt, va_list ap) {
   im_push_errorvf(im_get_context(), code, fmt, ap);
 }
 
diff --git a/ext.h b/ext.h
index 190ff76b094b1fb00d11242ddd68ea82704d8f13..9a25820ae280a6c5fa4036a691094ccf657b276b 100644 (file)
--- a/ext.h
+++ b/ext.h
@@ -26,14 +26,13 @@ typedef struct {
   void (*ICL_info)(const i_color *cl);
 
   im_context_t (*im_get_context_f)(void);
-  i_img*(*i_img_empty_f)(i_img *im,i_img_dim x,i_img_dim y);
   i_img*(*im_img_empty_ch_f)(im_context_t, i_img *im,i_img_dim x,i_img_dim y,int ch);
   void(*i_img_exorcise_f)(i_img *im);
 
   void(*i_img_info_f)(i_img *im,i_img_dim *info);
   
-  void(*i_img_setmask)(i_img *im,int ch_mask);
-  int (*i_img_getmask)(i_img *im);
+  void(*i_img_setmask_f)(i_img *im,int ch_mask);
+  int (*i_img_getmask_f)(i_img *im);
   
   /*
   int (*i_ppix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
diff --git a/image.c b/image.c
index 6a4fc8ddae18d5acc0b9391ca84d54fd18db4a4e..5c602d75c80ea2ea4df9254e612b7fc54de3646f 100644 (file)
--- a/image.c
+++ b/image.c
@@ -32,6 +32,8 @@ Some of these functions are internal.
 =cut
 */
 
+im_context_t (*im_get_context)(void) = NULL;
+
 #define XAXIS 0
 #define YAXIS 1
 #define XYAXIS 2
index 8246e4f2dfe3035d4e16d20d7b9bcf413b839378..0260d2452b9fa2d244e5d5116dcc277feff83504 100644 (file)
--- a/imager.h
+++ b/imager.h
@@ -48,16 +48,13 @@ extern void i_rgb_to_hsv(i_color *color);
 extern void i_hsv_to_rgb(i_color *color);
 
 i_img *im_img_8_new(pIMCTX, i_img_dim x,i_img_dim y,int ch);
-#define i_img_8_new(x,y,ch) im_img_8_new(aIMCTX, x,y,ch)
-i_img *i_img_empty(i_img *im,i_img_dim x,i_img_dim y);
+#define i_img_empty(im, x, y) i_img_empty_ch((im), (x), (y), 3)
 i_img *im_img_empty_ch(pIMCTX, i_img *im,i_img_dim x,i_img_dim y,int ch);
-#define i_img_empty_ch(im, x, y, ch) im_img_empty_ch(aIMCTX, im, x, y, ch)
+#define i_img_empty_ch(im, x, y, ch) im_img_empty_ch(aIMCTX, (im), (x), (y), (ch))
 void   i_img_exorcise(i_img *im);
 void   i_img_destroy(i_img *im);
 i_img *im_img_alloc(pIMCTX);
-#define i_img_alloc() im_img_alloc(aIMCTX)
 void im_img_init(pIMCTX, i_img *im);
-#define i_img_init(im) im_img_init(aIMCTX, im)
 
 void   i_img_info(i_img *im,i_img_dim *info);
 
@@ -248,17 +245,14 @@ extern i_palidx *i_quant_translate(i_quantize *quant, i_img *img);
 extern void i_quant_transparent(i_quantize *quant, i_palidx *indices, i_img *img, i_palidx trans_index);
 
 i_img *im_img_pal_new(pIMCTX, i_img_dim x, i_img_dim y, int ch, int maxpal);
-#define i_img_pal_new(x, y, ch, maxpal) im_img_pal_new(aIMCTX, x, y, ch, maxpal)
 
 extern i_img *i_img_to_pal(i_img *src, i_quantize *quant);
 extern i_img *i_img_to_rgb(i_img *src);
 extern i_img *i_img_masked_new(i_img *targ, i_img *mask, i_img_dim x, i_img_dim y, 
                                i_img_dim w, i_img_dim h);
 extern i_img *im_img_16_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
-#define i_img_16_new(x, y, ch) im_img_16_new(aIMCTX, x, y, ch)
 extern i_img *i_img_to_rgb16(i_img *im);
 extern i_img *im_img_double_new(pIMCTX, i_img_dim x, i_img_dim y, int ch);
-#define i_img_double_new(x, y, ch) im_img_double_new(aIMCTX, x, y, ch)
 extern i_img *i_img_to_drgb(i_img *im);
 
 extern int i_img_is_monochrome(i_img *im, int *zero_is_white);
@@ -372,11 +366,11 @@ extern void i_tags_print(i_img_tags *tags);
 
 /* image file limits */
 extern int
-i_set_image_file_limits(i_img_dim width, i_img_dim height, size_t bytes);
+im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes);
 extern int
-i_get_image_file_limits(i_img_dim *width, i_img_dim *height, size_t *bytes);
+im_get_image_file_limits(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes);
 extern int
-i_int_check_image_file_limits(i_img_dim width, i_img_dim height, int channels, size_t sample_size);
+im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size);
 
 /* memory allocation */
 void* mymalloc(size_t size);
index 34817ed10628f6599f203b1e682f370369684c7a..c563c458c253807490a220ec08e482aefa1468e1 100644 (file)
--- a/imageri.h
+++ b/imageri.h
@@ -122,6 +122,12 @@ typedef struct im_context_tag {
   const char *filename;
   int line;
 #endif
+
+  /* file size limits */
+  i_img_dim max_width, max_height;
+  size_t max_bytes;
 } im_context_struct;
 
+#define DEF_BYTES_LIMIT 0x40000000
+
 #endif
index b51600ec21e0f61ca7753cd01f0869508e56158d..e4a73189fae5c2a0a2e79b14299e64a2099af8e8 100644 (file)
--- a/imerror.h
+++ b/imerror.h
@@ -19,12 +19,10 @@ extern int i_set_errors_fatal(int new_fatal);
 extern i_errmsg *i_errors(void);
 
 extern void im_push_error(pIMCTX, int code, char const *msg);
-#define i_push_error(code, msg) im_push_error(aIMCTX, code, msg)
 extern void i_push_errorf(int code, char const *fmt, ...) I_FORMAT_ATTR(2, 3);
 extern void im_push_errorf(pIMCTX, int code, char const *fmt, ...) I_FORMAT_ATTR(3, 4);
-extern void i_push_errorvf(int code, char const *fmt, va_list);
+extern void im_push_errorvf(im_context_t ctx, int code, char const *fmt, va_list);
 extern void im_clear_error(pIMCTX);
-#define i_clear_error() im_clear_error(aIMCTX);
 extern int i_failed(int code, char const *msg);
 
 #endif
diff --git a/imext.c b/imext.c
index 6afaadd40dfe62ab75f97a62dc65d4aff448bc58..4f337958cab16e562490fa1c786a4d5a49b5a568 100644 (file)
--- a/imext.c
+++ b/imext.c
@@ -2,6 +2,8 @@
 #include "imager.h"
 #include "imio.h"
 
+static im_context_t get_context(void);
+
 /*
  DON'T ADD CASTS TO THESE
 */
@@ -18,10 +20,10 @@ im_ext_funcs imager_function_table =
     myfree_file_line,
     myrealloc_file_line,
 
-    i_img_8_new,
-    i_img_16_new,
-    i_img_double_new,
-    i_img_pal_new,
+    im_img_8_new,
+    im_img_16_new,
+    im_img_double_new,
+    im_img_pal_new,
     i_img_destroy,
     i_sametype,
     i_sametype_chans,
@@ -58,10 +60,10 @@ im_ext_funcs imager_function_table =
     i_quant_translate,
     i_quant_transparent,
 
-    i_clear_error,
-    i_push_error,
+    im_clear_error,
+    im_push_error,
     i_push_errorf,
-    i_push_errorvf,
+    im_push_errorvf,
 
     i_tags_new,
     i_tags_set,
@@ -99,9 +101,9 @@ im_ext_funcs imager_function_table =
     i_rubthru,
 
     /* IMAGER_API_LEVEL 2 functions */
-    i_set_image_file_limits,
-    i_get_image_file_limits,
-    i_int_check_image_file_limits,
+    im_set_image_file_limits,
+    im_get_image_file_limits,
+    im_int_check_image_file_limits,
 
     i_flood_fill_border,
     i_flood_cfill_border,
@@ -116,8 +118,8 @@ im_ext_funcs imager_function_table =
     i_loog,
 
     /* IMAGER_API_LEVEL 4 functions */
-    i_img_alloc,
-    i_img_init,
+    im_img_alloc,
+    im_img_init,
 
     /* IMAGER_API_LEVEL 5 functions */
     i_img_is_monochrome,
@@ -150,7 +152,9 @@ im_ext_funcs imager_function_table =
     io_new_buffer,
     io_new_cb,
     io_slurp,
-    io_glue_destroy
+    io_glue_destroy,
+
+    get_context
   };
 
 /* in general these functions aren't called by Imager internally, but
@@ -550,3 +554,20 @@ int
   return i_setcolors(im, index, colors, count);
 }
 
+/*
+=item im_get_context()
+
+Retrieve the context object for the current thread.
+
+Inside Imager itself this is just a function pointer, which the
+Imager.xs BOOT handler initializes for use within perl.  If you're
+taking the Imager code and embedding it elsewhere you need to
+initialize the C<im_get_context> pointer at some point.
+
+=cut
+*/
+
+static im_context_t
+get_context(void) {
+  return im_get_context();
+}
diff --git a/imext.h b/imext.h
index 1e4bccb63533a176070130917f7a707bacb7aad8..2bb7a70bddf3e230c98d223f909bffef520372a9 100644 (file)
--- a/imext.h
+++ b/imext.h
@@ -30,6 +30,8 @@ extern im_ext_funcs *imager_function_ext_table;
 /* just for use here */
 #define im_extt imager_function_ext_table
 
+#define im_get_context() ((im_extt->f_im_get_context)())
+
 #ifdef IMAGER_DEBUG_MALLOC
 
 #define mymalloc(size) ((im_extt->f_mymalloc_file_line)((size), __FILE__, __LINE__))
@@ -44,10 +46,10 @@ extern im_ext_funcs *imager_function_ext_table;
 
 #endif
 
-#define i_img_8_new(xsize, ysize, channels) ((im_extt->f_i_img_8_new)((xsize), (ysize), (channels)))
-#define i_img_16_new(xsize, ysize, channels) ((im_extt->f_i_img_16_new)((xsize), (ysize), (channels)))
-#define i_img_double_new(xsize, ysize, channels) ((im_extt->f_i_img_double_new)((xsize), (ysize), (channels)))
-#define i_img_pal_new(xsize, ysize, channels, maxpal) ((im_extt->f_i_img_pal_new)((xsize), (ysize), (channels), (maxpal)))
+#define im_img_8_new(ctx, xsize, ysize, channels) ((im_extt->f_im_img_8_new)((ctx), (xsize), (ysize), (channels)))
+#define im_img_16_new(ctx, xsize, ysize, channels) ((im_extt->f_im_img_16_new)((ctx), (xsize), (ysize), (channels)))
+#define im_img_double_new(ctx, xsize, ysize, channels) ((im_extt->f_im_img_double_new)((ctx), (xsize), (ysize), (channels)))
+#define im_img_pal_new(ctx, xsize, ysize, channels, maxpal) ((im_extt->f_im_img_pal_new)((ctx), (xsize), (ysize), (channels), (maxpal)))
 
 #define i_img_destroy(im) ((im_extt->f_i_img_destroy)(im))
 #define i_sametype(im, xsize, ysize) ((im_extt->f_i_sametype)((im), (xsize), (ysize)))
@@ -134,11 +136,11 @@ extern im_ext_funcs *imager_function_ext_table;
 #define i_quant_transparent(quant, indices, img, trans_index) \
   ((im_extt->f_i_quant_transparent)((quant), (indices), (img), (trans_index)))
 
-#define i_clear_error() ((im_extt->f_i_clear_error)())
-#define i_push_error(code, msg) ((im_extt->f_i_push_error)((code), (msg)))
+#define im_clear_error(ctx) ((im_extt->f_im_clear_error)(ctx))
+#define im_push_error(ctx, code, msg) ((im_extt->f_im_push_error)((ctx), (code), (msg)))
 #define i_push_errorf (im_extt->f_i_push_errorf)
-#define i_push_errorvf(code, fmt, list) \
-  ((im_extt->f_i_push_errorvf)((code), (fmt), (list)))
+#define im_push_errorvf(ctx, code, fmt, list)          \
+  ((im_extt->f_im_push_errorvf)((ctx), (code), (fmt), (list)))
 
 #define i_tags_new(tags) ((im_extt->f_i_tags_new)(tags))
 #define i_tags_set(tags, name, data, size) \
@@ -194,12 +196,12 @@ extern im_ext_funcs *imager_function_ext_table;
 #define i_rubthru(im, src, tx, ty, src_minx, src_miny, src_maxx, src_maxy) \
   ((im_extt->f_i_rubthru)((im), (src), (tx), (ty), (src_minx), (src_miny), (src_maxx), (src_maxy)))
 
-#define i_set_image_file_limits(max_width, max_height, max_bytes) \
-  ((im_extt->f_i_set_image_file_limits)((max_width), (max_height), (max_bytes)))
-#define i_get_image_file_limits(pmax_width, pmax_height, pmax_bytes) \
-  ((im_extt->f_i_get_image_file_limits)((pmax_width), (pmax_height), (pmax_bytes)))
-#define i_int_check_image_file_limits(width, height, channels, sample_size) \
-  ((im_extt->f_i_int_check_image_file_limits)((width), (height), (channels), (sample_size)))
+#define im_set_image_file_limits(ctx, max_width, max_height, max_bytes)        \
+  ((im_extt->f_im_set_image_file_limits)((max_width), (max_height), (max_bytes)))
+#define im_get_image_file_limits(ctx, pmax_width, pmax_height, pmax_bytes) \
+  ((im_extt->f_im_get_image_file_limits)((ctx), (pmax_width), (pmax_height), (pmax_bytes)))
+#define im_int_check_image_file_limits(ctx, width, height, channels, sample_size) \
+  ((im_extt->f_im_int_check_image_file_limits)((ctx), (width), (height), (channels), (sample_size)))
 
 #define i_img_setmask(img, mask) ((im_extt->f_i_img_setmask)((img), (mask)))
 #define i_img_getmask(img) ((im_extt->f_i_img_getmask)(img))
@@ -209,8 +211,8 @@ extern im_ext_funcs *imager_function_ext_table;
 #define i_lhead(file, line) ((im_extt->f_i_lhead)((file), (line)))
 #define i_loog (im_extt->f_i_loog)
 
-#define i_img_alloc() ((im_extt->f_i_img_alloc)())
-#define i_img_init(img) ((im_extt->f_i_img_init)(img))
+#define im_img_alloc(ctx) ((im_extt->f_im_img_alloc)(ctx))
+#define im_img_init(ctx, img) ((im_extt->fm_i_img_init)((ctx), (img)))
 
 #define i_img_is_monochrome(img, zero_is_white) ((im_extt->f_i_img_is_monochrome)((img), (zero_is_white)))
 
index e6a354affc56884fa7d6916bea0011d59ee30789..8a6bda4f436b440a48a3941be47eba6a805483d3 100644 (file)
@@ -50,10 +50,10 @@ typedef struct {
   void  (*f_myfree_file_line)(void *p, char*file, int line);
   void* (*f_myrealloc_file_line)(void *p, size_t newsize, char* file,int line);
 
-  i_img *(*f_i_img_8_new)(i_img_dim xsize, i_img_dim ysize, int channels);
-  i_img *(*f_i_img_16_new)(i_img_dim xsize, i_img_dim ysize, int channels);
-  i_img *(*f_i_img_double_new)(i_img_dim xsize, i_img_dim ysize, int channels);
-  i_img *(*f_i_img_pal_new)(i_img_dim xsize, i_img_dim ysize, int channels, int maxpal);
+  i_img *(*f_im_img_8_new)(im_context_t ctx, i_img_dim xsize, i_img_dim ysize, int channels);
+  i_img *(*f_im_img_16_new)(im_context_t ctx, i_img_dim xsize, i_img_dim ysize, int channels);
+  i_img *(*f_im_img_double_new)(im_context_t ctx, i_img_dim xsize, i_img_dim ysize, int channels);
+  i_img *(*f_im_img_pal_new)(im_context_t ctx, i_img_dim xsize, i_img_dim ysize, int channels, int maxpal);
   void (*f_i_img_destroy)(i_img *im);
   i_img *(*f_i_sametype)(i_img *im, i_img_dim xsize, i_img_dim ysize);
   i_img *(*f_i_sametype_chans)(i_img *im, i_img_dim xsize, i_img_dim ysize, int channels);
@@ -104,10 +104,10 @@ typedef struct {
   void (*f_i_quant_transparent)(i_quantize *quant, i_palidx *indices, 
                                 i_img *img, i_palidx trans_index);
 
-  void (*f_i_clear_error)(void);
-  void (*f_i_push_error)(int code, char const *msg);
+  void (*f_im_clear_error)(im_context_t ctx);
+  void (*f_im_push_error)(im_context_t ctx, int code, char const *msg);
   void (*f_i_push_errorf)(int code, char const *fmt, ...);
-  void (*f_i_push_errorvf)(int code, char const *fmt, va_list);
+  void (*f_im_push_errorvf)(im_context_t ctx, int code, char const *fmt, va_list);
   
   void (*f_i_tags_new)(i_img_tags *tags);
   int (*f_i_tags_set)(i_img_tags *tags, char const *name, char const *data, 
@@ -154,9 +154,9 @@ typedef struct {
   int (*f_i_rubthru)(i_img *im, i_img *src, i_img_dim tx, i_img_dim ty, i_img_dim src_minx, i_img_dim src_miny, i_img_dim src_maxx, i_img_dim src_maxy);
 
   /* IMAGER_API_LEVEL 2 functions */
-  int (*f_i_set_image_file_limits)(i_img_dim width, i_img_dim height, size_t bytes);
-  int (*f_i_get_image_file_limits)(i_img_dim *width, i_img_dim *height, size_t *bytes);
-  int (*f_i_int_check_image_file_limits)(i_img_dim width, i_img_dim height, int channels, size_t sample_size);
+  int (*f_im_set_image_file_limits)(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes);
+  int (*f_im_get_image_file_limits)(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes);
+  int (*f_im_int_check_image_file_limits)(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size);
   int (*f_i_flood_fill_border)(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol, const i_color *border);
   int (*f_i_flood_cfill_border)(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill, const i_color *border);
 
@@ -170,8 +170,8 @@ typedef struct {
   void (*f_i_loog)(int level, const char *msg, ...);
 
   /* IMAGER_API_LEVEL 4 functions will be added here */
-  i_img *(*f_i_img_alloc)(void);
-  void (*f_i_img_init)(i_img *);
+  i_img *(*f_im_img_alloc)(im_context_t ctx);
+  void (*f_im_img_init)(im_context_t ctx, i_img *);
 
   /* IMAGER_API_LEVEL 5 functions will be added here */
   /* added i_psampf?_bits macros */
@@ -220,7 +220,7 @@ typedef struct {
   void (*f_io_glue_destroy)(i_io_glue_t *ig);
 
   /* IMAGER_API_LEVEL 8 functions will be added here */
-
+  im_context_t (*f_im_get_context)(void);
 } im_ext_funcs;
 
 #define PERL_FUNCTION_TABLE_NAME "Imager::__ext_func_table"
index ad079c35082ad8df6dc419ab5e69b7a9a694286c..e970f9045da54912052e067d7672ef669012e21f 100644 (file)
@@ -86,4 +86,20 @@ returns -1 and pushes an error.
 
 #define pIMCTX im_context_t my_im_ctx
 
+#define i_img_8_new(xsize, ysize, channels) im_img_8_new(aIMCTX, (xsize), (ysize), (channels))
+#define i_img_16_new(xsize, ysize, channels) im_img_16_new(aIMCTX, (xsize), (ysize), (channels))
+#define i_img_double_new(xsize, ysize, channels) im_img_double_new(aIMCTX, (xsize), (ysize), (channels))
+#define i_img_pal_new(xsize, ysize, channels, maxpal) im_img_pal_new(aIMCTX, (xsize), (ysize), (channels), (maxpal))
+
+#define i_img_alloc() im_img_alloc(aIMCTX)
+#define i_img_init(im) im_img_init(aIMCTX, im)
+
+#define i_set_image_file_limits(width, height, bytes) im_set_image_file_limits(aIMCTX, width, height, bytes)
+#define i_get_image_file_limits(width, height, bytes) im_get_image_file_limits(aIMCTX, width, height, bytes)
+#define i_int_check_image_file_limits(width, height, channels, sample_size) im_int_check_image_file_limits(aIMCTX, width, height, channels, sample_size)
+
+#define i_clear_error() im_clear_error(aIMCTX)
+#define i_push_errorvf(code, fmt, args) im_push_errorvf(aIMCTX, code, fmt, args)
+#define i_push_error(code, msg) im_push_error(aIMCTX, code, msg)
+
 #endif
index cb784c2883a0d7e97678b502c9ce94ca5212744f..28c81aeb5b847425dbe5b4ab9d6e4dc28916744b 100644 (file)
@@ -40,15 +40,9 @@ Imager::APIRef - Imager's C API - reference.
   i_flood_cfill_border(im, 50, 50, fill, border);
 
   # Error handling
-  i_clear_error();
-  i_push_error(0, "Yep, it's broken");
-  i_push_error(errno, "Error writing");
   i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
 
   # Files
-  i_set_image_file_limits(500, 500, 1000000);
-  i_get_image_file_limits(&width, &height, &bytes)
-  i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
 
   # Fills
   i_fill_t *fill = i_new_fill_solidf(&fcolor, combine);
@@ -72,14 +66,8 @@ Imager::APIRef - Imager's C API - reference.
   # Image creation/destruction
   i_img *img = i_sametype(src, width, height);
   i_img *img = i_sametype_chans(src, width, height, channels);
-  i_img *img = i_img_16_new(width, height, channels);
-  i_img *img = i_img_8_new(width, height, channels);
-  i_img *img = i_img_double_new(width, height, channels);
-  i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
   i_img_destroy(img)
 
-  # Image Implementation
-
   # Image Information
   // only channel 0 writable 
   i_img_setmask(img, 0x01);
@@ -850,33 +838,6 @@ From: File immacros.h
 
 =over
 
-=item i_clear_error()
-
-  i_clear_error();
-
-Clears the error stack.
-
-Called by any Imager function before doing any other processing.
-
-
-=for comment
-From: File error.c
-
-=item i_push_error(int code, char const *msg)
-
-  i_push_error(0, "Yep, it's broken");
-  i_push_error(errno, "Error writing");
-
-Called by an Imager function to push an error message onto the stack.
-
-No message is pushed if the stack is full (since this means someone
-forgot to call i_clear_error(), or that a function that doesn't do
-error handling is calling function that does.).
-
-
-=for comment
-From: File error.c
-
 =item i_push_errorf(int code, char const *fmt, ...)
 
   i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
@@ -886,18 +847,6 @@ A version of i_push_error() that does printf() like formatting.
 Does not support perl specific format codes.
 
 
-=for comment
-From: File error.c
-
-=item i_push_errorvf(int C<code>, char const *C<fmt>, va_list C<ap>)
-
-
-Intended for use by higher level functions, takes a varargs pointer
-and a format to produce the finally pushed error message.
-
-Does not support perl specific format codes.
-
-
 =for comment
 From: File error.c
 
@@ -937,80 +886,6 @@ Returns 1 if the C<i_background> tag was found and valid.
 =for comment
 From: File image.c
 
-=item i_get_image_file_limits(&width, &height, &bytes)
-
-
-  i_get_image_file_limits(&width, &height, &bytes)
-
-Retrieves the file limits set by i_set_image_file_limits().
-
-=over
-
-=item *
-
-i_img_dim *width, *height - the maximum width and height of the image.
-
-=item *
-
-size_t *bytes - size in memory of the image in bytes.
-
-=back
-
-
-=for comment
-From: File limits.c
-
-=item i_int_check_image_file_limits(width, height, channels, sample_size)
-
-
-  i_i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))
-
-Checks the size of a file in memory against the configured image file
-limits.
-
-This also range checks the values to those permitted by Imager and
-checks for overflows in calculating the size.
-
-Returns non-zero if the file is within limits.
-
-This function is intended to be called by image file read functions.
-
-
-=for comment
-From: File limits.c
-
-=item i_set_image_file_limits(width, height, bytes)
-
-
-  i_set_image_file_limits(500, 500, 1000000);
-
-Set limits on the sizes of images read by Imager.
-
-Setting a limit to 0 means that limit is ignored.
-
-Negative limits result in failure.
-
-Parameters:
-
-=over
-
-=item *
-
-i_img_dim width, height - maximum width and height.
-
-=item *
-
-size_t bytes - maximum size in memory in bytes.  A value of zero sets
-this limit to one gigabyte.
-
-=back
-
-Returns non-zero on success.
-
-
-=for comment
-From: File limits.c
-
 
 =back
 
@@ -1476,57 +1351,6 @@ From: File rubthru.im
 
 =over
 
-=item i_img_16_new(x, y, ch)
-
-
-  i_img *img = i_img_16_new(width, height, channels);
-
-Create a new 16-bit/sample image.
-
-Returns the image on success, or NULL on failure.
-
-
-=for comment
-From: File img16.c
-
-=item i_img_8_new(x, y, ch)
-
-
-
-  i_img *img = i_img_8_new(width, height, channels);
-
-Creates a new image object I<x> pixels wide, and I<y> pixels high with
-I<ch> channels.
-
-
-=for comment
-From: File img8.c
-
-=item i_img_double_new(i_img_dim x, i_img_dim y, int ch)
-
-  i_img *img = i_img_double_new(width, height, channels);
-
-Creates a new double per sample image.
-
-
-=for comment
-From: File imgdouble.c
-
-=item i_img_pal_new(C<x>, C<y>, C<channels>, C<maxpal>)
-
-
-  i_img *img = i_img_pal_new(width, height, channels, max_palette_size)
-
-Creates a new paletted image of the supplied dimensions.
-
-C<maxpal> is the maximum palette size and should normally be 256.
-
-Returns a new image or NULL on failure.
-
-
-=for comment
-From: File palimg.c
-
 =item i_sametype(C<im>, C<xsize>, C<ysize>)
 
 
@@ -1564,53 +1388,6 @@ Destroy an image object
 From: File image.c
 
 
-=back
-
-=head2 Image Implementation
-
-=over
-
-=item i_img_alloc()
-
-Allocates a new i_img structure.
-
-When implementing a new image type perform the following steps in your
-image object creation function:
-
-=over
-
-=item 1.
-
-allocate the image with i_img_alloc().
-
-=item 2.
-
-initialize any function pointers or other data as needed, you can
-overwrite the whole block if you need to.
-
-=item 3.
-
-initialize Imager's internal data by calling i_img_init() on the image
-object.
-
-=back
-
-
-=for comment
-From: File image.c
-
-=item i_img_init(C<img>)
-
-Imager internal initialization of images.
-
-Currently this does very little, in the future it may be used to
-support threads, or color profiles.
-
-
-=for comment
-From: File image.c
-
-
 =back
 
 =head2 Image Information
index c0292549e1940a2ed6f861fd31fa881a2eddb4ec..0d4c22a20c3967cb783dfa3ac68d1df9834439a6 100644 (file)
--- a/limits.c
+++ b/limits.c
@@ -26,11 +26,6 @@ Setting a value of zero means that limit will be ignored.
 
 #include "imageri.h"
 
-#define DEF_BYTES_LIMIT 0x40000000
-
-static i_img_dim max_width, max_height;
-static size_t max_bytes = DEF_BYTES_LIMIT;
-
 /*
 =item i_set_image_file_limits(width, height, bytes)
 
@@ -64,7 +59,7 @@ Returns non-zero on success.
 */
 
 int
-i_set_image_file_limits(i_img_dim width, i_img_dim height, size_t bytes) {
+im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes) {
   i_clear_error();
 
   if (width < 0) {
@@ -80,9 +75,9 @@ i_set_image_file_limits(i_img_dim width, i_img_dim height, size_t bytes) {
     return 0;
   }
 
-  max_width = width;
-  max_height = height;
-  max_bytes = bytes ? bytes : DEF_BYTES_LIMIT;
+  ctx->max_width = width;
+  ctx->max_height = height;
+  ctx->max_bytes = bytes ? bytes : DEF_BYTES_LIMIT;
 
   return 1;
 }
@@ -111,12 +106,12 @@ size_t *bytes - size in memory of the image in bytes.
 */
 
 int
-i_get_image_file_limits(i_img_dim *width, i_img_dim *height, size_t *bytes) {
-  i_clear_error();
+im_get_image_file_limits(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes) {
+  im_clear_error(ctx);
 
-  *width = max_width;
-  *height = max_height;
-  *bytes = max_bytes;
+  *width = ctx->max_width;
+  *height = ctx->max_height;
+  *bytes = ctx->max_bytes;
 
   return 1;
 }
@@ -141,41 +136,41 @@ This function is intended to be called by image file read functions.
 */
 
 int
-i_int_check_image_file_limits(i_img_dim width, i_img_dim height, int channels, size_t sample_size) {
+im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size) {
   size_t bytes;
-  i_clear_error();
+  im_clear_error(ctx);
   
   if (width <= 0) {
-    i_push_errorf(0, "file size limit - image width of %" i_DF " is not positive",
+    im_push_errorf(ctx, 0, "file size limit - image width of %" i_DF " is not positive",
                  i_DFc(width));
     return 0;
   }
-  if (max_width && width > max_width) {
-    i_push_errorf(0, "file size limit - image width of %" i_DF " exceeds limit of %" i_DF,
-                 i_DFc(width), i_DFc(max_width));
+  if (ctx->max_width && width > ctx->max_width) {
+    im_push_errorf(ctx, 0, "file size limit - image width of %" i_DF " exceeds limit of %" i_DF,
+                 i_DFc(width), i_DFc(ctx->max_width));
     return 0;
   }
 
   if (height <= 0) {
-    i_push_errorf(0, "file size limit - image height of %" i_DF " is not positive",
+    im_push_errorf(ctx, 0, "file size limit - image height of %" i_DF " is not positive",
                  i_DFc(height));
     return 0;
   }
 
-  if (max_height && height > max_height) {
-    i_push_errorf(0, "file size limit - image height of %" i_DF
-                 " exceeds limit of %" i_DF, i_DFc(height), i_DFc(max_height));
+  if (ctx->max_height && height > ctx->max_height) {
+    im_push_errorf(ctx, 0, "file size limit - image height of %" i_DF
+                 " exceeds limit of %" i_DF, i_DFc(height), i_DFc(ctx->max_height));
     return 0;
   }
 
   if (channels < 1 || channels > MAXCHANNELS) {
-    i_push_errorf(0, "file size limit - channels %d out of range",
+    im_push_errorf(ctx, 0, "file size limit - channels %d out of range",
                  channels);
     return 0;
   }
   
   if (sample_size < 1 || sample_size > sizeof(long double)) {
-    i_push_errorf(0, "file size limit - sample_size %ld out of range",
+    im_push_errorf(ctx, 0, "file size limit - sample_size %ld out of range",
                  (long)sample_size);
     return 0;
   }
@@ -190,11 +185,11 @@ i_int_check_image_file_limits(i_img_dim width, i_img_dim height, int channels, s
     i_push_error(0, "file size limit - integer overflow calculating storage");
     return 0;
   }
-  if (max_bytes) {
-    if (bytes > max_bytes) {
-      i_push_errorf(0, "file size limit - storage size of %lu "
+  if (ctx->max_bytes) {
+    if (bytes > ctx->max_bytes) {
+      im_push_errorf(ctx, 0, "file size limit - storage size of %lu "
                    "exceeds limit of %lu", (unsigned long)bytes,
-                   (unsigned long)max_bytes);
+                   (unsigned long)ctx->max_bytes);
       return 0;
     }
   }
diff --git a/log.c b/log.c
index 5f8b92a6a9c651e94502c578f12bd6bc7578d726..2b0c32b1489495958bd1b8145e091ff5b0ddca72 100644 (file)
--- a/log.c
+++ b/log.c
@@ -19,6 +19,9 @@ static char  data_buffer[DATABUFF];
 
 #define LOG_DATE_FORMAT "%Y/%m/%d %H:%M:%S"
 
+static void
+im_vloog(pIMCTX, int level, const char *fmt, va_list ap);
+
 /*
  * Logging is active
  */
@@ -47,26 +50,34 @@ im_init_log(pIMCTX, const char* name,int level) {
   return aIMCTX->lg_file != NULL;
 }
 
-#if 0
 void
 i_fatal(int exitcode,const char *fmt, ... ) {
   va_list ap;
   time_t timi;
   struct tm *str_tm;
-  
-  if (lg_file != NULL) {
-    timi = time(NULL);
-    str_tm = localtime(&timi);
-    if ( strftime(date_buffer, DTBUFF, date_format, str_tm) )
-      fprintf(lg_file,"[%s] ",date_buffer);
+  pIMCTX = im_get_context();
+
+  if (aIMCTX->lg_file != NULL) {
     va_start(ap,fmt);
-    vfprintf(lg_file,fmt,ap);
+    im_vloog(aIMCTX, 0, fmt, ap);
     va_end(ap);
   }
   exit(exitcode);
 }
 
-#endif
+void
+im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) {
+  va_list ap;
+  time_t timi;
+  struct tm *str_tm;
+  
+  if (aIMCTX->lg_file != NULL) {
+    va_start(ap,fmt);
+    im_vloog(aIMCTX, 0, fmt, ap);
+    va_end(ap);
+  }
+  exit(exitcode);
+}
 
 /*
 =item i_loog(level, format, ...)
@@ -156,6 +167,7 @@ int i_init_log(const char* name,int onoff) {
 }
 
 void i_fatal(int exitcode,const char *fmt, ... ) { exit(exitcode); }
+void im_fatal(pIMCTX, int exitcode,const char *fmt, ... ) { exit(exitcode); }
 
 void
 i_loog(int level,const char *fmt, ... ) {
diff --git a/log.h b/log.h
index 0be9b13b07a915d65ed015962e525e94fba78028..2d23440df659806e6f6d76140fee87d24feb47b0 100644 (file)
--- a/log.h
+++ b/log.h
@@ -14,6 +14,7 @@
 int im_init_log(pIMCTX, const char *name, int onoff );
 #define i_init_log(name, onoff) im_init_log(aIMCTX, name, onoff)
 void i_fatal ( int exitcode,const char *fmt, ... );
+void im_fatal (pIMCTX, int exitcode,const char *fmt, ... );
 void im_lhead ( pIMCTX, const char *file, int line  );
 void i_lhead ( const char *file, int line  );
 void i_loog(int level,const char *msg, ... ) I_FORMAT_ATTR(2,3);
diff --git a/plug.h b/plug.h
index 017cf233e18a18cb2372397e10c6b0598434022c..0be22bfc59325e9f3a150aaa00486b2f6b521980 100644 (file)
--- a/plug.h
+++ b/plug.h
 #define i_color_info(cl) (symbol_table->i_color_info(cl))
 
 #define im_get_context() (symbol_table->im_get_context_f())
-#define i_img_empty(im,x,y) ((symbol_table->im_img_empty_f(im,x,y))
 #define i_img_empty_ch(im,x,y,ch) ((symbol_table->i_img_empty_ch_f(im_get_context(), im,x,y,ch))
-#define i_img_exorcise(im) (symbol_table->i_img_exorcise(im))
-#define i_img_info(im,info) (symbol_table->i_img_info(im,info))
+#define i_img_exorcise(im) (symbol_table->i_img_exorcise_f(im))
+#define i_img_info(im,info) (symbol_table->i_img_info_f(im,info))
 
-#define i_img_setmask(im,ch_mask) (symbol_table->i_img_setmask(im,ch_mask))
-#define i_img_getmask(im) (symbol_table->i_img_getmask(im))
+#define i_img_setmask(im,ch_mask) (symbol_table->i_img_setmask_f(im,ch_mask))
+#define i_img_getmask(im) (symbol_table->i_img_getmask_f(im))
 
 /*
 Not needed?  The i_gpix() macro in image.h will call the right function