]> git.imager.perl.org - imager.git/commitdiff
update limits.c with IMAGER_NO_CONTEXT
authorTony Cook <tony@develop-help.com>
Mon, 6 Aug 2012 01:54:07 +0000 (11:54 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 24 Nov 2012 03:59:22 +0000 (14:59 +1100)
limits.c

index 0d4c22a20c3967cb783dfa3ac68d1df9834439a6..a245a6b23a32daabfbd4534446cee00f4242aee0 100644 (file)
--- a/limits.c
+++ b/limits.c
@@ -24,6 +24,7 @@ Setting a value of zero means that limit will be ignored.
   
  */
 
+#define IMAGER_NO_CONTEXT
 #include "imageri.h"
 
 /*
@@ -59,7 +60,7 @@ Returns non-zero on success.
 */
 
 int
-im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, size_t bytes) {
+im_set_image_file_limits(pIMCTX, i_img_dim width, i_img_dim height, size_t bytes) {
   i_clear_error();
 
   if (width < 0) {
@@ -75,9 +76,9 @@ im_set_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, si
     return 0;
   }
 
-  ctx->max_width = width;
-  ctx->max_height = height;
-  ctx->max_bytes = bytes ? bytes : DEF_BYTES_LIMIT;
+  aIMCTX->max_width = width;
+  aIMCTX->max_height = height;
+  aIMCTX->max_bytes = bytes ? bytes : DEF_BYTES_LIMIT;
 
   return 1;
 }
@@ -106,12 +107,12 @@ size_t *bytes - size in memory of the image in bytes.
 */
 
 int
-im_get_image_file_limits(im_context_t ctx, i_img_dim *width, i_img_dim *height, size_t *bytes) {
-  im_clear_error(ctx);
+im_get_image_file_limits(pIMCTX, i_img_dim *width, i_img_dim *height, size_t *bytes) {
+  im_clear_error(aIMCTX);
 
-  *width = ctx->max_width;
-  *height = ctx->max_height;
-  *bytes = ctx->max_bytes;
+  *width = aIMCTX->max_width;
+  *height = aIMCTX->max_height;
+  *bytes = aIMCTX->max_bytes;
 
   return 1;
 }
@@ -136,41 +137,41 @@ This function is intended to be called by image file read functions.
 */
 
 int
-im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim height, int channels, size_t sample_size) {
+im_int_check_image_file_limits(pIMCTX, i_img_dim width, i_img_dim height, int channels, size_t sample_size) {
   size_t bytes;
-  im_clear_error(ctx);
+  im_clear_error(aIMCTX);
   
   if (width <= 0) {
-    im_push_errorf(ctx, 0, "file size limit - image width of %" i_DF " is not positive",
+    im_push_errorf(aIMCTX, 0, "file size limit - image width of %" i_DF " is not positive",
                  i_DFc(width));
     return 0;
   }
-  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));
+  if (aIMCTX->max_width && width > aIMCTX->max_width) {
+    im_push_errorf(aIMCTX, 0, "file size limit - image width of %" i_DF " exceeds limit of %" i_DF,
+                 i_DFc(width), i_DFc(aIMCTX->max_width));
     return 0;
   }
 
   if (height <= 0) {
-    im_push_errorf(ctx, 0, "file size limit - image height of %" i_DF " is not positive",
+    im_push_errorf(aIMCTX, 0, "file size limit - image height of %" i_DF " is not positive",
                  i_DFc(height));
     return 0;
   }
 
-  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));
+  if (aIMCTX->max_height && height > aIMCTX->max_height) {
+    im_push_errorf(aIMCTX, 0, "file size limit - image height of %" i_DF
+                 " exceeds limit of %" i_DF, i_DFc(height), i_DFc(aIMCTX->max_height));
     return 0;
   }
 
   if (channels < 1 || channels > MAXCHANNELS) {
-    im_push_errorf(ctx, 0, "file size limit - channels %d out of range",
+    im_push_errorf(aIMCTX, 0, "file size limit - channels %d out of range",
                  channels);
     return 0;
   }
   
   if (sample_size < 1 || sample_size > sizeof(long double)) {
-    im_push_errorf(ctx, 0, "file size limit - sample_size %ld out of range",
+    im_push_errorf(aIMCTX, 0, "file size limit - sample_size %ld out of range",
                  (long)sample_size);
     return 0;
   }
@@ -182,14 +183,14 @@ im_int_check_image_file_limits(im_context_t ctx, i_img_dim width, i_img_dim heig
   bytes = width * height * channels * sample_size;
   if (bytes / width != height * channels * sample_size
       || bytes / height != width * channels * sample_size) {
-    i_push_error(0, "file size limit - integer overflow calculating storage");
+    im_push_error(aIMCTX, 0, "file size limit - integer overflow calculating storage");
     return 0;
   }
-  if (ctx->max_bytes) {
-    if (bytes > ctx->max_bytes) {
-      im_push_errorf(ctx, 0, "file size limit - storage size of %lu "
+  if (aIMCTX->max_bytes) {
+    if (bytes > aIMCTX->max_bytes) {
+      im_push_errorf(aIMCTX, 0, "file size limit - storage size of %lu "
                    "exceeds limit of %lu", (unsigned long)bytes,
-                   (unsigned long)ctx->max_bytes);
+                   (unsigned long)aIMCTX->max_bytes);
       return 0;
     }
   }