Skip to content

Commit

Permalink
Introduced image data structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Nov 24, 2007
1 parent 99df4ae commit e0fa842
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 22 additions & 33 deletions builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,54 +117,46 @@ 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)
{
x += 0.5;
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,
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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**);

Expand All @@ -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);

Expand Down
12 changes: 7 additions & 5 deletions compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down Expand Up @@ -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 :
Expand Down
1 change: 1 addition & 0 deletions compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "tuples.h"
#include "exprtree.h"
#include "userval.h"

#include "compiler_types.h"
#include "opmacros.h"
Expand Down
12 changes: 6 additions & 6 deletions new_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion opmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ops.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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]"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion userval.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e0fa842

Please sign in to comment.