30#ifdef HAVE_IMAGEMAGICK
46#include <MagickWand/MagickWand.h>
53static gboolean _supported_image(
const gchar *filename)
55 const char *extensions_whitelist[] = {
"tif",
"tiff",
"gif",
"jpc",
"jp2",
"bmp",
"dcm",
"jng",
56 "miff",
"mng",
"pbm",
"pnm",
"ppm",
"pgm",
"webp", NULL };
58 char *ext = g_strrstr(filename,
".");
62 if(!g_ascii_strncasecmp(ext, *
i, strlen(*
i)))
74 MagickWand *image = NULL;
75 MagickBooleanType
ret;
81 image = NewMagickWand();
90 ret = MagickReadImage(image, filename);
91 if (ret != MagickTrue) {
92 fprintf(stderr,
"[ImageMagick_open] cannot open `%s'\n", img->
filename);
98 ColorspaceType colorspace;
100 colorspace = MagickGetImageColorspace(image);
102 if((colorspace == CMYColorspace) || (colorspace == CMYKColorspace))
104 fprintf(stderr,
"[ImageMagick_open] error: CMY(K) images are not supported.\n");
109 img->
width = MagickGetImageWidth(image);
110 img->
height = MagickGetImageHeight(image);
114 img->
dsc.
bpp = 4 *
sizeof(float);
117 img->
flags &= ~DT_IMAGE_RAW;
118 img->
flags &= ~DT_IMAGE_S_RAW;
119 img->
flags &= ~DT_IMAGE_HDR;
126 DT_MAGICK_ABORT_GUARD_DISARM();
127 DestroyMagickWand(image);
134 "[ImageMagick_open] could not alloc full buffer for image `%s'\n",
140 ret = MagickExportImagePixels(image, 0, 0, img->
width, img->
height,
"RGBP", FloatPixel, mipbuf);
141 if (ret != MagickTrue) {
143 "[ImageMagick_open] error reading image `%s'\n", img->
filename);
147 size_t profile_length;
148 uint8_t *profile_data = (uint8_t *)MagickGetImageProfile(image,
"icc", &profile_length);
151 profile_data = (uint8_t *)MagickGetImageProfile(image,
"icm", &profile_length);
155 img->
profile = (uint8_t *)g_malloc0(profile_length);
156 memcpy(img->
profile, profile_data, profile_length);
157 MagickRelinquishMemory(profile_data);
160 DT_MAGICK_ABORT_GUARD_DISARM();
161 DestroyMagickWand(image);
165 DT_MAGICK_ABORT_GUARD_DISARM();
166 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