/*************************************************************************** * Func: convolve * * * * Desc: convolves an image with the floating point kernel passed and * * writes out new image one line at a time * * * * Params: source - pointer to image in memory * * cols - number of columns in image * * rows - number of rows in image * * kwidth - width of convolution kernel * * kheight - height of convolution kernel * * kernel - pointer to convolution kernel * * bias - value to add to convolution sum * * filename - name of output file * ***************************************************************************/ void convolve(image_ptr source, int cols, int rows, int kwidth, int kheight, float *kernel, int bias, char *filename) { int x, y, i; /* image loop variables */ int kernx, kerny; /* kernel loop variables */ int index; /* image index */ int xextra, yextra; /* size of boundary */ int conv_line; /* size of output line */ float sum; /* accumulator used during convolution */ unsigned long destadd; /* destination image address */ unsigned long sourceadd; /* index into source image */ unsigned long sourcebase; /* address of line */ unsigned char *dest; /* destination image line */ FILE *fp; /* output file pointer */ unsigned char left[25]; /* storage of left pixel for duplication */ unsigned char right[25]; /* storage of right pixel for duplication */ int xpad, ypad; /* number of pixels to duplicate at edges */ int last_line; /* last line to process */ yextra = (kheight/2)*2; ypad = yextra/2; xextra = (kwidth/2)*2; xpad = xextra/2; conv_line = cols - xextra; last_line = rows - yextra; dest = malloc(cols); if((fp=fopen(filename, "wb")) == NULL) { printf("Unable to open %s for output\n",filename); exit(1); } fprintf(fp, "P5\n%d %d\n255\n", cols, rows); /* print out header */ for(y=0; y