Beispiel #1
0
void
bench_composite (const char *testname,
                 int         src_fmt,
                 int         src_flags,
                 int         op,
                 int         mask_fmt,
                 int         mask_flags,
                 int         dst_fmt,
                 double      npix)
{
    pixman_image_t *                src_img;
    pixman_image_t *                dst_img;
    pixman_image_t *                mask_img;
    pixman_image_t *                xsrc_img;
    pixman_image_t *                xdst_img;
    pixman_image_t *                xmask_img;
    double                          t1, t2, t3, pix_cnt;
    int64_t                         n, l1test_width, nlines;
    double                             bytes_per_pix = 0;
    pixman_bool_t                   bench_pixbuf = FALSE;

    pixman_composite_func_t func = pixman_image_composite_wrapper;

    if (!(src_flags & SOLID_FLAG))
    {
        bytes_per_pix += (src_fmt >> 24) / 8.0;
        src_img = pixman_image_create_bits (src_fmt,
                                            WIDTH, HEIGHT,
                                            src,
                                            WIDTH * 4);
        xsrc_img = pixman_image_create_bits (src_fmt,
                                             XWIDTH, XHEIGHT,
                                             src,
                                             XWIDTH * 4);
    }
Beispiel #2
0
static pixman_image_t *
create_image (pixman_image_t **clone)
{
    pixman_format_code_t format = RANDOM_ELT (formats);
    pixman_image_t *image;
    int width = prng_rand_n (MAX_WIDTH);
    int height = prng_rand_n (MAX_HEIGHT);
    int stride = ((width * (PIXMAN_FORMAT_BPP (format) / 8)) + 3) & ~3;
    uint32_t *bytes = malloc (stride * height);

    prng_randmemset (bytes, stride * height, RANDMEMSET_MORE_00_AND_FF);

    image = pixman_image_create_bits (
        format, width, height, bytes, stride);

    pixman_image_set_destroy_function (image, free_bits, NULL);

    assert (image);

    if (clone)
    {
        uint32_t *bytes_dup = malloc (stride * height);

        memcpy (bytes_dup, bytes, stride * height);

        *clone = pixman_image_create_bits (
            format, width, height, bytes_dup, stride);

        pixman_image_set_destroy_function (*clone, free_bits, NULL);
    }
    
    return image;
}
Beispiel #3
0
int
main (int argc, char **argv)
{
    uint32_t dst[SIZE];
    pixman_image_t *src_img;
    pixman_image_t *dst_img;
    int i, j, x, y;
    int ret = 0;

    for (i = 0; i < n_test_cases; ++i)
    {
	for (j = 0; j < 2; ++j)
	{
	    src_img = pixman_image_create_bits (testcases[i].format,
						testcases[i].width,
						testcases[i].height,
						testcases[i].src,
						testcases[i].stride);
	    pixman_image_set_indexed(src_img, testcases[i].indexed);

	    dst_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
						testcases[i].width,
						testcases[i].height,
						dst,
						testcases[i].width*4);

	    if (j)
	    {
		pixman_image_set_accessors (src_img, reader, writer);
		pixman_image_set_accessors (dst_img, reader, writer);
	    }

	    pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img,
				    0, 0, 0, 0, 0, 0, testcases[i].width, testcases[i].height);

	    pixman_image_unref (src_img);
	    pixman_image_unref (dst_img);

	    for (y = 0; y < testcases[i].height; ++y)
	    {
		for (x = 0; x < testcases[i].width; ++x)
		{
		    int offset = y * testcases[i].width + x;

		    if (dst[offset] != testcases[i].dst[offset])
		    {
			printf ("test %i%c: pixel mismatch at (x=%d,y=%d): %08x expected, %08x obtained\n",
			        i + 1, 'a' + j,
			        x, y,
			        testcases[i].dst[offset], dst[offset]);
			ret = 1;
		    }
		}
	    }
	}
    }

    return ret;
}
int
main ()
{
    int o, s, m, d;

    enable_fp_exceptions();

    for (o = 0; o < ARRAY_LENGTH (pdf_ops); ++o)
    {
	pixman_op_t op = pdf_ops[o];

	for (s = 0; s < ARRAY_LENGTH (pixels); ++s)
	{
	    pixman_image_t *src;

	    src = pixman_image_create_bits (
		PIXMAN_a8r8g8b8, 1, 1, (uint32_t *)&(pixels[s]), 4);

	    for (m = -1; m < ARRAY_LENGTH (pixels); ++m)
	    {
		pixman_image_t *msk = NULL;
		if (m >= 0)
		{
		    msk = pixman_image_create_bits (
			PIXMAN_a8r8g8b8, 1, 1, (uint32_t *)&(pixels[m]), 4);
		}

		for (d = 0; d < ARRAY_LENGTH (pixels); ++d)
		{
		    pixman_image_t *dst;
		    uint32_t dp = pixels[d];

		    dst = pixman_image_create_bits (
			PIXMAN_a8r8g8b8, 1, 1, &dp, 4);

		    pixman_image_composite (op, src, msk, dst,
					    0, 0, 0, 0, 0, 0, 1, 1);

		    pixman_image_unref (dst);
		}
		if (msk)
		    pixman_image_unref (msk);
	    }

	    pixman_image_unref (src);
	}
    }

    return 0;
}
static void
Transform(DataSourceSurface* aDest,
          DataSourceSurface* aSource,
          const gfx3DMatrix& aTransform,
          const Point& aDestOffset)
{
  IntSize destSize = aDest->GetSize();
  pixman_image_t* dest = pixman_image_create_bits(PIXMAN_a8r8g8b8,
                                                  destSize.width,
                                                  destSize.height,
                                                  (uint32_t*)aDest->GetData(),
                                                  aDest->Stride());

  IntSize srcSize = aSource->GetSize();
  pixman_image_t* src = pixman_image_create_bits(PIXMAN_a8r8g8b8,
                                                 srcSize.width,
                                                 srcSize.height,
                                                 (uint32_t*)aSource->GetData(),
                                                 aSource->Stride());

  MOZ_ASSERT(src !=0 && dest != 0, "Failed to create pixman images?");

  pixman_transform pixTransform = Matrix3DToPixman(aTransform);
  pixman_transform pixTransformInverted;

  // If the transform is singular then nothing would be drawn anyway, return here
  if (!pixman_transform_invert(&pixTransformInverted, &pixTransform)) {
    pixman_image_unref(dest);
    pixman_image_unref(src);
    return;
  }
  pixman_image_set_transform(src, &pixTransformInverted);

  pixman_image_composite32(PIXMAN_OP_SRC,
                           src,
                           nullptr,
                           dest,
                           aDestOffset.x,
                           aDestOffset.y,
                           0,
                           0,
                           0,
                           0,
                           destSize.width,
                           destSize.height);

  pixman_image_unref(dest);
  pixman_image_unref(src);
}
Beispiel #6
0
pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
        int width)
{
    pixman_image_t *image = pixman_image_create_bits(format, width, 1, NULL, 0);
    assert(image != NULL);
    return image;
}
Beispiel #7
0
static XImage *create_temp_image(int screen, int width, int height,
                                 pixman_image_t **pixman_image_out,
                                 XShmSegmentInfo **shminfo_out)
{
    XImage *image;
    XShmSegmentInfo *shminfo;
    RedDrawable::Format format;
    pixman_image_t *pixman_image;
    XVisualInfo *vinfo;

    image = NULL;
    shminfo = NULL;

    vinfo = XPlatform::get_vinfo()[screen];
    format = XPlatform::get_screen_format(screen);

    image = XPlatform::create_x_image(format, width, height, vinfo->depth,
					  vinfo->visual, &shminfo);

    pixman_image = pixman_image_create_bits(RedDrawable::format_to_pixman(format),
                                            width, height,
                                            (uint32_t *)image->data, image->bytes_per_line);
    if (pixman_image == NULL) {
        THROW("surf create failed");
    }
    *pixman_image_out = pixman_image;
    *shminfo_out = shminfo;
    return image;
}
Beispiel #8
0
static int
pixman_renderer_surface_copy_content(struct weston_surface *surface,
				     void *target, size_t size,
				     int src_x, int src_y,
				     int width, int height)
{
	const pixman_format_code_t format = PIXMAN_a8b8g8r8;
	const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */
	struct pixman_surface_state *ps = get_surface_state(surface);
	pixman_image_t *out_buf;

	if (!ps->image)
		return -1;

	out_buf = pixman_image_create_bits(format, width, height,
					   target, width * bytespp);

	pixman_image_set_transform(ps->image, NULL);
	pixman_image_composite32(PIXMAN_OP_SRC,
				 ps->image,    /* src */
				 NULL,         /* mask */
				 out_buf,      /* dest */
				 src_x, src_y, /* src_x, src_y */
				 0, 0,         /* mask_x, mask_y */
				 0, 0,         /* dest_x, dest_y */
				 width, height);

	pixman_image_unref(out_buf);

	return 0;
}
static int
headless_compositor_create_output(struct headless_compositor *c,
				  struct headless_parameters *param)
{
	struct headless_output *output;
	struct wl_event_loop *loop;

	output = zalloc(sizeof *output);
	if (output == NULL)
		return -1;

	output->mode.flags =
		WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
	output->mode.width = param->width;
	output->mode.height = param->height;
	output->mode.refresh = 60000;
	wl_list_init(&output->base.mode_list);
	wl_list_insert(&output->base.mode_list, &output->mode.link);

	output->base.current_mode = &output->mode;
	weston_output_init(&output->base, &c->base, 0, 0, param->width,
			   param->height, param->transform, 1);

	output->base.make = "weston";
	output->base.model = "headless";

	loop = wl_display_get_event_loop(c->base.wl_display);
	output->finish_frame_timer =
		wl_event_loop_add_timer(loop, finish_frame_handler, output);

	output->base.start_repaint_loop = headless_output_start_repaint_loop;
	output->base.repaint = headless_output_repaint;
	output->base.destroy = headless_output_destroy;
	output->base.assign_planes = NULL;
	output->base.set_backlight = NULL;
	output->base.set_dpms = NULL;
	output->base.switch_mode = NULL;

	if (c->use_pixman) {
		output->image_buf = malloc(param->width * param->height * 4);
		if (!output->image_buf)
			return -1;

		output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8,
							 param->width,
							 param->height,
							 output->image_buf,
							 param->width * 4);

		if (pixman_renderer_output_create(&output->base) < 0)
			return -1;

		pixman_renderer_output_set_buffer(&output->base,
						  output->image);
	}

	wl_list_insert(c->base.output_list.prev, &output->base.link);

	return 0;
}
Beispiel #10
0
int xrdp_server_shared_framebuffer(xrdpModule* mod, XRDP_MSG_SHARED_FRAMEBUFFER* msg)
{
	mod->framebuffer.fbWidth = msg->width;
	mod->framebuffer.fbHeight = msg->height;
	mod->framebuffer.fbScanline = msg->scanline;
	mod->framebuffer.fbSegmentId = msg->segmentId;
	mod->framebuffer.fbBitsPerPixel = msg->bitsPerPixel;
	mod->framebuffer.fbBytesPerPixel = msg->bytesPerPixel;

	printf("received shared framebuffer message: mod->framebuffer.fbAttached: %d msg->attach: %d\n",
			mod->framebuffer.fbAttached, msg->attach);

	if (!mod->framebuffer.fbAttached && msg->attach)
	{
		mod->framebuffer.fbSharedMemory = (BYTE*) shmat(mod->framebuffer.fbSegmentId, 0, 0);
		mod->framebuffer.fbAttached = TRUE;

		printf("attached segment %d to %p\n",
				mod->framebuffer.fbSegmentId, mod->framebuffer.fbSharedMemory);

		mod->framebuffer.image = (void*) pixman_image_create_bits(PIXMAN_x8r8g8b8,
				mod->framebuffer.fbWidth, mod->framebuffer.fbHeight,
				(uint32_t*) mod->framebuffer.fbSharedMemory, mod->framebuffer.fbScanline);
	}

	if (mod->framebuffer.fbAttached && !msg->attach)
	{
		shmdt(mod->framebuffer.fbSharedMemory);
		mod->framebuffer.fbAttached = FALSE;
		mod->framebuffer.fbSharedMemory = 0;
	}

	return 0;
}
Beispiel #11
0
static inline pixman_image_t *__surface_create_stride(pixman_format_code_t format, int width, int height,
                                                      int stride)
{
    uint8_t *data;
    uint8_t *stride_data;
    pixman_image_t *surface;
    PixmanData *pixman_data;

    data = (uint8_t *)spice_malloc_n(abs(stride), height);
    if (stride < 0) {
        stride_data = data + (-stride) * (height - 1);
    } else {
        stride_data = data;
    }

    surface = pixman_image_create_bits(format, width, height, (uint32_t *)stride_data, stride);

    if (surface == NULL) {
        free(data);
        spice_error("create surface failed, out of memory");
    }

    pixman_data = pixman_image_add_data(surface);
    pixman_data->data = data;
    pixman_data->format = format;

    return surface;
}
cairo_surface_t *
_cairo_image_surface_create_with_pixman_format (unsigned char		*data,
						pixman_format_code_t	 pixman_format,
						int			 width,
						int			 height,
						int			 stride)
{
    cairo_surface_t *surface;
    pixman_image_t *pixman_image;

    if (! _cairo_image_surface_is_size_valid (width, height))
    {
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
    }

    pixman_image = pixman_image_create_bits (pixman_format, width, height,
					     (uint32_t *) data, stride);

    if (unlikely (pixman_image == NULL))
	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));

    surface = _cairo_image_surface_create_for_pixman_image (pixman_image,
							    pixman_format);
    if (unlikely (surface->status)) {
	pixman_image_unref (pixman_image);
	return surface;
    }

    /* we can not make any assumptions about the initial state of user data */
    surface->is_clear = data == NULL;
    return surface;
}
WL_EXPORT int
pixman_renderer_output_create(struct weston_output *output)
{
	struct pixman_output_state *po = calloc(1, sizeof *po);
	int w, h;

	if (!po)
		return -1;

	/* set shadow image transformation */
	w = output->current_mode->width;
	h = output->current_mode->height;

	po->shadow_buffer = malloc(w * h * 4);

	if (!po->shadow_buffer) {
		free(po);
		return -1;
	}

	po->shadow_image =
		pixman_image_create_bits(PIXMAN_x8r8g8b8, w, h,
					 po->shadow_buffer, w * 4);

	if (!po->shadow_image) {
		free(po->shadow_buffer);
		free(po);
		return -1;
	}

	output->renderer_state = po;

	return 0;
}
Beispiel #14
0
static pixman_image_t *
create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
{
    PixmapPtr pixmap;
    FbBits *bits;
    FbStride stride;
    int bpp;
    pixman_image_t *image;

    fbGetDrawablePixmap(pict->pDrawable, pixmap, *xoff, *yoff);
    fbGetPixmapBitsData(pixmap, bits, stride, bpp);

    image = pixman_image_create_bits((pixman_format_code_t) pict->format,
                                     pixmap->drawable.width,
                                     pixmap->drawable.height, (uint32_t *) bits,
                                     stride * sizeof(FbStride));

    if (!image)
        return NULL;

#ifdef FB_ACCESS_WRAPPER
#if FB_SHIFT==5

    pixman_image_set_accessors(image,
                               (pixman_read_memory_func_t) wfbReadMemory,
                               (pixman_write_memory_func_t) wfbWriteMemory);

#else

#error The pixman library only works when FbBits is 32 bits wide

#endif
#endif

    /* pCompositeClip is undefined for source pictures, so
     * only set the clip region for pictures with drawables
     */
    if (has_clip) {
        if (pict->clientClipType != CT_NONE)
            pixman_image_set_has_client_clip(image, TRUE);

        if (*xoff || *yoff)
            pixman_region_translate(pict->pCompositeClip, *xoff, *yoff);

        pixman_image_set_clip_region(image, pict->pCompositeClip);

        if (*xoff || *yoff)
            pixman_region_translate(pict->pCompositeClip, -*xoff, -*yoff);
    }

    /* Indexed table */
    if (pict->pFormat->index.devPrivate)
        pixman_image_set_indexed(image, pict->pFormat->index.devPrivate);

    /* Add in drawable origin to position within the image */
    *xoff += pict->pDrawable->x;
    *yoff += pict->pDrawable->y;

    return image;
}
Beispiel #15
0
static void process_image_data(struct fp_img_dev *dev, char **output, int *output_height)
{
    //pixman stuff taken from libfprint/pixman.c, adapted for my purposes.
    pixman_image_t *orig, *resized;
    pixman_transform_t transform;
    struct vfs0050_dev *vfs_dev = dev->priv;
    struct vfs0050_line *line, *calibration_line;
    char *buf = malloc(vfs_dev->scanbuf_idx);
    int lines = vfs_dev->scanbuf_idx / VFS0050_FRAME_SIZE;
    int i, x, sum, last_sum, diff;
    int new_height;
    //just grab one around middle, there should be 100
    calibration_line = (struct vfs0050_line *) ((char *) vfs_dev->calbuf + (50 * VFS0050_FRAME_SIZE));

    new_height = 0;
    for (i = 0; i < lines; i++) {
        line = (struct vfs0050_line *) ((char *) vfs_dev->scanbuf + (i * VFS0050_FRAME_SIZE));
        if (!is_noise(line))
            memcpy(buf + (new_height++ * VFS0050_IMG_WIDTH), line->row, VFS0050_IMG_WIDTH);
        else
            fp_dbg("removed noise at line: %d\n", i);
    }

    orig = pixman_image_create_bits(PIXMAN_a8, VFS0050_IMG_WIDTH, new_height, (uint32_t *) buf, VFS0050_IMG_WIDTH);
    new_height *= VFS0050_SCALE_FACTOR; //scale for resized image
    resized = pixman_image_create_bits(PIXMAN_a8, VFS0050_IMG_WIDTH, new_height, NULL, VFS0050_IMG_WIDTH);
    pixman_transform_init_identity(&transform);
    pixman_transform_scale(NULL, &transform, pixman_int_to_fixed(1), pixman_double_to_fixed(0.2));
    pixman_image_set_transform(orig, &transform);
    pixman_image_set_filter(orig, PIXMAN_FILTER_BEST, NULL, 0);
    pixman_image_composite32(PIXMAN_OP_SRC,
                             orig,
                             NULL,
                             resized,
                             0, 0,
                             0, 0,
                             0, 0,
                             VFS0050_IMG_WIDTH, new_height
                            );
    memcpy(buf, pixman_image_get_data(resized), VFS0050_IMG_WIDTH * new_height);

    pixman_image_unref(orig);
    pixman_image_unref(resized);

    *output_height = new_height;
    *output = buf;
}
Beispiel #16
0
static pixman_image_t *
load_jpeg(FILE *fp)
{
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;
	pixman_image_t *pixman_image = NULL;
	unsigned int i;
	int stride, first;
	JSAMPLE *data, *rows[4];
	jmp_buf env;

	cinfo.err = jpeg_std_error(&jerr);
	jerr.error_exit = error_exit;
	cinfo.client_data = env;
	if (setjmp(env))
		return NULL;

	jpeg_create_decompress(&cinfo);

	jpeg_stdio_src(&cinfo, fp);

	jpeg_read_header(&cinfo, TRUE);

	cinfo.out_color_space = JCS_RGB;
	jpeg_start_decompress(&cinfo);

	stride = cinfo.output_width * 4;
	data = malloc(stride * cinfo.output_height);
	if (data == NULL) {
		fprintf(stderr, "couldn't allocate image data\n");
		return NULL;
	}

	while (cinfo.output_scanline < cinfo.output_height) {
		first = cinfo.output_scanline;
		for (i = 0; i < ARRAY_LENGTH(rows); i++)
			rows[i] = data + (first + i) * stride;

		jpeg_read_scanlines(&cinfo, rows, ARRAY_LENGTH(rows));
		for (i = 0; first + i < cinfo.output_scanline; i++)
			swizzle_row(rows[i], cinfo.output_width);
	}

	jpeg_finish_decompress(&cinfo);

	jpeg_destroy_decompress(&cinfo);

	pixman_image = pixman_image_create_bits(PIXMAN_a8r8g8b8,
					cinfo.output_width,
					cinfo.output_height,
					(uint32_t *) data, stride);

	pixman_image_set_destroy_function(pixman_image,
				pixman_image_destroy_func, data);

	return pixman_image;
}
Beispiel #17
0
pixman_image_t *qemu_pixman_mirror_create(pixman_format_code_t format,
                                          pixman_image_t *image)
{
    return pixman_image_create_bits(format,
                                    pixman_image_get_width(image),
                                    pixman_image_get_height(image),
                                    NULL,
                                    pixman_image_get_stride(image));
}
int
main (int argc, char **argv)
{
#define WIDTH 400
#define HEIGHT 200
    int y, x, p;
    float alpha;
 
    uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
    uint32_t *src1 = malloc (WIDTH * HEIGHT * 4);
    pixman_image_t *dest_img, *src1_img;
   
    dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8_sRGB,
					 WIDTH, HEIGHT,
					 dest,
					 WIDTH * 4);
    src1_img = pixman_image_create_bits (PIXMAN_a8r8g8b8,
					 WIDTH, HEIGHT,
					 src1,
					 WIDTH * 4);

    for (y = 0; y < HEIGHT; y ++)
    {
	p = WIDTH * y;
	for (x = 0; x < WIDTH; x ++)
	{
	     alpha = (float) x / WIDTH;
	     src1[p + x] = linear_argb_to_premult_argb (alpha, 1, 0, 1);
	     dest[p + x] = linear_argb_to_premult_srgb_argb (1-alpha, 0, 1, 0);
	}
    }
    
    pixman_image_composite (PIXMAN_OP_ADD, src1_img, NULL, dest_img,
			    0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
    pixman_image_unref (src1_img);
    free (src1);

    show_image (dest_img);
    pixman_image_unref (dest_img);
    free (dest);
    
    return 0;
}
int
main ()
{
    static const pixman_point_fixed_t inner = { 0x0000, 0x0000 };
    static const pixman_point_fixed_t outer = { 0x0000, 0x0000 };
    static const pixman_fixed_t r_inner = 0;
    static const pixman_fixed_t r_outer = 64 << 16;
    static const pixman_gradient_stop_t stops[] = {
	{ 0x00000, { 0x6666, 0x6666, 0x6666, 0xffff } },
	{ 0x10000, { 0x0000, 0x0000, 0x0000, 0xffff } }
    };
    static const pixman_transform_t transform = {
	{ { 0x0,        0x26ee, 0x0}, 
	  { 0xffffeeef, 0x0,    0x0}, 
	  { 0x0,        0x0,    0x10000}
	}
    };
    static const pixman_color_t z = { 0x0000, 0x0000, 0x0000, 0x0000 };
    pixman_image_t *dest, *radial, *zero;
    int i;
    double before, after;

    dest = pixman_image_create_bits (
	PIXMAN_x8r8g8b8, 640, 429, NULL, -1);
    zero = pixman_image_create_solid_fill (&z);
    radial = pixman_image_create_radial_gradient (
	&inner, &outer, r_inner, r_outer, stops, ARRAY_LENGTH (stops));
    pixman_image_set_transform (radial, &transform);
    pixman_image_set_repeat (radial, PIXMAN_REPEAT_PAD);

#define N_COMPOSITE	500

    before = gettime();
    for (i = 0; i < N_COMPOSITE; ++i)
    {
	before -= gettime();

	pixman_image_composite (
	    PIXMAN_OP_SRC, zero, NULL, dest,
	    0, 0, 0, 0, 0, 0, 640, 429);

	before += gettime();

	pixman_image_composite32 (
	    PIXMAN_OP_OVER, radial, NULL, dest,
	    - 150, -158, 0, 0, 0, 0, 640, 361);
    }

    after = gettime();

    write_png (dest, "radial.png");

    printf ("Average time to composite: %f\n", (after - before) / N_COMPOSITE);
    return 0;
}
int
main (int argc, char **argv)
{
#define WIDTH 200
#define HEIGHT 200

#define d2f pixman_double_to_fixed
    
    uint32_t *src = malloc (WIDTH * HEIGHT * 4);
    uint32_t *mask = malloc (WIDTH * HEIGHT * 4);
    uint32_t *dest = malloc (WIDTH * HEIGHT * 4);
    pixman_fixed_t convolution[] =
    {
	d2f (3), d2f (3),
	d2f (0.5), d2f (0.5), d2f (0.5),
	d2f (0.5), d2f (0.5), d2f (0.5),
	d2f (0.5), d2f (0.5), d2f (0.5),
    };
    pixman_image_t *simg, *mimg, *dimg;

    int i;

    for (i = 0; i < WIDTH * HEIGHT; ++i)
    {
	src[i] = 0x7f007f00;
	mask[i] = (i % 256) * 0x01000000;
	dest[i] = 0;
    }

    simg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src, WIDTH * 4);
    mimg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, mask, WIDTH * 4);
    dimg = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4);

    pixman_image_set_filter (mimg, PIXMAN_FILTER_CONVOLUTION,
			     convolution, 11);

    pixman_image_composite (PIXMAN_OP_OVER, simg, mimg, dimg, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);

    show_image (dimg);
    
    return 0;
}
Beispiel #21
0
static pixman_image_t *
make_image (const image_info_t *info)
{
    char *data = malloc (info->stride * info->height);
    int i;

    for (i = 0; i < info->height * info->stride; ++i)
	data[i] = (i % 255) ^ (((i % 16) << 4) | (i & 0xf0));

    return pixman_image_create_bits (info->format, info->width, info->height, (uint32_t *)data, info->stride);
}
Beispiel #22
0
/* Create random image for testing purposes */
static pixman_image_t *
create_random_image (pixman_format_code_t *allowed_formats,
		     int                   max_width,
		     int                   max_height,
		     int                   max_extra_stride,
		     pixman_format_code_t *used_fmt)
{
    int n = 0, i, width, height, stride;
    pixman_format_code_t fmt;
    uint32_t *buf;
    pixman_image_t *img;

    while (allowed_formats[n] != PIXMAN_null)
	n++;

    if (n > N_MOST_LIKELY_FORMATS && lcg_rand_n (4) != 0)
	n = N_MOST_LIKELY_FORMATS;
    fmt = allowed_formats[lcg_rand_n (n)];

    width = lcg_rand_n (max_width) + 1;
    height = lcg_rand_n (max_height) + 1;
    stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 +
	lcg_rand_n (max_extra_stride + 1);
    stride = (stride + 3) & ~3;

    /* do the allocation */
    buf = aligned_malloc (64, stride * height);

    /* initialize image with random data */
    for (i = 0; i < stride * height; i++)
    {
	/* generation is biased to having more 0 or 255 bytes as
	 * they are more likely to be special-cased in code
	 */
	*((uint8_t *)buf + i) = lcg_rand_n (4) ? lcg_rand_n (256) :
	    (lcg_rand_n (2) ? 0 : 255);
    }

    img = pixman_image_create_bits (fmt, width, height, buf, stride);

    if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
    {
	pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
    }
    else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
    {
	pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
    }

    image_endian_swap (img);

    if (used_fmt) *used_fmt = fmt;
    return img;
}
Beispiel #23
0
cairo_image_surface_t *
_cairo_image_surface_create_from_image (cairo_image_surface_t *other,
					pixman_format_code_t format,
					int x, int y,
					int width, int height, int stride)
{
    cairo_image_surface_t *surface;
    cairo_status_t status;
    pixman_image_t *image;
    void *mem = NULL;

    status = other->base.status;
    if (unlikely (status))
	goto cleanup;

    if (stride) {
	mem = _cairo_malloc_ab (height, stride);
	if (unlikely (mem == NULL)) {
	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
	    goto cleanup;
	}
    }

    image = pixman_image_create_bits (format, width, height, mem, stride);
    if (unlikely (image == NULL)) {
	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
	goto cleanup_mem;
    }

    surface = (cairo_image_surface_t *)
	_cairo_image_surface_create_for_pixman_image (image, format);
    if (unlikely (surface->base.status)) {
	status = surface->base.status;
	goto cleanup_image;
    }

    pixman_image_composite32 (PIXMAN_OP_SRC,
                              other->pixman_image, NULL, image,
                              x, y,
                              0, 0,
                              0, 0,
                              width, height);
    surface->base.is_clear = FALSE;
    surface->owns_data = mem != NULL;

    return surface;

cleanup_image:
    pixman_image_unref (image);
cleanup_mem:
    free (mem);
cleanup:
    return (cairo_image_surface_t *) _cairo_surface_create_in_error (status);
}
Beispiel #24
0
/* This test demonstrates that clipping is done totally different depending
 * on whether the source is transformed or not.
 */
int
main (int argc, char **argv)
{
#define WIDTH 200
#define HEIGHT 200

#define SMALL 25
    
    uint32_t *sbits = malloc (SMALL * SMALL * 4);
    uint32_t *bits = malloc (WIDTH * HEIGHT * 4);
    pixman_transform_t trans = {
    {
	{ pixman_double_to_fixed (1.0), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.1), },
	{ pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.1), },
	{ pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) }
    } };
	  
    pixman_image_t *src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, SMALL, SMALL, sbits, 4 * SMALL);
    pixman_image_t *dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, bits, 4 * WIDTH);

    memset (bits, 0xff, WIDTH * HEIGHT * 4);
    memset (sbits, 0x00, SMALL * SMALL * 4);

    pixman_image_composite (PIXMAN_OP_IN,
			    src_img, NULL, dest_img,
			    0, 0, 0, 0, SMALL, SMALL, 200, 200);
    
    pixman_image_set_transform (src_img, &trans);
    
    pixman_image_composite (PIXMAN_OP_IN,
			    src_img, NULL, dest_img,
			    0, 0, 0, 0, SMALL * 2, SMALL * 2, 200, 200);
    
    show_image (dest_img);
    
    pixman_image_unref (src_img);
    pixman_image_unref (dest_img);
    free (bits);
    
    return 0;
}
Beispiel #25
0
static void *
_glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
                            int stride, int revert)
{
    PictFormatShort dst_format, src_format;
    pixman_image_t *dst_image;
    pixman_image_t *src_image;
    int src_stride;

    if (revert == REVERT_UPLOADING_A1) {
        src_format = PICT_a1;
        dst_format = PICT_a8;
        src_stride = PixmapBytePad(w, 1);
    }
    else {
        dst_format = PICT_a1;
        src_format = PICT_a8;
        src_stride = (((w * 8 + 7) / 8) + 3) & ~3;
    }

    dst_image = pixman_image_create_bits(dst_format, w, h, dst_bits, stride);
    if (dst_image == NULL) {
        return NULL;
    }

    src_image = pixman_image_create_bits(src_format,
                                         w, h, src_bits, src_stride);

    if (src_image == NULL) {
        pixman_image_unref(dst_image);
        return NULL;
    }

    pixman_image_composite(PictOpSrc, src_image, NULL, dst_image,
                           0, 0, 0, 0, 0, 0, w, h);

    pixman_image_unref(src_image);
    pixman_image_unref(dst_image);
    return dst_bits;
}
Beispiel #26
0
int
main (int argc, char **argv)
{
#define WIDTH 40
#define HEIGHT 40
    
    uint32_t *src1 = malloc (WIDTH * HEIGHT * 4);
    uint32_t *src2 = malloc (WIDTH * HEIGHT * 4);
    uint32_t *src3 = malloc (WIDTH * HEIGHT * 4);
    uint32_t *dest = malloc (3 * WIDTH * 2 * HEIGHT * 4);
    pixman_image_t *simg1, *simg2, *simg3, *dimg;

    int i;

    for (i = 0; i < WIDTH * HEIGHT; ++i)
    {
	src1[i] = 0x7ff00000;
	src2[i] = 0x7f00ff00;
	src3[i] = 0x7f0000ff;
    }

    for (i = 0; i < 3 * WIDTH * 2 * HEIGHT; ++i)
    {
	dest[i] = 0x0;
    }

    simg1 = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src1, WIDTH * 4);
    simg2 = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src2, WIDTH * 4);
    simg3 = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src3, WIDTH * 4);
    dimg  = pixman_image_create_bits (PIXMAN_a8r8g8b8, 3 * WIDTH, 2 * HEIGHT, dest, 3 * WIDTH * 4);

    pixman_image_composite (PIXMAN_OP_SCREEN, simg1, NULL, dimg, 0, 0, 0, 0, WIDTH, HEIGHT / 4, WIDTH, HEIGHT);
    pixman_image_composite (PIXMAN_OP_SCREEN, simg2, NULL, dimg, 0, 0, 0, 0, (WIDTH/2), HEIGHT / 4 + HEIGHT / 2, WIDTH, HEIGHT);
    pixman_image_composite (PIXMAN_OP_SCREEN, simg3, NULL, dimg, 0, 0, 0, 0, (4 * WIDTH) / 3, HEIGHT, WIDTH, HEIGHT);

    show_image (dimg);
    
    return 0;
}
Beispiel #27
0
int
main (int argc, char **argv)
{
    uint8_t *alpha = make_random_bytes (WIDTH * HEIGHT);
    uint32_t *src = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);
    uint32_t *dest = (uint32_t *)make_random_bytes (WIDTH * HEIGHT * 4);

    pixman_image_t *a = pixman_image_create_bits (PIXMAN_a8, WIDTH, HEIGHT, (uint32_t *)alpha, WIDTH);
    pixman_image_t *d = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4);
    pixman_image_t *s = pixman_image_create_bits (PIXMAN_a2r10g10b10, WIDTH, HEIGHT, src, WIDTH * 4);

    fail_after (5, "Infinite loop detected: 5 seconds without progress\n");

    pixman_image_set_alpha_map (s, a, 0, 0);
    pixman_image_set_alpha_map (a, s, 0, 0);

    pixman_image_composite (PIXMAN_OP_SRC, s, NULL, d, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);

    pixman_image_unref (s);

    return 0;
}
Beispiel #28
0
static cairo_gl_surface_t *
tristrip_to_surface (void *_dst,
		  const cairo_rectangle_int_t *extents,
		  cairo_antialias_t	antialias,
		  cairo_tristrip_t	*strip)
{
    pixman_format_code_t pixman_format;
    pixman_image_t *pixman_image;
    cairo_surface_t *image, *mask;
    cairo_status_t status;

    pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1,
    pixman_image = pixman_image_create_bits (pixman_format,
					     extents->width,
					     extents->height,
					     NULL, 0);
    if (unlikely (pixman_image == NULL))
	return (cairo_gl_surface_t *)_cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));

    _pixman_image_add_tristrip (pixman_image, extents->x, extents->y, strip);
    image = _cairo_image_surface_create_for_pixman_image (pixman_image,
							  pixman_format);
    if (unlikely (image->status)) {
	pixman_image_unref (pixman_image);
	return (cairo_gl_surface_t *)image;
    }

    mask = _cairo_surface_create_scratch (_dst,
					  CAIRO_CONTENT_COLOR_ALPHA,
					  extents->width,
					  extents->height,
					  NULL);
    if (unlikely (mask->status)) {
	cairo_surface_destroy (image);
	return (cairo_gl_surface_t *)mask;
    }

    status = _cairo_gl_surface_draw_image ((cairo_gl_surface_t *)mask,
					   (cairo_image_surface_t *)image,
					   0, 0,
					   extents->width, extents->height,
					   0, 0,
					   TRUE);
    cairo_surface_destroy (image);
    if (unlikely (status)) {
	cairo_surface_destroy (mask);
	return (cairo_gl_surface_t*)_cairo_surface_create_in_error (status);
    }

    return (cairo_gl_surface_t*)mask;
}
static void
pixman_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
{
	struct pixman_surface_state *ps = get_surface_state(es);
	struct wl_shm_buffer *shm_buffer;
	pixman_format_code_t pixman_format;

	weston_buffer_reference(&ps->buffer_ref, buffer);

	if (ps->image) {
		pixman_image_unref(ps->image);
		ps->image = NULL;
	}

	if (!buffer)
		return;
	
	shm_buffer = wl_shm_buffer_get(buffer->resource);

	if (! shm_buffer) {
		weston_log("Pixman renderer supports only SHM buffers\n");
		weston_buffer_reference(&ps->buffer_ref, NULL);
		return;
	}

	switch (wl_shm_buffer_get_format(shm_buffer)) {
	case WL_SHM_FORMAT_XRGB8888:
		pixman_format = PIXMAN_x8r8g8b8;
		break;
	case WL_SHM_FORMAT_ARGB8888:
		pixman_format = PIXMAN_a8r8g8b8;
		break;
	case WL_SHM_FORMAT_RGB565:
		pixman_format = PIXMAN_r5g6b5;
		break;
	default:
		weston_log("Unsupported SHM buffer format\n");
		weston_buffer_reference(&ps->buffer_ref, NULL);
		return;
	break;
	}

	buffer->shm_buffer = shm_buffer;
	buffer->width = wl_shm_buffer_get_width(shm_buffer);
	buffer->height = wl_shm_buffer_get_height(shm_buffer);

	ps->image = pixman_image_create_bits(pixman_format,
		buffer->width, buffer->height,
		wl_shm_buffer_get_data(shm_buffer),
		wl_shm_buffer_get_stride(shm_buffer));
}
/* Creates a cairo-gl pattern surface for the given trapezoids */
static cairo_status_t
_cairo_gl_get_traps_pattern (cairo_gl_surface_t *dst,
			     int dst_x, int dst_y,
			     int width, int height,
			     cairo_trapezoid_t *traps,
			     int num_traps,
			     cairo_antialias_t antialias,
			     cairo_surface_pattern_t *pattern)
{
    pixman_format_code_t pixman_format;
    pixman_image_t *image;
    cairo_surface_t *surface;
    int i;

    pixman_format = antialias != CAIRO_ANTIALIAS_NONE ? PIXMAN_a8 : PIXMAN_a1,
    image = pixman_image_create_bits (pixman_format, width, height, NULL, 0);
    if (unlikely (image == NULL))
	return _cairo_error (CAIRO_STATUS_NO_MEMORY);

    for (i = 0; i < num_traps; i++) {
	pixman_trapezoid_t trap;

	trap.top = _cairo_fixed_to_16_16 (traps[i].top);
	trap.bottom = _cairo_fixed_to_16_16 (traps[i].bottom);

	trap.left.p1.x = _cairo_fixed_to_16_16 (traps[i].left.p1.x);
	trap.left.p1.y = _cairo_fixed_to_16_16 (traps[i].left.p1.y);
	trap.left.p2.x = _cairo_fixed_to_16_16 (traps[i].left.p2.x);
	trap.left.p2.y = _cairo_fixed_to_16_16 (traps[i].left.p2.y);

	trap.right.p1.x = _cairo_fixed_to_16_16 (traps[i].right.p1.x);
	trap.right.p1.y = _cairo_fixed_to_16_16 (traps[i].right.p1.y);
	trap.right.p2.x = _cairo_fixed_to_16_16 (traps[i].right.p2.x);
	trap.right.p2.y = _cairo_fixed_to_16_16 (traps[i].right.p2.y);

	pixman_rasterize_trapezoid (image, &trap, -dst_x, -dst_y);
    }

    surface = _cairo_image_surface_create_for_pixman_image (image,
							    pixman_format);
    if (unlikely (surface->status)) {
	pixman_image_unref (image);
	return surface->status;
    }

    _cairo_pattern_init_for_surface (pattern, surface);
    cairo_surface_destroy (surface);

    return CAIRO_STATUS_SUCCESS;
}