blob: 4c356e2176b41b22afa0d429432c954da7f07d8b [file] [log] [blame]
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "modules/video_processing/main/source/brighten.h"
12
13#include <cstdlib>
14
15#include "system_wrappers/interface/trace.h"
16
17namespace webrtc {
henrik.lundin@webrtc.org219acc62011-12-20 15:33:49 +000018namespace VideoProcessing {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000019
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000020WebRtc_Word32 Brighten(I420VideoFrame* frame, int delta) {
mikhal@webrtc.org0e196e12012-10-19 15:43:31 +000021 assert(frame);
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000022 if (frame->IsZeroSize()) {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000023 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1,
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000024 "zero size frame");
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000025 return VPM_PARAMETER_ERROR;
26 }
27
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000028 if (frame->width() <= 0 || frame->height() <= 0) {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000029 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1,
30 "Invalid frame size");
31 return VPM_PARAMETER_ERROR;
32 }
33
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000034 int numPixels = frame->width() * frame->height();
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000035
36 int lookUp[256];
37 for (int i = 0; i < 256; i++) {
38 int val = i + delta;
39 lookUp[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val);
40 }
41
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000042 WebRtc_UWord8* tempPtr = frame->buffer(kYPlane);
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000043
44 for (int i = 0; i < numPixels; i++) {
45 *tempPtr = static_cast<WebRtc_UWord8>(lookUp[*tempPtr]);
46 tempPtr++;
47 }
48 return VPM_OK;
49}
50
henrik.lundin@webrtc.org219acc62011-12-20 15:33:49 +000051} // namespace VideoProcessing
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000052} // namespace webrtc