]> mj.ucw.cz Git - libucw.git/blobdiff - images/io-libmagick.c
Libucw: Be able to use public tmp directory.
[libucw.git] / images / io-libmagick.c
index cdf58048ced1d69946e6ce3d11dc28b3c15cb3da..1a636b2a29ad7b9c53ec3e91c4fb8db21f7d4f4a 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"
@@ -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)
     {