Example #1
0
static void
test_dist (void)
{
    ArtVpath *vpath;
    ArtSVP *svp;
    art_u8 buf[512 * 512 * BYTES_PP];
    int x, y;
    int ix;
    double dist;
    int wind;

    vpath = randstar (20);
#ifdef NO_STROKE
    svp = art_svp_from_vpath (vpath);
#else
    svp = art_svp_vpath_stroke (vpath,
                                ART_PATH_STROKE_JOIN_MITER,
                                ART_PATH_STROKE_CAP_BUTT,
                                15,
                                4,
                                0.5);
#endif

    art_rgb_svp_aa (svp, 0, 0, 512, 512,
                    0xffe0a0, 0x100040,
                    buf, 512 * BYTES_PP,
                    NULL);

    ix = 0;
    for (y = 0; y < 512; y++)
    {
        for (x = 0; x < 512; x++)
        {
            wind = art_svp_point_wind (svp, x, y);
            buf[ix] = 204 - wind * 51;
            dist = art_svp_point_dist (svp, x, y);
            if (((x | y) & 0x3f) == 0)
            {
                fprintf (stderr, "%d,%d: %f\n", x, y, dist);
            }
            buf[ix + 1] = 255 - dist;
            ix += 3;
        }
    }

    printf ("P6\n512 512\n255\n");
    fwrite (buf, 1, 512 * 512 * BYTES_PP, stdout);

}
Example #2
0
gfxpoly_t* gfxpoly_from_stroke(gfxline_t*line, gfxcoord_t width, gfx_capType cap_style, gfx_joinType joint_style, double miterLimit, double gridsize)
{
    ArtVpath* vec = gfxline_to_ArtVpath(line, 0);
    msg("<verbose> Casting gfxline of %d segments to a stroke-polygon", gfxline_len(line));

    ArtVpath* vec2 = art_vpath_perturb(vec);
    free(vec);
    vec = vec2;

    ArtSVP *svp = art_svp_vpath_stroke (vec,
			(joint_style==gfx_joinMiter)?ART_PATH_STROKE_JOIN_MITER:
			((joint_style==gfx_joinRound)?ART_PATH_STROKE_JOIN_ROUND:
			 ((joint_style==gfx_joinBevel)?ART_PATH_STROKE_JOIN_BEVEL:ART_PATH_STROKE_JOIN_BEVEL)),
			(cap_style==gfx_capButt)?ART_PATH_STROKE_CAP_BUTT:
			((cap_style==gfx_capRound)?ART_PATH_STROKE_CAP_ROUND:
			 ((cap_style==gfx_capSquare)?ART_PATH_STROKE_CAP_SQUARE:ART_PATH_STROKE_CAP_SQUARE)),
			width, //line_width
			miterLimit, //miter_limit
			0.05 //flatness
			);
    free(vec);
    return (gfxpoly_t*)svp;
}
Example #3
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
}
Example #4
0
void art_draw_poly(art_buffer_p buffer, art_context_p context, int filled,
		   float *x, float *y, int n, int closed)
{
  ArtVpath *vec, *vec2;
  ArtSVP *svp;
  double dash_data[2];
  ArtVpathDash dash;
  ArtDRect drect;
  ArtIRect irect;
  int i, mark = 0;

  vec = art_new(ArtVpath, n + 1 + closed);
  for(i = 0; i < n; i++) {
    vec[mark].code = i ? ART_LINETO : ART_MOVETO;
    if(i == 0 || i == n - 1 || hypot(x[i] - vec[mark - 1].x,
				     (buffer->height - y[i]) - 
				     vec[mark - 1].y) > 1.0) {
      vec[mark].x = x[i];
      vec[mark].y = buffer->height - y[i];
      mark++;
    }
  }
  n = mark;
  if(closed) {
    vec[n].code = ART_LINETO;
    vec[n].x = vec[0].x;
    vec[n].y = vec[0].y;
  }
  vec[n + closed].code = ART_END;
  vec[n + closed].x = 0;
  vec[n + closed].y = 0;
  if(context->current_dash_on > 0) {
    dash.offset = 0;
    dash_data[0] = context->current_dash_on;
    dash_data[1] = context->current_dash_off;
    dash.n_dash = 2;
    dash.dash = dash_data;
    vec2 = art_vpath_dash(vec, &dash);
    art_free(vec);
    vec = vec2;
  }

  if(filled)
    svp = art_svp_from_vpath(vec);
  else
    svp = art_svp_vpath_stroke(vec, context->current_jointype, 
			       context->current_captype,
			       context->current_linewidth,
			       context->current_miterlimit, 
			       context->current_flatness);
  art_free(vec);

  art_drect_svp(&drect, svp);
  art_drect_to_irect(&irect, &drect);
  if(irect.x1 > buffer->width)
    irect.x1 = buffer->width;
  if(irect.y1 > buffer->height)
    irect.y1 = buffer->height;
  if(irect.x0 < 0)
    irect.x0 = 0;
  if(irect.y0 < 0)
    irect.y0 = 0;
  art_rgb_svp_alpha(svp, irect.x0, irect.y0, irect.x1, irect.y1, 
		    context->current_color,
		    buffer->buffer + (irect.y0 * buffer->width + irect.x0) * 3,
		    buffer->width * 3, NULL);
  art_svp_free(svp);
}