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

📄 image.c

📁 此code含H.264解码需要的 lib和 src
💻 C
📖 第 1 页 / 共 5 页
字号:

/*!
 ***********************************************************************
 * \file image.c
 *
 * \brief
 *    Decode a Slice
 *
 * \author
 *    Main contributors (see contributors.h for copyright, address and affiliation details)
 *    - Inge Lille-Langoy               <inge.lille-langoy@telenor.com>
 *    - Rickard Sjoberg                 <rickard.sjoberg@era.ericsson.se>
 *    - Jani Lainema                    <jani.lainema@nokia.com>
 *    - Sebastian Purreiter             <sebastian.purreiter@mch.siemens.de>
 *    - Byeong-Moon Jeon                <jeonbm@lge.com>
 *    - Thomas Wedi                     <wedi@tnt.uni-hannover.de>
 *    - Gabi Blaettermann
 *    - Ye-Kui Wang                     <wyk@ieee.org>
 *    - Antti Hallapuro                 <antti.hallapuro@nokia.com>
 *    - Alexis Tourapis                 <alexismt@ieee.org>
 *    - Jill Boyce                      <jill.boyce@thomson.net>
 *    - Saurav K Bandyopadhyay          <saurav@ieee.org>
 *    - Zhenyu Wu                       <Zhenyu.Wu@thomson.net
 *    - Purvin Pandit                   <Purvin.Pandit@thomson.net>
 *
 ***********************************************************************
 */

//#include "contributors.h"

#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#if defined(WIN32) || defined(UNDER_CE)

#else
#include <unistd.h>
#endif

#include "global.h"
//#include "errorconcealment.h"
#include "image.h"
#include "mbuffer.h"
//#include "fmo.h"
#include "nalu.h"
#include "parsetcommon.h"
#include "parset.h"
#include "header.h"
//#include "rtp.h"
#include "sei.h"
//#include "output.h"
//#include "biaridecod.h"
//#include "mb_access.h"
#include "memalloc.h"
#include "annexb.h"

//#include "context_ini.h"
//#include "cabac.h"
//#include "loopfilter.h"

#include "vlc.h"

//#include "erc_api.h"
//extern objectBuffer_t *erc_object_list;
//extern ercVariables_t *erc_errorVar;
//extern frame erc_recfr;
//extern int erc_mvperMB;
//extern struct img_par *erc_img;

//extern FILE *p_out2;

extern StorablePicture **listX[6];
//extern ColocatedParams *Co_located;

extern StorablePicture *no_reference_picture;
int non_conforming_stream;

StorablePicture *dec_picture;

OldSliceParams old_slice;

#if !defined(max)
#define max( a , b ) ( (a) > (b) ? (a) : (b) )
#endif

void write_reg(int address, int data)
{
	h264_reg[h264_reg_size].address = address;
    h264_reg[h264_reg_size].data = data;
	h264_reg_size++;
	
	return;
}

//void MbAffPostProc()
//{
//  imgpel temp[16][32];
//
//  imgpel ** imgY  = dec_picture->imgY;
//  imgpel ***imgUV = dec_picture->imgUV;
//
//  int i, x, y, x0, y0, uv;
//  for (i=0; i<(int)dec_picture->PicSizeInMbs; i+=2)
//  {
//    if (dec_picture->mb_field[i])
//    {
//      get_mb_pos(i, &x0, &y0, IS_LUMA);
//      for (y=0; y<(2*MB_BLOCK_SIZE);y++)
//        for (x=0; x<MB_BLOCK_SIZE; x++)
//          temp[x][y] = imgY[y0+y][x0+x];
//
//      for (y=0; y<MB_BLOCK_SIZE;y++)
//        for (x=0; x<MB_BLOCK_SIZE; x++)
//        {
//          imgY[y0+(2*y)][x0+x]   = temp[x][y];
//          imgY[y0+(2*y+1)][x0+x] = temp[x][y+MB_BLOCK_SIZE];
//        }
//
//      if (dec_picture->chroma_format_idc != YUV400)
//      {
//        x0 = x0 / (16/img->mb_cr_size_x);
//        y0 = y0 / (16/img->mb_cr_size_y);
//
//        for (uv=0; uv<2; uv++)
//        {
//          for (y=0; y<(2*img->mb_cr_size_y);y++)
//            for (x=0; x<img->mb_cr_size_x; x++)
//              temp[x][y] = imgUV[uv][y0+y][x0+x];
//
//          for (y=0; y<img->mb_cr_size_y;y++)
//            for (x=0; x<img->mb_cr_size_x; x++)
//            {
//              imgUV[uv][y0+(2*y)][x0+x]   = temp[x][y];
//              imgUV[uv][y0+(2*y+1)][x0+x] = temp[x][y+img->mb_cr_size_y];
//            }
//        }
//      }
//    }
//  }
//}

/*!
 ***********************************************************************
 * \brief
 *    decodes one I- or P-frame
 *
 ***********************************************************************
 */
//int decode_one_frame(struct img_par *img,struct inp_par *inp/*, struct snr_par *snr*/)
//{
//  int current_header;
//  Slice *currSlice = img->currentSlice;
//  int i;
//
//  img->current_slice_nr = 0;
//  img->current_mb_nr = -4711;     // initialized to an impossible value for debugging -- correct value is taken from slice header
//  currSlice->next_header = -8888; // initialized to an impossible value for debugging -- correct value is taken from slice header
//  img->num_dec_mb = 0;
//  img->newframe = 1;
//
//  while (1/*(currSlice->next_header != EOS && currSlice->next_header != SOP)*/)
//  {
//    current_header = read_new_slice();
//
//    // error tracking of primary and redundant slices.
//    Error_tracking();
//
//    // If primary and redundant are received and primary is correct, discard the redundant
//    // else, primary slice will be replaced with redundant slice.
//    if(img->frame_num == previous_frame_num && img->redundant_pic_cnt !=0
//      && Is_primary_correct !=0 && current_header != EOS)
//    {
//      continue;
//    }
//
//    // update reference flags and set current ref_flag
//    if(!(img->redundant_pic_cnt != 0 && previous_frame_num == img->frame_num))
//    {
//      for(i=16;i>0;i--)
//      {
//        ref_flag[i] = ref_flag[i-1];
//      }
//    }
//    ref_flag[0] = img->redundant_pic_cnt==0 ? Is_primary_correct : Is_redundant_correct;
//
//    previous_frame_num = img->frame_num;
//
//    if (current_header == EOS)
//    {
//      exit_picture();
//      return EOS;
//    }
//
//    decode_slice(img, inp, current_header);
//
//    img->newframe = 0;
//    img->current_slice_nr++;
//  }
//
//  exit_picture();
//
//  return (SOP);
//}
//

/*!
 ************************************************************************
 * \brief
 *    Convert file read buffer to source picture structure
 * \param imgX
 *    Pointer to image plane
 * \param buf
 *    Buffer for file output
 * \param size_x
 *    horizontal image size in pixel
 * \param size_y
 *    vertical image size in pixel
 * \param symbol_size_in_bytes
 *    number of bytes used per pel
 ************************************************************************
 */
//void buf2img (imgpel** imgX, unsigned char* buf, int size_x, int size_y, int symbol_size_in_bytes)
//{
//  int i,j;
//
//  unsigned short tmp16, ui16;
//  unsigned long  tmp32, ui32;
//
//  if (symbol_size_in_bytes> sizeof(imgpel))
//  {
//    error ("Source picture has higher bit depth than imgpel data type. Please recompile with larger data type for imgpel.", 500);
//  }
//
//  if (( sizeof(char) == sizeof (imgpel)) && ( sizeof(char) == symbol_size_in_bytes))
//  {
//    // imgpel == pixel_in_file == 1 byte -> simple copy
//    for(j=0;j<size_y;j++)
//      memcpy(&imgX[j][0], buf+j*size_x, size_x);
//  }
//  else
//  {
//    // sizeof (imgpel) > sizeof(char)
//    if (testEndian())
//    {
//      // big endian
//      switch (symbol_size_in_bytes)
//      {
//      case 1:
//        {
//          for(j=0;j<size_y;j++)
//            for(i=0;i<size_x;i++)
//            {
//              imgX[j][i]= buf[i+j*size_x];
//            }
//          break;
//        }
//      case 2:
//        {
//          for(j=0;j<size_y;j++)
//            for(i=0;i<size_x;i++)
//            {
//              memcpy(&tmp16, buf+((i+j*size_x)*2), 2);
//              ui16  = (tmp16 >> 8) | ((tmp16&0xFF)<<8);
//              imgX[j][i] = (imgpel) ui16;
//            }
//          break;
//        }
//      case 4:
//        {
//          for(j=0;j<size_y;j++)
//            for(i=0;i<size_x;i++)
//            {
//              memcpy(&tmp32, buf+((i+j*size_x)*4), 4);
//              ui32  = ((tmp32&0xFF00)<<8) | ((tmp32&0xFF)<<24) | ((tmp32&0xFF0000)>>8) | ((tmp32&0xFF000000)>>24);
//              imgX[j][i] = (imgpel) ui32;
//            }
//        }
//      default:
//        {
//           error ("reading only from formats of 8, 16 or 32 bit allowed on big endian architecture", 500);
//           break;
//        }
//      }
//
//    }
//    else
//    {
//      // little endian
//      if (symbol_size_in_bytes == 1)
//      {
//        for (j=0; j < size_y; j++)
//        {
//          for (i=0; i < size_x; i++)
//          {
//            imgX[j][i]=*(buf++);
//          }
//        }
//      }
//      else
//      {
//        for (j=0; j < size_y; j++)
//        {
//          int jpos = j*size_x;
//          for (i=0; i < size_x; i++)
//          {
//            imgX[j][i]=0;
//            memcpy(&(imgX[j][i]), buf +((i+jpos)*symbol_size_in_bytes), symbol_size_in_bytes);
//          }
//        }
//      }
//
//    }
//  }
//}


/*!
************************************************************************
* \brief
*    Find PSNR for all three components.Compare decoded frame with
*    the original sequence. Read inp->jumpd frames to reflect frame skipping.
************************************************************************
*/
//void find_snr(
//              struct snr_par  *snr,   //!< pointer to snr parameters
//              StorablePicture *p,     //!< picture to be compared
//              int p_ref)              //!< open reference YUV file
//{
//  static const int SubWidthC  [4]= { 1, 2, 2, 1};
//  static const int SubHeightC [4]= { 1, 2, 1, 1};
//  int crop_left, crop_right, crop_top, crop_bottom;
//
//  int i,j, k;
//  int64 diff_comp[3] = {0};
//  int64  status;
//  int symbol_size_in_bytes = img->pic_unit_bitsize_on_disk/8;
//  int comp_size_x[3], comp_size_y[3];
//  int64 framesize_in_bytes;
//
//  unsigned int max_pix_value_sqd[3] = {iabs2(img->max_imgpel_value),  iabs2(img->max_imgpel_value_uv), iabs2(img->max_imgpel_value_uv)};
//
//  Boolean rgb_output = (Boolean) (active_sps->vui_seq_parameters.matrix_coefficients==0);
//  unsigned char *buf;
//  imgpel **cur_ref[3]  = {imgY_ref, imgUV_ref[0], imgUV_ref[1]};
//  imgpel **cur_comp[3] = {p->imgY, p->imgUV[0], p->imgUV[1]};
//
//  // picture error concealment
//  char yuv_types[4][6]= {"4:0:0","4:2:0","4:2:2","4:4:4"};
//
//  // calculate frame number
//  int  psnrPOC = active_sps->mb_adaptive_frame_field_flag ? p->poc /(input->poc_scale) : p->poc/(input->poc_scale);
//
//  // cropping for luma
//  if (p->frame_cropping_flag)
//  {
//    crop_left   = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset;
//    crop_right  = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset;
//    crop_top    = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) *  p->frame_cropping_rect_top_offset;
//    crop_bottom = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) *  p->frame_cropping_rect_bottom_offset;
//  }
//  else
//  {
//    crop_left = crop_right = crop_top = crop_bottom = 0;
//  }
//
//  comp_size_x[0] = p->size_x - crop_left - crop_right;
//  comp_size_y[0] = p->size_y - crop_top - crop_bottom;
//
//  // cropping for chroma
//  if (p->frame_cropping_flag)
//  {
//    crop_left   = p->frame_cropping_rect_left_offset;
//    crop_right  = p->frame_cropping_rect_right_offset;
//    crop_top    = ( 2 - p->frame_mbs_only_flag ) *  p->frame_cropping_rect_top_offset;
//    crop_bottom = ( 2 - p->frame_mbs_only_flag ) *   p->frame_cropping_rect_bottom_offset;
//  }
//  else
//  {
//    crop_left = crop_right = crop_top = crop_bottom = 0;
//  }

⌨️ 快捷键说明

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