static GimpPDBStatusType save_image (const gchar *uri, gint32 image_ID, gint32 drawable_ID, gint32 run_mode, GError **error) { GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; gchar *tmpname; tmpname = get_temp_name (uri, NULL); if (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname) && valid_file (tmpname)) { if (uri_backend_save_image (uri, tmpname, run_mode, error)) { status = GIMP_PDB_SUCCESS; } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s", gimp_get_pdb_error ()); } g_unlink (tmpname); g_free (tmpname); return status; }
static gboolean image_save(format_type type, image_output imageout, format_params params) { gboolean result; if (type == FORMAT_BMP) { result = image_save_bmp(imageout); } else if(type == FORMAT_GIF) { result = image_save_gif(imageout, ((format_params_gif)params)->interlace); } else if(type == FORMAT_ICON) { result = image_save_icon(imageout); } else if(type == FORMAT_JPEG) { result = image_save_jpeg( imageout, ((format_params_jpeg)params)->quality, ((format_params_jpeg)params)->smoothing, ((format_params_jpeg)params)->entropy, ((format_params_jpeg)params)->progressive, ((format_params_jpeg)params)->comment, ((format_params_jpeg)params)->subsampling, ((format_params_jpeg)params)->baseline, ((format_params_jpeg)params)->markers, ((format_params_jpeg)params)->dct ); } else if(type == FORMAT_PNG) { result = image_save_png(imageout, ((format_params_png)params)->interlace, ((format_params_png)params)->compression, ((format_params_png)params)->savebgc, ((format_params_png)params)->savegamma, ((format_params_png)params)->saveoff, ((format_params_png)params)->savephys, ((format_params_png)params)->savetime, ((format_params_png)params)->savecomm, ((format_params_png)params)->savetrans ); } else if(type == FORMAT_TGA) { result = image_save_tga(imageout, ((format_params_tga)params)->rle, ((format_params_tga)params)->origin); } else if(type == FORMAT_TIFF) { result = image_save_tiff(imageout, ((format_params_tiff)params)->compression); } else { result = gimp_file_save( GIMP_RUN_NONINTERACTIVE, imageout->image_id, imageout->drawable_id, imageout->filepath, imageout->filename ); } return result; }
static GimpPDBStatusType save_image (const gchar *uri, gint32 image_ID, gint32 drawable_ID, gint32 run_mode, GError **error) { GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; gchar *tmpname; gboolean mapped = FALSE; tmpname = uri_backend_map_image (uri, run_mode); if (tmpname) mapped = TRUE; else tmpname = get_temp_name (uri, NULL); if (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname)) { if (mapped) { status = GIMP_PDB_SUCCESS; } else if (valid_file (tmpname)) { if (uri_backend_save_image (uri, tmpname, run_mode, error)) { status = GIMP_PDB_SUCCESS; } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to save to temporary file '%s'"), gimp_filename_to_utf8 (tmpname)); } } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s", gimp_get_pdb_error ()); } if (! mapped) g_unlink (tmpname); g_free (tmpname); return status; }
static GimpPDBStatusType save_image (const gchar *filename, gint32 image_ID, gint32 drawable_ID, gint32 run_mode) { GimpPDBStatusType status = GIMP_PDB_SUCCESS; gchar *ext; gchar *tmpname; gchar *mailcmd[3]; GPid mailpid; FILE *mailpipe; GError *error = NULL; ext = find_extension (filename); if (ext == NULL) return GIMP_PDB_CALLING_ERROR; /* get a temp name with the right extension and save into it. */ tmpname = gimp_temp_name (ext + 1); /* construct the "sendmail user@location" line */ mailcmd[0] = SENDMAIL; mailcmd[1] = mail_info.receipt; mailcmd[2] = NULL; /* create a pipe to sendmail */ mailpipe = sendmail_pipe (mailcmd, &mailpid); if (mailpipe == NULL) return GIMP_PDB_EXECUTION_ERROR; create_headers (mailpipe); fflush (mailpipe); if (! (gimp_file_save (run_mode, image_ID, drawable_ID, tmpname, tmpname) && valid_file (tmpname))) { goto error; } if (! to64 (tmpname, mailpipe, &error)) { g_message ("%s", error->message); g_error_free (error); goto error; } fprintf (mailpipe, "\n--GUMP-MIME-boundary--\n"); goto cleanup; error: /* stop sendmail from doing anything */ kill (mailpid, SIGINT); status = GIMP_PDB_EXECUTION_ERROR; cleanup: /* close out the sendmail process */ fclose (mailpipe); waitpid (mailpid, NULL, 0); g_spawn_close_pid (mailpid); /* delete the tmpfile that was generated */ g_unlink (tmpname); g_free (tmpname); return status; }
static gboolean image_save(format_type type, image_output imageout, format_params params) { gboolean result; if (type == FORMAT_BMP) { result = image_save_bmp(imageout); } else if(type == FORMAT_GIF) { result = image_save_gif(imageout, ((format_params_gif)params)->interlace); } else if(type == FORMAT_ICON) { result = image_save_icon(imageout); } else if(type == FORMAT_JPEG) { result = image_save_jpeg( imageout, ((format_params_jpeg)params)->quality, ((format_params_jpeg)params)->smoothing, ((format_params_jpeg)params)->entropy, ((format_params_jpeg)params)->progressive, ((format_params_jpeg)params)->comment, ((format_params_jpeg)params)->subsampling, ((format_params_jpeg)params)->baseline, ((format_params_jpeg)params)->markers, ((format_params_jpeg)params)->dct ); } else if(type == FORMAT_PNG) { result = image_save_png(imageout, ((format_params_png)params)->interlace, ((format_params_png)params)->compression, ((format_params_png)params)->savebgc, ((format_params_png)params)->savegamma, ((format_params_png)params)->saveoff, ((format_params_png)params)->savephys, ((format_params_png)params)->savetime, ((format_params_png)params)->savecomm, ((format_params_png)params)->savetrans ); } else if(type == FORMAT_TGA) { result = image_save_tga(imageout, ((format_params_tga)params)->rle, ((format_params_tga)params)->origin); } else if(type == FORMAT_TIFF) { result = image_save_tiff(imageout, ((format_params_tiff)params)->compression); } else { // save in the original format int final_drawable = gimp_image_merge_visible_layers(imageout->image_id, GIMP_CLIP_TO_IMAGE); // but first check if the images was a GIF and it's palette has changed during the process if (file_has_extension(imageout->filename, ".gif") && gimp_drawable_is_rgb(final_drawable)) { gimp_image_convert_indexed( imageout->image_id, GIMP_FS_DITHER, GIMP_MAKE_PALETTE, gimp_drawable_has_alpha (final_drawable) ? 255 : 256, TRUE, FALSE, "" ); } result = gimp_file_save( GIMP_RUN_NONINTERACTIVE, imageout->image_id, final_drawable, imageout->filepath, imageout->filename ); } return result; }
void p_example_read_video(char *videofile, gdouble skip_seconds, gint32 nframes) { t_GVA_Handle* gvahand; gint32 vid_track; gint32 aud_track; vid_track = 1; aud_track = 1; gvahand = GVA_open_read(videofile, vid_track, aud_track); if(gvahand) { t_GVA_RetCode l_rc; gint32 framenumber; GimpRunMode runmode; /* print informations about the videofile */ printf("Videofile : %s\n", videofile); printf(" framesize : %d x %d\n", (int)gvahand->width, (int)gvahand->width ); printf(" # of frames : %d\n", (int)gvahand->total_frames ); printf(" framerate : %f (f/sec)\n", (float)gvahand->framerate ); printf("Decoder Name : %s\n", gvahand->dec_elem->decoder_name); runmode = GIMP_RUN_INTERACTIVE; if (skip_seconds > 0.0) { /* skip the the trailer (time in seconds) */ l_rc = GVA_seek_frame(gvahand, skip_seconds, GVA_UPOS_SECS); } /* read nframes from the video */ for(framenumber=1; framenumber <= nframes; framenumber++) { gboolean delete_mode = TRUE; gint32 deinterlace; /* 0.. NO deinterlace, 1..odd rows, 2..even rows */ gdouble threshold; /* 0.0 <= threshold <= 1.0 */ char *framename; deinterlace = 1; /* threshold for interpolated rows (only used if deinterlace != 0) * - big thresholds 1.0 do smooth mix interpolation * - small thresholds keep hard edges (does not mix different colors) * - threshold 0.0 does not interpolate at all and just makes a copy of the previous row */ threshold = 1.0; /* fetch one frame to buffer gvahand->frame_data * (and proceed position to next frame) */ l_rc = GVA_get_next_frame(gvahand); if(l_rc == GVA_RET_OK) { /* convert fetched frame from buffer to gimp image gvahand->image_id * by creating a new layer gvahand->layer_id * delete_mode TRUE does first delete gvahand->layer_id * (delete_mode FALSE would not delete the layer and the layerstack would * grow upto full nframes Layers in the last turn of the loop) */ l_rc = GVA_frame_to_gimp_layer(gvahand, delete_mode, framenumber, deinterlace, threshold); /* save the extracted frames using gimp_file_save * (the fileformat is selected automatically by the extension) */ framename = g_strdup_printf("frame_%04d.jpg"); printf ("saving: %s\n", framename); gimp_file_save(runmode, gvahand->image_id, gvahand->layer_id, framename, framename); g_free(framename); /* foreach following frame use the same save settings (same jpeg quality) * as given by the User in the 1.st INTERACTIVE Run */ runmode = GIMP_RUN_WITH_LAST_VALS; } } GVA_close(gvahand); } } /* end p_example_read_video */