Changeset 1587 in SHVCSoftware for branches/SHM-dev/source/App
- Timestamp:
- 14 Nov 2016, 22:27:52 (8 years ago)
- Location:
- branches/SHM-dev/source/App/TAppDownConvert
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/App/TAppDownConvert/DownConvert.cpp
r1549 r1587 92 92 93 93 void 94 DownConvert::downsamplingSVC( unsigned char* pucBufferY, int iStrideY,95 unsigned char* pucBufferU, int iStrideU,96 unsigned char* pucBufferV, int iStrideV,94 DownConvert::downsamplingSVC( short* pucBufferY, int iStrideY, 95 short* pucBufferU, int iStrideU, 96 short* pucBufferV, int iStrideV, 97 97 ResizeParameters* pcParameters, bool bBotCoincided ) 98 98 { … … 130 130 if( !bTopAndBottomResampling ) 131 131 { 132 unsigned char* pSrc = pucBufferY + iStrideY * iCurrBot;133 unsigned char* pDes = pucBufferY + iStrideY * iBaseBot;132 short* pSrc = pucBufferY + iStrideY * iCurrBot; 133 short* pDes = pucBufferY + iStrideY * iBaseBot; 134 134 xCopyToImageBuffer ( pSrc, iCurrW, iCurrH >> iCurrField, iStrideY << iCurrField ); 135 135 xCompDownsampling ( pcParameters, false, bBotFieldFlag, bVerticalDownsampling ); … … 148 148 { 149 149 //===== U ===== 150 unsigned char* pSrc = pucBufferU + iStrideU * iCurrBot;151 unsigned char* pDes = pucBufferU + iStrideU * iBaseBot;150 short* pSrc = pucBufferU + iStrideU * iCurrBot; 151 short* pDes = pucBufferU + iStrideU * iBaseBot; 152 152 xCopyToImageBuffer ( pSrc, iCurrW, iCurrH >> iCurrField, iStrideU << iCurrField ); 153 153 xCompDownsampling ( pcParameters, true, bBotFieldFlag, bVerticalDownsampling ); … … 195 195 196 196 void 197 DownConvert::xCopyToImageBuffer( unsigned char* pucSrc, int iWidth, int iHeight, int iStride )197 DownConvert::xCopyToImageBuffer( short* pucSrc, int iWidth, int iHeight, int iStride ) 198 198 { 199 199 int* piDes = m_paiImageBuffer; … … 210 210 211 211 void 212 DownConvert::xCopyFromImageBuffer( unsigned char* pucDes, int iWidth, int iHeight, int iStride )212 DownConvert::xCopyFromImageBuffer( short* pucDes, int iWidth, int iHeight, int iStride ) 213 213 { 214 214 int* piSrc = m_paiImageBuffer; … … 217 217 for( int i = 0; i < iWidth; i++ ) 218 218 { 219 pucDes[i] = ( unsigned char)piSrc[i];219 pucDes[i] = (short)piSrc[i]; 220 220 } 221 221 pucDes += iStride; … … 262 262 int iScaleX = ( ( (unsigned int)iScaledW << iShiftX ) + ( iRefW >> 1 ) ) / iRefW; 263 263 int iScaleY = ( ( (unsigned int)iScaledH << iShiftY ) + ( iRefH >> 1 ) ) / iRefH; 264 265 int inputBitDepth = pcParameters->inputBitDepth; 266 int outputBitDepth = pcParameters->outputBitDepth; 267 264 268 if( ! pcParameters->m_bFrameMbsOnlyFlag || ! pcParameters->m_bRefLayerFrameMbsOnlyFlag ) 265 269 { … … 304 308 if( bVerticalDownsampling ) 305 309 { 306 xVertDownsampling( iCurrW, iCurrH, bBotFlag 310 xVertDownsampling( iCurrW, iCurrH, bBotFlag, inputBitDepth, outputBitDepth); 307 311 } 308 312 … … 311 315 iLOffset, iTOffset, iROffset, iBOffset, 312 316 iShiftX, iShiftY, iScaleX, iScaleY, 313 iAddX, iAddY, iDeltaX, iDeltaY ); 317 iAddX, iAddY, iDeltaX, iDeltaY, 318 inputBitDepth, outputBitDepth); 314 319 } 315 320 … … 317 322 DownConvert::xVertDownsampling( int iBaseW, 318 323 int iBaseH, 319 bool bBotFlag 324 bool bBotFlag, int inputBitDepth, int outputBitDepth) 320 325 { 321 326 int aiVertFilter[13] = { 2, 0, -4, -3, 5, 19, 26, 19, 5, -3, -4, 0, 2 }; … … 323 328 int iCurrW = iBaseW; 324 329 int iCurrH = iBaseH << 1; 330 331 int shift = 6 + (inputBitDepth - outputBitDepth); 332 int shift_round = (1 << (shift -1)); 325 333 326 334 //===== vertical downsampling ===== … … 336 344 m_paiTmp1dBuffer[i] += aiVertFilter[k] * piSrc[m*m_iImageStride]; 337 345 } 338 m_paiTmp1dBuffer[i] = ( m_paiTmp1dBuffer[i] + 32 ) >> 6;346 m_paiTmp1dBuffer[i] = ( m_paiTmp1dBuffer[i] + shift_round ) >> shift; 339 347 } 340 348 //--- clip and copy back to image buffer --- 341 for( int n = 0; n < iBaseH; n++ )342 {343 piSrc[n*m_iImageStride] = xClip( m_paiTmp1dBuffer[n], 0, 255);344 }349 for( int n = 0; n < iBaseH; n++ ) 350 { 351 piSrc[n*m_iImageStride] = xClip( m_paiTmp1dBuffer[n], 0, ((1<<outputBitDepth)-1) ); 352 } 345 353 } 346 354 } … … 350 358 int iLOffset, int iTOffset, int iROffset, int iBOffset, 351 359 int iShiftX, int iShiftY, int iScaleX, int iScaleY, 352 int iAddX, int iAddY, int iDeltaX, int iDeltaY )360 int iAddX, int iAddY, int iDeltaX, int iDeltaY, int inputBitDepth, int outputBitDepth ) 353 361 { 354 362 const int filter16[8][16][12] = … … 527 535 int iShiftYM4 = iShiftY - 4; 528 536 537 int shift = 14 + (inputBitDepth - outputBitDepth); 538 int shift_round = (1 << (shift -1)); 539 529 540 //===== horizontal downsampling ===== 530 541 { … … 567 578 m_paiTmp1dBuffer[j] += filter16[iVerFilter][iPhase][k] * piSrc[m*m_iImageStride]; 568 579 } 569 m_paiTmp1dBuffer[j] = ( m_paiTmp1dBuffer[j] + 8192 ) >> 14;580 m_paiTmp1dBuffer[j] = ( m_paiTmp1dBuffer[j] + shift_round ) >> shift; 570 581 } 571 582 //--- clip and copy back to image buffer --- 572 for( int n = 0; n < iBaseH; n++ )573 {574 piSrc[n*m_iImageStride] = xClip( m_paiTmp1dBuffer[n], 0, 255);575 }576 } 577 } 578 } 579 580 581 582 583 for( int n = 0; n < iBaseH; n++ ) 584 { 585 piSrc[n*m_iImageStride] = xClip( m_paiTmp1dBuffer[n], 0, ((1<<outputBitDepth)-1)); 586 } 587 } 588 } 589 } 590 591 592 593 -
branches/SHM-dev/source/App/TAppDownConvert/DownConvert.h
r1549 r1587 94 94 , m_iRefLayerWidthInSamples ( 0 ) 95 95 , m_iRefLayerHeightInSamples ( 0 ) 96 , inputBitDepth ( 8 ) 97 , outputBitDepth ( 8 ) 96 98 { 97 99 }; … … 129 131 Int m_iRefLayerWidthInSamples; 130 132 Int m_iRefLayerHeightInSamples; 133 134 //===== parameters for bit depth ===== 135 int inputBitDepth; 136 int outputBitDepth; 131 137 }; 132 138 … … 146 152 // main functions for DownConvert Tool 147 153 //===================================== 148 void downsamplingSVC ( unsigned char* pucBufferY, int iStrideY,149 unsigned char* pucBufferU, int iStrideU,150 unsigned char* pucBufferV, int iStrideV,154 void downsamplingSVC ( short* pucBufferY, int iStrideY, 155 short* pucBufferU, int iStrideU, 156 short* pucBufferV, int iStrideV, 151 157 ResizeParameters* pcParameters, bool bBotCoincided = false ); 152 158 … … 164 170 //======================================= 165 171 //--- place to and get from image buffer --- 166 void xCopyToImageBuffer ( unsigned char* pucSrc,172 void xCopyToImageBuffer ( short* pucSrc, 167 173 int iWidth, 168 174 int iHeight, 169 175 int iStride ); 170 void xCopyFromImageBuffer ( unsigned char* pucDes,176 void xCopyFromImageBuffer ( short* pucDes, 171 177 int iWidth, 172 178 int iHeight, … … 179 185 void xVertDownsampling ( int iBaseW, 180 186 int iBaseH, 181 bool bBotFlag ); 187 bool bBotFlag, 188 int inputBitDepth, 189 int outputBitDepth); 182 190 void xBasicDownsampling ( int iBaseW, int iBaseH, int iCurrW, int iCurrH, 183 191 int iLOffset, int iTOffset, int iROffset, int iBOffset, 184 192 int iShiftX, int iShiftY, int iScaleX, int iScaleY, 185 int iAddX, int iAddY, int iDeltaX, int iDeltaY ); 193 int iAddX, int iAddY, int iDeltaX, int iDeltaY, 194 int inputBitDepth, int outputBitDepth); 186 195 private: 187 196 //===== member variables ===== -
branches/SHM-dev/source/App/TAppDownConvert/TAppDownConvert.cpp
r1549 r1587 48 48 int stride; 49 49 int lines; 50 unsigned char* data;51 unsigned char* data2;50 short* data; 51 short* data2; 52 52 } ColorComponent; 53 53 54 54 typedef struct 55 55 { 56 int inputBitDepth; 57 int outputBitDepth; 56 58 ColorComponent y; 57 59 ColorComponent u; … … 68 70 c.stride = maxwidth; 69 71 c.lines = maxheight; 70 c.data = new unsigned char[ size ];71 c.data2 = new unsigned char[ size ];72 c.data = new short [ size ]; 73 c.data2 = new short [ size ]; 72 74 73 75 if( ! c.data || ! c.data2 ) … … 90 92 91 93 int 92 readColorComponent( ColorComponent& c, FILE* file, int width, int height, bool second )94 readColorComponent( ColorComponent& c, FILE* file, int width, int height, int inputBitDepth, bool second ) 93 95 { 94 96 assert( width <= c.stride ); 95 97 assert( height <= c.lines ); 96 98 unsigned char *temp=NULL; 99 97 100 int iMaxPadWidth = gMin( c.stride, ( ( width + 15 ) >> 4 ) << 4 ); 98 101 int iMaxPadHeight = gMin( c.lines, ( ( height + 31 ) >> 5 ) << 5 ); … … 100 103 for( int i = 0; i < height; i++ ) 101 104 { 102 unsigned char* buffer = ( second ? c.data2 : c.data ) + i * c.stride; 103 int rsize = (int)fread( buffer, sizeof(unsigned char), width, file ); 105 short* buffer = ( second ? c.data2 : c.data ) + i * c.stride; 106 int rsize; 107 108 if (inputBitDepth == 10) 109 { 110 rsize = (int)fread( buffer, sizeof(short), width, file ); 111 } 112 else 113 { 114 if (temp == NULL) 115 temp = (unsigned char * )calloc(width, sizeof(unsigned char)); 116 rsize = (int)fread( temp, sizeof(unsigned char), width, file ); 117 for (int j = 0; j < width; j++) 118 buffer[j] = (short) temp[j]; 119 } 104 120 if( rsize != width ) 105 121 { … … 113 129 for( int yp = height; yp < iMaxPadHeight; yp++ ) 114 130 { 115 unsigned char* buffer = ( second ? c.data2 : c.data ) + yp * c.stride;116 unsigned char* bufferX = buffer - c.stride;131 short* buffer = ( second ? c.data2 : c.data ) + yp * c.stride; 132 short* bufferX = buffer - c.stride; 117 133 for( int xp = 0; xp < c.stride; xp++ ) 118 134 { … … 120 136 } 121 137 } 138 if (temp!=NULL) 139 free(temp); 122 140 return 0; 123 141 } … … 126 144 duplicateColorComponent( ColorComponent& c ) 127 145 { 128 memcpy( c.data2, c.data, c.stride * c.lines * sizeof( unsigned char) );146 memcpy( c.data2, c.data, c.stride * c.lines * sizeof(short) ); 129 147 } 130 148 … … 133 151 { 134 152 int offs = ( bBotField ? c.stride : 0 ); 135 unsigned char* pDes = c.data + offs;136 unsigned char* pSrc = c.data2 + offs;153 short* pDes = c.data + offs; 154 short* pSrc = c.data2 + offs; 137 155 for( int i = 0; i < c.lines / 2; i++, pDes += 2*c.stride, pSrc += 2*c.stride ) 138 156 { 139 memcpy( pDes, pSrc, c.stride * sizeof( unsigned char) );140 } 141 } 142 143 void 144 writeColorComponent( ColorComponent& c, FILE* file, int width, int height, bool second )157 memcpy( pDes, pSrc, c.stride * sizeof(short) ); 158 } 159 } 160 161 void 162 writeColorComponent( ColorComponent& c, FILE* file, int width, int height, int outputBitDepth, bool second ) 145 163 { 146 164 assert( width <= c.stride ); 147 165 assert( height <= c.lines ); 148 166 unsigned char* temp = NULL; 167 149 168 for( int i = 0; i < height; i++ ) 150 169 { 151 unsigned char* buffer = ( second ? c.data2 : c.data ) + i * c.stride; 152 int wsize = (int)fwrite( buffer, sizeof(unsigned char), width, file ); 170 short* buffer = ( second ? c.data2 : c.data ) + i * c.stride; 171 int wsize; 172 173 if ( outputBitDepth == 8 ) 174 { 175 if (temp == NULL) 176 temp = (unsigned char * )calloc(width, sizeof(unsigned char)); 177 for (int j = 0; j < width; j ++) 178 temp[j] = (unsigned char)buffer[j]; 179 wsize = (int)fwrite( temp, sizeof(unsigned char), width, file ); 180 } 181 else 182 { 183 wsize = (int)fwrite( buffer, sizeof(short), width, file ); 184 } 153 185 154 186 if( wsize != width ) … … 162 194 163 195 void 164 createFrame( YuvFrame& f, int width, int height ) 165 { 196 createFrame( YuvFrame& f, int width, int height, int inputBitDepth, int outputBitDepth ) 197 { 198 f.inputBitDepth = inputBitDepth; 199 f.outputBitDepth = outputBitDepth; 166 200 createColorComponent( f.y, width, height ); 167 201 createColorComponent( f.u, width >> 1, height >> 1 ); … … 180 214 readFrame( YuvFrame& f, FILE* file, int width, int height, bool second = false ) 181 215 { 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 );216 ROTRS( readColorComponent( f.y, file, width, height, f.inputBitDepth, second ), 1 ); 217 ROTRS( readColorComponent( f.u, file, width >> 1, height >> 1, f.inputBitDepth, second ), 1 ); 218 ROTRS( readColorComponent( f.v, file, width >> 1, height >> 1, f.inputBitDepth, second ), 1 ); 185 219 return 0; 186 220 } … … 205 239 writeFrame( YuvFrame& f, FILE* file, int width, int height, bool both = false ) 206 240 { 207 writeColorComponent( f.y, file, width, height, f alse );208 writeColorComponent( f.u, file, width >> 1, height >> 1, f alse );209 writeColorComponent( f.v, file, width >> 1, height >> 1, f alse );241 writeColorComponent( f.y, file, width, height, f.outputBitDepth, false ); 242 writeColorComponent( f.u, file, width >> 1, height >> 1, f.outputBitDepth, false ); 243 writeColorComponent( f.v, file, width >> 1, height >> 1, f.outputBitDepth, false ); 210 244 211 245 if( both ) 212 246 { 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 );247 writeColorComponent( f.y, file, width, height, f.outputBitDepth, true ); 248 writeColorComponent( f.u, file, width >> 1, height >> 1, f.outputBitDepth, true ); 249 writeColorComponent( f.v, file, width >> 1, height >> 1, f.outputBitDepth, true ); 216 250 } 217 251 } … … 227 261 fprintf ( stderr, "\nERROR: %s\n", message ); 228 262 } 229 fprintf ( stderr, "\nUsage: %s <win> <hin> <in> <wout> <hout> <out> [< t> [<skip> [<frms>]]] [[-phase <args>] ]\n\n", name );263 fprintf ( stderr, "\nUsage: %s <win> <hin> <in> <wout> <hout> <out> [<bin> <bout> <method> <t> [<skip> [<frms>]]] [[-phase <args>] ]\n\n", name ); 230 264 fprintf ( stderr, " win : input width (luma samples)\n" ); 231 265 fprintf ( stderr, " hin : input height (luma samples)\n" ); … … 235 269 fprintf ( stderr, " out : output file\n" ); 236 270 fprintf ( stderr, "\n--------------------------- OPTIONAL ---------------------------\n\n" ); 271 fprintf ( stderr, " bin : input bit depth (8 or 10) (default: 8)\n" ); 272 fprintf ( stderr, " bout : output bit depth (8 or 10) (default: 8)\n" ); 273 fprintf ( stderr, " method : sampling method (0, 1, 2, 3, 4) (default: 0)\n" ); 237 274 fprintf ( stderr, " t : number of temporal downsampling stages (default: 0)\n" ); 238 275 fprintf ( stderr, " skip : number of frames to skip at start (default: 0)\n" ); … … 244 281 fprintf ( stderr, " out_uv_ph_x: output chroma phase shift in horizontal direction (default:-1)\n" ); 245 282 fprintf ( stderr, " out_uv_ph_y: output chroma phase shift in vertical direction (default: 0)\n" ); 283 fprintf ( stderr, "\n-------------------------- EXAMPLE --------------------------\n\n" ); 284 fprintf ( stderr, "\nUsage: %s 4096 2048 input_video_4096x2048_10bits.yuv 2048 1024 output_video_2048x1024_8bits.yuv 10 8\n\n", name ); 246 285 fprintf ( stderr, "\n\n"); 247 286 exit ( 1 ); … … 304 343 cRP.m_iScaledRefFrmWidth = iScaledRefFrmW; 305 344 cRP.m_iScaledRefFrmHeight = iScaledRefFrmH; 345 cRP.inputBitDepth = rcFrame.inputBitDepth; 346 cRP.outputBitDepth = rcFrame.outputBitDepth; 306 347 } 307 348 assert( resamplingMethod == 0 ); … … 354 395 FILE* outputFile = 0; 355 396 FILE* croppingParametersFile = 0; 397 int inputBitDepth = 8; 398 int outputBitDepth = 8; 356 399 int resamplingMethod = 0; 357 400 int resamplingMode = 0; … … 396 439 print_usage_and_exit( cRP.m_iChromaPhaseY > 1 || cRP.m_iChromaPhaseY < -1, argv[0], "wrong phase x parameters (range : [-1, 1])"); 397 440 } 398 else if (i == 7) 441 else if (i == 7) // input bit depth 442 { 443 inputBitDepth = atoi( argv[i++] ); 444 print_usage_and_exit( inputBitDepth != 8 && inputBitDepth != 10, argv[0], "wrong input bit depth (8 bit or 10 bit)"); 445 } 446 else if (i == 8) // output bit depth 447 { 448 outputBitDepth = atoi( argv[i++] ); 449 print_usage_and_exit( outputBitDepth != 8 && outputBitDepth != 10, argv[0], "wrong output bit depth (8 bit or 10 bit)"); 450 } 451 else if (i == 9) // downsampling methods 399 452 { 400 453 methodInitialized = true; … … 439 492 } 440 493 } 441 else if( i == 8 )494 else if( i == 10 ) // temporal stages 442 495 { 443 496 int TStages = atoi( argv[i++] ); … … 445 498 print_usage_and_exit( TStages < 0, argv[0], "negative number of temporal stages" ); 446 499 } 447 else if( i == 9 )500 else if( i == 11 ) // skipped frames 448 501 { 449 502 skipAtStart = atoi( argv[i++] ); 450 503 print_usage_and_exit( skipAtStart < 0, argv[0], "negative number of skipped frames at start" ); 451 504 } 452 else if( i == 1 0 )505 else if( i == 12 ) // output frames 453 506 { 454 507 maxNumOutputFrames = atoi( argv[i++] ); … … 515 568 maxWidth = ( ( maxWidth * minWRnd16 + ( minWidth << 4 ) - 1 ) / ( minWidth << 4 ) ) << 4; 516 569 maxHeight = ( ( maxHeight * minHRnd32 + ( minHeight << 4 ) - 1 ) / ( minHeight << 4 ) ) << 4; 517 createFrame( cFrame, maxWidth, maxHeight );570 createFrame( cFrame, maxWidth, maxHeight, inputBitDepth, outputBitDepth ); 518 571 cDownConvert.init( maxWidth, maxHeight ); 519 572 }
Note: See TracChangeset for help on using the changeset viewer.