X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=bmp%2Fbmp.c;h=520b2838b061d3a6c9c04b2a14ac1effe557438b;hb=577595e067a03be4d9bb9c7f1277047e7a6eb5de;hp=94e11d15c266469f7639fc3e2b65882d7d304774;hpb=515c7fc6da820714686f9bfc87ccb9743c57d692;p=my-code%2Fapi.git diff --git a/bmp/bmp.c b/bmp/bmp.c index 94e11d1..520b283 100644 --- a/bmp/bmp.c +++ b/bmp/bmp.c @@ -138,6 +138,32 @@ int bmp_write_file(t_bmp *bmp) { return B_SUCCESS; } +int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz) { + + 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; + } + + /* obsolete - we point to wanted memory instead + if(bmp_alloc_map(dst)!=B_SUCCESS) { + dprintf(dst->outfd,"[bmp] no map memory\n"); + return B_E_MEM; + } + */ + + /* obsolete - we point to wanted memory instead + memcpy(dst->map,src->map+(src->height-dz)*src->width, + dz*src->width*sizeof(t_pixel)); + */ + dst->map=src->map+(src->height-dz)*src->width; + + return B_SUCCESS; +} + int bmp_read_file(t_bmp *bmp) { unsigned char buf[BMP_H_SIZE+BMP_I_SIZE]; @@ -167,17 +193,20 @@ int bmp_read_file(t_bmp *bmp) { return B_HI_FAIL; } - bmp->map=(t_pixel *)malloc(bmp->info.width*bmp->info.height*sizeof(t_pixel)); + bmp->width=bmp->info.width; + bmp->height=bmp->info.height; + + bmp->map=(t_pixel *)malloc(bmp->width*bmp->height*sizeof(t_pixel)); if(bmp->map==NULL) { dprintf(bmp->outfd,"[bmp] malloc of map memory failed\n"); return B_E_MEM; } - crop=(bmp->info.imagesize/bmp->info.height)%4; - xsize=(bmp->info.bpp/8)*bmp->info.width; + crop=bmp->info.imagesize/bmp->height-bmp->width*(bmp->info.bpp/8); + xsize=(bmp->info.bpp/8)*bmp->width; - for(y=0;yinfo.height;y++) { - if(read(bmp->fd,bmp->map+y*bmp->info.width,xsize)height;y++) { + if(read(bmp->fd,bmp->map+y*bmp->width,xsize)outfd,"[bmp] reading image data of line %d failed\n",y); return B_E_READ_DATA; }