]> mj.ucw.cz Git - libucw.git/blobdiff - images/io-libmagick.c
ucw docs: init and commit hooks described in-place
[libucw.git] / images / io-libmagick.c
index cdf58048ced1d69946e6ce3d11dc28b3c15cb3da..fd9069f349d210297e53853dd9adc034f7a4cb77 100644 (file)
@@ -9,9 +9,9 @@
 
 #undef LOCAL_DEBUG
 
-#include "lib/lib.h"
-#include "lib/mempool.h"
-#include "lib/fastbuf.h"
+#include "ucw/lib.h"
+#include "ucw/mempool.h"
+#include "ucw/fastbuf.h"
 #include "images/images.h"
 #include "images/error.h"
 #include "images/color.h"
@@ -82,7 +82,7 @@ libmagick_read_header(struct image_io *io)
   DBG("libmagick_read_header()");
 
   /* Read entire stream */
-  sh_off_t file_size = bfilesize(io->fastbuf) - btell(io->fastbuf);
+  ucw_off_t file_size = bfilesize(io->fastbuf) - btell(io->fastbuf);
   if (unlikely(file_size > MAX_FILE_SIZE))
     {
       IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Too long stream.");
@@ -170,8 +170,11 @@ libmagick_read_data(struct image_io *io)
   /* Prepare the image */
   struct image_io_read_data_internals rdi;
   uns read_flags = io->flags;
+  uns cs = read_flags & IMAGE_COLOR_SPACE;
+  if (cs != COLOR_SPACE_GRAYSCALE && cs != COLOR_SPACE_RGB)
+    read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_PIXEL_FORMAT) | COLOR_SPACE_RGB;
   if ((read_flags & IMAGE_IO_USE_BACKGROUND) && !(read_flags & IMAGE_ALPHA))
-    read_flags = (read_flags | IMAGE_ALPHA) & IMAGE_CHANNELS_FORMAT;
+    read_flags = (read_flags & IMAGE_CHANNELS_FORMAT) | IMAGE_ALPHA;
   if (unlikely(!image_io_read_data_prepare(&rdi, io, rd->image->columns, rd->image->rows, read_flags)))
     {
       libmagick_destroy_read_data(rd);
@@ -279,7 +282,8 @@ libmagick_write(struct image_io *io)
         info->colorspace = RGBColorspace;
         break;
       default:
-        ASSERT(0);
+        IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "Unsupported color space.");
+        goto err;
     }
   switch (io->format)
     {