⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gethdr.c

📁 H.263的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ * *  gethdr.c, header decoding for tmndecode (H.263 decoder) *  Copyright (C) 1995, 1996  Telenor R&D, Norway * *  Contacts: *  Robert Danielsen                  <Robert.Danielsen@nta.no> * *  Telenor Research and Development  http://www.nta.no/brukere/DVC/ *  P.O.Box 83                        tel.:   +47 63 84 84 00 *  N-2007 Kjeller, Norway            fax.:   +47 63 81 00 76 * *  Copyright (C) 1997  University of BC, Canada *  Modified by: Michael Gallant <mikeg@ee.ubc.ca> *               Guy Cote <guyc@ee.ubc.ca> *               Berna Erol <bernae@ee.ubc.ca> * *  Contacts: *  Michael Gallant                   <mikeg@ee.ubc.ca> * *  UBC Image Processing Laboratory   http://www.ee.ubc.ca/image *  2356 Main Mall                    tel.: +1 604 822 4051 *  Vancouver BC Canada V6T1Z4        fax.: +1 604 822 5949 * ************************************************************************//* Disclaimer of Warranty *  * These software programs are available to the user without any license fee * or royalty on an "as is" basis. The University of British Columbia * disclaims any and all warranties, whether express, implied, or * statuary, including any implied warranties or merchantability or of * fitness for a particular purpose.  In no event shall the * copyright-holder be liable for any incidental, punitive, or * consequential damages of any kind whatsoever arising from the use of * these programs. *  * This disclaimer of warranty extends to the user of these programs and * user's customers, employees, agents, transferees, successors, and * assigns. *  * The University of British Columbia does not represent or warrant that the * programs furnished hereunder are free of infringement of any * third-party patents. *  * Commercial implementations of H.263, including shareware, are subject to * royalty fees to patent holders.  Many of these patents are general * enough such that they are unavoidable regardless of implementation * design. *  *//* modified to support annex O true B frames, mikeg@ee.ubc.ca *  * modified to support general H.263+ syntax, bernae@ee.ubc.ca *  * based on mpeg2decode, (C) 1994, MPEG Software Simulation Group and * mpeg2play, (C) 1994 Stefan Eckart <stefan@lis.e-technik.tu-muenchen.de> */#include <stdio.h>#include <stdlib.h>#include "config.h"#include "tmndec.h"#include "global.h"/* private prototypes */static void getpicturehdr _ANSI_ARGS_ ((void));/* decode headers from one input stream until an End of Sequence or * picture start code is found */int getheader (){  unsigned int code, gob;  /* look for startcode */  startcode ();  code = getbits (PSC_LENGTH);  gob = getbits (5);  if (gob == SE_CODE)    return 0;  if (gob == 0)  {    if (trace)    {      fprintf (trace_file, "\nPSC: ");      printbits ((code << 5 + gob), 22, 22);    }    getpicturehdr ();    if (syntax_arith_coding)    /* reset decoder after receiving */      decoder_reset ();         /* fixed length PSC string */  }   else  {    if (trace)    {      fprintf (trace_file, "\nGBSC: ");      printbits (((code << 5) + gob), 22, 22);    }  }  return gob + 1;}/* align to start of next startcode */void startcode (){  /* search for new picture start code */  while (showbits (PSC_LENGTH) != 1l)    flushbits (1);}/* decode picture header */static void getpicturehdr (){  int pos, pei, tmp;  int TRPI = 0;  int BCI = 0;  int clock_conversion_code = 0;  int clock_divisor = 0;  int extended_temporal_reference = 0;  UFEP = 0;  pos = ld->bitcnt;  temp_ref = getbits (8);  if (trace)  {    fprintf (trace_file, "\nTR: ");    printbits (temp_ref, 8, 8);  }  if (trd < 0)    trd += 256;  tmp = getbits (1);            /* always "1" */  if (trace)    fprintf (trace_file, "\nSpare: %d", tmp);  if (!tmp)    if (!quiet)      printf ("warning: spare in picture header should be \"1\"\n");  tmp = getbits (1);            /* always "0" */  if (trace)    fprintf (trace_file, "\nH.261 distinction bit: %d", tmp);  if (tmp)    if (!quiet)      printf ("warning: H.261 distinction bit should be \"0\"\n");  tmp = getbits (1);            /* split_screen_indicator */  if (trace)    fprintf (trace_file, "\nsplit_screen_indicator: %d", tmp);  if (tmp)  {    if (!quiet)      printf ("error: split-screen not supported in this version\n");    exit (-1);  }  tmp = getbits (1);            /* document_camera_indicator */  if (trace)    fprintf (trace_file, "\ndocument_camera_indicator: %d", tmp);  if (tmp)    if (!quiet)      printf ("warning: document camera indicator not supported in this version\n");  tmp = getbits (1);            /* freeze_picture_release */  if (trace)    fprintf (trace_file, "\nfreeze_picture_release: %d", tmp);  if (tmp)    if (!quiet)      printf ("warning: frozen picture not supported in this version\n");  tmp = getbits (3);  if (trace)  {    fprintf (trace_file, "\nsource_format: ");    printbits (tmp, 3, 3);  }  if (tmp == 0)  {    if (!quiet)      printf ("error: source format 000 is reserved and not used in this version\n");    exit (-1);  }  if (tmp == EXTENDED_PTYPE)  {    if (trace)      fprintf (trace_file, "\n----------EXTENDED_PTYPE----------");    plus_type = 1;    UFEP = getbits (3);    if (trace)    {      fprintf (trace_file, "\nUFEP: ");      printbits (UFEP, 3, 3);    }    if (UFEP == 1)    {                           /* OPPTYPE */      if (trace)        fprintf (trace_file, "\n----------OPTIONAL PLUS PTYPE----------");      source_format = getbits (3);      if (trace)      {        fprintf (trace_file, "\nsource_format: ");        printbits (source_format, 3, 3);      }          /* optional custom picture clock frequency */      optional_custom_PCF = getbits (1);      if (trace)      {        fprintf (trace_file, "\noptional_custom_PCF: ");        printbits (optional_custom_PCF, 1, 1);      }      if (optional_custom_PCF)      {        if (!quiet)          printf ("error: Optional custom picture clock frequency is not supported in this version\n");        exit (-1);      }      mv_outside_frame = getbits (1);      if (trace)      {        fprintf (trace_file, "\nmv_outside_frame: ");        printbits (mv_outside_frame, 1, 1);      }      long_vectors = (mv_outside_frame ? 1 : 0);      syntax_arith_coding = getbits (1);      if (trace)      {        fprintf (trace_file, "\nsyntax_arith_coding: ");        printbits (syntax_arith_coding, 1, 1);      }            adv_pred_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nadv_pred_mode: ");        printbits (adv_pred_mode, 1, 1);      }      mv_outside_frame = (adv_pred_mode ? 1 : mv_outside_frame);      overlapping_MC = (adv_pred_mode ? 1 : 0);      use_4mv = (adv_pred_mode ? 1 : 0);      pb_frame = 0;      advanced_intra_coding = getbits (1);      if (trace)      {        fprintf (trace_file, "\nadvanced_intra_coding: ");        printbits (advanced_intra_coding, 1, 1);      }      deblocking_filter_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\ndeblocking_filter_mode: ");        printbits (deblocking_filter_mode, 1, 1);      }      mv_outside_frame = (deblocking_filter_mode ? 1 : mv_outside_frame);      use_4mv = (deblocking_filter_mode ? 1 : use_4mv);      slice_structured_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nslice_structured_mode: ");        printbits (slice_structured_mode, 1, 1);      }      if (slice_structured_mode)      {        if (!quiet)          printf ("error: Slice structured mode is not supported in this version\n");        exit (-1);      }      reference_picture_selection_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nreference_picture_selection_mode: ");        printbits (reference_picture_selection_mode, 1, 1);      }      independently_segmented_decoding_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nindependently_segmented_decoding_mode: ");        printbits (independently_segmented_decoding_mode, 1, 1);      }      if (independently_segmented_decoding_mode)      {        if (!quiet)          printf ("error: Independently segmented decoding mode is not supported in this version\n");        exit (-1);      }      alternative_inter_VLC_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nalternative_inter_VLC_mode: ");        printbits (alternative_inter_VLC_mode, 1, 1);      }      modified_quantization_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nmodified_quantization_mode: ");        printbits (modified_quantization_mode, 1, 1);      }      tmp = getbits (4);      if (trace)      {        fprintf (trace_file, "\nspare, reserve, reserve, reserve: ");        printbits (tmp, 4, 4);      }      if (tmp != 8)      {                         /* OPPTYPE : bit15=1, bit16,bit17,bit18=0 */        if (!quiet)          printf ("error: The last 4 bits of OPPTYPE is expected to be 1000\n");        exit (-1);      }    }    if ((UFEP == 1) || (UFEP == 0))    {      if (UFEP == 0)      {        if (scalability_mode >= 3)        {          horizontal_size = lines[base_source_format];          vertical_size = pels[base_source_format];          mb_width = horizontal_size / 16;          mb_height = vertical_size / 16;          /* Need to store previous (reference layer) values            * for interpolation purposes, as the new values,            * i.e. of the spatially scaled layer, depend on            * the type of spatial scalability in use. */          ref_coded_picture_width = coded_picture_width = horizontal_size;          ref_coded_picture_height = coded_picture_height = vertical_size;          ref_chrom_width = chrom_width = coded_picture_width >> 1;          ref_chrom_height = chrom_height = coded_picture_height >> 1;          source_format = base_source_format;        }      }      /* MMPTYPE */      if (trace)        fprintf (trace_file, "\n----------MANDATORY PLUS PTYPE----------");      pict_type = getbits (3);      if (trace)      {        fprintf (trace_file, "\npict_type: ");        printbits (pict_type, 3, 3);      }      if (pict_type == PCT_IPB)        pb_frame = IM_PB_FRAMES;      else        pb_frame = 0;      if (PCT_B == pict_type)      {        true_B_frame = ON;        /* Allow motion over picture boundaries, regardless of whether or         * not UMV is turned on. */        mv_outside_frame = 1;        true_b_trb = temp_ref - prev_non_disposable_temp_ref;        if (true_b_trb < 0)          true_b_trb += 256;      } else      {        true_B_frame = OFF;        prev_non_disposable_temp_ref = next_non_disposable_temp_ref;        next_non_disposable_temp_ref = temp_ref;        trd = temp_ref - prev_non_disposable_temp_ref;        if (trd < 0)          trd += 256;      }      reference_picture_resampling_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nreference_picture_resampling_mode: ");        printbits (reference_picture_resampling_mode, 1, 1);      }      if (reference_picture_resampling_mode)      {        if (!quiet)          printf ("error: Reference picture resampling mode is not supported in this version\n");        exit (-1);      }      reduced_resolution_update_mode = getbits (1);      if (trace)      {        fprintf (trace_file, "\nreduced_resolution_update_mode: ");        printbits (reduced_resolution_update_mode, 1, 1);      }      if (reduced_resolution_update_mode)      {        if (!quiet)          printf ("error: Reduced resolution update mode is not supported in this version\n");        exit (-1);      }      rtype = getbits (1);      /* rounding type */      if (trace)      {        fprintf (trace_file, "\nrounding_type: ");        printbits (rtype, 1, 1);      }      if (trace)      {        fprintf (trace_file, "\nrtype: ");        printbits (rtype, 1, 1);      }      tmp = getbits (3);      if (trace)      {        fprintf (trace_file, "\nreserve, reserve, spare: ");        printbits (tmp, 3, 3);      }      if (tmp != 1)      {                         /* MPPTYPE : bit7,bit8=0  bit9=1 */        if (!quiet)          exit (-1);      }    } else    {      /* UFEP is neither 001 nor 000 */      if (!quiet)        printf ("error: UFEP should be either 001 or 000.\n");      exit (-1);    }    tmp = getbits (1);    if (trace)    {      fprintf (trace_file, "\nCPM: ");      printbits (tmp, 1, 1);    }    if (tmp)    {      if (!quiet)        printf ("error: CPM not supported in this version\n");      exit (-1);    }      if (UFEP && (source_format == SF_CUSTOM))    {      /* Read custom picture format */      if (trace)        fprintf (trace_file, "\ncustom picture format \n");      CP_PAR_code = getbits (4);      if (trace)      {        fprintf (trace_file, "\nCP_PAR_code: ");        printbits (CP_PAR_code, 4, 4);      }      if (CP_PAR_code != PAR_CIF)      {        if (!quiet)        {          printf ("error: only 12:11 pixel aspect ratio supported ");        }        exit(-1);      }      tmp=getbits (9);      horizontal_size = (tmp + 1 ) * 4;      if (trace)      {        fprintf (trace_file, "\nCP_picture_width_indication: ");        printbits (tmp, 9, 9);      }      tmp = getbits (1);      if (trace)      {        fprintf (trace_file, "\nspare: ");        printbits (tmp, 1, 1);      }      if (!tmp)      {        if (!quiet)          printf ("error: The 14th bit of Custom Picture Format(CPFMT) should be 1\n");        exit (-1);      }      tmp = getbits (9);      vertical_size = tmp * 4;      if (trace)      {        fprintf (trace_file, "\nCP_picture_height_indication: ");        printbits (tmp, 9, 9);      }      if ((horizontal_size%16) || (vertical_size%16))      {        if(!quiet)        {          printf ("error: only factor of 16 custom source format supported\n");        }        exit (-1);      }      if (CP_PAR_code == EXTENDED_PAR)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -