henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 6f3d8fc | 2013-05-27 14:12:16 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/video_processing/main/source/brighten.h" |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 14 | |
pbos@webrtc.org | 6f3d8fc | 2013-05-27 14:12:16 +0000 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/interface/trace.h" |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
henrik.lundin@webrtc.org | 219acc6 | 2011-12-20 15:33:49 +0000 | [diff] [blame] | 18 | namespace VideoProcessing { |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 19 | |
pbos@webrtc.org | 1ab45f6 | 2013-04-09 13:38:10 +0000 | [diff] [blame] | 20 | int32_t Brighten(I420VideoFrame* frame, int delta) { |
mikhal@webrtc.org | 0e196e1 | 2012-10-19 15:43:31 +0000 | [diff] [blame] | 21 | assert(frame); |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 22 | if (frame->IsZeroSize()) { |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 23 | WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1, |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 24 | "zero size frame"); |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 25 | return VPM_PARAMETER_ERROR; |
| 26 | } |
| 27 | |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 28 | if (frame->width() <= 0 || frame->height() <= 0) { |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 29 | WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoPreocessing, -1, |
| 30 | "Invalid frame size"); |
| 31 | return VPM_PARAMETER_ERROR; |
| 32 | } |
| 33 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame^] | 34 | int num_pixels = frame->width() * frame->height(); |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 35 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame^] | 36 | int look_up[256]; |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 37 | for (int i = 0; i < 256; i++) { |
| 38 | int val = i + delta; |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame^] | 39 | look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val); |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 40 | } |
| 41 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame^] | 42 | uint8_t* temp_ptr = frame->buffer(kYPlane); |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 43 | |
mikhal@webrtc.org | b43d807 | 2013-10-03 16:42:41 +0000 | [diff] [blame^] | 44 | for (int i = 0; i < num_pixels; i++) { |
| 45 | *temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]); |
| 46 | temp_ptr++; |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 47 | } |
| 48 | return VPM_OK; |
| 49 | } |
| 50 | |
henrik.lundin@webrtc.org | 219acc6 | 2011-12-20 15:33:49 +0000 | [diff] [blame] | 51 | } // namespace VideoProcessing |
henrik.lundin@webrtc.org | 33df533 | 2011-11-14 15:30:26 +0000 | [diff] [blame] | 52 | } // namespace webrtc |