Guest User

Untitled

a guest
Aug 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.21 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. typedef struct
  5. {
  6.     int col;
  7.     int  fi;
  8.     unsigned char  **m;
  9.  
  10.  
  11. }matricial;
  12. typedef struct
  13. {
  14.     int f1;
  15.     int f2;
  16.     int c1;
  17.     int c2;
  18.     int factor;
  19.     unsigned char **m;
  20.  
  21.  
  22.  
  23. }coordenadas;
  24. void reservar(matricial *m);
  25. void lee(matricial *matriz,char imagen[20]);
  26. void opera(matricial *matriz,matricial *matriz2);
  27. void introduce(matricial *matriz2,char imagen[20]);
  28. void ampliar(coordenadas datos,char imagen[20]);
  29. int main()
  30. {
  31.  
  32.     matricial matriz, matriz2;
  33.     coordenadas datos;
  34. //  reservar(&matriz);
  35. //  lee(&matriz,"fruta3.pgm");
  36. //  opera(&matriz,&matriz2);
  37. //  introduce(&matriz2,"imagen.pgm");
  38.         printf("dame desde que fila vas a recorrer\n");
  39.         scanf("%d",&datos.f1);
  40.         printf("dame desde que fila vas a a llegar\n");
  41.         scanf("%d",&datos.f2);
  42.         printf("dame desde que columna  vas a a recorrer\n");
  43.         scanf("%d",&datos.c1);
  44.         printf("dame desde que columna  vas a a recorrer\n");
  45.         scanf("%d",&datos.c2);
  46.         printf("dame el factor de apliación\n");
  47.         scanf("%d",&datos.factor);
  48.         ampliar(datos,"fruta3.pgm");
  49.    
  50.    
  51.  
  52. }
  53. void reservar(matricial *matriz)
  54. {
  55.  
  56.     int i,j;
  57.     (*matriz).m=(unsigned char **)malloc(sizeof(unsigned char*)*((*matriz).fi));
  58.     for(i=0;i<(*matriz).col;i++)
  59.     {
  60.         (*matriz).m[i]=(unsigned char*)malloc(sizeof(unsigned char)*((*matriz).col));
  61.     }
  62.  
  63. }
  64. void lee(matricial *matriz,char imagen[20])
  65. {
  66.     int fil,col,i;
  67.     FILE *f;
  68.  
  69.     f=fopen(imagen,"rb");
  70.     fscanf(f,"%d %d",&fil,&col);
  71.     (*matriz).fi=fil;
  72.     (*matriz).col=col;
  73.  
  74.     for(i=0;i<(*matriz).fi;i++)
  75.     {
  76.    
  77.     fread(&(*matriz).m[i],sizeof(unsigned char),(*matriz).col,f);
  78.     }
  79.     fclose(f);
  80. }
  81. void opera(matricial *matriz,matricial *matriz2)
  82. {
  83.    
  84.    
  85.     int i,j;
  86.     (*matriz2).fi=(*matriz).fi;
  87.     (*matriz2).col=(*matriz).col;
  88.  
  89.     reservar(matriz2);//aqui esta el fallo!
  90.  
  91.    
  92.     for(i=0;i<(*matriz).fi;i++)
  93.     {
  94.         for(j=0;j<(*matriz).col;j++)
  95.         {
  96.             (*matriz2).m[i][j]=255-(*matriz).m[i][j];
  97.         }
  98.  
  99.     }
  100.    
  101.  
  102. }
  103. void introduce(matricial *matriz2,char imagen[20])
  104. {
  105.     int i,j;
  106.  
  107.     FILE *f;
  108.     fopen(imagen,"wb");
  109.    
  110.  
  111.    
  112.     for(i=0;i<(*matriz2).fi;i++)
  113.     {
  114.         for(j=0;j<(*matriz2).col;j++)
  115.         {
  116.             fwrite(&(*matriz2).m[i][j],sizeof(unsigned char),1,f);
  117.         }
  118.  
  119.     }
  120.     fclose(f);
  121.  
  122. }
  123. void ampliar(coordenadas datos,char imagen[20])
  124. {
  125.     int tamf,tamc,fac;
  126.     fac=datos.factor;
  127.     tamf=(datos.f2-datos.f1)*datos.factor;
  128.     tamc=(datos.c2-datos.c1)*datos.factor;
  129.     int i,j;
  130.     datos.m=(unsigned char **)malloc(sizeof(unsigned char*)*tamf);
  131.     for(i=0;i<tamc;i++)
  132.     {
  133.         datos.m[i]=(unsigned char*)malloc(sizeof(unsigned char)*tamf);
  134.     }
  135.    
  136.     FILE *f;
  137.     int mf,mc;
  138.     mf=datos.f2-datos.f1;
  139.     mc=datos.c2-datos.c1;
  140.     unsigned char aux[datos.f2-datos.f1][datos.c2-datos.c1];
  141.     f=fopen(imagen,"rb");
  142.    
  143.     for(i=datos.f1;i<datos.f2;i++);
  144.     {
  145.         for(j=datos.c1;i<datos.c2;j++)
  146.         {
  147.             fread(&aux[i][j],sizeof(unsigned char),1,f);
  148.         }
  149.  
  150.     }
  151.     fclose(f);
  152.     int aumento=0;
  153.     int h,k=0;
  154.  
  155.     for(i=0;i<mf;i++);
  156.     {
  157.             h=0;
  158.         for(j=0;i<mc;j++)
  159.         {
  160.             while(fac!=0)
  161.             {
  162.                        
  163.                 datos.m[i+k][h]=aux[i][j];
  164.                 h++;
  165.                 fac --;
  166.                 while(fac!=0)
  167.                 {
  168.  
  169.                     datos.m[k][h]=aux[i][j];
  170.  
  171.                     k++;
  172.                     fac--;
  173.                 }
  174.                 h++;
  175.                 fac --;
  176.             }
  177.                 fac=datos.factor;
  178.         }
  179.        
  180.  
  181.        
  182.  
  183.     }  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203. }
Add Comment
Please, Sign In to add comment