示例#1
0
gboolean
gimp_curve_save (GimpData  *data,
                 GError   **error)
{
  /* GimpCurve *curve; */
  FILE      *file;

  g_return_val_if_fail (GIMP_IS_CURVE (data), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  /* curve = GIMP_CURVE (data); */

  file = g_fopen (gimp_data_get_filename (data), "wb");

  if (! file)
    {
      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_OPEN,
                   _("Could not open '%s' for writing: %s"),
                   gimp_filename_to_utf8 (gimp_data_get_filename (data)),
                   g_strerror (errno));
      return FALSE;
    }

  /* FIXME: write curve */

  fclose (file);

  return TRUE;
}
示例#2
0
/**
 * gimp_curve_is_identity:
 * @curve: a #GimpCurve object
 *
 * If this function returns %TRUE, then the curve maps each value to
 * itself. If it returns %FALSE, then this assumption can not be made.
 *
 * Return value: %TRUE if the curve is an identity mapping, %FALSE otherwise.
 **/
gboolean
gimp_curve_is_identity (GimpCurve *curve)
{
  g_return_val_if_fail (GIMP_IS_CURVE (curve), FALSE);

  return curve->identity;
}
示例#3
0
gint
gimp_curve_get_n_samples (GimpCurve *curve)
{
  g_return_val_if_fail (GIMP_IS_CURVE (curve), 0);

  return curve->n_samples;
}
示例#4
0
void
gimp_curve_delete_point (GimpCurve *curve,
                         gint       point)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (point >= 0 && point < curve->n_points);

  if (point == 0)
    {
      curve->points[0].x = 0.0;
      curve->points[0].y = 0.0;
    }
  else if (point == curve->n_points - 1)
    {
      curve->points[curve->n_points - 1].x = 1.0;
      curve->points[curve->n_points - 1].y = 1.0;
    }
  else
    {
      curve->points[point].x = -1.0;
      curve->points[point].y = -1.0;
    }

  g_object_notify (G_OBJECT (curve), "points");

  gimp_data_dirty (GIMP_DATA (curve));
}
示例#5
0
gint
gimp_curve_get_closest_point (GimpCurve *curve,
                              gdouble    x)
{
  gint    closest_point = 0;
  gdouble distance      = G_MAXDOUBLE;
  gint    i;

  g_return_val_if_fail (GIMP_IS_CURVE (curve), 0);

  for (i = 0; i < curve->n_points; i++)
    {
      if (curve->points[i].x >= 0.0 &&
          fabs (x - curve->points[i].x) < distance)
        {
          distance = fabs (x - curve->points[i].x);
          closest_point = i;
        }
    }

  if (distance > (1.0 / (curve->n_points * 2.0)))
    closest_point = ROUND (x * (gdouble) (curve->n_points - 1));

  return closest_point;
}
示例#6
0
void
gimp_curve_set_n_samples (GimpCurve *curve,
                          gint       n_samples)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (n_samples >= 256);
  g_return_if_fail (n_samples <= 4096);

  if (n_samples != curve->n_samples)
    {
      gint i;

      g_object_freeze_notify (G_OBJECT (curve));

      curve->n_samples = n_samples;
      g_object_notify (G_OBJECT (curve), "n-samples");

      curve->samples = g_renew (gdouble, curve->samples, curve->n_samples);

      for (i = 0; i < curve->n_samples; i++)
        curve->samples[i] = (gdouble) i / (gdouble) (curve->n_samples - 1);

      g_object_notify (G_OBJECT (curve), "samples");

      if (curve->curve_type == GIMP_CURVE_FREE)
        curve->identity = TRUE;

      g_object_thaw_notify (G_OBJECT (curve));
    }
}
示例#7
0
GimpCurveType
gimp_curve_get_curve_type (GimpCurve *curve)
{
  g_return_val_if_fail (GIMP_IS_CURVE (curve), GIMP_CURVE_SMOOTH);

  return curve->curve_type;
}
示例#8
0
void
gimp_curve_get_uchar (GimpCurve *curve,
                      gint       n_samples,
                      guchar    *samples)
{
  gint i;

  g_return_if_fail (GIMP_IS_CURVE (curve));
  /* FIXME: support n_samples != curve->n_samples */
  g_return_if_fail (n_samples == curve->n_samples);
  g_return_if_fail (samples != NULL);

  for (i = 0; i < curve->n_samples; i++)
    samples[i] = curve->samples[i] * 255.999;
}
示例#9
0
void
gimp_curve_set_curve_type (GimpCurve     *curve,
                           GimpCurveType  curve_type)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));

  if (curve->curve_type != curve_type)
    {
      g_object_freeze_notify (G_OBJECT (curve));

      curve->curve_type = curve_type;

      if (curve_type == GIMP_CURVE_SMOOTH)
        {
          gint n_points;
          gint i;

          for (i = 0; i < curve->n_points; i++)
            {
              curve->points[i].x = -1;
              curve->points[i].y = -1;
            }

          /*  pick some points from the curve and make them control
           *  points
           */
          n_points = CLAMP (9, curve->n_points / 2, curve->n_points);

          for (i = 0; i < n_points; i++)
            {
              gint sample = i * (curve->n_samples - 1) / (n_points - 1);
              gint point  = i * (curve->n_points  - 1) / (n_points - 1);

              curve->points[point].x = ((gdouble) sample /
                                        (gdouble) (curve->n_samples - 1));
              curve->points[point].y = curve->samples[sample];
            }

          g_object_notify (G_OBJECT (curve), "points");
        }

      g_object_notify (G_OBJECT (curve), "curve-type");

      g_object_thaw_notify (G_OBJECT (curve));

      gimp_data_dirty (GIMP_DATA (curve));
    }
}
示例#10
0
void
gimp_curve_set_curve (GimpCurve *curve,
                      gdouble    x,
                      gdouble    y)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (x >= 0 && x <= 1.0);
  g_return_if_fail (y >= 0 && y <= 1.0);

  if (curve->curve_type == GIMP_CURVE_SMOOTH)
    return;

  curve->samples[ROUND (x * (gdouble) (curve->n_samples - 1))] = y;

  g_object_notify (G_OBJECT (curve), "samples");

  gimp_data_dirty (GIMP_DATA (curve));
}
示例#11
0
void
gimp_curve_move_point (GimpCurve *curve,
                       gint       point,
                       gdouble    y)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (point >= 0 && point < curve->n_points);
  g_return_if_fail (y >= 0 && y <= 1.0);

  if (curve->curve_type == GIMP_CURVE_FREE)
    return;

  curve->points[point].y = y;

  g_object_notify (G_OBJECT (curve), "points");

  gimp_data_dirty (GIMP_DATA (curve));
}
示例#12
0
void
gimp_curve_get_point (GimpCurve *curve,
                      gint       point,
                      gdouble   *x,
                      gdouble   *y)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (point >= 0 && point < curve->n_points);

  if (curve->curve_type == GIMP_CURVE_FREE)
    {
      if (x) *x = -1.0;
      if (y) *y = -1.0;

      return;
    }

  if (x) *x = curve->points[point].x;
  if (y) *y = curve->points[point].y;
}
示例#13
0
void
gimp_curve_reset (GimpCurve *curve,
                  gboolean   reset_type)
{
  gint i;

  g_return_if_fail (GIMP_IS_CURVE (curve));

  g_object_freeze_notify (G_OBJECT (curve));

  for (i = 0; i < curve->n_samples; i++)
    curve->samples[i] = (gdouble) i / (gdouble) (curve->n_samples - 1);

  g_object_notify (G_OBJECT (curve), "samples");

  curve->points[0].x = 0.0;
  curve->points[0].y = 0.0;

  for (i = 1; i < curve->n_points - 1; i++)
    {
      curve->points[i].x = -1.0;
      curve->points[i].y = -1.0;
    }

  curve->points[curve->n_points - 1].x = 1.0;
  curve->points[curve->n_points - 1].y = 1.0;

  g_object_notify (G_OBJECT (curve), "points");

  if (reset_type)
    {
      curve->curve_type = GIMP_CURVE_SMOOTH;
      g_object_notify (G_OBJECT (curve), "curve-type");
    }

  curve->identity = TRUE;

  g_object_thaw_notify (G_OBJECT (curve));

  gimp_data_dirty (GIMP_DATA (curve));
}
示例#14
0
void
gimp_curve_set_n_points (GimpCurve *curve,
                         gint       n_points)
{
  g_return_if_fail (GIMP_IS_CURVE (curve));
  g_return_if_fail (n_points >= 2);
  g_return_if_fail (n_points <= 1024);

  if (n_points != curve->n_points)
    {
      gint i;

      g_object_freeze_notify (G_OBJECT (curve));

      curve->n_points = n_points;
      g_object_notify (G_OBJECT (curve), "n-points");

      curve->points = g_renew (GimpVector2, curve->points, curve->n_points);

      curve->points[0].x = 0.0;
      curve->points[0].y = 0.0;

      for (i = 1; i < curve->n_points - 1; i++)
        {
          curve->points[i].x = -1.0;
          curve->points[i].y = -1.0;
        }

      curve->points[curve->n_points - 1].x = 1.0;
      curve->points[curve->n_points - 1].y = 1.0;

      g_object_notify (G_OBJECT (curve), "points");

      if (curve->curve_type == GIMP_CURVE_SMOOTH)
        curve->identity = TRUE;

      g_object_thaw_notify (G_OBJECT (curve));
    }
}