2 #ifndef __COG_FRAME_H__
3 #define __COG_FRAME_H__
5 #include <cog/cogutils.h>
9 typedef struct _CogFrame CogFrame;
10 typedef struct _CogFrameData CogFrameData;
11 typedef struct _CogUpsampledFrame CogUpsampledFrame;
13 typedef void (*CogFrameFreeFunc)(CogFrame *frame, void *priv);
14 typedef void (*CogFrameRenderFunc)(CogFrame *frame, void *dest, int component, int i);
16 typedef enum _CogColorMatrix {
17 COG_COLOR_MATRIX_UNKNOWN = 0,
18 COG_COLOR_MATRIX_HDTV,
22 typedef enum _CogChromaSite {
23 COG_CHROMA_SITE_UNKNOWN = 0,
24 COG_CHROMA_SITE_MPEG2 = 1,
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
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,
39 COG_FRAME_FORMAT_S16_444 = 0x04,
40 COG_FRAME_FORMAT_S16_422 = 0x05,
41 COG_FRAME_FORMAT_S16_420 = 0x07,
43 COG_FRAME_FORMAT_S32_444 = 0x08,
44 COG_FRAME_FORMAT_S32_422 = 0x09,
45 COG_FRAME_FORMAT_S32_420 = 0x0b,
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,
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
69 #define COG_FRAME_FORMAT_H_SHIFT(format) ((format) & 0x1)
70 #define COG_FRAME_FORMAT_V_SHIFT(format) (((format)>>1) & 0x1)
72 #define COG_FRAME_IS_PACKED(format) (((format)>>8) & 0x1)
74 #define COG_FRAME_CACHE_SIZE 8
76 struct _CogFrameData {
77 CogFrameFormat format;
89 CogFrameFreeFunc free;
90 CogMemoryDomain *domain;
94 CogFrameFormat format;
98 CogFrameData components[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);
114 struct _CogUpsampledFrame {
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)))
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);
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);
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);
163 CogFrame * cog_frame_convert_to_444 (CogFrame *frame);
164 void cog_frame_md5 (CogFrame *frame, uint32_t *state);
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);
174 void cog_frame_data_get_codeblock (CogFrameData *dest, CogFrameData *src,
175 int x, int y, int horiz_codeblocks, int vert_codeblocks);
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,
183 int cog_upsampled_frame_get_pixel_prec1 (CogUpsampledFrame *upframe, int k,
185 int cog_upsampled_frame_get_pixel_prec3 (CogUpsampledFrame *upframe, int k,
187 int cog_upsampled_frame_get_pixel_precN (CogUpsampledFrame *upframe, int k,
188 int x, int y, int mv_precision);
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);
199 void cog_frame_get_subdata (CogFrame *frame, CogFrameData *fd,
200 int comp, int x, int y);
202 void cog_frame_split_fields (CogFrame *dest1, CogFrame *dest2, CogFrame *src);