Пример #1
0
static void
gimp_brush_generated_transform_size (GimpBrush *gbrush,
                                     gdouble    scale,
                                     gdouble    aspect_ratio,
                                     gdouble    angle,
                                     gint      *width,
                                     gint      *height)
{
  GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (gbrush);
  gdouble             ratio;

  ratio = fabs (aspect_ratio) * 19.0 / 20.0 + 1.0;
  ratio = MIN (ratio, 20);

  /* Since generated brushes are symmetric they don't have aspect
   * ratios < 1.0. it's the same as rotating by 90 degrees and 1 /
   * ratio, so we fix the input for this case.
   */
  if (aspect_ratio < 0.0)
    angle = angle + 0.25;

  angle *= 360;

  if (angle < 0.0)
    angle = -1.0 * fmod (angle, 180.0);
  else if (angle > 180.0)
    angle = fmod (angle, 180.0);

  gimp_brush_generated_get_size (brush,
                                 brush->shape,
                                 brush->radius * scale,
                                 brush->spikes,
                                 brush->hardness,
                                 ratio,
                                 angle,
                                 width, height,
                                 NULL, NULL, NULL, NULL);
}
Пример #2
0
static void
gimp_brush_generated_transform_size (GimpBrush *gbrush,
                                     gdouble    scale,
                                     gdouble    aspect_ratio,
                                     gdouble    angle,
                                     gint      *width,
                                     gint      *height)
{
  GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (gbrush);
  gdouble             ratio;

  if (aspect_ratio == 0.0)
    {
      ratio = brush->aspect_ratio;
    }
  else
    {
      ratio = MIN (fabs (aspect_ratio) + 1, 20);
      /* Since generated brushes are symmetric the dont have input
       * for aspect ratios  < 1.0. its same as rotate by 90 degrees and
       * 1 / ratio. So we fix the input up for this case.   */

      if (aspect_ratio < 0.0)
        {
          angle = angle + 0.25;
        }
    }

  gimp_brush_generated_get_size (brush,
                                 brush->shape,
                                 brush->radius * scale,
                                 brush->spikes,
                                 brush->hardness,
                                 ratio,
                                 (brush->angle + 360 * angle),
                                 width, height,
                                 NULL, NULL, NULL, NULL);
}
Пример #3
0
static GimpTempBuf *
gimp_brush_generated_calc (GimpBrushGenerated      *brush,
                           GimpBrushGeneratedShape  shape,
                           gfloat                   radius,
                           gint                     spikes,
                           gfloat                   hardness,
                           gfloat                   aspect_ratio,
                           gfloat                   angle,
                           GimpVector2             *xaxis,
                           GimpVector2             *yaxis)
{
  guchar      *centerp;
  guchar      *lookup;
  guchar       a;
  gint         x, y;
  gdouble      c, s, cs, ss;
  GimpVector2  x_axis;
  GimpVector2  y_axis;
  GimpTempBuf *mask;
  gint         width;
  gint         height;
  gint         half_width;
  gint         half_height;

  gimp_brush_generated_get_size (brush,
                                 shape,
                                 radius,
                                 spikes,
                                 hardness,
                                 aspect_ratio,
                                 angle,
                                 &width, &height,
                                 &s, &c, &x_axis, &y_axis);

  mask = gimp_temp_buf_new (width, height,
                            babl_format ("Y u8"));

  half_width  = width  / 2;
  half_height = height / 2;

  centerp = gimp_temp_buf_get_data (mask) +
            half_height * width + half_width;

  lookup = gimp_brush_generated_calc_lut (radius, hardness);

  cs = cos (- 2 * G_PI / spikes);
  ss = sin (- 2 * G_PI / spikes);

  /* for an even number of spikes compute one half and mirror it */
  for (y = ((spikes % 2) ? -half_height : 0); y <= half_height; y++)
    {
      for (x = -half_width; x <= half_width; x++)
        {
          gdouble d  = 0;
          gdouble tx = c * x - s * y;
          gdouble ty = fabs (s * x + c * y);

          if (spikes > 2)
            {
              gdouble angle = atan2 (ty, tx);

              while (angle > G_PI / spikes)
                {
                  gdouble sx = tx;
                  gdouble sy = ty;

                  tx = cs * sx - ss * sy;
                  ty = ss * sx + cs * sy;

                  angle -= 2 * G_PI / spikes;
                }
            }

          ty *= aspect_ratio;

          switch (shape)
            {
            case GIMP_BRUSH_GENERATED_CIRCLE:
              d = sqrt (SQR (tx) + SQR (ty));
              break;
            case GIMP_BRUSH_GENERATED_SQUARE:
              d = MAX (fabs (tx), fabs (ty));
              break;
            case GIMP_BRUSH_GENERATED_DIAMOND:
              d = fabs (tx) + fabs (ty);
              break;
            }

          if (d < radius + 1)
            a = lookup[(gint) RINT (d * OVERSAMPLING)];
          else
            a = 0;

          centerp[y * width + x] = a;

          if (spikes % 2 == 0)
            centerp[-1 * y * width - x] = a;
        }
    }

  g_free (lookup);

  if (xaxis)
    *xaxis = x_axis;

  if (yaxis)
    *yaxis = y_axis;

  return mask;
}