Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / rtjpeg.c
blob171648fc0ca9e2863c5d0a133f58b942a2ad223d
1 #include <stdio.h>
2 #include "rtjpeg.h"
3 #include "quicktime.h"
6 int quicktime_init_codec_rtjpeg(quicktime_video_map_t *vtrack, int jpeg_type)
8 quicktime_rtjpeg_codec_t *codec = &(vtrack->codecs.rtjpeg_codec);
10 codec->quality = 100;
11 codec->output_buffer = 0;
12 codec->buffer_size = codec->image_size = 0;
13 RTjpeg_init_compress(&(codec->compress_struct), vtrack->track->tkhd.track_width, vtrack->track->tkhd.track_height, (int)((float)codec->quality / 100 * 255));
14 RTjpeg_init_decompress(&(codec->decompress_struct), vtrack->track->tkhd.track_width, vtrack->track->tkhd.track_height);
15 codec->yuv_frame = malloc(vtrack->track->tkhd.track_width * vtrack->track->tkhd.track_height * 3);
18 int quicktime_delete_codec_rtjpeg(quicktime_video_map_t *vtrack)
20 quicktime_rtjpeg_codec_t *codec = &(vtrack->codecs.rtjpeg_codec);
21 if(codec->output_buffer)
22 free(codec->output_buffer);
23 if(codec->yuv_frame)
24 free(codec->yuv_frame);
25 codec->output_buffer = 0;
26 codec->yuv_frame = 0;
29 int quicktime_decode_rtjpeg(quicktime_t *file, unsigned char **row_pointers, int track)
31 int result = 0;
32 register int i;
33 long size;
34 quicktime_trak_t *trak = file->vtracks[track].track;
35 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
36 quicktime_rtjpeg_codec_t *codec = &(vtrack->codecs.rtjpeg_codec);
38 /* Read the entire chunk from disk. */
39 quicktime_set_video_position(file, vtrack->current_position, track);
40 size = quicktime_frame_size(file, vtrack->current_position, track);
41 if(size > codec->buffer_size && codec->output_buffer)
43 free(codec->output_buffer);
44 codec->output_buffer = 0;
46 if(!codec->output_buffer)
48 codec->output_buffer = malloc(size);
49 codec->buffer_size = size;
51 result = !quicktime_read_data(file, codec->output_buffer, size);
53 if(!result)
55 /* Decompress the frame */
56 RTjpeg_init_Q(&(codec->decompress_struct), codec->output_buffer[0]);
57 RTjpeg_decompressYUV420(&(codec->decompress_struct), &(codec->output_buffer[8]), codec->yuv_frame);
58 RTjpeg_yuv420rgb(&(codec->decompress_struct), codec->yuv_frame, row_pointers[0], 0);
61 return result;
65 int quicktime_encode_jpeg(quicktime_t *file, unsigned char **row_pointers, int track)
67 long offset = quicktime_position(file);
68 int result = 0;
69 register int i;
70 quicktime_trak_t *trak = file->vtracks[track].track;
71 quicktime_video_map_t *vtrack = &(file->vtracks[track]);
72 quicktime_jpeg_codec_t *codec = &(vtrack->codecs.jpeg_codec);
76 bytes = quicktime_position(file) - offset;
77 quicktime_update_tables(file,
78 vtrack->track,
79 offset,
80 vtrack->current_chunk,
81 vtrack->current_position,
83 bytes);
85 vtrack->current_chunk++;
86 return result;