upsample_grey32 Tcl_Obj* imageObj int factor /* * The input image is upsampled 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, yo, xi, yi, dx, dy; 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 (image->itype, image->w*factor, image->h*factor); for (yo = 0, yi = 0; yi < image->h; yo += factor, yi ++) { for (xo = 0, xi = 0; xi < image->w; xo += factor, xi ++) { /* Copy the pixel */ GREY32 (result, xo, yo) = GREY32 (image, xi, yi); /* And insert factor black (0) pixels after */ for (dx = 1; dx < factor; dx++) { GREY32 (result, xo + dx, yo) = BLACK; } } /* And insert factor black lines after the intput line*/ for (dy = 1; dy < factor; dy++) { for (xo = 0; xo < result->w; xo++) { GREY32 (result, xo, yo + dy) = 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: */