From: hackbard Date: Mon, 15 Sep 2003 22:22:28 +0000 (+0000) Subject: fixed write_bmp function (working now!) X-Git-Tag: fpb~12 X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=385dd1d28c455f57ecdbdc61766607123a0c5063;p=physik%2Fnlsop.git fixed write_bmp function (working now!) --- diff --git a/nlsop.c b/nlsop.c index 372af4e..ec8e4d3 100644 --- a/nlsop.c +++ b/nlsop.c @@ -307,7 +307,7 @@ int calc_max_extra(d3_lattice *d3_l) int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) { - int fd,i,j,size=0; + int fd,i,j,size=0,foo=0; int width=0,height=0; char bmpfile[MAX_CHARS]; char buf[128]; @@ -315,21 +315,24 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) if(window==1) { sprintf(bmpfile,"x-z_%d.bmp",y); - size=3*d3_l->max_x*d3_l->max_z; + foo=3*d3_l->max_x; + size=(foo+(4-foo%4))*d3_l->max_z; width=d3_l->max_x; height=d3_l->max_z; } if(window==2) { sprintf(bmpfile,"y-z_%d.bmp",x); - size=3*d3_l->max_y*d3_l->max_z; + foo=3*d3_l->max_y; + size=(foo+(4-foo%4))*d3_l->max_z; width=d3_l->max_y; height=d3_l->max_z; } if(window==3) { sprintf(bmpfile,"x-y_%d.bmp",z); - size=3*d3_l->max_x*d3_l->max_y; + foo=3*d3_l->max_x; + size=(foo+(4-foo%4))*d3_l->max_y; width=d3_l->max_x; height=d3_l->max_y; } @@ -391,6 +394,15 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) return-1; } } + if(foo%4) + { + memset(buf,0,4-foo%4); + if(write(fd,buf,4-foo%4)<4-foo%4) + { + puts("failed writing 4 byte ending"); + return -1; + } + } } } if(window==2) @@ -407,6 +419,15 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) return-1; } } + if(foo%4) + { + memset(buf,0,4-foo%4); + if(write(fd,buf,4-foo%4)<4-foo%4) + { + puts("failed writing 4 byte ending"); + return -1; + } + } } } if(window==3) @@ -423,6 +444,15 @@ int write_bmp(d3_lattice *d3_l,int window,u32 x,u32 y,u32 z) return -1; } } + if(foo%4) + { + memset(buf,0,4-foo%4); + if(write(fd,buf,4-foo%4)<4-foo%4) + { + puts("failed writing 4 byte ending"); + return -1; + } + } } } close(fd);