74     for (
UInt y = 0; y < height; y++, img+=stride)
 
   76       for (
UInt x = 0; x < width; x++)
 
   82   else if (shiftbits < 0)
 
   86     Pel rounding = 1 << (shiftbits-1);
 
   87     for (
UInt y = 0; y < height; y++, img+=stride)
 
   89       for (
UInt x = 0; x < width; x++)
 
   91         img[x] = 
Clip3(minval, maxval, 
Pel((img[x] + rounding) >> shiftbits));
 
  125     m_fileBitdepth       [ch] = std::min<UInt>(fileBitDepth[ch], 16);
 
  126     m_MSBExtendedBitDepth[ch] = MSBExtendedBitDepth[ch];
 
  127     m_bitdepthShift      [ch] = internalBitDepth[ch] - m_MSBExtendedBitDepth[ch];
 
  129     if (m_fileBitdepth[ch] > 16)
 
  133         std::cerr << 
"\nWARNING: Cannot write a yuv file of bit depth greater than 16 - output will be right-shifted down to 16-bit precision\n" << std::endl;
 
  137         std::cerr << 
"\nERROR: Cannot read a yuv file of bit depth greater than 16\n" << std::endl;
 
  145     m_cHandle.open( fileName.c_str(), ios::binary | ios::out );
 
  147     if( m_cHandle.fail() )
 
  149       printf(
"\nfailed to write reconstructed YUV file\n");
 
  155     m_cHandle.open( fileName.c_str(), ios::binary | ios::in );
 
  157     if( m_cHandle.fail() )
 
  159       printf(
"\nfailed to open Input YUV file\n");
 
  174   return m_cHandle.eof();
 
  179   return m_cHandle.fail();
 
  197   streamoff frameSize = 0;
 
  208   frameSize *= wordsize;
 
  211   const streamoff offset = frameSize * numFrames;
 
  214   if (!!m_cHandle.seekg(offset, ios::cur))
 
  222   const streamoff offset_mod_bufsize = offset % 
sizeof(buf);
 
  223   for (streamoff i = 0; i < offset - offset_mod_bufsize; i += 
sizeof(buf))
 
  225     m_cHandle.read(buf, 
sizeof(buf));
 
  227   m_cHandle.read(buf, offset_mod_bufsize);
 
  260                       const UInt fileBitDepth)
 
  267   const UInt width_dest       = width444 >>csx_dest;
 
  268   const UInt height_dest      = height444>>csy_dest;
 
  269   const UInt pad_x_dest       = pad_x444>>csx_dest;
 
  270   const UInt pad_y_dest       = pad_y444>>csy_dest;
 
  271   const UInt stride_dest      = stride444>>csx_dest;
 
  273   const UInt full_width_dest  = width_dest+pad_x_dest;
 
  274   const UInt full_height_dest = height_dest+pad_y_dest;
 
  276   const UInt stride_file      = (width444 * (is16bit ? 2 : 1)) >> csx_file;
 
  277   std::vector<UChar> bufVec(stride_file);
 
  278   UChar *buf=&(bufVec[0]);
 
  285       const Pel value=
Pel(1<<(fileBitDepth-1));
 
  286       for (
UInt y = 0; y < full_height_dest; y++, dst+=stride_dest)
 
  288         for (
UInt x = 0; x < full_width_dest; x++)
 
  297       const UInt height_file      = height444>>csy_file;
 
  298       fd.seekg(height_file*stride_file, ios::cur);
 
  299       if (fd.eof() || fd.fail() )
 
  307     const UInt mask_y_file=(1<<csy_file)-1;
 
  308     const UInt mask_y_dest=(1<<csy_dest)-1;
 
  309     for(
UInt y444=0; y444<height444; y444++)
 
  311       if ((y444&mask_y_file)==0)
 
  314         fd.read(reinterpret_cast<TChar*>(buf), stride_file);
 
  315         if (fd.eof() || fd.fail() )
 
  321       if ((y444&mask_y_dest)==0)
 
  324         if (csx_file < csx_dest)
 
  327           const UInt sx=csx_dest-csx_file;
 
  330             for (
UInt x = 0; x < width_dest; x++)
 
  337             for (
UInt x = 0; x < width_dest; x++)
 
  339               dst[x] = 
Pel(buf[(x<<sx)*2+0]) | (
Pel(buf[(x<<sx)*2+1])<<8);
 
  346           const UInt sx=csx_file-csx_dest;
 
  349             for (
UInt x = 0; x < width_dest; x++)
 
  356             for (
UInt x = 0; x < width_dest; x++)
 
  358               dst[x] = 
Pel(buf[(x>>sx)*2+0]) | (
Pel(buf[(x>>sx)*2+1])<<8);
 
  364         const Pel val=dst[width_dest-1];
 
  365         for (
UInt x = width_dest; x < full_width_dest; x++)
 
  375     for (
UInt y = height_dest; y < full_height_dest; y++, dst+=stride_dest)
 
  377       for (
UInt x = 0; x < full_width_dest; x++)
 
  379         dst[x] = (dst - stride_dest)[x];
 
  407                        const UInt fileBitDepth)
 
  414   const UInt stride_src      = stride444>>csx_src;
 
  416   const UInt stride_file      = (width444 * (is16bit ? 2 : 1)) >> csx_file;
 
  417   const UInt width_file       = width444 >>csx_file;
 
  418   const UInt height_file      = height444>>csy_file;
 
  420   std::vector<UChar> bufVec(stride_file);
 
  421   UChar *buf=&(bufVec[0]);
 
  427       const UInt value=1<<(fileBitDepth-1);
 
  429       for(
UInt y=0; y< height_file; y++)
 
  434           for (
UInt x = 0; x < width_file; x++)
 
  442           for (
UInt x = 0; x < width_file; x++)
 
  444             buf[2*x+0]= (val>>0) & 0xff;
 
  445             buf[2*x+1]= (val>>8) & 0xff;
 
  449         fd.write(reinterpret_cast<const TChar*>(buf), stride_file);
 
  450         if (fd.eof() || fd.fail() )
 
  459     const UInt mask_y_file=(1<<csy_file)-1;
 
  460     const UInt mask_y_src =(1<<csy_src )-1;
 
  461     for(
UInt y444=0; y444<height444; y444++)
 
  463       if ((y444&mask_y_file)==0)
 
  466         if (csx_file < csx_src)
 
  469           const UInt sx=csx_src-csx_file;
 
  472             for (
UInt x = 0; x < width_file; x++)
 
  474               buf[x] = (
UChar)(src[x>>sx]);
 
  479             for (
UInt x = 0; x < width_file; x++)
 
  481               buf[2*x  ] = (src[x>>sx]>>0) & 0xff;
 
  482               buf[2*x+1] = (src[x>>sx]>>8) & 0xff;
 
  489           const UInt sx=csx_file-csx_src;
 
  492             for (
UInt x = 0; x < width_file; x++)
 
  494               buf[x] = (
UChar)(src[x<<sx]);
 
  499             for (
UInt x = 0; x < width_file; x++)
 
  501               buf[2*x  ] = (src[x<<sx]>>0) & 0xff;
 
  502               buf[2*x+1] = (src[x<<sx]>>8) & 0xff;
 
  507         fd.write(reinterpret_cast<const TChar*>(buf), stride_file);
 
  508         if (fd.eof() || fd.fail() )
 
  514       if ((y444&mask_y_src)==0)
 
  530                        const UInt fileBitDepth, 
const Bool isTff)
 
  537   const UInt stride_src      = stride444>>csx_src;
 
  539   const UInt stride_file      = (width444 * (is16bit ? 2 : 1)) >> csx_file;
 
  540   const UInt width_file       = width444 >>csx_file;
 
  541   const UInt height_file      = height444>>csy_file;
 
  543   std::vector<UChar> bufVec(stride_file * 2);
 
  544   UChar *buf=&(bufVec[0]);
 
  550       const UInt value=1<<(fileBitDepth-1);
 
  552       for(
UInt y=0; y< height_file; y++)
 
  554         for (
UInt field = 0; field < 2; field++)
 
  556           UChar *fieldBuffer = buf + (field * stride_file);
 
  561             for (
UInt x = 0; x < width_file; x++)
 
  569             for (
UInt x = 0; x < width_file; x++)
 
  571               fieldBuffer[2*x+0]= (val>>0) & 0xff;
 
  572               fieldBuffer[2*x+1]= (val>>8) & 0xff;
 
  577         fd.write(reinterpret_cast<const TChar*>(buf), (stride_file * 2));
 
  578         if (fd.eof() || fd.fail() )
 
  587     const UInt mask_y_file=(1<<csy_file)-1;
 
  588     const UInt mask_y_src =(1<<csy_src )-1;
 
  589     for(
UInt y444=0; y444<height444; y444++)
 
  591       if ((y444&mask_y_file)==0)
 
  593         for (
UInt field = 0; field < 2; field++)
 
  595           UChar *fieldBuffer = buf + (field * stride_file);
 
  596           Pel   *src         = (((field == 0) && isTff) || ((field == 1) && (!isTff))) ? top : bottom;
 
  599           if (csx_file < csx_src)
 
  602             const UInt sx=csx_src-csx_file;
 
  605               for (
UInt x = 0; x < width_file; x++)
 
  607                 fieldBuffer[x] = (
UChar)(src[x>>sx]);
 
  612               for (
UInt x = 0; x < width_file; x++)
 
  614                 fieldBuffer[2*x  ] = (src[x>>sx]>>0) & 0xff;
 
  615                 fieldBuffer[2*x+1] = (src[x>>sx]>>8) & 0xff;
 
  622             const UInt sx=csx_file-csx_src;
 
  625               for (
UInt x = 0; x < width_file; x++)
 
  627                 fieldBuffer[x] = (
UChar)(src[x<<sx]);
 
  632               for (
UInt x = 0; x < width_file; x++)
 
  634                 fieldBuffer[2*x  ] = (src[x<<sx]>>0) & 0xff;
 
  635                 fieldBuffer[2*x+1] = (src[x<<sx]>>8) & 0xff;
 
  641         fd.write(reinterpret_cast<const TChar*>(buf), (stride_file * 2));
 
  642         if (fd.eof() || fd.fail() )
 
  648       if ((y444&mask_y_src)==0)
 
  651         bottom += stride_src;
 
  688   Bool is16bit = 
false;
 
  692     if (m_fileBitdepth[ch] > 8)
 
  701   const UInt pad_h444       = aiPad[0];
 
  702   const UInt pad_v444       = aiPad[1];
 
  707   const UInt width444       = width_full444 - pad_h444;
 
  708   const UInt height444      = height_full444 - pad_v444;
 
  715     const Int desired_bitdepth = m_MSBExtendedBitDepth[chType] + m_bitdepthShift[chType];
 
  717     const Bool b709Compliance=(bClipToRec709) && (m_bitdepthShift[chType] < 0 && desired_bitdepth >= 8);     
 
  718     const Pel minval = b709Compliance? ((   1 << (desired_bitdepth - 8))   ) : 0;
 
  719     const Pel maxval = b709Compliance? ((0xff << (desired_bitdepth - 8)) -1) : (1 << desired_bitdepth) - 1;
 
  721     if (! 
readPlane(pPicYuv->
getAddr(compID), m_cHandle, is16bit, stride444, width444, height444, pad_h444, pad_v444, compID, pPicYuv->
getChromaFormat(), format, m_fileBitdepth[chType]))
 
  730       scalePlane(pPicYuv->
getAddr(compID), stride444>>csx, width_full444>>csx, height_full444>>csy, m_bitdepthShift[chType], minval, maxval);
 
  736     ColourSpaceConvert(*pPicYuvTrueOrg, *pPicYuvUser, ipcsc, 
true);
 
  761     ColourSpaceConvert(*pPicYuvUser, cPicYuvCSCd, ipCSC, 
false);
 
  766   Bool is16bit = 
false;
 
  767   Bool nonZeroBitDepthShift=
false;
 
  771     if (m_fileBitdepth[ch] > 8)
 
  775     if (m_bitdepthShift[ch] != 0)
 
  777       nonZeroBitDepthShift=
true;
 
  788   if (nonZeroBitDepthShift)
 
  797       const Bool b709Compliance = bClipToRec709 && (-m_bitdepthShift[ch] < 0 && m_MSBExtendedBitDepth[ch] >= 8);     
 
  798       const Pel minval = b709Compliance? ((   1 << (m_MSBExtendedBitDepth[ch] - 8))   ) : 0;
 
  799       const Pel maxval = b709Compliance? ((0xff << (m_MSBExtendedBitDepth[ch] - 8)) -1) : (1 << m_MSBExtendedBitDepth[ch]) - 1;
 
  801       copyPlane(*pPicYuv, compID, *dstPicYuv, compID);
 
  814   if ((width444 == 0) || (height444 == 0))
 
  816     printf (
"\nWarning: writing %d x %d luma sample output picture!", width444, height444);
 
  825     const Int planeOffset =  (confLeft>>csx) + (confTop>>csy) * dstPicYuv->
getStride(compID);
 
  826     if (! 
writePlane(m_cHandle, dstPicYuv->
getAddr(compID) + planeOffset, is16bit, stride444, width444, height444, compID, dstPicYuv->
getChromaFormat(), format, m_fileBitdepth[ch]))
 
  832   if (nonZeroBitDepthShift)
 
  852     ColourSpaceConvert(*pPicYuvUserTop,    cPicYuvTopCSCd,    ipCSC, 
false);
 
  853     ColourSpaceConvert(*pPicYuvUserBottom, cPicYuvBottomCSCd, ipCSC, 
false);
 
  858   Bool is16bit = 
false;
 
  859   Bool nonZeroBitDepthShift=
false;
 
  863     if (m_fileBitdepth[ch] > 8)
 
  867     if (m_bitdepthShift[ch] != 0)
 
  869       nonZeroBitDepthShift=
true;
 
  876   for (
UInt field = 0; field < 2; field++)
 
  878     TComPicYuv *pPicYuv = (field == 0) ? pPicYuvTop : pPicYuvBottom;
 
  885     TComPicYuv* &dstPicYuv = (field == 0) ? dstPicYuvTop : dstPicYuvBottom;
 
  887     if (nonZeroBitDepthShift)
 
  896         const Bool b709Compliance=bClipToRec709 && (-m_bitdepthShift[ch] < 0 && m_MSBExtendedBitDepth[ch] >= 8);     
 
  897         const Pel minval = b709Compliance? ((   1 << (m_MSBExtendedBitDepth[ch] - 8))   ) : 0;
 
  898         const Pel maxval = b709Compliance? ((0xff << (m_MSBExtendedBitDepth[ch] - 8)) -1) : (1 << m_MSBExtendedBitDepth[ch]) - 1;
 
  900         copyPlane(*pPicYuv, compID, *dstPicYuv, compID);
 
  920     assert(dstPicYuvTop->
getWidth          (compID) == dstPicYuvBottom->
getWidth          (compID));
 
  929     if ((width444 == 0) || (height444 == 0))
 
  931       printf (
"\nWarning: writing %d x %d luma sample output picture!", width444, height444);
 
  936     const Int planeOffset  = (confLeft>>csx) + ( confTop>>csy) * dstPicYuvTop->
getStride(compID); 
 
  939                      (dstPicYuvTop   ->getAddr(compID) + planeOffset),
 
  940                      (dstPicYuvBottom->
getAddr(compID) + planeOffset),
 
  943                      width444, height444, compID, dstPicYuvTop->
getChromaFormat(), format, m_fileBitdepth[ch], isTff))
 
  949   if (nonZeroBitDepthShift)
 
  954     delete dstPicYuvBottom;
 
  968   assert(dest.
getWidth(destPlane) == width);
 
  969   assert(dest.
getHeight(destPlane) == height);
 
  974   for(
UInt y=0; y<height; y++, pSrc+=strideSrc, pDest+=strideDest)
 
  976     memcpy(pDest, pSrc, width*
sizeof(
Pel));
 
  997         for(
UInt comp=0; comp<numValidComp; comp++)
 
 1005         for(
UInt comp=0; comp<numValidComp; comp++)
 
 1022         for(
UInt comp=0; comp<numValidComp; comp++)
 
 1026           copyPlane(src, bIsForwards?compIDsrc:compIDdst, dest, bIsForwards?compIDdst:compIDsrc);
 
 1034         for(
UInt comp=0; comp<numValidComp; comp++)
 
Bool write(TComPicYuv *pPicYuv, const InputColourSpaceConversion ipCSC, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0, ChromaFormat fileFormat=NUM_CHROMA_FORMAT, const Bool bClipToRec709=false)
write one YUV frame with padding parameter 
static Void copyPlane(const TComPicYuv &src, const ComponentID srcPlane, TComPicYuv &dest, const ComponentID destPlane)
Int getStride(const ComponentID id) const 
global variables & functions (header) 
static Void ColourSpaceConvert(const TComPicYuv &src, TComPicYuv &dest, const InputColourSpaceConversion conversion, Bool bIsForwards)
Void open(const std::string &fileName, Bool bWriteMode, const Int fileBitDepth[MAX_NUM_CHANNEL_TYPE], const Int MSBExtendedBitDepth[MAX_NUM_CHANNEL_TYPE], const Int internalBitDepth[MAX_NUM_CHANNEL_TYPE])
open or create file 
Void createWithoutCUInfo(const Int picWidth, const Int picHeight, const ChromaFormat chromaFormatIDC, const Bool bUseMargin=false, const UInt maxCUWidth=0, const UInt maxCUHeight=0)
used for margin only 
Int getHeight(const ComponentID id) const 
static Void scalePlane(Pel *img, const UInt stride, const UInt width, const UInt height, Int shiftbits, Pel minval, Pel maxval)
Bool isEof()
check for end-of-file 
YUV file I/O class (header) 
Int getWidth(const ComponentID id) const 
UInt getComponentScaleY(const ComponentID id) const 
UInt getComponentScaleX(const ComponentID id) const 
Bool isFail()
check for failure 
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip 
ChromaFormat
chroma formats (according to semantics of chroma_format_idc) 
static Bool writePlane(ostream &fd, Pel *src, Bool is16bit, UInt stride444, UInt width444, UInt height444, const ComponentID compID, const ChromaFormat srcFormat, const ChromaFormat fileFormat, const UInt fileBitDepth)
UInt getNumberValidComponents() const 
InputColourSpaceConversion
Bool read(TComPicYuv *pPicYuv, TComPicYuv *pPicYuvTrueOrg, const InputColourSpaceConversion ipcsc, Int aiPad[2], ChromaFormat fileFormat=NUM_CHROMA_FORMAT, const Bool bClipToRec709=false)
read one frame with padding parameter 
Pel * getAddr(const ComponentID ch)
static Bool writeField(ostream &fd, Pel *top, Pel *bottom, Bool is16bit, UInt stride444, UInt width444, UInt height444, const ComponentID compID, const ChromaFormat srcFormat, const ChromaFormat fileFormat, const UInt fileBitDepth, const Bool isTff)
static Bool readPlane(Pel *dst, istream &fd, Bool is16bit, UInt stride444, UInt width444, UInt height444, UInt pad_x444, UInt pad_y444, const ComponentID compID, const ChromaFormat destFormat, const ChromaFormat fileFormat, const UInt fileBitDepth)
Void skipFrames(Int numFrames, UInt width, UInt height, ChromaFormat format)
ChromaFormat getChromaFormat() const