Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/main/curve.c File Reference

#include <gimp-print/gimp-print.h>
#include "gimp-print-internal.h"
#include <gimp-print/gimp-print-intl-internal.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

Go to the source code of this file.

Data Structures

struct  stp_curve

Defines

#define inline
#define DEFINE_DATA_SETTER(t, name)
#define DEFINE_DATA_ACCESSOR(t, name)

Functions

void check_curve (const stp_curve_t *curve)
size_t get_real_point_count (const stp_curve_t *curve)
size_t get_point_count (const stp_curve_t *curve)
void invalidate_auxiliary_data (stp_curve_t *curve)
void clear_curve_data (stp_curve_t *curve)
void compute_linear_deltas (stp_curve_t *curve)
void compute_spline_deltas_piecewise (stp_curve_t *curve)
void compute_spline_deltas_dense (stp_curve_t *curve)
void compute_spline_deltas (stp_curve_t *curve)
void compute_intervals (stp_curve_t *curve)
int stpi_curve_set_points (stp_curve_t *curve, size_t points)
void stpi_curve_ctor (stp_curve_t *curve, stp_curve_wrap_mode_t wrap_mode)
stp_curve_tstp_curve_create (stp_curve_wrap_mode_t wrap_mode)
 Create a new curve.

void curve_dtor (stp_curve_t *curve)
void stp_curve_destroy (stp_curve_t *curve)
 Destroy an curve.

void stp_curve_copy (stp_curve_t *dest, const stp_curve_t *source)
 Copy an curve.

stp_curve_tstp_curve_create_copy (const stp_curve_t *curve)
 Copy and allocate an curve.

int stp_curve_set_bounds (stp_curve_t *curve, double low, double high)
 Set the lower and upper bounds on a curve.

void stp_curve_get_bounds (const stp_curve_t *curve, double *low, double *high)
 Get the lower and upper bounds on a curve.

void stp_curve_get_range (const stp_curve_t *curve, double *low, double *high)
size_t stp_curve_count_points (const stp_curve_t *curve)
 Get the number of allocated points in the curve.

stp_curve_wrap_mode_t stp_curve_get_wrap (const stp_curve_t *curve)
 Get the wrapping mode.

int stp_curve_is_piecewise (const stp_curve_t *curve)
 Determine whether the curve is piecewise.

int stp_curve_set_interpolation_type (stp_curve_t *curve, stp_curve_type_t itype)
 Set the curve interpolation type.

stp_curve_type_t stp_curve_get_interpolation_type (const stp_curve_t *curve)
 Get the curve interpolation type.

int stp_curve_set_gamma (stp_curve_t *curve, double fgamma)
 Set the gamma of a curve.

double stp_curve_get_gamma (const stp_curve_t *curve)
 Get the gamma value of the curve.

int stp_curve_set_data (stp_curve_t *curve, size_t count, const double *data)
 Set all data points of the curve.

int stp_curve_set_data_points (stp_curve_t *curve, size_t count, const stp_curve_point_t *data)
 Set all data points of the curve.

const double * stp_curve_get_data (const stp_curve_t *curve, size_t *count)
 Get a pointer to the curve's raw data.

const stp_curve_point_tstp_curve_get_data_points (const stp_curve_t *curve, size_t *count)
 Get a pointer to the curve's raw data as points.

const double * stpi_curve_get_data_internal (const stp_curve_t *curve, size_t *count)
stp_curve_tstp_curve_get_subrange (const stp_curve_t *curve, size_t start, size_t count)
 Get a curve containing a subrange of data.

int stp_curve_set_subrange (stp_curve_t *curve, const stp_curve_t *range, size_t start)
int stp_curve_set_point (stp_curve_t *curve, size_t where, double data)
 Set a point along the curve.

int stp_curve_get_point (const stp_curve_t *curve, size_t where, double *data)
 Get a point along the curve.

const stp_sequence_tstp_curve_get_sequence (const stp_curve_t *curve)
 Get the underlying stp_sequence_t data structure which stp_curve_t is derived from.

int stp_curve_rescale (stp_curve_t *curve, double scale, stp_curve_compose_t mode, stp_curve_bounds_t bounds_mode)
 Rescale a curve (multiply all points by a scaling constant).

int stpi_curve_check_parameters (stp_curve_t *curve, size_t points)
double interpolate_gamma_internal (const stp_curve_t *curve, double where)
double do_interpolate_spline (double low, double high, double frac, double interval_low, double interval_high, double x_interval)
double interpolate_point_internal (stp_curve_t *curve, double where)
int stp_curve_interpolate_value (const stp_curve_t *curve, double where, double *result)
 Interpolate a point along the curve.

int stp_curve_resample (stp_curve_t *curve, size_t points)
 Resample a curve (change the number of points).

unsigned gcd (unsigned a, unsigned b)
unsigned lcm (unsigned a, unsigned b)
int create_gamma_curve (stp_curve_t **retval, double lo, double hi, double fgamma, int points)
int interpolate_points (stp_curve_t *a, stp_curve_t *b, stp_curve_compose_t mode, int points, double *tmp_data)
int stp_curve_compose (stp_curve_t **retval, stp_curve_t *a, stp_curve_t *b, stp_curve_compose_t mode, int points)
 Compose two curves, creating a third curve.

stp_curve_tstp_curve_create_from_xmltree (stp_mxml_node_t *curve)
stp_mxml_node_tstp_xmltree_create_from_curve (const stp_curve_t *curve)
stp_mxml_node_txmldoc_create_from_curve (const stp_curve_t *curve)
int curve_whitespace_callback (stp_mxml_node_t *node, int where)
int stp_curve_write (FILE *file, const stp_curve_t *curve)
 Write a curve to a file.

char * stp_curve_write_string (const stp_curve_t *curve)
 Write a curve to a string.

stp_curve_txml_doc_get_curve (stp_mxml_node_t *doc)
stp_curve_tstp_curve_create_from_file (const char *file)
 Create a curve from a stream.

stp_curve_tstp_curve_create_from_stream (FILE *fp)
 Create a curve from a stream.

stp_curve_tstp_curve_create_from_string (const char *string)
 Create a curve from a string.


Variables

const int curve_point_limit = 1048576
const char *const  stpi_curve_type_names []
const int stpi_curve_type_count
const char *const  stpi_wrap_mode_names []
const int stpi_wrap_mode_count


Define Documentation

#define DEFINE_DATA_ACCESSOR t,
name   ) 
 

Value:

const t *                                                               \
stp_curve_get_##name##_data(const stp_curve_t *curve, size_t *count)    \
{                                                                       \
  if (curve->piecewise)                                                 \
    return 0;                                                           \
  return stp_sequence_get_##name##_data(curve->seq, count);             \
}

Definition at line 764 of file curve.c.

#define DEFINE_DATA_SETTER t,
name   ) 
 

Value:

int                                                                        \
stp_curve_set_##name##_data(stp_curve_t *curve, size_t count, const t *data) \
{                                                                          \
  double *tmp_data;                                                        \
  size_t i;                                                                \
  int status;                                                              \
  size_t real_count = count;                                               \
                                                                           \
  check_curve(curve);                                                      \
  if (count < 2)                                                           \
    return 0;                                                              \
  if (curve->wrap_mode == STP_CURVE_WRAP_AROUND)                           \
    real_count++;                                                          \
  if (real_count > curve_point_limit)                                      \
    return 0;                                                              \
  tmp_data = stp_malloc(count * sizeof(double));                           \
  for (i = 0; i < count; i++)                                              \
    tmp_data[i] = (double) data[i];                                        \
  status = stp_curve_set_data(curve, count, tmp_data);                     \
  stp_free(tmp_data);                                                      \
  return status;                                                           \
 }

Definition at line 731 of file curve.c.

#define inline
 

Definition at line 46 of file curve.c.


Function Documentation

void check_curve const stp_curve_t curve  )  [static]
 

Definition at line 85 of file curve.c.

References stp_curve::seq, stp_abort(), stp_curve_t, and stp_erprintf().

Referenced by curve_dtor(), stp_curve_copy(), stp_curve_count_points(), stp_curve_create_copy(), stp_curve_get_bounds(), stp_curve_get_data(), stp_curve_get_data_points(), stp_curve_get_gamma(), stp_curve_get_interpolation_type(), stp_curve_get_point(), stp_curve_get_range(), stp_curve_get_sequence(), stp_curve_get_wrap(), stp_curve_is_piecewise(), stp_curve_rescale(), stp_curve_set_bounds(), stp_curve_set_data(), stp_curve_set_data_points(), stp_curve_set_gamma(), stp_curve_set_interpolation_type(), stp_curve_set_point(), stp_curve_set_subrange(), and stpi_curve_get_data_internal().

void clear_curve_data stp_curve_t curve  )  [static]
 

Definition at line 133 of file curve.c.

References invalidate_auxiliary_data(), stp_curve::recompute_interval, stp_curve::seq, stp_curve_t, and stp_sequence_set_size().

Referenced by curve_dtor(), stp_curve_set_gamma(), and stpi_curve_set_points().

void compute_intervals stp_curve_t curve  )  [static]
 

Definition at line 359 of file curve.c.

References compute_linear_deltas(), compute_spline_deltas(), stp_curve::curve_type, stp_curve::interval, stp_curve::recompute_interval, stp_curve::seq, stp_curve_t, STP_CURVE_TYPE_LINEAR, STP_CURVE_TYPE_SPLINE, stp_free(), and stp_sequence_get_size().

Referenced by interpolate_point_internal(), and stp_curve_resample().

void compute_linear_deltas stp_curve_t curve  )  [static]
 

Definition at line 142 of file curve.c.

References get_real_point_count(), stp_curve::interval, stp_curve::piecewise, stp_curve::seq, stp_curve_t, stp_malloc(), and stp_sequence_get_data().

Referenced by compute_intervals().

void compute_spline_deltas stp_curve_t curve  )  [static]
 

Definition at line 345 of file curve.c.

References compute_spline_deltas_dense(), compute_spline_deltas_piecewise(), stp_curve::piecewise, and stp_curve_t.

Referenced by compute_intervals().

void compute_spline_deltas_dense stp_curve_t curve  )  [static]
 

Definition at line 262 of file curve.c.

References get_point_count(), stp_curve::interval, stp_curve::seq, stp_curve_t, STP_CURVE_WRAP_AROUND, stp_free(), stp_malloc(), stp_sequence_get_data(), and stp_curve::wrap_mode.

Referenced by compute_spline_deltas().

void compute_spline_deltas_piecewise stp_curve_t curve  )  [static]
 

Definition at line 171 of file curve.c.

References get_point_count(), stp_curve::interval, stp_curve::seq, stp_curve_t, STP_CURVE_WRAP_AROUND, STP_DBG_CURVE, stp_deprintf(), stp_free(), stp_malloc(), stp_sequence_get_data(), stp_curve::wrap_mode, stp_curve_point_t::x, and stp_curve_point_t::y.

Referenced by compute_spline_deltas().

int create_gamma_curve stp_curve_t **  retval,
double  lo,
double  hi,
double  fgamma,
int  points
[static]
 

Definition at line 1263 of file curve.c.

References stp_curve_create(), stp_curve_destroy(), stp_curve_resample(), stp_curve_set_bounds(), stp_curve_set_gamma(), and STP_CURVE_WRAP_NONE.

Referenced by stp_curve_compose().

void curve_dtor stp_curve_t curve  )  [static]
 

Definition at line 431 of file curve.c.

References check_curve(), clear_curve_data(), stp_curve::curve_type, stp_curve::seq, stp_curve_t, and stp_sequence_destroy().

Referenced by stp_curve_copy(), and stp_curve_destroy().

int curve_whitespace_callback stp_mxml_node_t node,
int  where
[static]
 

Definition at line 1697 of file curve.c.

References stp_mxml_value_u::element, stp_mxml_value_s::name, STP_MXML_ELEMENT, stp_mxml_node_t, STP_MXML_WS_AFTER_CLOSE, STP_MXML_WS_AFTER_OPEN, STP_MXML_WS_BEFORE_CLOSE, STP_MXML_WS_BEFORE_OPEN, stp_mxmlElementGetAttr(), stp_mxml_node_s::type, and stp_mxml_node_s::value.

Referenced by stp_curve_write(), and stp_curve_write_string().

double do_interpolate_spline double  low,
double  high,
double  frac,
double  interval_low,
double  interval_high,
double  x_interval
[inline, static]
 

Definition at line 1022 of file curve.c.

Referenced by interpolate_point_internal(), and stp_curve_resample().

unsigned gcd unsigned  a,
unsigned  b
[static]
 

Definition at line 1226 of file curve.c.

size_t get_point_count const stp_curve_t curve  )  [static]
 

Definition at line 117 of file curve.c.

References get_real_point_count(), stp_curve_t, STP_CURVE_WRAP_AROUND, and stp_curve::wrap_mode.

Referenced by compute_spline_deltas_dense(), compute_spline_deltas_piecewise(), interpolate_point_internal(), stp_curve_count_points(), stp_curve_get_data(), stp_curve_get_data_points(), stp_curve_get_point(), stp_curve_rescale(), stp_curve_set_point(), and stpi_curve_get_data_internal().

size_t get_real_point_count const stp_curve_t curve  )  [static]
 

Definition at line 103 of file curve.c.

References stp_curve::piecewise, stp_curve::seq, stp_curve_t, and stp_sequence_get_size().

Referenced by compute_linear_deltas(), get_point_count(), interpolate_gamma_internal(), stp_curve_interpolate_value(), and stp_curve_rescale().

double interpolate_gamma_internal const stp_curve_t curve,
double  where
[inline, static]
 

Definition at line 999 of file curve.c.

References stp_curve::gamma, get_real_point_count(), stp_curve::seq, stp_curve_t, STP_DBG_CURVE, stp_deprintf(), and stp_sequence_get_bounds().

Referenced by stp_curve_interpolate_value().

double interpolate_point_internal stp_curve_t curve,
double  where
[inline, static]
 

Definition at line 1036 of file curve.c.

References compute_intervals(), stp_curve::curve_type, do_interpolate_spline(), get_point_count(), stp_curve::interval, stp_curve::recompute_interval, stp_curve::seq, stp_curve_t, STP_CURVE_TYPE_LINEAR, stp_sequence_get_bounds(), and stp_sequence_get_point().

int interpolate_points stp_curve_t a,
stp_curve_t b,
stp_curve_compose_t  mode,
int  points,
double *  tmp_data
[static]
 

Definition at line 1277 of file curve.c.

References STP_CURVE_COMPOSE_ADD, stp_curve_count_points(), stp_curve_interpolate_value(), STP_DBG_CURVE_ERRORS, and stp_deprintf().

Referenced by stp_curve_compose().

void invalidate_auxiliary_data stp_curve_t curve  )  [static]
 

Definition at line 127 of file curve.c.

References stp_curve::interval, stp_curve_t, and STP_SAFE_FREE.

Referenced by clear_curve_data(), stp_curve_rescale(), stp_curve_set_point(), and stp_curve_set_subrange().

unsigned lcm unsigned  a,
unsigned  b
[static]
 

Definition at line 1246 of file curve.c.

References curve_point_limit, and gcd().

stp_curve_t* stp_curve_create_from_xmltree stp_mxml_node_t curve  ) 
 

Definition at line 1408 of file curve.c.

References stp_curve_count_points(), stp_curve_create(), stp_curve_destroy(), stp_curve_set_bounds(), stp_curve_set_data(), stp_curve_set_data_points(), stp_curve_set_gamma(), stp_curve_set_interpolation_type(), stp_curve_t, STP_CURVE_TYPE_LINEAR, STP_CURVE_TYPE_SPLINE, stp_curve_type_t, STP_CURVE_WRAP_AROUND, stp_curve_wrap_mode_t, STP_CURVE_WRAP_NONE, STP_DBG_CURVE_ERRORS, stp_deprintf(), STP_MXML_DESCEND, stp_mxml_node_t, stp_mxmlElementGetAttr(), stp_mxmlFindElement(), stp_sequence_create_from_xmltree(), stp_sequence_destroy(), stp_sequence_get_bounds(), stp_sequence_get_data(), stp_sequence_t, stp_xml_exit(), stp_xml_init(), stp_xmlstrtod(), and stpi_curve_check_parameters().

Referenced by stp_printer_create_from_xmltree(), and xml_doc_get_curve().

stp_mxml_node_t* stp_xmltree_create_from_curve const stp_curve_t curve  ) 
 

Definition at line 1572 of file curve.c.

References stp_curve::piecewise, stp_asprintf(), stp_curve_get_bounds(), stp_curve_get_gamma(), stp_curve_get_interpolation_type(), stp_curve_get_wrap(), stp_curve_type_t, stp_curve_wrap_mode_t, STP_CURVE_WRAP_NONE, STP_DBG_CURVE_ERRORS, stp_deprintf(), stp_free(), STP_MXML_ADD_AFTER, stp_mxml_node_t, stp_mxmlAdd(), stp_mxmlDelete(), stp_mxmlElementSetAttr(), stp_mxmlNewElement(), stp_sequence_create(), stp_sequence_destroy(), stp_sequence_set_bounds(), stp_sequence_set_data(), stp_sequence_set_size(), stp_sequence_t, stp_xml_exit(), stp_xml_init(), stp_xmltree_create_from_sequence(), stpi_curve_get_data_internal(), stpi_curve_type_names, and stpi_wrap_mode_names.

Referenced by xmldoc_create_from_curve().

int stpi_curve_check_parameters stp_curve_t curve,
size_t  points
[static]
 

Definition at line 979 of file curve.c.

References stp_curve::gamma, stp_curve::seq, stp_curve_t, STP_DBG_CURVE_ERRORS, stp_deprintf(), stp_sequence_get_bounds(), and stp_curve::wrap_mode.

Referenced by stp_curve_create_from_xmltree().

void stpi_curve_ctor stp_curve_t curve,
stp_curve_wrap_mode_t  wrap_mode
[static]
 

Definition at line 404 of file curve.c.

References stp_curve::curve_type, stp_curve::piecewise, stp_curve::seq, stp_curve_t, STP_CURVE_TYPE_LINEAR, STP_CURVE_WRAP_NONE, stp_sequence_create(), stp_sequence_set_bounds(), stp_sequence_set_point(), stpi_curve_set_points(), and stp_curve::wrap_mode.

Referenced by stp_curve_create().

const double* stpi_curve_get_data_internal const stp_curve_t curve,
size_t *  count
[static]
 

Definition at line 717 of file curve.c.

References check_curve(), get_point_count(), stp_curve::piecewise, stp_curve::seq, stp_curve_t, and stp_sequence_get_data().

Referenced by stp_xmltree_create_from_curve().

int stpi_curve_set_points stp_curve_t curve,
size_t  points
[static]
 

Definition at line 382 of file curve.c.

References clear_curve_data(), curve_point_limit, stp_curve::piecewise, stp_curve::seq, stp_curve_t, STP_CURVE_WRAP_AROUND, stp_sequence_set_size(), and stp_curve::wrap_mode.

Referenced by stp_curve_rescale(), stp_curve_set_data(), stp_curve_set_data_points(), and stpi_curve_ctor().

stp_curve_t* xml_doc_get_curve stp_mxml_node_t doc  )  [static]
 

Definition at line 1801 of file curve.c.

References stp_mxml_node_s::child, stp_curve_create_from_xmltree(), stp_curve_t, STP_DBG_CURVE_ERRORS, stp_deprintf(), stp_mxml_node_t, and stp_xml_get_node().

Referenced by stp_curve_create_from_file(), stp_curve_create_from_stream(), and stp_curve_create_from_string().

stp_mxml_node_t* xmldoc_create_from_curve const stp_curve_t curve  )  [static]
 

Definition at line 1660 of file curve.c.

References stp_mxml_node_s::child, STP_DBG_CURVE_ERRORS, stp_deprintf(), STP_MXML_ADD_AFTER, stp_mxml_node_t, stp_mxmlAdd(), stp_mxmlDelete(), stp_xmldoc_create_generic(), and stp_xmltree_create_from_curve().

Referenced by stp_curve_write(), and stp_curve_write_string().


Variable Documentation

const int curve_point_limit = 1048576 [static]
 

Definition at line 48 of file curve.c.

Referenced by lcm(), stp_curve_compose(), stp_curve_set_data(), stp_curve_set_data_points(), and stpi_curve_set_points().

const int stpi_curve_type_count [static]
 

Initial value:

(sizeof(stpi_curve_type_names) / sizeof(const char *))

Definition at line 69 of file curve.c.

Referenced by stp_curve_set_interpolation_type().

const char* const stpi_curve_type_names[] [static]
 

Initial value:

  {
    "linear",
    "spline",
  }

Definition at line 63 of file curve.c.

Referenced by stp_xmltree_create_from_curve().

const int stpi_wrap_mode_count [static]
 

Initial value:

(sizeof(stpi_wrap_mode_names) / sizeof(const char *))

Definition at line 78 of file curve.c.

const char* const stpi_wrap_mode_names[] [static]
 

Initial value:

  {
    "nowrap",
    "wrap"
  }

Definition at line 72 of file curve.c.

Referenced by stp_xmltree_create_from_curve().


Generated on Wed Aug 25 07:56:15 2004 for libgimpprint API Reference by doxygen 1.3.6