C言語のプログラミングの解答例又は修正箇所をおしえていただきたいのですが
#include <stdio.h>
int main(int argc, char **argv){
int a,b,c,g,r,i,j,ll; int blue,green,red; FILE *fpi,*fpo;
unsigned long size,head,width,height,offset; unsigned long comp,isize,ucolor,icolor;
unsigned short plane,bitsize; unsigned long wreso,hreso;
unsigned char *image; char infile[1024] = "t.bmp"; char outfile[1024] = "g.bmp";
long ww,hh; long w3,h3; unsigned char *img; unsigned char *img2;
int bai1,bai2; bai1=1,bai2=3;
fpi=fopen(infile,”rb");
for(i=0;i<2;i++){c=getc(fpi);} for(i=0,size=0;i<4;i++){size += (getc(fpi))<<(8*i);}
for(i=0;i<4;i++){c=getc(fpi);}
for(i=0,offset=0;i<4;i++){offset += (getc(fpi))<<(8*i);}
↑と同じようhead,width,height,plane,bitsize,comp,isize,wreso,hreso,ucolor,icolorを書く(ただしplane,bitsizeはi<2)
hh=height*bai1/bai2; ww=width *bai1/bai2;
img2 = (unsigned char*)malloc(sizeof(char)*3*ww*hh);
for(j=0;j<hh;j++){
for(i=0;i<ww;i++){ int i1,j1,i2,j2; double x,pa,pb,pc,pd,x11,x21,x12,x22; int bb,gg,rr;
i1=(i*(width-1))/(ww-1); i2=i1+1; x=(i*(width-1)*1.0)/((double)(ww-1)); pa=x-i1; pb=i2-x; j1=(j*(height-1))/(hh-1); j2=j1+1; x=(j*(height-1)*1.0)/((double)(hh-1)); pc=x-j1; pd=j2-x;
x11=(double)img[j1*width*3+i1*3+0;] x21=(double)img[j1*width*3+i2*3+0];
x12=(double)img[j2*width*3+i1*3+0]; x22=(double)img[j2*width*3+i2*3+0];
bb=(((x11*pb+x21*pa)/(pa+pb))*pd+((x12*pb+x22*pa)/(pa+pb))*pc)/(pc+pd);
x11=(double)img[j1*width*3+i1*3+1]; x21=(double)img[j1*width*3+i2*3+1];
x12=(double)img[j2*width*3+i1*3+1]; x22=(double)img[j2*width*3+i2*3+1];
gg=(((x11*pb+x21*pa)/(pa+pb))*pd+((x12*pb+x22*pa)/(pa+pb))*pc)/(pc+pd);
x11=(double)img[j1*width*3+i1*3+2]; x21=(double)img[j1*width*3+i2*3+2];
x12=(double)img[j2*width*3+i1*3+2]; x22=(double)img[j2*width*3+i2*3+2];
rr=(((x11*pb+x21*pa)/(pa+pb))*pd+((x12*pb+x22*pa)/(pa+pb))*pc)/(pc+pd);;
img2[j*ww*3+i*3+0]=(unsigned char)(bb&0xff); img2[j*ww*3+i*3+1]=(unsigned char)(gg&0xff);
img2[j*ww*3+i*3+2]=(unsigned char)(rr&0xff); } }
w3=ww*3; h3=hh*3;
if((w3*3)%4==0){size=offset+w3*h3*3;} else{size= offset+w3*h3*3-(4-(w3*3)%4);}
isize = size-offset;
fpo=fopen(outfile,"wb"); putc('B', fpo); putc('M', fpo); for(i=0;i<4;i++){putc(((size>>(8*i))&0xff),fpo);} for(i=0;i<4;i++){putc(0x0,fpo);}
for(i=0;i<4;i++){putc((((offset)>>(8*i)&0xff),fpo);} ↑と同じようhead,width,height,plane,bitsize,comp,isize,wreso,hreso,ucolor,icolorを書く(ただしplane,bitsizeはi<2)
fwrite(&w3 ,sizeof(long),1,fpo);
↑と同じように&h,&offset,&head,&width,&height,&plane,&bitsize,&comp,&isize,&wreso,&hreso,&ucolor,&icolorを書く
for(jj=0;jj<3;jj++){
for(j=hh-1;j>=0;j--){
ll=0;
for(ii=0;ii<3;ii++){
for(i=0;i<ww;i++){
putc(img2[j*ww*3+i*3+0],fpo); putc(img2[j*ww*3+i*3+1],fpo); putc(img2[j*ww*3+i*3+2],fpo);
ll+=3; } } ll=ll%4;
if(ll!=0){for(i=0;i<(4-ll);i++)putc(0x0,fpo);} } } printf("Done\n"); fclose(fpo);
printf("%s -> %s\n",infile,outfile); }
お礼
ありがとうございました。