/** * Saves a GdkPixbuf image to the current clip. * * Needed, because the image might come from the last grabbed * frame, or the recording of every frame might be automatic. (video) * * The gdkpixbufsink element posts messages containing the pixbuf. */ void Pipeline::save_image_to_current_clip(GdkPixbuf *pixbuf) { Clip *thisclip = owner_->get_current_clip(); bool is_verbose = owner_->get_configuration()->get_verbose(); int current_clip_id = thisclip->get_id(); int w = gdk_pixbuf_get_width(pixbuf); int h = gdk_pixbuf_get_height(pixbuf); /* if this is the first frame grabbed, set frame properties in clip */ // TODO:2010-08-27:aalex:Use image size, not clip size. // A clip may contain images that are not the same size. if (! thisclip->get_has_recorded_frame()) { // TODO: each image should be a different size, if that's what it is. thisclip->set_width(w); thisclip->set_height(h); thisclip->set_has_recorded_frame(); } int new_image_number = thisclip->frame_add(); Image *new_image = thisclip->get_image(new_image_number); if (new_image == 0) { // This is very unlikely to happen std::cerr << "No image at " << new_image_number << std::endl; g_object_unref(pixbuf); return; } if (is_verbose) std::cout << "Grab a frame. Current clip: " << current_clip_id << ". Image number: " << new_image_number << std::endl; std::string file_name = thisclip->get_image_full_path(new_image); // We need 3 textures: // * the onionskin of the last frame grabbed. (or at the writehead position) // * the frame at the playhead position // * the current live input. (GST gives us this one) if (!gdk_pixbuf_save(pixbuf, file_name.c_str(), "jpeg", NULL, "quality", "100", NULL)) { g_print("Image %s could not be saved. Error\n", file_name.c_str()); } else { if (is_verbose) g_print("Image %s saved\n", file_name.c_str()); owner_->get_controller()->add_frame_signal_(current_clip_id, new_image_number); thisclip->remove_first_if_more_than(owner_->get_configuration()->get_max_images_per_clip()); } }
bool Pipeline::import_image(const std::string &file_name) { bool is_verbose = owner_->get_configuration()->get_verbose(); if (! toonloop::file_exists(file_name)) { if (is_verbose) std::cout << __FUNCTION__ << ": " << std::endl; return false; } Clip *clip = owner_->get_current_clip(); int clip_id = clip->get_id(); // TODO: set clip size if not set. int new_image_number = clip->frame_add(); Image *new_image = clip->get_image(new_image_number); if (new_image == 0) { // This is very unlikely to happen std::cerr << __FUNCTION__ << ": No image at " << new_image_number << std::endl; return false; } if (is_verbose) std::cout << "Import an image. Current clip: " << clip_id << ". Image number: " << new_image_number << std::endl; std::string save_as_file_name = clip->get_image_full_path(new_image); unsigned int width = (unsigned int) owner_->get_configuration()->get_capture_width(); unsigned int height = (unsigned int) owner_->get_configuration()->get_capture_height(); ImageImporter img(file_name, save_as_file_name, width, height, is_verbose); bool ok = img.resize(); if (! ok) return false; if (is_verbose) g_print("Image %s saved\n", save_as_file_name.c_str()); owner_->get_controller()->add_frame_signal_(clip_id, new_image_number); clip->remove_first_if_more_than(owner_->get_configuration()->get_max_images_per_clip()); return true; }