6 Create a new Imager context object.
12 im_context_new(void) {
13 im_context_t ctx = mymalloc(sizeof(im_context_struct));
16 ctx->error_sp = IM_ERROR_COUNT-1;
17 for (i = 0; i < IM_ERROR_COUNT; ++i) {
18 ctx->error_alloc[i] = 0;
19 ctx->error_stack[i].msg = NULL;
20 ctx->error_stack[i].code = 0;
34 =item im_context_delete(ctx)
36 Release memory used by an Imager context object.
42 im_context_delete(im_context_t ctx) {
45 for (i = 0; i < IM_ERROR_COUNT; ++i) {
46 if (ctx->error_stack[i].msg)
47 myfree(ctx->error_stack[i].msg);
56 =item im_context_clone(ctx)
58 Clone an Imager context object, returning the result.
64 im_context_clone(im_context_t ctx) {
65 im_context_t nctx = mymalloc(sizeof(im_context_struct));
68 nctx->error_sp = ctx->error_sp;
69 for (i = 0; i < IM_ERROR_COUNT; ++i) {
70 if (ctx->error_stack[i].msg) {
71 size_t sz = ctx->error_alloc[i];
72 nctx->error_alloc[i] = sz;
73 nctx->error_stack[i].msg = mymalloc(sz);
74 memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz);
77 nctx->error_alloc[i] = 0;
78 nctx->error_stack[i].msg = NULL;
80 nctx->error_stack[i].code = ctx->error_stack[i].code;
83 nctx->log_level = ctx->log_level;
85 /* disable buffering, this isn't perfect */
86 setvbuf(ctx->lg_file, NULL, _IONBF, 0);
88 /* clone that and disable buffering some more */
89 nctx->lg_file = fdopen(fileno(ctx->lg_file), "a");
91 setvbuf(nctx->lg_file, NULL, _IONBF, 0);
97 nctx->max_width = ctx->max_width;
98 nctx->max_height = ctx->max_height;
99 nctx->max_bytes = ctx->max_bytes;