X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fio-libmagick.c;h=cdf58048ced1d69946e6ce3d11dc28b3c15cb3da;hb=4142115bf20293bef998d1f683ac7ce3008178fb;hp=44e45ddebad6c339aa53c7fdcf72e7a13346fd2b;hpb=23d9630d51a5db803d9ce3800f3dbeba97d2f535;p=libucw.git diff --git a/images/io-libmagick.c b/images/io-libmagick.c index 44e45dde..cdf58048 100644 --- a/images/io-libmagick.c +++ b/images/io-libmagick.c @@ -13,12 +13,15 @@ #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" + #include #include #include #include +#include #define MAX_FILE_SIZE (1 << 30) #define QUANTUM_SCALE (QuantumDepth - 8) @@ -27,6 +30,7 @@ #define ALPHA_TO_BYTE(x) (255 - QUANTUM_TO_BYTE(x)) #define BYTE_TO_ALPHA(x) (BYTE_TO_QUANTUM(255 - (x))) +static pthread_mutex_t libmagick_mutex = PTHREAD_MUTEX_INITIALIZER; static uns libmagick_counter; struct magick_read_data { @@ -38,18 +42,20 @@ struct magick_read_data { int libmagick_init(struct image_io *io UNUSED) { - // FIXME: lock + pthread_mutex_lock(&libmagick_mutex); if (!libmagick_counter++) InitializeMagick(NULL); + pthread_mutex_unlock(&libmagick_mutex); return 1; } void libmagick_cleanup(struct image_io *io UNUSED) { - // FIXME: lock + pthread_mutex_lock(&libmagick_mutex); if (!--libmagick_counter) DestroyMagick(); + pthread_mutex_unlock(&libmagick_mutex); } static void @@ -79,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; @@ -99,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; } @@ -176,7 +182,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; @@ -294,7 +300,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; @@ -304,7 +310,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; } @@ -378,7 +384,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; } @@ -387,12 +393,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; }