/* Double Images */
void doubleImageSmooth( image full, image *twice )
{
int r, c, p, q, u, v ;
/* construct an image structure of the appropriate size */
if ( !newImage( twice, full.nrows*2, full.ncols*2 ) )
{
printf("doubleImageSmooth(): newImage() failed\n" );
exit( EXIT_FAILURE );
}
/* Deal with most of the image, except last row and last col */
for ( r=0; r<full.nrows-1; r++ )
for ( c=0; c<full.ncols-1; c++ )
{
p = getPixel( full, r, c ) ;
q = getPixel( full, r, c+1 ) ;
u = getPixel( full, r+1, c ) ;
v = getPixel( full, r+1, c+1 ) ;
setPixel( *twice, r*2, c*2, (unsigned char)p );
setPixel( *twice, r*2, c*2+1, (unsigned char)((p+q)/2) );
setPixel( *twice, r*2+1, c*2, (unsigned char)((p+u)/2) );
setPixel( *twice, r*2+1, c*2+1, (unsigned char)((p+v)/2) );
}
/* Deal with last row */
r = full.nrows-1;
for ( c=0; c<full.ncols; c++ )
{
p = getPixel( full, r, c ) ;
setPixel( *twice, r*2, c*2, (unsigned char)p );
setPixel( *twice, r*2, c*2+1, (unsigned char)p );
setPixel( *twice, r*2+1, c*2, (unsigned char)p );
setPixel( *twice, r*2+1, c*2+1, (unsigned char)p );
}
/* Deal with last col */
c = full.ncols-1;
for ( r=0; r<full.nrows-1; r++ )
{
p = getPixel( full, r, c ) ;
setPixel( *twice, r*2, c*2, (unsigned char)p );
setPixel( *twice, r*2, c*2+1, (unsigned char)p );
setPixel( *twice, r*2+1, c*2, (unsigned char)p );
setPixel( *twice, r*2+1, c*2+1, (unsigned char)p );
}
}
Comments: