Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
180 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "imageri.h" | ||
|
||
/* | ||
=item im_context_new() | ||
Create a new Imager context object. | ||
=cut | ||
*/ | ||
|
||
im_context_t | ||
im_context_new(void) { | ||
im_context_t ctx = mymalloc(sizeof(im_context_struct)); | ||
int i; | ||
|
||
ctx->error_sp = IM_ERROR_COUNT-1; | ||
for (i = 0; i < IM_ERROR_COUNT; ++i) { | ||
ctx->error_alloc[i] = 0; | ||
ctx->error_stack[i].msg = NULL; | ||
ctx->error_stack[i].code = 0; | ||
} | ||
#ifdef IMAGER_LOG | ||
ctx->log_level = 0; | ||
ctx->lg_file = NULL; | ||
#endif | ||
|
||
return ctx; | ||
} | ||
|
||
/* | ||
=item im_context_delete(ctx) | ||
Release memory used by an Imager context object. | ||
=cut | ||
*/ | ||
|
||
void | ||
im_context_delete(im_context_t ctx) { | ||
int i; | ||
|
||
for (i = 0; i < IM_ERROR_COUNT; ++i) { | ||
if (ctx->error_stack[i].msg) | ||
myfree(ctx->error_stack[i].msg); | ||
} | ||
#ifdef IMAGER_LOG | ||
if (ctx->lg_file) | ||
fclose(ctx->lg_file); | ||
#endif | ||
} | ||
|
||
/* | ||
=item im_context_clone(ctx) | ||
Clone an Imager context object, returning the result. | ||
=cut | ||
*/ | ||
|
||
im_context_t | ||
im_context_clone(im_context_t ctx) { | ||
im_context_t nctx = mymalloc(sizeof(im_context_struct)); | ||
int i; | ||
|
||
nctx->error_sp = ctx->error_sp; | ||
for (i = 0; i < IM_ERROR_COUNT; ++i) { | ||
if (ctx->error_stack[i].msg) { | ||
size_t sz = ctx->error_alloc[i]; | ||
nctx->error_alloc[i] = sz; | ||
nctx->error_stack[i].msg = mymalloc(sz); | ||
memcpy(nctx->error_stack[i].msg, ctx->error_stack[i].msg, sz); | ||
} | ||
else { | ||
nctx->error_alloc[i] = 0; | ||
nctx->error_stack[i].msg = NULL; | ||
} | ||
nctx->error_stack[i].code = ctx->error_stack[i].code; | ||
} | ||
#ifdef IMAGER_LOG | ||
nctx->log_level = ctx->log_level; | ||
if (ctx->lg_file) { | ||
/* disable buffering, this isn't perfect */ | ||
setvbuf(ctx->lg_file, NULL, _IONBF, 0); | ||
|
||
/* clone that and disable buffering some more */ | ||
nctx->lg_file = fdopen(fileno(ctx->lg_file), "a"); | ||
if (nctx->lg_file) | ||
setvbuf(nctx->lg_file, NULL, _IONBF, 0); | ||
} | ||
else { | ||
ctx->lg_file = NULL; | ||
} | ||
#endif | ||
|
||
return ctx; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,5 +262,4 @@ extern im_ext_funcs *imager_function_ext_table; | |
#define mm_log(x) | ||
#endif | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters