28#ifdef HAVE_GRAPHICSMAGICK
40#include <magick/api.h>
49static gboolean _supported_image(
const gchar *filename)
51 const char *extensions_whitelist[] = {
"tif",
"tiff",
"gif",
"jpc",
"jp2",
"bmp",
"dcm",
"jng",
52 "miff",
"mng",
"pbm",
"pnm",
"ppm",
"pgm",
"webp", NULL };
54 char *ext = g_strrstr(filename,
".");
58 if(!g_ascii_strncasecmp(ext, *
i, strlen(*
i)))
70 ExceptionInfo exception;
72 ImageInfo *image_info = NULL;
79 GetExceptionInfo(&exception);
80 image_info = CloneImageInfo((ImageInfo *)NULL);
82 g_strlcpy(image_info->filename, filename,
sizeof(image_info->filename));
90 image = ReadImage(image_info, &exception);
91 if(exception.severity != UndefinedException) CatchException(&exception);
94 fprintf(stderr,
"[GraphicsMagick_open] image `%s' not found\n", img->
filename);
101 if(IsCMYKColorspace(image->colorspace))
103 fprintf(stderr,
"[GraphicsMagick_open] error: CMYK images are not supported.\n");
108 width = image->columns;
116 img->
dsc.
bpp = 4 *
sizeof(float);
119 img->
flags &= ~DT_IMAGE_RAW;
120 img->
flags &= ~DT_IMAGE_HDR;
121 img->
flags &= ~DT_IMAGE_S_RAW;
128 DT_MAGICK_ABORT_GUARD_DISARM();
129 if(image) DestroyImage(image);
130 if(image_info) DestroyImageInfo(image_info);
131 DestroyExceptionInfo(&exception);
138 fprintf(stderr,
"[GraphicsMagick_open] could not alloc full buffer for image `%s'\n", img->
filename);
145 float *bufprt = mipbuf + (size_t)4 *
row * img->
width;
146 int ret = DispatchImage(image, 0,
row,
width, 1,
"RGBP", FloatPixel, bufprt, &exception);
147 if(exception.severity != UndefinedException) CatchException(&exception);
148 if(ret != MagickPass)
150 fprintf(stderr,
"[GraphicsMagick_open] error reading image `%s'\n", img->
filename);
156 size_t profile_length;
157 const uint8_t *profile_data = (
const uint8_t *)GetImageProfile(image,
"ICM", &profile_length);
161 img->
profile = (uint8_t *)g_malloc0(profile_length);
162 memcpy(img->
profile, profile_data, profile_length);
165 DT_MAGICK_ABORT_GUARD_DISARM();
166 if(image) DestroyImage(image);
167 if(image_info) DestroyImageInfo(image_info);
168 DestroyExceptionInfo(&exception);
172 DT_MAGICK_ABORT_GUARD_DISARM();
173 if(image) DestroyImage(image);
174 if(image_info) DestroyImageInfo(image_info);
175 DestroyExceptionInfo(&exception);
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_gm(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