Ejemplo n.º 1
0
void art_draw_transformed_rgba_image(art_buffer_p dest_buffer, 
				     unsigned char *src_buffer, int src_width,
				     int src_height, int dest_x, int dest_y,
				     float angle, float scale)
{
  double affine[6];

  affine[0] = scale * cos(angle);
  affine[1] = -scale * sin(angle);
  affine[2] = scale * sin(angle);
  affine[3] = scale * cos(angle);
  affine[4] = dest_x - src_height * scale * sin(angle);
  affine[5] = dest_buffer->height - dest_y - src_height * scale * cos(angle);

  art_rgb_rgba_affine(dest_buffer->buffer, 0, 0, dest_buffer->width,
		      dest_buffer->height, dest_buffer->width * 3,
		      (art_u8 *)src_buffer, src_width, src_height, 
		      src_width * 4, affine, ART_FILTER_NEAREST, NULL);
}
Ejemplo n.º 2
0
void art_draw_rgba_image(art_buffer_p dest_buffer, int dest_x, int dest_y,
			 int dest_width, int dest_height, 
			 unsigned char *src_buffer, int src_width,
			 int src_height)
{
  double affine[6];

  affine[0] = dest_width / (float)src_width;
  affine[1] = 0;
  affine[2] = 0;
  affine[3] = dest_height / (float)src_height;
  affine[4] = dest_x;
  affine[5] = dest_buffer->height - dest_y - dest_height;

  art_rgb_rgba_affine(dest_buffer->buffer, 0, 0, dest_buffer->width,
		      dest_buffer->height, dest_buffer->width * 3,
		      (art_u8 *)src_buffer, src_width, src_height, 
		      src_width * 3, affine, ART_FILTER_NEAREST, NULL);
}
Ejemplo n.º 3
0
/**
 * art_rgb_pixbuf_affine: Affine transform source RGB pixbuf and composite.
 * @dst: Destination image RGB buffer.
 * @x0: Left coordinate of destination rectangle.
 * @y0: Top coordinate of destination rectangle.
 * @x1: Right coordinate of destination rectangle.
 * @y1: Bottom coordinate of destination rectangle.
 * @dst_rowstride: Rowstride of @dst buffer.
 * @pixbuf: source image pixbuf.
 * @affine: Affine transform.
 * @level: Filter level.
 * @alphagamma: #ArtAlphaGamma for gamma-correcting the compositing.
 *
 * Affine transform the source image stored in @src, compositing over
 * the area of destination image @dst specified by the rectangle
 * (@x0, @y0) - (@x1, @y1). As usual in libart, the left and top edges
 * of this rectangle are included, and the right and bottom edges are
 * excluded.
 *
 * The @alphagamma parameter specifies that the alpha compositing be
 * done in a gamma-corrected color space. In the current
 * implementation, it is ignored.
 *
 * The @level parameter specifies the speed/quality tradeoff of the
 * image interpolation. Currently, only ART_FILTER_NEAREST is
 * implemented.
 **/
void
art_rgb_pixbuf_affine (art_u8 *dst,
                       int x0, int y0, int x1, int y1, int dst_rowstride,
                       const ArtPixBuf *pixbuf,
                       const double affine[6],
                       ArtFilterLevel level,
                       ArtAlphaGamma *alphagamma)
{
  if (pixbuf->format != ART_PIX_RGB)
    {
      art_warn ("art_rgb_pixbuf_affine: need RGB format image\n");
      return;
    }

  if (pixbuf->bits_per_sample != 8)
    {
      art_warn ("art_rgb_pixbuf_affine: need 8-bit sample data\n");
      return;
    }

  if (pixbuf->n_channels != 3 + (pixbuf->has_alpha != 0))
    {
      art_warn ("art_rgb_pixbuf_affine: need 8-bit sample data\n");
      return;
    }

  if (pixbuf->has_alpha)
    art_rgb_rgba_affine (dst, x0, y0, x1, y1, dst_rowstride,
                         pixbuf->pixels,
                         pixbuf->width, pixbuf->height, pixbuf->rowstride,
                         affine,
                         level,
                         alphagamma);
  else
    art_rgb_affine (dst, x0, y0, x1, y1, dst_rowstride,
                    pixbuf->pixels,
                    pixbuf->width, pixbuf->height, pixbuf->rowstride,
                    affine,
                    level,
                    alphagamma);
}
Ejemplo n.º 4
0
static void
make_testpat (void)
{
    ArtVpath *vpath, *vpath2, *vpath3;
    ArtSVP *svp, *svp2;
    ArtSVP *svp3;
    art_u8 buf[512 * 512 * BYTES_PP];
    int i, j;
    int iter;
    art_u8 colorimg[256][256][3];
    art_u8 rgbaimg[256][256][4];
    art_u8 bitimg[16][2];
    int x, y;
    double affine[6];
    double affine2[6];
    double affine3[6];
    ArtAlphaGamma *alphagamma;
    double dash_data[] = { 20 };
    ArtVpathDash dash;

    dash.offset = 0;
    dash.n_dash = 1;
    dash.dash = dash_data;

#ifdef TEST_AFFINE
    test_affine ();
    exit (0);
#endif

    vpath = randstar (50);
    svp = art_svp_from_vpath (vpath);
    art_free (vpath);

    vpath2 = randstar (50);
#if 1
    vpath3 = art_vpath_dash (vpath2, &dash);
    art_free (vpath2);
    svp2 = art_svp_vpath_stroke (vpath3,
                                 ART_PATH_STROKE_JOIN_MITER,
                                 ART_PATH_STROKE_CAP_BUTT,
                                 15,
                                 4,
                                 0.5);
    art_free (vpath3);
#else
    svp2 = art_svp_from_vpath (vpath2);
#endif

#if 1
    svp3 = art_svp_intersect (svp, svp2);
#else
    svp3 = svp2;
#endif

#if 0
    print_svp (svp);
#endif

    for (y = 0; y < 256; y++)
        for (x = 0; x < 256; x++)
        {
            colorimg[y][x][0] = (x + y) >> 1;
            colorimg[y][x][1] = (x + (255 - y)) >> 1;
            colorimg[y][x][2] = ((255 - x) + y) >> 1;

            rgbaimg[y][x][0] = (x + y) >> 1;
            rgbaimg[y][x][1] = (x + (255 - y)) >> 1;
            rgbaimg[y][x][2] = ((255 - x) + y) >> 1;
            rgbaimg[y][x][3] = y;
        }

    for (y = 0; y < 16; y++)
        for (x = 0; x < 2; x++)
            bitimg[y][x] = (x << 4) | y;

    affine[0] = 0.5;
    affine[1] = .2;
    affine[2] = -.2;
    affine[3] = 0.5;
    affine[4] = 64;
    affine[5] = 64;

    affine2[0] = 1;
    affine2[1] = -.2;
    affine2[2] = .2;
    affine2[3] = 1;
    affine2[4] = 128;
    affine2[5] = 128;

    affine3[0] = 5;
    affine3[1] = -.2;
    affine3[2] = .2;
    affine3[3] = 5;
    affine3[4] = 384;
    affine3[5] = 32;

#if 0
    alphagamma = art_alphagamma_new (1.8);
#else
    alphagamma = NULL;
#endif

#ifdef COLOR
    printf ("P6\n512 512\n255\n");
#else
    printf ("P5\n512 512\n255\n");
#endif
    for (iter = 0; iter < NUM_ITERS; iter++)
        for (j = 0; j < 512; j += TILE_SIZE)
            for (i = 0; i < 512; i += TILE_SIZE)
            {
#ifdef COLOR
                art_rgb_svp_aa (svp, i, j, i + TILE_SIZE, j + TILE_SIZE,
                                0xffe0a0, 0x100040,
                                buf + (j * 512 + i) * BYTES_PP, 512 * BYTES_PP,
                                alphagamma);
                art_rgb_svp_alpha (svp2, i, j, i + TILE_SIZE, j + TILE_SIZE,
                                   0xff000080,
                                   buf + (j * 512 + i) * BYTES_PP, 512 * BYTES_PP,
                                   alphagamma);
                art_rgb_svp_alpha (svp3, i, j, i + TILE_SIZE, j + TILE_SIZE,
                                   0x00ff0080,
                                   buf + (j * 512 + i) * BYTES_PP, 512 * BYTES_PP,
                                   alphagamma);
                art_rgb_affine (buf + (j * 512 + i) * BYTES_PP,
                                i, j, i + TILE_SIZE, j + TILE_SIZE, 512 * BYTES_PP,
                                (art_u8 *)colorimg, 256, 256, 256 * 3,
                                affine,
                                ART_FILTER_NEAREST, alphagamma);
                art_rgb_rgba_affine (buf + (j * 512 + i) * BYTES_PP,
                                     i, j, i + TILE_SIZE, j + TILE_SIZE,
                                     512 * BYTES_PP,
                                     (art_u8 *)rgbaimg, 256, 256, 256 * 4,
                                     affine2,
                                     ART_FILTER_NEAREST, alphagamma);
                art_rgb_bitmap_affine (buf + (j * 512 + i) * BYTES_PP,
                                       i, j, i + TILE_SIZE, j + TILE_SIZE,
                                       512 * BYTES_PP,
                                       (art_u8 *)bitimg, 16, 16, 2,
                                       0xffff00ff,
                                       affine3,
                                       ART_FILTER_NEAREST, alphagamma);
#else
                art_gray_svp_aa (svp, i, j, i + TILE_SIZE, j + TILE_SIZE,
                                 buf + (j * 512 + i) * BYTES_PP, 512 * BYTES_PP);
#endif
            }

    art_svp_free (svp2);
    art_svp_free (svp3);
    art_svp_free (svp);

#if 1
    fwrite (buf, 1, 512 * 512 * BYTES_PP, stdout);
#endif
}