2 * Image Library -- GrapgicsMagick
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 #include "images/images.h"
14 #include <sys/types.h>
17 #include <magick/api.h>
20 libmagick_read_header(struct image_io *io)
22 image_thread_err(io->thread, IMAGE_ERR_NOT_IMPLEMENTED, "GraphicsMagick read not implemented.");
27 libmagick_read_data(struct image_io *io UNUSED)
33 libmagick_write(struct image_io *io)
35 image_thread_err(io->thread, IMAGE_ERR_NOT_IMPLEMENTED, "GraphicsMagick write not implemented.");
40 struct magick_internals {
41 ExceptionInfo exception;
42 QuantizeInfo quantize;
47 magick_cleanup(struct image_io *io)
49 DestroyImageInfo(io->internals->info);
50 DestroyExceptionInfo(&io->internals->exception);
55 magick_read_header(struct image_io *io)
57 DBG("magick_read_header()");
58 struct magick_internals *i = io->internals = mp_alloc(io->pool, sizeof(*i));
60 InitializeMagick(NULL);
61 GetExceptionInfo(&i->exception);
62 i->info = CloneImageInfo(NULL);
63 i->info->subrange = 1;
64 GetQuantizeInfo(&i->quantize);
65 i->quantize.colorspace = RGBColorspace;
67 uns len = bfilesize(io->fastbuf);
68 byte *buf = mp_alloc(io->pool, len);
69 len = bread(io->fastbuf, buf, len);
71 Image *image = BlobToImage(magick_info, imo->thumb_data, imo->thumb_size, &magick_exception);
83 magick_read_data(struct image_io *io)
85 DBG("magick_read_data()");
94 magick_decompress_thumbnail(struct image_obj *imo)
96 DBG("Quantizing image");
97 QuantizeImage(&magick_quantize, image);
98 DBG("Converting pixels");
99 PixelPacket *pixels = (PixelPacket *)AcquireImagePixels(image, 0, 0, image->columns, image->rows, &magick_exception);
101 uns size = image->columns * image->rows;
102 byte *p = imo->thumb.pixels = mp_alloc(imo->pool, imo->thumb.size = size * 3);
103 for (uns i = 0; i < size; i++)
105 p[0] = pixels->red >> (QuantumDepth - 8);
106 p[1] = pixels->green >> (QuantumDepth - 8);
107 p[2] = pixels->blue >> (QuantumDepth - 8);