Home | History | Annotate | Download | only in source
      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 
     11 #include "webrtc/modules/video_processing/main/source/brighten.h"
     12 
     13 #include <stdlib.h>
     14 
     15 namespace webrtc {
     16 namespace VideoProcessing {
     17 
     18 int32_t Brighten(I420VideoFrame* frame, int delta) {
     19   assert(frame);
     20   if (frame->IsZeroSize()) {
     21     return VPM_PARAMETER_ERROR;
     22   }
     23   if (frame->width() <= 0 || frame->height() <= 0) {
     24     return VPM_PARAMETER_ERROR;
     25   }
     26 
     27   int num_pixels = frame->width() * frame->height();
     28 
     29   int look_up[256];
     30   for (int i = 0; i < 256; i++) {
     31     int val = i + delta;
     32     look_up[i] = ((((val < 0) ? 0 : val) > 255) ? 255 : val);
     33   }
     34 
     35   uint8_t* temp_ptr = frame->buffer(kYPlane);
     36 
     37   for (int i = 0; i < num_pixels; i++) {
     38     *temp_ptr = static_cast<uint8_t>(look_up[*temp_ptr]);
     39     temp_ptr++;
     40   }
     41   return VPM_OK;
     42 }
     43 
     44 }  // namespace VideoProcessing
     45 }  // namespace webrtc
     46