r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / raw.c
blob75a94269eac072fe1609113e4017f732c821fa5b
1 #include "colormodels.h"
2 #include "funcprotos.h"
3 #include "quicktime.h"
4 #include "funcprotos.h"
5 #include "graphics.h"
7 typedef struct
9 unsigned char *temp_frame; /* For changing color models and scaling */
10 unsigned char **temp_rows;
11 } quicktime_raw_codec_t;
14 static int quicktime_delete_codec_raw(quicktime_video_map_t *vtrack)
16 quicktime_raw_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
17 if(codec->temp_frame)
19 free(codec->temp_frame);
20 free(codec->temp_rows);
22 free(codec);
23 return 0;
26 static int source_cmodel(quicktime_t *file, int track)
28 int depth = quicktime_video_depth(file, track);
29 if(depth == 24)
30 return BC_RGB888;
31 else
32 return BC_ARGB8888;
35 static int quicktime_decode_raw(quicktime_t *file, unsigned char **row_pointers, int track)
37 int result = 0;
38 quicktime_trak_t *trak = file->vtracks[track].track;
39 int frame_depth = quicktime_video_depth(file, track);
40 int height = trak->tkhd.track_height;
41 int width = trak->tkhd.track_width;
42 long bytes;
43 int i;
44 quicktime_raw_codec_t *codec = ((quicktime_codec_t*)file->vtracks[track].codec)->priv;
45 int pixel_size = frame_depth / 8;
46 int cmodel = source_cmodel(file, track);
47 int use_temp = (cmodel != file->color_model ||
48 file->in_x != 0 ||
49 file->in_y != 0 ||
50 file->in_w != width ||
51 file->in_h != height ||
52 file->out_w != width ||
53 file->out_h != height);
54 unsigned char *temp_data;
55 unsigned char **temp_rows = malloc(sizeof(unsigned char*) * height);
57 if(use_temp)
59 if(!codec->temp_frame)
61 codec->temp_frame = malloc(cmodel_calculate_datasize(width,
62 height,
63 -1,
64 cmodel));
66 for(i = 0; i < height; i++)
67 temp_rows[i] = codec->temp_frame +
68 cmodel_calculate_pixelsize(cmodel) * width * i;
69 temp_data = codec->temp_frame;
71 else
73 temp_data = row_pointers[0];
74 for(i = 0; i < height; i++)
75 temp_rows[i] = row_pointers[i];
79 /* Read data */
80 quicktime_set_video_position(file, file->vtracks[track].current_position, track);
81 bytes = quicktime_frame_size(file, file->vtracks[track].current_position, track);
82 result = !quicktime_read_data(file, temp_data, bytes);
84 /* Convert colormodel */
85 if(use_temp)
87 cmodel_transfer(row_pointers,
88 temp_rows,
89 row_pointers[0],
90 row_pointers[1],
91 row_pointers[2],
95 file->in_x,
96 file->in_y,
97 file->in_w,
98 file->in_h,
99 0,
101 file->out_w,
102 file->out_h,
103 cmodel,
104 file->color_model,
106 width,
107 file->out_w);
110 return result;
113 static int quicktime_encode_raw(quicktime_t *file,
114 unsigned char **row_pointers,
115 int track)
117 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
118 quicktime_raw_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
119 quicktime_trak_t *trak = vtrack->track;
120 int64_t offset = quicktime_position(file);
121 int result = 0;
122 register int i, j;
123 int height = trak->tkhd.track_height;
124 int width = trak->tkhd.track_width;
125 int depth = quicktime_video_depth(file, track);
126 int64_t bytes = height * width * depth / 8;
127 int64_t bytes_per_row = width * depth / 8;
128 unsigned char temp;
129 int dest_cmodel;
130 quicktime_atom_t chunk_atom;
132 //printf("quicktime_encode_raw %llx %llx\n", file->file_position, file->ftell_position);
133 if(depth == 32)
135 dest_cmodel = BC_ARGB8888;
138 else
140 dest_cmodel = BC_RGB888;
146 if(file->color_model != dest_cmodel)
148 if(!codec->temp_frame)
150 codec->temp_frame = malloc(cmodel_calculate_datasize(width,
151 height,
153 dest_cmodel));
154 codec->temp_rows = malloc(sizeof(unsigned char*) * height);
156 for(i = 0; i < height; i++)
158 codec->temp_rows[i] = codec->temp_frame +
159 i * cmodel_calculate_pixelsize(dest_cmodel) * width;
165 cmodel_transfer(codec->temp_rows, /* Leave NULL if non existent */
166 row_pointers,
167 0, /* Leave NULL if non existent */
170 row_pointers[0], /* Leave NULL if non existent */
171 row_pointers[1],
172 row_pointers[2],
173 0, /* Dimensions to capture from input frame */
175 width,
176 height,
177 0, /* Dimensions to project on output frame */
179 width,
180 height,
181 file->color_model,
182 dest_cmodel,
183 0, /* When transfering BC_RGBA8888 to non-alpha this is the background color in 0xRRGGBB hex */
184 width, /* For planar use the luma rowspan */
185 width); /* For planar use the luma rowspan */
187 quicktime_write_chunk_header(file, trak, &chunk_atom);
188 result = !quicktime_write_data(file, codec->temp_frame,
189 cmodel_calculate_datasize(width,
190 height,
192 dest_cmodel));
193 quicktime_write_chunk_footer(file,
194 trak,
195 vtrack->current_chunk,
196 &chunk_atom,
199 else
201 quicktime_write_chunk_header(file, trak, &chunk_atom);
202 result = !quicktime_write_data(file, row_pointers[0],
203 cmodel_calculate_datasize(width,
204 height,
206 file->color_model));
207 quicktime_write_chunk_footer(file,
208 trak,
209 vtrack->current_chunk,
210 &chunk_atom,
215 vtrack->current_chunk++;
216 return result;
219 int quicktime_raw_rows_consecutive(unsigned char **row_pointers, int w, int h, int depth)
221 int i, result;
222 /* see if row_pointers are consecutive */
223 for(i = 1, result = 1; i < h; i++)
225 if(row_pointers[i] - row_pointers[i - 1] != w * depth) result = 0;
227 return result;
230 static int reads_colormodel(quicktime_t *file,
231 int colormodel,
232 int track)
234 return (colormodel == BC_RGB888 ||
235 colormodel == BC_BGR8888);
238 void quicktime_init_codec_raw(quicktime_video_map_t *vtrack)
240 quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
242 codec_base->priv = calloc(1, sizeof(quicktime_raw_codec_t));
243 codec_base->delete_vcodec = quicktime_delete_codec_raw;
244 codec_base->decode_video = quicktime_decode_raw;
245 codec_base->encode_video = quicktime_encode_raw;
246 codec_base->decode_audio = 0;
247 codec_base->encode_audio = 0;
248 codec_base->reads_colormodel = reads_colormodel;
249 codec_base->fourcc = QUICKTIME_RAW;
250 codec_base->title = "RGB uncompressed";
251 codec_base->desc = "RGB uncompressed";