Advertisement
shouhei

color3

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