1 #include "colormodels.h"
2 #include "funcprotos.h"
4 #include "funcprotos.h"
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
;
19 free(codec
->temp_frame
);
20 free(codec
->temp_rows
);
26 static int source_cmodel(quicktime_t
*file
, int track
)
28 int depth
= quicktime_video_depth(file
, track
);
35 static int quicktime_decode_raw(quicktime_t
*file
, unsigned char **row_pointers
, int track
)
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
;
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
||
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
);
59 if(!codec
->temp_frame
)
61 codec
->temp_frame
= malloc(cmodel_calculate_datasize(width
,
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
;
73 temp_data
= row_pointers
[0];
74 for(i
= 0; i
< height
; i
++)
75 temp_rows
[i
] = row_pointers
[i
];
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 */
87 cmodel_transfer(row_pointers
,
113 static int quicktime_encode_raw(quicktime_t
*file
,
114 unsigned char **row_pointers
,
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
);
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;
130 quicktime_atom_t chunk_atom
;
132 //printf("quicktime_encode_raw %llx %llx\n", file->file_position, file->ftell_position);
135 dest_cmodel
= BC_ARGB8888
;
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
,
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 */
167 0, /* Leave NULL if non existent */
170 row_pointers
[0], /* Leave NULL if non existent */
173 0, /* Dimensions to capture from input frame */
177 0, /* Dimensions to project on output frame */
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
,
193 quicktime_write_chunk_footer(file
,
195 vtrack
->current_chunk
,
201 quicktime_write_chunk_header(file
, trak
, &chunk_atom
);
202 result
= !quicktime_write_data(file
, row_pointers
[0],
203 cmodel_calculate_datasize(width
,
207 quicktime_write_chunk_footer(file
,
209 vtrack
->current_chunk
,
215 vtrack
->current_chunk
++;
219 int quicktime_raw_rows_consecutive(unsigned char **row_pointers
, int w
, int h
, int depth
)
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;
230 static int reads_colormodel(quicktime_t
*file
,
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";