ctx->log_level = 0;
ctx->lg_file = NULL;
#endif
+ ctx->max_width = 0;
+ ctx->max_height = 0;
+ ctx->max_bytes = 0;
return 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;
}
ICL_set_internal,
ICL_info,
do_get_context,
- i_img_empty,
im_img_empty_ch,
i_img_exorcise,
i_img_info,
}
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);
}
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);
=cut
*/
+im_context_t (*im_get_context)(void) = NULL;
+
#define XAXIS 0
#define YAXIS 1
#define XYAXIS 2
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);
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);
/* 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);
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
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
#include "imager.h"
#include "imio.h"
+static im_context_t get_context(void);
+
/*
DON'T ADD CASTS TO THESE
*/
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,
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,
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,
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,
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
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();
+}
/* 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__))
#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)))
#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) \
#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))
#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)))
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);
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,
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);
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 */
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"
#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
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);
# 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);
=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);
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
=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
=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>)
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
#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)
*/
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) {
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;
}
*/
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;
}
*/
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;
}
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;
}
}
#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
*/
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, ...)
}
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, ... ) {
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);
#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