void stp_curve_reverse(stp_curve_t *dest, const stp_curve_t *source) { CHECK_CURVE(dest); CHECK_CURVE(source); curve_dtor(dest); dest->curve_type = source->curve_type; dest->wrap_mode = source->wrap_mode; dest->gamma = source->gamma; if (source->piecewise) { const double *source_data; size_t size; double *new_data; int i; stp_sequence_get_data(source->seq, &size, &source_data); new_data = stp_malloc(sizeof(double) * size); for (i = 0; i < size; i += 2) { int j = size - i - 2; new_data[i] = 1.0 - source_data[j]; new_data[i + 1] = source_data[j + 1]; } dest->seq = stp_sequence_create(); stp_sequence_set_data(dest->seq, size, new_data); stp_free(new_data); } else dest->seq = stp_sequence_create_reverse(source->seq); dest->piecewise = source->piecewise; dest->recompute_interval = 1; }
void stp_array_set_size(stp_array_t *array, int x_size, int y_size) { check_array(array); if (array->data) /* Free old data */ stp_sequence_destroy(array->data); array->x_size = x_size; array->y_size = y_size; array->data = stp_sequence_create(); stp_sequence_set_size(array->data, array->x_size * array->y_size); }
/* * Create a default curve */ static void stpi_curve_ctor(stp_curve_t *curve, stp_curve_wrap_mode_t wrap_mode) { curve->seq = stp_sequence_create(); stp_sequence_set_bounds(curve->seq, 0.0, 1.0); curve->curve_type = STP_CURVE_TYPE_LINEAR; curve->wrap_mode = wrap_mode; curve->piecewise = 0; stpi_curve_set_points(curve, 2); curve->recompute_interval = 1; if (wrap_mode == STP_CURVE_WRAP_NONE) curve->gamma = 1.0; stp_sequence_set_point(curve->seq, 0, 0); stp_sequence_set_point(curve->seq, 1, 1); }
stp_mxml_node_t * stp_xmltree_create_from_curve(const stp_curve_t *curve) /* The curve */ { stp_curve_wrap_mode_t wrapmode; stp_curve_type_t interptype; double gammaval, low, high; stp_sequence_t *seq; char *cgamma; stp_mxml_node_t *curvenode = NULL; stp_mxml_node_t *child = NULL; stp_xml_init(); /* Get curve details */ wrapmode = stp_curve_get_wrap(curve); interptype = stp_curve_get_interpolation_type(curve); gammaval = stp_curve_get_gamma(curve); if (gammaval && wrapmode != STP_CURVE_WRAP_NONE) { stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: " "curve sets gamma and wrap_mode is not STP_CURVE_WRAP_NONE\n"); goto error; } /* Construct the allocated strings required */ stp_asprintf(&cgamma, "%g", gammaval); curvenode = stp_mxmlNewElement(NULL, "curve"); stp_mxmlElementSetAttr(curvenode, "wrap", stpi_wrap_mode_names[wrapmode]); stp_mxmlElementSetAttr(curvenode, "type", stpi_curve_type_names[interptype]); stp_mxmlElementSetAttr(curvenode, "gamma", cgamma); if (curve->piecewise) stp_mxmlElementSetAttr(curvenode, "piecewise", "true"); else stp_mxmlElementSetAttr(curvenode, "piecewise", "false"); stp_free(cgamma); seq = stp_sequence_create(); stp_curve_get_bounds(curve, &low, &high); stp_sequence_set_bounds(seq, low, high); if (gammaval != 0) /* A gamma curve does not require sequence data */ { stp_sequence_set_size(seq, 0); } else { const double *data; size_t count; data = stpi_curve_get_data_internal(curve, &count); stp_sequence_set_data(seq, count, data); } child = stp_xmltree_create_from_sequence(seq); if (seq) { stp_sequence_destroy(seq); seq = NULL; } if (child == NULL) { stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: sequence node is NULL\n"); goto error; } stp_mxmlAdd(curvenode, STP_MXML_ADD_AFTER, NULL, child); stp_xml_exit(); return curvenode; error: stp_deprintf(STP_DBG_CURVE_ERRORS, "stp_xmltree_create_from_curve: error during xmltree creation\n"); if (curvenode) stp_mxmlDelete(curvenode); if (child) stp_mxmlDelete(child); stp_xml_exit(); return NULL; }
static void array_ctor(stp_array_t *array) { array->data = stp_sequence_create(); stp_sequence_set_size(array->data, array->x_size * array->y_size); }