grab cut function implemented (memcpy data to leave orig untouched)
authorhackbard <hackbard>
Tue, 19 Oct 2004 15:22:55 +0000 (15:22 +0000)
committerhackbard <hackbard>
Tue, 19 Oct 2004 15:22:55 +0000 (15:22 +0000)
bmp/bmp.c
bmp/bmp.h

index 520b283..cc53c7c 100644 (file)
--- a/bmp/bmp.c
+++ b/bmp/bmp.c
@@ -138,7 +138,9 @@ int bmp_write_file(t_bmp *bmp) {
   return B_SUCCESS;
 }
 
-int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz) {
+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;
@@ -148,18 +150,13 @@ int bmp_cut_bottom(t_bmp *dst,t_bmp *src,int dz) {
     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;
+  off=(m==GRAB)?0:(src->height-dz)*src->width;
+  memcpy(dst->map,src->map+off,dz*src->width*sizeof(t_pixel));
 
   return B_SUCCESS;
 }
index 40e6df4..f9216a8 100644 (file)
--- a/bmp/bmp.h
+++ b/bmp/bmp.h
@@ -28,6 +28,7 @@
 #define MAX_CHARS_FILE 32
 #define BMP_H_SIZE 14
 #define BMP_I_SIZE 40
+#define GRAB 'g'
 
 /* bmp specific variables */
 typedef struct s_bmp_hdr {
@@ -78,7 +79,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_cut_grab_bottom(t_bmp *dst,t_bmp *src,int dz,unsigned char m);
 int bmp_read_file(t_bmp *bmp);
 
 #endif