image-file.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /******************************************************************************
  2. Copyright (C) 2016 by Hugh Bailey <[email protected]>
  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. typedef struct gs_image_file gs_image_file_t;
  48. typedef struct gs_image_file2 gs_image_file2_t;
  49. typedef struct gs_image_file3 gs_image_file3_t;
  50. EXPORT void gs_image_file_init(gs_image_file_t *image, const char *file);
  51. EXPORT void gs_image_file_free(gs_image_file_t *image);
  52. EXPORT void gs_image_file_init_texture(gs_image_file_t *image);
  53. EXPORT bool gs_image_file_tick(gs_image_file_t *image,
  54. uint64_t elapsed_time_ns);
  55. EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
  56. EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
  57. EXPORT bool gs_image_file2_tick(gs_image_file2_t *if2,
  58. uint64_t elapsed_time_ns);
  59. EXPORT void gs_image_file2_update_texture(gs_image_file2_t *if2);
  60. EXPORT void gs_image_file3_init(gs_image_file3_t *if3, const char *file,
  61. enum gs_image_alpha_mode alpha_mode);
  62. EXPORT bool gs_image_file3_tick(gs_image_file3_t *if3,
  63. uint64_t elapsed_time_ns);
  64. EXPORT void gs_image_file3_update_texture(gs_image_file3_t *if3);
  65. static void gs_image_file2_free(gs_image_file2_t *if2)
  66. {
  67. gs_image_file_free(&if2->image);
  68. if2->mem_usage = 0;
  69. }
  70. static void gs_image_file2_init_texture(gs_image_file2_t *if2)
  71. {
  72. gs_image_file_init_texture(&if2->image);
  73. }
  74. static void gs_image_file3_free(gs_image_file3_t *if3)
  75. {
  76. gs_image_file2_free(&if3->image2);
  77. }
  78. static void gs_image_file3_init_texture(gs_image_file3_t *if3)
  79. {
  80. gs_image_file2_init_texture(&if3->image2);
  81. }
  82. #ifdef __cplusplus
  83. }
  84. #endif