blob: 907a549064a31316be599646071a8ba7cb282391 [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
pbos@webrtc.org6f3d8fc2013-05-27 14:12:16 +000011#include "webrtc/modules/video_processing/main/source/brighten.h"
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000012
pbos@webrtc.org12dc1a32013-08-05 16:22:53 +000013#include <stdlib.h>
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000014
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000015namespace webrtc {
henrik.lundin@webrtc.org219acc62011-12-20 15:33:49 +000016namespace VideoProcessing {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000017
pbos@webrtc.org1ab45f62013-04-09 13:38:10 +000018int32_t Brighten(I420VideoFrame* frame, int delta) {
mikhal@webrtc.org0e196e12012-10-19 15:43:31 +000019 assert(frame);
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000020 if (frame->IsZeroSize()) {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000021 return VPM_PARAMETER_ERROR;
22 }
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +000023 if (frame->width() <= 0 || frame->height() <= 0) {
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000024 return VPM_PARAMETER_ERROR;
25 }
26
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000027 int num_pixels = frame->width() * frame->height();
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000028
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000029 int look_up[256];
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000030 for (int i = 0; i < 256; i++) {
31 int val = i + delta;
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000032 look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val);
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000033 }
34
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000035 uint8_t* temp_ptr = frame->buffer(kYPlane);
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000036
mikhal@webrtc.orgb43d8072013-10-03 16:42:41 +000037 for (int i = 0; i < num_pixels; i++) {
38 *temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]);
39 temp_ptr++;
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000040 }
41 return VPM_OK;
42}
43
henrik.lundin@webrtc.org219acc62011-12-20 15:33:49 +000044} // namespace VideoProcessing
henrik.lundin@webrtc.org33df5332011-11-14 15:30:26 +000045} // namespace webrtc