2014-06-28 10:07:55 -07:00
|
|
|
#include "graphics.h"
|
2017-09-05 13:30:24 -07:00
|
|
|
#include "obsconfig.h"
|
2014-06-28 10:07:55 -07:00
|
|
|
|
2014-07-04 11:34:15 -07:00
|
|
|
#define MAGICKCORE_QUANTUM_DEPTH 16
|
2019-06-22 22:13:45 -07:00
|
|
|
#define MAGICKCORE_HDRI_ENABLE 0
|
2017-09-05 13:30:24 -07:00
|
|
|
|
|
|
|
#if LIBOBS_IMAGEMAGICK_DIR_STYLE == LIBOBS_IMAGEMAGICK_DIR_STYLE_6L
|
2014-06-28 10:07:55 -07:00
|
|
|
#include <magick/MagickCore.h>
|
2017-09-05 13:30:24 -07:00
|
|
|
#elif LIBOBS_IMAGEMAGICK_DIR_STYLE == LIBOBS_IMAGEMAGICK_DIR_STYLE_7GE
|
|
|
|
#include <MagickCore/MagickCore.h>
|
|
|
|
#endif
|
2014-06-28 10:07:55 -07:00
|
|
|
|
|
|
|
void gs_init_image_deps()
|
|
|
|
{
|
|
|
|
MagickCoreGenesis(NULL, MagickTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs_free_image_deps()
|
|
|
|
{
|
|
|
|
MagickCoreTerminus();
|
|
|
|
}
|
|
|
|
|
2016-01-17 17:33:41 -08:00
|
|
|
uint8_t *gs_create_texture_file_data(const char *file,
|
2019-06-22 22:13:45 -07:00
|
|
|
enum gs_color_format *format,
|
|
|
|
uint32_t *cx_out, uint32_t *cy_out)
|
2014-06-28 10:07:55 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
uint8_t *data = NULL;
|
|
|
|
ImageInfo *info;
|
2014-06-28 18:52:13 -07:00
|
|
|
ExceptionInfo *exception;
|
2019-06-22 22:13:45 -07:00
|
|
|
Image *image;
|
2014-06-28 10:07:55 -07:00
|
|
|
|
2014-06-28 18:52:13 -07:00
|
|
|
if (!file || !*file)
|
|
|
|
return NULL;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
info = CloneImageInfo(NULL);
|
2014-06-28 18:52:13 -07:00
|
|
|
exception = AcquireExceptionInfo();
|
|
|
|
|
2014-06-28 10:07:55 -07:00
|
|
|
strcpy(info->filename, file);
|
|
|
|
image = ReadImage(info, exception);
|
|
|
|
if (image) {
|
2019-06-22 22:13:45 -07:00
|
|
|
size_t cx = image->magick_columns;
|
|
|
|
size_t cy = image->magick_rows;
|
|
|
|
data = bmalloc(cx * cy * 4);
|
2014-06-28 10:07:55 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
ExportImagePixels(image, 0, 0, cx, cy, "BGRA", CharPixel, data,
|
|
|
|
exception);
|
2016-01-17 17:33:41 -08:00
|
|
|
if (exception->severity != UndefinedException) {
|
2019-06-22 22:13:45 -07:00
|
|
|
blog(LOG_WARNING,
|
|
|
|
"magickcore warning/error getting "
|
|
|
|
"pixels from file '%s': %s",
|
|
|
|
file, exception->reason);
|
2016-01-17 17:33:41 -08:00
|
|
|
bfree(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
2014-06-28 10:07:55 -07:00
|
|
|
|
2016-01-17 17:33:41 -08:00
|
|
|
*format = GS_BGRA;
|
|
|
|
*cx_out = (uint32_t)cx;
|
|
|
|
*cy_out = (uint32_t)cy;
|
2014-06-28 10:07:55 -07:00
|
|
|
DestroyImage(image);
|
|
|
|
|
|
|
|
} else if (exception->severity != UndefinedException) {
|
2019-06-22 22:13:45 -07:00
|
|
|
blog(LOG_WARNING,
|
|
|
|
"magickcore warning/error reading file "
|
|
|
|
"'%s': %s",
|
|
|
|
file, exception->reason);
|
2014-06-28 10:07:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DestroyImageInfo(info);
|
|
|
|
DestroyExceptionInfo(exception);
|
|
|
|
|
2016-01-17 17:33:41 -08:00
|
|
|
return data;
|
2014-06-28 10:07:55 -07:00
|
|
|
}
|