summaryrefslogtreecommitdiff
path: root/src/lib/emile/emile_image.h
blob: ef62d316d149d8281368701848d4a93bfc5f47e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef EMILE_IMAGE_H
#define EMILE_IMAGE_H

/* All the value from below enum should be the same as in Evas_Loader.h */
typedef enum _Emile_Colorspace
{
  EMILE_COLORSPACE_ARGB8888,/**< ARGB 32 bits per pixel, high-byte is Alpha, accessed 1 32bit word at a time */
  EMILE_COLORSPACE_YCBCR422P601_PL, /**< YCbCr 4:2:2 Planar, ITU.BT-601 specifications. The data pointed to is just an array of row pointer, pointing to the Y rows, then the Cb, then Cr rows */
  EMILE_COLORSPACE_YCBCR422P709_PL, /**< YCbCr 4:2:2 Planar, ITU.BT-709 specifications. The data pointed to is just an array of row pointer, pointing to the Y rows, then the Cb, then Cr rows */
  EMILE_COLORSPACE_RGB565_A5P, /**< 16bit rgb565 + Alpha plane at end - 5 bits of the 8 being used per alpha byte */
  EMILE_COLORSPACE_GRY8 = 4,
  EMILE_COLORSPACE_YCBCR422601_PL, /**<  YCbCr 4:2:2, ITU.BT-601 specifications. The data pointed to is just an array of row pointer, pointing to line of Y,Cb,Y,Cr bytes */
  EMILE_COLORSPACE_YCBCR420NV12601_PL, /**< YCbCr 4:2:0, ITU.BT-601 specification. The data pointed to is just an array of row pointer, pointing to the Y rows, then the Cb,Cr rows. */
  EMILE_COLORSPACE_YCBCR420TM12601_PL, /**< YCbCr 4:2:0, ITU.BT-601 specification. The data pointed to is just an array of tiled row pointer, pointing to the Y rows, then the Cb,Cr rows. */
  EMILE_COLORSPACE_AGRY88 = 8, /**< AY 8bits Alpha and 8bits Grey, accessed 1 16bits at a time */
  EMILE_COLORSPACE_ETC1 = 9, /**< OpenGL ETC1 encoding of RGB texture (4 bit per pixel) @since 1.10 */
  EMILE_COLORSPACE_RGB8_ETC2 = 10, /**< OpenGL GL_COMPRESSED_RGB8_ETC2 texture compression format (4 bit per pixel) @since 1.10 */
  EMILE_COLORSPACE_RGBA8_ETC2_EAC = 11, /**< OpenGL GL_COMPRESSED_RGBA8_ETC2_EAC texture compression format, supports alpha (8 bit per pixel) @since 1.10 */
  EMILE_COLORSPACE_ETC1_ALPHA = 12, /**< ETC1 with alpha support using two planes: ETC1 RGB and ETC1 grey for alpha @since 1.11 */
  EMILE_COLORSPACE_RGB_S3TC_DXT1 = 13,  /**< OpenGL COMPRESSED_RGB_S3TC_DXT1_EXT format with RGB only. @since 1.11 */
  EMILE_COLORSPACE_RGBA_S3TC_DXT1 = 14, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT1_EXT format with RGBA punchthrough. @since 1.11 */
  EMILE_COLORSPACE_RGBA_S3TC_DXT2 = 15, /**< DirectDraw DXT2 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */
  EMILE_COLORSPACE_RGBA_S3TC_DXT3 = 16, /**< OpenGL COMPRESSED_RGBA_S3TC_DXT3_EXT format with RGBA. @since 1.11 */
  EMILE_COLORSPACE_RGBA_S3TC_DXT4 = 17, /**< DirectDraw DXT4 format with premultiplied RGBA. Not supported by OpenGL itself. @since 1.11 */
  EMILE_COLORSPACE_RGBA_S3TC_DXT5 = 18  /**< OpenGL COMPRESSED_RGBA_S3TC_DXT5_EXT format with RGBA. @since 1.11 */
} Emile_Colorspace;

typedef enum _Emile_Image_Encoding
{
  EMILE_IMAGE_LOSSLESS = 0,
  EMILE_IMAGE_JPEG = 1,
  EMILE_IMAGE_ETC1 = 2,
  EMILE_IMAGE_ETC2_RGB = 3,
  EMILE_IMAGE_ETC2_RGBA = 4,
  EMILE_IMAGE_ETC1_ALPHA = 5
} Emile_Image_Encoding;

typedef enum _Emile_Image_Scale_Hint
{
  EMILE_IMAGE_SCALE_HINT_NONE = 0, /**< No scale hint at all */
  EMILE_IMAGE_SCALE_HINT_DYNAMIC = 1, /**< Image is being re-scaled over time, thus turning scaling cache @b off for its data */
  EMILE_IMAGE_SCALE_HINT_STATIC = 2 /**< Image is not being re-scaled over time, thus turning scaling cache @b on for its data */
} Emile_Image_Scale_Hint;

typedef enum _Emile_Image_Animated_Loop_Hint
{
  EMILE_IMAGE_ANIMATED_HINT_NONE = 0,
  EMILE_IMAGE_ANIMATED_HINT_LOOP = 1,
  EMILE_IMAGE_ANIMATED_HINT_PINGPONG = 2
} Emile_Image_Animated_Loop_Hint;

typedef enum _Emile_Image_Load_Error
{
   EMILE_IMAGE_LOAD_ERROR_NONE = 0, /**< No error on load */
   EMILE_IMAGE_LOAD_ERROR_GENERIC = 1, /**< A non-specific error occurred */
   EMILE_IMAGE_LOAD_ERROR_DOES_NOT_EXIST = 2, /**< File (or file path) does not exist */
   EMILE_IMAGE_LOAD_ERROR_PERMISSION_DENIED = 3, /**< Permission denied to an existing file (or path) */
   EMILE_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = 4, /**< Allocation of resources failure prevented load */
   EMILE_IMAGE_LOAD_ERROR_CORRUPT_FILE = 5, /**< File corrupt (but was detected as a known format) */
   EMILE_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT = 6 /**< File is not a known format */
} Emile_Image_Load_Error; /**< Emile image load error codes one can get - see emile_load_error_str() too. */

typedef struct _Emile_Image Emile_Image;
typedef struct _Emile_Image_Property Emile_Image_Property;
typedef struct _Emile_Image_Load_Opts Emile_Image_Load_Opts;
typedef struct _Emile_Image_Animated Emile_Image_Animated;

struct _Emile_Image_Property
{
   struct {
      unsigned char l, r, t, b;
   } borders;

   const Emile_Colorspace *cspaces;
   Emile_Colorspace cspace;

   Emile_Image_Encoding encoding;

   unsigned int w;
   unsigned int h;
   unsigned int row_stride;

   unsigned char scale;

   Eina_Bool rotated;
   Eina_Bool alpha;
   Eina_Bool premul;
   Eina_Bool alpha_sparse;

   Eina_Bool flipped;
   Eina_Bool comp;
};

struct _Emile_Image_Animated
{
   Eina_List *frames;

   Emile_Image_Animated_Loop_Hint loop_hint;

   int frame_count;
   int loop_count;
   int cur_frame;

   Eina_Bool animated;
};

struct _Emile_Image_Load_Opts
{
   Eina_Rectangle region;
   struct {
      int src_x, src_y, src_w, src_h;
      int dst_w, dst_h;
      int smooth;
      Emile_Image_Scale_Hint scale_hint;
   } scale_load;
   double dpi;
   unsigned int w, h;
   unsigned int degree;
   int scale_down_by;

   Eina_Bool orientation;
};

// FIXME: should we set region at load time, instead of head time

EAPI Emile_Image *emile_image_tgv_memory_open(Eina_Binbuf *source,
                                              Emile_Image_Load_Opts *opts,
                                              Emile_Image_Animated *animated,
                                              Emile_Image_Load_Error *error);
EAPI Emile_Image *emile_image_tgv_file_open(Eina_File *source,
                                            Emile_Image_Load_Opts *opts,
                                            Emile_Image_Animated *animated,
                                            Emile_Image_Load_Error *error);

EAPI Emile_Image *emile_image_jpeg_memory_open(Eina_Binbuf *source,
                                               Emile_Image_Load_Opts *opts,
                                               Emile_Image_Animated *animated,
                                               Emile_Image_Load_Error *error);
EAPI Emile_Image *emile_image_jpeg_file_open(Eina_File *source,
                                             Emile_Image_Load_Opts *opts,
                                             Emile_Image_Animated *animated,
                                             Emile_Image_Load_Error *error);

EAPI Eina_Bool emile_image_head(Emile_Image *image,
                                Emile_Image_Property *prop,
                                unsigned int property_size,
                                Emile_Image_Load_Error *error);
EAPI Eina_Bool emile_image_data(Emile_Image *image,
                                Emile_Image_Property *prop,
                                unsigned int property_size,
                                void *pixels,
                                Emile_Image_Load_Error *error);

EAPI void emile_image_close(Emile_Image *source);

EAPI const char *emile_load_error_str(Emile_Image *source,
                                      Emile_Image_Load_Error error);

#endif