r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / v408.c
blob204280e75382ce3c93d17bd58d2be433dc170506
1 #include "colormodels.h"
2 #include "funcprotos.h"
3 #include "quicktime.h"
4 #include "workarounds.h"
5 #include "v408.h"
7 #include <stdint.h>
8 #include <stdlib.h>
10 typedef struct
12 unsigned char *work_buffer;
13 } quicktime_v408_codec_t;
15 static int delete_codec(quicktime_video_map_t *vtrack)
17 quicktime_v408_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_v408_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_UYVA8888,
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_v408_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_UYVA8888,
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,
182 vtrack->current_chunk++;
184 free(output_rows);
185 return result;
188 void quicktime_init_codec_v408(quicktime_video_map_t *vtrack)
190 quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
192 /* Init public items */
193 codec_base->priv = calloc(1, sizeof(quicktime_v408_codec_t));
194 codec_base->delete_vcodec = delete_codec;
195 codec_base->decode_video = decode;
196 codec_base->encode_video = encode;
197 codec_base->decode_audio = 0;
198 codec_base->encode_audio = 0;
199 codec_base->reads_colormodel = reads_colormodel;
200 codec_base->writes_colormodel = writes_colormodel;
201 codec_base->fourcc = QUICKTIME_YUVA4444;
202 codec_base->title = "Component Y'CbCrA 8-bit 4:4:4:4";
203 codec_base->desc = "Component Y'CbCrA 8-bit 4:4:4:4";