static void clear_curve_data(stp_curve_t *curve) { if (curve->seq) stp_sequence_set_size(curve->seq, 0); curve->recompute_interval = 0; invalidate_auxiliary_data(curve); }
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); }
static int stpi_curve_set_points(stp_curve_t *curve, size_t points) { if (points < 2) return 0; if (points > curve_point_limit || (curve->wrap_mode == STP_CURVE_WRAP_AROUND && points > curve_point_limit - 1)) return 0; clear_curve_data(curve); if (curve->wrap_mode == STP_CURVE_WRAP_AROUND) points++; if (curve->piecewise) points *= 2; if ((stp_sequence_set_size(curve->seq, points)) == 0) return 0; return 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); }