yolobs-studio/libobs/graphics/graphics-magick.c

73 lines
1.6 KiB
C
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
#include "graphics.h"
2018-02-19 19:54:37 +00:00
#include "obsconfig.h"
2016-02-23 23:16:51 +00:00
#define MAGICKCORE_QUANTUM_DEPTH 16
2019-09-22 21:19:10 +00:00
#define MAGICKCORE_HDRI_ENABLE 0
2018-02-19 19:54:37 +00:00
#if LIBOBS_IMAGEMAGICK_DIR_STYLE == LIBOBS_IMAGEMAGICK_DIR_STYLE_6L
2016-02-23 23:16:51 +00:00
#include <magick/MagickCore.h>
2018-02-19 19:54:37 +00:00
#elif LIBOBS_IMAGEMAGICK_DIR_STYLE == LIBOBS_IMAGEMAGICK_DIR_STYLE_7GE
#include <MagickCore/MagickCore.h>
#endif
2016-02-23 23:16:51 +00:00
void gs_init_image_deps()
{
MagickCoreGenesis(NULL, MagickTrue);
}
void gs_free_image_deps()
{
MagickCoreTerminus();
}
uint8_t *gs_create_texture_file_data(const char *file,
2019-09-22 21:19:10 +00:00
enum gs_color_format *format,
uint32_t *cx_out, uint32_t *cy_out)
2016-02-23 23:16:51 +00:00
{
2019-09-22 21:19:10 +00:00
uint8_t *data = NULL;
ImageInfo *info;
2016-02-23 23:16:51 +00:00
ExceptionInfo *exception;
2019-09-22 21:19:10 +00:00
Image *image;
2016-02-23 23:16:51 +00:00
if (!file || !*file)
return NULL;
2019-09-22 21:19:10 +00:00
info = CloneImageInfo(NULL);
2016-02-23 23:16:51 +00:00
exception = AcquireExceptionInfo();
strcpy(info->filename, file);
image = ReadImage(info, exception);
if (image) {
2019-09-22 21:19:10 +00:00
size_t cx = image->magick_columns;
size_t cy = image->magick_rows;
data = bmalloc(cx * cy * 4);
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
ExportImagePixels(image, 0, 0, cx, cy, "BGRA", CharPixel, data,
exception);
2016-02-23 23:16:51 +00:00
if (exception->severity != UndefinedException) {
2019-09-22 21:19:10 +00:00
blog(LOG_WARNING,
"magickcore warning/error getting "
"pixels from file '%s': %s",
file, exception->reason);
2016-02-23 23:16:51 +00:00
bfree(data);
data = NULL;
}
*format = GS_BGRA;
*cx_out = (uint32_t)cx;
*cy_out = (uint32_t)cy;
DestroyImage(image);
} else if (exception->severity != UndefinedException) {
2019-09-22 21:19:10 +00:00
blog(LOG_WARNING,
"magickcore warning/error reading file "
"'%s': %s",
file, exception->reason);
2016-02-23 23:16:51 +00:00
}
DestroyImageInfo(info);
DestroyExceptionInfo(exception);
return data;
}