int TranslateMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr) { VFrame *input, *output; input = input_ptr; output = output_ptr; load_configuration(); //printf("TranslateMain::process_realtime 1 %p\n", input); if(input->get_rows()[0] == output->get_rows()[0]) { if(!temp_frame) temp_frame = new VFrame(0, -1, input_ptr->get_w(), input_ptr->get_h(), input->get_color_model(), -1); temp_frame->copy_from(input); input = temp_frame; } //printf("TranslateMain::process_realtime 2 %p\n", input); if(!overlayer) { overlayer = new OverlayFrame(smp + 1); } output->clear_frame(); // printf("TranslateMain::process_realtime 3 output=%p input=%p config.w=%f config.h=%f" // "%f %f %f %f -> %f %f %f %f\n", output, input, config.w, config.h, // in_x1, in_y1, in_x2, in_y2, out_x1, out_y1, out_x2, out_y2); overlayer->overlay(output, input, config.in_x, config.in_y, config.in_x + config.in_w, config.in_y + config.in_h, config.out_x, config.out_y, config.out_x + config.out_w, config.out_y + config.out_h, 1, TRANSFER_REPLACE, get_interpolation_type()); return 0; }
int SvgMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr) { int fh_lockfile; char filename_png[1024], filename_lock[1024]; struct stat st_svg, st_png; int result_stat_png; VFrame *input, *output; input = input_ptr; output = output_ptr; need_reconfigure |= load_configuration(); if (config.svg_file[0] == 0) { output->copy_from(input); return(0); } strcpy(filename_png, config.svg_file); strcat(filename_png, ".png"); // get the time of the last PNG change result_stat_png = stat (filename_png, &st_png); // printf("PNg mtime: %li, last_load: %li\n", st_png.st_mtime, config.last_load); if (need_reconfigure || result_stat_png || (st_png.st_mtime > config.last_load)) { if (temp_frame) delete temp_frame; temp_frame = 0; } need_reconfigure = 0; if(!temp_frame) { int result; VFrame *tmp2; // printf("PROCESSING: %s %li\n", filename_png, config.last_load); if (result = stat (config.svg_file, &st_svg)) { printf(_("Error calling stat() on svg file: %s\n"), config.svg_file); } if (force_png_render || result_stat_png || st_png.st_mtime < st_svg.st_mtime) { char command[1024]; sprintf(command, "sodipodi --export-png=%s --export-width=%i --export-height=%i %s", filename_png, (int)config.in_w, (int)config.in_h, config.svg_file); printf(_("Running command %s\n"), command); system(command); stat(filename_png, &st_png); force_png_render = 0; } // advisory lock, so we wait for sodipodi to finish strcpy(filename_lock, filename_png); strcat(filename_lock, ".lock"); // printf("Cinelerra locking %s\n", filename_lock); fh_lockfile = open (filename_lock, O_CREAT | O_RDWR); int res = lockf(fh_lockfile, F_LOCK, 10); // Blocking call - will wait for sodipodi to finish! // printf("Cinelerra: filehandle: %i, cineres: %i, errno: %i\n", fh_lockfile, res, errno); // perror("Cineerror"); int fh = open(filename_png, O_RDONLY); unsigned char *pngdata; // get the size again result_stat_png = fstat (fh, &st_png); pngdata = (unsigned char*) malloc(st_png.st_size + 4); *((int32_t *)pngdata) = st_png.st_size; // printf("PNG size: %i\n", st_png.st_size); result = read(fh, pngdata+4, st_png.st_size); close(fh); // unlock the file lockf(fh_lockfile, F_ULOCK, 0); close(fh_lockfile); // printf("Cinelerra unlocking\n"); config.last_load = st_png.st_mtime; // we just updated tmp2 = new VFrame(pngdata); temp_frame = new VFrame(0, tmp2->get_w(), tmp2->get_h(), output_ptr->get_color_model()); free (pngdata); cmodel_transfer(temp_frame->get_rows(), tmp2->get_rows(), 0, 0, 0, 0, 0, 0, 0, 0, tmp2->get_w(), tmp2->get_h(), 0, 0, temp_frame->get_w(), temp_frame->get_h(), tmp2->get_color_model(), temp_frame->get_color_model(), 0, tmp2->get_w(), temp_frame->get_w()); delete tmp2; } //printf("SvgMain::process_realtime 2 %p\n", input); if(!overlayer) { overlayer = new OverlayFrame(smp + 1); } // output->clear_frame(); // printf("SvgMain::process_realtime 3 output=%p input=%p config.w=%f config.h=%f" // "%f %f %f %f -> %f %f %f %f\n", // output, // input, // config.w, // config.h, // in_x1, // in_y1, // in_x2, // in_y2, // out_x1, // out_y1, // out_x2, // out_y2); output->copy_from(input); overlayer->overlay(output, temp_frame, config.in_x, config.in_y, config.in_x + config.in_w, config.in_y + config.in_h, config.out_x, config.out_y, config.out_x + config.out_w, config.out_y + config.out_h, 1, TRANSFER_NORMAL, get_interpolation_type()); return(0); }
int PhotoScaleMain::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) { load_configuration(); if(config.use_file) { frame->get_params()->update("AUTOSCALE", 1); frame->get_params()->update("AUTOSCALE_W", config.width); frame->get_params()->update("AUTOSCALE_H", config.height); read_frame(frame, 0, start_position, frame_rate, get_use_opengl()); return 0; } else { frame->get_params()->update("AUTOSCALE", 0); } read_frame(frame, 0, start_position, frame_rate, 0); if(!engine) engine = new PhotoScaleEngine(this, PluginClient::get_project_smp() + 1); engine->process_packages(); // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // engine->top_border, // engine->bottom_border, // engine->left_border, // engine->right_border); int in_width = engine->right_border - engine->left_border; int in_height = engine->bottom_border - engine->top_border; if(in_width > 0 && in_height > 0 && (engine->top_border > 0 || engine->left_border > 0 || engine->bottom_border < frame->get_h() || engine->right_border < frame->get_w())) { VFrame *temp_frame = new_temp(frame->get_w(), frame->get_h(), frame->get_color_model()); temp_frame->copy_from(frame); if(!overlayer) { overlayer = new OverlayFrame(PluginClient::get_project_smp() + 1); } float scale1 = (float)config.width / in_width; float scale2 = (float)config.height / in_height; float out_x1 = 0; float out_y1 = 0; float out_x2 = 0; float out_y2 = 0; // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // engine->left_border, // engine->top_border, // engine->right_border, // engine->bottom_border); // printf("PhotoScaleMain::process_buffer %d %f %f\n", __LINE__, scale1, scale2); if(scale1 < scale2) { out_x1 = (float)frame->get_w() / 2 - config.width / 2; out_y1 = (float)frame->get_h() / 2 - in_height * scale1 / 2; out_x2 = (float)frame->get_w() / 2 + config.width / 2; out_y2 = (float)frame->get_h() / 2 + in_height * scale1 / 2; } else { out_x1 = (float)frame->get_w() / 2 - in_width * scale2 / 2; out_y1 = (float)frame->get_h() / 2 - config.height / 2; out_x2 = (float)frame->get_w() / 2 + in_width * scale2 / 2; out_y2 = (float)frame->get_h() / 2 + config.height / 2; } // printf("PhotoScaleMain::process_buffer %d %d %d %d %d\n", // __LINE__, // (int)out_x1, // (int)out_y1, // (int)out_x2, // (int)out_y2); frame->clear_frame(); overlayer->overlay(frame, temp_frame, (float)engine->left_border, (float)engine->top_border, (float)engine->right_border, (float)engine->bottom_border, (float)out_x1, (float)out_y1, (float)out_x2, (float)out_y2, 1, TRANSFER_REPLACE, get_interpolation_type()); } return 0; }