CRIMP
Artifact [08f7c6fe97]
Not logged in

Artifact 08f7c6fe97544763000cd4f53b43ab2b31514885:


expand_grey32_extend
Tcl_Obj* imageObj
int ww
int hn
int we
int hs

/*
 * Border expansion by subtracting mirrored pixels from the edge pixel, making
 * this a combination of mirror and replicate.
 */

crimp_image* image;
crimp_input (imageObj, image, grey32);

/*
 * This is the simple definition. Might be better to generate macros
 * specialized to each quadrant. Except, even they have to perform modulo
 * arithmetic, as the border may be larger than image's width or height,
 * causing multiple wrapping.
 *
 * NOTE: The replicate part can be optimized for the eight outer quadrants.
 */

#define FILL(xo,yo) {						   \
	int xb = xo - ww;					   \
	int yb = yo - hn;					   \
	int xi = xb;						   \
	int yi = yb;						   \
	int tg;							   \
								   \
	if      (xb < 0)         { xb = 0;            }		   \
	else if (xb >= crimp_w (image)) { xb = (crimp_w (image)-1); }		   \
								   \
	if      (yb < 0)         { yb = 0;            }		   \
	else if (yb >= crimp_h (image)) { yb = (crimp_h (image)-1); }		   \
								   \
	while (1) {						   \
	    if      (xi < 0)         { xi = 0              - xi; } \
	    else if (xi >= crimp_w (image)) { xi = 2*(crimp_w (image)-1) - xi; } \
	    else break;						   \
	}							   \
								   \
	while (1) {						   \
	    if      (yi < 0)         { yi = 0              - yi; } \
	    else if (yi >= crimp_h (image)) { yi = 2*(crimp_h (image)-1) - yi; } \
	    else break;						   \
	}							   \
								   \
	tg = GREY32 (image, xi, yi) - GREY32 (image, xb, yb);	   \
								   \
	GREY32 (result, xo, yo) = CLAMP (0, tg, 255);		   \
    }

#define COPY(xo,yo,xi,yi) {				\
	GREY32 (result, xo, yo) = GREY32 (image, xi, yi); \
    }

#include <expand_op.c>

/* vim: set sts=4 sw=4 tw=80 et ft=c: */
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */