Переглянути джерело

Merge branch 'master' of ssh://git.davidventura.com.ar:443/david/orga2-simd

Fabian 11 роки тому
батько
коміт
ede2dc31b7
1 змінених файлів з 38 додано та 2 видалено
  1. 38 2
      filtros/blur_c.c

+ 38 - 2
filtros/blur_c.c

@@ -1,18 +1,54 @@
 #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 radius)
+    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);
 }
+