Example #1
0
void render() {
	draw_fill(ctx, rgba(0,0,0,127));

	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, window->width);
	cairo_surface_t * surface = cairo_image_surface_create_for_data(ctx->buffer, CAIRO_FORMAT_ARGB32, window->width, window->height, stride);
	cairo_t * cr = cairo_create(surface);

	cairo_set_line_width (cr, 6);

	cairo_rectangle (cr, 12, 12, 232, 70);
	cairo_new_sub_path (cr); cairo_arc (cr, 64, 64, 40, 0, 2*M_PI);
	cairo_new_sub_path (cr); cairo_arc_negative (cr, 192, 64, 40, 0, -2*M_PI);

	cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
	cairo_set_source_rgb (cr, 0, 0.7, 0); cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr);

	cairo_translate (cr, 0, 128);
	cairo_rectangle (cr, 12, 12, 232, 70);
	cairo_new_sub_path (cr); cairo_arc (cr, 64, 64, 40, 0, 2*M_PI);
	cairo_new_sub_path (cr); cairo_arc_negative (cr, 192, 64, 40, 0, -2*M_PI);

	cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
	cairo_set_source_rgb (cr, 0, 0, 0.9); cairo_fill_preserve (cr);
	cairo_set_source_rgb (cr, 0, 0, 0); cairo_stroke (cr);

	cairo_surface_flush(surface);
	cairo_destroy(cr);
	cairo_surface_flush(surface);
	cairo_surface_destroy(surface);
}
Example #2
0
inline static cairo_pattern_t *
create_stipple (const char *color_name, guchar stipple_data[])
{
	cairo_surface_t *surface;
	cairo_pattern_t *pattern;
	GdkColor color;
	int stride;
	const int width = 8; 
	const int height = 8;

	gdk_color_parse (color_name, &color);
/*	stipple_data[2] = stipple_data[14] = color.red >> 8;
	stipple_data[1] = stipple_data[13] = color.green >> 8;
	stipple_data[0] = stipple_data[12] = color.blue >> 8;
*/
	stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
	g_assert (stride>0);
	NG_DEBUG ("stride = %i", stride);
	surface = cairo_image_surface_create_for_data (stipple_data,
	                                               CAIRO_FORMAT_ARGB32,
	                                               width, height, stride);
	pattern = cairo_pattern_create_for_surface (surface);
	cairo_surface_destroy (surface);
	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);

	return pattern;
}
Example #3
0
cairo_t* gui_screen_t::getGraphics() {

	// get buffer
	auto bufferInfo = canvas->getBuffer();
	if (bufferInfo.buffer == 0) {
		return 0;
	}

	bufferSize.width = bufferInfo.width;
	bufferSize.height = bufferInfo.height;

	// get the surface ready and go:
	if (existingSurface == 0 || existingSurfaceBuffer != bufferInfo.buffer) {
		if (existingContext != 0) {
			cairo_destroy(existingContext);
		}

		existingSurface = cairo_image_surface_create_for_data((uint8_t*) bufferInfo.buffer, CAIRO_FORMAT_ARGB32, bufferInfo.width, bufferInfo.height,
				cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, bufferInfo.width));
		existingSurfaceBuffer = bufferInfo.buffer;
		existingContext = cairo_create(existingSurface);
	}

	return existingContext;
}
static void
display_text_draw(struct font_freetype_text *text, struct graphics_priv *gr, struct graphics_gc_priv *fg, struct graphics_gc_priv *bg, struct point *p)
{
	int i,x,y,stride;
	struct font_freetype_glyph *g, **gp;
	struct color transparent={0x0,0x0,0x0,0x0};

	gp=text->glyph;
	i=text->glyph_count;
	x=p->x << 6;
	y=p->y << 6;
	while (i-- > 0)
	{
		g=*gp++;
		if (g->w && g->h && bg ) {
			unsigned char *shadow;
			stride=cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g->w+2);
			shadow=g_malloc(stride*(g->h+2));
			gr->freetype_methods.get_shadow(g, shadow, stride, &bg->c, &transparent);
			draw_rgb_image_buffer(gr->cairo, g->w+2, g->h+2, ((x+g->x)>>6)-1, ((y+g->y)>>6)-1, stride, shadow);
			g_free(shadow);
		}
		x+=g->dx;
		y+=g->dy;
	}
/**
 * cairo_image_surface_create_for_data:
 * @data: a pointer to a buffer supplied by the application in which
 *     to write contents. This pointer must be suitably aligned for any
 *     kind of variable, (for example, a pointer returned by malloc).
 * @format: the format of pixels in the buffer
 * @width: the width of the image to be stored in the buffer
 * @height: the height of the image to be stored in the buffer
 * @stride: the number of bytes between the start of rows in the
 *     buffer as allocated. This value should always be computed by
 *     cairo_format_stride_for_width() before allocating the data
 *     buffer.
 *
 * Creates an image surface for the provided pixel data. The output
 * buffer must be kept around until the #cairo_surface_t is destroyed
 * or cairo_surface_finish() is called on the surface.  The initial
 * contents of @data will be used as the initial image contents; you
 * must explicitly clear the buffer, using, for example,
 * cairo_rectangle() and cairo_fill() if you want it cleared.
 *
 * Note that the stride may be larger than
 * width*bytes_per_pixel to provide proper alignment for each pixel
 * and row. This alignment is required to allow high-performance rendering
 * within cairo. The correct way to obtain a legal stride value is to
 * call cairo_format_stride_for_width() with the desired format and
 * maximum image width value, and the use the resulting stride value
 * to allocate the data and to create the image surface. See
 * cairo_format_stride_for_width() for example code.
 *
 * Return value: a pointer to the newly created surface. The caller
 * owns the surface and should call cairo_surface_destroy() when done
 * with it.
 *
 * This function always returns a valid pointer, but it will return a
 * pointer to a "nil" surface in the case of an error such as out of
 * memory or an invalid stride value. In case of invalid stride value
 * the error status of the returned surface will be
 * %CAIRO_STATUS_INVALID_STRIDE.  You can use
 * cairo_surface_status() to check for this.
 *
 * See cairo_surface_set_user_data() for a means of attaching a
 * destroy-notification fallback to the surface if necessary.
 **/
cairo_surface_t *
cairo_image_surface_create_for_data (unsigned char     *data,
                                     cairo_format_t	format,
                                     int		width,
                                     int		height,
                                     int		stride)
{
    pixman_format_code_t pixman_format;
    int minstride;

    if (! CAIRO_FORMAT_VALID (format))
        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));

    if ((stride & (CAIRO_STRIDE_ALIGNMENT-1)) != 0)
        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));

    minstride = cairo_format_stride_for_width (format, width);
    if (stride < 0) {
        if (stride > -minstride) {
            return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
        }
    } else {
        if (stride < minstride) {
            return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
        }
    }

    pixman_format = _cairo_format_to_pixman_format_code (format);

    return _cairo_image_surface_create_with_pixman_format (data, pixman_format,
            width, height, stride);
}
static cairo_surface_t *
radeon_surface_create_internal (cairo_drm_device_t *device,
				cairo_format_t format,
				int width, int height)
{
    radeon_surface_t *surface;
    cairo_status_t status;

    surface = malloc (sizeof (radeon_surface_t));
    if (unlikely (surface == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));

    radeon_surface_init (surface, device, format, width, height);

    if (width && height) {
	surface->base.stride =
	    cairo_format_stride_for_width (surface->base.format, width);

	surface->base.bo = radeon_bo_create (to_radeon_device (&device->base),
					     surface->base.stride * height,
					     RADEON_GEM_DOMAIN_GTT);

	if (unlikely (surface->base.bo == NULL)) {
	    status = _cairo_drm_surface_finish (&surface->base);
	    free (surface);
	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	}
    }

    return &surface->base.base;
}
Example #7
0
void CairoGet(ImageBuffer& b, Size isz, cairo_surface_t *surface, cairo_surface_t *alpha_surface)
{
	cairo_surface_flush(surface);
	byte *a = (byte *)cairo_image_surface_get_data(surface);
	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx);
	RGBA *t = b;
	byte *aa = NULL;
	if(alpha_surface) {
		cairo_surface_flush(alpha_surface);
		aa = (byte *)cairo_image_surface_get_data(alpha_surface);
	}
	for(int yy = 0; yy < isz.cy; yy++) {
		RGBA *s = (RGBA *)a;
		RGBA *e = s + isz.cx;
		if(aa) {
			RGBA *ss = (RGBA *)aa;
			while(s < e) {
				*t = *s++;
				(t++)->a = (ss++)->r;
			}
			aa += stride;
		}
		else
			while(s < e) {
				*t = *s++;
				(t++)->a = 255;
			}
		a += stride;
	}
}
Example #8
0
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    const cairo_test_context_t *ctx = cairo_test_get_context (cr);
    cairo_format_t format = CAIRO_FORMAT_ARGB32;
    cairo_t *cr_src;
    cairo_surface_t *png, *src;
    uint8_t *data;
    int stride;

    png = cairo_test_create_surface_from_png (ctx, png_filename);

    stride = cairo_format_stride_for_width (format, width) + 12;
    data = xcalloc (stride, height);
    src = cairo_image_surface_create_for_data (data, format,
					       width, height, stride);

    cr_src = cairo_create (src);
    cairo_set_source_surface (cr_src, png, 0, 0);
    cairo_paint (cr_src);
    cairo_destroy (cr_src);

    cairo_set_source_surface (cr, src, 0, 0);
    cairo_paint (cr);

    cairo_surface_destroy (png);

    cairo_surface_finish (src);
    cairo_surface_destroy (src);

    free (data);

    return CAIRO_TEST_SUCCESS;
}
	RenderImageCairo::RenderImageCairo(void* data, size_t len)
	{
		int x, y, n;
		stbi_buffer_ = stbi_load_from_memory((const stbi_uc*)data, len, &x, &y, &n, 4);
		Color* pColorBegin = (Color*)stbi_buffer_;
		for (int i = 0; i < x*y; i++)
		{
			Color* pColor = pColorBegin + i;
			Color origin = *pColor;
			uint8 a = ColorGetA(origin);
			uint8 r = ColorGetB(origin);
			uint8 g = ColorGetG(origin);
			uint8 b = ColorGetR(origin);
			if (a < 255) {
				*pColor = ColorSetARGB(a, r*a/255, g*a/255, b*a/255);
			}
			else {
				*pColor = ColorSetARGB(a, r, g, b);
			}
		}

		size_.SetSize(x, y);

		cairo_format_t format = CAIRO_FORMAT_ARGB32;
		int stride = cairo_format_stride_for_width(format, x);
		image_surface_ = cairo_image_surface_create_for_data(stbi_buffer_, format, x, y, stride);
	}
Example #10
0
static cairo_surface_t *
_cairo_boilerplate_image16_create_similar (cairo_surface_t *other,
					   cairo_content_t content,
					   int width, int height)
{
    cairo_format_t format;
    cairo_surface_t *surface;
    int stride;
    void *ptr;

    switch (content) {
    case CAIRO_CONTENT_ALPHA: format = CAIRO_FORMAT_A8; break;
    case CAIRO_CONTENT_COLOR: format = CAIRO_FORMAT_RGB16_565; break;
    default:
    case CAIRO_CONTENT_COLOR_ALPHA: format = CAIRO_FORMAT_ARGB32; break;
    }

    stride = cairo_format_stride_for_width(format, width);
    ptr = malloc (stride* height);

    surface = cairo_image_surface_create_for_data (ptr, format,
						   width, height, stride);
    cairo_surface_set_user_data (surface, &key, ptr, free);

    return surface;
}
Example #11
0
static cairo_surface_t *
intel_surface_create (cairo_drm_device_t *device,
		      cairo_format_t format,
		      int width, int height)
{
    intel_surface_t *surface;
    cairo_status_t status;

    surface = malloc (sizeof (intel_surface_t));
    if (unlikely (surface == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));

    intel_surface_init (surface, &intel_surface_backend, device,
			format, width, height);

    if (width && height) {
	/* Vol I, p134: size restrictions for textures */
	width  = (width  + 3) & -4;
	height = (height + 1) & -2;
	surface->drm.stride =
	    cairo_format_stride_for_width (surface->drm.format, width);
	surface->drm.bo = &intel_bo_create (to_intel_device (&device->base),
					    surface->drm.stride * height,
					    surface->drm.stride * height,
					    TRUE, I915_TILING_NONE, surface->drm.stride)->base;
	if (surface->drm.bo == NULL) {
	    status = _cairo_drm_surface_finish (&surface->drm);
	    free (surface);
	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
	}
    }

    return &surface->drm.base;
}
Example #12
0
    void WriteImage(
            // source image data in RGB24 format
            uint8_t *srcData, int srcWidth, int srcHeight, 
            // offset
            int offsetX, int offsetY,
            // resize
            int tgtWidth, int tgtHeight)
    {
        typedef boost::shared_ptr<cairo_surface_t> SurfacePtr;

        cairo_save(ctx_);
        cairo_translate(ctx_, offsetX, offsetY);
        cairo_scale(ctx_, 
                static_cast<double>(tgtWidth)/srcWidth, 
                static_cast<double>(tgtHeight)/srcHeight);

        {
            int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, srcWidth);
            SurfacePtr srcSurface(
                    cairo_image_surface_create_for_data(
                        srcData, CAIRO_FORMAT_RGB24, srcWidth, srcHeight, stride),
                    cairo_surface_destroy);
            cairo_set_source_surface(ctx_, srcSurface.get(), 0, 0);
        }

        cairo_paint(ctx_);
        cairo_restore(ctx_);
    }
Example #13
0
static void size_allocate_callback(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
{
  dt_iop_module_t *self = (dt_iop_module_t *)user_data;
  dt_iop_zonesystem_gui_data_t *g = (dt_iop_zonesystem_gui_data_t *)self->gui_data;

  if(g->image) cairo_surface_destroy(g->image);
  free(g->image_buffer);

  /* load the dt logo as a brackground */
  char filename[PATH_MAX] = { 0 };
  char datadir[PATH_MAX] = { 0 };
  char *logo;
  dt_logo_season_t season = get_logo_season();
  if(season != DT_LOGO_SEASON_NONE)
    logo = g_strdup_printf("%%s/pixmaps/idbutton-%d.svg", (int)season);
  else
    logo = g_strdup("%s/pixmaps/idbutton.svg");

  dt_loc_get_datadir(datadir, sizeof(datadir));
  snprintf(filename, sizeof(filename), logo, datadir);
  g_free(logo);
  RsvgHandle *svg = rsvg_handle_new_from_file(filename, NULL);
  if(svg)
  {
    cairo_surface_t *surface;
    cairo_t *cr;

    RsvgDimensionData dimension;
    rsvg_handle_get_dimensions(svg, &dimension);

    float svg_size = MAX(dimension.width, dimension.height);
    float final_size = MIN(allocation->width, allocation->height) * 0.75;
    float factor = final_size / svg_size;
    float final_width = dimension.width * factor * darktable.gui->ppd,
          final_height = dimension.height * factor * darktable.gui->ppd;
    int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, final_width);

    g->image_buffer = (guint8 *)calloc(stride * final_height, sizeof(guint8));
    surface = dt_cairo_image_surface_create_for_data(g->image_buffer, CAIRO_FORMAT_ARGB32, final_width,
                                                     final_height, stride);
    if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS)
    {
      free(g->image_buffer);
      g->image_buffer = NULL;
    }
    else
    {
      cr = cairo_create(surface);
      cairo_scale(cr, factor, factor);
      rsvg_handle_render_cairo(svg, cr);
      cairo_destroy(cr);
      cairo_surface_flush(surface);
      g->image = surface;
      g->image_width = final_width / darktable.gui->ppd;
      g->image_height = final_height / darktable.gui->ppd;
    }
    g_object_unref(svg);
  }
}
Example #14
0
gint
image_setup (GimpDrawable *drawable,
             gint       interactive)
{
  /* Set the tile cache size */
  /* ======================= */

  gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) /
                          gimp_tile_width ());

  /* Get some useful info on the input drawable */
  /* ========================================== */

  input_drawable  = drawable;
  output_drawable = drawable;

  if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y,
                                      &border_w, &border_h))
    return FALSE;

  width  = input_drawable->width;
  height = input_drawable->height;

  gimp_pixel_rgn_init (&source_region, input_drawable,
                       0, 0, width, height, FALSE, FALSE);

  maxcounter = (glong) width * (glong) height;

  if (mapvals.transparent_background == TRUE)
    {
      gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0);
    }
  else
    {
      gimp_context_get_background (&background);
      gimp_rgb_set_alpha (&background, 1.0);
    }

  /* Assume at least RGB */
  /* =================== */

  in_channels = 3;
  if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE)
    in_channels++;

  if (interactive == TRUE)
    {
      preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24,
                                                          PREVIEW_WIDTH);
      preview_rgb_data = g_new0 (guchar, preview_rgb_stride * PREVIEW_HEIGHT);
      preview_surface = cairo_image_surface_create_for_data (preview_rgb_data,
                                                             CAIRO_FORMAT_RGB24,
                                                             PREVIEW_WIDTH,
                                                             PREVIEW_HEIGHT,
                                                             preview_rgb_stride);
    }

  return TRUE;
}
/* Create a cairo surface using the specified framebuffer */
cairo_surface_t *cairo_linuxfb_surface_create(cairo_linuxfb_device_t *device, const char *fb_name)
{
    cairo_surface_t *surface;

    // Open the file for reading and writing
    device->fb_fd = open(fb_name, O_RDWR);
    if (device->fb_fd == -1) {
        perror("Error: cannot open framebuffer device");
        goto handle_allocate_error;
    }

    // Get variable screen information
    if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) {
        perror("Error: reading variable information");
        goto handle_ioctl_error;
    }

    /* Set virtual display size double the width for double buffering */
    device->fb_vinfo.yoffset = 0;
    device->fb_vinfo.yres_virtual = device->fb_vinfo.yres * 2;
    if (ioctl(device->fb_fd, FBIOPUT_VSCREENINFO, &device->fb_vinfo)) {
        perror("Error setting variable screen info from fb");
        goto handle_ioctl_error;
    }

    // Get fixed screen information
    if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) {
        perror("Error reading fixed information");
        goto handle_ioctl_error;
    }

    // Map the device to memory
    device->fb_data = (unsigned char *)mmap(0, device->fb_finfo.smem_len,
                                            PROT_READ | PROT_WRITE, MAP_SHARED,
                                            device->fb_fd, 0);
    if ((int)device->fb_data == -1) {
        perror("Error: failed to map framebuffer device to memory");
        goto handle_ioctl_error;
    }


    /* Create the cairo surface which will be used to draw to */
    surface = cairo_image_surface_create_for_data(device->fb_data,
              CAIRO_FORMAT_RGB16_565,
              device->fb_vinfo.xres,
              device->fb_vinfo.yres_virtual,
              cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565,
                                            device->fb_vinfo.xres));
    cairo_surface_set_user_data(surface, NULL, device,
                                &cairo_linuxfb_surface_destroy);

    return surface;

handle_ioctl_error:
    close(device->fb_fd);
handle_allocate_error:
    free(device);
    exit(1);
}
Example #16
0
void init_graphicslib(void)
{
	int stride;
	stride=cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565, 160);
	printf("stride is %d\n", stride);
	cs=cairo_image_surface_create_for_data(cairobuff, CAIRO_FORMAT_RGB16_565, 160, 120, stride);
	c=cairo_create(cs);
}
Example #17
0
static cairo_surface_t *
display_create_shm_surface(struct display *display,
			   struct rectangle *rectangle)
{
	struct shm_surface_data *data;
	cairo_surface_t *surface;
	struct wl_visual *visual;
	int stride, fd;
	char filename[] = "/tmp/wayland-shm-XXXXXX";

	data = malloc(sizeof *data);
	if (data == NULL)
		return NULL;

	stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
						rectangle->width);
	data->length = stride * rectangle->height;
	fd = mkstemp(filename);
	if (fd < 0) {
		fprintf(stderr, "open %s failed: %m", filename);
		return NULL;
	}
	if (ftruncate(fd, data->length) < 0) {
		fprintf(stderr, "ftruncate failed: %m");
		close(fd);
		return NULL;
	}

	data->map = mmap(NULL, data->length,
			 PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	unlink(filename);

	if (data->map == MAP_FAILED) {
		fprintf(stderr, "mmap failed: %m");
		close(fd);
		return NULL;
	}

	surface = cairo_image_surface_create_for_data (data->map,
						       CAIRO_FORMAT_ARGB32,
						       rectangle->width,
						       rectangle->height,
						       stride);

	cairo_surface_set_user_data (surface, &surface_data_key,
				     data, shm_surface_data_destroy);

	visual = wl_display_get_premultiplied_argb_visual(display->display);
	data->data.buffer = wl_shm_create_buffer(display->shm,
						 fd,
						 rectangle->width,
						 rectangle->height,
						 stride, visual);

	close(fd);

	return surface;
}
Example #18
0
    virtual int ARGB(Plugin::FeatureSet features, int width,
        int height, unsigned char *bitmap, int sampleRate)
    {
      const double lower = MIN_FREQ;
      const double higher = MAX_FREQ;
      const double lower_log = log10(lower);
      const double higher_log = log10(higher);

      // set up cairo surface
      cairo_surface_t *surface;
      cairo_format_t format = CAIRO_FORMAT_ARGB32;
      int stride = cairo_format_stride_for_width(format, width);
      surface = cairo_image_surface_create_for_data (bitmap, format, width,
          height, stride);

      // set up cairo context
      cairo_t *cr;
      cr = cairo_create(surface);
      cairo_scale(cr, width, height);
      cairo_set_source_rgba(cr, BG_COLOUR);
      cairo_paint(cr);

      // find number of frames for peak/spec centroid
      unsigned int peakFrames = features[0].size();
      unsigned int scFrames = features[1].size();
      double scScale = (double)scFrames/(double)peakFrames;

      // for each peak frame, draw a colored line
      for (unsigned int peakFrame=0; peakFrame<peakFrames; peakFrame++)
      {
        // find spectral contrast, clip and scale
        double sc = features[1].at(floor(scScale*peakFrame)).values[0];
        if (sc < lower) sc=lower;
        if (sc > higher) sc=higher;
        sc = (log10(sc)-lower_log)/(higher_log-lower_log);

        // get peak values
        double peak1 = features[0].at(peakFrame).values[0];
        double peak2 = features[0].at(peakFrame).values[1];
        
        // draw waveform
        cairo_set_source_rgba(cr, red(sc), green(sc), blue(sc), 1.0);
        cairo_line_to(cr, (double)peakFrame/(double)peakFrames,
                          0.5-(peak1*0.5));
        cairo_line_to(cr, (double)peakFrame/(double)peakFrames,
                          0.5-(peak2*0.5));
        cairo_set_line_width (cr, 0.1/(double)width);
        cairo_stroke (cr);
      }

      // clean up
      cairo_destroy(cr);
      cairo_surface_destroy (surface);

      return 0;
    }
Example #19
0
static void		save_file(GtkWidget *widget, t_env *rt)
{
	cairo_surface_t *surface;

	surface = cairo_image_surface_create_for_data((unsigned char *)rt->tmp_data,
	CAIRO_FORMAT_ARGB32, rt->w, rt->h,
	cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, rt->w));
	cairo_surface_write_to_png(surface, gtk_entry_get_text(GTK_ENTRY(widget)));
	gtk_widget_destroy(rt->dialog);
}
ImageGStreamer::ImageGStreamer(GstBuffer*& buffer, IntSize size, cairo_format_t& cairoFormat)
    : m_image(0)
    , m_surface(0)
{
    m_surface = cairo_image_surface_create_for_data(GST_BUFFER_DATA(buffer), cairoFormat,
                                                    size.width(), size.height(),
                                                    cairo_format_stride_for_width(cairoFormat, size.width()));
    ASSERT(cairo_surface_status(m_surface) == CAIRO_STATUS_SUCCESS);
    m_image = BitmapImage::create(m_surface);
}
cairo_surface_t* UpdateChunk::createImage() const
{
    ASSERT(m_sharedMemory);
    if (!m_sharedMemory)
        return 0;

    int stride = cairo_format_stride_for_width(imageFormat, m_rect.width());
    return cairo_image_surface_create_for_data(static_cast<unsigned char*>(m_sharedMemory->data()),
                                               imageFormat, m_rect.width(), m_rect.height(), stride);
}
Example #22
0
cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name)
{
  cairo_linuxfb_device_t *device;
  cairo_surface_t *surface;

  if (fb_name == NULL) {
    fb_name = "/dev/fb1";
  }

  device = malloc(sizeof(*device));

  // Open the file for reading and writing
  device->fb_fd = open(fb_name, O_RDWR);
  if (device->fb_fd == -1) {
    perror("Error: cannot open framebuffer device");
    exit(1);
  }

  // Get variable screen information
  if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) {
    perror("Error reading variable information");
    exit(3);
  }

  // Figure out the size of the screen in bytes
  device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres
    * device->fb_vinfo.bits_per_pixel / 8;

  // Map the device to memory
  device->fb_data = (char *)mmap(0, device->fb_screensize,
				 PROT_READ | PROT_WRITE, MAP_SHARED,
				 device->fb_fd, 0);
  if ((int)device->fb_data == -1) {
    perror("Error: failed to map framebuffer device to memory");
    exit(4);
  }

  // Get fixed screen information
  if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) {
    perror("Error reading fixed information");
    exit(2);
  }

  surface = cairo_image_surface_create_for_data(device->fb_data,
						CAIRO_FORMAT_RGB16_565,
						device->fb_vinfo.xres,
						device->fb_vinfo.yres,
						cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565,
									      device->fb_vinfo.xres));
  cairo_surface_set_user_data(surface, NULL, device,
			      &cairo_linuxfb_surface_destroy);

  return surface;
}
Example #23
0
CairoFrame::CairoFrame(coord_t w, coord_t h) 
        : RawFrame(w, h, RawFrame::BGRAn8, 
        cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w)) {

    crs = cairo_image_surface_create_for_data(_data, CAIRO_FORMAT_ARGB32,
            _w, _h, _pitch);

    if (cairo_surface_status(crs) != CAIRO_STATUS_SUCCESS) {
        throw std::runtime_error("Cairo surface creation failed");
    }
}
Example #24
0
LcCairoPainter* LcCairoPainter::createImagePainter(unsigned char* data , int width, int height) {
    cairo_surface_t* surface;
    cairo_t* cr;
    int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
    surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,  width,  height, stride);
    cr = cairo_create(surface);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
    cairo_set_tolerance(cr, 0.25);
    cairo_set_antialias(cr, CAIRO_ANTIALIAS_GOOD);
    return new LcCairoPainter(surface, cr);
}
Example #25
0
int ui_create_window(lua_State *L)
{
	struct window_fb *window =
		lua_newuserdata(L, sizeof(struct window_fb));

	/* open the file for reading and writing */
	window->fb_fd = open("/dev/fb0", O_RDWR);
	if (window->fb_fd == -1) {
		perror("Error: cannot open framebuffer device");
		exit(1);
	}

	/* get variable screen information */
	if (ioctl(window->fb_fd, FBIOGET_VSCREENINFO, &window->fb_vinfo) == -1) {
		perror("Error reading variable information");
		exit(3);
	}

	/* figure out the size of the screen in bytes */
	window->fb_screensize = window->fb_vinfo.xres * window->fb_vinfo.yres
		* window->fb_vinfo.bits_per_pixel / 8;

	/* map the device to memory */
	window->fb_data = mmap(0, window->fb_screensize,
			       PROT_READ | PROT_WRITE, MAP_SHARED,
			       window->fb_fd, 0);
	if (window->fb_data == (unsigned char *)-1) {
		perror("Error: failed to map framebuffer device to memory");
		exit(4);
	}

	/* clear screen */
	memset(window->fb_data, 0x010101, window->fb_screensize);

	window->surface = cairo_image_surface_create_for_data(window->fb_data,
	              CAIRO_FORMAT_RGB16_565,
	              window->fb_vinfo.xres,
	              window->fb_vinfo.yres,
		      cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565,
						    window->fb_vinfo.xres));

	window->ev_fd = open("/dev/input/event1", O_RDWR);
	if (window->ev_fd == -1) {
		perror("Error: cannot open keyboard");
		exit(1);
	}

	luaL_getmetatable(L, "ui.window");
	lua_setmetatable(L, -2);

	return 1;
}
void guac_rdp_glyph_new(rdpContext* context, rdpGlyph* glyph) {

    int x, y, i;
    int stride;
    unsigned char* image_buffer;
    unsigned char* image_buffer_row;

    unsigned char* data = glyph->aj;
    int width  = glyph->cx;
    int height = glyph->cy;

    /* Init Cairo buffer */
    stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
    image_buffer = malloc(height*stride);
    image_buffer_row = image_buffer;

    /* Copy image data from image data to buffer */
    for (y = 0; y<height; y++) {

        unsigned int*  image_buffer_current;
        
        /* Get current buffer row, advance to next */
        image_buffer_current  = (unsigned int*) image_buffer_row;
        image_buffer_row     += stride;

        for (x = 0; x<width;) {

            /* Get byte from image data */
            unsigned int v = *(data++);

            /* Read bits, write pixels */
            for (i = 0; i<8 && x<width; i++, x++) {

                /* Output RGB */
                if (v & 0x80)
                    *(image_buffer_current++) = 0xFF000000;
                else
                    *(image_buffer_current++) = 0x00000000;

                /* Next bit */
                v <<= 1;

            }

        }
    }

    /* Store glyph surface */
    ((guac_rdp_glyph*) glyph)->surface = cairo_image_surface_create_for_data(
            image_buffer, CAIRO_FORMAT_ARGB32, width, height, stride);

}
Example #27
0
cairo_surface_t *
joy_gfx3d_screen_cairo_surface_create(JoyScreen *self, GFX3D_Image image)
{
	g_return_val_if_fail(JOY_IS_GFX3D_SCREEN(self), NULL);
	g_return_val_if_fail(image, NULL);
	struct Private *priv = GET_PRIVATE(self);
#if CAIRO_HAS_GFX3D_SURFACE
	cairo_surface_t *surface =
		cairo_gfx3d_surface_create(priv->display, image);
	cairo_status_t status = cairo_surface_status(surface);
	if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) {
		return NULL;
	}
	cairo_gfx3d_surface_set_owner(surface, TRUE);
	return surface;
#else // CAIRO_HAS_GFX3D_SURFACE
	GFX3D_Rect rect;
	GFX3D_Image_GetRect(image, &rect);
	gint stride;
	void *pixels = GFX3D_NATIVE_Surface_GetAddress(
			GFX3D_Image_Get_NATIVE_Surface(image), &stride);
	if (G_UNLIKELY(!pixels)) {
		return NULL;
	}
	stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
			rect.iWidth);
	cairo_surface_t *surface = cairo_image_surface_create_for_data(pixels,
			CAIRO_FORMAT_ARGB32, rect.iWidth, rect.iHeight,
			stride);
	cairo_status_t status = cairo_surface_status(surface);
	if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) {
		cairo_surface_destroy(surface);
		return NULL;
	}
	struct Data *data = g_slice_new0(struct Data);
	if (G_UNLIKELY(!data)) {
		cairo_surface_destroy(surface);
		return NULL;
	}
	data->display = priv->display;
	data->image = image;
	status = cairo_surface_set_user_data(surface, &key, data,
			(cairo_destroy_func_t)data_destroy);
	if (G_UNLIKELY(CAIRO_STATUS_SUCCESS != status)) {
		cairo_surface_destroy(surface);
		g_slice_free(struct Data, data);
		return NULL;
	}
	return surface;
#endif // CAIRO_HAS_GFX3D_SURFACE
}
Example #28
0
cairo_surface_t *CreateCairoSurface(const Image& img)
{
	Size isz = img.GetSize();
	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, isz.cx, isz.cy);
	cairo_surface_flush(surface);
	byte *a = (byte *)cairo_image_surface_get_data(surface);
	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, isz.cx);
	for(int yy = 0; yy < isz.cy; yy++) {
		Copy((RGBA *)a, img[yy], isz.cx);
		a += stride;
	}
	cairo_surface_mark_dirty(surface);
	return surface;
}
Example #29
0
static void _pdf_doc_render_page(
    struct _pdf_doc *self, cairo_t *cr, int x, int y,
    int pageno, mume_matrix_t ctm, mume_rect_t rect)
{
    /* TODO: implement a fz_device to rendering directly to cairo. */
    fz_colorspace *colorspace;
    fz_bbox bbox;
    fz_device *idev;
    fz_pixmap *pixmap;
    fz_display_list *list;
    cairo_format_t format;
    cairo_surface_t *surface;
    int stride;

#ifdef _WIN32
    colorspace = fz_device_bgr;
#else
    colorspace = fz_device_rgb;
#endif

    list = _pdf_doc_get_list(self, pageno);
    bbox = _mume_rect_to_fz_bbox(rect);
    pixmap = fz_new_pixmap_with_rect(colorspace, bbox);
    if (NULL == pixmap) {
        mume_error(("fz_new_pixmap_with_rect(%d, %d, %d, %d)\n",
                    bbox.x0, bbox.y0, bbox.x1, bbox.y1));
        return;
    }

    fz_clear_pixmap_with_color(pixmap, 255);
    idev = fz_new_draw_device(self->glyph_cache, pixmap);
    fz_execute_display_list(
        list, idev, _mume_matrix_to_fz_matrix(ctm), bbox);
    fz_free_device(idev);

    /* Create cairo surface. */
    format = CAIRO_FORMAT_ARGB32;
    stride = cairo_format_stride_for_width(format, pixmap->w);
    surface = cairo_image_surface_create_for_data(
        pixmap->samples, format, pixmap->w, pixmap->h, stride);

    if (surface) {
        cairo_set_source_surface(cr, surface, x, y);
        cairo_rectangle(cr, x, y, rect.width, rect.height);
        cairo_fill(cr);
        cairo_surface_destroy(surface);
    }

    fz_drop_pixmap(pixmap);
}
Example #30
0
static void remmina_rdp_event_connected(RemminaProtocolWidget* gp, RemminaPluginRdpUiObject* ui)
{
	rfContext* rfi;
	int stride;

	rfi = GET_DATA(gp);

	gtk_widget_realize(rfi->drawing_area);

	stride = cairo_format_stride_for_width(rfi->cairo_format, rfi->width);
	rfi->surface = cairo_image_surface_create_for_data((unsigned char*) rfi->primary_buffer, rfi->cairo_format, rfi->width, rfi->height, stride);
	gtk_widget_queue_draw_area(rfi->drawing_area, 0, 0, rfi->width, rfi->height);

	remmina_rdp_event_update_scale(gp);
}