28#ifdef HAVE_GRAPHICSMAGICK
39#include <magick/api.h>
48static gboolean _supported_image(
const gchar *filename)
50 const char *extensions_whitelist[] = {
"tif",
"tiff",
"gif",
"jpc",
"jp2",
"bmp",
"dcm",
"jng",
51 "miff",
"mng",
"pbm",
"pnm",
"ppm",
"pgm",
"webp", NULL };
53 char *ext = g_strrstr(filename,
".");
57 if(!g_ascii_strncasecmp(ext, *
i, strlen(*
i)))
69 ExceptionInfo exception;
71 ImageInfo *image_info = NULL;
78 GetExceptionInfo(&exception);
79 image_info = CloneImageInfo((ImageInfo *)NULL);
81 g_strlcpy(image_info->filename, filename,
sizeof(image_info->filename));
83 image = ReadImage(image_info, &exception);
84 if(exception.severity != UndefinedException) CatchException(&exception);
87 fprintf(stderr,
"[GraphicsMagick_open] image `%s' not found\n", img->
filename);
94 if(IsCMYKColorspace(image->colorspace))
96 fprintf(stderr,
"[GraphicsMagick_open] error: CMYK images are not supported.\n");
101 width = image->columns;
109 img->
dsc.
bpp = 4 *
sizeof(float);
112 img->
flags &= ~DT_IMAGE_RAW;
113 img->
flags &= ~DT_IMAGE_HDR;
114 img->
flags &= ~DT_IMAGE_S_RAW;
121 if(image) DestroyImage(image);
122 if(image_info) DestroyImageInfo(image_info);
123 DestroyExceptionInfo(&exception);
130 fprintf(stderr,
"[GraphicsMagick_open] could not alloc full buffer for image `%s'\n", img->
filename);
137 float *bufprt = mipbuf + (size_t)4 *
row * img->
width;
138 int ret = DispatchImage(image, 0,
row,
width, 1,
"RGBP", FloatPixel, bufprt, &exception);
139 if(exception.severity != UndefinedException) CatchException(&exception);
140 if(ret != MagickPass)
142 fprintf(stderr,
"[GraphicsMagick_open] error reading image `%s'\n", img->
filename);
148 size_t profile_length;
149 const uint8_t *profile_data = (
const uint8_t *)GetImageProfile(image,
"ICM", &profile_length);
153 img->
profile = (uint8_t *)g_malloc0(profile_length);
154 memcpy(img->
profile, profile_data, profile_length);
157 if(image) DestroyImage(image);
158 if(image_info) DestroyImageInfo(image_info);
159 DestroyExceptionInfo(&exception);
163 if(image) DestroyImage(image);
164 if(image_info) DestroyImageInfo(image_info);
165 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