The attached patch partially fixes the problem. You will still need to crop your image manually.

--
Jakub Wilk
diff --git a/fbgrab.c b/fbgrab.c
--- a/fbgrab.c
+++ b/fbgrab.c
@@ -121,7 +121,7 @@
     (void) close(fd);
 }
 
-static void read_framebuffer(char *device, size_t bytes, unsigned char *buf_p)
+static void read_framebuffer(char *device, size_t offset, size_t bytes, unsigned char *buf_p)
 {
     int fd; 
 
@@ -131,6 +131,7 @@
 	exit(EXIT_FAILURE);
     }
 
+    lseek(fd, offset, SEEK_SET);
     if (buf_p == NULL || read(fd, buf_p, bytes) != (ssize_t) bytes) 
 	fatal_error("Error: Not enough memory or data\n");
 }
@@ -306,8 +307,10 @@
     char *outfile = argv[argc-1];
     int optc;
     int vt_num=UNDEFINED, bitdepth=UNDEFINED, height=UNDEFINED, width=UNDEFINED;
+    int yoffset = 0;
     int old_vt=UNDEFINED;
     size_t buf_size;
+    size_t offset;
     char infile[MAX_LEN];
     struct fb_var_screeninfo fb_varinfo;
     int waitbfg=0; /* wait before grabbing (for -C )... */
@@ -397,15 +400,20 @@
 	    bitdepth = (int) fb_varinfo.bits_per_pixel;
 	
 	if (UNDEFINED == width)
-	    width = (int) fb_varinfo.xres;
+	    width = (int) fb_varinfo.xres_virtual;
 	
 	if (UNDEFINED == height)
+	{
 	    height = (int) fb_varinfo.yres;
+	    yoffset = (int) fb_varinfo.yoffset;
+	}
 
 	strncpy(infile, device, MAX_LEN - 1);
     }
     
-    buf_size = width * height * (((unsigned int) bitdepth + 7) >> 3);
+    const size_t bytes_per_line = width * (((unsigned int) bitdepth + 7) >> 3);
+    buf_size = height * bytes_per_line;
+    offset = yoffset * bytes_per_line;
 
     buf_p = malloc(buf_size);
     
@@ -414,7 +422,7 @@
 
     memset(buf_p, 0, buf_size);
 
-    read_framebuffer(infile, buf_size, buf_p);
+    read_framebuffer(infile, offset, buf_size, buf_p);
 
     if (UNDEFINED != old_vt)
 	(void) change_to_vt((unsigned short int) old_vt);

Reply via email to