Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // combineD
- //
- // Created by Dai on 2013/10/21.
- // Copyright (c) 2013年 Dai. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h> //memcpy
- #include<memory.h>
- int main(int argc,char *argv[])
- {
- FILE *fpi1,*fpi2,*fpo;
- int i,j,height1,width1,height2,width2;
- float dn1;
- int x,y;
- int re;
- int ix,iy;
- float *file1,*file2;
- float *file3;
- int iw,ih,iW,iH;
- if(argc!=11)
- {
- fprintf(stderr,"Usage: %s\n(2)Input_file1_filename\n(3)Input_file2_filename\n(4)Output_new_filename\n(5)width1\n(6)height1\n(7)width2\n(8)height2\n(9)x\n(10)y\n(11)re\n",argv[0]);
- exit(1);
- }
- printf("OPEN R FILE NAME:%s\n",argv[1]);
- printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
- printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
- //large
- width1 = atoi(argv[4]); printf("W = %d,", width1);
- iw=width1/10;
- height1 = atoi(argv[5]); printf("H = %d\n", height1);
- ih=height1/10;
- //small
- width2 = atoi(argv[6]); printf("W = %d,", width2);
- iW=width2/10;
- printf("iW=%d\n",iW);
- height2 = atoi(argv[7]); printf("H = %d\n", height2);
- iH=height2/10;
- printf("iH=%d\n",iH);
- x = atoi(argv[8]); printf("X = %d\n" , x); //corner of upper left in large image
- y = atoi(argv[9]); printf("Y = %d\n" , y); //corner of upper left in large image
- re = atoi(argv[10]); printf("RE = %d\n" , re);
- ix=x*re/10;
- iy=y*re/10;
- printf("ix=%d\n",ix);
- printf("iy=%d\n",iy);
- printf("check00\n");
- // file1= (float *)malloc(iw*ih*sizeof(float)); //large
- file2= (float *)malloc(iW*iH*sizeof(float)); //small
- // file3= (float *)malloc(iw*ih*sizeof(float)); //for output
- printf("check0\n");
- if((fpi1=fopen(argv[1],"rb+"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- printf("check0-1\n");
- // fread((float *)file1,sizeof(float),iw*ih,fpi1);
- printf("check0-2\n");
- if((fpi2=fopen(argv[2],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- printf("check0-3\n");
- fread((float *)file2,sizeof(float),iW*iH,fpi2);
- printf("check0-4\n");
- /* if((fpo=fopen(argv[3],"wb"))==NULL)
- {
- fprintf(stderr,"output file open error\n");
- exit(1);
- }
- */
- //fread((float *)file3,sizeof(float),width1*height1,fpo);
- printf("check1\n");
- j=0;
- for(i=iy;i<iy+iH;i++)//for large
- {
- for(j=0;j<iW;j++)//for large
- {
- //fseek(fpi1,i*iw*sizeof(float)+ix*sizeof(float),SEEK_SET);
- //fseek(fpi2,i*iW*sizeof(float),SEEK_SET);
- //if(i>iy && i<iy+iH && j>ix && j<ix+iW) //for small
- //{
- //j=ix;
- // printf("i=%d\n",i);
- // printf("j=%d\n\n",j);
- //printf("file1=%d\n",i*ih+j);
- // printf("file2=%d\n",(i-iy)*iW);
- //memcpy(&file1[i*iw+j],&file2[(i-iy)*iW],sizeof(float)*iW);
- // printf("memcpy-OK\n");
- fseek(fpi1,i*iw+ix+j,SEEK_SET);
- dn1=file2[(i-iy)*iW+j];
- fwrite(&dn1,sizeof(float),1,fpi1);
- // }
- /*
- if(i>iy && i<iy+iH && j>ix && j<ix+iW) //for small
- {
- dn1=file2[(i-iy)*iW+(j-ix)];
- }
- else
- {
- dn1=file1[i*iw+j];
- }
- file3[i*iw+j]=dn1;
- // printf("check3\n");
- //fwrite(&dn1,sizeof(float),1,fpo);
- //printf("i=%d j=%d dn1=%f\n",i,j,dn1);
- */
- }
- }
- printf("check2\n");
- //fwrite(&file1,sizeof(float),iw*ih,fpo);
- //free(file1);
- free(file2);
- //free(file3);
- fclose(fpi1);
- fclose(fpi2);
- // fclose(fpo);
- }
Advertisement
Add Comment
Please, Sign In to add comment