Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibVideoIO
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- Location:
- trunk/source/Lib/TLibVideoIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
r296 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 60 60 * @param maxval maximum clipping value 61 61 */ 62 static void invScalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,63 unsigned int shiftbits, Pel minval, Pel maxval)62 static void invScalePlane(Pel* img, UInt stride, UInt width, UInt height, 63 UInt shiftbits, Pel minval, Pel maxval) 64 64 { 65 65 Pel offset = 1 << (shiftbits-1); 66 for ( unsigned int y = 0; y < height; y++)67 { 68 for ( unsigned int x = 0; x < width; x++)66 for (UInt y = 0; y < height; y++) 67 { 68 for (UInt x = 0; x < width; x++) 69 69 { 70 70 Pel val = (img[x] + offset) >> shiftbits; … … 84 84 * @param shiftbits number of bits to shift 85 85 */ 86 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,87 unsigned int shiftbits)88 { 89 for ( unsigned int y = 0; y < height; y++)90 { 91 for ( unsigned int x = 0; x < width; x++)86 static void scalePlane(Pel* img, UInt stride, UInt width, UInt height, 87 UInt shiftbits) 88 { 89 for (UInt y = 0; y < height; y++) 90 { 91 for (UInt x = 0; x < width; x++) 92 92 { 93 93 img[x] <<= shiftbits; … … 112 112 * @param maxval maximum clipping value when dividing. 113 113 */ 114 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height,115 int shiftbits, Pel minval, Pel maxval)114 static void scalePlane(Pel* img, UInt stride, UInt width, UInt height, 115 Int shiftbits, Pel minval, Pel maxval) 116 116 { 117 117 if (shiftbits == 0) … … 147 147 * \param pchFile file name string 148 148 * \param bWriteMode file open mode: true=read, false=write 149 * \param fileBitDepth bit-depth of input/output file data. 150 * \param internalBitDepth bit-depth to scale image data to/from when reading/writing. 151 */ 152 Void TVideoIOYuv::open( char* pchFile, Bool bWriteMode, unsigned int fileBitDepth, unsigned int internalBitDepth ) 153 { 154 m_bitdepthShift = internalBitDepth - fileBitDepth; 155 m_fileBitdepth = fileBitDepth; 149 * \param fileBitDepthY bit-depth of input/output file data (luma component). 150 * \param fileBitDepthC bit-depth of input/output file data (chroma components). 151 * \param internalBitDepthY bit-depth to scale image data to/from when reading/writing (luma component). 152 * \param internalBitDepthC bit-depth to scale image data to/from when reading/writing (chroma components). 153 */ 154 Void TVideoIOYuv::open( Char* pchFile, Bool bWriteMode, Int fileBitDepthY, Int fileBitDepthC, Int internalBitDepthY, Int internalBitDepthC) 155 { 156 m_bitDepthShiftY = internalBitDepthY - fileBitDepthY; 157 m_bitDepthShiftC = internalBitDepthC - fileBitDepthC; 158 m_fileBitDepthY = fileBitDepthY; 159 m_fileBitDepthC = fileBitDepthC; 156 160 157 161 if ( bWriteMode ) … … 200 204 * seekable, by consuming bytes. 201 205 */ 202 void TVideoIOYuv::skipFrames( unsigned int numFrames, unsigned int width, unsigned int height)206 void TVideoIOYuv::skipFrames(UInt numFrames, UInt width, UInt height) 203 207 { 204 208 if (!numFrames) 205 209 return; 206 210 207 const unsigned int wordsize = m_fileBitdepth > 8? 2 : 1;211 const UInt wordsize = (m_fileBitDepthY > 8 || m_fileBitDepthC > 8) ? 2 : 1; 208 212 const streamoff framesize = wordsize * width * height * 3 / 2; 209 213 const streamoff offset = framesize * numFrames; … … 215 219 216 220 /* fall back to consuming the input */ 217 char buf[512];218 const unsignedoffset_mod_bufsize = offset % sizeof(buf);221 Char buf[512]; 222 const UInt offset_mod_bufsize = offset % sizeof(buf); 219 223 for (streamoff i = 0; i < offset - offset_mod_bufsize; i += sizeof(buf)) 220 224 { … … 239 243 * @return true for success, false in case of error 240 244 */ 241 static bool readPlane(Pel* dst, istream& fd, bool is16bit,242 unsigned int stride,243 unsigned int width, unsigned int height,244 unsigned int pad_x, unsigned int pad_y)245 { 246 int read_len = width * (is16bit ? 2 : 1);247 unsigned char *buf = new unsigned char[read_len];248 for ( int y = 0; y < height; y++)249 { 250 fd.read(reinterpret_cast< char*>(buf), read_len);245 static Bool readPlane(Pel* dst, istream& fd, Bool is16bit, 246 UInt stride, 247 UInt width, UInt height, 248 UInt pad_x, UInt pad_y) 249 { 250 Int read_len = width * (is16bit ? 2 : 1); 251 UChar *buf = new UChar[read_len]; 252 for (Int y = 0; y < height; y++) 253 { 254 fd.read(reinterpret_cast<Char*>(buf), read_len); 251 255 if (fd.eof() || fd.fail() ) 252 256 { … … 257 261 if (!is16bit) 258 262 { 259 for ( int x = 0; x < width; x++)263 for (Int x = 0; x < width; x++) 260 264 { 261 265 dst[x] = buf[x]; … … 264 268 else 265 269 { 266 for ( int x = 0; x < width; x++)270 for (Int x = 0; x < width; x++) 267 271 { 268 272 dst[x] = (buf[2*x+1] << 8) | buf[2*x]; … … 270 274 } 271 275 272 for ( int x = width; x < width + pad_x; x++)276 for (Int x = width; x < width + pad_x; x++) 273 277 { 274 278 dst[x] = dst[width - 1]; … … 276 280 dst += stride; 277 281 } 278 for ( int y = height; y < height + pad_y; y++)279 { 280 for ( int x = 0; x < width + pad_x; x++)282 for (Int y = height; y < height + pad_y; y++) 283 { 284 for (Int x = 0; x < width + pad_x; x++) 281 285 { 282 286 dst[x] = (dst - stride)[x]; … … 299 303 * @return true for success, false in case of error 300 304 */ 301 static bool writePlane(ostream& fd, Pel* src, bool is16bit,302 unsigned int stride,303 unsigned int width, unsigned int height)304 { 305 int write_len = width * (is16bit ? 2 : 1);306 unsigned char *buf = new unsigned char[write_len];307 for ( int y = 0; y < height; y++)305 static Bool writePlane(ostream& fd, Pel* src, Bool is16bit, 306 UInt stride, 307 UInt width, UInt height) 308 { 309 Int write_len = width * (is16bit ? 2 : 1); 310 UChar *buf = new UChar[write_len]; 311 for (Int y = 0; y < height; y++) 308 312 { 309 313 if (!is16bit) 310 314 { 311 for ( int x = 0; x < width; x++)315 for (Int x = 0; x < width; x++) 312 316 { 313 buf[x] = ( unsigned char) src[x];317 buf[x] = (UChar) src[x]; 314 318 } 315 319 } 316 320 else 317 321 { 318 for ( int x = 0; x < width; x++)322 for (Int x = 0; x < width; x++) 319 323 { 320 324 buf[2*x] = src[x] & 0xff; … … 323 327 } 324 328 325 fd.write(reinterpret_cast< char*>(buf), write_len);329 fd.write(reinterpret_cast<Char*>(buf), write_len); 326 330 if (fd.eof() || fd.fail() ) 327 331 { … … 348 352 * @return true for success, false in case of error 349 353 */ 350 bool TVideoIOYuv::read ( TComPicYuv* pPicYuv, Int aiPad[2], Bool bRewind)354 Bool TVideoIOYuv::read ( TComPicYuv* pPicYuv, Int aiPad[2] ) 351 355 { 352 356 // check end-of-file … … 356 360 357 361 // compute actual YUV width & height excluding padding size 358 unsigned int pad_h = aiPad[0]; 359 unsigned int pad_v = aiPad[1]; 360 unsigned int width_full = pPicYuv->getWidth(); 361 unsigned int height_full = pPicYuv->getHeight(); 362 unsigned int width = width_full - pad_h; 363 unsigned int height = height_full - pad_v; 364 bool is16bit = m_fileBitdepth > 8; 365 366 int desired_bitdepth = m_fileBitdepth + m_bitdepthShift; 367 Pel minval = 0; 368 Pel maxval = (1 << desired_bitdepth) - 1; 362 UInt pad_h = aiPad[0]; 363 UInt pad_v = aiPad[1]; 364 UInt width_full = pPicYuv->getWidth(); 365 UInt height_full = pPicYuv->getHeight(); 366 UInt width = width_full - pad_h; 367 UInt height = height_full - pad_v; 368 Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8; 369 370 Int desired_bitdepthY = m_fileBitDepthY + m_bitDepthShiftY; 371 Int desired_bitdepthC = m_fileBitDepthC + m_bitDepthShiftC; 372 Pel minvalY = 0; 373 Pel minvalC = 0; 374 Pel maxvalY = (1 << desired_bitdepthY) - 1; 375 Pel maxvalC = (1 << desired_bitdepthC) - 1; 369 376 #if CLIP_TO_709_RANGE 370 if (m_bitdepthShift < 0 && desired_bitdepth>= 8)377 if (m_bitdepthShiftY < 0 && desired_bitdepthY >= 8) 371 378 { 372 379 /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */ 373 minval = 1 << (desired_bitdepth - 8); 374 maxval = (0xff << (desired_bitdepth - 8)) -1; 380 minvalY = 1 << (desired_bitdepthY - 8); 381 maxvalY = (0xff << (desired_bitdepthY - 8)) -1; 382 } 383 if (m_bitdepthShiftC < 0 && desired_bitdepthC >= 8) 384 { 385 /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */ 386 minvalC = 1 << (desired_bitdepthC - 8); 387 maxvalC = (0xff << (desired_bitdepthC - 8)) -1; 375 388 } 376 389 #endif … … 378 391 if (! readPlane(pPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 379 392 return false; 380 scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bit depthShift, minval, maxval);393 scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitDepthShiftY, minvalY, maxvalY); 381 394 382 395 iStride >>= 1; … … 390 403 if (! readPlane(pPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 391 404 return false; 392 scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bit depthShift, minval, maxval);405 scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitDepthShiftC, minvalC, maxvalC); 393 406 394 407 if (! readPlane(pPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 395 408 return false; 396 scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 397 398 if( bRewind ) 399 { 400 Int iFrameSize = ( is16bit ? 2 : 1 ) * 6 * width * height; 401 m_cHandle.seekg( -iFrameSize, std::ios_base::cur ); 402 } 409 scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitDepthShiftC, minvalC, maxvalC); 403 410 404 411 return true; … … 413 420 * @return true for success, false in case of error 414 421 */ 415 Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int c ropLeft, Int cropRight, Int cropTop, Int cropBottom )422 Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int confLeft, Int confRight, Int confTop, Int confBottom ) 416 423 { 417 424 // compute actual YUV frame size excluding padding size 418 425 Int iStride = pPicYuv->getStride(); 419 UInt width = pPicYuv->getWidth() - c ropLeft - cropRight;420 UInt height = pPicYuv->getHeight() - c ropTop - cropBottom;421 bool is16bit = m_fileBitdepth> 8;426 UInt width = pPicYuv->getWidth() - confLeft - confRight; 427 UInt height = pPicYuv->getHeight() - confTop - confBottom; 428 Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8; 422 429 TComPicYuv *dstPicYuv = NULL; 423 bool retval = true;424 425 if (m_bit depthShift!= 0)430 Bool retval = true; 431 432 if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0) 426 433 { 427 434 dstPicYuv = new TComPicYuv; … … 429 436 pPicYuv->copyToPic(dstPicYuv); 430 437 431 Pel minval = 0; 432 Pel maxval = (1 << m_fileBitdepth) - 1; 438 Pel minvalY = 0; 439 Pel minvalC = 0; 440 Pel maxvalY = (1 << m_fileBitDepthY) - 1; 441 Pel maxvalC = (1 << m_fileBitDepthC) - 1; 433 442 #if CLIP_TO_709_RANGE 434 if (-m_bit depthShift < 0 && m_fileBitdepth>= 8)443 if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8) 435 444 { 436 445 /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */ 437 minval = 1 << (m_fileBitdepth - 8); 438 maxval = (0xff << (m_fileBitdepth - 8)) -1; 446 minvalY = 1 << (m_fileBitDepthY - 8); 447 maxvalY = (0xff << (m_fileBitDepthY - 8)) -1; 448 } 449 if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8) 450 { 451 /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */ 452 minvalC = 1 << (m_fileBitDepthC - 8); 453 maxvalC = (0xff << (m_fileBitDepthC - 8)) -1; 439 454 } 440 455 #endif 441 scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(), dstPicYuv->getHeight(), -m_bit depthShift, minval, maxval);442 scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bit depthShift, minval, maxval);443 scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bit depthShift, minval, maxval);456 scalePlane(dstPicYuv->getLumaAddr(), dstPicYuv->getStride(), dstPicYuv->getWidth(), dstPicYuv->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY); 457 scalePlane(dstPicYuv->getCbAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC); 458 scalePlane(dstPicYuv->getCrAddr(), dstPicYuv->getCStride(), dstPicYuv->getWidth()>>1, dstPicYuv->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC); 444 459 } 445 460 else … … 448 463 } 449 464 // location of upper left pel in a plane 450 Int planeOffset = 0; //cropLeft + cropTop * iStride;465 Int planeOffset = confLeft + confTop * iStride; 451 466 452 467 if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height)) … … 459 474 height >>= 1; 460 475 iStride >>= 1; 461 cropLeft >>= 1; 462 cropRight >>= 1; 463 464 planeOffset = 0; // cropLeft + cropTop * iStride; 476 confLeft >>= 1; 477 confRight >>= 1; 478 confTop >>= 1; 479 confBottom >>= 1; 480 481 planeOffset = confLeft + confTop * iStride; 465 482 466 483 if (! writePlane(m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height)) … … 476 493 477 494 exit: 478 if (m_bit depthShift!= 0)495 if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0) 479 496 { 480 497 dstPicYuv->destroy(); -
trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
r296 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 42 42 #include <fstream> 43 43 #include <iostream> 44 #include " ../TLibCommon/CommonDef.h"45 #include " ../TLibCommon/TComPicYuv.h"44 #include "TLibCommon/CommonDef.h" 45 #include "TLibCommon/TComPicYuv.h" 46 46 47 47 using namespace std; … … 56 56 private: 57 57 fstream m_cHandle; ///< file handle 58 unsigned int m_fileBitdepth; ///< bitdepth of input/output video file 59 int m_bitdepthShift; ///< number of bits to increase or decrease image by before/after write/read 58 Int m_fileBitDepthY; ///< bitdepth of input/output video file luma component 59 Int m_fileBitDepthC; ///< bitdepth of input/output video file chroma component 60 Int m_bitDepthShiftY; ///< number of bits to increase or decrease luma by before/after write/read 61 Int m_bitDepthShiftC; ///< number of bits to increase or decrease chroma by before/after write/read 60 62 61 63 public: … … 63 65 virtual ~TVideoIOYuv() {} 64 66 65 Void open ( char* pchFile, Bool bWriteMode, unsigned int fileBitDepth, unsigned int internalBitDepth); ///< open or create file67 Void open ( Char* pchFile, Bool bWriteMode, Int fileBitDepthY, Int fileBitDepthC, Int internalBitDepthY, Int internalBitDepthC ); ///< open or create file 66 68 Void close (); ///< close file 67 69 68 void skipFrames( unsigned int numFrames, unsigned int width, unsigned int height);70 void skipFrames(UInt numFrames, UInt width, UInt height); 69 71 70 bool read ( TComPicYuv* pPicYuv, Int aiPad[2], Bool bRewind = false); ///< read one YUV frame with padding parameter71 Bool write( TComPicYuv* pPicYuv, Int c ropLeft=0, Int cropRight=0, Int cropTop=0, Int cropBottom=0 );72 Bool read ( TComPicYuv* pPicYuv, Int aiPad[2] ); ///< read one YUV frame with padding parameter 73 Bool write( TComPicYuv* pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 ); 72 74 73 bool isEof (); ///< check for end-of-file74 bool isFail(); ///< check for failure75 Bool isEof (); ///< check for end-of-file 76 Bool isFail(); ///< check for failure 75 77 76 78 };
Note: See TracChangeset for help on using the changeset viewer.