Error *context_interpret(Context *context, const char *str) { Value *value; if (context->defining_variable) { // 変数定義 context->defining_variable = FALSE; value = value_new_symbol(str); if (NULL == value) { // エラー (変数名不正など) return error_new(IllegalVariableError, NULL); } map_put(context->map, value_symbol_name(value), value); } else if (str_is_integer(str)) { // 整数 value = value_new_integer_str(str); stack_push(context->stack, value); } else if (0 == strcmp(str, "VARIABLE")) { // 変数定義の開始 context->defining_variable = TRUE; } else if (NULL != (value = context_resolve(context, str))) { // シンボル ForshFunc *func; switch (value->type) { case TYPE_FUNCTION: func = value_function(value); return func(context->stack); default: stack_push(context->stack, value); break; } } else { fprintf(stderr, "Failed to interpret: %s\n", str); } return NULL; }
void create_image_histogram(void *src_pixels, size_t width, size_t height, size_t stride, uint32_t *histogram, channels channel) { value_function_ptr value_function = get_value_function_pointer(channel); for (int h = 0; h < height - 1; h++) { uint32_t *src_row = src_pixels + (stride * h); for (int w = 0; w < width - 1; w++) { uint8_t value = value_function(src_row[w]); histogram[value] += 1; } } }
void equalize_histogram_on_channel(void *src_pixels, void *dst_pixels, size_t width, size_t height, size_t stride, uint32_t *cdf, channels channel) { double_t conversion_constant = get_conversion_constant(width, height); value_function_ptr value_function = get_value_function_pointer(channel); pixel_convert_function_ptr pixel_convert_function = get_pixel_convert_function_pointer(channel); for (int h = 0; h < height - 1; h++) { uint32_t *src_row = src_pixels + (stride * h); uint32_t *dst_row = dst_pixels + (stride * h); for (int w = 0; w < width - 1; w++) { uint32_t old_value = value_function(src_row[w]); uint32_t new_value = conversion_constant * cdf[old_value]; dst_row[w] = pixel_convert_function(dst_row[w], old_value, new_value); } } }
function operator()(utree const& val) const { return function(value_function(val)); }