Exemple #1
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);
}
Exemple #2
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;
}
Exemple #3
0
static void
gwy_color_axis_adjust(GwyColorAxis *axis, gint width, gint height)
{
    gint i, j, rowstride, palsize, dval;
    guchar *pixels, *line;
    const guchar *samples, *s;
    gdouble cor;


    gwy_debug("");

    gwy_object_unref(axis->pixbuf);
    axis->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
                                  width, height);
    gwy_debug_objects_creation(G_OBJECT(axis->pixbuf));

    /*render pixbuf according to orientation*/
    pixels = gdk_pixbuf_get_pixels(axis->pixbuf);
    rowstride = gdk_pixbuf_get_rowstride(axis->pixbuf);
    samples = gwy_gradient_get_samples(axis->gradient, &palsize);

    if (axis->orientation == GTK_ORIENTATION_VERTICAL) {
        cor = (palsize-1.0)/height;
        for (i = 0; i < height; i++) {
            line = pixels + i*rowstride;
            dval = (gint)((height-i-1)*cor + 0.5);
            for (j = 0; j < width*height; j += height) {
                s = samples + 4*dval;
                *(line++) = *(s++);
                *(line++) = *(s++);
                *(line++) = *s;
            }
        }
    }
    if (axis->orientation == GTK_ORIENTATION_HORIZONTAL) {
        cor = (palsize-1.0)/width;
        for (i = 0; i < height; i++) {
            line = pixels + i*rowstride;
            for (j = 0; j < width*height; j += height) {
                dval = (gint)((j/height)*cor + 0.5);
                s = samples + 4*dval;
                *(line++) = *(s++);
                *(line++) = *(s++);
                *(line++) = *s;
            }
        }
    }

}
Exemple #4
0
/* From Pidgin */
static void
avatar_pixbuf_roundify (GdkPixbuf *pixbuf)
{
	int     width;
	int     height;
	int     rowstride;
	guchar *pixels;

	if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
		return;
	}

	width     = gdk_pixbuf_get_width (pixbuf);
	height    = gdk_pixbuf_get_height (pixbuf);
	rowstride = gdk_pixbuf_get_rowstride (pixbuf);
	pixels    = gdk_pixbuf_get_pixels (pixbuf);

	if (width < 6 || height < 6) {
		return;
	}

	/* Top left */
	pixels[3] = 0;
	pixels[7] = 0x80;
	pixels[11] = 0xC0;
	pixels[rowstride + 3] = 0x80;
	pixels[rowstride * 2 + 3] = 0xC0;

	/* Top right */
	pixels[width * 4 - 1] = 0;
	pixels[width * 4 - 5] = 0x80;
	pixels[width * 4 - 9] = 0xC0;
	pixels[rowstride + (width * 4) - 1] = 0x80;
	pixels[(2 * rowstride) + (width * 4) - 1] = 0xC0;

	/* Bottom left */
	pixels[(height - 1) * rowstride + 3] = 0;
	pixels[(height - 1) * rowstride + 7] = 0x80;
	pixels[(height - 1) * rowstride + 11] = 0xC0;
	pixels[(height - 2) * rowstride + 3] = 0x80;
	pixels[(height - 3) * rowstride + 3] = 0xC0;

	/* Bottom right */
	pixels[height * rowstride - 1] = 0;
	pixels[(height - 1) * rowstride - 1] = 0x80;
	pixels[(height - 2) * rowstride - 1] = 0xC0;
	pixels[height * rowstride - 5] = 0x80;
	pixels[height * rowstride - 9] = 0xC0;
}
Exemple #5
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);
         }
      }
   }
}
Exemple #6
0
static void Gimp(char* filename)
{
	GError *Error=NULL;
	GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(filename,&Error);
	if(NULL != pixbuf)
	{
		guchar *pixels, *p;
		int width, height, rowstride, n_channels;
		pixels=gdk_pixbuf_get_pixels(pixbuf);
		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);

		printf("static const uint8_t IMG%d_pixels[]=\n{\n\t",Index);
		for(int y=0;y<height;y++)
		{
			for(int x=0;x<width;x++)
			{
				p = pixels + y * rowstride + x * n_channels;
				printf("%-3d,%-3d,%-3d,  ",p[0],p[1],p[2]);
			}
			printf("\n\t");
		}
		printf("\n};\n");
		printf("static const SGIMPImage IMG%d_image=\n{/* %s */\n",Index,filename);
		printf("\t.dwWidth=%d,\n",width);
		printf("\t.dwHeight=%d,\n",height);
		printf("\t.dwBytes_per_pixel=%d,\n",3);
		printf("\t.pucPixel_data=IMG%d_pixels\n",Index);
		printf("};\n\n");

		Index++;
	}
	else
	{
		printf("Invalid arg: %s\n\tError:%s\n",filename,Error->message);
	}

}
Exemple #7
0
static GdkPixbuf *pl_data_to_pixbuf(int palette, int width, int height, int irowstride, guchar *pixel_data) {
  GdkPixbuf *pixbuf;
  int rowstride,orowstride;
  gboolean cheat=FALSE;
  gint n_channels;
  guchar *pixels,*end;

  switch (palette) {
  case WEED_PALETTE_RGB24:
  case WEED_PALETTE_BGR24:
    if (irowstride==pl_gdk_rowstride_value(width*3)) {
      pixbuf=pl_gdk_pixbuf_cheat(GDK_COLORSPACE_RGB, FALSE, 8, width, height, pixel_data);
      cheat=TRUE;
    } else pixbuf=gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
    n_channels=3;
    break;
  case WEED_PALETTE_RGBA32:
  case WEED_PALETTE_BGRA32:
  case WEED_PALETTE_ARGB32: // TODO - change to RGBA ??
    if (irowstride==pl_gdk_rowstride_value(width*4)) {
      pixbuf=pl_gdk_pixbuf_cheat(GDK_COLORSPACE_RGB, TRUE, 8, width, height, pixel_data);
      cheat=TRUE;
    } else pixbuf=gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
    n_channels=4;
    break;
  default:
    return NULL;
  }
  pixels=gdk_pixbuf_get_pixels(pixbuf);
  orowstride=gdk_pixbuf_get_rowstride(pixbuf);

  if (irowstride>orowstride) rowstride=orowstride;
  else rowstride=irowstride;
  end=pixels+orowstride*height;

  if (!cheat) {
    gboolean done=FALSE;
    for (; pixels<end&&!done; pixels+=orowstride) {
      if (pixels+orowstride>=end) {
        orowstride=rowstride=pl_gdk_last_rowstride_value(width,n_channels);
        done=TRUE;
      }
      weed_memcpy(pixels,pixel_data,rowstride);
      if (rowstride<orowstride) weed_memset(pixels+rowstride,0,orowstride-rowstride);
      pixel_data+=irowstride;
    }
  }
  return pixbuf;
}
void rotate180(GdkPixbuf *dest, GdkPixbuf *src, int sw, int sh) {
	if (src == 0)
		return;

	const gint srs = gdk_pixbuf_get_rowstride(src);
	guchar *s_pix = gdk_pixbuf_get_pixels(src);

	const gint drs = gdk_pixbuf_get_rowstride(dest);
	guchar *d_pix = gdk_pixbuf_get_pixels(dest) + (sh - 1) * drs;

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

	for (int i = 0; i < sh; ++i) {
		guchar *s = s_pix;
		guchar *d = d_pix + (sw - 1) * a;
		for (int j = 0; j < sw; ++j) {
			memcpy(d, s, a);
			s += a;
			d -= a;
		}
		s_pix += srs;
		d_pix -= drs;
	}
}
Exemple #9
0
static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
{
    /* 1) read in Python pixbuf, get the underlying gdk_pixbuf */
    PyGObject *py_pixbuf;
    GdkPixbuf *gdk_pixbuf;
    PyArrayObject *array;
    npy_intp dims[3] = { 0, 0, 3 };
    npy_intp strides[3];

    if (!PyArg_ParseTuple(args, "O!:pixbuf_get_pixels_array", &PyGdkPixbuf_Type, &py_pixbuf))
        return NULL;

    gdk_pixbuf = GDK_PIXBUF(py_pixbuf->obj);

    /* 2) same as pygtk/gtk/gdk.c _wrap_gdk_pixbuf_get_pixels_array()
     * with 'self' changed to py_pixbuf
     */

    dims[0] = gdk_pixbuf_get_height(gdk_pixbuf);
    dims[1] = gdk_pixbuf_get_width(gdk_pixbuf);
    if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
        dims[2] = 4;

    strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
    strides[1] = dims[2];
    strides[2] = 1;

    array = (PyArrayObject*)
        PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides,
                    (void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1,
                    NPY_ARRAY_WRITEABLE, NULL);

    if (array == NULL)
        return NULL;

    /* the array holds a ref to the pixbuf pixels through this wrapper*/
    Py_INCREF(py_pixbuf);
#if NPY_API_VERSION >= 0x00000007
    if (PyArray_SetBaseObject(array, (PyObject *)py_pixbuf) == -1) {
        Py_DECREF(py_pixbuf);
        Py_DECREF(array);
        return NULL;
    }
#else
    PyArray_BASE(array) = (PyObject *) py_pixbuf;
#endif
    return PyArray_Return(array);
}
Exemple #10
0
gint calculate_lightness(RSFilter *filter)
{
      RSFilterRequest *request = rs_filter_request_new();
      rs_filter_request_set_quick(RS_FILTER_REQUEST(request), TRUE);
      rs_filter_param_set_object(RS_FILTER_PARAM(request), "colorspace", rs_color_space_new_singleton("RSSrgb"));
      rs_filter_request_set_quick(RS_FILTER_REQUEST(request), TRUE);

      rs_filter_set_recursive(filter,
			      "bounding-box", TRUE,
			      "width", 256,
			      "height", 256,
			      NULL);

      RSFilterResponse *response = rs_filter_get_image8(filter, request);
      g_object_unref(request);

      if(!rs_filter_response_has_image8(response))
	return 127;

      GdkPixbuf *pixbuf = rs_filter_response_get_image8(response);
      g_object_unref(response);

      guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
      gint rowstride = gdk_pixbuf_get_rowstride(pixbuf);
      gint height = gdk_pixbuf_get_height(pixbuf);
      gint width = gdk_pixbuf_get_width(pixbuf);
      gint channels = gdk_pixbuf_get_n_channels(pixbuf);

      gint x,y,c;
      gulong sum = 0;
      gint num = 0;

      for (y = 0; y < height; y++)
        {
	  for (x = 0; x < width; x++)
	    {
	      for (c = 0; c < channels; c++)
		{
		  sum += pixels[x*c+y*rowstride];
		}
	    }
	}

      g_object_unref(pixbuf);

      num = width*height*channels;
      return (gint) (sum/num);
}
Exemple #11
0
static gboolean
area_realize (GimpPreviewArea *area)
{
  GdkPixbuf *pixbuf;

  pixbuf = load_image ("wilber-wizard.png");
  gimp_preview_area_draw (GIMP_PREVIEW_AREA (area), 0, 0,
                          gdk_pixbuf_get_width (pixbuf),
                          gdk_pixbuf_get_height (pixbuf),
                          GIMP_RGBA_IMAGE,
                          gdk_pixbuf_get_pixels (pixbuf),
                          gdk_pixbuf_get_rowstride (pixbuf));
  g_object_unref (pixbuf);

  return FALSE;
}
/* Auxiliary function, returns numeric representation of pixel.
 * For RGB format it is rrggbb(in hex), for RGBA - rrggbbaa. */
static guint32
get_pixel (GdkPixbuf *pixbuf, int x, int y)
{
    guchar *colors;
    guint32 pixel;

    colors = ((guchar*)gdk_pixbuf_get_pixels(pixbuf)
	      + gdk_pixbuf_get_n_channels(pixbuf) * x
	      + gdk_pixbuf_get_rowstride(pixbuf) * y);
    pixel = (colors[0] << 16) | (colors[1] << 8) | colors[2];

    if (gdk_pixbuf_get_n_channels (pixbuf) == 4)
        pixel = (pixel << 8) | colors[3];

    return pixel;
}
GdkPixbuf*
nsImageToPixbuf::ImgSurfaceToPixbuf(gfxImageSurface* aImgSurface, PRInt32 aWidth, PRInt32 aHeight)
{
    GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
                                       aWidth, aHeight);
    if (!pixbuf)
        return nullptr;

    PRUint32 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
    guchar* pixels = gdk_pixbuf_get_pixels (pixbuf);

    long cairoStride = aImgSurface->Stride();
    unsigned char* cairoData = aImgSurface->Data();

    gfxASurface::gfxImageFormat format = aImgSurface->Format();

    for (PRInt32 row = 0; row < aHeight; ++row) {
        for (PRInt32 col = 0; col < aWidth; ++col) {
            guchar* pixel = pixels + row * rowstride + 4 * col;

            PRUint32* cairoPixel = reinterpret_cast<PRUint32*>
                                                   ((cairoData + row * cairoStride + 4 * col));

            if (format == gfxASurface::ImageFormatARGB32) {
                const PRUint8 a = (*cairoPixel >> 24) & 0xFF;
                const PRUint8 r = unpremultiply((*cairoPixel >> 16) & 0xFF, a);
                const PRUint8 g = unpremultiply((*cairoPixel >>  8) & 0xFF, a);
                const PRUint8 b = unpremultiply((*cairoPixel >>  0) & 0xFF, a);

                *pixel++ = r;
                *pixel++ = g;
                *pixel++ = b;
                *pixel++ = a;
            } else {
                NS_ASSERTION(format == gfxASurface::ImageFormatRGB24,
                             "unexpected format");
                const PRUint8 r = (*cairoPixel >> 16) & 0xFF;
                const PRUint8 g = (*cairoPixel >>  8) & 0xFF;
                const PRUint8 b = (*cairoPixel >>  0) & 0xFF;

                *pixel++ = r;
                *pixel++ = g;
                *pixel++ = b;
                *pixel++ = 0xFF; // A
            }
        }
    }
Exemple #14
0
static void change_corner_alpha (GdkPixbuf* pixbuf, float fa)
{
    int rowstride, n_channels;
    guchar *pixels, *p;
    guchar alpha;

    alpha = (guchar) (fa * 255);
    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);

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

    //the outline of the icon are stripped.
    //so the for corner coordinates are (1, 1), (1, 15), (15, 1), (15, 15)
    //p = pixels + y * rowstride + x * n_channels;
    if (G_LIKELY(gdk_pixbuf_get_has_alpha (pixbuf)&&(n_channels == 4))) {
        p = pixels + 1 * rowstride + 1 * n_channels;
        p[3] = alpha;
        p = pixels + 15 * rowstride + 1 * n_channels;
        p[3] = alpha;
        p = pixels + 1 * rowstride + 15 * n_channels;
        p[3] = alpha;
        p = pixels + 15 * rowstride + 15 * n_channels;
        p[3] = alpha;
    } else {
        int i;
        p = pixels + 1 * rowstride + 1 * n_channels;
        for (i=0;i<3; i++) {
            p[i] = p[i] * fa;
        }
        p = pixels + 15 * rowstride + 1 * n_channels;
        for (i=0;i<3; i++) {
            p[i] = p[i] * fa;
        }
        p = pixels + 1 * rowstride + 15 * n_channels;
        for (i=0;i<3; i++) {
            p[i] = p[i] * fa;
        }
        p = pixels + 15 * rowstride + 15 * n_channels;
        for (i=0;i<3; i++) {
            p[i] = p[i] * fa;
        }
    }
}
Exemple #15
0
static void _load_tile_thread(gpointer _tile, gpointer _sat)
{
	GritsTile      *tile = _tile;
	GritsPluginSat *sat  = _sat;

	g_debug("GritsPluginSat: _load_tile_thread start %p - tile=%p",
			g_thread_self(), tile);
	if (sat->aborted) {
		g_debug("GritsPluginSat: _load_tile_thread - aborted");
		return;
	}

	/* Download tile */
	gchar *path = grits_wms_fetch(sat->wms, tile, GRITS_ONCE, NULL, NULL);
	if (!path) return; // Canceled/error

	/* Load pixbuf */
	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
	if (!pixbuf) {
		g_warning("GritsPluginSat: _load_tile_thread - Error loading pixbuf %s", path);
		g_remove(path);
		g_free(path);
		return;
	}
	g_free(path);

	/* Draw a border */
#ifdef DRAW_TILE_BORDER
	gint    border = 10;
	gint    width  = gdk_pixbuf_get_width(pixbuf);
	gint    height = gdk_pixbuf_get_height(pixbuf);
	gint    stride = gdk_pixbuf_get_rowstride(pixbuf);
	guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
	for (int i = 0; i < border; i++) {
		memset(&pixels[(         i)*stride], 0xff, stride);
		memset(&pixels[(height-1-i)*stride], 0xff, stride);
	}
	for (int i = 0; i < height; i++) {
		memset(&pixels[(i*stride)                   ], 0xff, border*4);
		memset(&pixels[(i*stride)+((width-border)*4)], 0xff, border*4);
	}
#endif

	/* Load the GL texture from the main thread */
	grits_tile_load_pixbuf(tile, pixbuf);
	g_debug("GritsPluginSat: _load_tile_thread end %p", g_thread_self());
}
bool yarpImage2Pixbuf(yarp::sig::ImageOf<yarp::sig::PixelMono> *sourceImg, 
                      GdkPixbuf* destPixbuf)
{
	// il pixbuf should already been allocated with the right dimensions
	guchar *dst_data;
	char *src_data;
	unsigned int rowstride;
	guchar *p_dst;
	char *p_src;
	unsigned int width, height;
	unsigned int n_channels;
	yarp::sig::PixelRgb srcPixel;
	unsigned int dst_size_in_memory;
	unsigned int src_line_size;

	dst_data = gdk_pixbuf_get_pixels(destPixbuf);
	width = sourceImg->width();
	printf("width=%d /n",width);
	height = sourceImg->height();
	printf("height=%d /n",height);
	rowstride = gdk_pixbuf_get_rowstride (destPixbuf);
	printf("rowstride=%d /n",rowstride);
	n_channels = gdk_pixbuf_get_n_channels (destPixbuf);
	printf("n_channels=%d /n",n_channels);
	n_channels=1;
	dst_size_in_memory = rowstride * height; //960*240
	dst_size_in_memory = width * height; //960*240
	src_line_size = sourceImg->getRowSize(); //GetAllocatedLineSize();
	printf("src_line_size=%d /n",src_line_size);
	src_data = (char *) sourceImg->getRawImage(); //GetRawBuffer();
	if ( src_line_size == rowstride)
        {
            memcpy(dst_data, src_data, dst_size_in_memory);
        }
	else
        {
            for (int i=0; i < (int)height; i++)
                {
                    p_dst = dst_data + i * rowstride;
                    p_src = src_data + i * src_line_size;
                    memcpy(p_dst, p_src, (n_channels*width));
                }
        }

	return true;
}
Exemple #17
0
/* Get the background pixbuf. */
static GdkPixbuf * get_background_pixbuf(void)
{
    /* Get the root window pixmap. */
    GdkScreen * screen = gdk_screen_get_default();
#ifdef ENABLE_GTK3
    GdkPixbuf * pixbuf = gdk_pixbuf_get_from_window(
        gdk_get_default_root_window(),
        0,
        0,
        gdk_screen_get_width(screen),		/* Width */
        gdk_screen_get_height(screen));		/* Height */
#else
    GdkPixbuf * pixbuf = gdk_pixbuf_get_from_drawable(
        NULL,					/* Allocate a new pixbuf */
        gdk_get_default_root_window(),		/* The drawable */
        NULL,					/* Its colormap */
        0, 0, 0, 0,				/* Coordinates */
        gdk_screen_get_width(screen),		/* Width */
        gdk_screen_get_height(screen));		/* Height */
#endif

    /* Make the background darker. */
    if (pixbuf != NULL)
    {
        unsigned char * pixels = gdk_pixbuf_get_pixels(pixbuf);
        int width = gdk_pixbuf_get_width(pixbuf);
        int height = gdk_pixbuf_get_height(pixbuf);
        int pixel_stride = ((gdk_pixbuf_get_has_alpha(pixbuf)) ? 4 : 3);
        int row_stride = gdk_pixbuf_get_rowstride(pixbuf);
        int y;
        for (y = 0; y < height; y += 1)
        {
            unsigned char * p = pixels;
            int x;
            for (x = 0; x < width; x += 1)
            {
                p[0] = p[0] / 2;
                p[1] = p[1] / 2;
                p[2] = p[2] / 2;
                p += pixel_stride;
            }
            pixels += row_stride;
        }
    }
    return pixbuf;
}
Exemple #18
0
/****************************************************************************
  Create a new sprite with the given pixmap, dimensions, and
  (optional) mask.

  FIXME: should be renamed as sprite_new or some such.
****************************************************************************/
struct sprite *ctor_sprite(GdkPixbuf *pixbuf)
{
  struct sprite *sprite = fc_malloc(sizeof(*sprite));
  bool has_alpha = FALSE, has_mask = FALSE;

  sprite->width = gdk_pixbuf_get_width(pixbuf);
  sprite->height = gdk_pixbuf_get_height(pixbuf);

  /* Check to see if this pixbuf has an alpha layer. */
  if (gdk_pixbuf_get_has_alpha(pixbuf)) {
    guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
    int x, y, rowstride = gdk_pixbuf_get_rowstride(pixbuf);

    for (y = 0; y < sprite->height; y++) {
      for (x = 0; x < sprite->width; x++) {
	int i = y * rowstride + 4 * x + 3;
	guchar pixel = pixels[i];

	if (pixel > 0 && pixel < 255) {
	  has_alpha = TRUE;
	}
	if (pixel == 0) {
	  has_mask = TRUE;
	}
      }
    }
  }

  sprite->pixbuf_fogged = NULL;
  sprite->pixmap_fogged = NULL;
  if (has_alpha) {
    sprite->pixbuf = pixbuf;
    sprite->pixmap = NULL;
    sprite->mask = NULL;
  } else {
    gdk_pixbuf_render_pixmap_and_mask(pixbuf, &sprite->pixmap,
				      &sprite->mask, 1);
    if (!has_mask && sprite->mask) {
      g_object_unref(sprite->mask);
      sprite->mask = NULL;
    }
    g_object_unref(pixbuf);
    sprite->pixbuf = NULL;
  }
  return sprite;
}
Exemple #19
0
/* Point handler for the pixbuf canvas item */
static double
foo_canvas_pixbuf_point (FooCanvasItem *item, double x, double y, int cx, int cy,
			   FooCanvasItem **actual_item)
{
	FooCanvasPixbuf *gcp;
	PixbufPrivate *priv;
	double x1, y1, x2, y2;
	int px, py;
	double no_hit;
	guchar *src;
	GdkPixbuf *pixbuf;

	gcp = FOO_CANVAS_PIXBUF (item);
	priv = gcp->priv;
	pixbuf = priv->pixbuf;

	*actual_item = item;

	no_hit = item->canvas->pixels_per_unit * 2 + 10;

	if (!priv->pixbuf)
		return no_hit;

	compute_bounding_box (gcp, 0.0, 0.0,
			      &x1, &y1, &x2, &y2);


	if (x < x1 || x >= x2 ||
	    y < y1 || y >= y2)
		return no_hit;

	if (!gdk_pixbuf_get_has_alpha (pixbuf) || priv->point_ignores_alpha)
		return 0.0;

	px = (x - x1) * gdk_pixbuf_get_width (pixbuf) / (x2 - x1);
	py = (y - y1) * gdk_pixbuf_get_height (pixbuf) / (y2 - y1);

	src = gdk_pixbuf_get_pixels (pixbuf) +
		py * gdk_pixbuf_get_rowstride (pixbuf) +
		px * gdk_pixbuf_get_n_channels (pixbuf);

	if (src[3] < 128)
		return no_hit;
	else
		return 0.0;
}
Exemple #20
0
int main(int argc, char *argv[])
{
    int width = 1920, height = 1080, max = 1000;
    const int black = 0x000000, white = 0xffffff;

    GError *error = NULL;
    GdkPixbuf *image = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
    guchar *pixels = gdk_pixbuf_get_pixels(image);
    int rowstride = gdk_pixbuf_get_rowstride(image);

    for (int row = 0; row < height; row++) {
        guchar *pixels_row = pixels;
        for (int col = 0; col < width; col++) {
            double c_re = (col - width/2)*4.0/width;
            double c_im = (row - height/2)*4.0/width;
            double x = 0, y = 0;
            int iterations = 0;
            while (x*x+y*y < 4 && iterations < max) {
                double x_new = x*x-y*y+c_re;
                y = 2*x*y+c_im;
                x = x_new;
                iterations++;
            } 

            int rgb;
            if (iterations < max) {
                rgb = white;
            } else {
                rgb = black;
            }
            *pixels_row++ = rgb >> 16;
            *pixels_row++ = rgb >> 8;
            *pixels_row++ = rgb >> 0;
        }
        pixels += rowstride;
    }

    if (!gdk_pixbuf_save(image, "mandelbrot.png", "png", &error, NULL)) {
        fprintf (stderr, "Unable to write file: %s\n", error->message);
    }

    g_object_unref(image);
    
    return 0;
}
Exemple #21
0
bool MCThemeDraw(MCGContextRef p_context, MCThemeDrawType p_type, MCThemeDrawInfo *p_info)
{
	MCXImageCacheNode *cache_node = NULL ;
	GdkPixbuf* t_argb_image ;
	bool t_cached ;
    
	if ( ( p_info -> moztype != MOZ_GTK_CHECKBUTTON ) && ( p_info -> moztype != MOZ_GTK_RADIOBUTTON ) )
		cache_node = MCimagecache -> find_cached_image ( p_info -> drect.width, p_info -> drect.height, p_info -> moztype, &p_info -> state, p_info -> flags ) ;
	
	if ( cache_node != NULL ) 
	{
		t_argb_image = MCimagecache -> get_from_cache( cache_node ) ;
		t_cached = true ;
    }
	else
	{
		// Calculate the alpha for the rendered widget, by rendering against white & black.
		t_argb_image = drawtheme_calc_alpha (*p_info) ;
        if (t_argb_image == NULL)
            return false;
        t_cached = MCimagecache -> add_to_cache (t_argb_image, *p_info) ;
    }

    MCGRaster t_raster;
	t_raster.width = gdk_pixbuf_get_width(t_argb_image);
	t_raster.height = gdk_pixbuf_get_height(t_argb_image);
	t_raster.stride = gdk_pixbuf_get_rowstride(t_argb_image);
	t_raster.pixels = gdk_pixbuf_get_pixels(t_argb_image);
	t_raster.format = kMCGRasterFormat_ARGB;
	
	MCGRectangle t_dest;
	t_dest.origin.x = p_info->crect.x;
	t_dest.origin.y = p_info->crect.y;
	t_dest.size.width = p_info->crect.width;
	t_dest.size.height = p_info->crect.height;

	// MM-2013-12-16: [[ Bug 11567 ]] Use bilinear filter when drawing theme elements.
    // MM-2014-01-27: [[ UpdateImageFilters ]] Updated to use new libgraphics image filter types (was bilinear).
	MCGContextDrawPixels(p_context, t_raster, t_dest, kMCGImageFilterMedium);
	
    if (!t_cached)
        g_object_unref(t_argb_image);
    
	return true;
}
void avi_writer_append_frame (AviWriter *self, const GdkPixbuf *frame) {
    int x, y;
    guchar bgr[3];
    guchar *pixels = gdk_pixbuf_get_pixels(frame);
    guchar *row, *pixel;
    int width = gdk_pixbuf_get_width(frame);
    int height = gdk_pixbuf_get_height(frame);
    int rowstride = gdk_pixbuf_get_rowstride(frame);
    int n_channels = gdk_pixbuf_get_n_channels(frame);
    int padding = 0;

    g_assert(width == self->width);
    g_assert(height == self->height);

    /* Start an uncompressed video frame */
    avi_writer_push_chunk(self, "00db");

    /* Write out our image data bottom-up in BGR order. Yuck.
     * Each row is padded to the next 4-byte boundary.
     */
    row = pixels + rowstride * (height-1);
    for (y=self->height-1; y>=0; y--) {
	pixel = row;
	padding = 0;

	for (x=0; x<self->width; x++) {
	    bgr[2] = pixel[0];
	    bgr[1] = pixel[1];
	    bgr[0] = pixel[2];

	    fwrite(bgr, 1, 3, self->file);
	    pixel += n_channels;
	    padding = (padding - 3) & 3;
	}

	if (padding) {
	    bgr[0] = bgr[1] = bgr[2] = 0;
	    fwrite(bgr, 1, padding, self->file);
	}
	row -= rowstride;
    }

    avi_writer_pop_chunk_with_index(self, AVIIF_KEYFRAME);
    self->frame_count++;
}
/**
 * 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);
}
Exemple #24
0
Picbuf *picbuf_new_from_pixbuf(GdkPixbuf *pixbuf, gboolean color)
{
	Picbuf *picbuf;
	guchar *pixels, *src, *dst;
	gint channels, rowstride, x, y;

	g_return_val_if_fail(pixbuf != NULL, NULL);
	g_return_val_if_fail(gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB, NULL);
	g_return_val_if_fail(gdk_pixbuf_get_bits_per_sample(pixbuf) == 8, NULL);

	picbuf = g_new0(Picbuf, 1);

	picbuf->color = color;
	picbuf->width = gdk_pixbuf_get_width(pixbuf);
	picbuf->height = gdk_pixbuf_get_height(pixbuf);
	picbuf->datalen = picbuf->width * picbuf->height * (color ? 3 : 1);
	picbuf->data = g_malloc(picbuf->datalen);
	picbuf->dataptr = 0;

	channels = gdk_pixbuf_get_n_channels(pixbuf);
	rowstride = gdk_pixbuf_get_rowstride(pixbuf);

	pixels = gdk_pixbuf_get_pixels(pixbuf);

	for (y = 0; y < picbuf->height; y++) {
		src = pixels + y * rowstride;
		dst = picbuf->data + y * picbuf->width * (color ? 3 : 1);

		for (x = 0; x < picbuf->width; x++) {
			if (color) {
				dst[0 * picbuf->width] = src[0];
				dst[1 * picbuf->width] = src[1];
				dst[2 * picbuf->width] = src[2];
			} else {
				dst[0] = (src[0] + src[1] + src[2]) / 3;
			}

			src += channels;
			dst += 1;
		}
	}

	return picbuf;
}
Exemple #25
0
	void _createPNGFromPixbuf(GdkPixbuf * pixbuf)
	{
		int colorType = PNG_COLOR_TYPE_RGB;

		//
		// OK define the PNG header from the info in GdkPixbuf
		//

		UT_uint32 width =  gdk_pixbuf_get_width(pixbuf);
		UT_uint32 height = gdk_pixbuf_get_height(pixbuf);
		int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
		guchar * pBuf = gdk_pixbuf_get_pixels(pixbuf);

		if(gdk_pixbuf_get_has_alpha(pixbuf))
		{
			colorType =  PNG_COLOR_TYPE_RGB_ALPHA;
		}

		//
		// Abi only has 8 bits per sample
		//
		static const int bitsPerSampleAbi = 8;
		png_set_IHDR ( m_pPNG,  m_pPNGInfo,
					   width,			       
					   height,			       
					   bitsPerSampleAbi,
					   colorType,
					   PNG_INTERLACE_NONE,
					   PNG_COMPRESSION_TYPE_DEFAULT,
					   PNG_FILTER_TYPE_DEFAULT );
		
		png_write_info(m_pPNG, m_pPNGInfo);
		UT_Byte* pngScanline = new UT_Byte[rowstride];

		for(UT_uint32 i =0; i < height; i++)
		{
			memmove(pngScanline,pBuf,rowstride);
			png_write_row(m_pPNG, pngScanline);
			pBuf += rowstride;
		}

		DELETEP (pngScanline);		
		png_write_end(m_pPNG, m_pPNGInfo);
	}
Exemple #26
0
ClutterActor *
ckd_slide_new_for_image (GFile *file)
{
        CkdSlide *self = g_object_new (CKD_TYPE_SLIDE, NULL);
        CkdSlidePriv *priv = CKD_SLIDE_GET_PRIVATE (self);

        GdkPixbuf *pixbuf;
        ClutterContent *image;

        /* 载入图像数据 */
        gchar *image_path = g_file_get_path (file);
        pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);

        /* 获取图像尺寸 */
        gfloat w = gdk_pixbuf_get_width (pixbuf);
        gfloat h = gdk_pixbuf_get_height (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,
                                (guint)w,
                                (guint)h,
                                gdk_pixbuf_get_rowstride (pixbuf),
                                NULL);
        g_object_unref (pixbuf);
        g_free (image_path);
                
        priv->content = clutter_actor_new ();

        clutter_actor_set_size (priv->content, w, h);
        clutter_actor_set_content_scaling_filters (priv->content,
                                                   CLUTTER_SCALING_FILTER_TRILINEAR,
                                                   CLUTTER_SCALING_FILTER_LINEAR);
        clutter_actor_set_content (priv->content, image);
        g_object_unref (image);
  

        clutter_actor_add_child (CLUTTER_ACTOR(self), priv->content);
        
        return (ClutterActor *)self;
}
Exemple #27
0
static gboolean histmap_read(HistMap *histmap, gboolean whole)
{
	gint w, h, i, j, srs, has_alpha, step, end_line;
	guchar *s_pix;
	GdkPixbuf *imgpixbuf = histmap->pixbuf;

	w = gdk_pixbuf_get_width(imgpixbuf);
	h = gdk_pixbuf_get_height(imgpixbuf);
	srs = gdk_pixbuf_get_rowstride(imgpixbuf);
	s_pix = gdk_pixbuf_get_pixels(imgpixbuf);
	has_alpha = gdk_pixbuf_get_has_alpha(imgpixbuf);

	if (whole)
		{
		end_line = h;
		}
	else
		{
		gint lines = 1 + 16384 / w;
		end_line = histmap->y + lines;
		if (end_line > h) end_line = h;
		}

	step = 3 + !!(has_alpha);
	for (i = histmap->y; i < end_line; i++)
		{
		guchar *sp = s_pix + (i * srs); /* 8bit */
		for (j = 0; j < w; j++)
			{
			guint max = sp[0];
			if (sp[1] > max) max = sp[1];
			if (sp[2] > max) max = sp[2];

			histmap->r[sp[0]]++;
			histmap->g[sp[1]]++;
			histmap->b[sp[2]]++;
			histmap->max[max]++;

			sp += step;
			}
		}
	histmap->y = end_line;
	return end_line >= h;
}
/**
 * ar_pixbuf_utils_create_highlight:
 * @pixbuf: the original pixbuf
 * @highligh_colour: the colour to use for the highlight
 *
 * Creates a highlighted pixbuf from @pixbuf using @highligh_colour.
 *
 * Returns: a new #GdkPixbuf, or %NULL if there was an error
 */
GdkPixbuf *
ar_pixbuf_utils_create_highlight (GdkPixbuf *pixbuf,
                                  const GdkColor *highligh_colour)
{
  GdkPixbuf *comppixbuf;
  guint x, y, width, height, rowstride;
  guint16 red, green, blue;
  guchar *pixels, *p;

  if (!pixbuf)
    return NULL;

  comppixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
                               gdk_pixbuf_get_has_alpha (pixbuf),
                               gdk_pixbuf_get_bits_per_sample (pixbuf),
                               gdk_pixbuf_get_width (pixbuf),
                               gdk_pixbuf_get_height (pixbuf));
  if (!comppixbuf)
    return NULL;

  gdk_pixbuf_saturate_and_pixelate (pixbuf, comppixbuf, 0.0, FALSE);

  pixels = gdk_pixbuf_get_pixels (comppixbuf);
  width = gdk_pixbuf_get_width (comppixbuf);
  height = gdk_pixbuf_get_height (comppixbuf);
  rowstride = gdk_pixbuf_get_rowstride (comppixbuf);

  red = highligh_colour->red >> 8;
  green = highligh_colour->green >> 8;
  blue = highligh_colour->blue >> 8;

  /* FIXMEchpe: This could probably use lots of improvements! */
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
      p = pixels + y * rowstride + x * 4;
      p[0] += (0xFF - p[0]) * red / 0xFF;
      p[1] += (0xFF - p[1]) * green / 0xFF;
      p[2] += (0xFF - p[2]) * blue / 0xFF;
    }
  }

  return comppixbuf;
}
Exemple #29
0
static void cache_add(gchar *key, GdkPixbuf *pixbuf, mapcache_extra_t extra)
{
  cache_item_t *ci = g_malloc ( sizeof(cache_item_t) );
  ci->pixbuf = pixbuf;
  ci->extra = extra;
#if !GLIB_CHECK_VERSION(2,26,0)
  // Only later versions of GLib actually return a value for this function
  // Annoyingly the documentation doesn't say anything about this interface change :(
  if ( g_hash_table_insert ( cache, key, ci ) )
#else
  g_hash_table_insert ( cache, key, ci );
#endif
  {
    cache_size += gdk_pixbuf_get_rowstride(pixbuf) * gdk_pixbuf_get_height(pixbuf);
    // ATM size of 'extra' data hardly worth trying to count (compared to pixbuf sizes)
    // Not sure what this 100 represents anyway - probably a guess at an average pixbuf metadata size
    cache_size += 100;
  }
}
Exemple #30
0
static void addRect(GdkPixbuf *pixbuf, int x, int y, int w, int h)
{
	int rowStride = gdk_pixbuf_get_rowstride(pixbuf);
	int nChannels = gdk_pixbuf_get_n_channels(pixbuf);
	guchar *pixels = gdk_pixbuf_get_pixels(pixbuf);
	
	
	for(int i = x; i < x+w; ++i)
	{
		pixelToRed(pixels + y*rowStride + i*nChannels);
		pixelToRed(pixels + (y+h-1)*rowStride + i*nChannels);
	}

	for(int i = y; i < y+h; ++i)
	{
		pixelToRed(pixels + i*rowStride + x*nChannels);
		pixelToRed(pixels + i*rowStride + (x+w-1)*nChannels);
	}
}