diff options
Diffstat (limited to '')
-rw-r--r-- | src/kern-linux.c | 14 | ||||
-rw-r--r-- | src/kern.h | 14 | ||||
-rw-r--r-- | src/png.c | 6 | ||||
-rw-r--r-- | src/png.h | 4 | ||||
-rw-r--r-- | src/pnm.c | 6 | ||||
-rw-r--r-- | src/pnm.h | 4 | ||||
-rw-r--r-- | src/scrotty.c | 12 |
7 files changed, 42 insertions, 18 deletions
diff --git a/src/kern-linux.c b/src/kern-linux.c index 00930f1..7e31d1b 100644 --- a/src/kern-linux.c +++ b/src/kern-linux.c @@ -71,10 +71,13 @@ get_fbpath (int altpath, int fbno) * @param fbpath The path to the framebuffer device.. * @param width Output parameter for the width of the image. * @param height Output parameter for the height of the image. + * @parma data Additional data to pass to `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int -measure (int fbno, char *restrict fbpath, long *restrict width, long *restrict height) +measure (int fbno, char *restrict fbpath, long *restrict width, + long *restrict height, void **restrict data) { static char buf[sizeof (SYSDIR "/class/graphics/fb/virtual_size") + 3 * sizeof(int)]; /* The string "/class/graphics/fb/virtual_size" is large enought for the call (*) "*/ @@ -126,11 +129,12 @@ measure (int fbno, char *restrict fbpath, long *restrict width, long *restrict h * (a whole number of pixels where available,) * otherwise, set to the number of bytes a * pixel is encoded. + * @param data Data from `measure`. * @return Zero on success, -1 on error. */ int -convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, - size_t n, size_t *restrict adjustment) +convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, size_t n, + size_t *restrict adjustment, void *restrict data) { const uint32_t *restrict pixel; int r, g, b; @@ -169,10 +173,12 @@ convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, * pixel is encoded. * @param state Use this to keep track of where in the you * stopped. It will be 0 on the first call. + * @param data Data from `measure`. * @return Zero on success, -1 on error. */ int convert_fb_to_png (png_struct *pngbuf, png_byte *restrict pixbuf, const char *restrict buf, - size_t n, long width3, size_t *restrict adjustment, long *restrict state) + size_t n, long width3, size_t *restrict adjustment, long *restrict state, + void *restrict data) { const uint32_t *restrict pixel; int r, g, b; @@ -58,9 +58,12 @@ char *get_fbpath (int altpath, int fbno); * @param fbpath The path to the framebuffer device.. * @param width Output parameter for the width of the image. * @param height Output parameter for the height of the image. + * @parma data Additional data to pass to `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ -int measure (int fbno, char *restrict fbpath, long *restrict width, long *restrict height); +int measure (int fbno, char *restrict fbpath, long *restrict width, + long *restrict height, void **restrict data); /** * Convert read data from a framebuffer to PNM pixel data. @@ -72,10 +75,11 @@ int measure (int fbno, char *restrict fbpath, long *restrict width, long *restri * (a whole number of pixels where available,) * otherwise, set to the number of bytes a * pixel is encoded. + * @param data Data from `measure`. * @return Zero on success, -1 on error. */ -int convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, - size_t n, size_t *restrict adjustment); +int convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, size_t n, + size_t *restrict adjustment, void *restrict data); /** * Convert read data from a framebuffer to PNG pixel data. @@ -90,8 +94,10 @@ int convert_fb_to_pnm (FILE *restrict file, const char *restrict buf, * pixel is encoded. * @param state Use this to keep track of where in the you * stopped. It will be 0 on the first call. + * @param data Data from `measure`. * @return Zero on success, -1 on error. */ int convert_fb_to_png (png_struct *pngbuf, png_byte *restrict pixbuf, const char *restrict buf, - size_t n, long width3, size_t *restrict adjustment, long *restrict state); + size_t n, long width3, size_t *restrict adjustment, long *restrict state, + void *restrict data); @@ -37,10 +37,12 @@ * @param width The width of the image. * @param height The height of the image. * @param imgfd The file descriptor connected to conversion process's stdin. + * @param data Additional data for `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int -save_png (int fbfd, long width, long height, int imgfd) +save_png (int fbfd, long width, long height, int imgfd, void *restrict data) { char buf[8 << 10]; FILE *file = NULL; @@ -94,7 +96,7 @@ save_png (int fbfd, long width, long height, int imgfd) /* Convert read pixels. */ if (convert_fb_to_png (pngbuf, pixbuf, buf, (size_t)got, - width3, &adjustment, &state) < 0) + width3, &adjustment, &state, data) < 0) goto fail; /* If we read a whole number of pixels, reset the buffer, otherwise, @@ -58,8 +58,10 @@ * @param width The width of the image. * @param height The height of the image. * @param imgfd The file descriptor connected to conversion process's stdin. + * @param data Additional data for `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int -save_png (int fbfd, long width, long height, int imgfd); +save_png (int fbfd, long width, long height, int imgfd, void *restrict data); @@ -55,10 +55,12 @@ const char* inttable[] = * @param width The width of the image. * @param height The height of the image. * @param imgfd The file descriptor connected to conversion process's stdin. + * @param data Additional data for `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int -save_pnm (int fbfd, long width, long height, int imgfd) +save_pnm (int fbfd, long width, long height, int imgfd, void *restrict data) { char buf[8 << 10]; FILE *file = NULL; @@ -88,7 +90,7 @@ save_pnm (int fbfd, long width, long height, int imgfd) got += off; /* Convert read pixels. */ - if (convert_fb_to_pnm (file, buf, (size_t)got, &adjustment) < 0) + if (convert_fb_to_pnm (file, buf, (size_t)got, &adjustment, data) < 0) goto fail; /* If we read a whole number of pixels, reset the buffer, otherwise, @@ -54,7 +54,9 @@ extern const char* inttable[]; * @param width The width of the image. * @param height The height of the image. * @param imgfd The file descriptor connected to conversion process's stdin. + * @param data Additional data for `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ -int save_pnm (int fbfd, long width, long height, int imgfd); +int save_pnm (int fbfd, long width, long height, int imgfd, void *restrict data); diff --git a/src/scrotty.c b/src/scrotty.c index 4bc6982..32b2168 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -71,10 +71,13 @@ static int try_alt_fbpath = 0; * @param width The width of the image. * @param height The height of the image. * @param raw Save in PNM? + * @param data Additional data for `convert_fb_to_pnm` + * and `convert_fb_to_png`. * @return Zero on success, -1 on error. */ static int -save (const char *fbpath, const char *imgpath, long width, long height, int raw) +save (const char *fbpath, const char *imgpath, long width, + long height, int raw, void *restrict data) { int imgfd = -1, fbfd; int saved_errno; @@ -91,7 +94,7 @@ save (const char *fbpath, const char *imgpath, long width, long height, int raw) FILE_FAILURE (fbpath); /* Save image. */ - if ((raw ? save_pnm : save_png) (fbfd, width, height, imgfd) < 0) + if ((raw ? save_pnm : save_png) (fbfd, width, height, imgfd, data) < 0) goto fail; close (fbfd); @@ -194,6 +197,7 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) char *fbpath; /* Statically allocate string is returned. */ char *execargs = NULL; long width, height; + void *data = NULL; int i, rc = 0, saved_errno = 0; /* Get pathname for framebuffer, and stop if we have read all existing ones. */ @@ -202,7 +206,7 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) return 1; /* Get the size of the framebuffer. */ - if (measure (fbno, fbpath, &width, &height) < 0) + if (measure (fbno, fbpath, &width, &height, &data) < 0) goto fail; /* Get output pathname. */ @@ -220,7 +224,7 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) } /* Take a screenshot of the current framebuffer. */ - if (save (fbpath, imgpath, width, height, raw) < 0) + if (save (fbpath, imgpath, width, height, raw, data) < 0) goto fail; fprintf (stderr, _("Saved framebuffer %i to %s.\n"), fbno, imgpath); |