| 
    OpenShot Library | libopenshot
    0.4.0
    
   | 
 
 
 
 
Go to the documentation of this file.
   21     init_effect_details();
 
   28     init_effect_details();
 
   32 void Brightness::init_effect_details()
 
   40     info.
description = 
"Adjust the brightness and contrast of the frame's image.";
 
   47 std::shared_ptr<openshot::Frame> 
Brightness::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
 
   50     std::shared_ptr<QImage> frame_image = frame->GetImage();
 
   57     unsigned char *pixels = (
unsigned char *) frame_image->bits();
 
   58     int pixel_count = frame_image->width() * frame_image->height();
 
   60     #pragma omp parallel for 
   61     for (
int pixel = 0; pixel < pixel_count; ++pixel)
 
   64         float factor = (259 * (contrast_value + 255)) / (255 * (259 - contrast_value));
 
   67         int A = pixels[pixel * 4 + 3];
 
   68         float alpha_percent = A / 255.0;
 
   71         unsigned char R = pixels[pixel * 4 + 0] / alpha_percent;
 
   72         unsigned char G = pixels[pixel * 4 + 1] / alpha_percent;
 
   73         unsigned char B = pixels[pixel * 4 + 2] / alpha_percent;
 
   76         R = 
constrain((factor * (R - 128)) + 128);
 
   77         G = 
constrain((factor * (G - 128)) + 128);
 
   78         B = 
constrain((factor * (B - 128)) + 128);
 
   81         pixels[pixel * 4 + 0] = 
constrain(R + (255 * brightness_value));
 
   82         pixels[pixel * 4 + 1] = 
constrain(G + (255 * brightness_value));
 
   83         pixels[pixel * 4 + 2] = 
constrain(B + (255 * brightness_value));
 
   86         pixels[pixel * 4 + 0] *= alpha_percent;
 
   87         pixels[pixel * 4 + 1] *= alpha_percent;
 
   88         pixels[pixel * 4 + 2] *= alpha_percent;
 
  125     catch (
const std::exception& e)
 
  128         throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
 
  139     if (!root[
"brightness"].isNull())
 
  141     if (!root[
"contrast"].isNull())
 
  156     return root.toStyledString();
 
  
std::string PropertiesJSON(int64_t requested_frame) const override
 
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
 
const Json::Value stringToJson(const std::string value)
 
EffectInfoStruct info
Information about the current effect.
 
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
 
This namespace is the default namespace for all code in the openshot library.
 
std::string Json() const override
Generate JSON string of this object.
 
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
 
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
 
Keyframe brightness
Brightness keyframe. A constant value here will prevent animation.
 
Json::Value JsonValue() const
Generate Json::Value for this object.
 
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
 
Header file for Brightness class.
 
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
 
Exception for invalid JSON.
 
Json::Value JsonValue() const override
Generate Json::Value for this object.
 
bool has_audio
Determines if this effect manipulates the audio of a frame.
 
std::string class_name
The class name of the effect.
 
std::string description
The description of this effect and what it does.
 
void SetJson(const std::string value) override
Load JSON string into this object.
 
bool has_video
Determines if this effect manipulates the image of a frame.
 
Brightness()
Blank constructor, useful when using Json to load the effect properties.
 
int constrain(int color_value)
Constrain a color value from 0 to 255.
 
std::string name
The name of the effect.
 
Keyframe contrast
Contrast keyframe.
 
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
 
Header file for all Exception classes.
 
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
 
double GetValue(int64_t index) const
Get the value at a specific index.