Advertisement
shouhei

color new

Nov 12th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5. //Decralation of variables
  6. FILE *fpi1,*fpi2,*fpo;
  7. int id,ix,iy,i,j,width,height;
  8. float x,y,z;
  9. unsigned char dn;
  10. unsigned char *buffer; /*入力画像用メモリのポインタ*/
  11.  
  12. //Open CSV file
  13. if((fpi1=fopen(argv[1],"r"))==NULL)
  14. {
  15. printf ("The file can't be opened. The program is exit.\n");
  16. return 0;
  17. }
  18.  
  19. if((fpi2=fopen(argv[2],"rb"))==NULL)
  20. {
  21. printf ("The file can't be opened. The program is exit.\n");
  22.  
  23. return 0;
  24. }
  25.  
  26. width = atoi(argv[4]); printf("W = %d,", width);
  27. height = atoi(argv[5]); printf("H = %d\n", height);
  28.  
  29. /*RGBを色平面に分解
  30. Rbuffer = (unsigned char*)malloc( width*height );
  31. Gbuffer = (unsigned char*)malloc( width*height );
  32. Bbuffer = (unsigned char*)malloc( width*height );
  33. */
  34. printf("check0\n");
  35. buffer = (unsigned char*)malloc(width*height*3);
  36. printf("check1\n");
  37.  
  38. fread((unsigned char*)buffer,sizeof(char),width*height*3,fpi2);
  39. printf("check2\n");
  40. //Open VTK file for save
  41. if((fpo=fopen(argv[3],"wb"))==NULL)
  42. {
  43. printf("The file can't be opened. The program is exit.\n");
  44.  
  45. return 0;
  46. }
  47.  
  48.  
  49. //count how many lines
  50. /*
  51. while((c=fgetc(fpi))!=EOF)
  52. {
  53. if(c=='\n')
  54. newline_count++;
  55. }
  56. */
  57. printf("check3\n");
  58. while(fscanf(fpi1,"%f %f %f %d %d",&x,&y,&z,&ix,&iy)!=EOF)
  59. {
  60. //printf("%f %f %f %d %d\n",x,y,z,ix,iy);
  61. //buffer[iy*width+ix]=127;
  62. //buffer[(iy*width+ix)+width*height]=127;
  63. //buffer[(iy*width+ix)+width*height*2]=127;
  64. buffer[3*(iy*width+ix)]=127;
  65. buffer[3*(iy*width+ix)+1]=127;
  66. buffer[3*(iy*width+ix)+2]=127;
  67. }
  68.  
  69. for(i=0;i<height*3;i++)
  70. {
  71. for(j=0;j<width;j++)
  72. {
  73. dn=buffer[i*width+j];
  74. fwrite(&dn,sizeof(char),1,fpo);
  75. }
  76. }
  77.  
  78.  
  79. fclose(fpi1);
  80. fclose(fpi2);
  81. fclose(fpo);
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement