From: Tony Cook Date: Mon, 6 Aug 2012 13:39:12 +0000 (+1000) Subject: WIP, it compiles X-Git-Tag: v0.92_01~51 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/a482206ee8b4a6d97081ef70ccd3c324461fbb55 WIP, it compiles --- diff --git a/context.c b/context.c index f4e7e2ac..8845722b 100644 --- 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; } diff --git a/dynaload.c b/dynaload.c index 8a12de25..faa605da 100644 --- a/dynaload.c +++ b/dynaload.c @@ -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 a5f97b87..4b3faf2c 100644 --- 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 190ff76b..9a25820a 100644 --- 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 6a4fc8dd..5c602d75 100644 --- 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 diff --git a/imager.h b/imager.h index 8246e4f2..0260d245 100644 --- 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); diff --git a/imageri.h b/imageri.h index 34817ed1..c563c458 100644 --- 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 diff --git a/imerror.h b/imerror.h index b51600ec..e4a73189 100644 --- 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 6afaadd4..4f337958 100644 --- 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 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 1e4bccb6..2bb7a70b 100644 --- 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))) diff --git a/imexttypes.h b/imexttypes.h index e6a354af..8a6bda4f 100644 --- a/imexttypes.h +++ b/imexttypes.h @@ -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" diff --git a/immacros.h b/immacros.h index ad079c35..e970f904 100644 --- a/immacros.h +++ b/immacros.h @@ -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 diff --git a/lib/Imager/APIRef.pod b/lib/Imager/APIRef.pod index cb784c28..28c81aeb 100644 --- a/lib/Imager/APIRef.pod +++ b/lib/Imager/APIRef.pod @@ -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, char const *C, va_list C) - - -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 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 pixels wide, and I pixels high with -I 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, C, C, C) - - - i_img *img = i_img_pal_new(width, height, channels, max_palette_size) - -Creates a new paletted image of the supplied dimensions. - -C 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, C, C) @@ -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) - -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 diff --git a/limits.c b/limits.c index c0292549..0d4c22a2 100644 --- 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 5f8b92a6..2b0c32b1 100644 --- 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 0be9b13b..2d23440d 100644 --- 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 017cf233..0be22bfc 100644 --- a/plug.h +++ b/plug.h @@ -16,13 +16,12 @@ #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