static gboolean validate_stage (gpointer data_) { ValidateData *data = data_; if (data->check_actor) { data->result = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (data->stage), CLUTTER_PICK_ALL, data->point.x, data->point.y); } if (data->check_color) { data->result = clutter_stage_read_pixels (CLUTTER_STAGE (data->stage), data->point.x, data->point.y, 1, 1); } if (!g_test_verbose ()) { clutter_actor_hide (data->stage); data->was_painted = TRUE; } return G_SOURCE_REMOVE; }
static VALUE rbclt_stage_read_pixels (VALUE self, VALUE x, VALUE y, VALUE width_arg, VALUE height_arg) { ClutterStage *stage = CLUTTER_STAGE (RVAL2GOBJ (self)); guchar *pixels; VALUE ret; gint width, height; width = NUM2INT (width_arg); height = NUM2INT (height_arg); pixels = clutter_stage_read_pixels (stage, NUM2INT (x), NUM2INT (y), width, height); if (pixels == NULL) ret = Qnil; else { ret = rb_str_new ((char *) pixels, width * 4 * height); g_free (pixels); } return ret; }
static void glide_window_export_pdf_real (GlideWindow *w, const gchar *filename) { cairo_surface_t *pdf_surface; cairo_t *cr; gint width, height; gint o_slide; int i = 0; glide_window_fullscreen_stage (w); while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, TRUE); width = clutter_actor_get_width (w->priv->stage); height = clutter_actor_get_height (w->priv->stage); pdf_surface = cairo_pdf_surface_create (filename, width, height); cr = cairo_create (pdf_surface); o_slide = glide_stage_manager_get_current_slide (w->priv->manager); for (i = 0; i < glide_document_get_n_slides (w->priv->document); i++) { guchar *pixels; guchar *p; GdkPixbuf *pb; glide_stage_manager_set_current_slide (w->priv->manager, i); pixels = clutter_stage_read_pixels (CLUTTER_STAGE (w->priv->stage), 0, 0, width, height); for (p = pixels + width * height * 4; p > pixels; p -= 3) *(--p) = 255; pb = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, width, height, width * 4, (GdkPixbufDestroyNotify) g_free, NULL); gdk_cairo_set_source_pixbuf (cr, pb, 0, 0); cairo_rectangle (cr, 0, 0, width, height); cairo_fill (cr); cairo_surface_show_page (pdf_surface); g_object_unref (G_OBJECT (pb)); } cairo_surface_flush (pdf_surface); cairo_destroy (cr); cairo_surface_destroy (pdf_surface); glide_window_unfullscreen_stage (w); glide_stage_manager_set_current_slide (w->priv->manager, o_slide); }
Image * Image::screenshot() { TPImage image; ClutterActor * stage = clutter_stage_get_default(); if ( ! stage ) { return 0; } if ( ! CLUTTER_ACTOR_IS_VISIBLE( stage ) ) { return 0; } gfloat width; gfloat height; clutter_actor_get_size( stage , & width , & height ); image.pixels = clutter_stage_read_pixels( CLUTTER_STAGE( stage ) , 0 , 0 , width , height ); if ( ! image.pixels ) { return 0; } // The alpha component of the stage is meaningless, so we set it // to 255 for every pixel. guchar * p = ( guchar * ) image.pixels + 3; for ( int i = 0; i < width * height ; ++i , p += 4 ) { *p = 255; } image.width = width; image.height = height; image.depth = 4; image.pitch = width * 4; image.bgr = 0; image.free_image = Image::free_image_with_g_free; image.pm_alpha = 0; return Image::make( image ); }
static gboolean validate_part (TestState *state, int xpos, int ypos, int clip_flags) { int x, y; gboolean pass = TRUE; /* Check whether the center of each division is the right color */ for (y = 0; y < SOURCE_DIVISIONS_Y; y++) for (x = 0; x < SOURCE_DIVISIONS_X; x++) { guchar *pixels; const ClutterColor *correct_color; /* Read the center pixels of this division */ pixels = clutter_stage_read_pixels (CLUTTER_STAGE (state->stage), x * DIVISION_WIDTH + DIVISION_WIDTH / 2 + xpos, y * DIVISION_HEIGHT + DIVISION_HEIGHT / 2 + ypos, 1, 1); /* If this division is clipped then it should be the stage color */ if ((clip_flags & (1 << ((y * SOURCE_DIVISIONS_X) + x)))) correct_color = &stage_color; else /* Otherwise it should be the color for this division */ correct_color = corner_colors + (y * SOURCE_DIVISIONS_X) + x; if (pixels == NULL || pixels[0] != correct_color->red || pixels[1] != correct_color->green || pixels[2] != correct_color->blue) pass = FALSE; g_free (pixels); } return pass; }
gboolean opt_show_export (OptShow *self, const char *path, GError **error) { #define HTML "<html><head><title>Slide %i</title></head>\n" \ "<body><p><center><img src=\"%s\"></center></p>\n" \ "<p><center><strong>%s%s</strong></center></p>\n" \ "</body></html>" GList *slide; OptShowPrivate *priv; ClutterActor *stage; gint i = 0; priv = self->priv; stage = clutter_stage_get_default(); g_object_set (stage, "offscreen", TRUE, NULL); clutter_actor_show_all (stage); slide = priv->slides; while (slide) { ClutterActor *e; guchar *data; GdkPixbuf *pixb = NULL; gchar name[32]; gchar *filename = NULL; gchar html[2048], html_next[512], html_prev[512]; e = CLUTTER_ACTOR(slide->data); clutter_container_add_actor (CLUTTER_CONTAINER(stage), e); clutter_actor_show_all (stage); clutter_actor_show_all (e); // clutter_redraw (CLUTTER_STAGE (stage)); data = clutter_stage_read_pixels (CLUTTER_STAGE(stage), 0, 0, clutter_actor_get_width (stage), clutter_actor_get_height (stage)); if (!data) { g_warning("Failed to grab pixels from stage"); return FALSE; } pixb = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE, 8, clutter_actor_get_width (stage), clutter_actor_get_height (stage), clutter_actor_get_width (stage) * 4, free_data, NULL); g_snprintf (name, 32, "slide-%02i.png", i); filename = g_build_filename(path, name, NULL); if (!gdk_pixbuf_save (pixb, filename, "png", error, "compression", "9", /* Really compress */ NULL)) { if (filename) g_free (filename); g_object_unref (pixb); return FALSE; } html_next[0] = html_prev[0] = '\0'; if (i > 0) snprintf(html_prev, 512, "<a href=\"slide-%02i.html\">Prev</a> |", i-1); if (slide->next) snprintf(html_next, 512, " <a href=\"slide-%02i.html\">Next</a>", i+1); g_snprintf(html, 2048, HTML, i, name, html_prev, html_next); g_snprintf(name, 32, "slide-%02i.html", i); g_free (filename); filename = g_build_filename(path, name, NULL); g_file_set_contents (filename, html, -1, NULL); g_print ("wrote '%s'\n", filename); clutter_actor_hide_all (e); clutter_group_remove (CLUTTER_GROUP(stage), e); if (filename) g_free (filename); slide = slide->next; i++; g_object_unref (pixb); } return TRUE; }