Changeset 540 in SHVCSoftware for trunk/source/App


Ignore:
Timestamp:
9 Jan 2014, 05:04:17 (11 years ago)
Author:
seregin
Message:

merge SHM-4.1-dev branch

Location:
trunk
Files:
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/App/TAppDecoder/TAppDecCfg.cpp

    r313 r540  
    6969  string cfg_ReconFile [MAX_LAYERS];
    7070  Int nLayerNum;
     71#if OUTPUT_LAYER_SET_INDEX
     72  Int olsIdx;
     73#endif
    7174#if AVC_BASE
    7275  string cfg_BLReconFile;
     
    110113#if SVC_EXTENSION
    111114  ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
     115#if OUTPUT_LAYER_SET_INDEX
     116  ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.")
     117#endif
    112118#endif
    113119  ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers")
     
    138144  m_tgtLayerId = nLayerNum - 1;
    139145  assert( m_tgtLayerId >= 0 );
     146#if OUTPUT_LAYER_SET_INDEX 
     147  this->getCommonDecoderParams()->setOutputLayerSetIdx( olsIdx       );
     148  this->getCommonDecoderParams()->setTargetLayerId    ( m_tgtLayerId );
     149#endif
    140150  for(UInt layer=0; layer<= m_tgtLayerId; layer++)
    141151  {
     
    201211      fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() );
    202212    }
     213#if OUTPUT_LAYER_SET_INDEX 
     214    this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet );
     215#endif
    203216  }
    204217
  • trunk/source/App/TAppDecoder/TAppDecCfg.h

    r313 r540  
    9191  std::vector<Int> m_targetDecLayerIdSet;             ///< set of LayerIds to be included in the sub-bitstream extraction process.
    9292  Int           m_respectDefDispWindow;               ///< Only output content inside the default display window
     93#if OUTPUT_LAYER_SET_INDEX
     94  CommonDecoderParams             m_commonDecoderParams;
     95#endif
    9396
    9497public:
     
    120123 
    121124  Bool  parseCfg        ( Int argc, Char* argv[] );   ///< initialize option class from configuration
     125#if OUTPUT_LAYER_SET_INDEX
     126  CommonDecoderParams* getCommonDecoderParams() {return &m_commonDecoderParams;}
     127#endif
    122128};
    123129
  • trunk/source/App/TAppDecoder/TAppDecTop.cpp

    r494 r540  
    145145  // main decoder loop
    146146  Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
     147  Bool loopFiltered[MAX_LAYERS];
     148  memset( loopFiltered, false, sizeof( loopFiltered ) );
     149
    147150  for(UInt layer=0; layer<=m_tgtLayerId; layer++)
    148151  {
     
    223226      }
    224227    }
    225     if (bNewPicture || !bitstreamFile)
     228
     229    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
    226230    {
    227231#if O0194_DIFFERENT_BITDEPTH_EL_BL
     
    230234      g_bitDepthC = g_bitDepthCLayer[curLayerId];
    231235#endif
    232       m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
     236      if (!loopFiltered[curLayerId] || bitstreamFile)
     237      {
     238        m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic);
     239      }
     240      loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS);
    233241#if EARLY_REF_PIC_MARKING
    234242      m_acTDecTop[curLayerId].earlyPicMarking(m_iMaxTemporalLayer, m_targetDecLayerIdSet);
     
    256264        xFlushOutput( pcListPic, curLayerId );
    257265      }
     266      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
     267      {
     268        xFlushOutput( pcListPic, curLayerId );       
     269      }
    258270      // write reconstruction to file
    259271      if(bNewPicture)
     
    316328  // main decoder loop
    317329  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
     330  Bool loopFiltered = false;
    318331
    319332#if SYNTAX_OUTPUT
     
    384397      }
    385398    }
    386     if (bNewPicture || !bitstreamFile)
    387     {
    388       m_cTDecTop.executeLoopFilters(poc, pcListPic);
     399    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS)
     400    {
     401      if (!loopFiltered || bitstreamFile)
     402      {
     403        m_cTDecTop.executeLoopFilters(poc, pcListPic);
     404      }
     405      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
    389406    }
    390407
     
    408425        xFlushOutput( pcListPic );
    409426      }
     427      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
     428      {
     429        xFlushOutput( pcListPic );       
     430      }
    410431      // write reconstruction to file
    411432      if(bNewPicture)
     
    494515    m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled);
    495516    m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 );
     517#if OUTPUT_LAYER_SET_INDEX
     518    m_acTDecTop[layer].setCommonDecoderParams( this->getCommonDecoderParams() );
     519#endif
    496520  }
    497521
     
    503527
    504528/** \param pcListPic list of pictures to be written to file
    505 \todo            DYN_REF_FREE should be revised
    506 */
     529    \todo            DYN_REF_FREE should be revised
     530 */
    507531#if SVC_EXTENSION
    508532Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId )
     
    511535#endif
    512536{
     537  if (pcListPic->empty())
     538  {
     539    return;
     540  }
     541
    513542  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
    514543  Int numPicsNotYetDisplayed = 0;
     
    730759#endif
    731760{
    732   if(!pcListPic)
     761  if(!pcListPic || pcListPic->empty())
    733762  {
    734763    return;
  • trunk/source/App/TAppDownConvert/TAppDownConvert.cpp

    r442 r540  
    3535    \brief    Down convert application main
    3636*/
    37 #include <stdio.h>
    38 #include <stdlib.h>
    39 #include <string.h>
    40 #include <math.h>
    41 
    42 //! \ingroup TAppDecoder
    43 //! \{
    44 
    45 #define pi 3.1415926
    46 
    47 int get_mem2DPelWithPad(unsigned char ***array2D, int dim0, int dim1, int iPadY, int iPadX)
    48 {
    49   int i;
    50   unsigned char *curr = NULL;
    51   int iHeight, iWidth;
    52 
    53   iHeight = dim0+2*iPadY;
    54   iWidth = dim1+2*iPadX;
    55   (*array2D) = (unsigned char**)malloc(iHeight*sizeof(unsigned char*));
    56   *(*array2D) = (unsigned char* )calloc(iHeight * iWidth, sizeof(unsigned char ));
    57 
    58   (*array2D)[0] += iPadX;
    59   curr = (*array2D)[0];
    60   for(i = 1 ; i < iHeight; i++)
    61   {
    62     curr += iWidth;
    63     (*array2D)[i] = curr;
    64   }
    65   (*array2D) = &((*array2D)[iPadY]);
    66 
     37
     38#include <cmath>
     39#include <cstdio>
     40#include <cstdlib>
     41#include <cstring>
     42#include <ctime>
     43
     44#include "DownConvert.h"
     45
     46typedef struct
     47{
     48  int            stride;
     49  int            lines;
     50  unsigned char* data;
     51  unsigned char* data2;
     52} ColorComponent;
     53
     54typedef struct
     55{
     56  ColorComponent y;
     57  ColorComponent u;
     58  ColorComponent v;
     59} YuvFrame;
     60
     61
     62void
     63  createColorComponent( ColorComponent& c, int maxwidth, int maxheight )
     64{
     65  maxwidth  = ( ( maxwidth  + 15 ) >> 4 ) << 4;
     66  maxheight = ( ( maxheight + 15 ) >> 4 ) << 4;
     67  int size  = maxwidth * maxheight;
     68  c.stride  = maxwidth;
     69  c.lines   = maxheight;
     70  c.data    = new unsigned char [ size ];
     71  c.data2   = new unsigned char [ size ];
     72
     73  if( ! c.data || ! c.data2 )
     74  {
     75    fprintf(stderr, "\nERROR: memory allocation failed!\n\n");
     76    exit(1);
     77  }
     78}
     79
     80void
     81  deleteColorComponent( ColorComponent& c )
     82{
     83  delete[] c.data;
     84  delete[] c.data2;
     85  c.stride  = 0;
     86  c.lines   = 0;
     87  c.data    = 0;
     88  c.data2   = 0;
     89}
     90
     91int
     92  readColorComponent( ColorComponent& c, FILE* file, int width, int height, bool second )
     93{
     94  assert( width  <= c.stride );
     95  assert( height <= c.lines  );
     96
     97  int iMaxPadWidth  = gMin( c.stride, ( ( width  + 15 ) >> 4 ) << 4 );
     98  int iMaxPadHeight = gMin( c.lines,  ( ( height + 31 ) >> 5 ) << 5 );
     99
     100  for( int i = 0; i < height; i++ )
     101  {
     102    unsigned char* buffer = ( second ? c.data2 : c.data ) + i * c.stride;
     103    int            rsize  = (int)fread( buffer, sizeof(unsigned char), width, file );
     104    if( rsize != width )
     105    {
     106      return 1;
     107    }
     108    for( int xp = width; xp < iMaxPadWidth; xp++ )
     109    {
     110      buffer[xp] = buffer[xp-1];
     111    }
     112  }
     113  for( int yp = height; yp < iMaxPadHeight; yp++ )
     114  {
     115    unsigned char* buffer  = ( second ? c.data2 : c.data ) + yp * c.stride;
     116    unsigned char* bufferX = buffer - c.stride;
     117    for( int xp = 0; xp < c.stride; xp++ )
     118    {
     119      buffer[xp] = bufferX[xp];
     120    }
     121  }
    67122  return 0;
    68123}
    69124
    70 int get_mem2DintWithPad(int ***array2D, int dim0, int dim1, int iPadY, int iPadX)
    71 {
    72   int i;
    73   int *curr = NULL;
    74   int iHeight, iWidth;
    75 
    76   iHeight = dim0+2*iPadY;
    77   iWidth = dim1+2*iPadX;
    78   (*array2D) = (int**)malloc(iHeight*sizeof(int*));
    79   *(*array2D) = (int* )calloc(iHeight * iWidth, sizeof(int ));
    80 
    81   (*array2D)[0] += iPadX;
    82   curr = (*array2D)[0];
    83   for(i = 1 ; i < iHeight; i++)
    84   {
    85     curr += iWidth;
    86     (*array2D)[i] = curr;
    87   }
    88   (*array2D) = &((*array2D)[iPadY]);
    89 
     125void
     126  duplicateColorComponent( ColorComponent& c )
     127{
     128  memcpy( c.data2, c.data, c.stride * c.lines * sizeof(unsigned char) );
     129}
     130
     131void
     132  combineTopAndBottomInColorComponent( ColorComponent& c, Bool bBotField )
     133{
     134  int            offs = ( bBotField ? c.stride : 0 );
     135  unsigned char* pDes = c.data  + offs;
     136  unsigned char* pSrc = c.data2 + offs;
     137  for( int i = 0; i < c.lines / 2; i++, pDes += 2*c.stride, pSrc += 2*c.stride )
     138  {
     139    memcpy( pDes, pSrc, c.stride * sizeof(unsigned char) );
     140  }
     141}
     142
     143void
     144  writeColorComponent( ColorComponent& c, FILE* file, int width, int height, bool second )
     145{
     146  assert( width  <= c.stride );
     147  assert( height <= c.lines  );
     148
     149  for( int i = 0; i < height; i++ )
     150  {
     151    unsigned char* buffer = ( second ? c.data2 : c.data ) + i * c.stride;
     152    int            wsize  = (int)fwrite( buffer, sizeof(unsigned char), width, file );
     153
     154    if( wsize != width )
     155    {
     156      fprintf(stderr, "\nERROR: while writing to output file!\n\n");
     157      exit(1);
     158    }
     159  }
     160}
     161
     162
     163void
     164  createFrame( YuvFrame& f, int width, int height )
     165{
     166  createColorComponent( f.y, width,      height      );
     167  createColorComponent( f.u, width >> 1, height >> 1 );
     168  createColorComponent( f.v, width >> 1, height >> 1 );
     169}
     170
     171void
     172  deleteFrame( YuvFrame& f )
     173{
     174  deleteColorComponent( f.y );
     175  deleteColorComponent( f.u );
     176  deleteColorComponent( f.v );
     177}
     178
     179int
     180  readFrame( YuvFrame& f, FILE* file, int width, int height, bool second = false )
     181{
     182  ROTRS( readColorComponent( f.y, file, width,      height,      second ), 1 );
     183  ROTRS( readColorComponent( f.u, file, width >> 1, height >> 1, second ), 1 );
     184  ROTRS( readColorComponent( f.v, file, width >> 1, height >> 1, second ), 1 );
    90185  return 0;
    91186}
    92187
    93 void free_mem2DPelWithPad(unsigned char **array2D, int iPadY, int iPadX)
    94 {
    95   if (array2D)
    96   {
    97     if (*array2D)
    98     {
    99       free (array2D[-iPadY]-iPadX);
    100     }
    101     else
    102     {
    103       printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
    104     }
    105 
    106     free (&array2D[-iPadY]);
    107   }
    108   else
    109   {
    110     printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
    111   }
    112 }
    113 
    114 void free_mem2DintWithPad(int **array2D, int iPadY, int iPadX)
    115 {
    116   if (array2D)
    117   {
    118     if (*array2D)
    119     {
    120       free (array2D[-iPadY]-iPadX);
    121     }
    122     else
    123     {
    124       printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
    125     }
    126 
    127     free (&array2D[-iPadY]);
    128   }
    129   else
    130   {
    131     printf("free_mem2DintWithPad: trying to free unused memory\r\nPress Any Key\r\n");
    132   }
    133 }
    134 
    135 void PadImgHorizontal(unsigned char **src, unsigned char **dst, int height, int width, int pad_h)
    136 {
    137   int i, j;
    138   unsigned char *BufSrc, *BufDst;
    139 
    140   for (j=0;j<height;j++)
    141   {   
    142     BufDst = &(dst[j][-pad_h] );
    143     BufSrc = src[j];
    144     for (i=0;i<pad_h;i++)
    145     {
    146       *(BufDst++) = BufSrc[0];
    147     }
    148     memcpy(BufDst, BufSrc, width*sizeof(unsigned char));
    149     BufDst += width;
    150     for (i=0;i<pad_h;i++)
    151     {
    152       *(BufDst++) = BufSrc[width-1];
    153     }
    154   }
    155 }
    156 
    157 void FilterImg( unsigned char **src,
    158                 int           **temp,
    159                 unsigned char **dst,
    160                 int           height1, 
    161                 int           width1, 
    162                 int           M,
    163                 int           N,
    164                 int           **phase_filter,
    165                 int           length,
    166                 int           shift,
    167                 int           plane)
    168 {
    169   int height2,width2;
    170   int k,iSum;
    171   int i0, div_i0, i1;
    172   int j0, div_j0, j1;
    173   int *p_filter;
    174   unsigned char *p_src, *p_dst;
    175   int **p_temp, *p_tmp;
    176   int shift2 = (2*shift);
    177   int shift_round = (1 << (2 * shift - 1));
    178 
    179   height2 = (height1 * M) / N;
    180   width2  = (width1  * M) / N;
    181 
    182   // horizontal filtering
    183   for(j1 = 0; j1 < height1; j1++)
    184   {
    185     i0=-N;
    186     p_tmp = temp[j1];
    187     for(i1 = 0; i1 < width2; i1++)
    188     {
    189       i0      += N;
    190       div_i0   = (i0 / M);
    191       p_src    = &src[j1][ div_i0 - (length >> 1)];
    192       p_filter = phase_filter[i0 - div_i0 * M];
    193       iSum     = 0;
    194       for(k = 0; k < length; k++)
    195       {
    196         iSum += (*p_src++) * (*p_filter++);
    197       }
    198       *p_tmp++ = iSum;
    199     }
    200   }
    201 
    202   // pad temp (vertical)
    203   for (k=-(length>>1);k<0;k++)
    204     memcpy(temp[k], temp[0], width2*sizeof(int));
    205   for (k=height1;k<(height1+(length>>1));k++)
    206     memcpy(temp[k], temp[k-1], (width2)* sizeof(int));
    207 
    208   // vertical filtering
    209   j0 = (plane == 0) ? -N : -(N-1);
    210  
    211   for(j1 = 0; j1 < height2; j1++)
    212   {
    213     j0      += N;
    214     div_j0   = (j0 / M);
    215     p_dst    = dst[j1];
    216     p_temp   = &temp[div_j0 - (length>>1)];
    217     p_filter = phase_filter[j0 - div_j0 * M];
    218     for(i1 = 0; i1 < width2;i1++)
    219     {
    220       iSum=0;
    221       for(k = 0; k < length; k++)
    222       {
    223         iSum += p_temp[k][i1] * p_filter[k];
    224       }
    225       iSum=((iSum + shift_round) >> shift2);
    226       *p_dst++ = (unsigned char)(iSum > 255 ? 255 : iSum < 0 ? 0 : iSum);
    227     }
    228   }
    229 }
    230 
    231 // ====================================================================================================================
    232 // Main function
    233 // ====================================================================================================================
    234 
    235 int main(int argc, char *argv[])
    236 {
    237   const int phase_filter_0[4][13]={
    238     {0,  2,  -3,  -9,   6,  39,  58,  39,   6,  -9,  -3,  2,  0}, 
    239     {0,  1,  -1,  -8,  -1,  31,  57,  47,  13,  -7,  -5,  1,  0}, 
    240     {0,  1,   0,  -7,  -5,  22,  53,  53,  22,  -5,  -7,  0,  1}, 
    241     {0,  0,   1,  -5,  -7,  13,  47,  57,  31,  -1,  -8,-1,  1} 
    242   };
    243 
    244   const int phase_filter_1[8][13]={
    245     {0,   0,  5,  -6,  -10,  37,  76,  37,-10,   -6, 5,  0,   0},   
    246     {0,  -1,  5,  -3,  -12,  29,  75,  45,  -7,   -8, 5,  0,   0},   
    247     {0,  -1,  4,  -1,  -13,  22,  73,  52,  -3,  -10, 4,  1,   0},   
    248     {0,  -1,  4,   1,  -13,  14,  70,  59,   2,  -12, 3,  2,  -1}, 
    249     {0,  -1,  3,   2,  -13,   8,  65,  65,   8,  -13, 2,  3,  -1},   
    250     {0,  -1,  2,   3,  -12,   2,  59,  70,  14,  -13, 1,  4,  -1},   
    251     {0,   0,  1,   4,  -10,  -3,  52,  73,  22,  -13,-1,  4,  -1},   
    252     {0,   0,  0,   5,   -8,  -7,  45,  75,  29,  -12,-3,  5,  -1}   
    253   };
    254 
    255   int i,j;
    256 
    257   int width_org,  width_org_c,  width_sampled,  width_sampled_c;
    258   int height_org, height_org_c, height_sampled, height_sampled_c;
    259   int size_org,   size_org_c,   size_sampled,   size_sampled_c;
    260 
    261   unsigned char **Y1,    **U1,    **V1;
    262   unsigned char **Y2,    **U2,    **V2;
    263   unsigned char **temp_luma,    **temp_chroma;
    264   int           **tempY, **tempU, **tempV;
    265 
    266   int **phase_filter;
    267   int log2_scaling_factor=7;
    268 
    269   FILE * infile;
    270   FILE * outfile;
    271 
    272   int M = -1 ,N = -1;
    273   int ratio = -1;
    274   int Frames=0;
    275   int totalFrames=0;
    276   int StartFrame=0;
    277   int Tap=13;
    278 
    279   if (argc < 6)
    280   {
    281     printf("\nIncorrect number of arguments!!!\n\n");
    282     printf("Syntax: \n");
    283     printf("%s <input width> <input height> <input file> <output file> <downsampling method> [frames_to_process] [start_frame]\n\n", argv[0]);
    284     printf("<downsampling method> 0: 2x downsampling, 1: 1.5x downsampling. \n");
    285     printf("Examples: \n");
    286     printf("%s 1920 1080 input_1920x1080_24p.yuv output_960x540_24p.yuv 0 \n", argv[0]);
    287     printf("%s 1920 1080 input_1920x1080_24p.yuv output_1280x720_24p.yuv 1 \n", argv[0]);
    288     return -1;
    289   }
    290 
    291   width_org  = atoi  (argv[1]);
    292   height_org = atoi  (argv[2]);
    293   infile     = fopen (argv[3], "rb");
    294   outfile    = fopen (argv[4], "wb");
    295   ratio      = atoi  (argv[5]);
    296 
    297   for(i=7; i<= argc; i++)
    298   {
    299     switch(i)
    300     {
    301     case 7:
    302       Frames = atoi(argv[6]);
    303       break;
    304     case 8:
    305       StartFrame = atoi(argv[7]);
    306       break;
    307     default:
    308       printf("Too many input arguments");
    309       break;
    310     }
    311   }
    312 
    313   if( width_org < 4 || height_org < 4 )
    314   {
    315     printf("\ninput resolution is too small, exit\n");
    316     return -1;
    317   }
    318   if ( infile == NULL || outfile == NULL )
    319   {
    320     printf("\ninput or output file is invalid, exit\n");
    321     return -1;
    322   }
    323   if ((argc > 6) && (Frames < 1 || StartFrame < 0))
    324   {
    325     printf("input frame parameter error\n");
    326     return -1;
    327   }
    328 
    329   switch( ratio )
    330   {
    331   default:
    332     printf("\ndown sampling parameter %d is not supported (0: 2x downsampling, 1: 1.5x downsampling)\n", ratio);
    333     return -1;
    334   case 0:
    335     M=4;
    336     N=8;
    337     break;
    338   case 1:
    339     M=8;
    340     N=12;
    341     break;
    342   }
    343 
    344   width_org_c      = width_org  >> 1;
    345   height_org_c     = height_org >> 1;
    346   width_sampled    = (width_org  * M) / N;
    347   height_sampled   = (height_org * M) / N;
    348   width_sampled_c  = width_sampled  >> 1;
    349   height_sampled_c = height_sampled >> 1;
    350   size_org         = height_org * width_org;
    351   size_org_c       = height_org_c * width_org_c;
    352   size_sampled     = height_sampled * width_sampled;
    353   size_sampled_c   = height_sampled_c * width_sampled_c;
    354 
    355   printf("\n=============================================================\n");
    356   printf("\n Input  = %s", argv[3]);
    357   printf("\n Output = %s", argv[4]);
    358   printf("\n Rescaling input from (%d,%d) to (%d,%d) resolution\n", width_org, height_org, width_sampled, height_sampled);
    359   printf("\n=============================================================\n\n"); 
    360 
    361   // construct phase filters
    362   get_mem2DintWithPad (&phase_filter, M, Tap, 0, 0);
    363 
    364   for (j=0;j<M;j++)
    365     for (i=0;i<Tap;i++)
    366       phase_filter[j][i]= ratio==0 ? phase_filter_0[j][i] :  phase_filter_1[j][i];
    367 
    368   get_mem2DPelWithPad (&Y1, height_org,   width_org,   0, Tap>>1);
    369   get_mem2DPelWithPad (&U1, height_org_c, width_org_c, 0, Tap>>1);
    370   get_mem2DPelWithPad (&V1, height_org_c, width_org_c, 0, Tap>>1);
    371 
    372   get_mem2DintWithPad (&tempY, height_org,   width_sampled,   Tap>>1, 0);
    373   get_mem2DintWithPad (&tempU, height_org_c, width_sampled_c, Tap>>1, 0);
    374   get_mem2DintWithPad (&tempV, height_org_c, width_sampled_c, Tap>>1, 0);
    375 
    376   get_mem2DPelWithPad (&Y2, height_sampled,   width_sampled,  0,0);
    377   get_mem2DPelWithPad (&U2, height_sampled_c, width_sampled_c,0,0);
    378   get_mem2DPelWithPad (&V2, height_sampled_c, width_sampled_c,0,0);
    379 
    380   get_mem2DPelWithPad (&temp_luma,   height_org,   width_org,  0,0);
    381   get_mem2DPelWithPad (&temp_chroma, height_org_c, width_org_c,0,0);
    382 
    383   if(StartFrame!=0)
    384   {
    385     for (i = 0; i < StartFrame; i ++)
    386     {
    387       fread(temp_luma[0], sizeof(unsigned char), size_org,     infile);
    388       fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
    389       fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
    390       if (feof(infile))
    391       {
    392         printf("\nThe start frame number exceeds the file size\n");
    393         return -1;
    394       }
    395     }
    396     //fseek64(infile, (size_org * StartFrame * 3) >> 1,SEEK_SET);
    397   }
    398 
    399   if (Frames)
    400   {
    401     totalFrames = Frames;
    402   }
    403   else
    404   {
    405     totalFrames = 0x7FFF;
    406   }
    407 
    408   i = 0;
    409   while(totalFrames)
    410   {
    411    
    412     // read and pad Y
    413     fread(temp_luma[0], sizeof(unsigned char), size_org,     infile);
    414     PadImgHorizontal(temp_luma, Y1, height_org, width_org, Tap>>1);
    415 
    416     // read and pad U
    417     fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
    418     PadImgHorizontal(temp_chroma, U1, height_org_c, width_org_c, Tap>>1);
    419 
    420     // read and pad V
    421     fread(temp_chroma[0], sizeof(unsigned char), size_org_c, infile);
    422     PadImgHorizontal(temp_chroma, V1, height_org_c, width_org_c, Tap>>1);
    423 
    424     if (feof(infile))
    425     {
    426       break;
    427     }
    428 
    429     fprintf(stdout,"Rescaling %dth frame\r", i);
    430     fflush(stdout);
    431 
    432     i ++;
    433     totalFrames --;
    434 
    435     FilterImg(Y1,tempY,Y2,height_org,  width_org,  M, N, phase_filter,Tap,log2_scaling_factor,0);
    436     FilterImg(U1,tempU,U2,height_org_c,width_org_c,M, N, phase_filter,Tap,log2_scaling_factor,1);
    437     FilterImg(V1,tempV,V2,height_org_c,width_org_c,M, N, phase_filter,Tap,log2_scaling_factor,2);
    438 
    439     // write a sampled frame
    440     fwrite(Y2[0], sizeof(unsigned char), size_sampled,     outfile);
    441     fwrite(U2[0], sizeof(unsigned char), size_sampled_c, outfile);
    442     fwrite(V2[0], sizeof(unsigned char), size_sampled_c, outfile);
    443 
    444   }
    445 
    446   printf("\nEnd of rescaling process.\n");
    447 
    448   free_mem2DintWithPad (phase_filter, 0, 0);
    449 
    450   free_mem2DPelWithPad (Y1, 0, Tap>>1);
    451   free_mem2DPelWithPad (U1, 0, Tap>>1);
    452   free_mem2DPelWithPad (V1, 0, Tap>>1);
    453 
    454   free_mem2DintWithPad (tempY, Tap>>1, 0);
    455   free_mem2DintWithPad (tempU, Tap>>1, 0);
    456   free_mem2DintWithPad (tempV, Tap>>1, 0);
    457 
    458   free_mem2DPelWithPad (Y2,0,0);
    459   free_mem2DPelWithPad (U2,0,0);
    460   free_mem2DPelWithPad (V2,0,0);
    461 
    462   free_mem2DPelWithPad (temp_luma,  0,0);
    463   free_mem2DPelWithPad (temp_chroma,0,0);
    464 
    465   fclose(infile);
    466   fclose(outfile);
    467 
     188void
     189  duplicateFrame( YuvFrame& f )
     190{
     191  duplicateColorComponent( f.y );
     192  duplicateColorComponent( f.u );
     193  duplicateColorComponent( f.v );
     194}
     195
     196void
     197  combineTopAndBottomInFrame( YuvFrame& f, Bool botField )
     198{
     199  combineTopAndBottomInColorComponent( f.y, botField );
     200  combineTopAndBottomInColorComponent( f.u, botField );
     201  combineTopAndBottomInColorComponent( f.v, botField );
     202}
     203
     204void
     205  writeFrame( YuvFrame& f, FILE* file, int width, int height, bool both = false )
     206{
     207  writeColorComponent( f.y, file, width,      height,      false );
     208  writeColorComponent( f.u, file, width >> 1, height >> 1, false );
     209  writeColorComponent( f.v, file, width >> 1, height >> 1, false );
     210
     211  if( both )
     212  {
     213    writeColorComponent( f.y, file, width,      height,      true );
     214    writeColorComponent( f.u, file, width >> 1, height >> 1, true );
     215    writeColorComponent( f.v, file, width >> 1, height >> 1, true );
     216  }
     217}
     218
     219
     220void
     221  print_usage_and_exit( int test, const char* name, const char* message = 0 )
     222{
     223  if( test )
     224  {
     225    if( message )
     226    {
     227      fprintf ( stderr, "\nERROR: %s\n", message );
     228    }
     229    fprintf (   stderr, "\nUsage: %s <win> <hin> <in> <wout> <hout> <out> [<t> [<skip> [<frms>]]] [[-phase <args>] ]\n\n", name );
     230    fprintf (   stderr, "  win     : input width  (luma samples)\n" );
     231    fprintf (   stderr, "  hin     : input height (luma samples)\n" );
     232    fprintf (   stderr, "  in      : input file\n" );
     233    fprintf (   stderr, "  wout    : output width  (luma samples)\n" );
     234    fprintf (   stderr, "  hout    : output height (luma samples)\n" );
     235    fprintf (   stderr, "  out     : output file\n" );
     236    fprintf (   stderr, "\n--------------------------- OPTIONAL ---------------------------\n\n" );
     237    fprintf (   stderr, "  t       : number of temporal downsampling stages (default: 0)\n" );
     238    fprintf (   stderr, "  skip    : number of frames to skip at start (default: 0)\n" );
     239    fprintf (   stderr, "  frms    : number of frames wanted in output file (default: max)\n" );
     240    fprintf (   stderr, "\n-------------------------- OVERLOADED --------------------------\n\n" );
     241    fprintf (   stderr, " -phase <in_uv_ph_x> <in_uv_ph_y> <out_uv_ph_x> <out_uv_ph_y>\n");
     242    fprintf (   stderr, "   in_uv_ph_x : input  chroma phase shift in horizontal direction (default:-1)\n" );
     243    fprintf (   stderr, "   in_uv_ph_y : input  chroma phase shift in vertical   direction (default: 0)\n" );
     244    fprintf (   stderr, "   out_uv_ph_x: output chroma phase shift in horizontal direction (default:-1)\n" );
     245    fprintf (   stderr, "   out_uv_ph_y: output chroma phase shift in vertical   direction (default: 0)\n" );
     246    fprintf (   stderr, "\n\n");
     247    exit    (   1 );
     248  }
     249}
     250
     251
     252void
     253  updateCropParametersFromFile( ResizeParameters& cRP, FILE* cropFile, int resamplingMethod, char* name )
     254{
     255  int crop_x0 = 0;
     256  int crop_y0 = 0;
     257  int crop_w  = 0;
     258  int crop_h  = 0;
     259  if( fscanf( cropFile, "%d,%d,%d,%d\n", &crop_x0, &crop_y0, &crop_w, &crop_h ) == 4 )
     260  {
     261    cRP.m_iLeftFrmOffset      = crop_x0;
     262    cRP.m_iTopFrmOffset       = crop_y0;
     263    cRP.m_iScaledRefFrmWidth  = crop_w;
     264    cRP.m_iScaledRefFrmHeight = crop_h;
     265  }
     266  print_usage_and_exit( cRP.m_iLeftFrmOffset     & 1 || cRP.m_iTopFrmOffset       & 1,                                              name, "cropping parameters must be even values" );
     267  print_usage_and_exit( cRP.m_iScaledRefFrmWidth & 1 || cRP.m_iScaledRefFrmHeight & 1,                                              name, "cropping parameters must be even values" );
     268  print_usage_and_exit( resamplingMethod == 2 && cRP.m_iScaledRefFrmWidth  != gMin( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),  name, "crop dimensions must be the same as the minimal dimensions" );
     269  print_usage_and_exit( resamplingMethod == 2 && cRP.m_iScaledRefFrmHeight != gMin( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),  name, "crop dimensions must be the same as the minimal dimensions" );
     270  print_usage_and_exit( cRP.m_iScaledRefFrmWidth  > gMax( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),                            name, "wrong crop window size" );
     271  print_usage_and_exit( cRP.m_iScaledRefFrmHeight > gMax( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),                            name, "wrong crop window size" );
     272  print_usage_and_exit( cRP.m_iScaledRefFrmWidth  < gMin( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),                            name, "wrong crop window size" );
     273  print_usage_and_exit( cRP.m_iScaledRefFrmHeight < gMin( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),                            name, "wrong crop window size" );
     274  print_usage_and_exit( cRP.m_iLeftFrmOffset + cRP.m_iScaledRefFrmWidth  > gMax( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ),     name, "wrong crop window size and origin" );
     275  print_usage_and_exit( cRP.m_iTopFrmOffset  + cRP.m_iScaledRefFrmHeight > gMax( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight ),     name, "wrong crop window size and origin" );
     276}
     277
     278
     279void
     280  resampleFrame( YuvFrame&          rcFrame,
     281  DownConvert&       rcDownConvert,
     282  ResizeParameters&  rcRP,
     283  int                resamplingMethod,
     284  int                resamplingMode,
     285  bool               resampling,
     286  bool               upsampling,
     287  bool               bSecondInputFrame )
     288{
     289  assert( upsampling == 0 );
     290
     291  //===== downsampling =====
     292  ResizeParameters cRP = rcRP;
     293  {
     294    Int iRefVerMbShift        = ( cRP.m_bRefLayerFrameMbsOnlyFlag ? 4 : 5 );
     295    Int iScaledVerShift       = ( cRP.m_bFrameMbsOnlyFlag         ? 1 : 2 );
     296    Int iHorDiv               = ( cRP.m_iFrameWidth    <<               1 );
     297    Int iVerDiv               = ( cRP.m_iFrameHeight   << iScaledVerShift );
     298    Int iRefFrmW              = ( ( cRP.m_iFrameWidth   + ( 1 <<               4 ) - 1 ) >>               4 ) <<               4;        // round to next multiple of 16
     299    Int iRefFrmH              = ( ( cRP.m_iFrameHeight  + ( 1 <<  iRefVerMbShift ) - 1 ) >>  iRefVerMbShift ) <<  iRefVerMbShift;        // round to next multiple of 16 or 32 (for interlaced)
     300    Int iScaledRefFrmW        = ( ( cRP.m_iScaledRefFrmWidth  * iRefFrmW + ( iHorDiv >> 1 ) ) / iHorDiv ) <<               1;  // scale and round to next multiple of  2
     301    Int iScaledRefFrmH        = ( ( cRP.m_iScaledRefFrmHeight * iRefFrmH + ( iVerDiv >> 1 ) ) / iVerDiv ) << iScaledVerShift;  // scale and round to next multiple of  2 or  4 (for interlaced)
     302    cRP.m_iFrameWidth         = iRefFrmW;
     303    cRP.m_iFrameHeight        = iRefFrmH;
     304    cRP.m_iScaledRefFrmWidth  = iScaledRefFrmW;
     305    cRP.m_iScaledRefFrmHeight = iScaledRefFrmH;
     306  }
     307  assert( resamplingMethod == 0 );
     308  if( resamplingMode < 4 )
     309  {
     310    rcDownConvert.downsamplingSVC       ( rcFrame.y.data,  rcFrame.y.stride, rcFrame.u.data,  rcFrame.u.stride, rcFrame.v.data,  rcFrame.v.stride, &cRP, resamplingMode == 3 );
     311    return;
     312  }
     313}
     314
     315
     316
     317int
     318  main( int argc, char *argv[] )
     319{
     320  //===== set standard resize parameters =====
     321  ResizeParameters cRP;
     322  cRP.m_bRefLayerFrameMbsOnlyFlag   = true;
     323  cRP.m_bFrameMbsOnlyFlag           = true;
     324  cRP.m_bRefLayerFieldPicFlag       = false;
     325  cRP.m_bFieldPicFlag               = false;
     326  cRP.m_bRefLayerBotFieldFlag       = false;
     327  cRP.m_bBotFieldFlag               = false;
     328  cRP.m_bRefLayerIsMbAffFrame       = false;
     329  cRP.m_bIsMbAffFrame               = false;
     330#if ZERO_PHASE
     331  cRP.m_iRefLayerChromaPhaseX       = 0;
     332  cRP.m_iRefLayerChromaPhaseY       = 1;
     333  cRP.m_iChromaPhaseX               = 0;
     334  cRP.m_iChromaPhaseY               = 1;
     335#else
     336  cRP.m_iRefLayerChromaPhaseX       = -1;
     337  cRP.m_iRefLayerChromaPhaseY       = 0;
     338  cRP.m_iChromaPhaseX               = -1;
     339  cRP.m_iChromaPhaseY               = 0;
     340#endif
     341  cRP.m_iRefLayerFrmWidth           = 0;
     342  cRP.m_iRefLayerFrmHeight          = 0;
     343  cRP.m_iScaledRefFrmWidth          = 0;
     344  cRP.m_iScaledRefFrmHeight         = 0;
     345  cRP.m_iFrameWidth                 = 0;
     346  cRP.m_iFrameHeight                = 0;
     347  cRP.m_iLeftFrmOffset              = 0;
     348  cRP.m_iTopFrmOffset               = 0;
     349  //cRP.m_iExtendedSpatialScalability = 0;
     350  cRP.m_iLevelIdc                   = 0;
     351
     352  //===== init parameters =====
     353  FILE* inputFile                   = 0;
     354  FILE* outputFile                  = 0;
     355  FILE* croppingParametersFile      = 0;
     356  int   resamplingMethod            = 0;
     357  int   resamplingMode              = 0;
     358  bool  croppingInitialized         = false;
     359  bool  phaseInitialized            = false;
     360  bool  methodInitialized           = false;
     361  bool  resampling                  = false;
     362  bool  upsampling                  = false;
     363  int   numSpatialDyadicStages      = 0;
     364  int   skipBetween                 = 0;
     365  int   skipAtStart                 = 0;
     366  int   maxNumOutputFrames          = 0;
     367
     368
     369  //===== read input parameters =====
     370  print_usage_and_exit( ( argc < 7 || argc > 24 ), argv[0], "wrong number of arguments" );
     371  cRP.m_iRefLayerFrmWidth   = atoi  ( argv[1] );
     372  cRP.m_iRefLayerFrmHeight  = atoi  ( argv[2] );
     373  inputFile                 = fopen ( argv[3], "rb" );
     374  cRP.m_iFrameWidth         = atoi  ( argv[4] );
     375  cRP.m_iFrameHeight        = atoi  ( argv[5] );
     376  outputFile                = fopen ( argv[6], "wb" );
     377  print_usage_and_exit( ! inputFile,  argv[0], "failed to open input file" );
     378  print_usage_and_exit( ! outputFile, argv[0], "failed to open input file" );
     379  print_usage_and_exit( cRP.m_iRefLayerFrmWidth > cRP.m_iFrameWidth && cRP.m_iRefLayerFrmHeight < cRP.m_iFrameHeight, argv[0], "mixed upsampling and downsampling not supported" );
     380  print_usage_and_exit( cRP.m_iRefLayerFrmWidth < cRP.m_iFrameWidth && cRP.m_iRefLayerFrmHeight > cRP.m_iFrameHeight, argv[0], "mixed upsampling and downsampling not supported" );
     381  for( int i = 7; i < argc; )
     382  {
     383    if( ! strcmp( argv[i], "-phase" ) )
     384    {
     385      print_usage_and_exit( resamplingMethod != 0,          argv[0], "phases only supported in normative resampling" );
     386      print_usage_and_exit( phaseInitialized || argc < i+5, argv[0], "wrong number of phase parameters" );
     387      phaseInitialized = true;
     388      i++;
     389      cRP.m_iRefLayerChromaPhaseX = atoi( argv[i++] );
     390      cRP.m_iRefLayerChromaPhaseY = atoi( argv[i++] );
     391      cRP.m_iChromaPhaseX         = atoi( argv[i++] );
     392      cRP.m_iChromaPhaseY         = atoi( argv[i++] );
     393      print_usage_and_exit( cRP.m_iRefLayerChromaPhaseX > 0 || cRP.m_iRefLayerChromaPhaseX < -1, argv[0], "wrong phase x parameters (range : [-1, 0])");
     394      print_usage_and_exit( cRP.m_iRefLayerChromaPhaseY > 1 || cRP.m_iRefLayerChromaPhaseY < -1, argv[0], "wrong phase x parameters (range : [-1, 1])");
     395      print_usage_and_exit( cRP.m_iChromaPhaseX         > 0 || cRP.m_iChromaPhaseX         < -1, argv[0], "wrong phase x parameters (range : [-1, 0])");
     396      print_usage_and_exit( cRP.m_iChromaPhaseY         > 1 || cRP.m_iChromaPhaseY         < -1, argv[0], "wrong phase x parameters (range : [-1, 1])");
     397    }
     398    else if (i == 7)
     399    {
     400      methodInitialized = true;
     401      resamplingMethod  = atoi( argv[i++] );
     402      print_usage_and_exit( resamplingMethod < 0 || resamplingMethod > 4, argv[0], "unsupported method" );
     403      if( resamplingMethod > 2 )
     404      {
     405        print_usage_and_exit( cRP.m_iRefLayerFrmWidth  > cRP.m_iFrameWidth,  argv[0], "method 3 and 4 are not supported for downsampling" );
     406        print_usage_and_exit( cRP.m_iRefLayerFrmHeight > cRP.m_iFrameHeight, argv[0], "method 3 and 4 are not supported for downsampling" );
     407      }
     408      if( resamplingMethod != 2 )
     409      {
     410        resampling  = true;
     411        upsampling  = ( cRP.m_iRefLayerFrmWidth < cRP.m_iFrameWidth ) || ( cRP.m_iRefLayerFrmHeight < cRP.m_iFrameHeight );
     412      }
     413      if( resamplingMethod == 1 )
     414      {
     415        if( upsampling )
     416        {
     417          int      div  = cRP.m_iFrameWidth / cRP.m_iRefLayerFrmWidth;
     418          if     ( div == 1) numSpatialDyadicStages =  0;
     419          else if( div == 2) numSpatialDyadicStages =  1;
     420          else if( div == 4) numSpatialDyadicStages =  2;
     421          else if( div == 8) numSpatialDyadicStages =  3;
     422          else               numSpatialDyadicStages = -1;
     423          print_usage_and_exit( numSpatialDyadicStages < 0,                           argv[0], "ratio not supported for dyadic upsampling method" );
     424          print_usage_and_exit( div * cRP.m_iRefLayerFrmWidth  != cRP.m_iFrameWidth,  argv[0], "ratio is not dyadic in dyadic mode" );
     425          print_usage_and_exit( div * cRP.m_iRefLayerFrmHeight != cRP.m_iFrameHeight, argv[0], "different horizontal and vertical ratio in dyadic mode" );
     426        }
     427        else
     428        {
     429          int      div  = cRP.m_iRefLayerFrmWidth / cRP.m_iFrameWidth;
     430          if     ( div == 1) numSpatialDyadicStages =  0;
     431          else if( div == 2) numSpatialDyadicStages =  1;
     432          else if( div == 4) numSpatialDyadicStages =  2;
     433          else if( div == 8) numSpatialDyadicStages =  3;
     434          else               numSpatialDyadicStages = -1;
     435          print_usage_and_exit( numSpatialDyadicStages < 0,                           argv[0], "ratio not supported for dyadic downsampling method" );
     436          print_usage_and_exit( div * cRP.m_iFrameWidth  != cRP.m_iRefLayerFrmWidth,  argv[0], "ratio is not dyadic in dyadic mode" );
     437          print_usage_and_exit( div * cRP.m_iFrameHeight != cRP.m_iRefLayerFrmHeight, argv[0], "different horizontal and vertical ratio in dyadic mode" );
     438        }
     439      }
     440    }
     441    else if( i == 8 )
     442    {
     443      int TStages = atoi( argv[i++] );
     444      skipBetween = ( 1 << TStages ) - 1;
     445      print_usage_and_exit( TStages < 0,              argv[0], "negative number of temporal stages" );
     446    }
     447    else if( i == 9 )
     448    {
     449      skipAtStart = atoi( argv[i++] );
     450      print_usage_and_exit( skipAtStart < 0,          argv[0], "negative number of skipped frames at start" );
     451    }
     452    else if( i == 10 )
     453    {
     454      maxNumOutputFrames = atoi( argv[i++] );
     455      print_usage_and_exit( maxNumOutputFrames < 0 ,  argv[0], "negative number of output frames" );
     456    }
     457    else
     458    {
     459      print_usage_and_exit( true, argv[0], "error in command line parameters" );
     460    }
     461  }
     462  if( ! methodInitialized )
     463  {
     464    resampling  = true;
     465    upsampling  = ( cRP.m_iRefLayerFrmWidth < cRP.m_iFrameWidth ) || ( cRP.m_iRefLayerFrmHeight < cRP.m_iFrameHeight );
     466  }
     467  if( ! croppingInitialized )
     468  {
     469    if( resamplingMethod == 2 )
     470    {
     471      cRP.m_iScaledRefFrmWidth  = gMin( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
     472      cRP.m_iScaledRefFrmHeight = gMin( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
     473    }
     474    else
     475    {
     476      cRP.m_iScaledRefFrmWidth  = gMax( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
     477      cRP.m_iScaledRefFrmHeight = gMax( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
     478    }
     479  }
     480
     481  //===== set basic parameters for resampling control =====
     482  if( resamplingMethod == 0 )
     483  {
     484    if( resamplingMode == 1 )
     485    {
     486      cRP.m_bRefLayerFrameMbsOnlyFlag = false;
     487      cRP.m_bFrameMbsOnlyFlag         = false;
     488    }
     489    else if( resamplingMode == 2 || resamplingMode == 3 )
     490    {
     491      cRP.m_bFrameMbsOnlyFlag     = false;
     492      if( ! upsampling )
     493      {
     494        cRP.m_bFieldPicFlag       = true;
     495        cRP.m_bBotFieldFlag       = ( resamplingMode == 3 );
     496      }
     497    }
     498    else if( resamplingMode == 4 || resamplingMode == 5 )
     499    {
     500      cRP.m_bRefLayerFrameMbsOnlyFlag = false;
     501      cRP.m_bRefLayerFieldPicFlag     = true;
     502    }
     503  }
     504
     505  //===== initialize classes =====
     506  YuvFrame    cFrame;
     507  DownConvert cDownConvert;
     508  {
     509    int maxWidth  = gMax( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
     510    int maxHeight = gMax( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
     511    int minWidth  = gMin( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  );
     512    int minHeight = gMin( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight );
     513    int minWRnd16 = ( ( minWidth  + 15 ) >> 4 ) << 4;
     514    int minHRnd32 = ( ( minHeight + 31 ) >> 5 ) << 5;
     515    maxWidth      = ( ( maxWidth  * minWRnd16 + ( minWidth  << 4 ) - 1 ) / ( minWidth  << 4 ) ) << 4;
     516    maxHeight     = ( ( maxHeight * minHRnd32 + ( minHeight << 4 ) - 1 ) / ( minHeight << 4 ) ) << 4;
     517    createFrame( cFrame, maxWidth, maxHeight );
     518    cDownConvert.init(   maxWidth, maxHeight );
     519  }
     520
     521  printf("Resampler\n\n");
     522
     523  //===== loop over frames =====
     524  int   skip              = skipAtStart;
     525  int   writtenFrames     = 0;
     526  int   numInputFrames    = ( resamplingMode >= 4 && ! upsampling ? 2 : 1 );
     527  int   numOutputFrames   = ( resamplingMode >= 4 &&   upsampling ? 2 : 1 );
     528  bool  bFinished         = false;
     529  long  startTime         = clock();
     530  while( ! bFinished )
     531  {
     532    for( int inputFrame = 0; inputFrame < numInputFrames && ! bFinished; inputFrame++ )
     533    {
     534      //===== read input frame =====
     535      for( int numToRead = skip + 1; numToRead > 0 && ! bFinished; numToRead-- )
     536      {
     537        bFinished = ( readFrame( cFrame, inputFile, cRP.m_iRefLayerFrmWidth, cRP.m_iRefLayerFrmHeight, inputFrame != 0 ) != 0 );
     538      }
     539      skip = skipBetween;
     540      if( cRP.m_iExtendedSpatialScalability == 2 && ! bFinished )
     541      {
     542        updateCropParametersFromFile( cRP, croppingParametersFile, resamplingMethod, argv[0] );
     543      }
     544
     545      //===== set resampling parameter =====
     546      if( resamplingMethod != 0 &&
     547        cRP.m_iScaledRefFrmWidth  == gMin( cRP.m_iRefLayerFrmWidth,  cRP.m_iFrameWidth  ) &&
     548        cRP.m_iScaledRefFrmHeight == gMin( cRP.m_iRefLayerFrmHeight, cRP.m_iFrameHeight )   )
     549      {
     550        resampling = false;
     551      }
     552      else
     553      {
     554        resampling = true;
     555      }
     556
     557      //===== resample input frame =====
     558      if( ! bFinished )
     559      {
     560        resampleFrame( cFrame, cDownConvert, cRP, resamplingMethod, resamplingMode, resampling, upsampling, inputFrame != 0 );
     561      }
     562    }
     563
     564    //===== write output frame =====
     565    if( ! bFinished )
     566    {
     567      Bool bWriteTwoFrames = ( numOutputFrames == 2 && ( maxNumOutputFrames == 0 || writtenFrames + 1 < maxNumOutputFrames ) );
     568      writeFrame( cFrame, outputFile, cRP.m_iFrameWidth, cRP.m_iFrameHeight, bWriteTwoFrames );
     569      writtenFrames += ( bWriteTwoFrames ? 2 : 1 );
     570      bFinished      = ( maxNumOutputFrames != 0 && writtenFrames == maxNumOutputFrames );
     571      fprintf( stderr, "\r%6d frames converted", writtenFrames );
     572    }
     573  }
     574  long  endTime           = clock();
     575
     576  deleteFrame( cFrame );
     577  fclose     ( inputFile );
     578  fclose     ( outputFile );
     579  if( croppingParametersFile )
     580  {
     581    fclose   ( croppingParametersFile );
     582  }
     583
     584  fprintf( stderr, "\n" );
     585  double deltaInSecond = (double)( endTime - startTime) / (double)CLOCKS_PER_SEC;
     586  fprintf( stderr, "in %.2lf seconds => %.0lf ms/frame\n", deltaInSecond, deltaInSecond / (double)writtenFrames * 1000.0 );
     587  if( writtenFrames < maxNumOutputFrames )
     588  {
     589    fprintf( stderr, "\nNOTE: less output frames generated than specified!!!\n\n" );
     590  }
    468591  return 0;
    469592}
    470 
    471 //! \}
  • trunk/source/App/TAppEncoder/TAppEncCfg.cpp

    r494 r540  
    399399  string* cfg_predLayerIdsPtr    [MAX_LAYERS];
    400400#endif
     401#if O0098_SCALED_REF_LAYER_ID
     402  string    cfg_scaledRefLayerId [MAX_LAYERS];
     403#endif
    401404  string    cfg_scaledRefLayerLeftOffset [MAX_LAYERS];
    402405  string    cfg_scaledRefLayerTopOffset [MAX_LAYERS];
     
    405408  Int*      cfg_numScaledRefLayerOffsets[MAX_LAYERS];
    406409
     410#if O0098_SCALED_REF_LAYER_ID
     411  string*    cfg_scaledRefLayerIdPtr           [MAX_LAYERS];
     412#endif
    407413  string*    cfg_scaledRefLayerLeftOffsetPtr   [MAX_LAYERS];
    408414  string*    cfg_scaledRefLayerTopOffsetPtr    [MAX_LAYERS];
     
    471477    for(Int i = 0; i < MAX_LAYERS; i++)
    472478    {
     479#if O0098_SCALED_REF_LAYER_ID
     480      cfg_scaledRefLayerIdPtr          [layer] = &cfg_scaledRefLayerId[layer]          ;
     481#endif
    473482      cfg_scaledRefLayerLeftOffsetPtr  [layer] = &cfg_scaledRefLayerLeftOffset[layer]  ;
    474483      cfg_scaledRefLayerTopOffsetPtr   [layer] = &cfg_scaledRefLayerTopOffset[layer]   ;
     
    582591#endif
    583592  ("NumScaledRefLayerOffsets%d",    cfg_numScaledRefLayerOffsets,     0, MAX_LAYERS,  "Number of scaled offset layer sets ")
     593#if O0098_SCALED_REF_LAYER_ID
     594  ("ScaledRefLayerId%d",           cfg_scaledRefLayerIdPtr,          string(""), MAX_LAYERS, "Layer ID of scaled base layer picture")
     595#endif
    584596  ("ScaledRefLayerLeftOffset%d",   cfg_scaledRefLayerLeftOffsetPtr,  string(""), MAX_LAYERS, "Horizontal offset of top-left luma sample of scaled base layer picture with respect to"
    585597                                                                 " top-left luma sample of the EL picture, in units of two luma samples")
     
    602614  ("MaxTidRefPresentFlag", m_maxTidRefPresentFlag, true, "max_tid_ref_present_flag (0: not present, 1: present(default)) " )
    603615  ("MaxTidIlRefPicsPlus1%d", cfg_maxTidIlRefPicsPlus1, 1, MAX_LAYERS, "allowed maximum temporal_id for inter-layer prediction")
    604 #endif
     616#endif
     617#if O0223_PICTURE_TYPES_ALIGN_FLAG
     618  ("CrossLayerPictureTypeAlignFlag", m_crossLayerPictureTypeAlignFlag, true, "align picture type across layers" ) 
     619#endif
     620#if N0147_IRAP_ALIGN_FLAG
     621    ("CrossLayerIrapAlignFlag", m_crossLayerIrapAlignFlag, true, "align IRAP across layers" ) 
     622#endif
    605623#if AVC_BASE
    606624  ("AvcBase,-avc",            m_avcBaseLayerFlag,     0, "avc_base_layer_flag")
     
    773791  ("MaxNumOffsetsPerPic",      m_maxNumOffsetsPerPic,       2048,  "Max number of SAO offset per picture (Default: 2048)")   
    774792  ("SAOLcuBoundary",           m_saoLcuBoundary,            false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
     793#if !HM_CLEANUP_SAO
    775794  ("SAOLcuBasedOptimization",  m_saoLcuBasedOptimization,   true,  "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")
     795#endif 
    776796  ("SliceMode",                m_sliceMode,                0,     "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes, 3:specify tiles per dependent slice")
    777797  ("SliceArgument",            m_sliceArgument,            0,     "Depending on SliceMode being:"
     
    827847  ("FIS", m_useFastIntraScalable, false, "Fast Intra Decision for Scalable HEVC")
    828848#endif
    829 #if RATE_CONTROL_LAMBDA_DOMAIN
    830849#if RC_SHVC_HARMONIZATION
    831850  ("RateControl%d", cfg_RCEnableRateControl, false, MAX_LAYERS, "Rate control: enable rate control for layer %d")
     
    839858  ( "RateControl",         m_RCEnableRateControl,   false, "Rate control: enable rate control" )
    840859  ( "TargetBitrate",       m_RCTargetBitrate,           0, "Rate control: target bitrate" )
    841 #if M0036_RC_IMPROVEMENT
    842860  ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit,     0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" )
    843 #else
    844   ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, false, "Rate control: keep hierarchical bit allocation in rate control algorithm" )
    845 #endif
    846861  ( "LCULevelRateControl", m_RCLCULevelRC,           true, "Rate control: true: LCU level RC; false: picture level RC" )
    847862  ( "RCLCUSeparateModel",  m_RCUseLCUSeparateModel,  true, "Rate control: use LCU level separate R-lambda model" )
    848863  ( "InitialQP",           m_RCInitialQP,               0, "Rate control: initial QP" )
    849864  ( "RCForceIntraQP",      m_RCForceIntraQP,        false, "Rate control: force intra QP to be equal to initial QP" )
    850 #endif
    851 #else
    852   ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")
    853   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
    854   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
    855865#endif
    856866
     
    954964  ("AdaptiveResolutionChange",     m_adaptiveResolutionChange, 0, "Adaptive resolution change frame number. Should coincide with EL RAP picture. (0: disable)")
    955965#endif
     966#if HIGHER_LAYER_IRAP_SKIP_FLAG
     967  ("SkipPictureAtArcSwitch",     m_skipPictureAtArcSwitch, false, "Code the higher layer picture in ARC up-switching as a skip picture. (0: disable)")
     968#endif
    956969#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    957970  ("SEIInterLayerConstrainedTileSets", m_interLayerConstrainedTileSetsSEIEnabled, false, "Control generation of inter layer constrained tile sets SEI message")
    958971  ("IlNumSetsInMessage",               m_ilNumSetsInMessage,                         0u, "Number of inter layer constrained tile sets")
    959972  ("TileSetsArray",                    cfg_tileSets,                         string(""), "Array containing tile sets params (TopLeftTileIndex, BottonRightTileIndex and ilcIdc for each set) ")
     973#endif
     974#if O0153_ALT_OUTPUT_LAYER_FLAG
     975  ("AltOutputLayerFlag",               m_altOutputLayerFlag,                      false, "Specifies the value of alt_output_layer_flag in VPS extension")
     976#endif
     977#if O0149_CROSS_LAYER_BLA_FLAG
     978  ("CrossLayerBLAFlag",                m_crossLayerBLAFlag,                       false, "Specifies the value of cross_layer_bla_flag in VPS")
    960979#endif
    961980  ;
     
    10861105    if(m_acLayerCfg[layer].m_numScaledRefLayerOffsets)
    10871106    {
     1107#if O0098_SCALED_REF_LAYER_ID
     1108      assert( strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""));
     1109#endif
    10881110      assert( strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  "") ||
    10891111              strcmp(cfg_scaledRefLayerRightOffset[layer].c_str(), "") ||
     
    10941116
    10951117    Int *tempArray = NULL;   // Contain the value
     1118
     1119#if O0098_SCALED_REF_LAYER_ID
     1120    // ID //
     1121    if(strcmp(cfg_scaledRefLayerId[layer].c_str(),  ""))
     1122    {
     1123      cfgStringToArray( &tempArray, cfg_scaledRefLayerId[layer], m_acLayerCfg[layer].m_numScaledRefLayerOffsets, "ScaledRefLayerId");
     1124      if(tempArray)
     1125      {
     1126        for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
     1127        {
     1128          m_acLayerCfg[layer].m_scaledRefLayerId[i] = tempArray[i];
     1129        }
     1130        delete [] tempArray; tempArray = NULL;
     1131      }
     1132    }
     1133#endif
     1134
    10961135    // Left offset //
    10971136    if(strcmp(cfg_scaledRefLayerLeftOffset[layer].c_str(),  ""))
     
    21532192  }
    21542193
    2155 #if RATE_CONTROL_LAMBDA_DOMAIN
    21562194#if RC_SHVC_HARMONIZATION
    21572195  for ( Int layer=0; layer<m_numLayers; layer++ )
     
    21842222  }
    21852223#endif
    2186 #else
    2187   if(m_enableRateCtrl)
    2188   {
    2189     Int numLCUInWidth  = (m_iSourceWidth  / m_uiMaxCUWidth) + (( m_iSourceWidth  %  m_uiMaxCUWidth ) ? 1 : 0);
    2190     Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight %  m_uiMaxCUHeight) ? 1 : 0);
    2191     Int numLCUInPic    =  numLCUInWidth * numLCUInHeight;
    2192 
    2193     xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
    2194 
    2195     m_iMaxDeltaQP       = MAX_DELTA_QP;
    2196     m_iMaxCuDQPDepth    = MAX_CUDQP_DEPTH;
    2197   }
    2198 #endif
    21992224
    22002225  xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
     
    22842309    xConfirmPara(m_numLayers != 2, "Adaptive resolution change works with 2 layers only");
    22852310    xConfirmPara(m_acLayerCfg[1].m_iIntraPeriod == 0 || (m_adaptiveResolutionChange % m_acLayerCfg[1].m_iIntraPeriod) != 0, "Adaptive resolution change must happen at enhancement layer RAP picture");
     2311  }
     2312#endif
     2313#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2314  if (m_adaptiveResolutionChange > 0)
     2315  {
     2316    xConfirmPara(m_crossLayerIrapAlignFlag != 0, "Cross layer IRAP alignment must be disabled when using adaptive resolution change.");
     2317  }
     2318  if (m_skipPictureAtArcSwitch)
     2319  {
     2320    xConfirmPara(m_adaptiveResolutionChange <= 0, "Skip picture at ARC switching only works when Adaptive Resolution Change is active (AdaptiveResolutionChange > 0)");
    22862321  }
    22872322#endif
     
    23792414  printf("Multiview                     : %d\n", m_scalabilityMask[1] );
    23802415  printf("Scalable                      : %d\n", m_scalabilityMask[2] );
     2416#if AVC_BASE
     2417  printf("Base layer                    : %s\n", m_avcBaseLayerFlag ? "AVC" : "HEVC");
     2418#endif
    23812419#if AUXILIARY_PICTURES
    23822420  printf("Auxiliary pictures            : %d\n", m_scalabilityMask[3] );
     
    23882426#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    23892427  printf("Adaptive Resolution Change    : %d\n", m_adaptiveResolutionChange );
     2428#endif
     2429#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2430  printf("Skip picture at ARC switch    : %d\n", m_skipPictureAtArcSwitch );
     2431#endif
     2432#if O0223_PICTURE_TYPES_ALIGN_FLAG
     2433  printf("Align picture type            : %d\n", m_crossLayerPictureTypeAlignFlag );
     2434#endif
     2435#if N0147_IRAP_ALIGN_FLAG
     2436  printf("Cross layer IRAP alignment    : %d\n", m_crossLayerIrapAlignFlag );
    23902437#endif
    23912438  for(UInt layer=0; layer<m_numLayers; layer++)
     
    24532500#endif
    24542501#if O0215_PHASE_ALIGNMENT
    2455   printf("cross-layer sample alignment : %d\n", m_phaseAlignFlag);
    2456 #endif
    2457 #if RATE_CONTROL_LAMBDA_DOMAIN
     2502  printf("Cross-layer sample alignment : %d\n", m_phaseAlignFlag);
     2503#endif
    24582504#if !RC_SHVC_HARMONIZATION
    24592505  printf("RateControl                  : %d\n", m_RCEnableRateControl );
     
    24682514  }
    24692515#endif
    2470 #else
    2471   printf("RateControl                  : %d\n", m_enableRateCtrl);
    2472   if(m_enableRateCtrl)
    2473   {
    2474     printf("TargetBitrate                : %d\n", m_targetBitrate);
    2475     printf("NumLCUInUnit                 : %d\n", m_numLCUInUnit);
    2476   }
    2477 #endif
     2516
    24782517  printf("Max Num Merge Candidates     : %d\n", m_maxNumMergeCand);
    24792518  printf("\n");
     
    25162555  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
    25172556#endif
     2557#if !HM_CLEANUP_SAO
    25182558  printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
    2519 
     2559#endif
    25202560  printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
    25212561  printf("WPP:%d ", (Int)m_useWeightedPred);
     
    25352575#if SVC_EXTENSION
    25362576  printf("RecalQP:%d ", m_recalculateQPAccordingToLambda ? 1 : 0 );
    2537 #if AVC_BASE
    2538   printf("AvcBase:%d ", m_avcBaseLayerFlag ? 1 : 0);
    2539 #else
    2540   printf("AvcBase:%d ", 0);
    2541 #endif
    25422577  printf("EL_RAP_SliceType: %d ", m_elRapSliceBEnabled);
    25432578  printf("REF_IDX_ME_ZEROMV: %d ", REF_IDX_ME_ZEROMV);
  • trunk/source/App/TAppEncoder/TAppEncCfg.h

    r494 r540  
    187187  Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
    188188  Bool      m_saoLcuBoundary;                                 ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
     189#if !HM_CLEANUP_SAO
    189190  Bool      m_saoLcuBasedOptimization;                        ///< SAO LCU-based optimization
     191#endif
    190192  // coding tools (loop filter)
    191193  Bool      m_bLoopFilterDisable;                             ///< flag for using deblocking filter
     
    295297  Int       m_TMVPModeId;
    296298  Int       m_signHideFlag;
    297 #if RATE_CONTROL_LAMBDA_DOMAIN
    298299#if !RC_SHVC_HARMONIZATION
    299300  Bool      m_RCEnableRateControl;                ///< enable rate control or not
    300301  Int       m_RCTargetBitrate;                    ///< target bitrate when rate control is enabled
    301 #if M0036_RC_IMPROVEMENT
    302302  Int       m_RCKeepHierarchicalBit;              ///< 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
    303 #else
    304   Bool      m_RCKeepHierarchicalBit;              ///< whether keeping hierarchical bit allocation structure or not
    305 #endif
    306303  Bool      m_RCLCULevelRC;                       ///< true: LCU level rate control; false: picture level rate control
    307304  Bool      m_RCUseLCUSeparateModel;              ///< use separate R-lambda model at LCU level
    308305  Int       m_RCInitialQP;                        ///< inital QP for rate control
    309306  Bool      m_RCForceIntraQP;                     ///< force all intra picture to use initial QP or not
    310 #endif
    311 #else
    312   Bool      m_enableRateCtrl;                                   ///< Flag for using rate control algorithm
    313   Int       m_targetBitrate;                                 ///< target bitrate
    314   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit
    315307#endif
    316308  Int       m_useScalingListId;                               ///< using quantization matrix
     
    358350  Int       m_log2MaxMvLengthHorizontal;                      ///< Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units
    359351  Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
     352#if O0153_ALT_OUTPUT_LAYER_FLAG
     353  Bool      m_altOutputLayerFlag;                             ///< Specifies the value of alt_output_laye_flag in VPS extension
     354#endif
    360355
    361356#if SVC_EXTENSION
     
    373368#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    374369  Int       m_adaptiveResolutionChange;                       ///< Indicate adaptive resolution change frame
     370#endif
     371#if HIGHER_LAYER_IRAP_SKIP_FLAG
     372  Bool      m_skipPictureAtArcSwitch;                         ///< Indicates that when ARC up-switching is performed the higher layer picture is a skip picture
    375373#endif
    376374#if REPN_FORMAT_IN_VPS
     
    386384#endif
    387385#if O0215_PHASE_ALIGNMENT
    388   bool m_phaseAlignFlag;
     386  Bool m_phaseAlignFlag;
     387#endif
     388#if O0223_PICTURE_TYPES_ALIGN_FLAG
     389  Bool m_crossLayerPictureTypeAlignFlag;
     390#endif
     391#if N0147_IRAP_ALIGN_FLAG
     392  Bool m_crossLayerIrapAlignFlag;
     393#endif
     394#if O0149_CROSS_LAYER_BLA_FLAG
     395  bool      m_crossLayerBLAFlag;
    389396#endif
    390397public:
  • trunk/source/App/TAppEncoder/TAppEncLayerCfg.cpp

    r494 r540  
    5353  m_aiPad[1] = m_aiPad[0] = 0;
    5454  m_numScaledRefLayerOffsets = 0;
     55#if O0098_SCALED_REF_LAYER_ID
     56  ::memset(m_scaledRefLayerId,           0, sizeof(m_scaledRefLayerId));
     57#endif
    5558  ::memset(m_scaledRefLayerLeftOffset,   0, sizeof(m_scaledRefLayerLeftOffset));
    5659  ::memset(m_scaledRefLayerTopOffset,    0, sizeof(m_scaledRefLayerTopOffset));
  • trunk/source/App/TAppEncoder/TAppEncLayerCfg.h

    r494 r540  
    9595  TAppEncCfg* m_cAppEncCfg;                                   ///< pointer to app encoder config
    9696  Int       m_numScaledRefLayerOffsets  ;
     97#if O0098_SCALED_REF_LAYER_ID
     98  Int       m_scaledRefLayerId          [MAX_LAYERS];
     99#endif
    97100  Int       m_scaledRefLayerLeftOffset  [MAX_LAYERS];
    98101  Int       m_scaledRefLayerTopOffset   [MAX_LAYERS];
  • trunk/source/App/TAppEncoder/TAppEncTop.cpp

    r498 r540  
    9090    vps->setMaxDecPicBuffering             ( m_maxDecPicBuffering[i], i );
    9191  }
     92
    9293#if REPN_FORMAT_IN_VPS
    9394  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
     
    148149  {
    149150    RepFormat *repFormat = vps->getVpsRepFormat( idx );
     151#if REPN_FORMAT_CONTROL_FLAG
     152    repFormat->setChromaAndBitDepthVpsPresentFlag( true );
     153    if (idx==0)
     154    {
     155      assert(repFormat->getChromaAndBitDepthVpsPresentFlag() == true);
     156    }
     157#endif
    150158    repFormat->setPicWidthVpsInLumaSamples  ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceWidth()   );
    151159    repFormat->setPicHeightVpsInLumaSamples ( m_acLayerCfg[mapIdxToLayer[idx]].getSourceHeight()  );
     
    162170    repFormat->setBitDepthVpsLuma           ( getInternalBitDepthY()                        );  // Need modification to change for each layer
    163171    repFormat->setBitDepthVpsChroma         ( getInternalBitDepthC()                        );  // Need modification to change for each layer
     172#endif
     173#if HIGHER_LAYER_IRAP_SKIP_FLAG
     174    m_acTEncTop[mapIdxToLayer[idx]].setSkipPictureAtArcSwitch( m_skipPictureAtArcSwitch );
    164175#endif
    165176  }
     
    459470
    460471    m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary);
     472#if !HM_CLEANUP_SAO
    461473    m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
     474#endif
    462475    m_acTEncTop[layer].setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
    463476    m_acTEncTop[layer].setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     
    535548    m_acTEncTop[layer].setScalingListFile            ( m_scalingListFile   );
    536549    m_acTEncTop[layer].setSignHideFlag(m_signHideFlag);
    537 #if RATE_CONTROL_LAMBDA_DOMAIN
    538550#if RC_SHVC_HARMONIZATION
    539551    m_acTEncTop[layer].setUseRateCtrl     (m_acLayerCfg[layer].getRCEnableRateControl());
     
    552564    m_acTEncTop[layer].setInitialQP           ( m_RCInitialQP );
    553565    m_acTEncTop[layer].setForceIntraQP        ( m_RCForceIntraQP );
    554 #endif
    555 #else
    556     m_acTEncTop[layer].setUseRateCtrl     ( m_enableRateCtrl);
    557     m_acTEncTop[layer].setTargetBitrate   ( m_targetBitrate);
    558     m_acTEncTop[layer].setNumLCUInUnit    ( m_numLCUInUnit);
    559566#endif
    560567    m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
     
    598605      for(Int i = 0; i < m_acLayerCfg[layer].m_numScaledRefLayerOffsets; i++)
    599606      {
     607#if O0098_SCALED_REF_LAYER_ID
     608        m_acTEncTop[layer].setScaledRefLayerId(i, m_acLayerCfg[layer].m_scaledRefLayerId[i]);
     609#endif
    600610        m_acTEncTop[layer].getScaledRefLayerWindow(i).setWindow( 2*m_acLayerCfg[layer].m_scaledRefLayerLeftOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerRightOffset[i],
    601611                                                  2*m_acLayerCfg[layer].m_scaledRefLayerTopOffset[i], 2*m_acLayerCfg[layer].m_scaledRefLayerBottomOffset[i]);
     
    607617#if AUXILIARY_PICTURES
    608618    m_acTEncTop[layer].setChromaFormatIDC( m_acLayerCfg[layer].m_chromaFormatIDC );
     619#endif
     620#if O0153_ALT_OUTPUT_LAYER_FLAG
     621    m_acTEncTop[layer].setAltOuputLayerFlag( m_altOutputLayerFlag );
     622#endif
     623#if O0149_CROSS_LAYER_BLA_FLAG
     624    m_acTEncTop[layer].setCrossLayerBLAFlag( m_crossLayerBLAFlag );
    609625#endif
    610626  }
     
    768784
    769785  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
     786#if !HM_CLEANUP_SAO
    770787  m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
     788#endif
    771789  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
    772790  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     
    836854  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
    837855  m_cTEncTop.setSignHideFlag(m_signHideFlag);
    838 #if RATE_CONTROL_LAMBDA_DOMAIN
    839856  m_cTEncTop.setUseRateCtrl         ( m_RCEnableRateControl );
    840857  m_cTEncTop.setTargetBitrate       ( m_RCTargetBitrate );
     
    844861  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
    845862  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
    846 #else
    847   m_cTEncTop.setUseRateCtrl     ( m_enableRateCtrl);
    848   m_cTEncTop.setTargetBitrate   ( m_targetBitrate);
    849   m_cTEncTop.setNumLCUInUnit    ( m_numLCUInUnit);
    850 #endif
    851863  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
    852864  m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
     
    10871099#endif
    10881100#endif
     1101#if VPS_TSLAYERS
     1102    vps->setMaxTSLayersPresentFlag(true);
     1103    for( i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++ )
     1104    {
     1105        vps->setMaxTSLayersMinus1(i, vps->getMaxTLayers()-1);
     1106    }
     1107#endif
    10891108#if N0120_MAX_TID_REF_PRESENT_FLAG
    10901109#if N0120_MAX_TID_REF_CFG
     
    11711190  }
    11721191#endif
     1192 #if VPS_DPB_SIZE_TABLE
     1193  // The Layer ID List variables can be derived here. 
     1194#if DERIVE_LAYER_ID_LIST_VARIABLES
     1195  vps->deriveLayerIdListVariables();
     1196#endif
     1197  vps->deriveNumberOfSubDpbs();
     1198  // Initialize dpb_size_table() for all ouput layer sets in the VPS extension
     1199  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
     1200  {
     1201    Int layerSetId = vps->getOutputLayerSetIdx(i);
     1202
     1203    // For each output layer set, set the DPB size for each layer and the reorder/latency value the maximum for all layers
     1204    Bool checkFlagOuter = false;      // Used to calculate sub_layer_flag_info_present_flag
     1205    Bool checkFlagInner[MAX_TLAYER];  // Used to calculate sub_layer_dpb_info_present_flag
     1206
     1207    for(Int j = 0; j < vps->getMaxTLayers(); j++)
     1208    {
     1209
     1210      Int maxNumReorderPics = -1;
     1211      for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
     1212      {
     1213        Int layerId = vps->getLayerSetLayerIdList(layerSetId, k); // k-th layer in the output layer set
     1214        vps->setMaxVpsDecPicBufferingMinus1( i, k, j,  m_acTEncTop[layerId].getMaxDecPicBuffering(j) - 1 );
     1215        maxNumReorderPics       = std::max( maxNumReorderPics, m_acTEncTop[layerId].getNumReorderPics(j));
     1216      }
     1217      vps->setMaxVpsNumReorderPics(i, j, maxNumReorderPics);
     1218     
     1219      if( j == 0 )  // checkFlagInner[0] is always 1
     1220      {
     1221        checkFlagInner[j] = true;     // Always signal sub-layer DPB information for the first sub-layer
     1222      }
     1223      else
     1224      {
     1225        checkFlagInner[j] = false;    // Initialize to be false. If the values of the current sub-layers matches with the earlier sub-layer,
     1226                                      // then will be continue to be false - i.e. the j-th sub-layer DPB info is not signaled
     1227        checkFlagInner[j] |= ( maxNumReorderPics != vps->getMaxVpsNumReorderPics(i, j - 1) );
     1228        for(Int k = 0; k < vps->getNumSubDpbs(i) && !checkFlagInner[j]; k++)  // If checkFlagInner[j] is true, break and signal the values
     1229        {
     1230          checkFlagInner[j] |= ( vps->getMaxVpsDecPicBufferingMinus1(i, k, j - 1) != vps->getMaxVpsDecPicBufferingMinus1(i, k, j) );
     1231        }
     1232      }
     1233      // If checkFlagInner[j] = true, then some value needs to be signalled for the j-th sub-layer
     1234      vps->setSubLayerDpbInfoPresentFlag( i, j, checkFlagInner[j] );
     1235    }
     1236    for(Int j = 1; j < vps->getMaxTLayers(); j++) // Check if DPB info of any of non-zero sub-layers is signaled. If so set flag to one
     1237    {
     1238      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )
     1239      {
     1240        checkFlagOuter = true;
     1241        break;
     1242      }
     1243    }
     1244    vps->setSubLayerFlagInfoPresentFlag( i, checkFlagOuter );
     1245  }
     1246#endif
    11731247#if VPS_EXTN_DIRECT_REF_LAYERS
    11741248  // Direct reference layers
    11751249  UInt maxDirectRefLayers = 0;
     1250#if O0096_DEFAULT_DEPENDENCY_TYPE
     1251  Bool isDefaultDirectDependencyTypeSet = false;
     1252#endif
    11761253  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
    11771254  {
     
    12021279        vps->setDirectDependencyType( layerCtr, refLayerCtr, ((m_acTEncTop[layerCtr].getSamplePredEnabledFlag(refLayerCtr) ? 1 : 0) |
    12031280                                                              (m_acTEncTop[layerCtr].getMotionPredEnabledFlag(refLayerCtr) ? 2 : 0)) - 1);
     1281#if O0096_DEFAULT_DEPENDENCY_TYPE
     1282        if (!isDefaultDirectDependencyTypeSet)
     1283        {
     1284          vps->setDefaultDirectDependecyTypeFlag(1);
     1285          vps->setDefaultDirectDependecyType(vps->getDirectDependencyType(layerCtr, refLayerCtr));
     1286          isDefaultDirectDependencyTypeSet = true;
     1287        }
     1288        else if (vps->getDirectDependencyType(layerCtr, refLayerCtr) != vps->getDefaultDirectDependencyType())
     1289        {
     1290          vps->setDefaultDirectDependecyTypeFlag(0);
     1291        }
     1292#endif
    12041293      }
    12051294      else
     
    12101299#endif
    12111300  }
    1212 #if IL_SL_SIGNALLING_N0371
    1213   for(i = 1; i < vps->getMaxLayers(); i++)
    1214   {
    1215     for(Int j = 0; j < i; j++)
    1216     {
    1217       vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
     1301
     1302#if O0092_0094_DEPENDENCY_CONSTRAINT
     1303  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     1304  {
     1305    vps->setNumRefLayers(vps->getLayerIdInNuh(layerCtr));   // identify the number of direct and indirect reference layers of current layer and set recursiveRefLayersFlags
     1306  }
     1307  if(vps->getMaxLayers() > MAX_REF_LAYERS)
     1308  {
     1309    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
     1310    {
     1311      assert( vps->getNumRefLayers(vps->getLayerIdInNuh(layerCtr)) <= MAX_REF_LAYERS);
    12181312    }
    12191313  }
     
    12321326    }
    12331327#endif
     1328#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1329    vps->setCrossLayerPictureTypeAlignFlag( m_crossLayerPictureTypeAlignFlag );
     1330#endif
    12341331#if N0147_IRAP_ALIGN_FLAG
    1235     vps->setCrossLayerIrapAlignFlag(true);
     1332    vps->setCrossLayerIrapAlignFlag( m_crossLayerIrapAlignFlag );
    12361333    for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
    12371334    {
     
    12561353#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    12571354  vps->setSingleLayerForNonIrapFlag(m_adaptiveResolutionChange > 0 ? true : false);
     1355#endif
     1356#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1357  vps->setHigherLayerIrapSkipFlag(m_skipPictureAtArcSwitch);
    12581358#endif
    12591359#if !VPS_EXTN_OFFSET_CALC
     
    12661366#if O0215_PHASE_ALIGNMENT
    12671367  vps->setPhaseAlignFlag( m_phaseAlignFlag );
     1368#endif
     1369
     1370#if O0153_ALT_OUTPUT_LAYER_FLAG
     1371  vps->setAltOuputLayerFlag( m_altOutputLayerFlag );
    12681372#endif
    12691373
     
    20222126    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    20232127    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    2024     case NAL_UNIT_CODED_SLICE_TLA_R:
     2128    case NAL_UNIT_CODED_SLICE_TSA_R:
    20252129    case NAL_UNIT_CODED_SLICE_TSA_N:
    20262130    case NAL_UNIT_CODED_SLICE_STSA_R:
Note: See TracChangeset for help on using the changeset viewer.