root/trunk/lib/cc3-ilp/cc3_conv.c

Revision 363, 0.9 kB (checked in by anthony_rowe, 2 years ago)

blah

Line 
1 #include "cc3_conv.h"
2
3 /*
4   cc3_convolve_img()
5   This is a simple integer image convolution. 
6   This will take an image and a kernel and convolve the kernel
7   across the image replacing its original content.
8
9   The max size of the convolution kernel MAX_KERNEL_SIZE is
10   defined in cc3_conv.h.
11
12   The function returns 1 upon success and 0 on failure.
13  */
14 int cc3_convolve_img(cc3_image_t *img, cc3_kernel_t kernel)
15 {
16 uint32_t i,j,k,l,mat_div;
17 cc3_pixel_t p;
18 if(kernel.size>MAX_KERNEL_SIZE) return 0;
19 if( img->height<kernel.size+1 ) return 0;
20 if( img->width<kernel.size+1 ) return 0;
21
22 mat_div=kernel.divisor;
23 for(j=0; j<img->height-kernel.size+1; j++ )
24         for(i=0; i<img->width-kernel.size+1; i++ )
25         {
26         uint32_t tmp;
27         tmp=0; 
28         for(k=0; k<kernel.size; k++ )
29                 for(l=0; l<kernel.size; l++ )
30                 {
31                 cc3_get_pixel (img, i+k, j+l, &p);             
32                 tmp+=p.channel[0]*kernel.mat[k][l];
33                 }
34
35         p.channel[0]=tmp / mat_div;
36         cc3_set_pixel (img, i, j, &p);         
37         }
38 return 1;
39 }
Note: See TracBrowser for help on using the browser.