static gpointer thumbnail_thread (gpointer data) { ThreadData *thread_data = data; gint n_pages; gint i; n_pages = poppler_document_get_n_pages (thread_data->document); for (i = 0; i < n_pages; i++) { IdleData *idle_data = g_new0 (IdleData, 1); idle_data->selector = thread_data->selector; idle_data->page_no = i; /* FIXME get preferred size from somewhere? */ idle_data->pixbuf = get_thumbnail (thread_data->document, i, THUMBNAIL_SIZE); g_idle_add (idle_set_thumbnail, idle_data); if (thread_data->stop_thumbnailing) break; } return NULL; }
void testVideoParse(const char* videoFile, const char* jpegFile) { init_libraries(); RequestInfo req; req.file = videoFile; req.split = 12; req.columns = 3; req.pageSize = 12; req.currentPage = 1; req.second = 15; req.width = 0; req.height = 300; ImageBuffer jpeg = get_thumbnail(req); if (jpeg.buffer) { printf("Writing file: %s\n", jpegFile); FILE* f = fopen(jpegFile, "w"); if (f) { fwrite(jpeg.buffer, jpeg.size, 1, f); fclose(f); printf("File written!\n"); } } else { printf("JPEG INVALIDO!!!!!!!!!!!!!!!!\n"); } }
void test_get_thumbnail_by_second(const char* videoFile, const char* jpegFile) { init_libraries(); RequestInfo req; req.file = videoFile; req.second = 15; req.height = 300; req.width = 0; ImageBuffer jpeg = get_thumbnail(req); if (jpeg.buffer) { printf("Writing image by second with name: %s\n", jpegFile); FILE* f = fopen(jpegFile, "w"); if (f) { fwrite(jpeg.buffer, jpeg.size, 1, f); fclose(f); printf("Image written!\n"); } } else { printf("Error to save jpeg a video frame!\n"); } }
int main(int argc,char **argv) { #define ThrowWandException(wand) \ { \ char \ *description; \ \ ExceptionType \ severity; \ \ description=MagickGetException(wand,&severity); \ (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \ description=(char *) MagickRelinquishMemory(description); \ exit(-1); \ } MagickBooleanType status; MagickWand *magick_wand; MagickWand *tmp_magick_wand; /* Read an image. */ size_t len; char *data; data = get_thumbnail(argv[1], argv[2], &len); MagickReadImageBlob(magick_wand, data, len); status=MagickWriteImages(magick_wand,argv[3],MagickTrue); if (status == MagickFalse) ThrowWandException(magick_wand); magick_wand=DestroyMagickWand(magick_wand); MagickWandTerminus(); return(0); }
static int videothumb_handler(request_rec *r) { char fullVideoPath[MAX_PATH_LENGTH]; if (!r) return DECLINED; module_config* conf = ap_get_module_config(r->server->module_config, &videothumb_module); if (!conf->enabled) { return DECLINED; } if (!(conf->app_path && (strstr(r->parsed_uri.path, conf->app_path) == r->parsed_uri.path))) { return DECLINED; } if (r->args) { void* ctx; parse_query_string(&ctx, r->args, r->pool); strncpy(fullVideoPath, conf->medias_path, MAX_PATH_LENGTH); if (!r->path_info) { LOG_ERROR("Could not find 'filename' on the URI"); return DECLINED; } strncat(fullVideoPath, r->path_info + 1, MAX_PATH_LENGTH); const char* temp = get_parameter(ctx, "split"); RequestInfo requestInfo; requestInfo.split = atoi(temp ? temp : ONE_VALUE); temp = get_parameter(ctx, "columns"); requestInfo.columns = atoi(temp ? temp : ONE_VALUE); requestInfo.file = fullVideoPath; requestInfo.jpegQuality = conf->quality; temp = get_parameter(ctx,"width"); if(temp == NULL) requestInfo.width = 0; else requestInfo.width = atoi(temp); temp = get_parameter(ctx,"height"); if(temp == NULL) requestInfo.height = 0; else requestInfo.height = atoi(temp); temp = get_parameter(ctx,"pageSize"); requestInfo.pageSize = temp ? atoi(temp) : requestInfo.split; temp = get_parameter(ctx,"currentPage"); requestInfo.currentPage = atoi(temp ? temp : ONE_VALUE); init_libraries(); temp = get_parameter(ctx, "second"); ImageBuffer jpeg; if(temp == NULL) { jpeg = get_storyboard(requestInfo, r->pool); } else { requestInfo.second = atoi(temp ? temp : ONE_VALUE); jpeg = get_thumbnail(requestInfo, r->pool); } if (jpeg.buffer) { ap_set_content_type(r, "image/jpeg"); ap_rwrite(jpeg.buffer, jpeg.size, r); free(jpeg.buffer); } else { LOG_ERROR("Cannot render thumbnail for this video"); return DECLINED; } } else { LOG_ERROR("Querystring null"); return DECLINED; } return OK; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[6]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_ID = -1; PopplerDocument *doc = NULL; GError *error = NULL; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; if (! g_thread_supported ()) g_thread_init (NULL); if (strcmp (name, LOAD_PROC) == 0) { PdfSelectedPages pages = { 0, NULL }; switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals); doc = open_document (param[1].data.d_string, &error); if (!doc) { status = GIMP_PDB_EXECUTION_ERROR; break; } if (load_dialog (doc, &pages)) gimp_set_data (LOAD_PROC, &loadvals, sizeof(loadvals)); else status = GIMP_PDB_CANCEL; break; case GIMP_RUN_WITH_LAST_VALS: /* FIXME: implement last vals mode */ status = GIMP_PDB_EXECUTION_ERROR; break; case GIMP_RUN_NONINTERACTIVE: doc = open_document (param[1].data.d_string, &error); if (doc) { PopplerPage *test_page = poppler_document_get_page (doc, 0); if (test_page) { pages.n_pages = 1; pages.pages = g_new (gint, 1); pages.pages[0] = 0; g_object_unref (test_page); } else { status = GIMP_PDB_EXECUTION_ERROR; g_object_unref (doc); } } else { status = GIMP_PDB_EXECUTION_ERROR; } break; } if (status == GIMP_PDB_SUCCESS) { image_ID = load_image (doc, param[1].data.d_string, run_mode, loadvals.target, loadvals.resolution, &pages); if (image_ID != -1) { *nreturn_vals = 2; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image_ID; } else { status = GIMP_PDB_EXECUTION_ERROR; } } if (doc) g_object_unref (doc); g_free (pages.pages); } else if (strcmp (name, LOAD_THUMB_PROC) == 0) { if (nparams < 2) { status = GIMP_PDB_CALLING_ERROR; } else { gdouble width = 0; gdouble height = 0; gdouble scale; gint32 image = -1; gint num_pages = 0; GdkPixbuf *pixbuf = NULL; /* Possibly retrieve last settings */ gimp_get_data (LOAD_PROC, &loadvals); doc = open_document (param[0].data.d_string, &error); if (doc) { PopplerPage *page = poppler_document_get_page (doc, 0); if (page) { poppler_page_get_size (page, &width, &height); g_object_unref (page); } num_pages = poppler_document_get_n_pages (doc); pixbuf = get_thumbnail (doc, 0, param[1].data.d_int32); g_object_unref (doc); } if (pixbuf) { image = gimp_image_new (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GIMP_RGB); gimp_image_undo_disable (image); layer_from_pixbuf (image, "thumbnail", 0, pixbuf, 0.0, 1.0); g_object_unref (pixbuf); gimp_image_undo_enable (image); gimp_image_clean_all (image); } scale = loadvals.resolution / gimp_unit_get_factor (GIMP_UNIT_POINT); width *= scale; height *= scale; if (image != -1) { *nreturn_vals = 6; values[1].type = GIMP_PDB_IMAGE; values[1].data.d_image = image; values[2].type = GIMP_PDB_INT32; values[2].data.d_int32 = width; values[3].type = GIMP_PDB_INT32; values[3].data.d_int32 = height; values[4].type = GIMP_PDB_INT32; values[4].data.d_int32 = GIMP_RGB_IMAGE; values[5].type = GIMP_PDB_INT32; values[5].data.d_int32 = num_pages; } else { status = GIMP_PDB_EXECUTION_ERROR; } } } else { status = GIMP_PDB_CALLING_ERROR; } if (status != GIMP_PDB_SUCCESS && error) { *nreturn_vals = 2; values[1].type = GIMP_PDB_STRING; values[1].data.d_string = error->message; } values[0].data.d_status = status; }
static gboolean vik_print_preview_expose_event (GtkWidget *widget, GdkEventExpose *eevent, VikPrintPreview *preview) { gdouble paper_width; gdouble paper_height; gdouble left_margin; gdouble right_margin; gdouble top_margin; gdouble bottom_margin; gdouble scale; cairo_t *cr; paper_width = gtk_page_setup_get_paper_width (preview->page, GTK_UNIT_POINTS); paper_height = gtk_page_setup_get_paper_height (preview->page, GTK_UNIT_POINTS); vik_print_preview_get_page_margins (preview, &left_margin, &right_margin, &top_margin, &bottom_margin); cr = gdk_cairo_create (gtk_widget_get_window(widget)); scale = vik_print_preview_get_scale (preview); /* draw background */ cairo_scale (cr, scale, scale); gdk_cairo_set_source_color (cr, >k_widget_get_style(widget)->white); cairo_rectangle (cr, 0, 0, paper_width, paper_height); cairo_fill (cr); /* draw page_margins */ gdk_cairo_set_source_color (cr, >k_widget_get_style(widget)->black); cairo_rectangle (cr, left_margin, top_margin, paper_width - left_margin - right_margin, paper_height - top_margin - bottom_margin); cairo_stroke (cr); if (preview->dragging) { gint width, height; gdk_drawable_get_size(preview->drawable, &width, &height); cairo_rectangle (cr, left_margin + preview->image_offset_x, top_margin + preview->image_offset_y, (gdouble) width * 72.0 / preview->image_xres, (gdouble) height * 72.0 / preview->image_yres); cairo_stroke (cr); } else { GdkDrawable *drawable = preview->drawable; /* draw image */ cairo_translate (cr, left_margin + preview->image_offset_x, top_margin + preview->image_offset_y); if (preview->pixbuf == NULL) { gint width = MIN (widget->allocation.width, 1024); gint height = MIN (widget->allocation.height, 1024); preview->pixbuf = get_thumbnail(drawable, width, height); } if (preview->pixbuf != NULL) { gint width, height; gdk_drawable_get_size(drawable, &width, &height); gdouble scale_x = ((gdouble) width / gdk_pixbuf_get_width (preview->pixbuf)); gdouble scale_y = ((gdouble) height / gdk_pixbuf_get_height (preview->pixbuf)); scale_x = scale_x * 72.0 / preview->image_xres; scale_y = scale_y * 72.0 / preview->image_yres; cairo_scale (cr, scale_x, scale_y); gdk_cairo_set_source_pixbuf (cr, preview->pixbuf, 0, 0); cairo_paint (cr); } } cairo_destroy (cr); return FALSE; }