Change luminance of all pixels by a specified value.

Modeled on color_enhancement.

BUG=
TEST=

Review URL: http://webrtc-codereview.appspot.com/269004
Patch from SriRam <tvnsriram@google.com>.

git-svn-id: http://webrtc.googlecode.com/svn/trunk@941 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org 2011-11-14 15:30:26 +00:00
parent 7de07652ad
commit 33df5335bf
6 changed files with 126 additions and 14 deletions

View File

@ -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

View File

@ -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 <cstdlib>
#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<WebRtc_UWord8>(lookUp[*tempPtr]);
tempPtr++;
}
return VPM_OK;
}
} // namespace webrtc

View File

@ -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_

View File

@ -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',

View File

@ -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)

View File

@ -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;