changes in bmp api
authorhackbard <hackbard>
Mon, 18 Oct 2004 19:32:31 +0000 (19:32 +0000)
committerhackbard <hackbard>
Mon, 18 Oct 2004 19:32:31 +0000 (19:32 +0000)
bmp/bmp.c
bmp/bmp.h

index 94e11d1..d42eefd 100644 (file)
--- a/bmp/bmp.c
+++ b/bmp/bmp.c
@@ -138,6 +138,30 @@ int bmp_write_file(t_bmp *bmp) {
   return B_SUCCESS;
 }
 
+int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz) {
+
+  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=(src->height-dz-1)*src->width;
+  printf("debug: off = %d height = %d dz = %d\n",off,src->height,dz);
+  memcpy(dst->map,&(src->map[off]),dz*src->width*sizeof(t_pixel));
+
+  return B_SUCCESS;
+}
+
 int bmp_read_file(t_bmp *bmp) {
 
   unsigned char buf[BMP_H_SIZE+BMP_I_SIZE];
@@ -167,17 +191,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;y<bmp->info.height;y++) {
-    if(read(bmp->fd,bmp->map+y*bmp->info.width,xsize)<xsize) {
+  for(y=0;y<bmp->height;y++) {
+    if(read(bmp->fd,bmp->map+y*bmp->width,xsize)<xsize) {
       dprintf(bmp->outfd,"[bmp] reading image data of line %d failed\n",y);
       return B_E_READ_DATA;
     }
index 4dd47f5..40e6df4 100644 (file)
--- a/bmp/bmp.h
+++ b/bmp/bmp.h
@@ -24,6 +24,7 @@
 #define B_E_MEM -7
 #define B_E_READ_DATA -8
 #define B_E_WRITE_DATA -9
+#define B_E_GEOMETRY -10
 #define MAX_CHARS_FILE 32
 #define BMP_H_SIZE 14
 #define BMP_I_SIZE 40
@@ -77,6 +78,7 @@ int bmp_shutdown(t_bmp *bmp);
 int bmp_check_header_and_info(t_bmp *bmp);
 int bmp_alloc_map(t_bmp *bmp);
 int bmp_write_file(t_bmp *bmp);
+int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz);
 int bmp_read_file(t_bmp *bmp);
 
 #endif