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; }
void _blur_image_surface (cairo_surface_t* surface, gint radius, gdouble sigma /* pass 0.0f for auto-calculation */) { pixman_fixed_t* params = NULL; gint n_params; pixman_image_t* src; gint w; gint h; gint s; gpointer p; gdouble radiusf; radiusf = fabs (radius) + 1.0f; if (sigma == 0.0f) sigma = sqrt (-(radiusf * radiusf) / (2.0f * log (1.0f / 255.0f))); w = cairo_image_surface_get_width (surface); h = cairo_image_surface_get_height (surface); s = cairo_image_surface_get_stride (surface); // create pixman image for cairo image surface p = cairo_image_surface_get_data (surface); src = pixman_image_create_bits (PIXMAN_a8r8g8b8, w, h, p, s); // attach gaussian kernel to pixman image params = create_gaussian_blur_kernel (radius, sigma, &n_params); pixman_image_set_filter (src, PIXMAN_FILTER_CONVOLUTION, params, n_params); g_free (params); // render blured image to new pixman image pixman_image_composite (PIXMAN_OP_SRC, src, NULL, src, 0, 0, 0, 0, 0, 0, w, h); pixman_image_unref (src); }
static void pixman_image_composite_wrapper (pixman_implementation_t *impl, pixman_composite_info_t *info) { if (use_scaling) { pixman_image_set_filter (info->src_image, filter, NULL, 0); pixman_image_set_transform(info->src_image, &m); } pixman_image_composite (info->op, info->src_image, info->mask_image, info->dest_image, info->src_x, info->src_y, info->mask_x, info->mask_y, info->dest_x, info->dest_y, info->width, info->height); }
static void apply(JoyFilter *self, JoyBubble *widget, cairo_t *cr) { struct Private *priv = GET_PRIVATE(self); if (G_UNLIKELY(!priv->kernel || !priv->n)) { return; } gint width = joy_bubble_get_width(widget); gint height = joy_bubble_get_height(widget); cairo_surface_t *surface = cairo_get_target(cr); cairo_surface_type_t type = cairo_surface_get_type(surface); if (CAIRO_SURFACE_TYPE_IMAGE != type) { cairo_surface_t *image_surface = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, width, height); cairo_t *image_cr = cairo_create(surface); cairo_set_source_surface(image_cr, surface, 0., 0.); cairo_paint(image_cr); cairo_destroy(image_cr); cairo_surface_flush(image_surface); surface = image_surface; } gint stride = cairo_image_surface_get_stride(surface); gpointer pixels = cairo_image_surface_get_data(surface); pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height, pixels, stride); if (!image) { goto error; } if (!pixman_image_set_filter(image, PIXMAN_FILTER_CONVOLUTION, priv->kernel, priv->n)) { goto error; } pixman_image_composite(PIXMAN_OP_SRC, image, NULL, image, 0, 0, 0, 0, 0, 0, width, height); pixman_image_unref(image); if (CAIRO_SURFACE_TYPE_IMAGE != type) { cairo_set_source_surface(cr, surface, 0., 0.); cairo_paint(cr); cairo_surface_destroy(surface); } return; error: if (CAIRO_SURFACE_TYPE_IMAGE != type) { cairo_surface_destroy(surface); } }
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 (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; }
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; }
void fbComposite (CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst, INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height) { pixman_image_t *src, *mask, *dest; int src_xoff, src_yoff; int msk_xoff, msk_yoff; int dst_xoff, dst_yoff; miCompositeSourceValidate (pSrc, xSrc - xDst, ySrc - yDst, width, height); if (pMask) miCompositeSourceValidate (pMask, xMask - xDst, yMask - yDst, width, height); src = image_from_pict_18 (pSrc, FALSE, &src_xoff, &src_yoff); mask = image_from_pict_18 (pMask, FALSE, &msk_xoff, &msk_yoff); dest = image_from_pict_18 (pDst, TRUE, &dst_xoff, &dst_yoff); if (src && dest && !(pMask && !mask)) { pixman_image_composite (op, src, mask, dest, xSrc + src_xoff, ySrc + src_yoff, xMask + msk_xoff, yMask + msk_yoff, xDst + dst_xoff, yDst + dst_yoff, width, height); } free_pixman_pict (pSrc, src); free_pixman_pict (pMask, mask); free_pixman_pict (pDst, dest); }
static gboolean on_expose (GtkWidget *da, GdkEvent *event, gpointer data) { app_t *app = data; GdkRectangle *area = &event->expose.area; cairo_surface_t *surface; pixman_image_t *tmp; cairo_t *cr; uint32_t *pixels; pixels = calloc (1, area->width * area->height * 4); tmp = pixman_image_create_bits ( PIXMAN_a8r8g8b8, area->width, area->height, pixels, area->width * 4); if (area->x < app->scaled_width && area->y < app->scaled_height) { pixman_image_composite ( PIXMAN_OP_SRC, app->original, NULL, tmp, area->x, area->y, 0, 0, 0, 0, app->scaled_width - area->x, app->scaled_height - area->y); } surface = cairo_image_surface_create_for_data ( (uint8_t *)pixels, CAIRO_FORMAT_ARGB32, area->width, area->height, area->width * 4); cr = gdk_cairo_create (da->window); cairo_set_source_surface (cr, surface, area->x, area->y); cairo_paint (cr); cairo_destroy (cr); cairo_surface_destroy (surface); free (pixels); pixman_image_unref (tmp); return TRUE; }
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; }
static uint32_t test_transform (int testnum, int verbose) { pixman_image_t *src, *dest; uint32_t crc; prng_srand (testnum); src = make_image (); dest = make_image (); pixman_image_composite (RANDOM_OP(), src, NULL, dest, 0, 0, 0, 0, WIDTH / 2, HEIGHT / 2, WIDTH, HEIGHT); crc = compute_crc32_for_image (0, dest); pixman_image_unref (src); pixman_image_unref (dest); return crc; }
static void rectangle_draw_internal(RGBA_Image *dst, RGBA_Draw_Context *dc, int x, int y, int w, int h) { RGBA_Gfx_Func func; int yy; DATA32 *ptr; RECTS_CLIP_TO_RECT(x, y, w, h, dc->clip.x, dc->clip.y, dc->clip.w, dc->clip.h); if ((w <= 0) || (h <= 0)) return; #ifdef HAVE_PIXMAN # ifdef PIXMAN_RECT pixman_op_t op = PIXMAN_OP_SRC; // _EVAS_RENDER_COPY if (dc->render_op == _EVAS_RENDER_BLEND) op = PIXMAN_OP_OVER; if ((dst->pixman.im) && (dc->col.pixman_color_image)) { pixman_image_composite(op, dc->col.pixman_color_image, NULL, dst->pixman.im, x, y, 0, 0, x, y, w, h); } else # endif #endif { func = evas_common_gfx_func_composite_color_span_get(dc->col.col, dst, w, dc->render_op); ptr = dst->image.data + (y * dst->cache_entry.w) + x; for (yy = 0; yy < h; yy++) { func(NULL, NULL, dc->col.col, ptr, w); ptr += dst->cache_entry.w; } } }
static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd, QXLRect *rect) { SimpleSpiceUpdate *update; QXLDrawable *drawable; QXLImage *image; QXLCommand *cmd; int bw, bh; struct timespec time_space; pixman_image_t *dest; trace_qemu_spice_create_update( rect->left, rect->right, rect->top, rect->bottom); update = g_malloc0(sizeof(*update)); drawable = &update->drawable; image = &update->image; cmd = &update->ext.cmd; bw = rect->right - rect->left; bh = rect->bottom - rect->top; update->bitmap = g_malloc(bw * bh * 4); drawable->bbox = *rect; drawable->clip.type = SPICE_CLIP_TYPE_NONE; drawable->effect = QXL_EFFECT_OPAQUE; drawable->release_info.id = (uintptr_t)(&update->ext); drawable->type = QXL_DRAW_COPY; drawable->surfaces_dest[0] = -1; drawable->surfaces_dest[1] = -1; drawable->surfaces_dest[2] = -1; clock_gettime(CLOCK_MONOTONIC, &time_space); /* time in milliseconds from epoch. */ drawable->mm_time = time_space.tv_sec * 1000 + time_space.tv_nsec / 1000 / 1000; drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT; drawable->u.copy.src_bitmap = (uintptr_t)image; drawable->u.copy.src_area.right = bw; drawable->u.copy.src_area.bottom = bh; QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, ssd->unique++); image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP; image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN; image->bitmap.stride = bw * 4; image->descriptor.width = image->bitmap.x = bw; image->descriptor.height = image->bitmap.y = bh; image->bitmap.data = (uintptr_t)(update->bitmap); image->bitmap.palette = 0; image->bitmap.format = SPICE_BITMAP_FMT_32BIT; dest = pixman_image_create_bits(PIXMAN_LE_x8r8g8b8, bw, bh, (void *)update->bitmap, bw * 4); pixman_image_composite(PIXMAN_OP_SRC, ssd->surface, NULL, ssd->mirror, rect->left, rect->top, 0, 0, rect->left, rect->top, bw, bh); pixman_image_composite(PIXMAN_OP_SRC, ssd->mirror, NULL, dest, rect->left, rect->top, 0, 0, 0, 0, bw, bh); pixman_image_unref(dest); cmd->type = QXL_CMD_DRAW; cmd->data = (uintptr_t)drawable; QTAILQ_INSERT_TAIL(&ssd->updates, update, next); }
int main (int argc, char **argv) { #define d2f pixman_double_to_fixed GtkWidget *window, *swindow; GtkWidget *table; uint32_t *dest = malloc (WIDTH * HEIGHT * 4); uint32_t *src = malloc (WIDTH * HEIGHT * 4); pixman_image_t *src_img; pixman_image_t *dest_img; pixman_point_fixed_t p1 = { -10 << 0, 0 }; pixman_point_fixed_t p2 = { WIDTH << 16, (HEIGHT - 10) << 16 }; uint16_t full = 0xcfff; uint16_t low = 0x5000; uint16_t alpha = 0xffff; pixman_gradient_stop_t stops[6] = { { d2f (0.0), { full, low, low, alpha } }, { d2f (0.25), { full, full, low, alpha } }, { d2f (0.4), { low, full, low, alpha } }, { d2f (0.6), { low, full, full, alpha } }, { d2f (0.8), { low, low, full, alpha } }, { d2f (1.0), { full, low, full, alpha } }, }; int i; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); table = gtk_table_new (G_N_ELEMENTS (operators) / 6, 6, TRUE); src_img = pixman_image_create_linear_gradient (&p1, &p2, stops, G_N_ELEMENTS (stops)); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_PAD); dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); pixman_image_set_accessors (dest_img, reader, writer); for (i = 0; i < G_N_ELEMENTS (operators); ++i) { GtkWidget *image; GdkPixbuf *pixbuf; GtkWidget *vbox; GtkWidget *label; int j, k; vbox = gtk_vbox_new (FALSE, 0); label = gtk_label_new (operators[i].name); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 6); gtk_widget_show (label); for (j = 0; j < HEIGHT; ++j) { for (k = 0; k < WIDTH; ++k) dest[j * WIDTH + k] = 0x7f6f6f00; } pixman_image_composite (operators[i].op, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); pixbuf = pixbuf_from_argb32 (pixman_image_get_data (dest_img), TRUE, WIDTH, HEIGHT, WIDTH * 4); image = gtk_image_new_from_pixbuf (pixbuf); gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0); gtk_widget_show (image); gtk_table_attach_defaults (GTK_TABLE (table), vbox, i % 6, (i % 6) + 1, i / 6, (i / 6) + 1); gtk_widget_show (vbox); g_object_unref (pixbuf); } pixman_image_unref (src_img); free (src); pixman_image_unref (dest_img); free (dest); swindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swindow), table); gtk_widget_show (table); gtk_container_add (GTK_CONTAINER (window), swindow); gtk_widget_show (swindow); gtk_widget_show (window); gtk_main (); return 0; }
int main (int argc, char **argv) { pixman_image_t *gradient_img; pixman_image_t *src_img, *dst_img; pixman_gradient_stop_t stops[2] = { { pixman_int_to_fixed (0), { 0xffff, 0x0000, 0x0000, 0xffff } }, { pixman_int_to_fixed (1), { 0xffff, 0xffff, 0x0000, 0xffff } } }; pixman_point_fixed_t p1 = { 0, 0 }; pixman_point_fixed_t p2 = { pixman_int_to_fixed (WIDTH), pixman_int_to_fixed (HEIGHT) }; pixman_point_fixed_t c_inner; pixman_point_fixed_t c_outer; pixman_fixed_t r_inner; pixman_fixed_t r_outer; pixman_region32_t clip_region; pixman_transform_t trans = { { { pixman_double_to_fixed (1.3), pixman_double_to_fixed (0), pixman_double_to_fixed (-0.5), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (-0.5), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (1.0) } } }; src_img = create_solid_bits (0xff0000ff); c_inner.x = pixman_double_to_fixed (100.0); c_inner.y = pixman_double_to_fixed (100.0); c_outer.x = pixman_double_to_fixed (100.0); c_outer.y = pixman_double_to_fixed (100.0); r_inner = 0; r_outer = pixman_double_to_fixed (100.0); gradient_img = pixman_image_create_radial_gradient (&c_inner, &c_outer, r_inner, r_outer, stops, 2); #if 0 gradient_img = pixman_image_create_linear_gradient (&p1, &p2, stops, 2); #endif pixman_image_composite (PIXMAN_OP_OVER, gradient_img, NULL, src_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); pixman_region32_init_rect (&clip_region, 50, 0, 100, 200); pixman_image_set_clip_region32 (src_img, &clip_region); pixman_image_set_source_clipping (src_img, TRUE); pixman_image_set_has_client_clip (src_img, TRUE); pixman_image_set_transform (src_img, &trans); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); dst_img = create_solid_bits (0xffff0000); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dst_img, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); #if 0 printf ("0, 0: %x\n", src[0]); printf ("10, 10: %x\n", src[10 * 10 + 10]); printf ("w, h: %x\n", src[(HEIGHT - 1) * 100 + (WIDTH - 1)]); #endif show_image (dst_img); pixman_image_unref (gradient_img); pixman_image_unref (src_img); return 0; }
int freerds_send_bitmap_update(rdsConnection* connection, int bpp, RDS_MSG_PAINT_RECT* msg) { BYTE* data; BYTE* tile; BYTE* buffer; int i, j, k; wStream* s; wStream* ts; int e, lines; int scanline; int rows, cols; int MaxRegionWidth; int MaxRegionHeight; INT32 nWidth, nHeight; pixman_image_t* image; pixman_image_t* fbImage; BITMAP_DATA* bitmapData; BITMAP_UPDATE bitmapUpdate; rdpUpdate* update = connection->client->update; //printf("%s\n", __FUNCTION__); MaxRegionWidth = 64 * 4; MaxRegionHeight = 64 * 1; if ((msg->nLeftRect % 4) != 0) { msg->nWidth += (msg->nLeftRect % 4); msg->nLeftRect -= (msg->nLeftRect % 4); } if ((msg->nTopRect % 4) != 0) { msg->nHeight += (msg->nTopRect % 4); msg->nTopRect -= (msg->nTopRect % 4); } if ((msg->nWidth * msg->nHeight) > (MaxRegionWidth * MaxRegionHeight)) { RDS_MSG_PAINT_RECT subMsg; rows = (msg->nWidth + (MaxRegionWidth - (msg->nWidth % MaxRegionWidth))) / MaxRegionWidth; cols = (msg->nHeight + (MaxRegionHeight - (msg->nHeight % MaxRegionHeight))) / MaxRegionHeight; //printf("Partitioning x: %d y: %d width: %d height: %d in %d partitions (%d rows, %d cols)\n", // msg->nLeftRect, msg->nTopRect, msg->nWidth, msg->nHeight, rows * cols, rows, cols); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { CopyMemory(&subMsg, msg, sizeof(RDS_MSG_PAINT_RECT)); subMsg.nLeftRect = msg->nLeftRect + (i * MaxRegionWidth); subMsg.nTopRect = msg->nTopRect + (j * MaxRegionHeight); subMsg.nWidth = (i < (rows - 1)) ? MaxRegionWidth : msg->nWidth - (i * MaxRegionWidth); subMsg.nHeight = (j < (cols - 1)) ? MaxRegionHeight : msg->nHeight - (j * MaxRegionHeight); //printf("\t[%d, %d]: x: %d y: %d width: %d height: %d\n", // i, j, subMsg.nLeftRect, subMsg.nTopRect, subMsg.nWidth, subMsg.nHeight); if ((subMsg.nWidth * subMsg.nHeight) > 0) freerds_send_bitmap_update(connection, bpp, &subMsg); } } return 0; } tile = (BYTE*) malloc(64 * 64 * 4); fbImage = (pixman_image_t*) msg->framebuffer->image; rows = (msg->nWidth + (64 - (msg->nWidth % 64))) / 64; cols = (msg->nHeight + (64 - (msg->nHeight % 64))) / 64; k = 0; bitmapUpdate.count = bitmapUpdate.number = rows * cols; bitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * bitmapUpdate.number); bitmapUpdate.rectangles = bitmapData; if ((msg->nWidth % 4) != 0) { msg->nLeftRect -= (msg->nWidth % 4); msg->nWidth += (msg->nWidth % 4); } if ((msg->nHeight % 4) != 0) { msg->nTopRect -= (msg->nHeight % 4); msg->nHeight += (msg->nHeight % 4); } for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { nWidth = (i < (rows - 1)) ? 64 : msg->nWidth - (i * 64); nHeight = (j < (cols - 1)) ? 64 : msg->nHeight - (j * 64); bitmapData[k].bitsPerPixel = 16; bitmapData[k].width = nWidth; bitmapData[k].height = nHeight; bitmapData[k].destLeft = msg->nLeftRect + (i * 64); bitmapData[k].destTop = msg->nTopRect + (j * 64); bitmapData[k].destRight = bitmapData[k].destLeft + nWidth - 1; bitmapData[k].destBottom = bitmapData[k].destTop + nHeight - 1; bitmapData[k].compressed = TRUE; if (((nWidth * nHeight) > 0) && (nWidth >= 4) && (nHeight >= 4)) { e = nWidth % 4; if (e != 0) e = 4 - e; //printf("k: %d destLeft: %d destTop: %d destRight: %d destBottom: %d nWidth: %d nHeight: %d\n", // k, bitmapData[k].destLeft, bitmapData[k].destTop, // bitmapData[k].destRight, bitmapData[k].destBottom, nWidth, nHeight); s = connection->encoder->bs; ts = connection->encoder->bts; Stream_SetPosition(s, 0); Stream_SetPosition(ts, 0); data = msg->framebuffer->fbSharedMemory; data = &data[(bitmapData[k].destTop * msg->framebuffer->fbScanline) + (bitmapData[k].destLeft * msg->framebuffer->fbBytesPerPixel)]; scanline = msg->framebuffer->fbScanline; if (bpp > 16) { int dstSize; UINT32 format; format = FREERDP_PIXEL_FORMAT(msg->framebuffer->fbBitsPerPixel, FREERDP_PIXEL_FORMAT_TYPE_ARGB, FREERDP_PIXEL_FLIP_NONE); buffer = connection->encoder->grid[k]; buffer = freerdp_bitmap_compress_planar(connection->encoder->planar_context, data, format, nWidth, nHeight, scanline, buffer, &dstSize); bitmapData[k].bitmapDataStream = buffer; bitmapData[k].bitmapLength = dstSize; bitmapData[k].bitsPerPixel = 32; bitmapData[k].cbScanWidth = nWidth * 4; bitmapData[k].cbUncompressedSize = nWidth * nHeight * 4; } else { image = pixman_image_create_bits(PIXMAN_r5g6b5, nWidth, nHeight, (uint32_t*) tile, nWidth * 2); pixman_image_composite(PIXMAN_OP_OVER, fbImage, NULL, image, bitmapData[k].destLeft, bitmapData[k].destTop, 0, 0, 0, 0, nWidth, nHeight); lines = freerdp_bitmap_compress((char*) pixman_image_get_data(image), nWidth, nHeight, s, 16, 16384, nHeight - 1, ts, e); Stream_SealLength(s); bitmapData[k].bitmapDataStream = Stream_Buffer(s); bitmapData[k].bitmapLength = Stream_Length(s); buffer = connection->encoder->grid[k]; CopyMemory(buffer, bitmapData[k].bitmapDataStream, bitmapData[k].bitmapLength); bitmapData[k].bitmapDataStream = buffer; bitmapData[k].bitsPerPixel = 16; bitmapData[k].cbScanWidth = nWidth * 2; bitmapData[k].cbUncompressedSize = nWidth * nHeight * 2; pixman_image_unref(image); } bitmapData[k].cbCompFirstRowSize = 0; bitmapData[k].cbCompMainBodySize = bitmapData[k].bitmapLength; k++; } } } bitmapUpdate.count = bitmapUpdate.number = k; IFCALL(update->BitmapUpdate, (rdpContext*) connection, &bitmapUpdate); free(bitmapData); free(tile); return 0; }
void sw_render_blit_texture(struct render_t * render, struct rect_t * drect, struct texture_t * texture, struct rect_t * srect) { struct rect_t dr, sr, clip; s32_t x, y, w, h; s32_t maxw, maxh; s32_t dx, dy; if(!render || !texture) return; clip.x = 0; clip.y = 0; clip.w = render->width; clip.h = render->height; if(!drect) { dr.x = 0; dr.y = 0; dr.w = render->width; dr.h = render->height; } else { dr.x = drect->x; dr.y = drect->y; dr.w = drect->w; dr.h = drect->h; } if (srect) { x = srect->x; w = srect->w; if (x < 0) { w += x; dr.x -= x; x = 0; } maxw = texture->width - x; if (maxw < w) w = maxw; y = srect->y; h = srect->h; if (y < 0) { h += y; dr.y -= y; y = 0; } maxh = texture->height - y; if (maxh < h) h = maxh; } else { x = 0; y = 0; w = texture->width; h = texture->height; } { dx = clip.x - dr.x; if (dx > 0) { w -= dx; dr.x += dx; x += dx; } dx = dr.x + w - clip.x - clip.w; if (dx > 0) w -= dx; dy = clip.y - dr.y; if (dy > 0) { h -= dy; dr.y += dy; y += dy; } dy = dr.y + h - clip.y - clip.h; if (dy > 0) h -= dy; } if (w > 0 && h > 0) { sr.x = x; sr.y = y; sr.w = dr.w = w; sr.h = dr.h = h; pixman_image_composite(PIXMAN_OP_SRC, texture->priv, NULL, render->data, sr.x, sr.y, 0, 0, dr.x, dr.y, dr.w, dr.h); } }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { pixman_image_t *src_img = NULL; pixman_image_t *dst_img = NULL; pixman_image_t *mask_img = NULL; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int mask_x, mask_y; int w, h; pixman_op_t op; pixman_format_code_t src_fmt, dst_fmt, mask_fmt; uint32_t *srcbuf, *maskbuf; uint32_t crc32; int max_width, max_height, max_extra_stride; FLOAT_REGS_CORRUPTION_DETECTOR_START (); max_width = max_height = 24 + testnum / 10000; max_extra_stride = 4 + testnum / 1000000; if (max_width > 256) max_width = 256; if (max_height > 16) max_height = 16; if (max_extra_stride > 8) max_extra_stride = 8; prng_srand (testnum); op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))]; if (prng_rand_n (8)) { /* normal image */ src_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &src_fmt); } else { /* solid case */ src_img = create_random_image (img_fmt_list, 1, 1, max_extra_stride, &src_fmt); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); } dst_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &dst_fmt); src_width = pixman_image_get_width (src_img); src_height = pixman_image_get_height (src_img); src_stride = pixman_image_get_stride (src_img); dst_width = pixman_image_get_width (dst_img); dst_height = pixman_image_get_height (dst_img); dst_stride = pixman_image_get_stride (dst_img); srcbuf = pixman_image_get_data (src_img); src_x = prng_rand_n (src_width); src_y = prng_rand_n (src_height); dst_x = prng_rand_n (dst_width); dst_y = prng_rand_n (dst_height); mask_img = NULL; mask_fmt = PIXMAN_null; mask_x = 0; mask_y = 0; maskbuf = NULL; if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) && (prng_rand_n (4) == 0)) { /* PIXBUF */ mask_fmt = prng_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8; mask_img = pixman_image_create_bits (mask_fmt, src_width, src_height, srcbuf, src_stride); mask_x = src_x; mask_y = src_y; maskbuf = srcbuf; } else if (prng_rand_n (2)) { if (prng_rand_n (2)) { mask_img = create_random_image (mask_fmt_list, max_width, max_height, max_extra_stride, &mask_fmt); } else { /* solid case */ mask_img = create_random_image (mask_fmt_list, 1, 1, max_extra_stride, &mask_fmt); pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL); } if (prng_rand_n (2)) pixman_image_set_component_alpha (mask_img, 1); mask_x = prng_rand_n (pixman_image_get_width (mask_img)); mask_y = prng_rand_n (pixman_image_get_height (mask_img)); } w = prng_rand_n (dst_width - dst_x + 1); h = prng_rand_n (dst_height - dst_y + 1); if (verbose) { printf ("op=%s\n", operator_name (op)); printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n", format_name (src_fmt), format_name (dst_fmt), format_name (mask_fmt)); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("src_stride=%d, dst_stride=%d\n", src_stride, dst_stride); printf ("w=%d, h=%d\n", w, h); } pixman_image_composite (op, src_img, mask_img, dst_img, src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h); if (verbose) print_image (dst_img); free_random_image (0, src_img, PIXMAN_null); crc32 = free_random_image (0, dst_img, dst_fmt); if (mask_img) { if (srcbuf == maskbuf) pixman_image_unref(mask_img); else free_random_image (0, mask_img, PIXMAN_null); } FLOAT_REGS_CORRUPTION_DETECTOR_FINISH (); return crc32; }
static cairo_int_status_t _cairo_image_surface_composite_trapezoids (cairo_operator_t op, cairo_pattern_t *pattern, void *abstract_dst, cairo_antialias_t antialias, int src_x, int src_y, int dst_x, int dst_y, unsigned int width, unsigned int height, cairo_trapezoid_t *traps, int num_traps) { cairo_surface_attributes_t attributes; cairo_image_surface_t *dst = abstract_dst; cairo_image_surface_t *src; cairo_int_status_t status; pixman_image_t *mask; pixman_format_code_t format; uint32_t *mask_data; pixman_trapezoid_t stack_traps[CAIRO_STACK_ARRAY_LENGTH (pixman_trapezoid_t)]; pixman_trapezoid_t *pixman_traps = stack_traps; int mask_stride; int i; if (height == 0 || width == 0) return CAIRO_STATUS_SUCCESS; /* Convert traps to pixman traps */ if (num_traps > ARRAY_LENGTH (stack_traps)) { pixman_traps = _cairo_malloc_ab (num_traps, sizeof (pixman_trapezoid_t)); if (pixman_traps == NULL) return _cairo_error (CAIRO_STATUS_NO_MEMORY); } for (i = 0; i < num_traps; i++) { pixman_traps[i].top = _cairo_fixed_to_16_16 (traps[i].top); pixman_traps[i].bottom = _cairo_fixed_to_16_16 (traps[i].bottom); pixman_traps[i].left.p1.x = _cairo_fixed_to_16_16 (traps[i].left.p1.x); pixman_traps[i].left.p1.y = _cairo_fixed_to_16_16 (traps[i].left.p1.y); pixman_traps[i].left.p2.x = _cairo_fixed_to_16_16 (traps[i].left.p2.x); pixman_traps[i].left.p2.y = _cairo_fixed_to_16_16 (traps[i].left.p2.y); pixman_traps[i].right.p1.x = _cairo_fixed_to_16_16 (traps[i].right.p1.x); pixman_traps[i].right.p1.y = _cairo_fixed_to_16_16 (traps[i].right.p1.y); pixman_traps[i].right.p2.x = _cairo_fixed_to_16_16 (traps[i].right.p2.x); pixman_traps[i].right.p2.y = _cairo_fixed_to_16_16 (traps[i].right.p2.y); } /* Special case adding trapezoids onto a mask surface; we want to avoid * creating an intermediate temporary mask unnecessarily. * * We make the assumption here that the portion of the trapezoids * contained within the surface is bounded by [dst_x,dst_y,width,height]; * the Cairo core code passes bounds based on the trapezoid extents. * * Currently the check surface->has_clip is needed for correct * functioning, since pixman_add_trapezoids() doesn't obey the * surface clip, which is a libpixman bug , but there's no harm in * falling through to the general case when the surface is clipped * since libpixman would have to generate an intermediate mask anyways. */ if (op == CAIRO_OPERATOR_ADD && _cairo_pattern_is_opaque_solid (pattern) && dst->base.content == CAIRO_CONTENT_ALPHA && ! dst->has_clip && antialias != CAIRO_ANTIALIAS_NONE) { pixman_add_trapezoids (dst->pixman_image, 0, 0, num_traps, pixman_traps); status = CAIRO_STATUS_SUCCESS; goto finish; } status = _cairo_pattern_acquire_surface (pattern, &dst->base, src_x, src_y, width, height, (cairo_surface_t **) &src, &attributes); if (status) goto finish; status = _cairo_image_surface_set_attributes (src, &attributes); if (status) goto CLEANUP_SOURCE; switch (antialias) { case CAIRO_ANTIALIAS_NONE: format = PIXMAN_a1; mask_stride = ((width + 31) / 8) & ~0x03; break; case CAIRO_ANTIALIAS_GRAY: case CAIRO_ANTIALIAS_SUBPIXEL: case CAIRO_ANTIALIAS_DEFAULT: default: format = PIXMAN_a8; mask_stride = (width + 3) & ~3; break; } /* The image must be initially transparent */ mask_data = calloc (mask_stride, height); if (mask_data == NULL) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto CLEANUP_SOURCE; } mask = pixman_image_create_bits (format, width, height, mask_data, mask_stride); if (mask == NULL) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto CLEANUP_IMAGE_DATA; } pixman_add_trapezoids (mask, - dst_x, - dst_y, num_traps, pixman_traps); pixman_image_composite (_pixman_operator (op), src->pixman_image, mask, dst->pixman_image, src_x + attributes.x_offset, src_y + attributes.y_offset, 0, 0, dst_x, dst_y, width, height); if (! _cairo_operator_bounded_by_mask (op)) status = _cairo_surface_composite_shape_fixup_unbounded (&dst->base, &attributes, src->width, src->height, width, height, src_x, src_y, 0, 0, dst_x, dst_y, width, height); pixman_image_unref (mask); CLEANUP_IMAGE_DATA: free (mask_data); CLEANUP_SOURCE: _cairo_pattern_release_surface (pattern, &src->base, &attributes); finish: if (pixman_traps != stack_traps) free (pixman_traps); return status; }
/* * We have a source image filled with solid color, set NORMAL or PAD repeat, * and some transform which results in nearest neighbour scaling. * * The expected result is either that the destination image filled with this solid * color or, if the transformation is such that we can't composite anything at * all, that nothing has changed in the destination. * * The surrounding memory of the source image is a different solid color so that * we are sure to get failures if we access it. */ static int run_test (int32_t dst_width, int32_t dst_height, int32_t src_width, int32_t src_height, int32_t src_x, int32_t src_y, int32_t scale_x, int32_t scale_y, pixman_filter_t filter, pixman_repeat_t repeat) { pixman_image_t * src_img; pixman_image_t * dst_img; pixman_transform_t transform; uint32_t * srcbuf; uint32_t * dstbuf; pixman_box32_t box = { 0, 0, src_width, src_height }; pixman_color_t color_cc = { 0xcccc, 0xcccc, 0xcccc, 0xcccc }; int result; int i; static const pixman_fixed_t kernel[] = { #define D(f) (pixman_double_to_fixed (f) + 0x0001) pixman_int_to_fixed (5), pixman_int_to_fixed (5), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0) }; result = 0; srcbuf = (uint32_t *)malloc ((src_width + 10) * (src_height + 10) * 4); dstbuf = (uint32_t *)malloc (dst_width * dst_height * 4); memset (srcbuf, 0x88, src_width * src_height * 4); memset (dstbuf, 0x33, dst_width * dst_height * 4); src_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, src_width, src_height, srcbuf + (src_width + 10) * 5 + 5, (src_width + 10) * 4); pixman_image_fill_boxes (PIXMAN_OP_SRC, src_img, &color_cc, 1, &box); dst_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, dst_width, dst_height, dstbuf, dst_width * 4); pixman_transform_init_scale (&transform, scale_x, scale_y); pixman_image_set_transform (src_img, &transform); pixman_image_set_repeat (src_img, repeat); if (filter == PIXMAN_FILTER_CONVOLUTION) pixman_image_set_filter (src_img, filter, kernel, 27); else pixman_image_set_filter (src_img, filter, NULL, 0); pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img, src_x, src_y, 0, 0, 0, 0, dst_width, dst_height); pixman_image_unref (src_img); pixman_image_unref (dst_img); for (i = 0; i < dst_width * dst_height; i++) { if (dstbuf[i] != 0xCCCCCCCC && dstbuf[i] != 0x33333333) { result = 1; break; } } free (srcbuf); free (dstbuf); return result; }
static void scale_rgba_in_to_out_clip_sample_internal(RGBA_Image *src, RGBA_Image *dst, RGBA_Draw_Context *dc, int src_region_x, int src_region_y, int src_region_w, int src_region_h, int dst_region_x, int dst_region_y, int dst_region_w, int dst_region_h) { int x, y; int *lin_ptr; DATA32 *buf, *dptr; DATA32 **row_ptr; DATA32 *ptr, *dst_ptr, *src_data, *dst_data; int dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h; int m_clip_x = 0, m_clip_y = 0, m_clip_w = 0, m_clip_h = 0, mdx = 0, mdy = 0; int src_w, src_h, dst_w, dst_h; RGBA_Gfx_Func func; RGBA_Image *maskobj = NULL; DATA8 *mask = NULL; if (!(RECTS_INTERSECT(dst_region_x, dst_region_y, dst_region_w, dst_region_h, 0, 0, dst->cache_entry.w, dst->cache_entry.h))) return; if (!(RECTS_INTERSECT(src_region_x, src_region_y, src_region_w, src_region_h, 0, 0, src->cache_entry.w, src->cache_entry.h))) return; src_w = src->cache_entry.w; src_h = src->cache_entry.h; dst_w = dst->cache_entry.w; dst_h = dst->cache_entry.h; src_data = src->image.data; dst_data = dst->image.data; if (dc->clip.use) { dst_clip_x = dc->clip.x; dst_clip_y = dc->clip.y; dst_clip_w = dc->clip.w; dst_clip_h = dc->clip.h; if (dst_clip_x < 0) { dst_clip_w += dst_clip_x; dst_clip_x = 0; } if (dst_clip_y < 0) { dst_clip_h += dst_clip_y; dst_clip_y = 0; } if ((dst_clip_x + dst_clip_w) > dst_w) dst_clip_w = dst_w - dst_clip_x; if ((dst_clip_y + dst_clip_h) > dst_h) dst_clip_h = dst_h - dst_clip_y; } else { dst_clip_x = 0; dst_clip_y = 0; dst_clip_w = dst_w; dst_clip_h = dst_h; } if (dc->mask.mask) { m_clip_x = dc->mask.x; m_clip_y = dc->mask.y; m_clip_w = dc->mask.mask->cache_entry.w; m_clip_h = dc->mask.mask->cache_entry.h; RECTS_CLIP_TO_RECT(m_clip_x, m_clip_y, m_clip_w, m_clip_h, dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h); if ((m_clip_w <= 0) || (m_clip_h <= 0)) return; dst_clip_x = m_clip_x; dst_clip_y = m_clip_y; dst_clip_w = m_clip_w; dst_clip_h = m_clip_h; } if (dst_clip_x < dst_region_x) { dst_clip_w += dst_clip_x - dst_region_x; dst_clip_x = dst_region_x; } if ((dst_clip_x + dst_clip_w) > (dst_region_x + dst_region_w)) dst_clip_w = dst_region_x + dst_region_w - dst_clip_x; if (dst_clip_y < dst_region_y) { dst_clip_h += dst_clip_y - dst_region_y; dst_clip_y = dst_region_y; } if ((dst_clip_y + dst_clip_h) > (dst_region_y + dst_region_h)) dst_clip_h = dst_region_y + dst_region_h - dst_clip_y; if ((src_region_w <= 0) || (src_region_h <= 0) || (dst_region_w <= 0) || (dst_region_h <= 0) || (dst_clip_w <= 0) || (dst_clip_h <= 0)) return; /* sanitise x */ if (src_region_x < 0) { dst_region_x -= (src_region_x * dst_region_w) / src_region_w; dst_region_w += (src_region_x * dst_region_w) / src_region_w; src_region_w += src_region_x; src_region_x = 0; } if (src_region_x >= src_w) return; if ((src_region_x + src_region_w) > src_w) { dst_region_w = (dst_region_w * (src_w - src_region_x)) / (src_region_w); src_region_w = src_w - src_region_x; } if (dst_region_w <= 0) return; if (src_region_w <= 0) return; if (dst_clip_x < 0) { dst_clip_w += dst_clip_x; dst_clip_x = 0; } if (dst_clip_w <= 0) return; if (dst_clip_x >= dst_w) return; if (dst_clip_x < dst_region_x) { dst_clip_w += (dst_clip_x - dst_region_x); dst_clip_x = dst_region_x; } if ((dst_clip_x + dst_clip_w) > dst_w) { dst_clip_w = dst_w - dst_clip_x; } if (dst_clip_w <= 0) return; /* sanitise y */ if (src_region_y < 0) { dst_region_y -= (src_region_y * dst_region_h) / src_region_h; dst_region_h += (src_region_y * dst_region_h) / src_region_h; src_region_h += src_region_y; src_region_y = 0; } if (src_region_y >= src_h) return; if ((src_region_y + src_region_h) > src_h) { dst_region_h = (dst_region_h * (src_h - src_region_y)) / (src_region_h); src_region_h = src_h - src_region_y; } if (dst_region_h <= 0) return; if (src_region_h <= 0) return; if (dst_clip_y < 0) { dst_clip_h += dst_clip_y; dst_clip_y = 0; } if (dst_clip_h <= 0) return; if (dst_clip_y >= dst_h) return; if (dst_clip_y < dst_region_y) { dst_clip_h += (dst_clip_y - dst_region_y); dst_clip_y = dst_region_y; } if ((dst_clip_y + dst_clip_h) > dst_h) { dst_clip_h = dst_h - dst_clip_y; } if (dst_clip_h <= 0) return; /* allocate scale lookup tables */ lin_ptr = alloca(dst_clip_w * sizeof(int)); row_ptr = alloca(dst_clip_h * sizeof(DATA32 *)); /* figure out dst jump */ //dst_jump = dst_w - dst_clip_w; /* figure out dest start ptr */ dst_ptr = dst_data + dst_clip_x + (dst_clip_y * dst_w); if (dc->mask.mask) { func = evas_common_gfx_func_composite_pixel_mask_span_get(src, dst, dst_clip_w, dc->render_op); maskobj = dc->mask.mask; mask = maskobj->mask.mask; /* if (1 || dst_region_w > src_region_w || dst_region_h > src_region_h){ printf("Mask w/h: %d/%d\n",maskobj->cache_entry.w, maskobj->cache_entry.h); printf("Warning: Unscaled mask (%d/%d) // (%d/%d)\n", dst_region_w,src_region_w, dst_region_h,src_region_h); } */ } else if (dc->mul.use) func = evas_common_gfx_func_composite_pixel_color_span_get(src, dc->mul.col, dst, dst_clip_w, dc->render_op); else func = evas_common_gfx_func_composite_pixel_span_get(src, dst, dst_clip_w, dc->render_op); if ((dst_region_w == src_region_w) && (dst_region_h == src_region_h)) { #ifdef HAVE_PIXMAN # ifdef PIXMAN_IMAGE_SCALE_SAMPLE if ((src->pixman.im) && (dst->pixman.im) && (!dc->mask.mask) && ((!dc->mul.use) || ((dc->mul.use) && (dc->mul.col == 0xffffffff))) && ((dc->render_op == _EVAS_RENDER_COPY) || (dc->render_op == _EVAS_RENDER_BLEND))) { pixman_op_t op = PIXMAN_OP_SRC; // _EVAS_RENDER_COPY if (dc->render_op == _EVAS_RENDER_BLEND) op = PIXMAN_OP_OVER; pixman_image_composite(op, src->pixman.im, NULL, dst->pixman.im, (dst_clip_x - dst_region_x) + src_region_x, (dst_clip_y - dst_region_y) + src_region_y, 0, 0, dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h); } else if ((src->pixman.im) && (dst->pixman.im) && (dc->mask.mask) && (dc->mask.mask->pixman.im) && ((dc->render_op == _EVAS_RENDER_COPY) || (dc->render_op == _EVAS_RENDER_BLEND))) { // In case of pixel and color operation. pixman_op_t op = PIXMAN_OP_SRC; // _EVAS_RENDER_COPY if (dc->render_op == _EVAS_RENDER_BLEND) op = PIXMAN_OP_OVER; pixman_image_composite(op, src->pixman.im, dc->mask.mask->pixman.im, dst->pixman.im, (dst_clip_x - dst_region_x) + src_region_x, (dst_clip_y - dst_region_y) + src_region_y, 0, 0, dst_clip_x, dst_clip_y, dst_clip_w, dst_clip_h); } else # endif #endif { ptr = src_data + ((dst_clip_y - dst_region_y + src_region_y) * src_w) + (dst_clip_x - dst_region_x) + src_region_x; if (mask) { mdx = (m_clip_x - dc->mask.x) + (m_clip_x - dst_clip_x); mdy = (m_clip_y - dc->mask.y) + (m_clip_y - dst_clip_y); mask += mdx + (mdy * maskobj->cache_entry.w); } for (y = 0; y < dst_clip_h; y++) { /* * blend here [clip_w *] ptr -> dst_ptr * */ func(ptr, mask, dc->mul.col, dst_ptr, dst_clip_w); ptr += src_w; dst_ptr += dst_w; if (mask) mask += maskobj->cache_entry.w; } } } else { /* fill scale tables */ for (x = 0; x < dst_clip_w; x++) lin_ptr[x] = (((x + dst_clip_x - dst_region_x) * src_region_w) / dst_region_w) + src_region_x; for (y = 0; y < dst_clip_h; y++) row_ptr[y] = src_data + (((((y + dst_clip_y - dst_region_y) * src_region_h) / dst_region_h) + src_region_y) * src_w); /* scale to dst */ dptr = dst_ptr; #ifdef DIRECT_SCALE if ((!src->cache_entry.flags.alpha) && (!dst->cache_entry.flags.alpha) && (!dc->mul.use)) { for (y = 0; y < dst_clip_h; y++) { dst_ptr = dptr; for (x = 0; x < dst_clip_w; x++) { ptr = row_ptr[y] + lin_ptr[x]; *dst_ptr = *ptr; dst_ptr++; } dptr += dst_w; } } else #endif { /* a scanline buffer */ buf = alloca(dst_clip_w * sizeof(DATA32)); for (y = 0; y < dst_clip_h; y++) { dst_ptr = buf; for (x = 0; x < dst_clip_w; x++) { ptr = row_ptr[y] + lin_ptr[x]; *dst_ptr = *ptr; dst_ptr++; } /* * blend here [clip_w *] buf -> dptr * */ func(buf, NULL, dc->mul.col, dptr, dst_clip_w); dptr += dst_w; } } } }
/* * pixman_composite_trapezoids() * * All the trapezoids are conceptually rendered to an infinitely big image. * The (0, 0) coordinates of this image are then aligned with the (x, y) * coordinates of the source image, and then both images are aligned with * the (x, y) coordinates of the destination. Then, in principle, compositing * of these three images takes place across the entire destination. * * FIXME: However, there is currently a bug, where we restrict this compositing * to the bounding box of the trapezoids. This is incorrect for operators such * as SRC and IN where blank source pixels do have an effect on the destination. */ PIXMAN_EXPORT void pixman_composite_trapezoids (pixman_op_t op, pixman_image_t * src, pixman_image_t * dst, pixman_format_code_t mask_format, int x_src, int y_src, int x_dst, int y_dst, int n_traps, const pixman_trapezoid_t * traps) { int i; if (n_traps <= 0) return; _pixman_image_validate (src); _pixman_image_validate (dst); if (op == PIXMAN_OP_ADD && (src->common.flags & FAST_PATH_IS_OPAQUE) && (mask_format == dst->common.extended_format_code) && !(dst->common.have_clip_region)) { for (i = 0; i < n_traps; ++i) { const pixman_trapezoid_t *trap = &(traps[i]); if (!pixman_trapezoid_valid (trap)) continue; pixman_rasterize_trapezoid (dst, trap, x_dst, y_dst); } } else { pixman_image_t *tmp; pixman_box32_t box; box.x1 = INT32_MAX; box.y1 = INT32_MAX; box.x2 = INT32_MIN; box.y2 = INT32_MIN; for (i = 0; i < n_traps; ++i) { const pixman_trapezoid_t *trap = &(traps[i]); int y1, y2; if (!pixman_trapezoid_valid (trap)) continue; y1 = pixman_fixed_to_int (trap->top); if (y1 < box.y1) box.y1 = y1; y2 = pixman_fixed_to_int (pixman_fixed_ceil (trap->bottom)); if (y2 > box.y2) box.y2 = y2; #define EXTEND_MIN(x) \ if (pixman_fixed_to_int ((x)) < box.x1) \ box.x1 = pixman_fixed_to_int ((x)); #define EXTEND_MAX(x) \ if (pixman_fixed_to_int (pixman_fixed_ceil ((x))) > box.x2) \ box.x2 = pixman_fixed_to_int (pixman_fixed_ceil ((x))); #define EXTEND(x) \ EXTEND_MIN(x); \ EXTEND_MAX(x); EXTEND(trap->left.p1.x); EXTEND(trap->left.p2.x); EXTEND(trap->right.p1.x); EXTEND(trap->right.p2.x); } if (box.x1 >= box.x2 || box.y1 >= box.y2) return; tmp = pixman_image_create_bits ( mask_format, box.x2 - box.x1, box.y2 - box.y1, NULL, -1); for (i = 0; i < n_traps; ++i) { const pixman_trapezoid_t *trap = &(traps[i]); if (!pixman_trapezoid_valid (trap)) continue; pixman_rasterize_trapezoid (tmp, trap, - box.x1, - box.y1); } pixman_image_composite (op, src, tmp, dst, x_src + box.x1, y_src + box.y1, 0, 0, x_dst + box.x1, y_dst + box.y1, box.x2 - box.x1, box.y2 - box.y1); pixman_image_unref (tmp); } }
/* * pixman_composite_trapezoids() * * All the trapezoids are conceptually rendered to an infinitely big image. * The (0, 0) coordinates of this image are then aligned with the (x, y) * coordinates of the source image, and then both images are aligned with * the (x, y) coordinates of the destination. Then these three images are * composited across the entire destination. */ PIXMAN_EXPORT void pixman_composite_trapezoids (pixman_op_t op, pixman_image_t * src, pixman_image_t * dst, pixman_format_code_t mask_format, int x_src, int y_src, int x_dst, int y_dst, int n_traps, const pixman_trapezoid_t * traps) { int i; return_if_fail (PIXMAN_FORMAT_TYPE (mask_format) == PIXMAN_TYPE_A); if (n_traps <= 0) return; _pixman_image_validate (src); _pixman_image_validate (dst); if (op == PIXMAN_OP_ADD && (src->common.flags & FAST_PATH_IS_OPAQUE) && (mask_format == dst->common.extended_format_code) && !(dst->common.have_clip_region)) { for (i = 0; i < n_traps; ++i) { const pixman_trapezoid_t *trap = &(traps[i]); if (!pixman_trapezoid_valid (trap)) continue; pixman_rasterize_trapezoid (dst, trap, x_dst, y_dst); } } else { pixman_image_t *tmp; pixman_box32_t box; int i; if (!get_trap_extents (op, dst, traps, n_traps, &box)) return; if (!(tmp = pixman_image_create_bits ( mask_format, box.x2 - box.x1, box.y2 - box.y1, NULL, -1))) return; for (i = 0; i < n_traps; ++i) { const pixman_trapezoid_t *trap = &(traps[i]); if (!pixman_trapezoid_valid (trap)) continue; pixman_rasterize_trapezoid (tmp, trap, - box.x1, - box.y1); } pixman_image_composite (op, src, tmp, dst, x_src + box.x1, y_src + box.y1, 0, 0, x_dst + box.x1, y_dst + box.y1, box.x2 - box.x1, box.y2 - box.y1); pixman_image_unref (tmp); } }
int main (int argc, char **argv) { #define WIDTH 400 #define HEIGHT 200 uint32_t *alpha = malloc (WIDTH * HEIGHT * 4); uint32_t *dest = malloc (WIDTH * HEIGHT * 4); uint32_t *src = malloc (WIDTH * HEIGHT * 4); pixman_image_t *grad_img; pixman_image_t *alpha_img; pixman_image_t *dest_img; pixman_image_t *src_img; int i; pixman_gradient_stop_t stops[2] = { { pixman_int_to_fixed (0), { 0x0000, 0x0000, 0x0000, 0x0000 } }, { pixman_int_to_fixed (1), { 0xffff, 0x0000, 0x1111, 0xffff } } }; pixman_point_fixed_t p1 = { pixman_double_to_fixed (0), 0 }; pixman_point_fixed_t p2 = { pixman_double_to_fixed (WIDTH), pixman_int_to_fixed (0) }; #if 0 pixman_transform_t trans = { { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }; #else pixman_transform_t trans = { { { pixman_fixed_1, 0, 0 }, { 0, pixman_fixed_1, 0 }, { 0, 0, pixman_fixed_1 } } }; #endif pixman_point_fixed_t c_inner; pixman_point_fixed_t c_outer; pixman_fixed_t r_inner; pixman_fixed_t r_outer; for (i = 0; i < WIDTH * HEIGHT; ++i) alpha[i] = 0x4f00004f; /* pale blue */ alpha_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, alpha, WIDTH * 4); for (i = 0; i < WIDTH * HEIGHT; ++i) dest[i] = 0xffffff00; /* yellow */ dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); for (i = 0; i < WIDTH * HEIGHT; ++i) src[i] = 0xffff0000; src_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, src, WIDTH * 4); c_inner.x = pixman_double_to_fixed (50.0); c_inner.y = pixman_double_to_fixed (50.0); c_outer.x = pixman_double_to_fixed (50.0); c_outer.y = pixman_double_to_fixed (50.0); r_inner = 0; r_outer = pixman_double_to_fixed (50.0); #if 0 grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner, stops, 2); #endif #if 0 grad_img = pixman_image_create_conical_gradient (&c_inner, r_inner, stops, 2); grad_img = pixman_image_create_linear_gradient (&c_inner, &c_outer, r_inner, r_outer, stops, 2); #endif grad_img = pixman_image_create_linear_gradient (&p1, &p2, stops, 2); pixman_image_set_transform (grad_img, &trans); pixman_image_set_repeat (grad_img, PIXMAN_REPEAT_PAD); pixman_image_composite (PIXMAN_OP_OVER, grad_img, NULL, alpha_img, 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT); pixman_image_set_alpha_map (src_img, alpha_img, 10, 10); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT); printf ("0, 0: %x\n", dest[0]); printf ("10, 10: %x\n", dest[10 * 10 + 10]); printf ("w, h: %x\n", dest[(HEIGHT - 1) * 100 + (WIDTH - 1)]); show_image (dest_img); pixman_image_unref (src_img); pixman_image_unref (grad_img); pixman_image_unref (alpha_img); free (dest); return 0; }
/* fill linebuf from framebuffer */ void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb, int width, int x, int y) { pixman_image_composite(PIXMAN_OP_SRC, fb, NULL, linebuf, x, y, 0, 0, 0, 0, width, 1); }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { int i; pixman_image_t * src_img; pixman_image_t * dst_img; pixman_transform_t transform; pixman_region16_t clip; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int src_bpp; int dst_bpp; int w, h; pixman_fixed_t scale_x = 65536, scale_y = 65536; pixman_fixed_t translate_x = 0, translate_y = 0; int op; int repeat = 0; int src_fmt, dst_fmt; uint32_t * srcbuf; uint32_t * dstbuf; uint32_t crc32; lcg_srand (testnum); src_bpp = (lcg_rand_n (2) == 0) ? 2 : 4; dst_bpp = (lcg_rand_n (2) == 0) ? 2 : 4; op = (lcg_rand_n (2) == 0) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER; src_width = lcg_rand_n (MAX_SRC_WIDTH) + 1; src_height = lcg_rand_n (MAX_SRC_HEIGHT) + 1; dst_width = lcg_rand_n (MAX_DST_WIDTH) + 1; dst_height = lcg_rand_n (MAX_DST_HEIGHT) + 1; src_stride = src_width * src_bpp + lcg_rand_n (MAX_STRIDE) * src_bpp; dst_stride = dst_width * dst_bpp + lcg_rand_n (MAX_STRIDE) * dst_bpp; if (src_stride & 3) src_stride += 2; if (dst_stride & 3) dst_stride += 2; src_x = -(src_width / 4) + lcg_rand_n (src_width * 3 / 2); src_y = -(src_height / 4) + lcg_rand_n (src_height * 3 / 2); dst_x = -(dst_width / 4) + lcg_rand_n (dst_width * 3 / 2); dst_y = -(dst_height / 4) + lcg_rand_n (dst_height * 3 / 2); w = lcg_rand_n (dst_width * 3 / 2 - dst_x); h = lcg_rand_n (dst_height * 3 / 2 - dst_y); srcbuf = (uint32_t *)malloc (src_stride * src_height); dstbuf = (uint32_t *)malloc (dst_stride * dst_height); for (i = 0; i < src_stride * src_height; i++) *((uint8_t *)srcbuf + i) = lcg_rand_n (256); for (i = 0; i < dst_stride * dst_height; i++) *((uint8_t *)dstbuf + i) = lcg_rand_n (256); src_fmt = src_bpp == 4 ? (lcg_rand_n (2) == 0 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8) : PIXMAN_r5g6b5; dst_fmt = dst_bpp == 4 ? (lcg_rand_n (2) == 0 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8) : PIXMAN_r5g6b5; src_img = pixman_image_create_bits ( src_fmt, src_width, src_height, srcbuf, src_stride); dst_img = pixman_image_create_bits ( dst_fmt, dst_width, dst_height, dstbuf, dst_stride); image_endian_swap (src_img, src_bpp * 8); image_endian_swap (dst_img, dst_bpp * 8); if (lcg_rand_n (8) > 0) { scale_x = -32768 * 3 + lcg_rand_N (65536 * 5); scale_y = -32768 * 3 + lcg_rand_N (65536 * 5); translate_x = lcg_rand_N (65536); translate_y = lcg_rand_N (65536); pixman_transform_init_scale (&transform, scale_x, scale_y); pixman_transform_translate (&transform, NULL, translate_x, translate_y); pixman_image_set_transform (src_img, &transform); } switch (lcg_rand_n (4)) { case 0: repeat = PIXMAN_REPEAT_NONE; break; case 1: repeat = PIXMAN_REPEAT_NORMAL; break; case 2: repeat = PIXMAN_REPEAT_PAD; break; case 3: repeat = PIXMAN_REPEAT_REFLECT; break; default: break; } pixman_image_set_repeat (src_img, repeat); if (lcg_rand_n (2)) pixman_image_set_filter (src_img, PIXMAN_FILTER_NEAREST, NULL, 0); else pixman_image_set_filter (src_img, PIXMAN_FILTER_BILINEAR, NULL, 0); if (verbose) { printf ("src_fmt=%08X, dst_fmt=%08X\n", src_fmt, dst_fmt); printf ("op=%d, scale_x=%d, scale_y=%d, repeat=%d\n", op, scale_x, scale_y, repeat); printf ("translate_x=%d, translate_y=%d\n", translate_x, translate_y); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("w=%d, h=%d\n", w, h); } if (lcg_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = lcg_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = lcg_rand_n (src_width); clip_boxes[i].y1 = lcg_rand_n (src_height); clip_boxes[i].x2 = clip_boxes[i].x1 + lcg_rand_n (src_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + lcg_rand_n (src_height - clip_boxes[i].y1); if (verbose) { printf ("source clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (src_img, &clip); pixman_image_set_source_clipping (src_img, 1); pixman_region_fini (&clip); } if (lcg_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = lcg_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = lcg_rand_n (dst_width); clip_boxes[i].y1 = lcg_rand_n (dst_height); clip_boxes[i].x2 = clip_boxes[i].x1 + lcg_rand_n (dst_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + lcg_rand_n (dst_height - clip_boxes[i].y1); if (verbose) { printf ("destination clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (dst_img, &clip); pixman_region_fini (&clip); } pixman_image_composite (op, src_img, NULL, dst_img, src_x, src_y, 0, 0, dst_x, dst_y, w, h); if (dst_fmt == PIXMAN_x8r8g8b8) { /* ignore unused part */ for (i = 0; i < dst_stride * dst_height / 4; i++) dstbuf[i] &= 0xFFFFFF; } image_endian_swap (dst_img, dst_bpp * 8); if (verbose) { int j; for (i = 0; i < dst_height; i++) { for (j = 0; j < dst_stride; j++) printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j)); printf ("\n"); } } pixman_image_unref (src_img); pixman_image_unref (dst_img); crc32 = compute_crc32 (0, dstbuf, dst_stride * dst_height); free (srcbuf); free (dstbuf); return crc32; }
/* copy linebuf to framebuffer */ void qemu_pixman_linebuf_copy(pixman_image_t *fb, int width, int x, int y, pixman_image_t *linebuf) { pixman_image_composite(PIXMAN_OP_SRC, linebuf, NULL, fb, 0, 0, 0, 0, x, y, width, 1); }
static cairo_int_status_t _cairo_image_surface_composite (cairo_operator_t op, cairo_pattern_t *src_pattern, cairo_pattern_t *mask_pattern, void *abstract_dst, int src_x, int src_y, int mask_x, int mask_y, int dst_x, int dst_y, unsigned int width, unsigned int height) { cairo_surface_attributes_t src_attr, mask_attr; cairo_image_surface_t *dst = abstract_dst; cairo_image_surface_t *src; cairo_image_surface_t *mask; cairo_int_status_t status; status = _cairo_pattern_acquire_surfaces (src_pattern, mask_pattern, &dst->base, src_x, src_y, mask_x, mask_y, width, height, (cairo_surface_t **) &src, (cairo_surface_t **) &mask, &src_attr, &mask_attr); if (status) return status; status = _cairo_image_surface_set_attributes (src, &src_attr); if (status) goto CLEANUP_SURFACES; if (mask) { status = _cairo_image_surface_set_attributes (mask, &mask_attr); if (status) goto CLEANUP_SURFACES; pixman_image_composite (_pixman_operator (op), src->pixman_image, mask->pixman_image, dst->pixman_image, src_x + src_attr.x_offset, src_y + src_attr.y_offset, mask_x + mask_attr.x_offset, mask_y + mask_attr.y_offset, dst_x, dst_y, width, height); } else { pixman_image_composite (_pixman_operator (op), src->pixman_image, NULL, dst->pixman_image, src_x + src_attr.x_offset, src_y + src_attr.y_offset, 0, 0, dst_x, dst_y, width, height); } if (! _cairo_operator_bounded_by_source (op)) status = _cairo_surface_composite_fixup_unbounded (&dst->base, &src_attr, src->width, src->height, mask ? &mask_attr : NULL, mask ? mask->width : 0, mask ? mask->height : 0, src_x, src_y, mask_x, mask_y, dst_x, dst_y, width, height); CLEANUP_SURFACES: if (mask) _cairo_pattern_release_surface (mask_pattern, &mask->base, &mask_attr); _cairo_pattern_release_surface (src_pattern, &src->base, &src_attr); return status; }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { int i; pixman_image_t *src_img = NULL; pixman_image_t *dst_img = NULL; pixman_image_t *mask_img = NULL; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int mask_x, mask_y; int w, h; pixman_op_t op; pixman_format_code_t src_fmt, dst_fmt, mask_fmt; uint32_t *dstbuf, *srcbuf, *maskbuf; uint32_t crc32; int max_width, max_height, max_extra_stride; FLOAT_REGS_CORRUPTION_DETECTOR_START (); max_width = max_height = 24 + testnum / 10000; max_extra_stride = 4 + testnum / 1000000; if (max_width > 256) max_width = 256; if (max_height > 16) max_height = 16; if (max_extra_stride > 8) max_extra_stride = 8; lcg_srand (testnum); op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))]; if (lcg_rand_n (8)) { /* normal image */ src_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &src_fmt); } else { /* solid case */ src_img = create_random_image (img_fmt_list, 1, 1, max_extra_stride, &src_fmt); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); } dst_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &dst_fmt); src_width = pixman_image_get_width (src_img); src_height = pixman_image_get_height (src_img); src_stride = pixman_image_get_stride (src_img); dst_width = pixman_image_get_width (dst_img); dst_height = pixman_image_get_height (dst_img); dst_stride = pixman_image_get_stride (dst_img); dstbuf = pixman_image_get_data (dst_img); srcbuf = pixman_image_get_data (src_img); src_x = lcg_rand_n (src_width); src_y = lcg_rand_n (src_height); dst_x = lcg_rand_n (dst_width); dst_y = lcg_rand_n (dst_height); mask_img = NULL; mask_fmt = PIXMAN_null; mask_x = 0; mask_y = 0; maskbuf = NULL; if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) && (lcg_rand_n (4) == 0)) { /* PIXBUF */ mask_fmt = lcg_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8; mask_img = pixman_image_create_bits (mask_fmt, src_width, src_height, srcbuf, src_stride); mask_x = src_x; mask_y = src_y; maskbuf = srcbuf; } else if (lcg_rand_n (2)) { if (lcg_rand_n (2)) { mask_img = create_random_image (mask_fmt_list, max_width, max_height, max_extra_stride, &mask_fmt); } else { /* solid case */ mask_img = create_random_image (mask_fmt_list, 1, 1, max_extra_stride, &mask_fmt); pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL); } if (lcg_rand_n (2)) pixman_image_set_component_alpha (mask_img, 1); mask_x = lcg_rand_n (pixman_image_get_width (mask_img)); mask_y = lcg_rand_n (pixman_image_get_height (mask_img)); } w = lcg_rand_n (dst_width - dst_x + 1); h = lcg_rand_n (dst_height - dst_y + 1); if (verbose) { printf ("op=%d, src_fmt=%08X, dst_fmt=%08X, mask_fmt=%08X\n", op, src_fmt, dst_fmt, mask_fmt); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("src_stride=%d, dst_stride=%d\n", src_stride, dst_stride); printf ("w=%d, h=%d\n", w, h); } pixman_image_composite (op, src_img, mask_img, dst_img, src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h); if (verbose) { int j; printf ("---\n"); for (i = 0; i < dst_height; i++) { for (j = 0; j < dst_stride; j++) { if (j == (dst_width * PIXMAN_FORMAT_BPP (dst_fmt) + 7) / 8) printf ("| "); printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j)); } printf ("\n"); } printf ("---\n"); } free_random_image (0, src_img, PIXMAN_null); crc32 = free_random_image (0, dst_img, dst_fmt); if (mask_img) { if (srcbuf == maskbuf) pixman_image_unref(mask_img); else free_random_image (0, mask_img, PIXMAN_null); } FLOAT_REGS_CORRUPTION_DETECTOR_FINISH (); return crc32; }
int main (int argc, char **argv) { #define WIDTH 400 #define HEIGHT 200 uint32_t *dest = malloc (WIDTH * HEIGHT * 4); pixman_image_t *src_img; pixman_image_t *dest_img; int i, j, k, p; typedef struct { pixman_point_fixed_t p0; pixman_point_fixed_t p1; } point_pair_t; pixman_gradient_stop_t onestop[1] = { { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, }; pixman_gradient_stop_t subsetstops[2] = { { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, { pixman_int_to_fixed (1), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, }; pixman_gradient_stop_t stops01[2] = { { pixman_int_to_fixed (0), { 0xffff, 0xeeee, 0xeeee, 0xeeee } }, { pixman_int_to_fixed (1), { 0xffff, 0x1111, 0x1111, 0x1111 } } }; point_pair_t point_pairs [] = { { { pixman_double_to_fixed (0), 0 }, { pixman_double_to_fixed (WIDTH / 8.), pixman_int_to_fixed (0) } }, { { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) }, { pixman_double_to_fixed (WIDTH / 2.0), pixman_double_to_fixed (HEIGHT / 2.0) } } }; pixman_transform_t transformations[] = { { { { pixman_double_to_fixed (2), pixman_double_to_fixed (0.5), pixman_double_to_fixed (-100), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (3), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (1), pixman_double_to_fixed (0), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (1.000), pixman_double_to_fixed (1.0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (0), pixman_double_to_fixed (0), pixman_double_to_fixed (0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } } }, { { { pixman_double_to_fixed (2), pixman_double_to_fixed (1), pixman_double_to_fixed (3), }, { pixman_double_to_fixed (1), pixman_double_to_fixed (1), pixman_double_to_fixed (0), }, { pixman_double_to_fixed (2), pixman_double_to_fixed (-1), pixman_double_to_fixed (0) } } }, }; pixman_fixed_t r_inner; pixman_fixed_t r_outer; enable_divbyzero_exceptions(); for (i = 0; i < WIDTH * HEIGHT; ++i) dest[i] = 0x4f00004f; /* pale blue */ dest_img = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, dest, WIDTH * 4); r_inner = 0; r_outer = pixman_double_to_fixed (50.0); for (i = 0; i < 3; ++i) { pixman_gradient_stop_t *stops; int num_stops; if (i == 0) { stops = onestop; num_stops = ARRAY_LENGTH (onestop); } else if (i == 1) { stops = subsetstops; num_stops = ARRAY_LENGTH (subsetstops); } else { stops = stops01; num_stops = ARRAY_LENGTH (stops01); } for (j = 0; j < 3; ++j) { for (p = 0; p < ARRAY_LENGTH (point_pairs); ++p) { point_pair_t *pair = &(point_pairs[p]); if (j == 0) src_img = pixman_image_create_conical_gradient (&(pair->p0), r_inner, stops, num_stops); else if (j == 1) src_img = pixman_image_create_radial_gradient (&(pair->p0), &(pair->p1), r_inner, r_outer, stops, num_stops); else src_img = pixman_image_create_linear_gradient (&(pair->p0), &(pair->p1), stops, num_stops); for (k = 0; k < ARRAY_LENGTH (transformations); ++k) { pixman_image_set_transform (src_img, &transformations[k]); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NONE); pixman_image_composite (PIXMAN_OP_OVER, src_img, NULL, dest_img, 0, 0, 0, 0, 0, 0, 10 * WIDTH, HEIGHT); } pixman_image_unref (src_img); } } } pixman_image_unref (dest_img); free (dest); return 0; }