image-file.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. typedef struct gs_image_file gs_image_file_t;
  44. typedef struct gs_image_file2 gs_image_file2_t;
  45. EXPORT void gs_image_file_init(gs_image_file_t *image, const char *file);
  46. EXPORT void gs_image_file_free(gs_image_file_t *image);
  47. EXPORT void gs_image_file_init_texture(gs_image_file_t *image);
  48. EXPORT bool gs_image_file_tick(gs_image_file_t *image,
  49. uint64_t elapsed_time_ns);
  50. EXPORT void gs_image_file_update_texture(gs_image_file_t *image);
  51. EXPORT void gs_image_file2_init(gs_image_file2_t *if2, const char *file);
  52. static void gs_image_file2_free(gs_image_file2_t *if2)
  53. {
  54. gs_image_file_free(&if2->image);
  55. if2->mem_usage = 0;
  56. }
  57. static inline void gs_image_file2_init_texture(gs_image_file2_t *if2)
  58. {
  59. gs_image_file_init_texture(&if2->image);
  60. }
  61. static inline bool gs_image_file2_tick(gs_image_file2_t *if2,
  62. uint64_t elapsed_time_ns)
  63. {
  64. return gs_image_file_tick(&if2->image, elapsed_time_ns);
  65. }
  66. static inline void gs_image_file2_update_texture(gs_image_file2_t *if2)
  67. {
  68. gs_image_file_update_texture(&if2->image);
  69. }
  70. #ifdef __cplusplus
  71. }
  72. #endif