1 2 #ifndef __SCHRO_FRAME_H__ 3 #define __SCHRO_FRAME_H__ 4 5 #include <schroedinger/schroutils.h> 6 #include <schroedinger/schrodomain.h> 7 8 SCHRO_BEGIN_DECLS 9 10 typedef struct _SchroFrame SchroFrame; 11 typedef struct _SchroFrameData SchroFrameData; 12 typedef struct _SchroUpsampledFrame SchroUpsampledFrame; 13 14 typedef void (*SchroFrameFreeFunc)(SchroFrame *frame, void *priv); 15 typedef void (*SchroFrameRenderFunc)(SchroFrame *frame, void *dest, int component, int i); 16 17 /* bit pattern: 18 * 0x100 - 0: normal, 1: indirect (packed) 19 * 0x001 - horizontal chroma subsampling: 0: 1, 1: 2 20 * 0x002 - vertical chroma subsampling: 0: 1, 1: 2 21 * 0x00c - depth: 0: u8, 1: s16, 2: s32 22 * */ 23 typedef enum _SchroFrameFormat { 24 SCHRO_FRAME_FORMAT_U8_444 = 0x00, 25 SCHRO_FRAME_FORMAT_U8_422 = 0x01, 26 SCHRO_FRAME_FORMAT_U8_420 = 0x03, 27 28 SCHRO_FRAME_FORMAT_S16_444 = 0x04, 29 SCHRO_FRAME_FORMAT_S16_422 = 0x05, 30 SCHRO_FRAME_FORMAT_S16_420 = 0x07, 31 32 SCHRO_FRAME_FORMAT_S32_444 = 0x08, 33 SCHRO_FRAME_FORMAT_S32_422 = 0x09, 34 SCHRO_FRAME_FORMAT_S32_420 = 0x0b, 35 36 /* indirectly supported */ 37 SCHRO_FRAME_FORMAT_YUYV = 0x100, /* YUYV order */ 38 SCHRO_FRAME_FORMAT_UYVY = 0x101, /* UYVY order */ 39 SCHRO_FRAME_FORMAT_AYUV = 0x102, 40 SCHRO_FRAME_FORMAT_ARGB = 0x103, 41 SCHRO_FRAME_FORMAT_RGB = 0x104, 42 SCHRO_FRAME_FORMAT_v216 = 0x105, 43 SCHRO_FRAME_FORMAT_v210 = 0x106, 44 SCHRO_FRAME_FORMAT_AY64 = 0x107 45 } SchroFrameFormat; 46 47 #define SCHRO_FRAME_FORMAT_DEPTH(format) ((format) & 0xc) 48 #define SCHRO_FRAME_FORMAT_DEPTH_U8 0x00 49 #define SCHRO_FRAME_FORMAT_DEPTH_S16 0x04 50 #define SCHRO_FRAME_FORMAT_DEPTH_S32 0x08 51 52 #define SCHRO_FRAME_FORMAT_H_SHIFT(format) ((format) & 0x1) 53 #define SCHRO_FRAME_FORMAT_V_SHIFT(format) (((format)>>1) & 0x1) 54 55 #define SCHRO_FRAME_IS_PACKED(format) (((format)>>8) & 0x1) 56 57 #define SCHRO_FRAME_CACHE_SIZE 32 58 59 struct _SchroFrameData { 60 SchroFrameFormat format; 61 void *data; 62 int stride; 63 int width; 64 int height; 65 int length; 66 int h_shift; 67 int v_shift; 68 }; 69 70 struct _SchroFrame { 71 int refcount; 72 SchroFrameFreeFunc free; 73 SchroMemoryDomain *domain; 74 void *regions[3]; 75 void *priv; 76 77 SchroFrameFormat format; 78 int width; 79 int height; 80 81 SchroFrameData components[3]; 82 83 int is_virtual; 84 int cached_lines[3][SCHRO_FRAME_CACHE_SIZE]; 85 SchroFrame *virt_frame1; 86 SchroFrame *virt_frame2; 87 void (*render_line) (SchroFrame *frame, void *dest, int component, int i); 88 void *virt_priv; 89 void *virt_priv2; 90 91 int extension; 92 int cache_offset[3]; 93 int is_upsampled; 94 }; 95 96 struct _SchroUpsampledFrame { 97 SchroFrame *frames[4]; 98 }; 99 100 #define SCHRO_FRAME_DATA_GET_LINE(fd,i) (SCHRO_OFFSET((fd)->data,(fd)->stride*(i))) 101 #define SCHRO_FRAME_DATA_GET_PIXEL_U8(fd,i,j) ((uint8_t *)SCHRO_OFFSET((fd)->data,(fd)->stride*(j)+(i))) 102 #define SCHRO_FRAME_DATA_GET_PIXEL_S16(fd,i,j) ((int16_t *)SCHRO_OFFSET((fd)->data,(fd)->stride*(j)+(i)*sizeof(int16_t))) 103 #define SCHRO_FRAME_DATA_GET_PIXEL_S32(fd,i,j) ((int32_t *)SCHRO_OFFSET((fd)->data,(fd)->stride*(j)+(i)*sizeof(int32_t))) 104 105 SchroFrame * schro_frame_new (void); 106 SchroFrame * schro_frame_new_and_alloc (SchroMemoryDomain *domain, 107 SchroFrameFormat format, int width, int height); 108 SchroFrame * schro_frame_new_from_data_I420 (void *data, int width, int height); 109 SchroFrame * schro_frame_new_from_data_Y42B (void *data, int width, int height); 110 SchroFrame * schro_frame_new_from_data_Y444 (void *data, int width, int height); 111 SchroFrame * schro_frame_new_from_data_YV12 (void *data, int width, int height); 112 SchroFrame * schro_frame_new_from_data_YUY2 (void *data, int width, int height); 113 SchroFrame * schro_frame_new_from_data_UYVY (void *data, int width, int height); 114 SchroFrame * schro_frame_new_from_data_UYVY_full (void *data, int width, int height, int stride); 115 SchroFrame * schro_frame_new_from_data_AYUV (void *data, int width, int height); 116 SchroFrame * schro_frame_new_from_data_v216 (void *data, int width, int height); 117 SchroFrame * schro_frame_new_from_data_v210 (void *data, int width, int height); 118 SchroFrame * schro_frame_new_from_data_AY64 (void *data, int width, int height); 119 void schro_frame_set_free_callback (SchroFrame *frame, 120 SchroFrameFreeFunc free_func, void *priv); 121 void schro_frame_unref (SchroFrame *frame); 122 SchroFrame *schro_frame_ref (SchroFrame *frame); 123 SchroFrame *schro_frame_dup (SchroFrame *frame); 124 SchroFrame *schro_frame_clone (SchroMemoryDomain *domain, SchroFrame *frame); 125 126 void schro_frame_convert (SchroFrame *dest, SchroFrame *src); 127 void schro_frame_add (SchroFrame *dest, SchroFrame *src); 128 void schro_frame_subtract (SchroFrame *dest, SchroFrame *src); 129 void schro_frame_shift_left (SchroFrame *frame, int shift); 130 void schro_frame_shift_right (SchroFrame *frame, int shift); 131 void schro_frame_clear (SchroFrame *frame); 132 133 void schro_frame_downsample (SchroFrame *dest, SchroFrame *src); 134 void schro_frame_upsample_horiz (SchroFrame *dest, SchroFrame *src); 135 void schro_frame_upsample_vert (SchroFrame *dest, SchroFrame *src); 136 double schro_frame_calculate_average_luma (SchroFrame *frame); 137 138 SchroFrame * schro_frame_convert_to_444 (SchroFrame *frame); 139 void schro_frame_md5 (SchroFrame *frame, uint32_t *state); 140 141 #ifdef SCHRO_ENABLE_UNSTABLE_API 142 143 SchroFrame * schro_frame_new_and_alloc_extended (SchroMemoryDomain *domain, 144 SchroFrameFormat format, int width, int height, int extension); 145 SchroFrame * schro_frame_new_and_alloc_full (SchroMemoryDomain * domain, 146 SchroFrameFormat format, int width, int height, int extension, 147 int upsampled); 148 SchroFrame *schro_frame_dup_extended (SchroFrame *frame, int extension); 149 SchroFrame *schro_frame_dup_full (SchroFrame *frame, int extension, 150 int is_upsampled); 151 void schro_frame_edge_extend (SchroFrame *frame, int width, int height); 152 void schro_frame_zero_extend (SchroFrame *frame, int width, int height); 153 void schro_frame_mark (SchroFrame *frame, int value); 154 void schro_frame_mc_edgeextend (SchroFrame *frame); 155 156 void schro_frame_data_get_codeblock (SchroFrameData *dest, SchroFrameData *src, 157 int x, int y, int horiz_codeblocks, int vert_codeblocks); 158 159 SchroUpsampledFrame * schro_upsampled_frame_new (SchroFrame *frame); 160 void schro_upsampled_frame_free (SchroUpsampledFrame *df); 161 void schro_upsampled_frame_upsample (SchroUpsampledFrame *df); 162 #ifdef ENABLE_MOTION_REF 163 int schro_upsampled_frame_get_pixel_prec0 (SchroUpsampledFrame *upframe, int k, 164 int x, int y); 165 int schro_upsampled_frame_get_pixel_prec1 (SchroUpsampledFrame *upframe, int k, 166 int x, int y); 167 int schro_upsampled_frame_get_pixel_prec3 (SchroUpsampledFrame *upframe, int k, 168 int x, int y); 169 int schro_upsampled_frame_get_pixel_precN (SchroUpsampledFrame *upframe, int k, 170 int x, int y, int mv_precision); 171 #endif 172 void schro_upsampled_frame_get_block_precN (SchroUpsampledFrame *upframe, int k, 173 int x, int y, int prec, SchroFrameData *dest); 174 void schro_upsampled_frame_get_block_fast_precN (SchroUpsampledFrame *upframe, int k, 175 int x, int y, int prec, SchroFrameData *dest, SchroFrameData *fd); 176 void schro_upsampled_frame_get_subdata_prec0 (SchroUpsampledFrame *upframe, 177 int k, int x, int y, SchroFrameData *fd); 178 void schro_upsampled_frame_get_subdata_prec1 (SchroUpsampledFrame *upframe, 179 int k, int x, int y, SchroFrameData *fd); 180 181 /* it extracts a block of data from a frame, if possible */ 182 int schro_frame_get_data (SchroFrame* frame, SchroFrameData* fd, int comp 183 , int x, int y); 184 185 void schro_frame_get_subdata (SchroFrame *frame, SchroFrameData *fd, 186 int comp, int x, int y); 187 void schro_frame_get_reference_subdata (SchroFrame* frame, SchroFrameData* fd 188 , int comp, int x, int y); 189 190 void schro_frame_split_fields (SchroFrame *dest1, SchroFrame *dest2, SchroFrame *src); 191 192 int schro_frame_get_bit_depth (SchroFrame *frame); 193 194 #endif 195 196 SCHRO_END_DECLS 197 198 #endif 199 200