r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / quicktime / v410.c
blob18e508f05c49f397b86520120163b5ddca393630
1 #include "colormodels.h"
2 #include "funcprotos.h"
3 #include "quicktime.h"
4 #include "workarounds.h"
5 #include "v410.h"
7 #include <stdint.h>
8 #include <stdlib.h>
10 typedef struct
12 unsigned char *work_buffer;
13 } quicktime_v410_codec_t;
15 static int delete_codec(quicktime_video_map_t *vtrack)
17 quicktime_v410_codec_t *codec;
19 codec = ((quicktime_codec_t*)vtrack->codec)->priv;
20 if(codec->work_buffer) free(codec->work_buffer);
21 free(codec);
22 return 0;
25 static int reads_colormodel(quicktime_t *file,
26 int colormodel,
27 int track)
29 return (colormodel == BC_RGB888 ||
30 colormodel == BC_RGBA8888 ||
31 colormodel == BC_RGB161616 ||
32 colormodel == BC_RGBA16161616 ||
33 colormodel == BC_YUV888 ||
34 colormodel == BC_YUVA8888 ||
35 colormodel == BC_YUV161616 ||
36 colormodel == BC_YUVA16161616 ||
37 colormodel == BC_RGB8 ||
38 colormodel == BC_RGB565 ||
39 colormodel == BC_BGR888 ||
40 colormodel == BC_BGR8888);
43 static int writes_colormodel(quicktime_t *file,
44 int colormodel,
45 int track)
47 return (colormodel == BC_RGB888 ||
48 colormodel == BC_RGBA8888 ||
49 colormodel == BC_RGB161616 ||
50 colormodel == BC_RGBA16161616 ||
51 colormodel == BC_YUV888 ||
52 colormodel == BC_YUVA8888 ||
53 colormodel == BC_YUV161616 ||
54 colormodel == BC_YUVA16161616);
70 static int decode(quicktime_t *file, unsigned char **row_pointers, int track)
72 int i;
73 int64_t bytes;
74 int result = 0;
75 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
76 quicktime_v410_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
77 int width = vtrack->track->tkhd.track_width;
78 int height = vtrack->track->tkhd.track_height;
79 unsigned char **input_rows;
80 if(!codec->work_buffer)
81 codec->work_buffer = malloc(vtrack->track->tkhd.track_width *
82 vtrack->track->tkhd.track_height *
83 4);
86 quicktime_set_video_position(file, vtrack->current_position, track);
87 bytes = quicktime_frame_size(file, vtrack->current_position, track);
88 result = !quicktime_read_data(file, codec->work_buffer, bytes);
92 input_rows = malloc(sizeof(unsigned char*) * height);
93 for(i = 0; i < height; i++)
94 input_rows[i] = codec->work_buffer + i * width * 4;
96 cmodel_transfer(row_pointers,
97 input_rows,
98 row_pointers[0],
99 row_pointers[1],
100 row_pointers[2],
104 file->in_x,
105 file->in_y,
106 file->in_w,
107 file->in_h,
110 file->out_w,
111 file->out_h,
112 BC_YUV101010,
113 file->color_model,
115 width,
116 file->out_w);
118 free(input_rows);
120 return result;
129 static int encode(quicktime_t *file, unsigned char **row_pointers, int track)
131 int64_t offset = quicktime_position(file);
132 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
133 quicktime_v410_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
134 quicktime_trak_t *trak = vtrack->track;
135 int width = vtrack->track->tkhd.track_width;
136 int height = vtrack->track->tkhd.track_height;
137 int bytes = width * height * 4;
138 int result = 0;
139 unsigned char **output_rows;
140 int i;
141 quicktime_atom_t chunk_atom;
142 if(!codec->work_buffer)
143 codec->work_buffer = malloc(vtrack->track->tkhd.track_width *
144 vtrack->track->tkhd.track_height *
148 output_rows = malloc(sizeof(unsigned char*) * height);
149 for(i = 0; i < height; i++)
150 output_rows[i] = codec->work_buffer + i * width * 4;
152 cmodel_transfer(output_rows,
153 row_pointers,
157 row_pointers[0],
158 row_pointers[1],
159 row_pointers[2],
162 width,
163 height,
166 width,
167 height,
168 file->color_model,
169 BC_YUV101010,
171 width,
172 width);
174 quicktime_write_chunk_header(file, trak, &chunk_atom);
175 result = !quicktime_write_data(file, codec->work_buffer, bytes);
176 quicktime_write_chunk_footer(file,
177 trak,
178 vtrack->current_chunk,
179 &chunk_atom,
181 //printf("quicktime_encode_yv12 2\n");
183 vtrack->current_chunk++;
185 free(output_rows);
186 return result;
189 void quicktime_init_codec_v410(quicktime_video_map_t *vtrack)
191 quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
193 /* Init public items */
194 codec_base->priv = calloc(1, sizeof(quicktime_v410_codec_t));
195 codec_base->delete_vcodec = delete_codec;
196 codec_base->decode_video = decode;
197 codec_base->encode_video = encode;
198 codec_base->decode_audio = 0;
199 codec_base->encode_audio = 0;
200 codec_base->reads_colormodel = reads_colormodel;
201 codec_base->writes_colormodel = writes_colormodel;
202 codec_base->fourcc = QUICKTIME_YUV444_10bit;
203 codec_base->title = "Component Y'CbCr 10-bit 4:4:4";
204 codec_base->desc = "Component Y'CbCr 10-bit 4:4:4";