CRIMP
Artifact [b93c09cc8c]
Not logged in

Artifact b93c09cc8c6f28a6ad93599cc12d56aa551220ea:


upsamplex_grey32
Tcl_Obj* imageObj
int      factor

/*
 * The input image is upsampled in the x direction by inserting 'factor-1'
 * 0-pixels after every pixel of the input. Note that this method of expanding
 * an image introduces copies of the input to appear at higher frequencies.
 *
 * The output image has to be convolved with a low-pass filter after expansion
 * to avoid such artefacts. The integrated combination of upsampling and such
 * a filter is called 'interpolation'. This is but one step in the generation
 * of difference image pyramids.
 */

crimp_image* image;
crimp_image* result;
int          xo, y, xi, dx;

crimp_input (imageObj, image, grey32);
if (factor < 1) {
    Tcl_SetResult(interp, "bad sampling factor, expected integer > 0", TCL_STATIC);
    return TCL_ERROR;
}

if (factor == 1) {
    Tcl_SetObjResult(interp, imageObj);
    return TCL_OK;
}

result = crimp_new_at (image->itype, crimp_x (image), crimp_y (image), crimp_w (image)*factor, crimp_h (image));

for (y = 0; y < crimp_h (image); y ++) {
    for (xo = 0, xi = 0; xi < crimp_w (image); xo += factor, xi ++) {

	/* Copy the pixel */
	GREY32 (result, xo, y) = GREY32 (image, xi, y);

	/* And insert factor black (0) pixels after */
	for (dx = 1; dx < factor; dx++) {
	    GREY32 (result, xo + dx, y) = BLACK;
	}
    }
}

Tcl_SetObjResult(interp, crimp_new_image_obj (result));
return TCL_OK;

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