Tizen 2.0 Release
[framework/multimedia/gst-plugins-bad0.10.git] / ext / cog / cogframe.h
1
2 #ifndef __COG_FRAME_H__
3 #define __COG_FRAME_H__
4
5 #include <cog/cogutils.h>
6
7 COG_BEGIN_DECLS
8
9 typedef struct _CogFrame CogFrame;
10 typedef struct _CogFrameData CogFrameData;
11 typedef struct _CogUpsampledFrame CogUpsampledFrame;
12
13 typedef void (*CogFrameFreeFunc)(CogFrame *frame, void *priv);
14 typedef void (*CogFrameRenderFunc)(CogFrame *frame, void *dest, int component, int i);
15
16 typedef enum _CogColorMatrix {
17   COG_COLOR_MATRIX_UNKNOWN = 0,
18   COG_COLOR_MATRIX_HDTV,
19   COG_COLOR_MATRIX_SDTV
20 } CogColorMatrix;
21
22 typedef enum _CogChromaSite {
23   COG_CHROMA_SITE_UNKNOWN = 0,
24   COG_CHROMA_SITE_MPEG2 = 1,
25   COG_CHROMA_SITE_JPEG
26 } CogChromaSite;
27
28 /* bit pattern:
29  *  0x100 - 0: normal, 1: indirect (packed)
30  *  0x001 - horizontal chroma subsampling: 0: 1, 1: 2
31  *  0x002 - vertical chroma subsampling: 0: 1, 1: 2
32  *  0x00c - depth: 0: u8, 1: s16, 2: s32
33  *  */
34 typedef enum _CogFrameFormat {
35   COG_FRAME_FORMAT_U8_444 = 0x00,
36   COG_FRAME_FORMAT_U8_422 = 0x01,
37   COG_FRAME_FORMAT_U8_420 = 0x03,
38
39   COG_FRAME_FORMAT_S16_444 = 0x04,
40   COG_FRAME_FORMAT_S16_422 = 0x05,
41   COG_FRAME_FORMAT_S16_420 = 0x07,
42
43   COG_FRAME_FORMAT_S32_444 = 0x08,
44   COG_FRAME_FORMAT_S32_422 = 0x09,
45   COG_FRAME_FORMAT_S32_420 = 0x0b,
46
47   /* indirectly supported */
48   COG_FRAME_FORMAT_YUYV = 0x100, /* YUYV order */
49   COG_FRAME_FORMAT_UYVY = 0x101, /* UYVY order */
50   COG_FRAME_FORMAT_AYUV = 0x102,
51   COG_FRAME_FORMAT_RGB = 0x104,
52   COG_FRAME_FORMAT_v216 = 0x105,
53   COG_FRAME_FORMAT_v210 = 0x106,
54   COG_FRAME_FORMAT_RGBx = 0x110,
55   COG_FRAME_FORMAT_xRGB = 0x111,
56   COG_FRAME_FORMAT_BGRx = 0x112,
57   COG_FRAME_FORMAT_xBGR = 0x113,
58   COG_FRAME_FORMAT_RGBA = 0x114,
59   COG_FRAME_FORMAT_ARGB = 0x115,
60   COG_FRAME_FORMAT_BGRA = 0x116,
61   COG_FRAME_FORMAT_ABGR = 0x117,
62 } CogFrameFormat;
63
64 #define COG_FRAME_FORMAT_DEPTH(format) ((format) & 0xc)
65 #define COG_FRAME_FORMAT_DEPTH_U8 0x00
66 #define COG_FRAME_FORMAT_DEPTH_S16 0x04
67 #define COG_FRAME_FORMAT_DEPTH_S32 0x08
68
69 #define COG_FRAME_FORMAT_H_SHIFT(format) ((format) & 0x1)
70 #define COG_FRAME_FORMAT_V_SHIFT(format) (((format)>>1) & 0x1)
71
72 #define COG_FRAME_IS_PACKED(format) (((format)>>8) & 0x1)
73
74 #define COG_FRAME_CACHE_SIZE 8
75
76 struct _CogFrameData {
77   CogFrameFormat format;
78   void *data;
79   int stride;
80   int width;
81   int height;
82   int length;
83   int h_shift;
84   int v_shift;
85 };
86
87 struct _CogFrame {
88   int refcount;
89   CogFrameFreeFunc free;
90   CogMemoryDomain *domain;
91   void *regions[3];
92   void *priv;
93
94   CogFrameFormat format;
95   int width;
96   int height;
97
98   CogFrameData components[3];
99
100   int is_virtual;
101   int cache_offset[3];
102   int cached_lines[3][COG_FRAME_CACHE_SIZE];
103   CogFrame *virt_frame1;
104   CogFrame *virt_frame2;
105   void (*render_line) (CogFrame *frame, void *dest, int component, int i);
106   void *virt_priv;
107   void *virt_priv2;
108   int param1;
109   int param2;
110
111   int extension;
112 };
113
114 struct _CogUpsampledFrame {
115   CogFrame *frames[4];
116   void *components[3];
117 };
118
119 #define COG_FRAME_DATA_GET_LINE(fd,i) (COG_OFFSET((fd)->data,(fd)->stride*(i)))
120 #define COG_FRAME_DATA_GET_PIXEL_U8(fd,i,j) ((uint8_t *)COG_OFFSET((fd)->data,(fd)->stride*(j)+(i)))
121 #define COG_FRAME_DATA_GET_PIXEL_S16(fd,i,j) ((int16_t *)COG_OFFSET((fd)->data,(fd)->stride*(j)+(i)*sizeof(int16_t)))
122
123 CogFrame * cog_frame_new (void);
124 CogFrame * cog_frame_new_and_alloc (CogMemoryDomain *domain,
125     CogFrameFormat format, int width, int height);
126 CogFrame * cog_frame_new_from_data_I420 (void *data, int width, int height);
127 CogFrame * cog_frame_new_from_data_YV12 (void *data, int width, int height);
128 CogFrame * cog_frame_new_from_data_YUY2 (void *data, int width, int height);
129 CogFrame * cog_frame_new_from_data_UYVY (void *data, int width, int height);
130 CogFrame * cog_frame_new_from_data_UYVY_full (void *data, int width, int height, int stride);
131 CogFrame * cog_frame_new_from_data_AYUV (void *data, int width, int height);
132 CogFrame * cog_frame_new_from_data_v216 (void *data, int width, int height);
133 CogFrame * cog_frame_new_from_data_v210 (void *data, int width, int height);
134 CogFrame * cog_frame_new_from_data_Y42B (void *data, int width, int height);
135 CogFrame * cog_frame_new_from_data_Y444 (void *data, int width, int height);
136 CogFrame * cog_frame_new_from_data_RGB (void *data, int width, int height);
137 CogFrame * cog_frame_new_from_data_RGBx (void *data, int width, int height);
138 CogFrame * cog_frame_new_from_data_xRGB (void *data, int width, int height);
139 CogFrame * cog_frame_new_from_data_BGRx (void *data, int width, int height);
140 CogFrame * cog_frame_new_from_data_xBGR (void *data, int width, int height);
141 CogFrame * cog_frame_new_from_data_RGBA (void *data, int width, int height);
142 CogFrame * cog_frame_new_from_data_ARGB (void *data, int width, int height);
143 CogFrame * cog_frame_new_from_data_BGRA (void *data, int width, int height);
144 CogFrame * cog_frame_new_from_data_ABGR (void *data, int width, int height);
145 void cog_frame_set_free_callback (CogFrame *frame,
146     CogFrameFreeFunc free_func, void *priv);
147 void cog_frame_unref (CogFrame *frame);
148 CogFrame *cog_frame_ref (CogFrame *frame);
149 CogFrame *cog_frame_dup (CogFrame *frame);
150 CogFrame *cog_frame_clone (CogMemoryDomain *domain, CogFrame *frame);
151
152 void cog_frame_convert (CogFrame *dest, CogFrame *src);
153 void cog_frame_add (CogFrame *dest, CogFrame *src);
154 void cog_frame_subtract (CogFrame *dest, CogFrame *src);
155 void cog_frame_shift_left (CogFrame *frame, int shift);
156 void cog_frame_shift_right (CogFrame *frame, int shift);
157
158 //void cog_frame_downsample (CogFrame *dest, CogFrame *src);
159 void cog_frame_upsample_horiz (CogFrame *dest, CogFrame *src);
160 void cog_frame_upsample_vert (CogFrame *dest, CogFrame *src);
161 double cog_frame_calculate_average_luma (CogFrame *frame);
162
163 CogFrame * cog_frame_convert_to_444 (CogFrame *frame);
164 void cog_frame_md5 (CogFrame *frame, uint32_t *state);
165
166 CogFrame * cog_frame_new_and_alloc_extended (CogMemoryDomain *domain,
167     CogFrameFormat format, int width, int height, int extension);
168 CogFrame *cog_frame_dup_extended (CogFrame *frame, int extension);
169 void cog_frame_edge_extend (CogFrame *frame, int width, int height);
170 void cog_frame_zero_extend (CogFrame *frame, int width, int height);
171 void cog_frame_mark (CogFrame *frame, int value);
172 void cog_frame_mc_edgeextend (CogFrame *frame);
173
174 void cog_frame_data_get_codeblock (CogFrameData *dest, CogFrameData *src,
175         int x, int y, int horiz_codeblocks, int vert_codeblocks);
176
177 CogUpsampledFrame * cog_upsampled_frame_new (CogFrame *frame);
178 void cog_upsampled_frame_free (CogUpsampledFrame *df);
179 void cog_upsampled_frame_upsample (CogUpsampledFrame *df);
180 #ifdef ENABLE_MOTION_REF
181 int cog_upsampled_frame_get_pixel_prec0 (CogUpsampledFrame *upframe, int k,
182     int x, int y);
183 int cog_upsampled_frame_get_pixel_prec1 (CogUpsampledFrame *upframe, int k,
184     int x, int y);
185 int cog_upsampled_frame_get_pixel_prec3 (CogUpsampledFrame *upframe, int k,
186     int x, int y);
187 int cog_upsampled_frame_get_pixel_precN (CogUpsampledFrame *upframe, int k,
188     int x, int y, int mv_precision);
189 #endif
190 void cog_upsampled_frame_get_block_precN (CogUpsampledFrame *upframe, int k,
191     int x, int y, int prec, CogFrameData *dest);
192 void cog_upsampled_frame_get_block_fast_precN (CogUpsampledFrame *upframe, int k,
193     int x, int y, int prec, CogFrameData *dest, CogFrameData *fd);
194 void cog_upsampled_frame_get_subdata_prec0 (CogUpsampledFrame *upframe,
195     int k, int x, int y, CogFrameData *fd);
196 void cog_upsampled_frame_get_subdata_prec1 (CogUpsampledFrame *upframe,
197     int k, int x, int y, CogFrameData *fd);
198
199 void cog_frame_get_subdata (CogFrame *frame, CogFrameData *fd,
200         int comp, int x, int y);
201
202 void cog_frame_split_fields (CogFrame *dest1, CogFrame *dest2, CogFrame *src);
203
204
205 COG_END_DECLS
206
207 #endif
208