]> mj.ucw.cz Git - libucw.git/commitdiff
small changes to image-tool - can read more formats with GraphicsMagick
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 9 Aug 2006 15:12:36 +0000 (17:12 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Wed, 9 Aug 2006 15:12:36 +0000 (17:12 +0200)
images/image-tool.c
images/io-main.c

index b52d59fda6cb4809887c2a237a39b5ffec56ca64..f217003868cb1c583765126f2c51ace9fcf3a21a 100644 (file)
@@ -8,10 +8,11 @@
  */
 
 #include "lib/lib.h"
-#include "lib/getopt.h"
 #include "lib/fastbuf.h"
 #include "images/images.h"
 #include "images/color.h"
+
+#include <getopt.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -35,10 +36,9 @@ Usage: image-tool [options] infile [outfile]\n\
   exit(1);
 }
 
-static char *shortopts = "qf:F:s:b:c:Q:g:" CF_SHORT_OPTS;
+static char *shortopts = "qf:F:s:b:c:Q:g:";
 static struct option longopts[] =
 {
-  CF_LONG_OPTS
   { "quiet",           0, 0, 'q' },
   { "input-format",    0, 0, 'f' },
   { "output-format",   0, 0, 'F' },
@@ -69,7 +69,7 @@ main(int argc, char **argv)
 {
   log_init(argv[0]);
   int opt;
-  while ((opt = cf_getopt(argc, argv, shortopts, longopts, NULL)) >= 0)
+  while ((opt = getopt_long(argc, argv, shortopts, longopts, NULL)) >= 0)
     switch (opt)
       {
        case 'q':
@@ -176,6 +176,8 @@ main(int argc, char **argv)
           }
       if (background_color.color_space)
        io.background_color = background_color;
+      else if (!io.background_color.color_space)
+       io.background_color = color_white;
       if (channels_format)
         io.flags = io.flags & ~IMAGE_PIXEL_FORMAT | channels_format;
       if (!(io.flags & IMAGE_ALPHA))
index 146f4b3f4d03bcfb464453074765483db85adc92..c4e8fc86c711735ffce54ea5b2e1c78b2de948b2 100644 (file)
@@ -99,7 +99,9 @@ image_io_read_header(struct image_io *io)
       break;
 
     case IMAGE_FORMAT_UNDEFINED:
-      // FIXME: auto-detect
+#if defined (CONFIG_IMAGES_LIBMAGICK)
+      return libmagick_read_header(io);
+#endif
       break;
 
     default:
@@ -147,6 +149,14 @@ image_io_read_data(struct image_io *io, int ref)
 #endif
       break;
 
+    case IMAGE_FORMAT_UNDEFINED:
+#if defined(CONFIG_IMAGES_LIBMAGICK)
+      result = libmagick_read_data(io);
+#else
+      ASSERT(0);
+#endif
+      break;
+
     default:
       ASSERT(0);
   }
@@ -201,7 +211,7 @@ image_io_write(struct image_io *io)
     default:
       break;
   }
-  image_thread_err(io->thread, IMAGE_ERR_INVALID_FILE_FORMAT, "Image format not supported.");
+  image_thread_err(io->thread, IMAGE_ERR_INVALID_FILE_FORMAT, "Output format not supported.");
   return 0;
 }
 
@@ -263,8 +273,10 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image
       if (io->cols != rdi->image->cols || io->rows != rdi->image->rows)
         {
          DBG("Scaling image");
-         rdi->need_transformations = ((io->flags ^ rdi->image->flags) & IMAGE_NEW_FLAGS);
-         struct image *img = image_new(io->thread, io->cols, io->rows, rdi->image->flags, rdi->need_transformations ? NULL : io->pool);
+         uns flags = rdi->image->flags;
+         if (!(rdi->need_transformations = ((io->flags ^ rdi->image->flags) & (IMAGE_NEW_FLAGS & ~IMAGE_PIXELS_ALIGNED))))
+           flags = io->flags;
+         struct image *img = image_new(io->thread, io->cols, io->rows, flags, rdi->need_transformations ? NULL : io->pool);
          if (unlikely(!img))
            {
              image_destroy(rdi->image);
@@ -303,6 +315,8 @@ image_io_read_data_finish(struct image_io_read_data_internals *rdi, struct image
          rdi->image = img;
        }
 
+      // FIXME: support for various color spaces
+
       ASSERT(!rdi->need_transformations);
     }