color-source.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <obs-module.h>
  2. struct color_source {
  3. uint32_t color;
  4. uint32_t width;
  5. uint32_t height;
  6. obs_source_t *src;
  7. };
  8. static const char *color_source_get_name(void *unused)
  9. {
  10. UNUSED_PARAMETER(unused);
  11. return obs_module_text("ColorSource");
  12. }
  13. static void color_source_update(void *data, obs_data_t *settings)
  14. {
  15. struct color_source *context = data;
  16. uint32_t color = (uint32_t)obs_data_get_int(settings, "color");
  17. uint32_t width = (uint32_t)obs_data_get_int(settings, "width");
  18. uint32_t height = (uint32_t)obs_data_get_int(settings, "height");
  19. context->color = color;
  20. context->width = width;
  21. context->height = height;
  22. }
  23. static void *color_source_create(obs_data_t *settings, obs_source_t *source)
  24. {
  25. UNUSED_PARAMETER(source);
  26. struct color_source *context = bzalloc(sizeof(struct color_source));
  27. context->src = source;
  28. color_source_update(context, settings);
  29. return context;
  30. }
  31. static void color_source_destroy(void *data)
  32. {
  33. bfree(data);
  34. }
  35. static obs_properties_t *color_source_properties(void *unused)
  36. {
  37. UNUSED_PARAMETER(unused);
  38. obs_properties_t *props = obs_properties_create();
  39. obs_properties_add_color(props, "color",
  40. obs_module_text("ColorSource.Color"));
  41. obs_properties_add_int(props, "width",
  42. obs_module_text("ColorSource.Width"), 0, 4096, 1);
  43. obs_properties_add_int(props, "height",
  44. obs_module_text("ColorSource.Height"), 0, 4096, 1);
  45. return props;
  46. }
  47. static void color_source_render(void *data, gs_effect_t *effect)
  48. {
  49. UNUSED_PARAMETER(effect);
  50. struct color_source *context = data;
  51. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  52. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  53. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  54. struct vec4 colorVal;
  55. vec4_from_rgba(&colorVal, context->color);
  56. gs_effect_set_vec4(color, &colorVal);
  57. gs_technique_begin(tech);
  58. gs_technique_begin_pass(tech, 0);
  59. gs_draw_sprite(0, 0, context->width, context->height);
  60. gs_technique_end_pass(tech);
  61. gs_technique_end(tech);
  62. }
  63. static uint32_t color_source_getwidth(void *data)
  64. {
  65. struct color_source *context = data;
  66. return context->width;
  67. }
  68. static uint32_t color_source_getheight(void *data)
  69. {
  70. struct color_source *context = data;
  71. return context->height;
  72. }
  73. static void color_source_defaults(obs_data_t *settings)
  74. {
  75. struct obs_video_info ovi;
  76. obs_get_video_info(&ovi);
  77. obs_data_set_default_int(settings, "color", 0xFFFFFFFF);
  78. obs_data_set_default_int(settings, "width", ovi.base_width);
  79. obs_data_set_default_int(settings, "height", ovi.base_height);
  80. }
  81. struct obs_source_info color_source_info = {
  82. .id = "color_source",
  83. .type = OBS_SOURCE_TYPE_INPUT,
  84. .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW,
  85. .create = color_source_create,
  86. .destroy = color_source_destroy,
  87. .update = color_source_update,
  88. .get_name = color_source_get_name,
  89. .get_defaults = color_source_defaults,
  90. .get_width = color_source_getwidth,
  91. .get_height = color_source_getheight,
  92. .video_render = color_source_render,
  93. .get_properties = color_source_properties
  94. };