/*
* 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
- *
+ *
*/
#ifndef DIFFKEY_H
#define DIFFKEY_H
+#include "bccolors.h"
#include "bcdisplayinfo.h"
#include "clip.h"
#include "bchash.h"
#include "guicast.h"
#include "language.h"
#include "loadbalance.h"
-#include "cicolors.h"
+#include "bccolors.h"
#include "pluginvclient.h"
-
+#include "playback3d.h"
#include <string.h>
DiffKeyConfig();
void copy_from(DiffKeyConfig &src);
int equivalent(DiffKeyConfig &src);
- void interpolate(DiffKeyConfig &prev,
- DiffKeyConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+ void interpolate(DiffKeyConfig &prev,
+ DiffKeyConfig &next,
+ int64_t prev_frame,
+ int64_t next_frame,
int64_t current_frame);
float threshold;
do_value == src.do_value;
}
-void DiffKeyConfig::interpolate(DiffKeyConfig &prev,
- DiffKeyConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+void DiffKeyConfig::interpolate(DiffKeyConfig &prev,
+ DiffKeyConfig &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);
DiffKey::DiffKey(PluginServer *server)
: PluginVClient(server)
{
-
+
engine = 0;
}
DiffKey::~DiffKey()
{
-
+
delete engine;
}
load_configuration();
// Don't process if only 1 layer.
- if(get_total_buffers() < 2)
+ if(get_total_buffers() < 2)
{
- read_frame(frame[0],
- 0,
- start_position,
+ read_frame(frame[0],
+ 0,
+ start_position,
frame_rate,
get_use_opengl());
return 0;
}
// Read frames from 2 layers
- read_frame(frame[0],
- 0,
- start_position,
+ read_frame(frame[0],
+ 0,
+ start_position,
frame_rate,
get_use_opengl());
- read_frame(frame[1],
- 1,
- start_position,
+ read_frame(frame[1],
+ 1,
+ start_position,
frame_rate,
get_use_opengl());
int DiffKey::handle_opengl()
{
#ifdef HAVE_GL
- static const char *diffkey_head =
+ static const char *diffkey_head =
"uniform sampler2D tex_bg;\n"
"uniform sampler2D tex_fg;\n"
"uniform float threshold;\n"
" vec4 foreground = texture2D(tex_fg, gl_TexCoord[0].st);\n"
" vec4 background = texture2D(tex_bg, gl_TexCoord[0].st);\n";
- static const char *colorcube =
+ static const char *colorcube =
" float difference = length(foreground.rgb - background.rgb);\n";
- static const char *yuv_value =
+ static const char *yuv_value =
" float difference = abs(foreground.r - background.r);\n";
- static const char *rgb_value =
- " float difference = abs(dot(foreground.rgb, vec3(0.29900, 0.58700, 0.11400)) - \n"
- " dot(background.rgb, vec3(0.29900, 0.58700, 0.11400)));\n";
+ static const char *rgb_value =
+ " float difference = abs("
+ " dot(foreground.rgb, rgb_to_y_vector) - "
+ " dot(background.rgb, rgb_to_y_vector));\n";
- static const char *diffkey_tail =
+ static const char *diffkey_tail =
" vec4 result;\n"
" if(difference < threshold)\n"
" result.a = 0.0;\n"
" gl_FragColor = result;\n"
"}\n";
-
-
-
-
- top_frame->enable_opengl();
- top_frame->init_screen();
-
top_frame->to_texture();
bottom_frame->to_texture();
top_frame->enable_opengl();
top_frame->init_screen();
- unsigned int shader_id = 0;
- if(config.do_value)
- {
- if(BC_CModels::is_yuv(top_frame->get_color_model()))
- shader_id = VFrame::make_shader(0,
- diffkey_head,
- yuv_value,
- diffkey_tail,
- 0);
- else
- shader_id = VFrame::make_shader(0,
- diffkey_head,
- rgb_value,
- diffkey_tail,
- 0);
- }
- else
- {
- shader_id = VFrame::make_shader(0,
- diffkey_head,
- colorcube,
- diffkey_tail,
- 0);
- }
-
-
-
+ const char *shader_stack[16];
+ memset(shader_stack,0, sizeof(shader_stack));
+ int current_shader = 0;
+
+ int need_rgb_to_y = 0;
+ const char *shader_frag = !config.do_value ? colorcube :
+ BC_CModels::is_yuv(top_frame->get_color_model()) ?
+ yuv_value : (need_rgb_to_y = 1, rgb_value);
+ if( need_rgb_to_y )
+ shader_stack[current_shader++] = bc_gl_rgb_to_y;
+ shader_stack[current_shader++] = diffkey_head;
+ shader_stack[current_shader++] = shader_frag;
+ shader_stack[current_shader++] = diffkey_tail;
+
+ shader_stack[current_shader] = 0;
+ unsigned int shader = VFrame::make_shader(shader_stack);
DIFFKEY_VARS(this)
bottom_frame->bind_texture(1);
top_frame->bind_texture(0);
- if(shader_id > 0)
- {
- glUseProgram(shader_id);
- glUniform1i(glGetUniformLocation(shader_id, "tex_fg"), 0);
- glUniform1i(glGetUniformLocation(shader_id, "tex_bg"), 1);
- glUniform1f(glGetUniformLocation(shader_id, "threshold"), threshold);
- glUniform1f(glGetUniformLocation(shader_id, "pad"), pad);
- glUniform1f(glGetUniformLocation(shader_id, "threshold_pad"), threshold_pad);
+ if( shader > 0 ) {
+ glUseProgram(shader);
+ glUniform1i(glGetUniformLocation(shader, "tex_fg"), 0);
+ glUniform1i(glGetUniformLocation(shader, "tex_bg"), 1);
+ glUniform1f(glGetUniformLocation(shader, "threshold"), threshold);
+ glUniform1f(glGetUniformLocation(shader, "pad"), pad);
+ glUniform1f(glGetUniformLocation(shader, "threshold_pad"), threshold_pad);
+ if( need_rgb_to_y )
+ BC_GL_MATRIX(shader, rgb_to_y_vector);
}
if(BC_CModels::components(get_output()->get_color_model()) == 3)
top_frame->draw_texture();
glUseProgram(0);
top_frame->set_opengl_state(VFrame::SCREEN);
-// Fastest way to discard output
- bottom_frame->set_opengl_state(VFrame::TEXTURE);
glDisable(GL_BLEND);
+// Fastest way to discard output
+ bottom_frame->set_opengl_state(VFrame::UNKNOWN);
-
+// kludge ahead
+ top_frame->screen_to_ram();
#endif
return 0;
}
-DiffKeyEngine::DiffKeyEngine(DiffKey *plugin)
+DiffKeyEngine::DiffKeyEngine(DiffKey *plugin)
: LoadServer(plugin->get_project_smp() + 1, plugin->get_project_smp() + 1)
{
this->plugin = plugin;
{
DiffKeyPackage *pkg = (DiffKeyPackage*)get_package(i);
pkg->row1 = y;
- pkg->row2 = MIN(y + increment, plugin->top_frame->get_h());
+ pkg->row2 = MIN(y + increment, plugin->top_frame->get_h());
y += increment;
}
}
DiffKey *plugin = engine->plugin;
int w = plugin->top_frame->get_w();
-#define RGB_TO_VALUE(r, g, b) \
-((r) * R_TO_Y + (g) * G_TO_Y + (b) * B_TO_Y)
+#define RGB_TO_VALUE(r, g, b) YUV::yuv.rgb_to_y_f((r),(g),(b))
#define DIFFKEY_MACRO(type, components, max, chroma_offset) \