"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/rtjpeg.c" (9 Jan 2007, 2670 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdio.h>
    2 #include "rtjpeg.h"
    3 #include "quicktime.h"
    4 
    5 
    6 int quicktime_init_codec_rtjpeg(quicktime_video_map_t *vtrack, int jpeg_type)
    7 {
    8     quicktime_rtjpeg_codec_t *codec = &(vtrack->codecs.rtjpeg_codec);
    9 
   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);
   16 }
   17 
   18 int quicktime_delete_codec_rtjpeg(quicktime_video_map_t *vtrack)
   19 {
   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;
   27 }
   28 
   29 int quicktime_decode_rtjpeg(quicktime_t *file, unsigned char **row_pointers, int track)
   30 {
   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);
   37 
   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)
   42     {
   43         free(codec->output_buffer);
   44         codec->output_buffer = 0;
   45     }
   46     if(!codec->output_buffer)
   47     {
   48         codec->output_buffer = malloc(size);
   49         codec->buffer_size = size;
   50     }
   51     result = !quicktime_read_data(file, codec->output_buffer, size);
   52 
   53     if(!result)
   54     {
   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);
   59     }
   60 
   61     return result;
   62 }
   63 
   64 
   65 int quicktime_encode_jpeg(quicktime_t *file, unsigned char **row_pointers, int track)
   66 {
   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);
   73 
   74 
   75 
   76     bytes = quicktime_position(file) - offset;
   77     quicktime_update_tables(file,
   78                         vtrack->track,
   79                         offset,
   80                         vtrack->current_chunk,
   81                         vtrack->current_position,
   82                         1,
   83                         bytes);
   84 
   85     vtrack->current_chunk++;
   86     return result;
   87 }