Advertisement
shouhei

color success

Nov 6th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 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,width,height,i,j;
  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. /*RGBを色平面に分解
  27. Rbuffer = (unsigned char*)malloc( width*height );
  28. Gbuffer = (unsigned char*)malloc( width*height );
  29. Bbuffer = (unsigned char*)malloc( width*height );
  30. */
  31.  
  32. buffer = (unsigned char*)malloc(width*height*3);
  33.  
  34. fread((unsigned char*)buffer,sizeof(char),width*height*3,fpi2);
  35.  
  36. //Open VTK file for save
  37. if((fpo=fopen(argv[3],"wb"))==NULL)
  38. {
  39. printf("The file can't be opened. The program is exit.\n");
  40.  
  41. return 0;
  42. }
  43.  
  44.  
  45. //count how many lines
  46. /*
  47. while((c=fgetc(fpi))!=EOF)
  48. {
  49. if(c=='\n')
  50. newline_count++;
  51. }
  52. */
  53.  
  54. while(fscanf(fpi1,"%d %f %f %f %d %d\n",id,x,y,z,ix,iy)!=EOF)
  55. {
  56. printf("%d %f %f %f %d %d\n",id,x,y,z,ix,iy);
  57. buffer[iy*width+ix]=127;
  58. buffer[(iy*width+ix)+width*height]=127;
  59. buffer[(iy*width+ix)+width*height*2]=127;
  60.  
  61. }
  62.  
  63. for(i=0;i<height*3;i++)
  64. {
  65. for(j=0;j<width;j++)
  66. {
  67. dn=buffer[i*width+j];
  68. fwrite(&dn,sizeof(char),1,fpo);
  69. }
  70. }
  71.  
  72.  
  73. fclose(fpi1);
  74. fclose(fpi2);
  75. fclose(fpo);
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement