30#ifdef HAVE_IMAGEMAGICK
45#include <MagickWand/MagickWand.h>
52static gboolean _supported_image(
const gchar *filename)
54 const char *extensions_whitelist[] = {
"tif",
"tiff",
"gif",
"jpc",
"jp2",
"bmp",
"dcm",
"jng",
55 "miff",
"mng",
"pbm",
"pnm",
"ppm",
"pgm",
"webp", NULL };
57 char *ext = g_strrstr(filename,
".");
61 if(!g_ascii_strncasecmp(ext, *
i, strlen(*
i)))
73 MagickWand *image = NULL;
74 MagickBooleanType
ret;
80 image = NewMagickWand();
83 ret = MagickReadImage(image, filename);
84 if (ret != MagickTrue) {
85 fprintf(stderr,
"[ImageMagick_open] cannot open `%s'\n", img->
filename);
91 ColorspaceType colorspace;
93 colorspace = MagickGetImageColorspace(image);
95 if((colorspace == CMYColorspace) || (colorspace == CMYKColorspace))
97 fprintf(stderr,
"[ImageMagick_open] error: CMY(K) images are not supported.\n");
102 img->
width = MagickGetImageWidth(image);
103 img->
height = MagickGetImageHeight(image);
107 img->
dsc.
bpp = 4 *
sizeof(float);
110 img->
flags &= ~DT_IMAGE_RAW;
111 img->
flags &= ~DT_IMAGE_S_RAW;
112 img->
flags &= ~DT_IMAGE_HDR;
119 DestroyMagickWand(image);
126 "[ImageMagick_open] could not alloc full buffer for image `%s'\n",
132 ret = MagickExportImagePixels(image, 0, 0, img->
width, img->
height,
"RGBP", FloatPixel, mipbuf);
133 if (ret != MagickTrue) {
135 "[ImageMagick_open] error reading image `%s'\n", img->
filename);
139 size_t profile_length;
140 uint8_t *profile_data = (uint8_t *)MagickGetImageProfile(image,
"icc", &profile_length);
143 profile_data = (uint8_t *)MagickGetImageProfile(image,
"icm", &profile_length);
147 img->
profile = (uint8_t *)g_malloc0(profile_length);
148 memcpy(img->
profile, profile_data, profile_length);
149 MagickRelinquishMemory(profile_data);
152 DestroyMagickWand(image);
156 DestroyMagickWand(image);
static void error(char *msg)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
void dt_print(dt_debug_thread_t thread, const char *msg,...)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
int supported(struct dt_imageio_module_storage_t *storage, struct dt_imageio_module_format_t *format)
int dt_exif_read(dt_image_t *img, const char *path)
@ DT_IMAGEIO_FILE_CORRUPTED
@ DT_IMAGEIO_FILE_NOT_FOUND
dt_imageio_retval_t dt_imageio_open_im(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf)
void * dt_mipmap_cache_alloc(dt_mipmap_buffer_t *buf, const dt_image_t *img)
char filename[DT_MAX_FILENAME_LEN]
dt_iop_buffer_type_t datatype