]> mj.ucw.cz Git - libucw.git/blob - images/io-libmagick.c
backup of incomplete sources
[libucw.git] / images / io-libmagick.c
1 /*
2  *      Image Library -- GrapgicsMagick
3  *
4  *      (c) 2006 Pavel Charvat <pchar@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #define LOCAL_DEBUG
11
12 #include "lib/lib.h"
13 #include "images/images.h"
14 #include <sys/types.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <magick/api.h>
18
19 int
20 libmagick_read_header(struct image_io *io)
21 {
22   image_thread_err(io->thread, IMAGE_ERR_NOT_IMPLEMENTED, "GraphicsMagick read not implemented.");
23   return 0;
24 }
25
26 int
27 libmagick_read_data(struct image_io *io UNUSED)
28 {
29   ASSERT(0);
30 }
31
32 int
33 libmagick_write(struct image_io *io)
34 {
35   image_thread_err(io->thread, IMAGE_ERR_NOT_IMPLEMENTED, "GraphicsMagick write not implemented.");
36   return 0;
37 }
38
39 #if 0
40 struct magick_internals {
41   ExceptionInfo exception;
42   QuantizeInfo quantize;
43   ImageInfo *info;
44 };
45
46 static inline void
47 magick_cleanup(struct image_io *io)
48 {
49   DestroyImageInfo(io->internals->info);
50   DestroyExceptionInfo(&io->internals->exception);
51   DestroyMagick();
52 }
53
54 static int
55 magick_read_header(struct image_io *io)
56 {
57   DBG("magick_read_header()");
58   struct magick_internals *i = io->internals = mp_alloc(io->pool, sizeof(*i));
59
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;
66
67   uns len = bfilesize(io->fastbuf);
68   byte *buf = mp_alloc(io->pool, len);
69   len = bread(io->fastbuf, buf, len);
70
71   Image *image = BlobToImage(magick_info, imo->thumb_data, imo->thumb_size, &magick_exception);
72   if (unlikely(!image))
73     goto error;
74
75   // FIXME
76   return 1;
77 error:
78   magick_cleanup(io);
79   return 0;
80 }
81
82 static int
83 magick_read_data(struct image_io *io)
84 {
85   DBG("magick_read_data()");
86
87   // FIXME
88
89   magick_cleanup(io);
90   return 1;
91 }
92
93 static int
94 magick_decompress_thumbnail(struct image_obj *imo)
95 {
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);
100   ASSERT(pixels);
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++)
104     {
105       p[0] = pixels->red >> (QuantumDepth - 8);
106       p[1] = pixels->green >> (QuantumDepth - 8);
107       p[2] = pixels->blue >> (QuantumDepth - 8);
108       p += 3;
109       pixels++;
110     }
111   DestroyImage(image);
112   return 1;
113 }
114 #endif