downsample_hsv
Tcl_Obj* imageObj
int      factor

/*
 * The input image is downsampled by storing only every 'factor' pixel into
 * the result. Note that this method of shrinking an image causes image
 * frequencies above the nyquist threshold of the result to be aliased into
 * the range.
 *
 * The input image has to be convolved with a low-pass filter first, to avoid
 * such artefacts. The integrated combination of such a filter with
 * downsampling is called 'decimation'. This is but one step in the generation
 * of image pyramids.
 */

crimp_image* image;
crimp_image* result;
int          xo, yo, xi, yi;

crimp_input (imageObj, image, hsv);
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 (image->itype, image->w/factor, image->h/factor);

for (yo = 0, yi = 0; yo < result->h; yo++, yi += factor) {
    for (xo = 0, xi = 0; xo < result->w; xo++, xi += factor) {

	H (result, xo, yo) = H (image, xi, yi);
	S (result, xo, yo) = S (image, xi, yi);
	V (result, xo, yo) = V (image, xi, yi);
    }
}

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:
 */