X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=images%2Fio-libmagick.c;h=60d3615941c0330fa7fa833670ea394f5ef54026;hb=ca2850c6c8941faecb6e07be3379127330feb04a;hp=543f3f8effc5b5787c5b6383deb3c8fb88f68533;hpb=92ba4a64f2141f83341ee9f0b664324940f0c563;p=libucw.git diff --git a/images/io-libmagick.c b/images/io-libmagick.c index 543f3f8e..60d36159 100644 --- a/images/io-libmagick.c +++ b/images/io-libmagick.c @@ -13,6 +13,7 @@ #include "lib/mempool.h" #include "lib/fastbuf.h" #include "images/images.h" +#include "images/error.h" #include "images/color.h" #include "images/io-main.h" @@ -84,7 +85,7 @@ libmagick_read_header(struct image_io *io) sh_off_t file_size = bfilesize(io->fastbuf) - btell(io->fastbuf); if (unlikely(file_size > MAX_FILE_SIZE)) { - image_thread_err(io->thread, IMAGE_ERR_READ_FAILED, "Too long stream."); + IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Too long stream."); return 0; } uns buf_size = file_size; @@ -104,12 +105,12 @@ libmagick_read_header(struct image_io *io) xfree(buf); if (unlikely(!rd->image)) { - image_thread_err(io->thread, IMAGE_ERR_READ_FAILED, "GraphicsMagick failed to read the image."); + IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "GraphicsMagick failed to read the image."); goto err; } - if (unlikely(rd->image->columns > IMAGE_MAX_SIZE || rd->image->rows > IMAGE_MAX_SIZE)) + if (unlikely(rd->image->columns > image_max_dim || rd->image->rows > image_max_dim)) { - image_thread_err(io->thread, IMAGE_ERR_INVALID_DIMENSIONS, "Image too large."); + IMAGE_ERROR(io->context, IMAGE_ERROR_INVALID_DIMENSIONS, "Image too large."); goto err; } @@ -169,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); @@ -181,7 +185,7 @@ libmagick_read_data(struct image_io *io) PixelPacket *src = (PixelPacket *)AcquireImagePixels(rd->image, 0, 0, rd->image->columns, rd->image->rows, &rd->exception); if (unlikely(!src)) { - image_thread_err(io->thread, IMAGE_ERR_READ_FAILED, "Cannot acquire image pixels."); + IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Cannot acquire image pixels."); libmagick_destroy_read_data(rd); image_io_read_data_break(&rdi, io); return 0; @@ -278,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) { @@ -299,7 +304,7 @@ libmagick_write(struct image_io *io) Image *image = AllocateImage(info); if (unlikely(!image)) { - image_thread_err(io->thread, IMAGE_ERR_WRITE_FAILED, "GraphicsMagick failed to allocate the image."); + IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "GraphicsMagick failed to allocate the image."); goto err; } image->columns = img->cols; @@ -309,7 +314,7 @@ libmagick_write(struct image_io *io) PixelPacket *pixels = SetImagePixels(image, 0, 0, img->cols, img->rows), *dest = pixels; if (unlikely(!pixels)) { - image_thread_err(io->thread, IMAGE_ERR_WRITE_FAILED, "Cannot get GraphicsMagick pixels."); + IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "Cannot get GraphicsMagick pixels."); goto err2; } @@ -383,7 +388,7 @@ libmagick_write(struct image_io *io) /* Store pixels */ if (unlikely(!SyncImagePixels(image))) { - image_thread_err(io->thread, IMAGE_ERR_WRITE_FAILED, "Cannot sync GraphicsMagick pixels."); + IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "Cannot sync GraphicsMagick pixels."); goto err2; } @@ -392,12 +397,12 @@ libmagick_write(struct image_io *io) void *buf = ImageToBlob(info, image, &buf_len, &exception); if (unlikely(!buf)) { - image_thread_err(io->thread, IMAGE_ERR_WRITE_FAILED, "GraphicsMagick failed to compress the image."); + IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "GraphicsMagick failed to compress the image."); goto err2; } if (unlikely(buf_len > MAX_FILE_SIZE)) { - image_thread_err(io->thread, IMAGE_ERR_WRITE_FAILED, "Image too large."); + IMAGE_ERROR(io->context, IMAGE_ERROR_WRITE_FAILED, "Image too large."); goto err2; }