From 2d0223286b7c0096e8e81f81e6bd07e97ed94444 Mon Sep 17 00:00:00 2001 From: "marpan@webrtc.org" Date: Fri, 27 Apr 2012 15:56:02 +0000 Subject: [PATCH] VPM: fix to coverity issues 10255-10258 (unintended sign extension). Review URL: https://webrtc-codereview.appspot.com/532002 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2140 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/source/content_analysis.cc | 43 +++++++++---------- .../main/source/content_analysis.h | 10 ++--- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/modules/video_processing/main/source/content_analysis.cc b/src/modules/video_processing/main/source/content_analysis.cc index 8ea319c24d..bd15e1744d 100644 --- a/src/modules/video_processing/main/source/content_analysis.cc +++ b/src/modules/video_processing/main/source/content_analysis.cc @@ -64,10 +64,11 @@ VPMContentAnalysis::ComputeContentMetrics(const VideoFrame* inputFrame) } // Init if needed (native dimension change) - if (_width != inputFrame->Width() || _height != inputFrame->Height()) + if (_width != static_cast(inputFrame->Width()) || + _height != static_cast(inputFrame->Height())) { - if (VPM_OK != Initialize((WebRtc_UWord16)inputFrame->Width(), - (WebRtc_UWord16)inputFrame->Height())) + if (VPM_OK != Initialize(static_cast(inputFrame->Width()), + static_cast(inputFrame->Height()))) { return NULL; } @@ -114,7 +115,7 @@ VPMContentAnalysis::Release() } WebRtc_Word32 -VPMContentAnalysis::Initialize(WebRtc_UWord16 width, WebRtc_UWord16 height) +VPMContentAnalysis::Initialize(int width, int height) { _width = width; _height = height; @@ -190,24 +191,23 @@ WebRtc_Word32 VPMContentAnalysis::TemporalDiffMetric_C() { // size of original frame - WebRtc_UWord16 sizei = _height; - WebRtc_UWord16 sizej = _width; + int sizei = _height; + int sizej = _width; WebRtc_UWord32 tempDiffSum = 0; WebRtc_UWord32 pixelSum = 0; WebRtc_UWord64 pixelSqSum = 0; WebRtc_UWord32 numPixels = 0; // counter for # of pixels - WebRtc_UWord32 ssn; - const WebRtc_Word32 width_end = ((_width - 2*_border) & -16) + _border; + const int width_end = ((_width - 2*_border) & -16) + _border; - for(WebRtc_UWord16 i = _border; i < sizei - _border; i += _skipNum) + for(int i = _border; i < sizei - _border; i += _skipNum) { - for(WebRtc_UWord16 j = _border; j < width_end; j++) + for(int j = _border; j < width_end; j++) { numPixels += 1; - ssn = i * sizej + j; + int ssn = i * sizej + j; WebRtc_UWord8 currPixel = _origFrame[ssn]; WebRtc_UWord8 prevPixel = _prevFrame[ssn]; @@ -254,8 +254,8 @@ WebRtc_Word32 VPMContentAnalysis::ComputeSpatialMetrics_C() { //size of original frame - const WebRtc_UWord16 sizei = _height; - const WebRtc_UWord16 sizej = _width; + const int sizei = _height; + const int sizej = _width; // pixel mean square average: used to normalize the spatial metrics WebRtc_UWord32 pixelMSA = 0; @@ -265,19 +265,18 @@ VPMContentAnalysis::ComputeSpatialMetrics_C() WebRtc_UWord32 spatialErrHSum = 0; // make sure work section is a multiple of 16 - const WebRtc_UWord32 width_end = ((sizej - 2*_border) & -16) + _border; + const int width_end = ((sizej - 2*_border) & -16) + _border; - for(WebRtc_UWord16 i = _border; i < sizei - _border; i += _skipNum) + for(int i = _border; i < sizei - _border; i += _skipNum) { - for(WebRtc_UWord16 j = _border; j < width_end; j++) + for(int j = _border; j < width_end; j++) { - WebRtc_UWord32 ssn1,ssn2,ssn3,ssn4,ssn5; - ssn1= i * sizej + j; - ssn2 = (i + 1) * sizej + j; // bottom - ssn3 = (i - 1) * sizej + j; // top - ssn4 = i * sizej + j + 1; // right - ssn5 = i * sizej + j - 1; // left + int ssn1= i * sizej + j; + int ssn2 = (i + 1) * sizej + j; // bottom + int ssn3 = (i - 1) * sizej + j; // top + int ssn4 = i * sizej + j + 1; // right + int ssn5 = i * sizej + j - 1; // left WebRtc_UWord16 refPixel1 = _origFrame[ssn1] << 1; WebRtc_UWord16 refPixel2 = _origFrame[ssn1] << 2; diff --git a/src/modules/video_processing/main/source/content_analysis.h b/src/modules/video_processing/main/source/content_analysis.h index 588712a94c..f927a011f4 100644 --- a/src/modules/video_processing/main/source/content_analysis.h +++ b/src/modules/video_processing/main/source/content_analysis.h @@ -29,7 +29,7 @@ public: // extractContentFeature // Inputs: width, height // Return value: 0 if OK, negative value upon error - WebRtc_Word32 Initialize(WebRtc_UWord16 width, WebRtc_UWord16 height); + WebRtc_Word32 Initialize(int width, int height); // Extract content Feature - main function of ContentAnalysis // Input: new frame @@ -67,10 +67,10 @@ private: const WebRtc_UWord8* _origFrame; WebRtc_UWord8* _prevFrame; - WebRtc_UWord16 _width; - WebRtc_UWord16 _height; - WebRtc_UWord32 _skipNum; - WebRtc_Word32 _border; + int _width; + int _height; + int _skipNum; + int _border; // Content Metrics: // stores the local average of the metrics