From e0fa842318efe6660e5ff22b0e66fca5d2145274 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Sun, 25 Nov 2007 00:11:39 +0100 Subject: [PATCH] Introduced image data structure. --- TODO | 1 + builtins.c | 55 ++++++++++++++++++++------------------------------ builtins.h | 5 +++-- compiler.c | 12 ++++++----- compiler.h | 1 + new_template.c | 12 +++++------ opmacros.h | 3 ++- ops.lisp | 7 ++++++- userval.h | 2 +- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/TODO b/TODO index 54efd56..d191406 100644 --- a/TODO +++ b/TODO @@ -13,6 +13,7 @@ Update screenshots ** GIMP Plug-In auto-completion? Histogram +Different fast image source size per drawable Adapt fast image source size to preview size zoom via preview diff --git a/builtins.c b/builtins.c index 6d0a331..eb8d193 100644 --- a/builtins.c +++ b/builtins.c @@ -117,42 +117,34 @@ apply_edge_behaviour (mathmap_invocation_t *invocation, int *_x, int *_y, int wi } static color_t -get_pixel (mathmap_invocation_t *invocation, int x, int y, userval_t *userval, int frame) +get_pixel (mathmap_invocation_t *invocation, int x, int y, input_drawable_t *drawable, int frame) { - if (userval->v.image.drawable == NULL) + if (drawable == NULL) return MAKE_RGBA_COLOR(255, 255, 255, 255); - apply_edge_behaviour(invocation, &x, &y, userval->v.image.drawable->width, userval->v.image.drawable->height); + apply_edge_behaviour(invocation, &x, &y, drawable->width, drawable->height); - return mathmap_get_pixel(invocation, userval->v.image.drawable, frame, x, y); + return mathmap_get_pixel(invocation, drawable, frame, x, y); } -static userval_t* -get_drawable_userval (mathmap_invocation_t *invocation, int drawable_index, float *x, float *y) +static input_drawable_t* +get_image_drawable (mathmap_invocation_t *invocation, image_t *image, float *x, float *y) { - userval_t *userval; + input_drawable_t *drawable = image->drawable; - if (drawable_index < 0 || drawable_index >= invocation->mathmap->main_filter->num_uservals) - return 0; + if (drawable == NULL) + return NULL; - userval = &invocation->uservals[drawable_index]; + *x = (*x + drawable->middle_x) * drawable->scale_x; + *y = -((*y - drawable->middle_y) * drawable->scale_y); - if (userval->type != USERVAL_IMAGE) - return 0; - - *x = (*x + userval->v.image.drawable->middle_x) * userval->v.image.drawable->scale_x; - *y = -((*y - userval->v.image.drawable->middle_y) * userval->v.image.drawable->scale_y); - - return userval; + return drawable; } color_t -get_orig_val_pixel (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame) +get_orig_val_pixel (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame) { - userval_t *userval = get_drawable_userval(invocation, drawable_index, &x, &y); - - if (userval == 0) - return COLOR_WHITE; + input_drawable_t *drawable = get_image_drawable(invocation, image, &x, &y); if (!invocation->supersampling) { @@ -160,11 +152,11 @@ get_orig_val_pixel (mathmap_invocation_t *invocation, float x, float y, int draw y += 0.5; } - return get_pixel(invocation, floor(x), floor(y), userval, frame); + return get_pixel(invocation, floor(x), floor(y), drawable, frame); } color_t -get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame) +get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame) { int x1, x2, @@ -180,13 +172,10 @@ get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float p4fact; color_t pixel1, pixel2, pixel3, pixel4, result; float_color_t fpixel1, fpixel2, fpixel3, fpixel4, fresult; - userval_t *userval = get_drawable_userval(invocation, drawable_index, &x, &y); + input_drawable_t *drawable = get_image_drawable(invocation, image, &x, &y); int pixel_inc_x, pixel_inc_y; - if (userval == 0) - return COLOR_WHITE; - - drawable_get_pixel_inc(invocation, userval->v.image.drawable, &pixel_inc_x, &pixel_inc_y); + drawable_get_pixel_inc(invocation, drawable, &pixel_inc_x, &pixel_inc_y); if (pixel_inc_x > 1) { @@ -230,10 +219,10 @@ get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float p3fact = x2fact * y1fact; p4fact = x2fact * y2fact; - pixel1 = get_pixel(invocation, x1, y1, userval, frame); - pixel2 = get_pixel(invocation, x1, y2, userval, frame); - pixel3 = get_pixel(invocation, x2, y1, userval, frame); - pixel4 = get_pixel(invocation, x2, y2, userval, frame); + pixel1 = get_pixel(invocation, x1, y1, drawable, frame); + pixel2 = get_pixel(invocation, x1, y2, drawable, frame); + pixel3 = get_pixel(invocation, x2, y1, drawable, frame); + pixel4 = get_pixel(invocation, x2, y2, drawable, frame); fpixel1 = COLOR_MUL_FLOAT(pixel1, p1fact); fpixel2 = COLOR_MUL_FLOAT(pixel2, p2fact); diff --git a/builtins.h b/builtins.h index a284e60..4fc0769 100644 --- a/builtins.h +++ b/builtins.h @@ -32,6 +32,7 @@ struct _mathmap_invocation_t; struct _compvar_t; +struct _image_t; typedef void (*generator_function_t) (struct _compvar_t***, int*, int*, struct _compvar_t**); @@ -43,8 +44,8 @@ void double_to_color (double val, unsigned int *red, unsigned int *green, void convert_rgb_to_hsv (float *rgb, float *hsv); void convert_hsv_to_rgb (float *hsv, float *rgb); -color_t get_orig_val_pixel (struct _mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame); -color_t get_orig_val_intersample_pixel (struct _mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame); +color_t get_orig_val_pixel (struct _mathmap_invocation_t *invocation, float x, float y, struct _image_t *image, int frame); +color_t get_orig_val_intersample_pixel (struct _mathmap_invocation_t *invocation, float x, float y, struct _image_t *image, int frame); void init_builtins (void); diff --git a/compiler.c b/compiler.c index 60e56fb..ae15397 100644 --- a/compiler.c +++ b/compiler.c @@ -296,11 +296,11 @@ static type_t primary_type (primary_t *primary); #define OUTPUT_COLOR_INTERPRETER(c) ({ invocation->interpreter_output_color = (c); invocation->interpreter_ip = -1; 0; }) -#define ORIG_VAL_INTERPRETER(x,y,d,f) ({ color_t c; \ +#define ORIG_VAL_INTERPRETER(x,y,i,f) ({ color_t c; \ if (invocation->antialiasing) \ - c = get_orig_val_intersample_pixel(invocation, (x), (y), (d), (f)); \ + c = get_orig_val_intersample_pixel(invocation, (x), (y), &(i), (f)); \ else \ - c = get_orig_val_pixel(invocation, (x), (y), (d), (f)); \ + c = get_orig_val_pixel(invocation, (x), (y), &(i), (f)); \ c; }) #define ARG(i) (invocation->uservals[(i)]) @@ -1984,8 +1984,10 @@ gen_code (exprtree *tree, compvar_t **dest, int is_alloced) case USERVAL_IMAGE : if (!is_alloced) - dest[0] = make_temporary(TYPE_INT); - emit_assign(make_lhs(dest[0]), make_int_const_rhs(tree->val.userval.info->index)); + dest[0] = make_temporary(TYPE_IMAGE); + emit_assign(make_lhs(dest[0]), + make_op_rhs(OP_USERVAL_IMAGE, + make_int_const_primary(tree->val.userval.info->index))); break; default : diff --git a/compiler.h b/compiler.h index aa41443..65030b0 100644 --- a/compiler.h +++ b/compiler.h @@ -30,6 +30,7 @@ #include "tuples.h" #include "exprtree.h" +#include "userval.h" #include "compiler_types.h" #include "opmacros.h" diff --git a/new_template.c b/new_template.c index 58ea257..2a45fd0 100644 --- a/new_template.c +++ b/new_template.c @@ -243,16 +243,16 @@ get_orig_val_pixel_fast (mathmap_invocation_t *invocation, float _x, float _y, i return *(color_t*)(userval->v.image.data + 4 * x + y * userval->v.image.row_stride); } -extern color_t get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame); +extern color_t get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame); static color_t -get_orig_val_intersample_pixel_fast (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame) +get_orig_val_intersample_pixel_fast (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame) { - return get_orig_val_intersample_pixel(invocation, x, y, drawable_index, frame); + return get_orig_val_intersample_pixel(invocation, x, y, image, frame); } #else -extern color_t get_orig_val_pixel (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame); -extern color_t get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, int drawable_index, int frame); +extern color_t get_orig_val_pixel (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame); +extern color_t get_orig_val_intersample_pixel (mathmap_invocation_t *invocation, float x, float y, image_t *image, int frame); #endif extern float noise (float, float, float); @@ -323,7 +323,7 @@ static void calc_lines (mathmap_slice_t *slice, int first_row, int last_row, unsigned char *q) { mathmap_invocation_t *invocation = slice->invocation; - color_t (*get_orig_val_pixel_func) (mathmap_invocation_t*, float, float, int, int); + color_t (*get_orig_val_pixel_func) (mathmap_invocation_t*, float, float, image_t*, int); int row, col; float t = invocation->current_t; float X = invocation->image_X, Y = invocation->image_Y; diff --git a/opmacros.h b/opmacros.h index 4bd3c7e..6affc3c 100644 --- a/opmacros.h +++ b/opmacros.h @@ -142,8 +142,9 @@ typedef struct #define USERVAL_CURVE_ACCESS(x,p) (ARG((x)).v.curve.values[(int)(CLAMP01((p)) * (USER_CURVE_POINTS - 1))]) #define USERVAL_COLOR_ACCESS(x) (ARG((x)).v.color.value) #define USERVAL_GRADIENT_ACCESS(x,p) (ARG((x)).v.gradient.values[(int)(CLAMP01((p)) * (USER_GRADIENT_POINTS - 1))]) +#define USERVAL_IMAGE_ACCESS(x) (ARG((x)).v.image) -#define ORIG_VAL(x,y,d,f) get_orig_val_pixel_func(invocation, (x), (y), (d), (f)) +#define ORIG_VAL(x,y,i,f) get_orig_val_pixel_func(invocation, (x), (y), &(i), (f)) #ifdef IN_COMPILED_CODE #ifdef OPENSTEP diff --git a/ops.lisp b/ops.lisp index 079bb00..aa4a0dd 100644 --- a/ops.lisp +++ b/ops.lisp @@ -36,6 +36,9 @@ ("crealf(~A)" "cimagf(~A)"))) (color "color_t" ("(%d,%d,%d,%d)" "MAKE_RGBA_COLOR(%d,%d,%d,%d)" ("RED(~A)" "GREEN(~A)" "BLUE(~A)" "ALPHA(~A)"))) + (image "image_t" ("DRAWABLE(%p)" "MAKE_INPUT_IMAGE(%p)" + ("(~A).drawable")) + ("drawable")) (gsl-matrix "gsl_matrix *" ("***MATRIX***" "***MATRIX***" ())) (v2 "mm_v2_t" ("[%f,%f]" "MAKE_V2(%f,%f)" ("~A.v[0]" "~A.v[1]")) @@ -144,7 +147,7 @@ (defop 'start-debug-tuple 1 "START_DEBUG_TUPLE" :type 'int :arg-type 'int :pure nil) (defop 'set-debug-tuple-data 2 "SET_DEBUG_TUPLE_DATA" :type 'int :arg-types '(int float) :pure nil) -(defop 'orig-val 4 "ORIG_VAL" :interpreter-c-name "ORIG_VAL_INTERPRETER" :type 'color :arg-types '(float float int float) :foldable nil) +(defop 'orig-val 4 "ORIG_VAL" :interpreter-c-name "ORIG_VAL_INTERPRETER" :type 'color :arg-types '(float float image float) :foldable nil) (defop 'red 1 "RED_FLOAT" :arg-type 'color :foldable nil) (defop 'green 1 "GREEN_FLOAT" :arg-type 'color :foldable nil) (defop 'blue 1 "BLUE_FLOAT" :arg-type 'color :foldable nil) @@ -211,6 +214,7 @@ (defop 'userval-curve 2 "USERVAL_CURVE_ACCESS" :type 'float :arg-types '(int float) :foldable nil) (defop 'userval-color 1 "USERVAL_COLOR_ACCESS" :type 'color :arg-type 'int :foldable nil) (defop 'userval-gradient 2 "USERVAL_GRADIENT_ACCESS" :type 'color :arg-types '(int float) :foldable nil) +(defop 'userval-image 1 "USERVAL_IMAGE_ACCESS" :type 'image :arg-type 'int :foldable nil) (defop 'make-color 4 "MAKE_COLOR" :type 'color) (defop 'output-color 1 "OUTPUT_COLOR" :interpreter-c-name "OUTPUT_COLOR_INTERPRETER" :type 'int :arg-type 'color :pure nil) @@ -307,6 +311,7 @@ (labels ((interpret-format (char arg) (ecase char (#\d (format nil "fprintf(out, \"%d\", ~A);" arg)) + (#\p (format nil "fprintf(out, \"%p\", ~A);" arg)) (#\f (format nil "{ gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_dtostr(buf, sizeof(buf), ~A); fputs(buf, out); }" arg))))) (if (> (length format) 0) diff --git a/userval.h b/userval.h index badbb9b..1cd7f9e 100644 --- a/userval.h +++ b/userval.h @@ -79,7 +79,7 @@ typedef struct _userval_info_t struct _userval_info_t *next; } userval_info_t; -typedef struct +typedef struct _image_t { input_drawable_t *drawable; } image_t;