Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

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 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 (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_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.

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

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 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)    \
{                                                                       \
  return stp_sequence_get_##name##_data(curve->seq, count);             \
}

Definition at line 525 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 492 of file curve.c.


Function Documentation

void check_curve const stp_curve_t   curve [static]
 

Definition at line 79 of file curve.c.

References stp_curve::seq, stp_abort(), 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_gamma(), stp_curve_get_interpolation_type(), stp_curve_get_point(), stp_curve_get_range(), stp_curve_get_sequence(), stp_curve_get_wrap(), stp_curve_interpolate_value(), stp_curve_resample(), stp_curve_rescale(), stp_curve_set_bounds(), stp_curve_set_data(), stp_curve_set_gamma(), stp_curve_set_interpolation_type(), stp_curve_set_point(), and stp_curve_set_subrange().

void clear_curve_data stp_curve_t   curve [static]
 

Definition at line 130 of file curve.c.

References invalidate_auxiliary_data(), stp_curve::recompute_interval, stp_curve::seq, 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 251 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_TYPE_LINEAR, STP_CURVE_TYPE_SPLINE, stp_free(), and stp_sequence_get_size().

Referenced by interpolate_point_internal().

void compute_linear_deltas stp_curve_t   curve [static]
 

Definition at line 139 of file curve.c.

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

Referenced by compute_intervals().

void compute_spline_deltas stp_curve_t   curve [static]
 

Definition at line 163 of file curve.c.

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

Referenced by compute_intervals().

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

Definition at line 925 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 320 of file curve.c.

References check_curve(), clear_curve_data(), stp_curve::curve_type, stp_curve::seq, 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 1305 of file curve.c.

References stp_mxml_value_u::element, stp_mxml_value_s::name, STP_MXML_ELEMENT, 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().

unsigned gcd unsigned    a,
unsigned    b
[static]
 

Definition at line 888 of file curve.c.

size_t get_point_count const stp_curve_t   curve [static]
 

Definition at line 108 of file curve.c.

References stp_curve::seq, STP_CURVE_WRAP_AROUND, stp_sequence_get_size(), and stp_curve::wrap_mode.

Referenced by compute_spline_deltas(), interpolate_point_internal(), stp_curve_count_points(), stp_curve_get_data(), stp_curve_get_point(), stp_curve_resample(), stp_curve_rescale(), and stp_curve_set_point().

size_t get_real_point_count const stp_curve_t   curve [static]
 

Definition at line 97 of file curve.c.

References stp_curve::seq, and stp_sequence_get_size().

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

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

Definition at line 741 of file curve.c.

References stp_curve::gamma, get_real_point_count(), stp_curve::seq, stp_erprintf(), and stp_sequence_get_bounds().

Referenced by stp_curve_interpolate_value(), and stp_curve_resample().

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

Definition at line 765 of file curve.c.

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

Referenced by stp_curve_interpolate_value(), and stp_curve_resample().

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 939 of file curve.c.

References STP_CURVE_COMPOSE_ADD, stp_curve_compose_t, stp_curve_count_points(), stp_curve_interpolate_value(), and stp_erprintf().

Referenced by stp_curve_compose().

void invalidate_auxiliary_data stp_curve_t   curve [static]
 

Definition at line 120 of file curve.c.

References stp_curve::interval, and stp_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 908 of file curve.c.

References curve_point_limit, and gcd().

stp_curve_t* stp_curve_create_from_xmltree stp_mxml_node_t   curve [static]
 

Definition at line 1052 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_gamma(), stp_curve_set_interpolation_type(), 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_erprintf(), STP_MXML_DESCEND, stp_mxmlElementGetAttr(), stp_mxmlFindElement(), stp_sequence_create_from_xmltree(), stp_sequence_destroy(), stp_sequence_get_bounds(), stp_sequence_get_data(), stp_xml_exit(), stp_xml_init(), stp_xmlstrtod(), and stpi_curve_check_parameters().

Referenced by xml_doc_get_curve().

stp_mxml_node_t* stp_xmltree_create_from_curve const stp_curve_t   curve [static]
 

Definition at line 1183 of file curve.c.

References stp_asprintf(), stp_curve_get_bounds(), stp_curve_get_data(), 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_erprintf(), stp_free(), STP_MXML_ADD_AFTER, 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_xml_exit(), stp_xml_init(), stp_xmltree_create_from_sequence(), 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 719 of file curve.c.

References stp_curve::gamma, stp_curve::seq, stp_erprintf(), 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 294 of file curve.c.

References stp_curve::curve_type, stp_curve::gamma, stp_curve::recompute_interval, stp_curve::seq, STP_CURVE_TYPE_LINEAR, stp_curve_wrap_mode_t, STP_CURVE_WRAP_NONE, stp_sequence_create(), stp_sequence_set_bounds(), stpi_curve_set_points(), and stp_curve::wrap_mode.

Referenced by stp_curve_create().

int stpi_curve_set_points stp_curve_t   curve,
size_t    points
[static]
 

Definition at line 274 of file curve.c.

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

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

stp_curve_t* xml_doc_get_curve stp_mxml_node_t   doc [static]
 

Definition at line 1409 of file curve.c.

References stp_mxml_node_s::child, stp_curve_create_from_xmltree(), stp_erprintf(), 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 1271 of file curve.c.

References stp_mxml_node_s::child, stp_erprintf(), STP_MXML_ADD_AFTER, 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 43 of file curve.c.

Referenced by lcm(), stp_curve_compose(), stp_curve_resample(), stp_curve_set_data(), 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 63 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 57 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 72 of file curve.c.

const char* const stpi_wrap_mode_names[] [static]
 

Initial value:

  {
    "nowrap",
    "wrap"
  }

Definition at line 66 of file curve.c.

Referenced by stp_xmltree_create_from_curve().


Generated on Wed May 12 20:21:35 2004 for libgimpprint API Reference by doxygen1.2.17