Exemplo n.º 1
0
static GdkPixbuf *
add_holes_to_pixbuf_small (GdkPixbuf *pixbuf, int width, int height)
{
	GdkPixbuf *holes, *tmp, *target;
	char *filename;
	int i;

	filename = g_build_filename (DATADIR, "xplayer", "filmholes.png", NULL);
	holes = gdk_pixbuf_new_from_file (filename, NULL);
	g_free (filename);

	if (holes == NULL) {
		g_object_ref (pixbuf);
		return pixbuf;
	}

	g_assert (gdk_pixbuf_get_has_alpha (pixbuf) == FALSE);
	g_assert (gdk_pixbuf_get_has_alpha (holes) != FALSE);
	target = g_object_ref (pixbuf);

	for (i = 0; i < height; i += gdk_pixbuf_get_height (holes))
	{
		gdk_pixbuf_composite (holes, target, 0, i,
				      MIN (width, gdk_pixbuf_get_width (holes)),
				      MIN (height - i, gdk_pixbuf_get_height (holes)),
				      0, i, 1, 1, GDK_INTERP_NEAREST, 255);
	}

	tmp = gdk_pixbuf_flip (holes, FALSE);
	g_object_unref (holes);
	holes = tmp;

	for (i = 0; i < height; i += gdk_pixbuf_get_height (holes))
	{
		gdk_pixbuf_composite (holes, target,
				      width - gdk_pixbuf_get_width (holes), i,
				      MIN (width, gdk_pixbuf_get_width (holes)),
				      MIN (height - i, gdk_pixbuf_get_height (holes)),
				      width - gdk_pixbuf_get_width (holes), i,
				      1, 1, GDK_INTERP_NEAREST, 255);
	}

	g_object_unref (holes);

	return target;
}
Exemplo n.º 2
0
void Pixbuf::_forceAlpha()
{
    if (gdk_pixbuf_get_has_alpha(_pixbuf)) return;

    GdkPixbuf *old = _pixbuf;
    _pixbuf = gdk_pixbuf_add_alpha(old, FALSE, 0, 0, 0);
    g_object_unref(old);
}
Exemplo n.º 3
0
static void
file_loaded (GObject      *source_object,
             GAsyncResult *result,
             gpointer      user_data)
{
  MetaBackgroundImage *image = META_BACKGROUND_IMAGE (source_object);
  GError *error = NULL;
  CoglError *catch_error = NULL;
  GTask *task;
  CoglTexture *texture;
  GdkPixbuf *pixbuf;
  int width, height, row_stride;
  guchar *pixels;
  gboolean has_alpha;

  task = G_TASK (result);
  pixbuf = g_task_propagate_pointer (task, &error);

  if (pixbuf == NULL)
    {
      char *uri = g_file_get_uri (image->file);
      g_warning ("Failed to load background '%s': %s",
                 uri, error->message);
      g_clear_error (&error);
      g_free (uri);
      goto out;
    }

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);
  row_stride = gdk_pixbuf_get_rowstride (pixbuf);
  pixels = gdk_pixbuf_get_pixels (pixbuf);
  has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);

  texture = meta_create_texture (width, height,
                                 has_alpha ? COGL_TEXTURE_COMPONENTS_RGBA : COGL_TEXTURE_COMPONENTS_RGB,
                                 META_TEXTURE_ALLOW_SLICING);

  if (!cogl_texture_set_data (texture,
                              has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                              row_stride,
                              pixels, 0,
                              &catch_error))
    {
      g_warning ("Failed to create texture for background");
      cogl_error_free (catch_error);
      cogl_object_unref (texture);
    }

  image->texture = texture;

out:
  if (pixbuf != NULL)
    g_object_unref (pixbuf);

  image->loaded = TRUE;
  g_signal_emit (image, signals[LOADED], 0);
}
Exemplo n.º 4
0
/**
 * eel_gdk_pixbuf_fill_rectangle_with_color:
 * @pixbuf: Target pixbuf to fill into.
 * @area: Rectangle to fill.
 * @color: The color to use.
 *
 * Fill the rectangle with the the given color.
 */
void
eel_gdk_pixbuf_fill_rectangle_with_color (GdkPixbuf *pixbuf,
        EelIRect area,
        guint32 color)
{
    EelIRect target;
    guchar red;
    guchar green;
    guchar blue;
    guchar alpha;
    guchar *pixels;
    gboolean has_alpha;
    guint pixel_offset;
    guint rowstride;
    guchar *row_offset;
    int x;
    int y;

    g_return_if_fail (eel_gdk_pixbuf_is_valid (pixbuf));

    target = eel_gdk_pixbuf_intersect (pixbuf, 0, 0, area);
    if (eel_irect_is_empty (&target))
    {
        return;
    }

    pixels = gdk_pixbuf_get_pixels (pixbuf);
    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
    pixel_offset = has_alpha ? 4 : 3;
    red = EEL_RGBA_COLOR_GET_R (color);
    green = EEL_RGBA_COLOR_GET_G (color);
    blue = EEL_RGBA_COLOR_GET_B (color);
    alpha = EEL_RGBA_COLOR_GET_A (color);

    row_offset = pixels + target.y0 * rowstride;

    for (y = target.y0; y < target.y1; y++)
    {
        guchar *offset = row_offset + (target.x0 * pixel_offset);

        for (x = target.x0; x < target.x1; x++)
        {
            *(offset++) = red;
            *(offset++) = green;
            *(offset++) = blue;

            if (has_alpha)
            {
                *(offset++) = alpha;
            }

        }

        row_offset += rowstride;
    }
}
Exemplo n.º 5
0
/*
 * This function is taken from Bickley, Copyright (c) Intel Corporation 2008.
 */
static gboolean
is_interesting (GdkPixbuf *pixbuf)
{
    int width, height, y, rowstride;
    gboolean has_alpha;
    guint32 histogram[4][4][4] = {{{0,},},};
    guchar *pixels;
    guint pxl_count = 0, count, i;

    width = gdk_pixbuf_get_width (pixbuf);
    height = gdk_pixbuf_get_height (pixbuf);
    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);

    pixels = gdk_pixbuf_get_pixels (pixbuf);
    for (y = 0; y < height; y++) {
        guchar *row = pixels + (y * rowstride);
        int c;

        for (c = 0; c < width; c++) {
            guchar r, g, b;

            r = row[0];
            g = row[1];
            b = row[2];

            histogram[r / 64][g / 64][b / 64]++;

            if (has_alpha) {
                row += 4;
            } else {
                row += 3;
            }

            pxl_count++;
        }
    }

    count = 0;
    for (i = 0; i < 4; i++) {
        int j;
        for (j = 0; j < 4; j++) {
            int k;

            for (k = 0; k < 4; k++) {
                /* Count how many bins have more than
                   1% of the pixels in the histogram */
                if (histogram[i][j][k] > pxl_count / 100) {
                    count++;
                }
            }
        }
    }

    /* Image is boring if there is only 1 bin with > 1% of pixels */
    return count > 1;
}
Exemplo n.º 6
0
static CoglTexture *
pixbuf_to_cogl_texture (GdkPixbuf *pixbuf)
{
  return data_to_cogl_texture (gdk_pixbuf_get_pixels (pixbuf),
                               gdk_pixbuf_get_has_alpha (pixbuf),
                               gdk_pixbuf_get_width (pixbuf),
                               gdk_pixbuf_get_height (pixbuf),
                               gdk_pixbuf_get_rowstride (pixbuf));
}
Exemplo n.º 7
0
void		
gp_image_set_mask ( GpImage *image, GdkBitmap *mask )
{
	GdkPixbuf *pixbuf;
	GdkPixbuf *m_pixbuf;
	guchar *pixels, *m_pixels;
	guchar *p, *m_p;
	gint w, h;
	gint n_channels, rowstride;

	g_return_if_fail ( GP_IS_IMAGE (image) );
	

	pixbuf		=   image->priv->pixbuf;
	if(!gdk_pixbuf_get_has_alpha ( pixbuf ) )
	{  /*add alpha*/
		GdkPixbuf *tmp ;
		tmp = gdk_pixbuf_add_alpha(pixbuf, FALSE, 0, 0, 0);
		g_object_unref(pixbuf);
		pixbuf = tmp;
	}
	m_pixbuf	=   gdk_pixbuf_copy ( pixbuf );
	
	gdk_pixbuf_get_from_drawable (  m_pixbuf, 
               						mask,
               						gdk_drawable_get_colormap (mask),
               						0,0,
               						0,0,
              						-1,-1);
	n_channels  =   gdk_pixbuf_get_n_channels   ( pixbuf );
	rowstride   =   gdk_pixbuf_get_rowstride	( pixbuf );
	w			=   gdk_pixbuf_get_width		( pixbuf );
	h			=   gdk_pixbuf_get_height		( pixbuf );
	pixels		=   gdk_pixbuf_get_pixels		( pixbuf );
	m_pixels	=   gdk_pixbuf_get_pixels		( m_pixbuf );
	while (h--) 
	{
		guint   i = w;
		p   = pixels;
		m_p = m_pixels;
		while (i--) 
		{
			if(m_p[0] == 0)
			{
				p[0] = 0; 
				p[1] = 0; 
				p[2] = 0; 
				p[3] = 0; 
			}
			p   += n_channels;
			m_p += n_channels;
		}
		pixels		+= rowstride;
		m_pixels	+= rowstride;
	}
	g_object_unref (m_pixbuf);
}
Exemplo n.º 8
0
static void
load_animation (GInputStream *input_stream,
                CbMedia      *media)
{
  GdkPixbufAnimation *animation;
  GdkPixbuf *frame;
  GError *error = NULL;
  cairo_surface_t *surface;
  cairo_t *ct;
  gboolean has_alpha;

  animation = gdk_pixbuf_animation_new_from_stream (input_stream, NULL, &error);
  if (error)
    {
      g_warning ("Couldn't load pixbuf: %s (%s)", error->message, media->url);
      mark_invalid (media);
      g_error_free (error);
      return;
    }
  frame = gdk_pixbuf_animation_get_static_image (animation);

  if (!gdk_pixbuf_animation_is_static_image (animation))
    media->animation = animation; /* Takes ref */
  else
    media->animation = NULL;

  has_alpha = gdk_pixbuf_get_has_alpha (frame);

  surface = cairo_image_surface_create (has_alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
                                        gdk_pixbuf_get_width (frame),
                                        gdk_pixbuf_get_height (frame));

  ct = cairo_create (surface);
  gdk_cairo_set_source_pixbuf (ct, frame, 0.0, 0.0);
  cairo_paint (ct);
  cairo_destroy (ct);

  media->surface = surface;

  if (media->surface == NULL)
    {
      g_warning ("Surface of %p is null", media);
      mark_invalid (media);
      goto out;
    }

  media->width   = gdk_pixbuf_get_width (frame);
  media->height  = gdk_pixbuf_get_height (frame);
  media->loaded  = TRUE;
  media->invalid = FALSE;

out:
  if (media->animation == NULL)
    g_object_unref (animation);

  cb_media_loading_finished (media);
}
Exemplo n.º 9
0
/**
 * gtk_clutter_texture_set_from_pixbuf:
 * @texture: a #GtkClutterTexture
 * @pixbuf: a #GdkPixbuf
 * @error: a return location for errors
 *
 * Sets the contents of @texture with a copy of @pixbuf.
 *
 * Return value: %TRUE on success, %FALSE on failure.
 */
gboolean
gtk_clutter_texture_set_from_pixbuf (GtkClutterTexture  *texture,
                                     GdkPixbuf          *pixbuf,
                                     GError            **error)
{
  g_return_val_if_fail (GTK_CLUTTER_IS_TEXTURE (texture), FALSE);
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);

  return clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
                                            gdk_pixbuf_get_pixels (pixbuf),
                                            gdk_pixbuf_get_has_alpha (pixbuf),
                                            gdk_pixbuf_get_width (pixbuf),
                                            gdk_pixbuf_get_height (pixbuf),
                                            gdk_pixbuf_get_rowstride (pixbuf),
                                            gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3,
                                            0,
                                            error);
}
Exemplo n.º 10
0
gint
main (gint   argc,
      gchar *argv[])
{
   ClutterContent *image;
   ClutterActor *stage;
   ClutterActor *box;
   GdkPixbuf *pixbuf;

   if (clutter_init(&argc, &argv) != CLUTTER_INIT_SUCCESS) {
      g_printerr("Failed to initialize clutter.\n");
      return 1;
   }

   stage = clutter_stage_new();
   clutter_stage_set_title (CLUTTER_STAGE (stage), "Image Viewer");
   clutter_actor_set_size(stage, 1400, 1200);
   clutter_actor_set_position(stage, 100, 100);
   g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
   clutter_actor_show(stage);

   pixbuf = gdk_pixbuf_new_from_file("testimage_8000.png", NULL);
   g_assert(pixbuf);

   image = clutter_image_new();
   clutter_image_set_data(CLUTTER_IMAGE(image),
                          gdk_pixbuf_get_pixels(pixbuf),
                          gdk_pixbuf_get_has_alpha(pixbuf) ?
                             COGL_PIXEL_FORMAT_RGBA_8888 :
                             COGL_PIXEL_FORMAT_RGB_888,
                          gdk_pixbuf_get_width(pixbuf),
                          gdk_pixbuf_get_height(pixbuf),
                          gdk_pixbuf_get_rowstride(pixbuf),
                          NULL);
   g_object_unref(pixbuf);

   box = clutter_actor_new();
   clutter_actor_set_position(box, 0, 0);
   clutter_actor_set_height(box, 8000);
   clutter_actor_set_width(box, 1200);
   //clutter_actor_add_constraint(box, clutter_bind_constraint_new(stage, CLUTTER_BIND_WIDTH, 0.0));
   clutter_actor_set_content(box, image);
   clutter_actor_add_child(stage, box);
   clutter_actor_show(box);

   clutter_stage_set_fullscreen(CLUTTER_STAGE(stage), TRUE);

   clutter_actor_animate(box,
                         CLUTTER_EASE_IN_OUT_QUAD,
                         4000,
                         "y", -8000.0,
                         NULL);

   clutter_main();

   return 0;
}
Exemplo n.º 11
0
static gboolean rc_area_changed_cb(gpointer data)
{
	RendererClutter *rc = (RendererClutter *)data;
	PixbufRenderer *pr = rc->pr;

	RendererClutterAreaParam *par = rc->pending_updates->data;

	gint h = MAX_REGION_AREA / par->w;
	if (h == 0) h = 1;
	if (h > par->h) h = par->h;


	DEBUG_3("%s upload start", get_exec_time());
	if (pr->pixbuf)
		{
		CoglHandle texture = clutter_texture_get_cogl_texture(CLUTTER_TEXTURE(rc->texture));

		cogl_texture_set_region(texture,
					par->x + GET_RIGHT_PIXBUF_OFFSET(rc),
					par->y,
					par->x,
					par->y,
					par->w,
					h,
					par->w,
					h,
					gdk_pixbuf_get_has_alpha(pr->pixbuf) ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
					gdk_pixbuf_get_rowstride(pr->pixbuf),
					gdk_pixbuf_get_pixels(pr->pixbuf));
		}
	DEBUG_3("%s upload end", get_exec_time());
	rc_area_clip_add(rc, par->x, par->y, par->w, h);


	par->y += h;
	par->h -= h;

	if (par->h == 0)
		{
		rc->pending_updates = g_list_remove(rc->pending_updates, par);
		g_free(par);
		}
	if (!rc->pending_updates)
		{
		clutter_actor_queue_redraw(CLUTTER_ACTOR(rc->texture));
		rc->idle_update = 0;

		/* FIXME: find a better place for this */
		if (!rc->clut_updated) rc_prepare_post_process_lut(rc);

		return FALSE;
		}

	rc_schedule_texture_upload(rc);

	return FALSE; /* it was rescheduled, possibly with different prio */
}
Exemplo n.º 12
0
BitmapPtr BitmapLoader::load(const UTF8String& sFName, PixelFormat pf) const
{
    AVG_ASSERT(s_pBitmapLoader != 0);
    GError* pError = 0;
    GdkPixbuf* pPixBuf;
    {
        ScopeTimer timer(GDKPixbufProfilingZone);
        pPixBuf = gdk_pixbuf_new_from_file(sFName.c_str(), &pError);
    }
    if (!pPixBuf) {
        string sErr = pError->message;
        g_error_free(pError);
        throw Exception(AVG_ERR_FILEIO, sErr);
    }
    IntPoint size = IntPoint(gdk_pixbuf_get_width(pPixBuf), 
            gdk_pixbuf_get_height(pPixBuf));
    
    PixelFormat srcPF;
    if (gdk_pixbuf_get_has_alpha(pPixBuf)) {
        srcPF = R8G8B8A8;
    } else {
        srcPF = R8G8B8;
    }
    if (pf == NO_PIXELFORMAT) {
        if (m_bBlueFirst) {
            if (srcPF == R8G8B8A8) {
                pf = B8G8R8A8;
            } else if (srcPF == R8G8B8) {
                pf = B8G8R8X8;
            }
        } else {
            if (srcPF == R8G8B8A8) {
                pf = R8G8B8A8;
            } else if (srcPF == R8G8B8) {
                pf = R8G8B8X8;
            }
        }
    }
    BitmapPtr pBmp(new Bitmap(size, pf, sFName));
    {
        ScopeTimer timer(ConvertProfilingZone);

        int stride = gdk_pixbuf_get_rowstride(pPixBuf);
        guchar* pSrc = gdk_pixbuf_get_pixels(pPixBuf);
        BitmapPtr pSrcBmp(new Bitmap(size, srcPF, pSrc, stride, false));
        {
            ScopeTimer timer(RGBFlipProfilingZone);
            if (pixelFormatIsBlueFirst(pf) != pixelFormatIsBlueFirst(srcPF)) {
                FilterFlipRGB().applyInPlace(pSrcBmp);
            }
        }
        pBmp->copyPixels(*pSrcBmp);
    }
    g_object_unref(pPixBuf);
    return pBmp;
}
Exemplo n.º 13
0
static GdkPixbuf*
create_spotlight_pixbuf(GdkPixbuf *src, guint32 color, guchar alpha)
{
	GdkPixbuf *dest;
	int i, j;
	int width, height, has_alpha, src_row_stride, dst_row_stride;
	guchar *target_pixels, *original_pixels;
	guchar *pixsrc, *pixdest;
	guchar r, g, b;
	gint n_channels;

	n_channels = gdk_pixbuf_get_n_channels(src);
	has_alpha = gdk_pixbuf_get_has_alpha(src);
	width = gdk_pixbuf_get_width(src);
	height = gdk_pixbuf_get_height(src);

	g_return_val_if_fail(gdk_pixbuf_get_colorspace(src) ==
			     GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail((!has_alpha && n_channels == 3) ||
			     (has_alpha && n_channels == 4), NULL);
	g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(src) == 8, NULL);

	dest = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(src), has_alpha,
			       gdk_pixbuf_get_bits_per_sample(src),
			       width, height);
	
	dst_row_stride = gdk_pixbuf_get_rowstride(dest);
	src_row_stride = gdk_pixbuf_get_rowstride(src);
	target_pixels = gdk_pixbuf_get_pixels(dest);
	original_pixels = gdk_pixbuf_get_pixels(src);

	r = (color & 0xff0000) >> 16;
	g = (color & 0xff00) >> 8;
	b = color & 0xff;

	for (i = 0; i < height; i++)
	{
		gint tmp;

		pixdest = target_pixels + i * dst_row_stride;
		pixsrc = original_pixels + i * src_row_stride;
		for (j = 0; j < width; j++)
		{
			tmp = (*pixsrc++ * alpha + r * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			tmp = (*pixsrc++ * alpha + g * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			tmp = (*pixsrc++ * alpha + b * (255 - alpha)) / 255;
			*pixdest++ = (guchar) MIN(255, tmp);
			if (has_alpha)
				*pixdest++ = *pixsrc++;
		}
	}

	return dest;
}
Exemplo n.º 14
0
static nsresult
moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
                          nsIChannel **aChannel)
{
  int width = gdk_pixbuf_get_width(aPixbuf);
  int height = gdk_pixbuf_get_height(aPixbuf);
  NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0 &&
                 gdk_pixbuf_get_colorspace(aPixbuf) == GDK_COLORSPACE_RGB &&
                 gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                 gdk_pixbuf_get_has_alpha(aPixbuf) &&
                 gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                 NS_ERROR_UNEXPECTED);

  const int n_channels = 4;
  gsize buf_size = 3 + n_channels * height * width;
  PRUint8 * const buf = (PRUint8*)NS_Alloc(buf_size);
  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
  PRUint8 *out = buf;

  *(out++) = width;
  *(out++) = height;
  *(out++) = 8; // bits of alpha per pixel
  
  const guchar * const pixels = gdk_pixbuf_get_pixels(aPixbuf);
  int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;

  // encode the RGB data and the A data
  const guchar * in = pixels;
  PRUint8 *alpha_out = out + height * width * 3;
#ifdef DEBUG
  PRUint8 * const alpha_start = alpha_out;
#endif
  for (int y = 0; y < height; ++y, in += rowextra) {
    for (int x = 0; x < width; ++x) {
      *(out++) = *(in++); // R
      *(out++) = *(in++); // G
      *(out++) = *(in++); // B
      *(alpha_out++) = *(in++); // A
    }
  }

  NS_ASSERTION(out == alpha_start && alpha_out == buf + buf_size,
               "size miscalculation");

  nsresult rv;
  nsCOMPtr<nsIInputStream> stream;
  rv = NS_NewByteInputStream(getter_AddRefs(stream), (char*)buf, buf_size);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIStringInputStream> sstream = do_QueryInterface(stream);
  sstream->AdoptData((char*)buf, buf_size); // previous call was |ShareData|

  rv = NS_NewInputStreamChannel(aChannel, aURI, stream,
                                NS_LITERAL_CSTRING("image/icon"));
  return rv;
}
Exemplo n.º 15
0
static void put_bounding_box(GdkPixbuf *pixbuf, ImageInfo *ii)
{
    int i, width, height, rowstride, n_channels;
    guchar *pixels, *p;
    const int bb_width = get_big_image_width_sub();
    const int bb_height = get_big_image_height_sub();
    int ns = ii->ns;
    int nl = ii->nl;

    n_channels = gdk_pixbuf_get_n_channels (pixbuf);

    g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
    g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
    g_assert (!gdk_pixbuf_get_has_alpha (pixbuf));
    g_assert (n_channels == 3);

    width = gdk_pixbuf_get_width (pixbuf);
    height = gdk_pixbuf_get_height (pixbuf);

    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    pixels = gdk_pixbuf_get_pixels (pixbuf);

    int bb_min_x = (center_samp - bb_width*zoom/2) * width / ns;
    if (bb_min_x < 0) bb_min_x = 0;
    if (bb_min_x > width-1) bb_min_x = width-1;

    int bb_max_x = (center_samp + bb_width*zoom/2) * width / ns;
    if (bb_max_x < 0) bb_max_x = 0;
    if (bb_max_x > width-1) bb_max_x = width-1;

    int bb_min_y = (center_line - bb_height*zoom/2) * height / nl;
    if (bb_min_y < 0) bb_min_y = 0;
    if (bb_min_y > height-1) bb_min_y = height-1;

    int bb_max_y = (center_line + bb_height*zoom/2) * height / nl;
    if (bb_max_y < 0) bb_max_y = 0;
    if (bb_max_y > height-1) bb_max_y = height-1;

    for (i=bb_min_x; i<=bb_max_x; ++i) {
        p = pixels + bb_min_y * rowstride + i * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
        p = pixels + bb_max_y * rowstride + i * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
    }

    for (i=bb_min_y+1; i<bb_max_y; ++i) {
        p = pixels + i * rowstride + bb_min_x * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
        p = pixels + i * rowstride + bb_max_x * n_channels;
        p[0] = 255;
        p[1] = p[2] = 0;
    }
}
static CoglHandle
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
                       gboolean   add_padding)
{
  CoglHandle texture, offscreen;
  CoglColor clear_color;
  int width, height;
  guint size;

  width = gdk_pixbuf_get_width (pixbuf);
  height = gdk_pixbuf_get_height (pixbuf);
  size = MAX (width, height);

  if (!add_padding || width == height)
    return cogl_texture_new_from_data (width,
                                       height,
                                       COGL_TEXTURE_NONE,
                                       gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                                       COGL_PIXEL_FORMAT_ANY,
                                       gdk_pixbuf_get_rowstride (pixbuf),
                                       gdk_pixbuf_get_pixels (pixbuf));

  texture = cogl_texture_new_with_size (size, size,
                                        COGL_TEXTURE_NO_SLICING,
                                        COGL_PIXEL_FORMAT_ANY);

  offscreen = cogl_offscreen_new_to_texture (texture);
  cogl_color_set_from_4ub (&clear_color, 0, 0, 0, 0);
  cogl_push_framebuffer (offscreen);
  cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR);
  cogl_pop_framebuffer ();
  cogl_handle_unref (offscreen);

  cogl_texture_set_region (texture,
                           0, 0,
                           (size - width) / 2, (size - height) / 2,
                           width, height,
                           width, height,
                           gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                           gdk_pixbuf_get_rowstride (pixbuf),
                           gdk_pixbuf_get_pixels (pixbuf));
  return texture;
}
Exemplo n.º 17
0
static cairo_surface_t *
display_create_drm_surface_from_file(struct display *display,
				     const char *filename,
				     struct rectangle *rect)
{
	cairo_surface_t *surface;
	GdkPixbuf *pixbuf;
	GError *error = NULL;
	int stride, i;
	unsigned char *pixels, *p, *end;
	struct drm_surface_data *data;

	pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
						   rect->width, rect->height,
						   FALSE, &error);
	if (error != NULL)
		return NULL;

	if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
	    gdk_pixbuf_get_n_channels(pixbuf) != 4) {
		gdk_pixbuf_unref(pixbuf);
		return NULL;
	}


	stride = gdk_pixbuf_get_rowstride(pixbuf);
	pixels = gdk_pixbuf_get_pixels(pixbuf);

	for (i = 0; i < rect->height; i++) {
		p = pixels + i * stride;
		end = p + rect->width * 4;
		while (p < end) {
			unsigned int t;

			MULT(p[0], p[0], p[3], t);
			MULT(p[1], p[1], p[3], t);
			MULT(p[2], p[2], p[3], t);
			p += 4;

		}
	}

	surface = display_create_drm_surface(display, rect);
	data = cairo_surface_get_user_data(surface, &surface_data_key);

	cairo_device_acquire(display->device);
	glBindTexture(GL_TEXTURE_2D, data->texture);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect->width, rect->height,
			GL_RGBA, GL_UNSIGNED_BYTE, pixels);
	cairo_device_release(display->device);

	gdk_pixbuf_unref(pixbuf);

	return surface;
}
Exemplo n.º 18
0
static jobject dnd_target_get_image(JNIEnv *env)
{
    GdkPixbuf *buf;
    GInputStream *stream;
    jobject result = NULL;
    GdkAtom targets[] = {
        TARGET_MIME_PNG_ATOM,
        TARGET_MIME_JPEG_ATOM,
        TARGET_MIME_TIFF_ATOM,
        TARGET_MIME_BMP_ATOM,
        0};
    GdkAtom *cur_target = targets;
    selection_data_ctx ctx;

    while(*cur_target != 0 && result == NULL) {
        if (dnd_target_receive_data(env, *cur_target, &ctx)) {
            stream = g_memory_input_stream_new_from_data(ctx.data, ctx.length * (ctx.format / 8),
                    (GDestroyNotify)g_free);
            buf = gdk_pixbuf_new_from_stream(stream, NULL, NULL);
            if (buf) {
                int w;
                int h;
                int stride;
                guchar *data;
                jbyteArray data_array;
                jobject buffer;

                if (!gdk_pixbuf_get_has_alpha(buf)) {
                    GdkPixbuf *tmp_buf = gdk_pixbuf_add_alpha(buf, FALSE, 0, 0, 0);
                    g_object_unref(buf);
                    buf = tmp_buf;
                }
                
                w = gdk_pixbuf_get_width(buf);
                h = gdk_pixbuf_get_height(buf);
                stride = gdk_pixbuf_get_rowstride(buf);
                data = gdk_pixbuf_get_pixels(buf);

                //Actually, we are converting RGBA to BGRA, but that's the same operation
                data = (guchar*) convert_BGRA_to_RGBA((int*) data, stride, h);
                data_array = env->NewByteArray(stride * h);
                env->SetByteArrayRegion(data_array, 0, stride*h, (jbyte*) data);

                buffer = env->CallStaticObjectMethod(jByteBufferCls, jByteBufferWrap, data_array);
                result = env->NewObject(jGtkPixelsCls, jGtkPixelsInit, w, h, buffer);

                g_object_unref(buf);
                g_free(data); // data from convert_BGRA_to_RGBA
            }
            g_object_unref(stream);
        }
        ++cur_target;
    }
    return result;
}
Exemplo n.º 19
0
/**
 * gwy_gl_material_sample_to_pixbuf:
 * @gl_material: A GL material to sample.
 * @pixbuf: A pixbuf to sample gl_material to (in horizontal direction).
 *
 * Samples GL material to a provided pixbuf.
 **/
void
gwy_gl_material_sample_to_pixbuf(GwyGLMaterial *gl_material,
                                 GdkPixbuf *pixbuf)
{
    GwyGLMaterial *glm = gl_material;
    gint width, height, rowstride, i, j, bpp;
    gboolean has_alpha;
    guchar *row, *pdata;
    guchar alpha;
    gdouble p, q;

    g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material));
    g_return_if_fail(GDK_IS_PIXBUF(pixbuf));

    width = gdk_pixbuf_get_width(pixbuf);
    height = gdk_pixbuf_get_height(pixbuf);
    rowstride = gdk_pixbuf_get_rowstride(pixbuf);
    has_alpha = gdk_pixbuf_get_has_alpha(pixbuf);
    pdata = gdk_pixbuf_get_pixels(pixbuf);
    bpp = 3 + (has_alpha ? 1 : 0);

    q = (width == 1) ? 0.0 : 1.0/(width - 1.0);
    p = (height == 1) ? 0.0 : 1.0/(height - 1.0);
    alpha = (guchar)CLAMP(MAX_CVAL*glm->ambient.a, 0.0, 255.0);

    for (j = 0; j < width; j++) {
        gdouble VRp = j*q*(2.0 - j*q);
        gdouble s = pow(VRp, 128.0*glm->shininess);
        GwyRGBA s0;

        s0.r = glm->emission.r + 0.3*glm->ambient.r + glm->specular.r*s;
        s0.g = glm->emission.g + 0.3*glm->ambient.g + glm->specular.g*s;
        s0.b = glm->emission.b + 0.3*glm->ambient.b + glm->specular.b*s;

        for (i = 0; i < height; i++) {
            gdouble LNp = 1.0 - i*p;
            gdouble v;

            row = pdata + i*rowstride + j*bpp;

            v = s0.r + glm->diffuse.r*LNp;
            *(row++) = (guchar)CLAMP(MAX_CVAL*v, 0.0, 255.0);

            v = s0.g + glm->diffuse.g*LNp;
            *(row++) = (guchar)CLAMP(MAX_CVAL*v, 0.0, 255.0);

            v = s0.b + glm->diffuse.b*LNp;
            *(row++) = (guchar)CLAMP(MAX_CVAL*v, 0.0, 255.0);

            if (has_alpha)
                *(row++) = alpha;
        }
    }
}
/* Create and initalize global sticky notes instance */
void
stickynotes_applet_init (PanelApplet *panel_applet)
{
	stickynotes = g_new(StickyNotes, 1);

	stickynotes->notes = NULL;
	stickynotes->applets = NULL;
	stickynotes->last_timeout_data = 0;

	g_set_application_name (_("Sticky Notes"));

	/* Register size for icons */
	gtk_icon_size_register ("stickynotes_icon_size", 8,8);

	gtk_window_set_default_icon_name ("consort-sticky-notes-applet");

	stickynotes->icon_normal = gtk_icon_theme_load_icon (
			gtk_icon_theme_get_default (),
			"consort-sticky-notes-applet",
			48, 0, NULL);

	stickynotes->icon_prelight = gdk_pixbuf_new (
			gdk_pixbuf_get_colorspace (stickynotes->icon_normal),
			gdk_pixbuf_get_has_alpha (stickynotes->icon_normal),
			gdk_pixbuf_get_bits_per_sample (
				stickynotes->icon_normal),
			gdk_pixbuf_get_width (stickynotes->icon_normal),
			gdk_pixbuf_get_height (stickynotes->icon_normal));
	stickynotes_make_prelight_icon (stickynotes->icon_prelight,
			stickynotes->icon_normal, 30);
	stickynotes->gconf = gconf_client_get_default();
	stickynotes->visible = TRUE;

	stickynotes_applet_init_icons();
	stickynotes_applet_init_prefs();

	/* Watch GConf values */
	gconf_client_add_dir (stickynotes->gconf, GCONF_PATH,
			GCONF_CLIENT_PRELOAD_NONE, NULL);
	gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/defaults",
			(GConfClientNotifyFunc) preferences_apply_cb,
			NULL, NULL, NULL);
	gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/settings",
			(GConfClientNotifyFunc) preferences_apply_cb,
			NULL, NULL, NULL);

	/* Max height for large notes*/
	stickynotes->max_height = 0.8*gdk_screen_get_height( gdk_screen_get_default() );

	/* Load sticky notes */
	stickynotes_load (gtk_widget_get_screen (GTK_WIDGET (panel_applet)));

	install_check_click_on_desktop ();
}
Exemplo n.º 21
0
/*
 * Returns a copy of pixbuf src rotated 90 degrees clockwise or 90 counterclockwise
 */
void rotate90(GdkPixbuf *dest, const GdkPixbuf *src, int sw, int sh, bool counter_clockwise) {
	gint has_alpha;
	//gint sw, sh, srs;
	gint srs;
	gint drs;
	guchar *s_pix;
	guchar *d_pix;
	gint i, j;
	gint a;
	//GdkPixbuf *buffer;
	guchar *b_pix;
	gint brs;
	gint w, h;

	if (src == 0)
		return;

	//sw = gdk_pixbuf_get_width(src);
	//sh = gdk_pixbuf_get_height(src);
	has_alpha = gdk_pixbuf_get_has_alpha(src);
	srs = gdk_pixbuf_get_rowstride(src);
	s_pix = gdk_pixbuf_get_pixels(src);

	drs = gdk_pixbuf_get_rowstride(dest);
	d_pix = gdk_pixbuf_get_pixels(dest);

	a = has_alpha ? 4 : 3;

	if (buffer == 0) {
		buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, has_alpha, 8, ROTATE_BUFFER_WIDTH, ROTATE_BUFFER_HEIGHT);
	}
	b_pix = gdk_pixbuf_get_pixels(buffer);
	brs = gdk_pixbuf_get_rowstride(buffer);

	for (i = 0; i < sh; i+= ROTATE_BUFFER_WIDTH) {
		w = MIN(ROTATE_BUFFER_WIDTH, sh - i);
		for (j = 0; j < sw; j += ROTATE_BUFFER_HEIGHT) {
			gint x, y;

			h = MIN(ROTATE_BUFFER_HEIGHT, sw - j);
			pixbuf_copy_block_rotate(s_pix, srs, j, i, b_pix, brs, h, w, a, counter_clockwise);

			if (counter_clockwise) {
				x = i;
				y = sw - h - j;
			} else {
				x = sh - w - i;
				y = j;
			}

			pixbuf_copy_block(b_pix, brs, w, h, d_pix, drs, x, y, a);
		}
	}
}
Exemplo n.º 22
0
static CoglHandle
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf,
                       gboolean   add_padding)
{
  return data_to_cogl_handle (gdk_pixbuf_get_pixels (pixbuf),
                              gdk_pixbuf_get_has_alpha (pixbuf),
                              gdk_pixbuf_get_width (pixbuf),
                              gdk_pixbuf_get_height (pixbuf),
                              gdk_pixbuf_get_rowstride (pixbuf),
                              add_padding);
}
Exemplo n.º 23
0
void rotate180(GdkPixbuf *buffer) {
	if (buffer == 0)
		return;

	const gint width = gdk_pixbuf_get_width(buffer);
	if (width <= 1) {
		return;
	}
	const gint height = gdk_pixbuf_get_height(buffer);
	const gint brs = gdk_pixbuf_get_rowstride(buffer);
	guchar *s_pix = gdk_pixbuf_get_pixels(buffer);
	guchar *d_pix = s_pix + (height - 1) * brs;

	const gint a = gdk_pixbuf_get_has_alpha(buffer) ? 4 : 3;

	guchar * const sbuf = new guchar[width * a];
	guchar * const dbuf = new guchar[width * a];
	guchar * const tmp = new guchar[a];

	while (s_pix < d_pix) {
		memcpy(sbuf, s_pix, width * a);
		memcpy(dbuf, d_pix, width * a);
		guchar *s = sbuf;
		guchar *d = dbuf + (width - 1) * a;
		for (int i = 0; i < width; ++i) {
			memcpy(tmp, s, a);
			memcpy(s, d, a);
			memcpy(d, tmp, a);
			s += a;
			d -= a;
		}
		memcpy(s_pix, sbuf, width * a);
		memcpy(d_pix, dbuf, width * a);
		s_pix += brs;
		d_pix -= brs;
	}
	if (s_pix == d_pix) {
		memcpy(sbuf, s_pix, width * a);
		guchar *s = sbuf;
		guchar *d = sbuf + (width - 1) * a;
		while (s < d) {
			memcpy(tmp, s, a);
			memcpy(s, d, a);
			memcpy(d, tmp, a);
			s += a;
			d -= a;
		}
		memcpy(s_pix, sbuf, width * a);
	}

	delete[] sbuf;
	delete[] dbuf;
	delete[] tmp;
}
Exemplo n.º 24
0
static CoglHandle
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf)
{
  return cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
                                     gdk_pixbuf_get_height (pixbuf),
                                     COGL_TEXTURE_NONE,
                                     gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                                     COGL_PIXEL_FORMAT_ANY,
                                     gdk_pixbuf_get_rowstride (pixbuf),
                                     gdk_pixbuf_get_pixels (pixbuf));
}
Exemplo n.º 25
0
/**
 * eel_gdk_pixbuf_new_from_pixbuf_sub_area:
 * @pixbuf: The source pixbuf.
 * @area: The area within the source pixbuf to use for the sub pixbuf.
 *        This area needs to be contained within the bounds of the
 *        source pixbuf, otherwise it will be clipped to that.
 *
 * Return value: A newly allocated pixbuf that shares the pixel data
 *               of the source pixbuf in order to represent a sub area.
 *
 * Create a pixbuf from a sub area of another pixbuf.  The resulting pixbuf
 * will share the pixel data of the source pixbuf.  Memory bookeeping is
 * all taken care for the caller.  All you need to do is g_object_unref()
 * the resulting pixbuf to properly free resources.
 */
GdkPixbuf *
eel_gdk_pixbuf_new_from_pixbuf_sub_area (GdkPixbuf *pixbuf,
        EelIRect area)
{
    GdkPixbuf *sub_pixbuf;
    EelIRect target;
    guchar *pixels;

    g_return_val_if_fail (eel_gdk_pixbuf_is_valid (pixbuf), NULL);
    g_return_val_if_fail (!eel_irect_is_empty (&area), NULL);

    /* Clip the pixbuf by the given area; bail if no work */
    target = eel_gdk_pixbuf_intersect (pixbuf, 0, 0, area);
    if (eel_irect_is_empty (&target))
    {
        return NULL;
    }

    /* Since we are going to be sharing the given pixbuf's data, we need
     * to ref it.  It will be unreffed in the destroy function above */
    g_object_ref (pixbuf);

    /* Compute the offset into the pixel data */
    pixels =
        gdk_pixbuf_get_pixels (pixbuf)
        + (target.y0 * gdk_pixbuf_get_rowstride (pixbuf))
        + (target.x0 * (gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3));

    /* Make a pixbuf pretending its real estate is the sub area */
    sub_pixbuf = gdk_pixbuf_new_from_data (pixels,
                                           GDK_COLORSPACE_RGB,
                                           gdk_pixbuf_get_has_alpha (pixbuf),
                                           8,
                                           eel_irect_get_width (target),
                                           eel_irect_get_height (target),
                                           gdk_pixbuf_get_rowstride (pixbuf),
                                           pixbuf_destroy_callback,
                                           pixbuf);

    return sub_pixbuf;
}
Exemplo n.º 26
0
static cairo_surface_t *
display_create_shm_surface_from_file(struct display *display,
				     const char *filename,
				     struct rectangle *rect)
{
	cairo_surface_t *surface;
	GdkPixbuf *pixbuf;
	GError *error = NULL;
	int stride, i;
	unsigned char *pixels, *p, *end, *dest_data;
	int dest_stride;
	uint32_t *d;

	pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
						   rect->width, rect->height,
						   FALSE, &error);
	if (error != NULL)
		return NULL;

	if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
	    gdk_pixbuf_get_n_channels(pixbuf) != 4) {
		gdk_pixbuf_unref(pixbuf);
		return NULL;
	}

	stride = gdk_pixbuf_get_rowstride(pixbuf);
	pixels = gdk_pixbuf_get_pixels(pixbuf);

	surface = display_create_shm_surface(display, rect);
	dest_data = cairo_image_surface_get_data (surface);
	dest_stride = cairo_image_surface_get_stride (surface);

	for (i = 0; i < rect->height; i++) {
		d = (uint32_t *) (dest_data + i * dest_stride);
		p = pixels + i * stride;
		end = p + rect->width * 4;
		while (p < end) {
			unsigned int t;
			unsigned char a, r, g, b;

			a = p[3];
			MULT(r, p[0], a, t);
			MULT(g, p[1], a, t);
			MULT(b, p[2], a, t);
			p += 4;
			*d++ = (a << 24) | (r << 16) | (g << 8) | b;
		}
	}

	gdk_pixbuf_unref(pixbuf);

	return surface;
}
GdkPixbuf *
eel_create_spotlight_pixbuf (GdkPixbuf* src)
{
	GdkPixbuf *dest;
	int i, j;
	int width, height, has_alpha, src_row_stride, dst_row_stride;
	guchar *target_pixels, *original_pixels;
	guchar *pixsrc, *pixdest;

	g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
			       && gdk_pixbuf_get_n_channels (src) == 3)
			      || (gdk_pixbuf_get_has_alpha (src)
				  && gdk_pixbuf_get_n_channels (src) == 4), NULL);
	g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);

	dest = create_new_pixbuf (src);
	
	has_alpha = gdk_pixbuf_get_has_alpha (src);
	width = gdk_pixbuf_get_width (src);
	height = gdk_pixbuf_get_height (src);
	dst_row_stride = gdk_pixbuf_get_rowstride (dest);
	src_row_stride = gdk_pixbuf_get_rowstride (src);
	target_pixels = gdk_pixbuf_get_pixels (dest);
	original_pixels = gdk_pixbuf_get_pixels (src);

	for (i = 0; i < height; i++) {
		pixdest = target_pixels + i * dst_row_stride;
		pixsrc = original_pixels + i * src_row_stride;
		for (j = 0; j < width; j++) {		
			*pixdest++ = lighten_component (*pixsrc++);
			*pixdest++ = lighten_component (*pixsrc++);
			*pixdest++ = lighten_component (*pixsrc++);
			if (has_alpha) {
				*pixdest++ = *pixsrc++;
			}
		}
	}
	return dest;
}
static void flip_pixbuf (GdkPixbuf *pixbuf,
                         jboolean flip_x,
                         jboolean flip_y,
                         jint width,
                         jint height)
{
  gint src_rs;
  guchar *src_pix;

  src_rs = gdk_pixbuf_get_rowstride (pixbuf);
  src_pix = gdk_pixbuf_get_pixels (pixbuf);

  if (flip_x) 
    {
      gint i, channels;
      guchar buf[4];

      channels = gdk_pixbuf_get_has_alpha (pixbuf) ? 4 : 3;

      for (i = 0; i < height; i++) 
        {
          guchar *left = src_pix + i * src_rs;
          guchar *right = left + channels * (width - 1);
          while (left < right)
            { 
              g_memmove (buf, left, channels);
              g_memmove (left, right, channels);
              g_memmove (right, buf, channels);
              left += channels;
              right -= channels;
            }
        }
    }

  if (flip_y) 
    {
      guchar *top = src_pix;
      guchar *bottom = top + (height - 1) * src_rs;
      gpointer buf = g_malloc (src_rs);
      
      while (top < bottom)
        {
          g_memmove (buf, top, src_rs);
          g_memmove (top, bottom, src_rs);
          g_memmove (bottom, buf, src_rs); 
          top += src_rs;
          bottom -= src_rs;
        }

      g_free (buf);
    }
}
Exemplo n.º 29
0
static void 
opt_show_set_property (GObject      *object, 
		       guint         prop_id,
		       const GValue *value, 
		       GParamSpec   *pspec)
{

  OptShow *show = OPT_SHOW(object);
  OptShowPrivate *priv;

  priv = show->priv;

  switch (prop_id) 
    {
    case PROP_TITLE_BORDER_SIZE:
      priv->title_border_size = g_value_get_int (value);
      break;
    case PROP_TITLE_BULLET_PAD:
      priv->title_bullet_pad = g_value_get_int (value);
      break;
    case PROP_BULLET_BORDER_SIZE:
      priv->bullet_border_size = g_value_get_int (value);
      break;
    case PROP_BULLET_PAD:
      priv->bullet_pad = g_value_get_int (value);
      break;
    case PROP_TITLE_FONT:
      if (priv->title_font) g_free (priv->title_font);
      priv->title_font = g_value_dup_string (value);
      break;
    case PROP_BULLET_FONT:
      if (priv->bullet_font) g_free (priv->bullet_font);
      priv->bullet_font = g_value_dup_string (value);
      break;
    case PROP_BACKGROUND:
      priv->background = g_value_get_object (value);

      clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (priv->bg),
                                         gdk_pixbuf_get_pixels (priv->background),
                                         gdk_pixbuf_get_has_alpha (priv->background),
                                         gdk_pixbuf_get_width (priv->background),
                                         gdk_pixbuf_get_height (priv->background),
                                         gdk_pixbuf_get_rowstride (priv->background),
                                         gdk_pixbuf_get_n_channels (priv->background), 
                                         0,
                                         NULL);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}
Exemplo n.º 30
0
static Image* LoadImage (ArchiveFile& file, const char *extension)
{
	RGBAImage* image = (RGBAImage *) 0;

	/* load the buffer from pk3 or filesystem */
	ScopedArchiveBuffer buffer(file);

	GdkPixbufLoader *loader = gdk_pixbuf_loader_new_with_type(extension, (GError**) 0);
	if (loader == (GdkPixbufLoader*)0) {
		g_warning("could not get a loader for: '%s'\n", extension);
		return image;
	}

	GError *error = (GError *) 0;
	if (gdk_pixbuf_loader_write(loader, (const guchar *) buffer.buffer, static_cast<gsize> (buffer.length),
			&error)) {
		int pos = 0;
		GdkPixbuf *pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
		const int width = gdk_pixbuf_get_width(pixbuf);
		const int height = gdk_pixbuf_get_height(pixbuf);
		const gboolean hasAlpha = gdk_pixbuf_get_has_alpha(pixbuf);
		const int stepWidth = gdk_pixbuf_get_n_channels(pixbuf);
		const guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);

		image = new RGBAImage(width, height, false);
		byte *rgba = image->getRGBAPixels();
		const int rowextra = gdk_pixbuf_get_rowstride(pixbuf) - width * stepWidth;

		for (int y = 0; y < height; ++y, pixels += rowextra) {
			for (int x = 0; x < width; ++x) {
				rgba[pos++] = *(pixels++);
				rgba[pos++] = *(pixels++);
				rgba[pos++] = *(pixels++);
				if (hasAlpha && *pixels != 255)
					image->setHasAlpha(true);
				rgba[pos++] = hasAlpha ? *(pixels++) : 255;
			}
		}

		g_object_unref(pixbuf);
	} else {
		g_warning("image could not get loaded: '%s' %s\n",
				file.getName().c_str(), (error != (GError *) 0) ? error->message : "");
		if (error)
			g_error_free(error);
	}

	gdk_pixbuf_loader_close(loader, (GError**) 0);

	return image;
}