Esempio n. 1
0
cairo_surface_t *
ink_cairo_surface_create_for_argb32_pixbuf(GdkPixbuf *pb)
{
    guchar *data = gdk_pixbuf_get_pixels(pb);
    int w = gdk_pixbuf_get_width(pb);
    int h = gdk_pixbuf_get_height(pb);
    int stride = gdk_pixbuf_get_rowstride(pb);

    cairo_surface_t *pbs = cairo_image_surface_create_for_data(
        data, CAIRO_FORMAT_ARGB32, w, h, stride);
    return pbs;
}
Esempio n. 2
0
static gboolean
pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2)
{
  if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2))
    return FALSE;
  if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2))
    return FALSE;
  if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2))
    return FALSE;
  if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2))
    return FALSE;
  if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2))
    return FALSE;
  if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2))
    return FALSE;
  if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2),
          gdk_pixbuf_get_byte_length (p1)) != 0)
    return FALSE;

  return TRUE;
}
Esempio n. 3
0
/** Create a pixbuf from a GdkPixbuf.
 * The constructor takes ownership of the passed GdkPixbuf reference,
 * so it should not be unrefed. */
Pixbuf::Pixbuf(GdkPixbuf *pb)
    : _pixbuf(pb)
    , _surface(0)
    , _mod_time(0)
    , _pixel_format(PF_GDK)
    , _cairo_store(false)
{
    _forceAlpha();
    _surface = cairo_image_surface_create_for_data(
        gdk_pixbuf_get_pixels(_pixbuf), CAIRO_FORMAT_ARGB32,
        gdk_pixbuf_get_width(_pixbuf), gdk_pixbuf_get_height(_pixbuf), gdk_pixbuf_get_rowstride(_pixbuf));
}
/**
 * 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;
	}
}
Esempio n. 5
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;
}
Esempio n. 7
0
/* Started from from http://www.gtkforums.com/about5204.html
 * Author: tadeboro */
GdkPixbuf *
_gdk_pixbuf_new_from_cairo_surface (cairo_surface_t *surface)
{
	int            width;
	int            height;
	int            s_stride;
	unsigned char *s_pixels;
	GdkPixbuf     *pixbuf;
	int            p_stride;
	guchar        *p_pixels;
	int            p_n_channels;

	if (surface == NULL)
		return NULL;

	if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
		return NULL;

	width = cairo_image_surface_get_width (surface);
	height = cairo_image_surface_get_height (surface);
	s_stride = cairo_image_surface_get_stride (surface);
	s_pixels = _cairo_image_surface_flush_and_get_data (surface);

	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, _cairo_image_surface_get_has_alpha (surface), 8, width, height);
	p_stride = gdk_pixbuf_get_rowstride (pixbuf);
	p_pixels = gdk_pixbuf_get_pixels (pixbuf);
	p_n_channels = gdk_pixbuf_get_n_channels (pixbuf);

	while (height--) {
		guchar *s_iter = s_pixels;
	        guchar *p_iter = p_pixels;
	        int     i;

	        for (i = 0; i < width; i++) {
	        	gdouble alpha_factor = (gdouble) 0xff / s_iter[CAIRO_ALPHA];

	        	p_iter[0] = (guchar) (alpha_factor * s_iter[CAIRO_RED]  + .5);
	        	p_iter[1] = (guchar) (alpha_factor * s_iter[CAIRO_GREEN] + .5);
	        	p_iter[2] = (guchar) (alpha_factor * s_iter[CAIRO_BLUE] + .5);
	        	if (p_n_channels == 4)
	        		p_iter[3] = s_iter[CAIRO_ALPHA];

	        	s_iter += 4;
	        	p_iter += p_n_channels;
		}

		s_pixels += s_stride;
		p_pixels += p_stride;
	}

	return pixbuf;
}
Esempio n. 8
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;
    }
}
Esempio n. 9
0
GdkPixbuf* BitmapImage::getGdkPixbuf()
{
    int width = cairo_image_surface_get_width(frameAtIndex(currentFrame()));
    int height = cairo_image_surface_get_height(frameAtIndex(currentFrame()));
    unsigned char* surfaceData = cairo_image_surface_get_data(frameAtIndex(currentFrame()));
    int surfaceRowStride = cairo_image_surface_get_stride(frameAtIndex(currentFrame()));

    GdkPixbuf* dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
    if (!dest)
        return 0;

    guchar* pixbufData = gdk_pixbuf_get_pixels(dest);
    int pixbufRowStride = gdk_pixbuf_get_rowstride(dest);

    /* From: http://cairographics.org/manual/cairo-image-surface.html#cairo-format-t
     * "CAIRO_FORMAT_ARGB32: each pixel is a 32-bit quantity, with alpha in
     * the upper 8 bits, then red, then green, then blue. The 32-bit
     * quantities are stored native-endian. Pre-multiplied alpha is used.
     * (That is, 50% transparent red is 0x80800000, not 0x80ff0000.)"
     *
     * See http://developer.gimp.org/api/2.0/gdk-pixbuf/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf
     * for information on the structure of GdkPixbufs stored with GDK_COLORSPACE_RGB.
     *
     * RGB color channels in CAIRO_FORMAT_ARGB32 are stored based on the
     * endianness of the machine and are also multiplied by the alpha channel.
     * To properly transfer the data from the Cairo surface we must divide each
     * of the RGB channels by the alpha channel and then reorder all channels
     * if this machine is little-endian.
     */
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            unsigned char* source = getCairoSurfacePixel(surfaceData, x, y, surfaceRowStride);
            guchar* dest = getGdkPixbufPixel(pixbufData, x, y, pixbufRowStride);

#if G_BYTE_ORDER == G_LITTLE_ENDIAN
            guchar alpha = source[3];
            dest[0] = alpha ? ((source[2] * 255) / alpha) : 0;
            dest[1] = alpha ? ((source[1] * 255) / alpha) : 0;
            dest[2] = alpha ? ((source[0] * 255) / alpha) : 0;
            dest[3] = alpha;
#else
            guchar alpha = source[0];
            dest[0] = alpha ? ((source[1] * 255) / alpha) : 0;
            dest[1] = alpha ? ((source[2] * 255) / alpha) : 0;
            dest[2] = alpha ? ((source[3] * 255) / alpha) : 0;
            dest[3] = alpha;
#endif
        }
    }

    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);
    }
}
Esempio n. 11
0
int main(int argc, char** argv)
{
    GtkWidget *window;
	int x, y;

    gtk_init(&argc, &argv);

   /* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_opacity(window, 0.7);
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), "pressed");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_show(window);
    gtk_main();
	*/
	GdkPixbuf* photo = gdk_pixbuf_new_from_file_at_size("bluesky.jpg", 300, 200, NULL);
	//GdkPixbuf* image = gdk_pixbuf_new_from_data(photo,;
	//photo = gdk_pixbuf_flip(photo, FALSE);
	//gdk_pixbuf_fill(photo, 0xff00ff64);
	//gdk_pixbuf_rotate_simple(photo, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
	//gdk_pixbuf_save(photo, "thumbnail.png", "png", NULL, NULL);
	guchar *pixels, *p;
	int rowstride, n_channels, bits, width, height ;
	GdkColorspace cs;

	n_channels = gdk_pixbuf_get_n_channels(photo);
	rowstride = gdk_pixbuf_get_rowstride(photo);
	pixels = gdk_pixbuf_get_pixels(photo);
	bits = gdk_pixbuf_get_bits_per_sample(photo);
	cs = gdk_pixbuf_get_colorspace(photo);
	width = gdk_pixbuf_get_width(photo);
	height = gdk_pixbuf_get_height(photo);
	printf("n_channels %d\n", n_channels);
	printf("rowstride %d\n", rowstride);
	printf("bits %d\n", bits);
	printf("cs %d\n", cs);
	printf("width %d\n", width);
	printf("height %d\n", height);

	//photo = gdk_pixbuf_new_from_data(pixels, cs, TRUE, bits, width, height, rowstride, NULL, NULL);
	//gdk_pixbuf_add_alpha(photo, FALSE, 0, 0, 0);

	for(x = 0; x < width; x++)
	{
		for(y = 0; y < height; y++)
		{
			put_pixel(photo, x, y, 100);
		}
	}
	gdk_pixbuf_save(photo, "thumbnail.jpg", "jpeg", NULL, NULL);

    return 0;
}
Esempio n. 12
0
/**
 * is_pixel_alpha:
 **/
static gboolean
is_pixel_alpha (GdkPixbuf *pixbuf, guint x, guint y)
{
	gint rowstride, n_channels;
	guchar *pixels, *p;

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

	p = pixels + y * rowstride + x * n_channels;
	return p[3] == 0;
}
Esempio n. 13
0
Pixbuf::Pixbuf()
{
    _width = 500;
    _height = 500;

    _ref = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, _width, _height);
    gdk_pixbuf_fill(_ref, 0xffffffff );
    _scale = 1;

    n_channels = gdk_pixbuf_get_n_channels(_ref);
    rowstride = gdk_pixbuf_get_rowstride(_ref);
    pixels = gdk_pixbuf_get_pixels(_ref);
};
Esempio n. 14
0
/* ----------------------------------------------------
 * p_create_desaturated_buf_from_pixbuf
 * ----------------------------------------------------
 */
static void
p_create_desaturated_buf_from_pixbuf(GapPView *pv_ptr)
{  

  pv_ptr->pv_desaturated_area_data = g_new ( guchar
                                      , pv_ptr->pv_height * pv_ptr->pv_width * pv_ptr->pv_bpp );

  p_desaturate(pv_ptr
             , gdk_pixbuf_get_pixels(pv_ptr->pixbuf)
             , gdk_pixbuf_get_rowstride(pv_ptr->pixbuf)
             );

}  /* end p_create_desaturated_buf_from_pixbuf */
Esempio n. 15
0
void
test_inspect (void)
{
    const gchar *expected;
    pixbuf1 = load_pixbuf("dark-circle.png");
    pixbuf2 = load_pixbuf("small-circle-no-alpha.png");

    expected = cut_take_printf("#<GdkPixbuf:%p "
                               "colorspace="
                               "<#<GdkColorspace: rgb(GDK_COLORSPACE_RGB:0)>>, "
                               "n-channels=<4>, "
                               "has-alpha=<TRUE>, "
                               "bits-per-sample=<8>, "
                               "width=<100>, "
                               "height=<100>, "
                               "rowstride=<400>, "
                               "pixels=<((gpointer) %p)>"
                               ">",
                               pixbuf1,
                               gdk_pixbuf_get_pixels(pixbuf1));
    cut_assert_equal_string_with_free(expected,
                                      gcut_object_inspect(G_OBJECT(pixbuf1)));

    expected = cut_take_printf("#<GdkPixbuf:%p "
                               "colorspace="
                               "<#<GdkColorspace: rgb(GDK_COLORSPACE_RGB:0)>>, "
                               "n-channels=<3>, "
                               "has-alpha=<FALSE>, "
                               "bits-per-sample=<8>, "
                               "width=<50>, "
                               "height=<50>, "
                               "rowstride=<152>, "
                               "pixels=<((gpointer) %p)>"
                               ">",
                               pixbuf2,
                               gdk_pixbuf_get_pixels(pixbuf2));
    cut_assert_equal_string_with_free(expected,
                                      gcut_object_inspect(G_OBJECT(pixbuf2)));
}
/**
 * games_card_textures_cache_get_card_texture_by_id:
 * @cache:
 * @card_id:
 *
 * Returns: a cached #CoglHandle for @card_id.
 */
CoglHandle
games_card_textures_cache_get_card_texture_by_id (GamesCardTexturesCache *cache,
                                                  guint card_id)
{
  GamesCardTexturesCachePrivate *priv = cache->priv;
  CoglHandle handle;

  g_return_val_if_fail (card_id < GAMES_CARDS_TOTAL , NULL);

  LOG_CALL (cache);

  handle = priv->cards[card_id];
  if (IS_FAILED_HANDLE (handle)) {
    LOG_CACHE_HIT (cache);
    return COGL_INVALID_HANDLE;
  }

  if (handle == COGL_INVALID_HANDLE) {
    GdkPixbuf *pixbuf;

    LOG_CACHE_MISS (cache);

    pixbuf = games_card_theme_get_card_pixbuf (priv->theme, card_id);
    if (!pixbuf) {
      priv->cards[card_id] = FAILED_HANDLE;
      return COGL_INVALID_HANDLE;
    }

    handle = cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
                                         gdk_pixbuf_get_height (pixbuf),
                                         64, FALSE,
                                         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));
    g_object_unref (pixbuf);

    if (handle == COGL_INVALID_HANDLE) {
      priv->cards[card_id] = FAILED_HANDLE;
      return COGL_INVALID_HANDLE;
    }

    priv->cards[card_id] = handle;
  } else {
    LOG_CACHE_HIT (cache);
  }

  return handle;
}
Esempio n. 17
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;
}
Esempio n. 18
0
void HudIconTextureSource::ColorForIcon(GdkPixbuf* pixbuf)
{
  if (GDK_IS_PIXBUF(pixbuf))
  {
    unsigned int width = gdk_pixbuf_get_width(pixbuf);
    unsigned int height = gdk_pixbuf_get_height(pixbuf);
    unsigned int row_bytes = gdk_pixbuf_get_rowstride(pixbuf);
    
    long int rtotal = 0, gtotal = 0, btotal = 0;
    float total = 0.0f;
    
    guchar* img = gdk_pixbuf_get_pixels(pixbuf);
    
    for (unsigned int i = 0; i < width; i++)
    {
      for (unsigned int j = 0; j < height; j++)
      {
        guchar* pixels = img + (j * row_bytes + i * 4);
        guchar r = *(pixels + 0);
        guchar g = *(pixels + 1);
        guchar b = *(pixels + 2);
        guchar a = *(pixels + 3);
        
        float saturation = (MAX(r, MAX(g, b)) - MIN(r, MIN(g, b))) / 255.0f;
        float relevance = .1 + .9 * (a / 255.0f) * saturation;
        
        rtotal += (guchar)(r * relevance);
        gtotal += (guchar)(g * relevance);
        btotal += (guchar)(b * relevance);
        
        total += relevance * 255;
      }
    }
    
    nux::color::RedGreenBlue rgb(rtotal / total,
                                 gtotal / total,
                                 btotal / total);
    nux::color::HueSaturationValue hsv(rgb);
    
    if (hsv.saturation > 0.15f)
      hsv.saturation = 0.65f;
    
    hsv.value = 0.90f;
    bg_color = nux::Color(nux::color::RedGreenBlue(hsv));
  }
  else
  {
    LOG_ERROR(logger) << "Pixbuf (" << pixbuf << ") passed is non valid";
    bg_color = nux::Color(255,255,255,255);
  }
}
Esempio n. 19
0
void CriaQuadTree(node **raiz, GdkPixbuf *imagem) {
    if ( cor_uniforme(imagem) ) {
        guchar *pixels = gdk_pixbuf_get_pixels (imagem);
        guint32 pixel;
        pixel = (
                    pixels[0] << 24 |
                    pixels[1] << 16 |
                    pixels[2] <<  8
                );
        (*raiz)->cor = pixel;
        (*raiz)->width = gdk_pixbuf_get_width (imagem);
        (*raiz)->height = gdk_pixbuf_get_height (imagem);        
    }
    else {
        node *ES = new_node();
        node *EI = new_node();
        node *DS = new_node();
        node *DI = new_node();
        (*raiz)->EsqInferior = EI;
        (*raiz)->EsqSuperior = ES;        
        (*raiz)->DirInferior = DI;
        (*raiz)->DirSuperior = DS;
        (*raiz)->width = gdk_pixbuf_get_width (imagem);
        (*raiz)->height = gdk_pixbuf_get_height (imagem);        
        
        int width_total = gdk_pixbuf_get_width (imagem);
        int height_total = gdk_pixbuf_get_height (imagem);
        int width_ES = width_total/2;
        int height_ES = height_total/2;                        
        
        GdkPixbuf *subpixbuf = gdk_pixbuf_new_subpixbuf (imagem, 0, 0, 
                                                         width_ES, 
                                                         height_ES);
        CriaQuadTree(&ES, subpixbuf);
       
        subpixbuf = gdk_pixbuf_new_subpixbuf (imagem, 0, height_ES,
                                              width_ES,
                                              height_total - height_ES);
        CriaQuadTree(&EI, subpixbuf);
        
        subpixbuf = gdk_pixbuf_new_subpixbuf (imagem, width_ES, 0, 
                                              width_total - width_ES,
                                              height_ES);
        CriaQuadTree(&DS, subpixbuf);                
        
        subpixbuf = gdk_pixbuf_new_subpixbuf (imagem, width_ES, height_ES,
                                              width_total - width_ES,
                                              height_total - height_ES);        
        CriaQuadTree(&DI, subpixbuf);
    }
}
Esempio n. 20
0
/* colorshift a pixbuf */
static void
do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift)
{
	gint i, j;
	gint width, height, has_alpha, srcrowstride, destrowstride;
	guchar *target_pixels;
	guchar *original_pixels;
	guchar *pixsrc;
	guchar *pixdest;
	int val;
	guchar r,g,b;

	has_alpha = gdk_pixbuf_get_has_alpha (src);
	width = gdk_pixbuf_get_width (src);
	height = gdk_pixbuf_get_height (src);
	srcrowstride = gdk_pixbuf_get_rowstride (src);
	destrowstride = gdk_pixbuf_get_rowstride (dest);
	target_pixels = gdk_pixbuf_get_pixels (dest);
	original_pixels = gdk_pixbuf_get_pixels (src);

	for (i = 0; i < height; i++) {
		pixdest = target_pixels + i*destrowstride;
		pixsrc = original_pixels + i*srcrowstride;
		for (j = 0; j < width; j++) {
			r = *(pixsrc++);
			g = *(pixsrc++);
			b = *(pixsrc++);
			val = r + shift;
			*(pixdest++) = CLAMP(val, 0, 255);
			val = g + shift;
			*(pixdest++) = CLAMP(val, 0, 255);
			val = b + shift;
			*(pixdest++) = CLAMP(val, 0, 255);
			if (has_alpha)
				*(pixdest++) = *(pixsrc++);
		}
	}
}
Esempio n. 21
0
static CoglTexture *
pixbuf_to_cogl_texture (GdkPixbuf *pixbuf)
{
  ClutterBackend *backend = clutter_get_default_backend ();
  CoglContext *ctx = clutter_backend_get_cogl_context (backend);

  return COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx,
                                                      gdk_pixbuf_get_width (pixbuf),
                                                      gdk_pixbuf_get_height (pixbuf),
                                                      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),
                                                      NULL));
}
Esempio n. 22
0
/**
 * shell_clutter_texture_set_from_pixbuf: 
 * texture: #ClutterTexture to be modified
 * pixbuf: #GdkPixbuf to set as an image for #ClutterTexture
 *
 * Convenience function for setting an image for #ClutterTexture based on #GdkPixbuf.
 * Copied from an example posted by hp in this thread http://mail.gnome.org/archives/gtk-devel-list/2008-September/msg00218.html
 *
 * Return value: %TRUE on success, %FALSE on failure
 */
gboolean
shell_clutter_texture_set_from_pixbuf (ClutterTexture *texture,
                                       GdkPixbuf      *pixbuf)
{
    return clutter_texture_set_from_rgb_data (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, NULL);
}
Esempio n. 23
0
static Image* LoadImageGDK (ArchiveFile& file)
{
	// Allocate a new GdkPixBuf and create an alpha-channel with alpha=1.0
	GdkPixbuf* rawPixbuf = gdk_pixbuf_new_from_file(file.getName().c_str(), NULL);

	// Only create an alpha channel if the other rawPixbuf could be loaded
	GdkPixbuf* img = (rawPixbuf != NULL) ? gdk_pixbuf_add_alpha(rawPixbuf, TRUE, 255, 0, 255) : NULL;

	if (img != NULL) {
		// Allocate a new image
		RGBAImage* image = new RGBAImage(gdk_pixbuf_get_width(img), gdk_pixbuf_get_height(img), false);

		// Initialise the source buffer pointers
		guchar* gdkStart = gdk_pixbuf_get_pixels(img);
		int rowstride = gdk_pixbuf_get_rowstride(img);
		int numChannels = gdk_pixbuf_get_n_channels(img);

		// Set the target buffer pointer to the first RGBAPixel
		RGBAPixel* targetPixel = image->pixels;

		// Now do an unelegant cycle over all the pixels and move them into the target
		for (unsigned int y = 0; y < image->height; y++) {
			for (unsigned int x = 0; x < image->width; x++) {
				guchar* gdkPixel = gdkStart + y * rowstride + x * numChannels;

				// Copy the values from the GdkPixel
				targetPixel->red = gdkPixel[0];
				targetPixel->green = gdkPixel[1];
				targetPixel->blue = gdkPixel[2];
				targetPixel->alpha = gdkPixel[3];
				if (targetPixel->alpha != 255)
					image->setHasAlpha(true);

				// Increase the pointer
				targetPixel++;
			}
		}

		// Free the GdkPixbufs from the memory
		g_object_unref(G_OBJECT(img));
		g_object_unref(G_OBJECT(rawPixbuf));

		return image;
	} else {
		g_warning("image could not get loaded: '%s'\n", file.getName().c_str());
	}

	// No image could be loaded, return NULL
	return NULL;
}
Esempio n. 24
0
void  image_draw_vline(GdkPixbuf *img, int x, int y, int height, guint32 color)
{
    guint32 *pixels = (guint32*) gdk_pixbuf_get_pixels(img);
    int rowstride = gdk_pixbuf_get_rowstride(img);
    int i;
    g_assert(gdk_pixbuf_get_n_channels(img) == 4);
    rowstride >>= 2;
    pixels += x + y * rowstride;

    for (i=height; i; i--) {
        *pixels = color;
        pixels += rowstride;
    }
}
Esempio n. 25
0
static inline uint32_t get_pixel(struct imgcache_element *element,
                                 int                      X,
                                 int                      Y)
{
  GdkPixbuf *buf;
  unsigned char *p;
  buf = element->ptr;

  p = gdk_pixbuf_get_pixels(buf);
  p += Y * gdk_pixbuf_get_rowstride(buf);
  p += X * 4;

  return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
static void
gcm_cell_renderer_set_color (GcmCellRendererColor *renderer)
{
	CdColorRGB8 rgb;
	GdkPixbuf *pixbuf = NULL;
	gint height = 26; /* TODO: needs to be a property */
	gint width = 400; /* TODO: needs to be a property */
	gint x, y;
	guchar *pixels;
	guint pos;
	cmsHPROFILE profile_srgb = NULL;
	cmsHPROFILE profile_lab = NULL;
	cmsHTRANSFORM xform = NULL;

	/* nothing set yet */
	if (renderer->color == NULL)
		goto out;

	/* convert the color to sRGB */
	profile_lab = cmsCreateLab2Profile (NULL);
	profile_srgb = cmsCreate_sRGBProfile ();
	xform = cmsCreateTransform (profile_lab, TYPE_Lab_DBL,
				    profile_srgb, TYPE_RGB_8,
				    INTENT_ABSOLUTE_COLORIMETRIC, 0);
	cmsDoTransform (xform, renderer->color, &rgb, 1);

	/* create a pixbuf of the right size */
	pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
	width = gdk_pixbuf_get_width (pixbuf);
	height = gdk_pixbuf_get_height (pixbuf);
	pixels = gdk_pixbuf_get_pixels (pixbuf);
	for (y=0; y<height; y++) {
		for (x=0; x<width; x++) {
			pos = (y*width+x) * 3;
			pixels[pos+0] = rgb.R;
			pixels[pos+1] = rgb.G;
			pixels[pos+2] = rgb.B;
		}
	}
out:
	g_object_set (renderer, "pixbuf", pixbuf, NULL);
	if (profile_srgb != NULL)
		cmsCloseProfile (profile_srgb);
	if (profile_lab != NULL)
		cmsCloseProfile (profile_lab);
	if (xform != NULL)
		cmsDeleteTransform (xform);
	if (pixbuf != NULL)
		g_object_unref (pixbuf);
}
Esempio n. 27
0
/*!
 * \brief Draw an image to Dia's _Image
 * \todo use maskColors to have some alpha support
 */
void
DiaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
			int width, int height, GfxImageColorMap *colorMap,
			GBool interpolate, int *maskColors, GBool inlineImg)
{
  DiaObject *obj;
  GdkPixbuf *pixbuf;
  Point pos;
  ObjectChange *change;
  double *ctm = state->getCTM();

  pos.x = ctm[4] * scale;
  // there is some undocumented magic done with the ctm for drawImage
  // deduced from SplashOutputDev::drawImage()
  // cmt[2] and ctm[3] being negative - use that for y postion
  // ctm[0] and ctm[3] have width and height in device coordinates
  pos.y = (ctm[5] + ctm[3]) * scale;

  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, maskColors ? TRUE : FALSE, 8, width, height);

  {
     // 3 channels, 8 bit
    ImageStream imgStr(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
    Guchar *line;
    int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
    int y;

    imgStr.reset(); // otherwise getLine() is crashing right away
    line = imgStr.getLine ();
    for (y = 0; y < height && line; ++y) {
      guchar *dest = pixels + y * rowstride;

      colorMap->getRGBLine (line, dest, width);

      // ToDo: respect maskColors

      line = imgStr.getLine ();
    }
  }
  obj = create_standard_image (pos.x, pos.y, 
			       ctm[0]  * scale,
			       ctm[3]  * scale, NULL);
  if ((change = dia_object_set_pixbuf (obj, pixbuf)) != NULL)
    change->free (change); /* reference transfered */
  else
    g_object_unref (pixbuf);

  addObject (obj);
}
Esempio n. 28
0
static cairo_t *_mt_cairo_begin_pixbuf(MT_TOOLKIT *mt, MT_WINDOW *win, MT_RECTANGLE *area, int x, int y, int width, int height)
{
   cairo_t *cr;
   int xoff=0, yoff=0;

   _cairo_buf = _mt_image_new(width, height);
   _cairo_win = win;
   mt_rectangle_set(_cairo_rect, x, y, width, height);

   _cairo_surface = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(_cairo_buf), CAIRO_FORMAT_RGB24, width, height, gdk_pixbuf_get_rowstride(_cairo_buf));
   cr = cairo_create(_cairo_surface);
   cairo_translate(cr, -xoff, -yoff);
   return cr;
}
Esempio n. 29
0
/** 
* @brief Copy part of display
* 
* @param display gui_diaplay instance
* @param rect    rectangle to copy
* @param img
* 
* @return 
*/
wg_status
gui_display_copy(Gui_display *display, Wg_rect *rect, Wg_image *img)
{
    wg_uchar *buffer = NULL;
    Wg_image image;
    Wg_image rect_image;
    wg_uint width  = 0;
    wg_uint height = 0;
    cam_status status = CAM_FAILURE;

    gdk_threads_enter();

    width  = gdk_pixbuf_get_width(display->pixbuf);
    height = gdk_pixbuf_get_height(display->pixbuf);
    buffer = gdk_pixbuf_get_pixels(display->pixbuf); 

    status = img_rgb_from_buffer(buffer, width, height, &image);
    if (CAM_FAILURE == status){
        return WG_FAILURE;
    }

    gdk_threads_leave();

    status = img_fill(rect->width, rect->height,
            RGB24_COMPONENT_NUM, IMG_RGB, &rect_image);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        return WG_FAILURE;
    }

    status = img_get_subimage(&image, rect->x, rect->y, &rect_image);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        img_cleanup(&rect_image);
        return WG_FAILURE;
    }

    status = img_rgb_2_hsv_gtk(&rect_image, img);
    if (CAM_FAILURE == status){
        img_cleanup(&image);
        img_cleanup(&rect_image);
        return WG_FAILURE;
    }

    img_cleanup(&image);
    img_cleanup(&rect_image);

    return WG_SUCCESS;
}
Esempio n. 30
0
static void get_alpha_mask(float_shape_t *shape)
{
   GdkColormap *colormap;
   GdkColor black;
   GdkColor white;
   GdkGC *gc;
   int rowstride, nchannels, x, y;
   guchar *pixels, *p;
   bool bright_green, has_alpha;

   colormap = gdk_colormap_get_system();
   gdk_color_black(colormap, &black);
   gdk_color_white(colormap, &white);

   shape->mask_bitmap =
      (GdkDrawable*)gdk_pixmap_new(NULL, shape->width, shape->height, 1);
   gc = gdk_gc_new(shape->mask_bitmap);
   
   gdk_gc_set_foreground(gc, &black);
   gdk_gc_set_background(gc, &white);
   gdk_draw_rectangle(shape->mask_bitmap, gc, TRUE, 0, 0,
                      shape->width, shape->height);

   nchannels = gdk_pixbuf_get_n_channels(shape->pixbuf);
   g_assert(gdk_pixbuf_get_colorspace(shape->pixbuf) == GDK_COLORSPACE_RGB);
   g_assert(gdk_pixbuf_get_bits_per_sample(shape->pixbuf) == 8);

   has_alpha = gdk_pixbuf_get_has_alpha(shape->pixbuf);
   
   rowstride = gdk_pixbuf_get_rowstride(shape->pixbuf);
   pixels = gdk_pixbuf_get_pixels(shape->pixbuf);

   gdk_gc_set_foreground(gc, &white);
   gdk_gc_set_background(gc, &black);
   
   for (y = 0; y < shape->height; y++) {
      for (x = 0; x < shape->width; x++) {
         p = pixels + y*rowstride + x*nchannels;
         bright_green = 0 == p[0] && 255 == p[1] && 0 == p[2];
         if (has_alpha) {
            if (255 == p[3])  // p[3] is alpha channel
               gdk_draw_point(shape->mask_bitmap, gc, x, y);
         } 
         else if (!bright_green) {   // Bright green is alpha for RGB images
            gdk_draw_point(shape->mask_bitmap, gc, x, y);
         }
      }
   }
}