static VALUE rb_cogl_texture_get_rowstride (VALUE self) { CoglHandle tex = rb_cogl_texture_get_handle (self); return UINT2NUM (cogl_texture_get_rowstride (tex)); }
Images::Cache::Entry::Entry( CoglHandle _handle , const JSON::Object & _tags ) : handle( cogl_handle_ref( _handle ) ), timestamp( ::timestamp() ), tags( _tags ) { // Size in MB size = ( cogl_texture_get_height( TP_COGL_TEXTURE( handle ) ) * cogl_texture_get_rowstride( TP_COGL_TEXTURE( handle ) ) ) / ( 1024.0 * 1024.0 ); }
static ClutterStageWaylandWaylandBuffer * wayland_create_shm_buffer (ClutterBackendWayland *backend_wayland, ClutterGeometry *geom) { ClutterStageWaylandWaylandBufferSHM *buffer; struct wl_visual *visual; CoglHandle tex; CoglTextureFlags flags = COGL_TEXTURE_NONE; /* XXX: tweak flags? */ CoglPixelFormat format = VISUAL_ARGB_PRE; int fd; gchar tmp[] = "/tmp/clutter-wayland-shm-XXXXXX"; buffer = g_slice_new (ClutterStageWaylandWaylandBufferSHM); buffer->buffer.type = BUFFER_TYPE_SHM; tex = cogl_texture_new_with_size ((unsigned int)geom->width, (unsigned int)geom->height, flags, format); buffer->format = format; buffer->stride = cogl_texture_get_rowstride(tex); buffer->size = cogl_texture_get_data(tex, format, buffer->stride, NULL); buffer->buffer.tex = tex; fd = g_mkstemp_full(tmp, O_RDWR, 0600); ftruncate(fd, buffer->size); buffer->data = mmap(NULL, buffer->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); g_unlink(tmp); visual = get_visual (backend_wayland->wayland_display, format); buffer->buffer.wayland_buffer = wl_shm_create_buffer (backend_wayland->wayland_shm, fd, geom->width, geom->height, buffer->stride, visual); close(fd); return &buffer->buffer; }
static VALUE rb_cogl_texture_get_data (int argc, VALUE *argv, VALUE self) { CoglHandle tex = rb_cogl_texture_get_handle (self); VALUE format_arg, rowstride_arg; CoglPixelFormat format; guint rowstride; VALUE data; rb_scan_args (argc, argv, "02", &format_arg, &rowstride_arg); format = NIL_P (format_arg) ? cogl_texture_get_format (tex) : NUM2UINT (format_arg); rowstride = (NIL_P (rowstride_arg) || NUM2UINT (rowstride_arg) == 0) ? cogl_texture_get_rowstride (tex) : NUM2UINT (rowstride_arg); data = rb_str_buf_new (rowstride * cogl_texture_get_height (tex)); cogl_texture_get_data (tex, format, rowstride, (guchar *) RSTRING (data)->ptr); RSTRING (data)->len = rowstride * cogl_texture_get_height (tex); return data; }
int main (int argc, char *argv[]) { ClutterActor *video; GdkPixbuf *shot = NULL; gint duration; CoglHandle tex_id; CoglPixelFormat format; gint size; gint width; gint height; gint rowstride; guchar *data = NULL; #ifdef USE_HELIX clutter_helix_init (&argc, &argv); #else gst_init (&argc, &argv); #endif clutter_init (&argc, &argv); if (argc < 3) { g_print ("Usage: %s <path to movie file> <output png>\n", argv[0]); exit(-1); } totem_resources_monitor_start (argv[1], 60 * G_USEC_PER_SEC); #ifdef USE_HELIX video = clutter_helix_video_texture_new (); #else video = clutter_gst_video_texture_new (); #endif if (argv[1][0] == '/') clutter_media_set_filename(CLUTTER_MEDIA(video), argv[1]); else clutter_media_set_uri(CLUTTER_MEDIA(video), argv[1]); clutter_media_set_volume (CLUTTER_MEDIA(video), 0); clutter_media_set_playing (CLUTTER_MEDIA(video), TRUE); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); duration = clutter_media_get_duration (CLUTTER_MEDIA(video)); } while (duration == 0); clutter_actor_realize (video); clutter_media_set_position (CLUTTER_MEDIA(video), duration/3); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); } while (clutter_media_get_position (CLUTTER_MEDIA(video)) <= duration/3); tex_id = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (video)); if (tex_id) { format = cogl_texture_get_format (tex_id); size = cogl_texture_get_data (tex_id, format, 0, NULL); width = cogl_texture_get_width (tex_id); height = cogl_texture_get_height (tex_id); rowstride = cogl_texture_get_rowstride (tex_id); data = (guchar*) g_malloc (sizeof(guchar) * size); if (!data) g_error ("malloc");; cogl_texture_get_data (tex_id, format, rowstride, data); shot = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, rowstride, NULL, NULL); } totem_resources_monitor_stop (); if (shot) { GdkPixbuf *thumb, *pic; gint x, y, nw, nh, w, h, size; size = 128; /* FIXME swap RGB pixels */ w = clutter_actor_get_width (video); h = clutter_actor_get_height (video); nh = ( h * size) / w; if (nh <= size) { nw = size; x = 0; y = (size - nh) / 2; } else { nw = ( w * size ) / h; nh = size; x = (size - nw) / 2; y = 0; } thumb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size); gdk_pixbuf_fill (thumb, 0x000000FF); pic = gdk_pixbuf_scale_simple (shot, nw, nh, GDK_INTERP_BILINEAR); gdk_pixbuf_copy_area (pic, 0, 0, nw, nh, thumb, x, y); if (!gdk_pixbuf_save (thumb, argv[2], "png", NULL, NULL)) { g_error ("%s: Pixbuf save failed\n", argv[0]); exit(-1); } g_object_unref (shot); g_object_unref (thumb); g_object_unref (pic); exit(0); } exit (-1); }
static void test_coglbox_init (TestCoglbox *self) { TestCoglboxPrivate *priv; guint width; guint height; guint rowstride; CoglPixelFormat format; gint size; guchar *data; gint x,y,t; guchar *pixel; self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); /* Load image from file */ priv->cogl_tex_id[0] = cogl_texture_new_from_file ("redhand.png", 40, FALSE, COGL_PIXEL_FORMAT_ANY, NULL); if (priv->cogl_tex_id[0] == COGL_INVALID_HANDLE) { printf ("Failed loading redhand.png image!\n"); return; } printf("Texture loaded from file.\n"); /* Obtain pixel data */ format = cogl_texture_get_format (priv->cogl_tex_id[0]); g_assert(format == COGL_PIXEL_FORMAT_RGBA_8888 || format == COGL_PIXEL_FORMAT_ARGB_8888); width = cogl_texture_get_width (priv->cogl_tex_id[0]); height = cogl_texture_get_height (priv->cogl_tex_id[0]); size = cogl_texture_get_data (priv->cogl_tex_id[0], format, 0, NULL); printf("size: %dx%d\n", width, height); printf("format: 0x%x\n", format); printf("bytesize: %d\n", size); data = (guchar*) g_malloc (sizeof(guchar) * size); cogl_texture_get_data (priv->cogl_tex_id[0], format, 0, data); rowstride = cogl_texture_get_rowstride (priv->cogl_tex_id[0]); /* Create new texture from modified data */ priv->cogl_tex_id[1] = cogl_texture_new_from_data (width, height, 0, FALSE, format, format, rowstride, data); if (priv->cogl_tex_id[1] == COGL_INVALID_HANDLE) { printf ("Failed creating image from data!\n"); return; } printf ("Texture created from data.\n"); /* Modify data (swap red and green) */ for (y=0; y<height; ++y) { for (x=0; x<width; ++x) { pixel = data + y * rowstride + x * 4; if (format == COGL_PIXEL_FORMAT_RGBA_8888) { t = pixel[0]; pixel[0] = pixel[1]; pixel[1] = t; } else { t = pixel[1]; pixel[1] = pixel[2]; pixel[2] = t; } } } cogl_texture_set_region (priv->cogl_tex_id[1], 0, 0, 0, 0, 100, 100, width, height, format, 0, data); cogl_texture_set_region (priv->cogl_tex_id[1], 100, 100, 100, 100, 100, 100, width, height, format, 0, data); printf ("Subregion data updated.\n"); }