2014-06-27 15:37:04 -07:00
|
|
|
#include <obs-module.h>
|
|
|
|
|
|
|
|
#define warn(format, ...) \
|
|
|
|
blog(LOG_WARNING, "[image_source: '%s'] " format, \
|
|
|
|
obs_source_getname(context->source), ##__VA_ARGS__)
|
|
|
|
|
|
|
|
struct image_source {
|
|
|
|
obs_source_t source;
|
|
|
|
|
|
|
|
texture_t tex;
|
|
|
|
uint32_t cx;
|
|
|
|
uint32_t cy;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *image_source_get_name(void)
|
|
|
|
{
|
2014-07-14 08:06:00 -07:00
|
|
|
return obs_module_text("ImageInput");
|
2014-06-27 15:37:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void image_source_update(void *data, obs_data_t settings)
|
|
|
|
{
|
|
|
|
struct image_source *context = data;
|
|
|
|
const char *file = obs_data_getstring(settings, "file");
|
|
|
|
|
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
|
|
|
|
if (context->tex) {
|
|
|
|
texture_destroy(context->tex);
|
|
|
|
context->tex = NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-24 00:25:05 -07:00
|
|
|
if (file && *file) {
|
2014-06-27 15:37:04 -07:00
|
|
|
context->tex = gs_create_texture_from_file(file);
|
|
|
|
if (context->tex) {
|
|
|
|
context->cx = texture_getwidth(context->tex);
|
|
|
|
context->cy = texture_getheight(context->tex);
|
|
|
|
} else {
|
|
|
|
warn("failed to load texture '%s'", file);
|
|
|
|
context->cx = 0;
|
|
|
|
context->cy = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_leavecontext();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *image_source_create(obs_data_t settings, obs_source_t source)
|
|
|
|
{
|
|
|
|
struct image_source *context = bzalloc(sizeof(struct image_source));
|
|
|
|
context->source = source;
|
|
|
|
|
|
|
|
image_source_update(context, settings);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void image_source_destroy(void *data)
|
|
|
|
{
|
|
|
|
struct image_source *context = data;
|
|
|
|
|
|
|
|
gs_entercontext(obs_graphics());
|
|
|
|
texture_destroy(context->tex);
|
|
|
|
gs_leavecontext();
|
|
|
|
|
|
|
|
bfree(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t image_source_getwidth(void *data)
|
|
|
|
{
|
|
|
|
struct image_source *context = data;
|
|
|
|
return context->cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t image_source_getheight(void *data)
|
|
|
|
{
|
|
|
|
struct image_source *context = data;
|
|
|
|
return context->cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void image_source_render(void *data, effect_t effect)
|
|
|
|
{
|
|
|
|
struct image_source *context = data;
|
|
|
|
if (!context->tex)
|
|
|
|
return;
|
|
|
|
|
2014-07-16 14:51:59 -07:00
|
|
|
gs_reset_blend_state();
|
2014-06-27 15:37:04 -07:00
|
|
|
effect_settexture(effect_getparambyname(effect, "image"), context->tex);
|
|
|
|
gs_draw_sprite(context->tex, 0, context->cx, context->cy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *image_filter =
|
|
|
|
"All formats (*.bmp *.tga *.png *.jpeg *.jpg *.gif);;"
|
|
|
|
"BMP Files (*.bmp);;"
|
|
|
|
"Targa Files (*.tga);;"
|
|
|
|
"PNG Files (*.png);;"
|
|
|
|
"JPEG Files (*.jpeg *.jpg);;"
|
|
|
|
"GIF Files (*.gif)";
|
|
|
|
|
|
|
|
static obs_properties_t image_source_properties(void)
|
|
|
|
{
|
|
|
|
obs_properties_t props = obs_properties_create();
|
|
|
|
|
2014-07-09 22:12:57 -07:00
|
|
|
obs_properties_add_path(props,
|
|
|
|
"file", obs_module_text("File"),
|
|
|
|
OBS_PATH_FILE, image_filter, NULL);
|
2014-06-27 15:37:04 -07:00
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct obs_source_info image_source_info = {
|
|
|
|
.id = "image_source",
|
|
|
|
.type = OBS_SOURCE_TYPE_INPUT,
|
|
|
|
.output_flags = OBS_SOURCE_VIDEO,
|
|
|
|
.getname = image_source_get_name,
|
|
|
|
.create = image_source_create,
|
|
|
|
.destroy = image_source_destroy,
|
|
|
|
.update = image_source_update,
|
|
|
|
.getwidth = image_source_getwidth,
|
|
|
|
.getheight = image_source_getheight,
|
|
|
|
.video_render = image_source_render,
|
|
|
|
.properties = image_source_properties
|
|
|
|
};
|
|
|
|
|
|
|
|
OBS_DECLARE_MODULE()
|
2014-07-09 22:12:57 -07:00
|
|
|
OBS_MODULE_USE_DEFAULT_LOCALE("image-source", "en-US")
|
2014-06-27 15:37:04 -07:00
|
|
|
|
|
|
|
bool obs_module_load(uint32_t libobs_version)
|
|
|
|
{
|
|
|
|
obs_register_source(&image_source_info);
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(libobs_version);
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-09 22:12:57 -07:00
|
|
|
|
|
|
|
void obs_module_unload(void)
|
|
|
|
{
|
|
|
|
OBS_MODULE_FREE_DEFAULT_LOCALE();
|
|
|
|
}
|