I forgot that image_external.c requires both OpenCV and LibRaw. Please replace the content of image_external.c with the following code:
/* Include required header */
#include "WolframLibrary.h"
#include "WolframImageLibrary.h"
#include "libraw.h"
/* Return the version of Library Link */
DLLEXPORT mint WolframLibrary_getVersion( ) {
return WolframLibraryVersion;
}
/* Initialize Library */
DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData) {
return LIBRARY_NO_ERROR;
}
/* Uninitialize Library */
DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) {
return;
}
EXTERN_C DLLEXPORT int read_raw_image(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument res) {
int err;
int check;
MImage out;
char * file;
libraw_data_t *iprc = libraw_init(0);
libraw_processed_image_t * img;
WolframImageLibrary_Functions imgFuns = libData->imageLibraryFunctions;
err = LIBRARY_FUNCTION_ERROR;
file = MArgument_getUTF8String(Args[0]);
libraw_open_file(iprc, file);
libraw_unpack(iprc);
iprc->params.output_bps = 8;
check = libraw_dcraw_process(iprc);
if (check != LIBRAW_SUCCESS) goto cleanup;
img = libraw_dcraw_make_mem_image(iprc, &check);
if (img == NULL) goto cleanup;
if (img->type != LIBRAW_IMAGE_BITMAP || img->colors != 3) goto cleanup;
if (img->bits == 16) {
raw_t_ubit16 * raw_data = (raw_t_ubit16*)img->data;
imgFuns->MImage_new2D(img->width, img->height, 3, MImage_Type_Bit16, MImage_CS_RGB, 1, &out);
memcpy(imgFuns->MImage_getBit16Data(out), raw_data, img->width * img->height * 3 * sizeof(raw_t_ubit16));
} else if (img->bits == 8) {
raw_t_ubit8 * raw_data = (raw_t_ubit8*)img->data;
imgFuns->MImage_new2D(img->width, img->height, 3, MImage_Type_Bit8, MImage_CS_RGB, 1, &out);
memcpy(imgFuns->MImage_getByteData(out), raw_data, img->width * img->height * 3 * sizeof(raw_t_ubit8));
} else {
goto cleanup;
}
MArgument_setMImage(res, out);
err = LIBRARY_NO_ERROR;
cleanup:
libData->UTF8String_disown(file);
libraw_dcraw_clear_mem(img);
return err;
}