diff --git a/src/modules/video_processing/main/interface/video_processing.h b/src/modules/video_processing/main/interface/video_processing.h index 580758416b..0ffc5b2dfb 100644 --- a/src/modules/video_processing/main/interface/video_processing.h +++ b/src/modules/video_processing/main/interface/video_processing.h @@ -198,6 +198,31 @@ public: */ static WebRtc_Word32 ColorEnhancement(VideoFrame& frame); + /** + Increases/decreases the luminance value. + + \param[in,out] frame + Pointer to the video frame buffer. + + \param[in] width + Frame width in pixels. + + \param[in] height + Frame height in pixels. + + \param[in] delta + The amount to change the chrominance value of every single pixel. + Can be < 0 also. + + \return 0 on success, -1 on failure. + */ + static WebRtc_Word32 Brighten(WebRtc_UWord8* frame, + int width, int height, int delta); + /** + \overload + */ + static WebRtc_Word32 Brighten(VideoFrame& frame, int delta); + /** Detects and removes camera flicker from a video stream. Every frame from the stream must be passed in. A frame will only be altered if flicker has been @@ -376,4 +401,3 @@ public: } //namespace #endif - diff --git a/src/modules/video_processing/main/source/brighten.cc b/src/modules/video_processing/main/source/brighten.cc new file mode 100644 index 0000000000..b459dfc226 --- /dev/null +++ b/src/modules/video_processing/main/source/brighten.cc @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "modules/video_processing/main/source/brighten.h" + +#include + +#include "system_wrappers/interface/trace.h" + +namespace webrtc { + +WebRtc_Word32 Brighten(WebRtc_UWord8* frame, + int width, int height, int delta) { + if (frame == NULL) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1, + "Null frame pointer"); + return VPM_PARAMETER_ERROR; + } + + if (width <= 0 || height <= 0) { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1, + "Invalid frame size"); + return VPM_PARAMETER_ERROR; + } + + int numPixels = width * height; + + int lookUp[256]; + for (int i = 0; i < 256; i++) { + int val = i + delta; + lookUp[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val); + } + + WebRtc_UWord8* tempPtr = frame; + + for (int i = 0; i < numPixels; i++) { + *tempPtr = static_cast(lookUp[*tempPtr]); + tempPtr++; + } + return VPM_OK; +} + +} // namespace webrtc diff --git a/src/modules/video_processing/main/source/brighten.h b/src/modules/video_processing/main/source/brighten.h new file mode 100644 index 0000000000..ed189fefb5 --- /dev/null +++ b/src/modules/video_processing/main/source/brighten.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef MODULES_VIDEO_PROCESSING_MAIN_SOURCE_BRIGHTEN_H_ +#define MODULES_VIDEO_PROCESSING_MAIN_SOURCE_BRIGHTEN_H_ + +#include "typedefs.h" +#include "modules/video_processing/main/interface/video_processing.h" + +namespace webrtc { + +WebRtc_Word32 Brighten(WebRtc_UWord8* frame, + int width, int height, int delta); +} // namespace + +#endif // MODULES_VIDEO_PROCESSING_MAIN_SOURCE_BRIGHTEN_H_ diff --git a/src/modules/video_processing/main/source/video_processing.gypi b/src/modules/video_processing/main/source/video_processing.gypi index a6ada810cf..a4eaf05a48 100644 --- a/src/modules/video_processing/main/source/video_processing.gypi +++ b/src/modules/video_processing/main/source/video_processing.gypi @@ -33,6 +33,7 @@ # headers 'video_processing_impl.h', 'brightness_detection.h', + 'brighten.h', 'color_enhancement.h', 'color_enhancement_private.h', 'content_analysis.h', @@ -45,6 +46,7 @@ # sources 'video_processing_impl.cc', 'brightness_detection.cc', + 'brighten.cc', 'color_enhancement.cc', 'content_analysis.cc', 'deflickering.cc', diff --git a/src/modules/video_processing/main/source/video_processing_impl.cc b/src/modules/video_processing/main/source/video_processing_impl.cc index ccb6b03018..744ba6d070 100644 --- a/src/modules/video_processing/main/source/video_processing_impl.cc +++ b/src/modules/video_processing/main/source/video_processing_impl.cc @@ -238,6 +238,21 @@ VideoProcessingModule::ColorEnhancement(WebRtc_UWord8* frame, return VideoProcessing::ColorEnhancement(frame, width, height); } +WebRtc_Word32 +VideoProcessingModule::Brighten(VideoFrame& frame, int delta) +{ + return Brighten(frame.Buffer(), frame.Width(), frame.Height(), delta); +} + +WebRtc_Word32 +VideoProcessingModule::Brighten(WebRtc_UWord8* frame, + int width, + int height, + int delta) +{ + return Brighten(frame, width, height, delta); +} + WebRtc_Word32 VideoProcessingModuleImpl::Deflickering(VideoFrame& frame, FrameStats& stats) diff --git a/src/modules/video_processing/main/source/video_processing_impl.h b/src/modules/video_processing/main/source/video_processing_impl.h index 813f2a7507..50ff916793 100644 --- a/src/modules/video_processing/main/source/video_processing_impl.h +++ b/src/modules/video_processing/main/source/video_processing_impl.h @@ -8,14 +8,11 @@ * be found in the AUTHORS file in the root of the source tree. */ -/* - * video_processing_impl.h - */ - #ifndef WEBRTC_MODULE_VIDEO_PROCESSING_IMPL_H #define WEBRTC_MODULE_VIDEO_PROCESSING_IMPL_H #include "video_processing.h" +#include "brighten.h" #include "brightness_detection.h" #include "color_enhancement.h" #include "deflickering.h" @@ -28,9 +25,9 @@ class CriticalSectionWrapper; class VideoProcessingModuleImpl : public VideoProcessingModule { public: - + VideoProcessingModuleImpl(WebRtc_Word32 id); - + virtual ~VideoProcessingModuleImpl(); virtual WebRtc_Word32 Version(WebRtc_Word8* version, @@ -48,14 +45,14 @@ public: WebRtc_UWord32 height, WebRtc_UWord32 timestamp, FrameStats& stats); - + virtual WebRtc_Word32 Deflickering(VideoFrame& frame, FrameStats& stats); virtual WebRtc_Word32 Denoising(WebRtc_UWord8* frame, WebRtc_UWord32 width, WebRtc_UWord32 height); - + virtual WebRtc_Word32 Denoising(VideoFrame& frame); virtual WebRtc_Word32 BrightnessDetection(const WebRtc_UWord8* frame, @@ -79,20 +76,21 @@ public: //Set max frame rate virtual WebRtc_Word32 SetMaxFrameRate(WebRtc_UWord32 maxFrameRate); - + // Set Target Resolution: frame rate and dimension virtual WebRtc_Word32 SetTargetResolution(WebRtc_UWord32 width, WebRtc_UWord32 height, WebRtc_UWord32 frameRate); + // Get decimated values: frame rate/dimension virtual WebRtc_UWord32 DecimatedFrameRate(); virtual WebRtc_UWord32 DecimatedWidth() const; virtual WebRtc_UWord32 DecimatedHeight() const; - // Pre-process: - // Pre-process incoming frame: Sample when needed and compute content metrics - // when enable. + // Preprocess: + // Pre-process incoming frame: Sample when needed and compute content + // metrics when enabled. // If no resampling takes place - processedFrame is set to NULL. virtual WebRtc_Word32 PreprocessFrame(const VideoFrame* frame, VideoFrame** processedFrame); @@ -101,7 +99,7 @@ public: private: WebRtc_Word32 _id; CriticalSectionWrapper& _mutex; - + VPMDeflickering _deflickering; VPMDenoising _denoising; VPMBrightnessDetection _brightnessDetection;