r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / v308.c
blobc7bf3d0b66f71e47d1eb859506c60917945cfe1d
1 #include "colormodels.h"
2 #include "funcprotos.h"
3 #include "quicktime.h"
4 #include "workarounds.h"
5 #include "v308.h"
7 #include <stdint.h>
8 #include <stdlib.h>
11 typedef struct
13 unsigned char *work_buffer;
14 } quicktime_v308_codec_t;
16 static int delete_codec(quicktime_video_map_t *vtrack)
18 quicktime_v308_codec_t *codec;
20 codec = ((quicktime_codec_t*)vtrack->codec)->priv;
21 if(codec->work_buffer) free(codec->work_buffer);
22 free(codec);
23 return 0;
26 static int reads_colormodel(quicktime_t *file,
27 int colormodel,
28 int track)
30 return (colormodel == BC_RGB888 ||
31 colormodel == BC_RGBA8888 ||
32 colormodel == BC_RGB161616 ||
33 colormodel == BC_RGBA16161616 ||
34 colormodel == BC_YUV888 ||
35 colormodel == BC_YUVA8888 ||
36 colormodel == BC_YUV161616 ||
37 colormodel == BC_YUVA16161616 ||
38 colormodel == BC_RGB8 ||
39 colormodel == BC_RGB565 ||
40 colormodel == BC_BGR888 ||
41 colormodel == BC_BGR8888);
44 static int writes_colormodel(quicktime_t *file,
45 int colormodel,
46 int track)
48 return (colormodel == BC_RGB888 ||
49 colormodel == BC_RGBA8888 ||
50 colormodel == BC_RGB161616 ||
51 colormodel == BC_RGBA16161616 ||
52 colormodel == BC_YUV888 ||
53 colormodel == BC_YUVA8888 ||
54 colormodel == BC_YUV161616 ||
55 colormodel == BC_YUVA16161616);
71 static int decode(quicktime_t *file, unsigned char **row_pointers, int track)
73 int i;
74 int64_t bytes;
75 int result = 0;
76 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
77 quicktime_v308_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
78 int width = vtrack->track->tkhd.track_width;
79 int height = vtrack->track->tkhd.track_height;
80 unsigned char **input_rows;
81 if(!codec->work_buffer)
82 codec->work_buffer = malloc(vtrack->track->tkhd.track_width *
83 vtrack->track->tkhd.track_height *
84 3);
88 quicktime_set_video_position(file, vtrack->current_position, track);
89 bytes = quicktime_frame_size(file, vtrack->current_position, track);
90 result = !quicktime_read_data(file, codec->work_buffer, bytes);
94 input_rows = malloc(sizeof(unsigned char*) * height);
95 for(i = 0; i < height; i++)
96 input_rows[i] = codec->work_buffer + i * width * 3;
98 cmodel_transfer(row_pointers,
99 input_rows,
100 row_pointers[0],
101 row_pointers[1],
102 row_pointers[2],
106 file->in_x,
107 file->in_y,
108 file->in_w,
109 file->in_h,
112 file->out_w,
113 file->out_h,
114 BC_VYU888,
115 file->color_model,
117 width,
118 file->out_w);
120 free(input_rows);
122 return result;
131 static int encode(quicktime_t *file, unsigned char **row_pointers, int track)
133 int64_t offset = quicktime_position(file);
134 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
135 quicktime_v308_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
136 quicktime_trak_t *trak = vtrack->track;
137 int width = vtrack->track->tkhd.track_width;
138 int height = vtrack->track->tkhd.track_height;
139 int bytes = width * height * 3;
140 int result = 0;
141 unsigned char **output_rows;
142 int i;
143 quicktime_atom_t chunk_atom;
144 if(!codec->work_buffer)
145 codec->work_buffer = malloc(vtrack->track->tkhd.track_width *
146 vtrack->track->tkhd.track_height *
150 output_rows = malloc(sizeof(unsigned char*) * height);
151 for(i = 0; i < height; i++)
152 output_rows[i] = codec->work_buffer + i * width * 3;
154 cmodel_transfer(output_rows,
155 row_pointers,
159 row_pointers[0],
160 row_pointers[1],
161 row_pointers[2],
164 width,
165 height,
168 width,
169 height,
170 file->color_model,
171 BC_VYU888,
173 width,
174 width);
176 quicktime_write_chunk_header(file, trak, &chunk_atom);
177 result = !quicktime_write_data(file, codec->work_buffer, bytes);
178 quicktime_write_chunk_footer(file,
179 trak,
180 vtrack->current_chunk,
181 &chunk_atom,
184 vtrack->current_chunk++;
186 free(output_rows);
187 return result;
190 void quicktime_init_codec_v308(quicktime_video_map_t *vtrack)
192 quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
194 /* Init public items */
195 codec_base->priv = calloc(1, sizeof(quicktime_v308_codec_t));
196 codec_base->delete_vcodec = delete_codec;
197 codec_base->decode_video = decode;
198 codec_base->encode_video = encode;
199 codec_base->decode_audio = 0;
200 codec_base->encode_audio = 0;
201 codec_base->reads_colormodel = reads_colormodel;
202 codec_base->writes_colormodel = writes_colormodel;
203 codec_base->fourcc = QUICKTIME_YUV444;
204 codec_base->title = "Component Y'CbCr 8-bit 4:4:4";
205 codec_base->desc = "Component Y'CbCr 8-bit 4:4:4";