Advertisement
k3rsowa

☆line(read txt)

Jan 26th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     //Decralation of variables
  8.     FILE *fpi1,*fpi2,*fpo;
  9.     int id,ix,iy,i,j,width,height,time,num;
  10.     unsigned char dn;
  11.     unsigned char *buffer;
  12.     int *imeco;
  13.     unsigned char r,g,b;
  14.     char line[4];
  15.    
  16.     //GPS data logger
  17.     if((fpi1=fopen(argv[1],"r"))==NULL)
  18.     {
  19.         printf ("The file can't be opened. The program is exit.\n");
  20.         return 0;
  21.     }
  22.    
  23.     //image data
  24.     if((fpi2=fopen(argv[2],"rb"))==NULL)
  25.     {
  26.         printf ("The file can't be opened. The program is exit.\n");
  27.         return 0;
  28.     }
  29.    
  30.     //image data + GPS
  31.     if((fpo=fopen(argv[3],"wb"))==NULL)
  32.     {
  33.         printf("The file can't be opened. The program is exit.\n");
  34.         return 0;
  35.     }
  36.    
  37.     width = atoi(argv[4]); printf("W = %d,", width);
  38.     height = atoi(argv[5]); printf("H = %d\n", height);
  39.    
  40.     r=atoi(argv[6]);
  41.     g=atoi(argv[7]);
  42.     b=atoi(argv[8]);
  43.    
  44.     time=atoi(argv[9]);
  45.     printf("time=%d\n",time);
  46.     num=atoi(argv[10]);
  47.  
  48.    
  49.     //2 : x y
  50.     imeco=(int*)malloc(2*num);
  51.     fread((int*)imeco,sizeof(int),2*num,fpi1);
  52.    
  53.     //for image data :
  54.     buffer= (unsigned char*)malloc(width*height*3);
  55.     fread((unsigned char*)buffer,sizeof(char),width*height*3,fpi2);
  56.    
  57.     fseek(fpi1,time*7,SEEK_SET);
  58.     fgets(line, 4, fpi1);
  59.     ix=atoi(line);
  60.     fgets(line, 4, fpi1);
  61.     iy=atoi(line);
  62.    
  63.     //x y position on that time
  64.     printf("ix=%d\n",ix);
  65.     printf("iy=%d\n",iy);
  66.    
  67.    
  68.    
  69.     //colored point on that position
  70.     buffer[3*(iy*width+ix)]=r;
  71.     buffer[3*(iy*width+ix)+1]=g;
  72.     buffer[3*(iy*width+ix)+2]=b;
  73.    
  74.    
  75.    
  76.     //record colored point to file (write)
  77.     for(i=0;i<height*3;i++)
  78.     {
  79.         for(j=0;j<width;j++)
  80.         {
  81.             dn=buffer[i*width+j];
  82.             fwrite(&dn,sizeof(char),1,fpo);
  83.         }
  84.     }
  85.    
  86.     printf("check6\n");
  87.    
  88.     free(buffer);
  89.     free(imeco);
  90.    
  91.     fclose(fpi1);
  92.     fclose(fpi2);
  93.     fclose(fpo);
  94.    
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement