vacendak

figurapecsept01

Aug 8th, 2018
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define ANCHURA 512
  4. #define ALTURA  512
  5.  
  6. void guardaPGMd(char* nombre, int anchura, int altura, double *pixels,
  7.                 double pixel_min, double pixel_max)
  8.                 {
  9.                     int i, j, ij, p;
  10.                     FILE* imagen;
  11.  
  12.                     imagen=fopen(nombre,"wb");
  13.                     fprintf(imagen,"P2");
  14.                     fprintf(imagen,"#guardaPGMd %s\n", nombre);
  15.                     fprintf(imagen,"%d %d\n",anchura,altura);
  16.                     fprintf(imagen,"255\n");
  17.  
  18.                     ij=0;
  19.                     for(i=0;i<altura; i++)
  20.                     {
  21.                         for(j=0;j<anchura;j++)
  22.                             {
  23.                                 p=(int)(255*(pixels[ij]-pixel_min))/(pixel_max-pixel_min);
  24.                                 if(p<0) p=0;
  25.                                 if(p>255) p=255;
  26.  
  27.                                 fprintf(imagen," %d",p);
  28.  
  29.                                 ij++;
  30.                             }
  31.                             fprintf(imagen,"\n");
  32.                     }
  33.                     fclose(imagen);
  34.  
  35.                     return;
  36.                 }
  37. int main(int argc, char **argv)
  38. {
  39.     int i, j;
  40.     double x,y,z;
  41.     double f[ALTURA][ANCHURA];
  42.  
  43.     for(i=0;i<ALTURA;i++)
  44.     {
  45.         for(j=0;j<ANCHURA;j++)
  46.         {
  47.             x=2*(double)j/(ANCHURA-1)-1.0;
  48.             y=2*(double)i/(ALTURA-1)-1.0;
  49.             z=1.0/(1+(2*x*x+3*y*y));
  50.  
  51.             f[i][j]=z;
  52.         }
  53.  
  54.     }
  55.  
  56.     guardaPGMd("prueba.pgm",ANCHURA,ALTURA,(double*)f,0,1.0);
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment