2 * Copyright (C) 2007 Florian octo Forster <octo at verplant.org>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <wand/magick-wand.h>
25 #include "utils_image.h"
27 ui_image_t *ui_create (uint32_t width, uint32_t height)
29 ui_image_t *img = NULL;
31 img = (ui_image_t *) malloc (sizeof (ui_image_t));
34 memset (img, '\0', sizeof (ui_image_t));
40 img->data = (uint8_t **) malloc (3 * sizeof (uint8_t *));
41 if (img->data == NULL)
47 /* FIXME: s/4/3 when bug is fixed! */
48 fprintf (stderr, "Theres still a bug in %s, line %i!\n",
50 img->data[0] = (uint8_t *) malloc (4 * width * height * sizeof (uint8_t));
51 if (img->data[0] == NULL)
57 memset (img->data[0], '\0', 3 * width * height * sizeof (uint8_t));
58 /* FIXME: Remove +16 */
59 img->data[1] = img->data[0] + (width * height);
60 img->data[2] = img->data[1] + (width * height);
63 } /* ui_image_t *ui_create */
65 ui_image_t *ui_create_file (const char *file)
68 MagickBooleanType status;
70 ui_image_t *img = NULL;
76 mwand = NewMagickWand ();
80 status = MagickReadImage (mwand, file);
81 if (status == MagickFalse)
83 DestroyMagickWand (mwand);
87 width = (uint32_t) MagickGetImageWidth (mwand);
88 height = (uint32_t) MagickGetImageHeight (mwand);
90 img = ui_create (width, height);
93 DestroyMagickWand (mwand);
97 for (i = 0; i < 3; i++)
103 case 0: map = "R"; break;
104 case 1: map = "G"; break;
105 case 2: map = "B"; break;
106 default: map = "*invalid*";
109 status = MagickGetImagePixels (mwand,
111 img->width, img->height,
112 map, CharPixel, (void *) img->data[i]);
113 if (status == MagickFalse)
115 } /* for (i = 0, 1, 2) */
116 if (status == MagickFalse)
122 DestroyMagickWand (mwand);
125 } /* ui_image_t *ui_create_file */
127 void ui_destroy (ui_image_t *img)
131 if (img->data != NULL)
133 if (img->data[0] != NULL)
139 } /* void ui_destroy */
142 * vim: set tabstop=8 softtabstop=2 shiftwidth=2 :