| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #define M_PI 3.14159265358979323846
- #include "../tp2.h"
- void blur_c (
- unsigned char *src,
- unsigned char *dst,
- int cols,
- int filas,
- float sigma,
- int r)
- {
- unsigned char (*src_matrix)[cols*4] = (unsigned char (*)[cols*4]) src;
- unsigned char (*dst_matrix)[cols*4] = (unsigned char (*)[cols*4]) dst;
- int i,j=0,x,y;
- int tmp[3];
-
- float val;
- float *mc=malloc(sizeof(float)*4*r*r);
- printf("r: %d, plsgiv %d\n", r, sizeof(float)*r*r);
- for(y=0;y<2*r;y++) {
- for(x=0;x<2*r;x++){
- val=(1/(2*M_PI*sigma*sigma) * exp(- ((x*x)+(y*y))/(2*sigma*sigma)));
- mc[x+(4*y*r)]= val;
- }
- }
- for(i=r;i<filas-r;i++){ //
- for(j=r;j<cols-r;j++) { //ignoro los bordes de tamaño R
- tmp[0]=0;
- tmp[1]=0;
- tmp[2]=0;
- for(y=0;y<2*r;y++){
- for(x=0;x<2*r;x++){
- tmp[0]+=src_matrix[i+y][4*(x+j)+0]*mc[x+(r*y*2)];
- tmp[1]+=src_matrix[i+y][4*(x+j)+1]*mc[x+(r*y*2)];
- tmp[2]+=src_matrix[i+y][4*(x+j)+2]*mc[x+(r*y*2)];
- }
- }
- dst_matrix[i][4*j+0]=tmp[0];
- dst_matrix[i][4*j+1]=tmp[1];
- dst_matrix[i][4*j+2]=tmp[2];
- }
- }
- free(mc);
- }
|