image-file.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "graphics.h"
  16. #include "libnsgif/libnsgif.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct gs_image_file {
  21. gs_texture_t *texture;
  22. enum gs_color_format format;
  23. uint32_t cx;
  24. uint32_t cy;
  25. bool is_animated_gif;
  26. bool frame_updated;
  27. bool loaded;
  28. gif_animation gif;
  29. uint8_t *gif_data;
  30. uint8_t **animation_frame_cache;
  31. uint8_t *animation_frame_data;
  32. uint64_t cur_time;
  33. int cur_frame;
  34. int cur_loop;
  35. int last_decoded_frame;
  36. uint8_t *texture_data;
  37. gif_bitmap_callback_vt bitmap_callbacks;
  38. };
  39. struct gs_image_file2 {
  40. struct gs_image_file image;
  41. uint64_t mem_usage;
  42. };
  43. struct gs_image_file3 {
  44. struct gs_image_file2 image2;
  45. enum gs_image_alpha_mode alpha_mode;
  46. };
  47. struct gs_image_file4 {
  48. struct gs_image_file3 image3;
  49. enum gs_color_space space;
  50. };
  51. typedef struct gs_image_file gs_image_file_t;
  52. typedef struct gs_image_file2 gs_image_file2_t;
  53. typedef struct gs_image_file3 gs_image_file3_t;
  54. typedef struct gs_image_file4 gs_image_file4_t;
  55. EXPORT void gs_image_file_init(gs_image_file_t *image, const char *file);
  56. EXPORT void gs_image_file_free(gs_image_file_t *image);
  57. EXPORT void gs_image_file_init_texture(gs_image_file_t *image);
  58. EXPORT bool gs_image_file_tick(gs_image_file_t *image, uint64_t elapsed_time_ns);
  59. EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
  60. EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
  61. EXPORT bool gs_image_file2_tick(gs_image_file2_t *if2, uint64_t elapsed_time_ns);
  62. EXPORT void gs_image_file2_update_texture(gs_image_file2_t *if2);
  63. EXPORT void gs_image_file3_init(gs_image_file3_t *if3, const char *file, enum gs_image_alpha_mode alpha_mode);
  64. EXPORT bool gs_image_file3_tick(gs_image_file3_t *if3, uint64_t elapsed_time_ns);
  65. EXPORT void gs_image_file3_update_texture(gs_image_file3_t *if3);
  66. EXPORT void gs_image_file4_init(gs_image_file4_t *if4, const char *file, enum gs_image_alpha_mode alpha_mode);
  67. EXPORT bool gs_image_file4_tick(gs_image_file4_t *if4, uint64_t elapsed_time_ns);
  68. EXPORT void gs_image_file4_update_texture(gs_image_file4_t *if4);
  69. static inline void gs_image_file2_free(gs_image_file2_t *if2)
  70. {
  71. gs_image_file_free(&if2->image);
  72. if2->mem_usage = 0;
  73. }
  74. static inline void gs_image_file2_init_texture(gs_image_file2_t *if2)
  75. {
  76. gs_image_file_init_texture(&if2->image);
  77. }
  78. static inline void gs_image_file3_free(gs_image_file3_t *if3)
  79. {
  80. gs_image_file2_free(&if3->image2);
  81. }
  82. static inline void gs_image_file3_init_texture(gs_image_file3_t *if3)
  83. {
  84. gs_image_file2_init_texture(&if3->image2);
  85. }
  86. static inline void gs_image_file4_free(gs_image_file4_t *if4)
  87. {
  88. gs_image_file3_free(&if4->image3);
  89. }
  90. static inline void gs_image_file4_init_texture(gs_image_file4_t *if4)
  91. {
  92. gs_image_file3_init_texture(&if4->image3);
  93. }
  94. #ifdef __cplusplus
  95. }
  96. #endif