| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #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;
- unsigned int i,j=0,x,y;
- float tmp[3];
-
- float val;
- float *mc=malloc(sizeof(float)*40*r*r);
- printf("r: %d, plsgiv %d\n", r, sizeof(float)*r*r);
- unsigned int indice_de_mierda=0;
- for(y=-r;y<r;y++) {
- for(x=-r;x<r;x++){
- val=(1/(2*M_PI*sigma*sigma) * exp(- ((x*x)+(y*y))/(2*sigma*sigma)));
- mc[indice_de_mierda]= val;
- indice_de_mierda++;
- }
- }
- for(i=r;i<filas-r-1;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)];
- }
- }
- printf("%f\n",tmp[0]);
- dst_matrix[i][4*j+0]=(int)tmp[0];
- dst_matrix[i][4*j+1]=(int)tmp[1];
- dst_matrix[i][4*j+2]=(int)tmp[2];
- //printf("%d %d\n",i,4*j);
- }
- }
- free(mc);
- }
|