From a0cf13df6930e95973c2494a1f8650305c5b5fa7 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 9 Aug 2006 17:12:36 +0200 Subject: [PATCH] small changes to image-tool - can read more formats with GraphicsMagick --- images/image-tool.c | 10 ++++++---- images/io-main.c | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/images/image-tool.c b/images/image-tool.c index b52d59fd..f2170038 100644 --- a/images/image-tool.c +++ b/images/image-tool.c @@ -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 #include #include #include @@ -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)) diff --git a/images/io-main.c b/images/io-main.c index 146f4b3f..c4e8fc86 100644 --- a/images/io-main.c +++ b/images/io-main.c @@ -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); } -- 2.39.2