Subversion Repositories Kolibri OS

Rev

Rev 9558 | Rev 9810 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* Written by turbocat2001 (Logaev Maxim) */
  2.  
  3. #ifndef KOLIBRI_LIBIMG_H
  4. #define KOLIBRI_LIBIMG_H
  5.  
  6. #include <stddef.h>
  7. #include <stdbool.h>
  8.  
  9. //list of format id's
  10. #define LIBIMG_FORMAT_BMP       1
  11. #define LIBIMG_FORMAT_ICO       2
  12. #define LIBIMG_FORMAT_CUR       3
  13. #define LIBIMG_FORMAT_GIF       4
  14. #define LIBIMG_FORMAT_PNG       5
  15. #define LIBIMG_FORMAT_JPEG      6
  16. #define LIBIMG_FORMAT_TGA       7
  17. #define LIBIMG_FORMAT_PCX       8
  18. #define LIBIMG_FORMAT_XCF       9
  19. #define LIBIMG_FORMAT_TIFF      10
  20. #define LIBIMG_FORMAT_PNM       11
  21. #define LIBIMG_FORMAT_WBMP      12
  22. #define LIBIMG_FORMAT_XBM       13
  23. #define LIBIMG_FORMAT_Z80       14
  24.  
  25. #pragma pack(push, 1)
  26. typedef struct{
  27.   uint32_t Checksum; // ((Width ROL 16) OR Height) XOR Data[0]        ; ignored so far
  28.   uint32_t Width;
  29.   uint32_t Height;
  30.   uint32_t Next;
  31.   uint32_t Previous;
  32.   uint32_t Type;     // one of Image.bppN
  33.   uint32_t* Data;
  34.   uint32_t Palette;  // used iff Type eq Image.bpp1, Image.bpp2, Image.bpp4 or Image.bpp8i
  35.   uint32_t Extended;
  36.   uint32_t Flags;    // bitfield
  37.   uint32_t Delay;    // used iff Image.IsAnimated is set in Flags
  38. } Image;
  39. #pragma pack(pop)
  40.  
  41. #define IMAGE_BPP8i  1  // indexed
  42. #define IMAGE_BPP24  2
  43. #define IMAGE_BPP32  3
  44. #define IMAGE_BPP15  4
  45. #define IMAGE_BPP16  5
  46. #define IMAGE_BPP1   6
  47. #define IMAGE_BPP8g  7  // grayscale
  48. #define IMAGE_BPP2i  8
  49. #define IMAGE_BPP4i  9
  50. #define IMAGE_BPP8a 10
  51.  
  52. // scale type
  53. #define LIBIMG_SCALE_NONE       0
  54. #define LIBIMG_SCALE_INTEGER    1  
  55. #define LIBIMG_SCALE_TILE       2    
  56. #define LIBIMG_SCALE_STRETCH    3  
  57. #define LIBIMG_SCALE_FIT_BOTH   LIBIMG_SCALE_STRETCH
  58. #define LIBIMG_SCALE_FIT_MIN    4
  59. #define LIBIMG_SCALE_FIT_RECT   LIBIMG_SCALE_FIT_MIN
  60. #define LIBIMG_SCALE_FIT_WIDTH  5  
  61. #define LIBIMG_SCALE_FIT_HEIGHT 6
  62. #define LIBIMG_SCALE_FIT_MAX    7    
  63.  
  64. // interpolation algorithm
  65. #define LIBIMG_INTER_NONE       0     // use it with LIBIMG_SCALE_INTEGER, LIBIMG_SCALE_TILE, etc
  66. #define LIBIMG_INTER_BILINEAR   1
  67. #define LIBIMG_INTER_BICUBIC    2
  68. #define LIBIMG_INTER_LANCZOS    3
  69. #define LIBIMG_INTER_DEFAULT   LIBIMG_INTER_BILINEAR
  70.  
  71. //error codes
  72. #define LIBIMG_ERROR_OUT_OF_MEMORY      1
  73. #define LIBIMG_ERROR_FORMAT             2
  74. #define LIBIMG_ERROR_CONDITIONS         3
  75. #define LIBIMG_ERROR_BIT_DEPTH          4
  76. #define LIBIMG_ERROR_ENCODER            5
  77. #define LIBIMG_ERROR_SRC_TYPE           6
  78. #define LIBIMG_ERROR_SCALE              7
  79. #define LIBIMG_ERROR_INTER              8
  80. #define LIBIMG_ERROR_NOT_INPLEMENTED    9
  81. #define LIBIMG_ERROR_INVALID_INPUT      10
  82.  
  83. //encode flags (byte 0x02 of _common option)
  84. #define LIBIMG_ENCODE_STRICT_SPECIFIC   0x01
  85. #define LIBIMG_ENCODE_STRICT_BIT_DEPTH  0x02
  86. #define LIBIMG_ENCODE_DELETE_ALPHA      0x08
  87. #define LIBIMG_ENCODE_FLUSH_ALPHA       0x10
  88.  
  89. #define FLIP_VERTICAL   0x01
  90. #define FLIP_HORIZONTAL 0x02
  91.  
  92. #define ROTATE_90_CW    0x01
  93. #define ROTATE_180      0x02
  94. #define ROTATE_270_CW   0x03
  95. #define ROTATE_90_CCW   ROTATE_270_CW
  96. #define ROTATE_270_CCW  ROTATE_90_CW
  97.  
  98. extern Image* __stdcall (*img_decode)(void* file_data, uint32_t size, uint32_t b_color);
  99. extern Image* __stdcall (*img_encode)(Image* img, uint32_t length, uint32_t option);
  100. extern Image* __stdcall (*img_create)(uint32_t width, uint32_t height, uint32_t type);
  101. extern void   __stdcall (*img_to_rgb2)(Image* img, void *rgb_data);
  102. extern Image* __stdcall (*img_to_rgb)(Image* img);
  103. extern bool   __stdcall (*img_flip)(Image* img, uint32_t flip);
  104. extern bool   __stdcall (*img_flip_layer)(Image *img, uint32_t flip);
  105. extern bool   __stdcall (*img_rotate)(Image *img, uint32_t rotate);
  106. extern bool   __stdcall (*img_rotate_layer)(Image* data, uint32_t rotate);
  107. extern void   __stdcall (*img_draw)(Image *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t xoff,  uint32_t yoff);
  108. extern int32_t __stdcall (*img_count)(Image *img);
  109. extern bool   __stdcall (*img_destroy)(Image *img);
  110. extern bool   __stdcall (*img_destroy_layer)(Image* img);
  111. extern Image* __stdcall (*img_blend)(Image* dst, Image* src, uint32_t out_x, uint32_t out_y, uint32_t in_x, uint32_t in_y, uint32_t width, uint32_t height);
  112. extern Image* __stdcall (*img_convert)(Image *src, Image *dst, uint32_t dst_type, uint32_t, uint32_t);
  113. extern Image* __stdcall (*img_resize_data)(Image *src, uint32_t width, uint32_t height);
  114. extern Image* __stdcall (*img_scale)(Image* src, uint32_t crop_x, uint32_t crop_y, uint32_t crop_width, uint32_t crop_height, Image* dst, uint32_t scale_type, uint32_t inter, uint32_t new_width, uint32_t new_height);
  115.  
  116. void img_fill_color(Image* img, uint32_t width, uint32_t height, uint32_t color){
  117.     for (uint32_t i = 0; i < width*height; i++) {
  118.         img->Data[i] = color;
  119.     }
  120. }
  121.  
  122. int kolibri_libimg_init(void);
  123.  
  124. #endif /* KOLIBRI_LIBIMG_H */
  125.