Ticket #1643: fix.patch

File fix.patch, 7.2 KB (added by zhijiehuang, 2 months ago)
  • source/Lib/Utilities/VideoIOYuv.cpp

    diff --git a/source/Lib/Utilities/VideoIOYuv.cpp b/source/Lib/Utilities/VideoIOYuv.cpp
    index c1421d794..cd29e6fce 100644
    a b bool VideoIOYuv::write(uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf 
    12371237  return retval;
    12381238}
    12391239
     1240bool VideoIOYuv::write(uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf &pic,
     1241                       const InputColourSpaceConversion ipCSC, const bool packedYuvOutputMode, int SPSconfLeft,
     1242                       int SPSconfRight, int SPSconfTop, int SPSconfBottom, int PPSconfLeft,
     1243                       int PPSconfRight, int PPSconfTop, int PPSconfBottom, ChromaFormat format, const bool clipToRec709,
     1244                       const bool subtractConfWindowOffsets)
     1245{
     1246  PelStorage interm;
     1247
     1248  if (ipCSC!=IPCOLOURSPACE_UNCHANGED)
     1249  {
     1250    interm.create( pic.chromaFormat, Area( Position(), pic.Y()) );
     1251    colourSpaceConvert(pic, interm, ipCSC, false);
     1252  }
     1253
     1254  const CPelUnitBuf& picC = (ipCSC==IPCOLOURSPACE_UNCHANGED) ? pic : interm;
     1255
     1256  // compute actual YUV frame size excluding padding size
     1257  bool is16bit = false;
     1258  for (const auto bd: m_fileBitdepth)
     1259  {
     1260    if (bd > 8)
     1261    {
     1262      is16bit=true;
     1263    }
     1264  }
     1265
     1266  bool nonZeroBitDepthShift = false;
     1267  for (const auto bdShift: m_bitdepthShift)
     1268  {
     1269    if (bdShift != 0)
     1270    {
     1271      nonZeroBitDepthShift=true;
     1272    }
     1273  }
     1274
     1275  bool retval = true;
     1276  if (format == ChromaFormat::UNDEFINED)
     1277  {
     1278    format= picC.chromaFormat;
     1279  }
     1280
     1281  PelStorage picZ;
     1282  if (nonZeroBitDepthShift)
     1283  {
     1284    picZ.create( picC.chromaFormat, Area( Position(), picC.Y() ) );
     1285    picZ.copyFrom( picC );
     1286
     1287    for(uint32_t comp=0; comp < ::getNumberValidComponents( picZ.chromaFormat ); comp++)
     1288    {
     1289      const ComponentID compID=ComponentID(comp);
     1290      const ChannelType ch=toChannelType(compID);
     1291      const bool        rec709Compliance =
     1292        clipToRec709
     1293        && (-m_bitdepthShift[ch] < 0
     1294            && m_msbExtendedBitDepth[ch] >= 8); /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     1295      const Pel minval = rec709Compliance ? ((1 << (m_msbExtendedBitDepth[ch] - 8))) : 0;
     1296      const Pel maxval =
     1297        rec709Compliance ? ((0xff << (m_msbExtendedBitDepth[ch] - 8)) - 1) : (1 << m_msbExtendedBitDepth[ch]) - 1;
     1298
     1299      scalePlane(picZ.get(compID), -m_bitdepthShift[ch], minval, maxval);
     1300    }
     1301  }
     1302
     1303  const CPelUnitBuf& picO = nonZeroBitDepthShift ? picZ : picC;
     1304
     1305  const CPelBuf areaY     = picO.get(COMPONENT_Y);
     1306  const uint32_t    width444  = areaY.width - PPSconfLeft - PPSconfRight;
     1307  const uint32_t    height444 = areaY.height -  PPSconfTop  - PPSconfBottom;
     1308
     1309  if( subtractConfWindowOffsets )
     1310  {
     1311    orgWidth -= SPSconfLeft + SPSconfRight;
     1312    orgHeight -= SPSconfTop + SPSconfBottom;
     1313  }
     1314
     1315  if ((width444 == 0) || (height444 == 0))
     1316  {
     1317    msg( WARNING, "\nWarning: writing %d x %d luma sample output picture!", width444, height444);
     1318  }
     1319
     1320  if (m_outY4m)
     1321  {
     1322    m_fileStream.write(Y4M::FRAME_HEADER, Y4M::FRAME_HEADER_LENGTH);
     1323  }
     1324
     1325  for(uint32_t comp=0; retval && comp < ::getNumberValidComponents(format); comp++)
     1326  {
     1327    const ComponentID compID      = ComponentID(comp);
     1328    const ChannelType ch          = toChannelType(compID);
     1329    const uint32_t    csx         = ::getComponentScaleX(compID, format);
     1330    const uint32_t    csy         = ::getComponentScaleY(compID, format);
     1331    const CPelBuf     area        = picO.get(compID);
     1332    const ptrdiff_t   planeOffset = (PPSconfLeft >> csx) + (PPSconfTop >> csy) * area.stride;
     1333    if (!writePlane(orgWidth, orgHeight, m_fileStream, area.bufAt(0, 0) + planeOffset, is16bit, area.stride, width444,
     1334                    height444, compID, picO.chromaFormat, format, m_fileBitdepth[ch], packedYuvOutputMode ? 1 : 0))
     1335    {
     1336      retval = false;
     1337    }
     1338  }
     1339
     1340  return retval;
     1341}
     1342
    12401343bool VideoIOYuv::write(const CPelUnitBuf &picTop, const CPelUnitBuf &picBottom, const InputColourSpaceConversion ipCSC,
    12411344                       const bool packedYuvOutputMode, int confLeft, int confRight, int confTop, int confBottom,
    12421345                       ChromaFormat format, const bool isTff, const bool clipToRec709)
    bool VideoIOYuv::writeUpscaledPicture(const SPS &sps, const PPS &pps, const CPel 
    14661569    else
    14671570    {
    14681571      const Window &conf = pps.getConformanceWindow();
    1469 
     1572      const Window &spsconf = sps.getConformanceWindow();
    14701573      ret = write(sps.getMaxPicWidthInLumaSamples(), sps.getMaxPicHeightInLumaSamples(), pic, ipCSC,
    1471                   packedYuvOutputMode, conf.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIdc),
     1574                  packedYuvOutputMode, spsconf.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIdc),
     1575                  spsconf.getWindowRightOffset() * SPS::getWinUnitX(chromaFormatIdc),
     1576                  spsconf.getWindowTopOffset() * SPS::getWinUnitY(chromaFormatIdc),
     1577                  spsconf.getWindowBottomOffset() * SPS::getWinUnitY(chromaFormatIdc), conf.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIdc),
    14721578                  conf.getWindowRightOffset() * SPS::getWinUnitX(chromaFormatIdc),
    14731579                  conf.getWindowTopOffset() * SPS::getWinUnitY(chromaFormatIdc),
    14741580                  conf.getWindowBottomOffset() * SPS::getWinUnitY(chromaFormatIdc), ChromaFormat::UNDEFINED,
    1475                   clipToRec709, false);
     1581                  clipToRec709, true);
    14761582    }
    14771583  }
    14781584  else
  • source/Lib/Utilities/VideoIOYuv.h

    diff --git a/source/Lib/Utilities/VideoIOYuv.h b/source/Lib/Utilities/VideoIOYuv.h
    index d3d8ab255..37b0b4649 100644
    a b public: 
    9595  bool read(PelUnitBuf& pic, PelUnitBuf& picOrg, const InputColourSpaceConversion ipcsc, int pad[2],
    9696            ChromaFormat fileFormat   = ChromaFormat::UNDEFINED,
    9797            const bool   clipToRec709 = false);   ///< read one frame with padding parameter
    98 
    9998  // If fileFormat=NUM_CHROMA_FORMAT, use the format defined by pPicYuv
    10099  bool write(uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf& pic, const InputColourSpaceConversion ipCSC,
    101100             const bool packedYuvOutputMode, int confLeft = 0, int confRight = 0, int confTop = 0, int confBottom = 0,
    102101             ChromaFormat format = ChromaFormat::UNDEFINED, const bool clipToRec709 = false,
    103102             const bool subtractConfWindowOffsets = true);   ///< write one YUV frame with padding parameter
    104103
     104  bool write(uint32_t orgWidth, uint32_t orgHeight, const CPelUnitBuf &pic,
     105                       const InputColourSpaceConversion ipCSC, const bool packedYuvOutputMode, int SPSconfLeft,
     106                       int SPSconfRight, int SPSconfTop, int SPSconfBottom, int PPSconfLeft,
     107                       int PPSconfRight, int PPSconfTop, int PPSconfBottom, ChromaFormat format, const bool clipToRec709,
     108                       const bool subtractConfWindowOffsets); ///< write one YUV frame with padding parameter
    105109  // If fileFormat=NUM_CHROMA_FORMAT, use the format defined by pPicYuvTop and pPicYuvBottom
    106110  bool write(const CPelUnitBuf& picTop, const CPelUnitBuf& picBot, const InputColourSpaceConversion ipCSC,
    107111             const bool packedYuvOutputMode, int confLeft = 0, int confRight = 0, int confTop = 0, int confBottom = 0,