upgrade to ffmpeg 4.2, rework mask for speedup
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginclient.C
index 606f83d95af6ce007aa7d685d5a6fbb730761af3..726bd00f57b254b40cb964a393395ea0bb7a25c3 100644 (file)
 #include "track.h"
 #include "transportque.inc"
 
-
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <string.h>
 #include <ctype.h>
 #include <errno.h>
-#include <string.h>
-
-
-
 
 
 PluginClientThread::PluginClientThread(PluginClient *client)
@@ -551,38 +551,38 @@ void PluginClient::load_defaults_xml()
        using_defaults = 1;
 //printf("PluginClient::load_defaults_xml %d %s\n", __LINE__, path);
 
-       KeyFrame temp_keyframe;
-       FILE *fp = fopen(path, "r");
-       if( fp ) {
-               struct stat st;  int fd = fileno(fp);
-               int64_t sz = !fstat(fd, &st) ? st.st_size : BCTEXTLEN;
-               char *data = temp_keyframe.get_data(sz+1);
-               int data_size = fread(data, 1, sz, fp);
-               if( data_size < 0 ) data_size = 0;
-               if( data_size > 0 ) {
-                       data[data_size] = 0;
-                       temp_keyframe.xbuf->oseek(data_size);
+       char *data = 0;
+       int64_t len = -1;
+       struct stat st;
+       int fd = open(path, O_RDONLY);
+       if( fd >= 0 && !fstat(fd, &st) ) {
+               int64_t sz = st.st_size;
+               data = new char[sz+1];
+               len = read(fd, data, sz);
+               close(fd);
+       }
+       if( data && len >= 0 ) {
+               data[len] = 0;
 // Get window extents
-                       int i = 0;
-                       for( int state=0; i<(data_size-8) && state>=0; ++i ) {
-                               if( !data[i] || data[i] == '<' ) break;
-                               if( !isdigit(data[i]) ) continue;
-                               if( !state ) {
-                                       window_x = atoi(data + i);
-                                       state = 1;
-                               }
-                               else {
-                                       window_y = atoi(data + i);
-                                       state = -1;
-                               }
-                               while( i<data_size && isdigit(data[i]) ) ++i;
+               int i = 0;
+               for( int state=0; i<len && state>=0; ++i ) {
+                       if( !data[i] || data[i] == '<' ) break;
+                       if( !isdigit(data[i]) ) continue;
+                       if( !state ) {
+                               window_x = atoi(data+i);
+                               state = 1;
                        }
-                       temp_keyframe.xbuf->iseek(i);
-                       read_data(&temp_keyframe);
+                       else {
+                               window_y = atoi(data+i);
+                               state = -1;
+                       }
+                       while( i<len && isdigit(data[i]) ) ++i;
                }
-
-               fclose(fp);
+               KeyFrame keyframe(data+i, len-i);
+               read_data(&keyframe);
        }
+       delete [] data;
+
        using_defaults = 0;
 //printf("PluginClient::load_defaults_xml %d %s\n", __LINE__, path);
 }
@@ -688,6 +688,7 @@ double PluginClient::get_project_framerate()
 
 const char *PluginClient::get_source_path()
 {
+       if( server->plugin ) return 0;
        int64_t source_position = server->plugin->startproject;
        Edit *edit = server->plugin->track->edits->editof(source_position,PLAY_FORWARD,0);
        Indexable *indexable = edit ? edit->get_source() : 0;
@@ -733,24 +734,24 @@ int PluginClient::get_interpolation_type()
 
 float PluginClient::get_red()
 {
-       EDL *edl = server->mwindow ? server->mwindow->edl : server->edl;
-       return !edl ? 0 : edl->local_session->use_max ?
+       EDL *edl = get_edl();
+       return edl->local_session->use_max ?
                edl->local_session->red_max :
                edl->local_session->red;
 }
 
 float PluginClient::get_green()
 {
-       EDL *edl = server->mwindow ? server->mwindow->edl : server->edl;
-       return !edl ? 0 : edl->local_session->use_max ?
+       EDL *edl = get_edl();
+       return edl->local_session->use_max ?
                edl->local_session->green_max :
                edl->local_session->green;
 }
 
 float PluginClient::get_blue()
 {
-       EDL *edl = server->mwindow ? server->mwindow->edl : server->edl;
-       return !edl ? 0 : edl->local_session->use_max ?
+       EDL *edl = get_edl();
+       return edl->local_session->use_max ?
                edl->local_session->blue_max :
                edl->local_session->blue;
 }
@@ -864,14 +865,44 @@ void PluginClient::get_projector(float *x, float *y, float *z, int64_t position)
 }
 
 
-EDLSession* PluginClient::get_edlsession()
+void PluginClient::output_to_track(float ox, float oy, float &tx, float &ty)
 {
-       if(server->edl)
-               return server->edl->session;
-       return 0;
+       float projector_x, projector_y, projector_z;
+       int64_t position = get_source_position();
+       get_projector(&projector_x, &projector_y, &projector_z, position);
+       EDL *edl = get_edl();
+       projector_x += edl->session->output_w / 2;
+       projector_y += edl->session->output_h / 2;
+       Track *track = server->plugin ? server->plugin->track : 0;
+       int track_w = track ? track->track_w : edl->session->output_w;
+       int track_h = track ? track->track_h : edl->session->output_h;
+       tx = (ox - projector_x) / projector_z + track_w / 2;
+       ty = (oy - projector_y) / projector_z + track_h / 2;
+}
+
+void PluginClient::track_to_output(float tx, float ty, float &ox, float &oy)
+{
+       float projector_x, projector_y, projector_z;
+       int64_t position = get_source_position();
+       get_projector(&projector_x, &projector_y, &projector_z, position);
+       EDL *edl = get_edl();
+       projector_x += edl->session->output_w / 2;
+       projector_y += edl->session->output_h / 2;
+       Track *track = server->plugin ? server->plugin->track : 0;
+       int track_w = track ? track->track_w : edl->session->output_w;
+       int track_h = track ? track->track_h : edl->session->output_h;
+       ox = (tx - track_w / 2) * projector_z + projector_x;
+       oy = (ty - track_h / 2) * projector_z + projector_y;
+}
+
+
+EDL *PluginClient::get_edl()
+{
+       return server->mwindow ? server->mwindow->edl : server->edl;
 }
 
 int PluginClient::gui_open()
 {
        return server->gui_open();
 }
+