Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibVideoIO
- Timestamp:
- 11 May 2012, 21:20:17 (13 years ago)
- Location:
- trunk/source/Lib/TLibVideoIO
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibVideoIO/TVideoIOYuv.cpp
r5 r56 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 5 * 6 * Copyright (c) 2010-201 1,ISO/IEC4 * granted under this license. 5 * 6 * Copyright (c) 2010-2012, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 15 15 * this list of conditions and the following disclaimer in the documentation 16 16 * and/or other materials provided with the distribution. 17 * * Neither the name of the I SO/IEC nor the names of its contributors may17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may 18 18 * be used to endorse or promote products derived from this software without 19 19 * specific prior written permission. … … 32 32 */ 33 33 34 35 36 34 /** \file TVideoIOYuv.cpp 37 35 \brief YUV file I/O class … … 45 43 #include <iostream> 46 44 45 #include "TLibCommon/TComRom.h" 47 46 #include "TVideoIOYuv.h" 48 47 … … 50 49 51 50 /** 52 * Perform division with rounding of all pixels in #img by 53 * \f$ 2^{#shiftbits} \f$. All pixels are clipped to [minval, maxval] 54 * 55 * @param stride distance between vertically adjacent pixels of #img. 56 * @param width width of active area in #img. 57 * @param height height of active area in #img. 58 * @param minval minimum clipping value 59 * @param maxval maximum clipping value 51 * Perform division with rounding of all pixels in img by 52 * 2<sup>shiftbits</sup>. All pixels are clipped to [minval, maxval] 53 * 54 * @param img pointer to image to be transformed 55 * @param stride distance between vertically adjacent pixels of img. 56 * @param width width of active area in img. 57 * @param height height of active area in img. 58 * @param shiftbits number of rounding bits 59 * @param minval minimum clipping value 60 * @param maxval maximum clipping value 60 61 */ 61 62 static void invScalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height, … … 75 76 76 77 /** 77 * Multiply all pixels in #img by \f$ 2^{#shiftbits} \f$. 78 * 79 * @param stride distance between vertically adjacent pixels of #img. 80 * @param width width of active area in #img. 81 * @param height height of active area in #img. 78 * Multiply all pixels in img by 2<sup>shiftbits</sup>. 79 * 80 * @param img pointer to image to be transformed 81 * @param stride distance between vertically adjacent pixels of img. 82 * @param width width of active area in img. 83 * @param height height of active area in img. 84 * @param shiftbits number of bits to shift 82 85 */ 83 86 static void scalePlane(Pel* img, unsigned int stride, unsigned int width, unsigned int height, … … 95 98 96 99 /** 97 * Scale all pixels in #img depending upon sign of #shiftbits by a factor of 98 * \f$ 2^{#shiftbits} \f$. 99 * 100 * @param stride distance between vertically adjacent pixels of #img. 101 * @param width width of active area in #img. 102 * @param height height of active area in #img. 100 * Scale all pixels in img depending upon sign of shiftbits by a factor of 101 * 2<sup>shiftbits</sup>. 102 * 103 * @param img pointer to image to be transformed 104 * @param stride distance between vertically adjacent pixels of img. 105 * @param width width of active area in img. 106 * @param height height of active area in img. 103 107 * @param shiftbits if zero, no operation performed 104 * if > 0, multiply by \f$ 2^{#shiftbits} \f$, see scalePlane()105 * if < 0, divide and round by \f$ 2^{#shiftbits} \f$and clip,108 * if > 0, multiply by 2<sup>shiftbits</sup>, see scalePlane() 109 * if < 0, divide and round by 2<sup>shiftbits</sup> and clip, 106 110 * see invScalePlane(). 107 111 * @param minval minimum clipping value when dividing. … … 134 138 * Open file for reading/writing Y'CbCr frames. 135 139 * 136 * Frames read/written have bitdepth #fileBitDepth, and are automatically140 * Frames read/written have bitdepth fileBitDepth, and are automatically 137 141 * formatted as 8 or 16 bit word values (see TVideoIOYuv::write()). 138 142 * 139 * Image data read or written is converted to/from #internalBitDepth143 * Image data read or written is converted to/from internalBitDepth 140 144 * (See scalePlane(), TVideoIOYuv::read() and TVideoIOYuv::write() for 141 145 * further details). … … 185 189 } 186 190 187 /** 188 * Skip @numFrames in input. 191 Bool TVideoIOYuv::isFail() 192 { 193 return m_cHandle.fail(); 194 } 195 196 /** 197 * Skip numFrames in input. 189 198 * 190 199 * This function correctly handles cases where the input file is not … … 216 225 217 226 /** 218 * Read \f$ #width * #height \f$ pixels from #fd into #dst, optionally227 * Read width*height pixels from fd into dst, optionally 219 228 * padding the left and right edges by edge-extension. Input may be 220 229 * either 8bit or 16bit little-endian lsb-aligned words. 221 230 * 222 231 * @param dst destination image 232 * @param fd input file stream 223 233 * @param is16bit true if input file carries > 8bit data, false otherwise. 224 * @param stride distance between vertically adjacent pixels of #dst.225 * @param width width of active area in #dst.226 * @param height height of active area in #dst.234 * @param stride distance between vertically adjacent pixels of dst. 235 * @param width width of active area in dst. 236 * @param height height of active area in dst. 227 237 * @param pad_x length of horizontal padding. 228 238 * @param pad_y length of vertical padding. 229 */ 230 static void readPlane(Pel* dst, istream& fd, bool is16bit, 239 * @return true for success, false in case of error 240 */ 241 static bool readPlane(Pel* dst, istream& fd, bool is16bit, 231 242 unsigned int stride, 232 243 unsigned int width, unsigned int height, … … 238 249 { 239 250 fd.read(reinterpret_cast<char*>(buf), read_len); 240 if (!is16bit) { 241 for (int x = 0; x < width; x++) { 251 if (fd.eof() || fd.fail() ) 252 { 253 delete[] buf; 254 return false; 255 } 256 257 if (!is16bit) 258 { 259 for (int x = 0; x < width; x++) 260 { 242 261 dst[x] = buf[x]; 243 262 } 244 263 } 245 else { 246 for (int x = 0; x < width; x++) { 264 else 265 { 266 for (int x = 0; x < width; x++) 267 { 247 268 dst[x] = (buf[2*x+1] << 8) | buf[2*x]; 248 269 } … … 257 278 for (int y = height; y < height + pad_y; y++) 258 279 { 259 for (int x = width; x < width + pad_x; x++)260 { 261 dst[x] = dst[x - stride];280 for (int x = 0; x < width + pad_x; x++) 281 { 282 dst[x] = (dst - stride)[x]; 262 283 } 263 284 dst += stride; 264 285 } 265 286 delete[] buf; 266 } 267 268 /** 269 * Write \f$ #width * #height \f$ pixels info #fd from #src. 270 * 287 return true; 288 } 289 290 /** 291 * Write width*height pixels info fd from src. 292 * 293 * @param fd output file stream 271 294 * @param src source image 272 295 * @param is16bit true if input file carries > 8bit data, false otherwise. 273 * @param stride distance between vertically adjacent pixels of #src. 274 * @param width width of active area in #src. 275 * @param height height of active area in #src. 276 */ 277 static void writePlane(ostream& fd, Pel* src, bool is16bit, 296 * @param stride distance between vertically adjacent pixels of src. 297 * @param width width of active area in src. 298 * @param height height of active area in src. 299 * @return true for success, false in case of error 300 */ 301 static bool writePlane(ostream& fd, Pel* src, bool is16bit, 278 302 unsigned int stride, 279 303 unsigned int width, unsigned int height) … … 300 324 301 325 fd.write(reinterpret_cast<char*>(buf), write_len); 326 if (fd.eof() || fd.fail() ) 327 { 328 delete[] buf; 329 return false; 330 } 302 331 src += stride; 303 332 } 304 333 delete[] buf; 334 return true; 305 335 } 306 336 … … 309 339 * from the bitdepth of the input file to the internal bit-depth. 310 340 * 311 * If a bit-depth reduction is requ ried, and internalBitdepth >= 8, then341 * If a bit-depth reduction is required, and internalBitdepth >= 8, then 312 342 * the input file is assumed to be ITU-R BT.601/709 compliant, and the 313 343 * resulting data is clipped to the appropriate legal range, as if the 314 344 * file had been provided at the lower-bitdepth compliant to Rec601/709. 315 345 * 316 \param rpcPicYuv input picture YUV buffer class pointer 317 \param aiPad[2] source padding size, aiPad[0] = horizontal, aiPad[1] = vertical 318 */ 319 Void TVideoIOYuv::read ( TComPicYuv*& rpcPicYuv, Int aiPad[2], Bool bRewind /* = false */ ) 346 * @param pPicYuv input picture YUV buffer class pointer 347 * @param aiPad source padding size, aiPad[0] = horizontal, aiPad[1] = vertical 348 * @return true for success, false in case of error 349 */ 350 bool TVideoIOYuv::read ( TComPicYuv* pPicYuv, Int aiPad[2], Bool bRewind ) 320 351 { 321 352 // check end-of-file 322 if ( isEof() ) return ;353 if ( isEof() ) return false; 323 354 324 Int iStride = rpcPicYuv->getStride();355 Int iStride = pPicYuv->getStride(); 325 356 326 357 // compute actual YUV width & height excluding padding size 327 358 unsigned int pad_h = aiPad[0]; 328 359 unsigned int pad_v = aiPad[1]; 329 unsigned int width_full = rpcPicYuv->getWidth();330 unsigned int height_full = rpcPicYuv->getHeight();360 unsigned int width_full = pPicYuv->getWidth(); 361 unsigned int height_full = pPicYuv->getHeight(); 331 362 unsigned int width = width_full - pad_h; 332 363 unsigned int height = height_full - pad_v; … … 345 376 #endif 346 377 347 readPlane(rpcPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v); 348 scalePlane(rpcPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 378 if (! readPlane(pPicYuv->getLumaAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 379 return false; 380 scalePlane(pPicYuv->getLumaAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 349 381 350 382 iStride >>= 1; … … 356 388 pad_v >>= 1; 357 389 358 readPlane(rpcPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v); 359 scalePlane(rpcPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 360 361 readPlane(rpcPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v); 362 scalePlane(rpcPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 390 if (! readPlane(pPicYuv->getCbAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 391 return false; 392 scalePlane(pPicYuv->getCbAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 393 394 if (! readPlane(pPicYuv->getCrAddr(), m_cHandle, is16bit, iStride, width, height, pad_h, pad_v)) 395 return false; 396 scalePlane(pPicYuv->getCrAddr(), iStride, width_full, height_full, m_bitdepthShift, minval, maxval); 363 397 364 398 if( bRewind ) … … 367 401 m_cHandle.seekg( -iFrameSize, std::ios_base::cur ); 368 402 } 369 } 370 371 /** 372 * Write one Y'CbCr frame. No bit-depth conversion is performed, #pcPicYuv is 403 404 return true; 405 } 406 407 /** 408 * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is 373 409 * assumed to be at TVideoIO::m_fileBitdepth depth. 374 410 * 375 \param pcPicYuv input picture YUV buffer class pointer 376 \param aiPad[2] source padding size, aiPad[0] = horizontal, aiPad[1] = vertical 377 */ 378 Void TVideoIOYuv::write( TComPicYuv* pcPicYuv, Int aiPad[2] ) 411 * @param pPicYuv input picture YUV buffer class pointer 412 * @param aiPad source padding size, aiPad[0] = horizontal, aiPad[1] = vertical 413 * @return true for success, false in case of error 414 */ 415 #if PIC_CROPPING 416 Bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom ) 417 #else 418 bool TVideoIOYuv::write( TComPicYuv* pPicYuv, Int aiPad[2] ) 419 #endif 379 420 { 380 421 // compute actual YUV frame size excluding padding size 381 Int iStride = pcPicYuv->getStride(); 382 unsigned int width = pcPicYuv->getWidth() - aiPad[0]; 383 unsigned int height = pcPicYuv->getHeight() - aiPad[1]; 422 Int iStride = pPicYuv->getStride(); 423 #if PIC_CROPPING 424 UInt width = pPicYuv->getWidth() - cropLeft - cropRight; 425 UInt height = pPicYuv->getHeight() - cropTop - cropBottom; 426 #else 427 unsigned int width = pPicYuv->getWidth() - aiPad[0]; 428 unsigned int height = pPicYuv->getHeight() - aiPad[1]; 429 #endif 384 430 bool is16bit = m_fileBitdepth > 8; 385 431 TComPicYuv *dstPicYuv = NULL; 432 bool retval = true; 386 433 387 434 if (m_bitdepthShift != 0) 388 435 { 389 436 dstPicYuv = new TComPicYuv; 390 dstPicYuv->create( p cPicYuv->getWidth(), pcPicYuv->getHeight(), 1, 1, 0 );391 p cPicYuv->copyToPic(dstPicYuv);437 dstPicYuv->create( pPicYuv->getWidth(), pPicYuv->getHeight(), 1, 1, 0 ); 438 pPicYuv->copyToPic(dstPicYuv); 392 439 393 440 Pel minval = 0; … … 407 454 else 408 455 { 409 dstPicYuv = pcPicYuv; 410 } 456 dstPicYuv = pPicYuv; 457 } 458 #if PIC_CROPPING 459 // location of upper left pel in a plane 460 Int planeOffset = 0; //cropLeft + cropTop * iStride; 411 461 412 writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height); 462 if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr() + planeOffset, is16bit, iStride, width, height)) 463 #else 464 if (! writePlane(m_cHandle, dstPicYuv->getLumaAddr(), is16bit, iStride, width, height)) 465 #endif 466 { 467 retval=false; 468 goto exit; 469 } 413 470 414 471 width >>= 1; 415 472 height >>= 1; 416 473 iStride >>= 1; 417 writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height); 418 writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height); 474 #if PIC_CROPPING 475 cropLeft >>= 1; 476 cropRight >>= 1; 477 478 planeOffset = 0; // cropLeft + cropTop * iStride; 479 480 if (! writePlane(m_cHandle, dstPicYuv->getCbAddr() + planeOffset, is16bit, iStride, width, height)) 481 #else 482 if (! writePlane(m_cHandle, dstPicYuv->getCbAddr(), is16bit, iStride, width, height)) 483 #endif 484 { 485 retval=false; 486 goto exit; 487 } 488 #if PIC_CROPPING 489 if (! writePlane(m_cHandle, dstPicYuv->getCrAddr() + planeOffset, is16bit, iStride, width, height)) 490 #else 491 if (! writePlane(m_cHandle, dstPicYuv->getCrAddr(), is16bit, iStride, width, height)) 492 #endif 493 { 494 retval=false; 495 goto exit; 496 } 419 497 498 exit: 420 499 if (m_bitdepthShift != 0) 421 500 { … … 423 502 delete dstPicYuv; 424 503 } 425 } 426 504 return retval; 505 } 506 -
trunk/source/Lib/TLibVideoIO/TVideoIOYuv.h
r5 r56 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 1,ISO/IEC6 * Copyright (c) 2010-2012, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 15 15 * this list of conditions and the following disclaimer in the documentation 16 16 * and/or other materials provided with the distribution. 17 * * Neither the name of the I SO/IEC nor the names of its contributors may17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may 18 18 * be used to endorse or promote products derived from this software without 19 19 * specific prior written permission. … … 31 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 32 */ 33 34 35 33 36 34 /** \file TVideoIOYuv.h … … 70 68 void skipFrames(unsigned int numFrames, unsigned int width, unsigned int height); 71 69 72 Void read ( TComPicYuv*& rpcPicYuv, Int aiPad[2], Bool bRewind = false ); ///< read one YUV frame with padding parameter 73 Void write ( TComPicYuv* pcPicYuv, Int aiPad[2] ); ///< write one YUV frame with padding parameter 70 bool read ( TComPicYuv* pPicYuv, Int aiPad[2], Bool bRewind = false ); ///< read one YUV frame with padding parameter 71 #if PIC_CROPPING 72 Bool write( TComPicYuv* pPicYuv, Int cropLeft=0, Int cropRight=0, Int cropTop=0, Int cropBottom=0 ); 73 #else 74 bool write ( TComPicYuv* pPicYuv, Int aiPad[2] ); ///< write one YUV frame with padding parameter 75 #endif 74 76 75 Bool isEof (); ///< check end-of-file 77 bool isEof (); ///< check for end-of-file 78 bool isFail(); ///< check for failure 76 79 77 80 };
Note: See TracChangeset for help on using the changeset viewer.