0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/libobs/graphics/graphics-magick.c
jp9000 c9df41c1e2 (API Change) Remove pointers from all typedefs
Typedef pointers are unsafe.  If you do:
typedef struct bla *bla_t;
then you cannot use it as a constant, such as: const bla_t, because
that constant will be to the pointer itself rather than to the
underlying data.  I admit this was a fundamental mistake that must
be corrected.

All typedefs that were pointer types will now have their pointers
removed from the type itself, and the pointers will be used when they
are actually used as variables/parameters/returns instead.

This does not break ABI though, which is pretty nice.
2014-09-25 21:48:11 -07:00

60 lines
1.4 KiB
C

#include "graphics.h"
#define MAGICKCORE_QUANTUM_DEPTH 16
#define MAGICKCORE_HDRI_ENABLE 0
#include <magick/MagickCore.h>
void gs_init_image_deps()
{
MagickCoreGenesis(NULL, MagickTrue);
}
void gs_free_image_deps()
{
MagickCoreTerminus();
}
gs_texture_t *gs_texture_create_from_file(const char *file)
{
gs_texture_t *tex = NULL;
ImageInfo *info;
ExceptionInfo *exception;
Image *image;
if (!file || !*file)
return NULL;
info = CloneImageInfo(NULL);
exception = AcquireExceptionInfo();
strcpy(info->filename, file);
image = ReadImage(info, exception);
if (image) {
size_t cx = image->magick_columns;
size_t cy = image->magick_rows;
uint8_t *data = malloc(cx * cy * 4);
ExportImagePixels(image, 0, 0, cx, cy, "BGRA", CharPixel,
data, exception);
if (exception->severity == UndefinedException)
tex = gs_texture_create(cx, cy, GS_BGRA, 1,
(const uint8_t**)&data, 0);
else
blog(LOG_WARNING, "magickcore warning/error getting "
"pixels from file '%s': %s", file,
exception->reason);
free(data);
DestroyImage(image);
} else if (exception->severity != UndefinedException) {
blog(LOG_WARNING, "magickcore warning/error reading file "
"'%s': %s", file, exception->reason);
}
DestroyImageInfo(info);
DestroyExceptionInfo(exception);
return tex;
}