+ for(y=0;y<bmp->height;y++) {
+ if(write(bmp->fd,bmp->map+y*bmp->width,xsize)<xsize) {
+ dprintf(bmp->outfd,"[bmp] unable to write image data line %d\n",y);
+ return B_E_WRITE_DATA;
+ }
+ if(write(bmp->fd,buf,fill)<fill) {
+ dprintf(bmp->outfd,"[bmp] unable to write fill bytes\n");
+ return B_E_WRITE_DATA;
+ }
+ }
+
+ close(bmp->fd);
+
+ return B_SUCCESS;
+}
+
+int bmp_cut_grab_bottom(t_bmp *dst,t_bmp *src,int dz,unsigned char m) {
+
+ int off;
+
+ dst->width=src->width;
+ dst->height=dz;
+
+ if(dz>src->height) {
+ dprintf(src->outfd,"[bmp] cut region greater than image height\n");
+ return B_E_GEOMETRY;
+ }
+
+ if(bmp_alloc_map(dst)!=B_SUCCESS) {
+ dprintf(dst->outfd,"[bmp] no map memory\n");
+ return B_E_MEM;
+ }
+
+ off=(m==GRAB)?0:(src->height-dz)*src->width;
+ memcpy(dst->map,src->map+off,dz*src->width*sizeof(t_pixel));