diff options
Diffstat (limited to '')
-rw-r--r-- | src/info.c | 1 | ||||
-rw-r--r-- | src/kern-linux.c | 45 | ||||
-rw-r--r-- | src/kern.h | 19 | ||||
-rw-r--r-- | src/png.c | 3 | ||||
-rw-r--r-- | src/png.h | 3 | ||||
-rw-r--r-- | src/pnm.c | 120 | ||||
-rw-r--r-- | src/pnm.h | 62 | ||||
-rw-r--r-- | src/scrotty.auto-completion | 3 | ||||
-rw-r--r-- | src/scrotty.c | 31 | ||||
-rw-r--r-- | src/scrotty.sv.auto-completion | 3 |
10 files changed, 16 insertions, 274 deletions
@@ -36,7 +36,6 @@ print_help (void) "\t-h, --help Print usage information.\n" "\t-v, --version Print program name and version.\n" "\t-c, --copyright Print copyright information.\n" - "\t-r, --raw Save in PNM rather than in PNG.\n" "\t-e, --exec CMD Command to run for each saved image.\n" "\n" "SPECIAL STRINGS\n" diff --git a/src/kern-linux.c b/src/kern-linux.c index 7e31d1b..e6ca1a2 100644 --- a/src/kern-linux.c +++ b/src/kern-linux.c @@ -18,7 +18,6 @@ */ #include "common.h" #include "kern.h" -#include "pnm.h" #include "png.h" @@ -71,8 +70,7 @@ 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`. + * @parma data Additional data to pass to `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int @@ -120,47 +118,6 @@ measure (int fbno, char *restrict fbpath, long *restrict width, /** - * Convert read data from a framebuffer to PNM pixel data. - * - * @param file The output image file. - * @param buf Buffer with read data. - * @param n The number of read characters. - * @param adjustment Set to zero if all bytes were converted - * (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, void *restrict data) -{ - const uint32_t *restrict pixel; - int r, g, b; - size_t off; - - for (off = 0; off < n; off += 4) - { - /* A pixel in the framebuffer is formatted as `%{blue}%{green}%{red}%{x}` - in big-endian binary, or `%{x}%{red}%{green}%{blue}` in little-endian binary. */ - pixel = (const uint32_t *)(buf + off); - r = (*pixel >> 16) & 255; - g = (*pixel >> 8) & 255; - b = (*pixel >> 0) & 255; - - if (SAVE_PNM_PIXEL (file, r, g, b) < 0) - goto fail; - } - - *adjustment = (off != n ? 4 : 0); - return 0; - fail: - return -1; -} - - -/** * Convert read data from a framebuffer to PNG pixel data. * * @param file The output image file. @@ -58,30 +58,13 @@ 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`. + * @parma data Additional data to pass to `convert_fb_to_png`. * @return Zero on success, -1 on error. */ 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. - * - * @param file The output image file. - * @param buf Buffer with read data. - * @param n The number of read characters. - * @param adjustment Set to zero if all bytes were converted - * (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, void *restrict data); - -/** * Convert read data from a framebuffer to PNG pixel data. * * @param file The output image file. @@ -37,8 +37,7 @@ * @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`. + * @param data Additional data for `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int @@ -58,8 +58,7 @@ * @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`. + * @param data Additional data for `convert_fb_to_png`. * @return Zero on success, -1 on error. */ int diff --git a/src/pnm.c b/src/pnm.c deleted file mode 100644 index 86fa738..0000000 --- a/src/pnm.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * scrotty — Screenshot program for Linux's TTY - * - * Copyright © 2014, 2015 Mattias Andrée (maandree@member.fsf.org) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -#include "common.h" -#include "pnm.h" -#include "kern.h" - - - -#define LIST_0_9(P) P"0\n", P"1\n", P"2\n", P"3\n", P"4\n", P"5\n", P"6\n", P"7\n", P"8\n", P"9\n" -/** - * [0, 255]-integer-to-text convertion lookup table for faster conversion from - * raw framebuffer data to the PNM format. The values have a whitespace at the - * end for even faster conversion. - * Lines should not be longer than 70 (although most programs will probably - * work even if there are longer lines), therefore the selected whitespace - * is LF (new line). - * - * ASCII has wider support than binary, and is create for version control, - * especifially with one datum per line. - */ -const char* inttable[] = - { - LIST_0_9(""), LIST_0_9("1"), LIST_0_9("2"), LIST_0_9("3"), LIST_0_9("4"), - LIST_0_9("5"), LIST_0_9("6"), LIST_0_9("7"), LIST_0_9("8"), LIST_0_9("9"), - - LIST_0_9("10"), LIST_0_9("11"), LIST_0_9("12"), LIST_0_9("13"), LIST_0_9("14"), - LIST_0_9("15"), LIST_0_9("16"), LIST_0_9("17"), LIST_0_9("18"), LIST_0_9("19"), - - LIST_0_9("20"), LIST_0_9("21"), LIST_0_9("22"), LIST_0_9("23"), LIST_0_9("24"), - "250\n", "251\n", "252\n", "253\n", "254\n", "255\n" - }; - - - -/** - * Create an PNM file. - * - * @param fbfd The file descriptor connected to framebuffer device. - * @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, void *restrict data) -{ - char buf[8 << 10]; - FILE *file = NULL; - ssize_t got, off; - size_t adjustment; - int saved_errno; - - /* Create a FILE *, for writing, for the image file. */ - file = fdopen (imgfd, "w"); - if (file == NULL) - goto fail; - - /* The PNM image should begin with `P3\n%{width} %{height}\n%{colour max=255}\n`. - ('\n' and ' ' can be exchanged at will.) */ - if (fprintf (file, "P3\n%li %li\n255\n", width, height) < 0) - goto fail; - - /* Convert raw framebuffer data into a PNM image. */ - for (off = 0;;) - { - /* Read data from the framebuffer, we may have up to 3 bytes buffered. */ - got = read (fbfd, buf + off, sizeof (buf) - (size_t)off * sizeof (char)); - if (got < 0) - goto fail; - if (got == 0) - break; - got += off; - - /* Convert read pixels. */ - 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, - move the unconverted bytes to the beginning of the buffer. */ - if (adjustment) - { - off -= (ssize_t)adjustment; - memcpy (buf, buf + off, (size_t)(got - off) * sizeof (char)); - off = got - off; - } - else - off = 0; - } - - /* Close file and return successfully. */ - fflush (file); - fclose (file); - return 0; - - fail: - saved_errno = errno; - if (file != NULL) - fclose (file); - errno = saved_errno; - return -1; -} - diff --git a/src/pnm.h b/src/pnm.h deleted file mode 100644 index f13972c..0000000 --- a/src/pnm.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - * scrotty — Screenshot program for Linux's TTY - * - * Copyright © 2014, 2015 Mattias Andrée (maandree@member.fsf.org) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - - -/** - * Store a pixel to a PNM image. - * - * A pixel in the PNM image is formatted as `%{red} %{green} %{blue} ` in text. - * - * @param F:FILE * The file whither the pixel shall be save. - * @param R:int The [0, 255]-value on the red subpixel. - * @param G:int The [0, 255]-value on the green subpixel. - * @param B:int The [0, 255]-value on the blue subpixel. - * @return Positive on success (not zero!), -1 on error. - */ -#define SAVE_PNM_PIXEL(F, R, G, B) \ - fprintf (F, "%s%s%s", inttable[R], inttable[G], inttable[B]) - - -/** - * [0, 255]-integer-to-text convertion lookup table for faster conversion from - * raw framebuffer data to the PNM format. The values have a whitespace at the - * end for even faster conversion. - * Lines should not be longer than 70 (although most programs will probably - * work even if there are longer lines), therefore the selected whitespace - * is LF (new line). - * - * ASCII is wider supported than binary, and is create for version control, - * especifially with one datum per line. - */ -extern const char* inttable[]; - - -/** - * Create an PNM file. - * - * @param fbfd The file descriptor connected to framebuffer device. - * @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, void *restrict data); - diff --git a/src/scrotty.auto-completion b/src/scrotty.auto-completion index 8e9e91f..83cb284 100644 --- a/src/scrotty.auto-completion +++ b/src/scrotty.auto-completion @@ -11,9 +11,6 @@ (unargumented (options -c --copyright) (complete --copyright) (desc 'Print copyright information.')) - (unargumented (options -r --raw) (complete --raw) - (desc 'Save in PNM rather than in PNG.')) - (argumented (options -e --exec) (complete --exec) (arg COMMAND) (files -0) (desc 'Command to run for each saved image.')) diff --git a/src/scrotty.c b/src/scrotty.c index 30c1dcc..e95b4e3 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -20,7 +20,6 @@ #include "common.h" #include "kern.h" #include "info.h" -#include "pnm.h" #include "png.h" #include "pattern.h" @@ -70,14 +69,12 @@ static int try_alt_fbpath = 0; * @param imgname The pathname of the output image. * @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`. + * @param data Additional data for `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, void *restrict data) + long height, void *restrict data) { int imgfd = -1, fbfd = -1; int saved_errno; @@ -94,7 +91,7 @@ save (const char *fbpath, const char *imgpath, long width, FILE_FAILURE (fbpath); /* Save image. */ - if ((raw ? save_pnm : save_png) (fbfd, width, height, imgfd, data) < 0) + if (save_png (fbfd, width, height, imgfd, data) < 0) goto fail; close (fbfd); @@ -183,16 +180,15 @@ exec_image (char *flatten_args) * Take a screenshot of a framebuffer. * * @param fbno The number of the framebuffer. - * @param raw Save in PNM rather than in PNG?. * @param filepattern The pattern for the filename, `NULL` for default. * @param execpattern The pattern for the command to run to * process the image, `NULL` for none. * @return Zero on success, -1 on error, 1 if the framebuffer does not exist. */ static int -save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) +save_fb (int fbno, const char *filepattern, const char *execpattern) { - char imgpath_[sizeof ("fb.xyz.") + 2 * 3 * sizeof (int)]; + char imgpath_[sizeof ("fb.png.") + 2 * 3 * sizeof (int)]; char *imgpath = imgpath_; char *fbpath; /* Statically allocate string is returned. */ char *execargs = NULL; @@ -212,9 +208,9 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) /* Get output pathname. */ if (filepattern == NULL) { - sprintf (imgpath, "fb%i.%s", fbno, (raw ? "pnm" : "png")); + sprintf (imgpath, "fb%i.png", fbno); for (i = 2; access (imgpath, F_OK) == 0; i++) - sprintf (imgpath, "fb%i.%s.%i", fbno, (raw ? "pnm" : "png"), i); + sprintf (imgpath, "fb%i.png.%i", fbno, i); } else { @@ -224,7 +220,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, data) < 0) + if (save (fbpath, imgpath, width, height, data) < 0) goto fail; fprintf (stderr, _("Saved framebuffer %i to %s.\n"), fbno, imgpath); @@ -257,14 +253,13 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern) /** * Take a screenshot of all framebuffers. * - * @param raw Save in PNM rather than in PNG?. * @param filepattern The pattern for the filename, `NULL` for default. * @param execpattern The pattern for the command to run to * process thes image, `NULL` for none. * @return Zero on success, -1 on error, 1 if no framebuffer exists. */ static -int save_fbs (int raw, const char *filepattern, const char *exec) +int save_fbs (const char *filepattern, const char *exec) { int r, fbno, found = 0; @@ -272,7 +267,7 @@ int save_fbs (int raw, const char *filepattern, const char *exec) /* Take a screenshot of each framebuffer. */ for (fbno = 0;; fbno++) { - r = save_fb (fbno, raw, filepattern, exec); + r = save_fb (fbno, filepattern, exec); if (r < 0) goto fail; else if (r == 0) @@ -326,7 +321,7 @@ main (int argc, char *argv[]) #define USAGE_ASSERT(ASSERTION, MSG) \ do { if (!(ASSERTION)) EXIT_USAGE (MSG); } while (0) - int r, raw = 0; + int r, all = 1, devno = 0; char *exec = NULL; char *filepattern = NULL; struct option long_options[] = @@ -334,7 +329,6 @@ main (int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"copyright", no_argument, NULL, 'c'}, - {"raw", no_argument, NULL, 'r'}, {"exec", required_argument, NULL, 'e'}, {NULL, 0, NULL, 0 } }; @@ -355,7 +349,6 @@ main (int argc, char *argv[]) else if (r == 'h') return -(print_help ()); else if (r == 'v') return -(print_version ()); else if (r == 'c') return -(print_copyright ()); - else if (r == 'r') raw = 1; else if (r == 'e') { USAGE_ASSERT (exec == NULL, _("--exec is used twice.")); @@ -373,7 +366,7 @@ main (int argc, char *argv[]) } /* Take a screenshot of each framebuffer. */ - r = save_fbs (raw, filepattern, exec); + r = save_fbs (filepattern, exec); if (r < 0) goto fail; if (r > 0) diff --git a/src/scrotty.sv.auto-completion b/src/scrotty.sv.auto-completion index 24bd201..73e2c2a 100644 --- a/src/scrotty.sv.auto-completion +++ b/src/scrotty.sv.auto-completion @@ -11,9 +11,6 @@ (unargumented (options -c --copyright) (complete --copyright) (desc 'Skriv ut upphovsrättsinformation.')) - (unargumented (options -r --raw) (complete --raw) - (desc 'Spara som PNM-bild snarare än som PNG-bild.')) - (argumented (options -e --exec) (complete --exec) (arg KOMMANDO) (files -0) (desc 'Kör ett Kommando för varje sparad bild.')) |