"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/v408.c" (9 Jan 2007, 4435 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 "colormodels.h"
    2 #include "funcprotos.h"
    3 #include "quicktime.h"
    4 #include "workarounds.h"
    5 #include "v408.h"
    6 
    7 #include <stdint.h>
    8 #include <stdlib.h>
    9 
   10 typedef struct
   11 {
   12     unsigned char *work_buffer;
   13 } quicktime_v408_codec_t;
   14 
   15 static int delete_codec(quicktime_video_map_t *vtrack)
   16 {
   17     quicktime_v408_codec_t *codec;
   18 
   19     codec = ((quicktime_codec_t*)vtrack->codec)->priv;
   20     if(codec->work_buffer) free(codec->work_buffer);
   21     free(codec);
   22     return 0;
   23 }
   24 
   25 static int reads_colormodel(quicktime_t *file, 
   26         int colormodel, 
   27         int track)
   28 {
   29     return (colormodel == BC_RGB888 ||
   30         colormodel == BC_RGBA8888 ||
   31         colormodel == BC_RGB161616 ||
   32         colormodel == BC_RGBA16161616 ||
   33         colormodel == BC_YUV888 ||
   34         colormodel == BC_YUVA8888 ||
   35         colormodel == BC_YUV161616 ||
   36         colormodel == BC_YUVA16161616 ||
   37         colormodel == BC_RGB8 ||
   38         colormodel == BC_RGB565 ||
   39         colormodel == BC_BGR888 ||
   40         colormodel == BC_BGR8888);
   41 }
   42 
   43 static int writes_colormodel(quicktime_t *file, 
   44         int colormodel, 
   45         int track)
   46 {
   47     return (colormodel == BC_RGB888 ||
   48         colormodel == BC_RGBA8888 ||
   49         colormodel == BC_RGB161616 ||
   50         colormodel == BC_RGBA16161616 ||
   51         colormodel == BC_YUV888 ||
   52         colormodel == BC_YUVA8888 ||
   53         colormodel == BC_YUV161616 ||
   54         colormodel == BC_YUVA16161616);
   55 }
   56 
   57 
   58 
   59 
   60 
   61 
   62 
   63 
   64 
   65 
   66 
   67 
   68 
   69 
   70 static int decode(quicktime_t *file, unsigned char **row_pointers, int track)
   71 {
   72     int i;
   73     int64_t bytes;
   74     int result = 0;
   75     quicktime_video_map_t *vtrack = &(file->vtracks[track]);
   76     quicktime_v408_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
   77     int width = vtrack->track->tkhd.track_width;
   78     int height = vtrack->track->tkhd.track_height;
   79     unsigned char **input_rows;
   80     if(!codec->work_buffer)
   81         codec->work_buffer = malloc(vtrack->track->tkhd.track_width * 
   82             vtrack->track->tkhd.track_height *
   83             4);
   84 
   85 
   86     quicktime_set_video_position(file, vtrack->current_position, track);
   87     bytes = quicktime_frame_size(file, vtrack->current_position, track);
   88     result = !quicktime_read_data(file, codec->work_buffer, bytes);
   89 
   90 
   91 
   92     input_rows = malloc(sizeof(unsigned char*) * height);
   93     for(i = 0; i < height; i++)
   94         input_rows[i] = codec->work_buffer + i * width * 4;
   95 
   96     cmodel_transfer(row_pointers, 
   97         input_rows,
   98         row_pointers[0],
   99         row_pointers[1],
  100         row_pointers[2],
  101         0,
  102         0,
  103         0,
  104         file->in_x, 
  105         file->in_y, 
  106         file->in_w, 
  107         file->in_h,
  108         0, 
  109         0, 
  110         file->out_w, 
  111         file->out_h,
  112         BC_UYVA8888, 
  113         file->color_model,
  114         0,
  115         width,
  116         file->out_w);
  117 
  118     free(input_rows);
  119 
  120     return result;
  121 }
  122 
  123 
  124 
  125 
  126 
  127 
  128 
  129 static int encode(quicktime_t *file, unsigned char **row_pointers, int track)
  130 {
  131     int64_t offset = quicktime_position(file);
  132     quicktime_video_map_t *vtrack = &(file->vtracks[track]);
  133     quicktime_v408_codec_t *codec = ((quicktime_codec_t*)vtrack->codec)->priv;
  134     quicktime_trak_t *trak = vtrack->track;
  135     int width = vtrack->track->tkhd.track_width;
  136     int height = vtrack->track->tkhd.track_height;
  137     int bytes = width * height * 4;
  138     int result = 0;
  139     unsigned char **output_rows;
  140     int i;
  141     quicktime_atom_t chunk_atom;
  142     if(!codec->work_buffer)
  143         codec->work_buffer = malloc(vtrack->track->tkhd.track_width * 
  144             vtrack->track->tkhd.track_height *
  145             4);
  146 
  147 
  148     output_rows = malloc(sizeof(unsigned char*) * height);
  149     for(i = 0; i < height; i++)
  150         output_rows[i] = codec->work_buffer + i * width * 4;
  151 
  152     cmodel_transfer(output_rows, 
  153         row_pointers,
  154         0,
  155         0,
  156         0,
  157         row_pointers[0],
  158         row_pointers[1],
  159         row_pointers[2],
  160         0, 
  161         0, 
  162         width, 
  163         height,
  164         0, 
  165         0, 
  166         width, 
  167         height,
  168         file->color_model,
  169         BC_UYVA8888, 
  170         0,
  171         width,
  172         width);
  173 
  174     quicktime_write_chunk_header(file, trak, &chunk_atom);
  175     result = !quicktime_write_data(file, codec->work_buffer, bytes);
  176     quicktime_write_chunk_footer(file, 
  177         trak,
  178         vtrack->current_chunk,
  179         &chunk_atom, 
  180         1);
  181 
  182     vtrack->current_chunk++;
  183     
  184     free(output_rows);
  185     return result;
  186 }
  187 
  188 void quicktime_init_codec_v408(quicktime_video_map_t *vtrack)
  189 {
  190     quicktime_codec_t *codec_base = (quicktime_codec_t*)vtrack->codec;
  191 
  192 /* Init public items */
  193     codec_base->priv = calloc(1, sizeof(quicktime_v408_codec_t));
  194     codec_base->delete_vcodec = delete_codec;
  195     codec_base->decode_video = decode;
  196     codec_base->encode_video = encode;
  197     codec_base->decode_audio = 0;
  198     codec_base->encode_audio = 0;
  199     codec_base->reads_colormodel = reads_colormodel;
  200     codec_base->writes_colormodel = writes_colormodel;
  201     codec_base->fourcc = QUICKTIME_YUVA4444;
  202     codec_base->title = "Component Y'CbCrA 8-bit 4:4:4:4";
  203     codec_base->desc = "Component Y'CbCrA 8-bit 4:4:4:4";
  204 }
  205