2011-11-14 15:30:26 +00:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-27 14:12:16 +00:00
|
|
|
#include "webrtc/modules/video_processing/main/source/brighten.h"
|
2011-11-14 15:30:26 +00:00
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <stdlib.h>
|
2011-11-14 15:30:26 +00:00
|
|
|
|
2013-05-27 14:12:16 +00:00
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
2011-11-14 15:30:26 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2011-12-20 15:33:49 +00:00
|
|
|
namespace VideoProcessing {
|
2011-11-14 15:30:26 +00:00
|
|
|
|
2013-04-09 13:38:10 +00:00
|
|
|
int32_t Brighten(I420VideoFrame* frame, int delta) {
|
2012-10-19 15:43:31 +00:00
|
|
|
assert(frame);
|
2012-10-24 18:33:04 +00:00
|
|
|
if (frame->IsZeroSize()) {
|
2011-11-14 15:30:26 +00:00
|
|
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1,
|
2012-10-24 18:33:04 +00:00
|
|
|
"zero size frame");
|
2011-11-14 15:30:26 +00:00
|
|
|
return VPM_PARAMETER_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
if (frame->width() <= 0 || frame->height() <= 0) {
|
2011-11-14 15:30:26 +00:00
|
|
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1,
|
|
|
|
|
"Invalid frame size");
|
|
|
|
|
return VPM_PARAMETER_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int num_pixels = frame->width() * frame->height();
|
2011-11-14 15:30:26 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
int look_up[256];
|
2011-11-14 15:30:26 +00:00
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
|
int val = i + delta;
|
2013-10-03 16:42:41 +00:00
|
|
|
look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val);
|
2011-11-14 15:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
uint8_t* temp_ptr = frame->buffer(kYPlane);
|
2011-11-14 15:30:26 +00:00
|
|
|
|
2013-10-03 16:42:41 +00:00
|
|
|
for (int i = 0; i < num_pixels; i++) {
|
|
|
|
|
*temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]);
|
|
|
|
|
temp_ptr++;
|
2011-11-14 15:30:26 +00:00
|
|
|
}
|
|
|
|
|
return VPM_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 15:33:49 +00:00
|
|
|
} // namespace VideoProcessing
|
2011-11-14 15:30:26 +00:00
|
|
|
} // namespace webrtc
|