]> mj.ucw.cz Git - libucw.git/blobdiff - images/object.c
make regex and asciidoc work on Darwin without hacking
[libucw.git] / images / object.c
index 3935f89b6e37712cd388b2548f4364720e046574..9133b7e6d8ff16e4d74f631ad6e12088478caf34 100644 (file)
@@ -6,12 +6,12 @@
  *     This software may be freely distributed and used according to the terms
  */
 
-#define LOCAL_DEBUG
+#undef LOCAL_DEBUG
 
 #include "sherlock/sherlock.h"
-#include "lib/base224.h"
-#include "lib/mempool.h"
-#include "lib/fastbuf.h"
+#include "ucw/base224.h"
+#include "ucw/mempool.h"
+#include "ucw/fastbuf.h"
 #include "sherlock/object.h"
 #include "images/images.h"
 #include "images/object.h"
@@ -29,7 +29,7 @@ get_image_obj_info(struct image_obj_info *ioi, struct odes *o)
       DBG("Missing image info attribute");
       return 0;
     }
-  byte color_space[MAX_ATTR_SIZE], thumb_format[MAX_ATTR_SIZE];
+  byte color_space[16], thumb_format[16];
   UNUSED uns cnt = sscanf(v, "%d%d%s%d%d%d%s", &ioi->cols, &ioi->rows, color_space,
       &ioi->colors, &ioi->thumb_cols, &ioi->thumb_rows, thumb_format);
   ASSERT(cnt == 7);
@@ -48,9 +48,13 @@ get_image_obj_thumb(struct image_obj_info *ioi, struct odes *o, struct mempool *
       return 0;
     }
   uns count = 0;
+  uns max_len = 0;
   for (struct oattr *b = a; b; b = b->same)
-    count++;
-  byte buf[count * MAX_ATTR_SIZE], *b = buf;
+    {
+      count++;
+      max_len += strlen(b->val);
+    }
+  byte buf[max_len + 1], *b = buf;
   for (; a; a = a->same)
     b += base224_decode(b, a->val, strlen(a->val));
   ASSERT(b != buf);
@@ -75,23 +79,21 @@ read_image_obj_thumb(struct image_obj_info *ioi, struct fastbuf *fb, struct imag
   if (!io->background_color.color_space)
     io->background_color = color_white;
   struct image *img;
-  if (!(img = image_io_read_data(io, 0)))
+  if (!(img = image_io_read_data(io, 1)))
     goto error;
-  ASSERT(img->cols == ioi->thumb_cols && img->rows == ioi->thumb_rows);
   DBG("Decompressed thumbnail: size=%ux%u", img->cols, img->rows);
   return img;
 error:
   DBG("Failed to decompress thumbnail: %s", io->thread->err_msg);
-  return NULL;  
+  return NULL;
 }
 
 void
 put_image_obj_signature(struct odes *o, struct image_signature *sig)
 {
-  /* signatures should be short enough to fit one attribute */
-  byte buf[MAX_ATTR_SIZE];
+  /* signatures should be short enough to in a single attribute */
   uns size = image_signature_size(sig->len);
-  ASSERT(MAX_ATTR_SIZE > BASE224_ENC_LENGTH(size));
+  byte buf[BASE224_ENC_LENGTH(size) + 1];
   buf[base224_encode(buf, (byte *)sig, size)] = 0;
   obj_set_attr(o, 'H', buf);
 }