image.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * File : image.h
  3. * This file is part of RT-Thread GUI Engine
  4. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-10-16 Bernard first version
  23. */
  24. #ifndef __RTGUI_IMAGE_H__
  25. #define __RTGUI_IMAGE_H__
  26. #include <rtgui/dc.h>
  27. #include <rtgui/filerw.h>
  28. #include <rtgui/region.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. struct rtgui_image;
  33. struct rtgui_image_engine
  34. {
  35. const char *name;
  36. struct rtgui_list_node list;
  37. /* image engine function */
  38. rt_bool_t (*image_check)(struct rtgui_filerw *file);
  39. rt_bool_t (*image_load)(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
  40. void (*image_unload)(struct rtgui_image *image);
  41. void (*image_blit)(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
  42. };
  43. struct rtgui_image_palette
  44. {
  45. rtgui_color_t *colors;
  46. rt_uint32_t ncolors;
  47. };
  48. typedef struct rtgui_image_palette rtgui_image_palette_t;
  49. struct rtgui_image
  50. {
  51. /* image metrics */
  52. rt_uint16_t w, h;
  53. /* image engine */
  54. const struct rtgui_image_engine *engine;
  55. /* image palette */
  56. rtgui_image_palette_t *palette;
  57. /* image private data */
  58. void *data;
  59. };
  60. typedef struct rtgui_image rtgui_image_t;
  61. /* init rtgui image system */
  62. void rtgui_system_image_init(void);
  63. #if defined(RTGUI_USING_DFS_FILERW)
  64. struct rtgui_image_engine *rtgui_image_get_engine_by_filename(const char *fn);
  65. struct rtgui_image *rtgui_image_create_from_file(const char *type, const char *filename, rt_bool_t load);
  66. struct rtgui_image *rtgui_image_create(const char *filename, rt_bool_t load);
  67. #endif
  68. struct rtgui_image *rtgui_image_create_from_mem(const char *type, const rt_uint8_t *data, rt_size_t length, rt_bool_t load);
  69. void rtgui_image_destroy(struct rtgui_image *image);
  70. /* get image's rect */
  71. void rtgui_image_get_rect(struct rtgui_image *image, struct rtgui_rect *rect);
  72. /* register an image engine */
  73. void rtgui_image_register_engine(struct rtgui_image_engine *engine);
  74. /* blit an image on DC */
  75. void rtgui_image_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
  76. struct rtgui_image_palette *rtgui_image_palette_create(rt_uint32_t ncolors);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif