dynamic keyframes, textbox rework, andrea ffmpeg.opts, perpetual chkpt undo, lv2...
[goodguy/history.git] / cinelerra-5.1 / plugins / brightness / brightness.C
index 8acdd46b7067a3aae08bc97dfb55b83dfadc2040..19bcae30242659944d37b005a72a39d50f4bf882 100644 (file)
@@ -2,28 +2,30 @@
 /*
  * CINELERRA
  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
+ *
  */
 
-#include "clip.h"
-#include "filexml.h"
 #include "brightness.h"
+#include "bccolors.h"
 #include "bchash.h"
+#include "clip.h"
+#include "filexml.h"
 #include "language.h"
+#include "playback3d.h"
 
 #include <stdio.h>
 #include <stdint.h>
@@ -43,7 +45,7 @@ BrightnessConfig::BrightnessConfig()
 
 int BrightnessConfig::equivalent(BrightnessConfig &that)
 {
-       return (brightness == that.brightness && 
+       return (brightness == that.brightness &&
                contrast == that.contrast &&
                luma == that.luma);
 }
@@ -55,10 +57,10 @@ void BrightnessConfig::copy_from(BrightnessConfig &that)
        luma = that.luma;
 }
 
-void BrightnessConfig::interpolate(BrightnessConfig &prev, 
-       BrightnessConfig &next, 
-       int64_t prev_frame, 
-       int64_t next_frame, 
+void BrightnessConfig::interpolate(BrightnessConfig &prev,
+       BrightnessConfig &next,
+       int64_t prev_frame,
+       int64_t next_frame,
        int64_t current_frame)
 {
        double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
@@ -77,26 +79,24 @@ void BrightnessConfig::interpolate(BrightnessConfig &prev,
 
 
 
-YUV BrightnessMain::yuv;
-
 BrightnessMain::BrightnessMain(PluginServer *server)
  : PluginVClient(server)
 {
     redo_buffers = 1;
        engine = 0;
-       
+
 }
 
 BrightnessMain::~BrightnessMain()
 {
-       
+
        if(engine) delete engine;
 }
 
-const char* BrightnessMain::plugin_title() { return _("Brightness/Contrast"); }
+const char* BrightnessMain::plugin_title() { return N_("Brightness/Contrast"); }
 int BrightnessMain::is_realtime() { return 1; }
 
-NEW_WINDOW_MACRO(BrightnessMain, BrightnessWindow)     
+NEW_WINDOW_MACRO(BrightnessMain, BrightnessWindow)
 LOAD_CONFIGURATION_MACRO(BrightnessMain, BrightnessConfig)
 
 int BrightnessMain::process_buffer(VFrame *frame,
@@ -105,9 +105,9 @@ int BrightnessMain::process_buffer(VFrame *frame,
 {
        load_configuration();
 
-       read_frame(frame, 
-               0, 
-               start_position, 
+       read_frame(frame,
+               0,
+               start_position,
                frame_rate,
                get_use_opengl());
 
@@ -138,7 +138,7 @@ int BrightnessMain::process_buffer(VFrame *frame,
 int BrightnessMain::handle_opengl()
 {
 #ifdef HAVE_GL
-       static const char *brightness_yuvluma_frag = 
+       static const char *brightness_yuvluma_frag =
                "uniform sampler2D tex;\n"
                "uniform float brightness;\n"
                "uniform float contrast;\n"
@@ -151,7 +151,7 @@ int BrightnessMain::handle_opengl()
                "       gl_FragColor = yuva;\n"
                "}\n";
 
-       static const char *brightness_yuv_frag = 
+       static const char *brightness_yuv_frag =
                "uniform sampler2D tex;\n"
                "uniform float brightness;\n"
                "uniform float contrast;\n"
@@ -184,16 +184,11 @@ int BrightnessMain::handle_opengl()
                "uniform float brightness;\n"
                "uniform float contrast;\n"
                "uniform float offset;\n"
+               "uniform mat3 yuv_to_rgb_matrix;\n"
+               "uniform mat3 rgb_to_yuv_matrix;\n"
+
                "void main()\n"
                "{\n"
-               "       const mat3 yuv_to_rgb_matrix = mat3(\n"
-               "               1,       1,        1, \n"
-               "               0,       -0.34414, 1.77200, \n"
-               "               1.40200, -0.71414, 0);\n"
-               "       const mat3 rgb_to_yuv_matrix = mat3(\n"
-               "               0.29900, -0.16874, 0.50000, \n"
-               "               0.58700, -0.33126, -0.41869, \n"
-               "               0.11400, 0.50000,  -0.08131);\n"
                "       vec4 rgba = texture2D(tex, gl_TexCoord[0].st);\n"
                "       rgba.rgb = rgb_to_yuv_matrix * rgba.rgb;\n"
                "       rgba.r += brightness;\n"
@@ -204,51 +199,32 @@ int BrightnessMain::handle_opengl()
 
        get_output()->to_texture();
        get_output()->enable_opengl();
+       int need_matrix = 0;
+       const char *brightness_frag = BC_CModels::is_yuv(get_output()->get_color_model()) ?
+               (config.luma ? (need_matrix = 0, brightness_yuvluma_frag) : brightness_yuv_frag) :
+               (config.luma ? (need_matrix = 1, brightness_rgbluma_frag) : brightness_rgb_frag) ;
 
-       unsigned int shader_id = 0;
-       switch(get_output()->get_color_model())
-       {
-               case BC_YUV888:
-               case BC_YUVA8888:
-                       if(config.luma)
-                               shader_id = VFrame::make_shader(0,
-                                       brightness_yuvluma_frag,
-                                       0);
-                       else
-                               shader_id = VFrame::make_shader(0,
-                                       brightness_yuv_frag,
-                                       0);
-                       break;
-               default:
-                       if(config.luma)
-                               shader_id = VFrame::make_shader(0,
-                                       brightness_rgbluma_frag,
-                                       0);
-                       else
-                               shader_id = VFrame::make_shader(0,
-                                       brightness_rgb_frag,
-                                       0);
-                       break;
-       }
-
-
-       if(shader_id > 0) 
-       {
+       unsigned int shader_id = VFrame::make_shader(0, brightness_frag, 0);
+       if( shader_id > 0 ) {
                glUseProgram(shader_id);
                glUniform1i(glGetUniformLocation(shader_id, "tex"), 0);
                glUniform1f(glGetUniformLocation(shader_id, "brightness"), config.brightness / 100);
-               float contrast = (config.contrast < 0) ? 
-                       (config.contrast + 100) / 100 : 
+               float contrast = (config.contrast < 0) ?
+                       (config.contrast + 100) / 100 :
                        (config.contrast + 25) / 25;
                glUniform1f(glGetUniformLocation(shader_id, "contrast"), contrast);
                float offset = 0.5 - contrast / 2;
                glUniform1f(glGetUniformLocation(shader_id, "offset"), offset);
+               if( need_matrix ) {
+                       BC_GL_MATRIX(shader_id, yuv_to_rgb_matrix);
+                       BC_GL_MATRIX(shader_id, rgb_to_yuv_matrix);
+               }
        }
 
        get_output()->init_screen();
        get_output()->bind_texture(0);
 
-       
+
 
        get_output()->draw_texture();
        glUseProgram(0);
@@ -274,13 +250,13 @@ void BrightnessMain::update_gui()
        }
 }
 
+
 void BrightnessMain::save_data(KeyFrame *keyframe)
 {
        FileXML output;
 
 // cause data to be stored directly in text
-       output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
+       output.set_shared_output(keyframe->xbuf);
        output.tag.set_title("BRIGHTNESS");
        output.tag.set_property("BRIGHTNESS", config.brightness);
        output.tag.set_property("CONTRAST",  config.contrast);
@@ -296,7 +272,7 @@ void BrightnessMain::read_data(KeyFrame *keyframe)
 {
        FileXML input;
 
-       input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
+       input.set_shared_input(keyframe->xbuf);
 
        int result = 0;
 
@@ -345,7 +321,7 @@ BrightnessUnit::BrightnessUnit(BrightnessEngine *server, BrightnessMain *plugin)
 BrightnessUnit::~BrightnessUnit()
 {
 }
-       
+
 void BrightnessUnit::process_package(LoadPackage *package)
 {
        BrightnessPackage *pkg = (BrightnessPackage*)package;
@@ -353,7 +329,7 @@ void BrightnessUnit::process_package(LoadPackage *package)
 
        VFrame *output = plugin->output;
        VFrame *input = plugin->input;
-       
+
 
 
 
@@ -447,7 +423,7 @@ void BrightnessUnit::process_package(LoadPackage *package)
                                                b = input_row[j * components + 2]; \
                                                if(max == 0xff) \
                                                { \
-                                                       BrightnessMain::yuv.rgb_to_yuv_8( \
+                                                       YUV::yuv.rgb_to_yuv_8( \
                                                                r,  \
                                                                g,  \
                                                                b,  \
@@ -457,7 +433,7 @@ void BrightnessUnit::process_package(LoadPackage *package)
                                                } \
                                                else \
                                                { \
-                                                       BrightnessMain::yuv.rgb_to_yuv_16( \
+                                                       YUV::yuv.rgb_to_yuv_16( \
                                                                r,  \
                                                                g,  \
                                                                b,  \
@@ -482,7 +458,7 @@ void BrightnessUnit::process_package(LoadPackage *package)
                                        { \
                                                if(max == 0xff) \
                                                { \
-                                                       BrightnessMain::yuv.yuv_to_rgb_8( \
+                                                       YUV::yuv.yuv_to_rgb_8( \
                                                                r,  \
                                                                g,  \
                                                                b,  \
@@ -492,7 +468,7 @@ void BrightnessUnit::process_package(LoadPackage *package)
                                                } \
                                                else \
                                                { \
-                                                       BrightnessMain::yuv.yuv_to_rgb_16( \
+                                                       YUV::yuv.yuv_to_rgb_16( \
                                                                r,  \
                                                                g,  \
                                                                b,  \
@@ -597,24 +573,9 @@ void BrightnessUnit::process_package(LoadPackage *package)
                                        r = input_row[j * components]; \
                                        g = input_row[j * components + 1]; \
                                        b = input_row[j * components + 2]; \
-                                       YUV::rgb_to_yuv_f( \
-                                               r,  \
-                                               g,  \
-                                               b,  \
-                                               y,  \
-                                               u,  \
-                                               v); \
- \
+                                       YUV::yuv.rgb_to_yuv_f(r, g, b, y, u, v); \
                                        y = y * contrast + offset; \
- \
- \
-                                       YUV::yuv_to_rgb_f( \
-                                               r,  \
-                                               g,  \
-                                               b,  \
-                                               y,  \
-                                               u,  \
-                                               v); \
+                                       YUV::yuv.yuv_to_rgb_f(r, g, b, y, u, v); \
                                        input_row[j * components] = r; \
                                        input_row[j * components + 1] = g; \
                                        input_row[j * components + 2] = b; \