nsxivef0ed32
Removed exif support; made gif support non-optional
+16 −160
7 files changed
- M Makefile +5 −8
- M README.md +7 −12
- D config.c +0 −38
- M config.def.h +0 −12
- M image.c +3 −67
- M options.c +0 −13
- M thumbs.c +1 −10
| @@ -3,7 +3,7 @@ VERSION = git-20120211 | |||
| 3 | 3 | CC = gcc | |
| 4 | 4 | CFLAGS = -ansi -Wall -pedantic -O2 | |
| 5 | 5 | LDFLAGS = | |
| 6 | − | LIBS = -lX11 -lImlib2 | |
| 6 | + | LIBS = -lX11 -lImlib2 -lgif | |
| 7 | 7 | ||
| 8 | 8 | PREFIX = /usr/local | |
| 9 | 9 | MANPREFIX = $(PREFIX)/share/man | |
| @@ -24,22 +24,19 @@ options: | |||
| 24 | 24 | @echo "CC $<" | |
| 25 | 25 | @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< | |
| 26 | 26 | ||
| 27 | − | $(OBJ) config: Makefile config.h | |
| 28 | − | ||
| 29 | − | config: config.c | |
| 30 | − | @$(CC) $(CFLAGS) -o $@ $@.c | |
| 27 | + | $(OBJ): Makefile config.h | |
| 31 | 28 | ||
| 32 | 29 | config.h: | |
| 33 | 30 | @echo "creating $@ from config.def.h" | |
| 34 | 31 | @cp config.def.h $@ | |
| 35 | 32 | ||
| 36 | − | sxiv: $(OBJ) config | |
| 33 | + | sxiv: $(OBJ) | |
| 37 | 34 | @echo "CC -o $@" | |
| 38 | − | @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./config -l) | |
| 35 | + | @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) | |
| 39 | 36 | ||
| 40 | 37 | clean: | |
| 41 | 38 | @echo "cleaning" | |
| 42 | − | @rm -f $(OBJ) config sxiv sxiv-$(VERSION).tar.gz | |
| 39 | + | @rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz | |
| 43 | 40 | ||
| 44 | 41 | install: all | |
| 45 | 42 | @echo "installing executable file to $(DESTDIR)$(PREFIX)/bin" | |
| @@ -1,11 +1,11 @@ | |||
| 1 | 1 | sxiv: Simple (or small or suckless) X Image Viewer | |
| 2 | 2 | ||
| 3 | − | sxiv is an alternative to feh and qiv. Its only dependency besides xlib is | |
| 4 | − | imlib2. The primary goal for writing sxiv is to create an image viewer, which | |
| 5 | − | only has the most basic features required for fast image viewing (the ones I | |
| 6 | − | want). It has vi key bindings and works nicely with tiling window managers. | |
| 7 | − | Its code base should be kept small and clean to make it easy for you to dig | |
| 8 | − | into it and customize it for your needs. | |
| 3 | + | sxiv is an alternative to feh and qiv. Its only dependencies besides xlib are | |
| 4 | + | imlib2 and giflib. The primary goal for writing sxiv is to create an image | |
| 5 | + | viewer, which only has the most basic features required for fast image viewing | |
| 6 | + | (the ones I want). It has vi key bindings and works nicely with tiling window | |
| 7 | + | managers. Its code base should be kept small and clean to make it easy for you | |
| 8 | + | to dig into it and customize it for your needs. | |
| 9 | 9 | ||
| 10 | 10 | Features | |
| 11 | 11 | -------- | |
| @@ -15,14 +15,9 @@ Features | |||
| 15 | 15 | * Thumbnail mode: grid of selectable previews of all images | |
| 16 | 16 | * Ability to cache thumbnails for fast re-loading | |
| 17 | 17 | * Basic support for multi-frame images | |
| 18 | + | * Load all frames from GIF files and play GIF animations | |
| 18 | 19 | * Display image information in window title | |
| 19 | 20 | ||
| 20 | − | Additional features, that need to be enabled at compile-time (in *config.h*), | |
| 21 | − | because they depend on additional libraries: | |
| 22 | − | ||
| 23 | − | * Load all frames from GIF files and play GIF animations (requires giflib) | |
| 24 | − | * Auto-orientate JPEG images according to their EXIF tags (requires libexif) | |
| 25 | − | ||
| 26 | 21 | Screenshots | |
| 27 | 22 | ----------- | |
| 28 | 23 | ||
| @@ -1,38 +0,0 @@ | |||
| 1 | − | #define _POSIX_C_SOURCE 200112L | |
| 2 | − | #define _FEATURE_CONFIG | |
| 3 | − | ||
| 4 | − | #include <stdio.h> | |
| 5 | − | ||
| 6 | − | #include "config.h" | |
| 7 | − | ||
| 8 | − | #define QUOTE(m) #m | |
| 9 | − | #define PUT_MACRO(m) \ | |
| 10 | − | printf(" -D%s=%s", #m, QUOTE(m)) | |
| 11 | − | ||
| 12 | − | int puts_if(const char *s, int c) { | |
| 13 | − | return c ? printf(" %s", s) : 0; | |
| 14 | − | } | |
| 15 | − | ||
| 16 | − | int main(int argc, char **argv) { | |
| 17 | − | int i; | |
| 18 | − | unsigned int n = 0; | |
| 19 | − | ||
| 20 | − | for (i = 1; i < argc; i++) { | |
| 21 | − | switch ((argv[i][0] != '-' || argv[i][2] != '\0') ? -1 : argv[i][1]) { | |
| 22 | − | case 'D': | |
| 23 | − | n += PUT_MACRO(EXIF_SUPPORT); | |
| 24 | − | n += PUT_MACRO(GIF_SUPPORT); | |
| 25 | − | break; | |
| 26 | − | case 'l': | |
| 27 | − | n += puts_if("-lexif", EXIF_SUPPORT); | |
| 28 | − | n += puts_if("-lgif", GIF_SUPPORT); | |
| 29 | − | break; | |
| 30 | − | default: | |
| 31 | − | fprintf(stderr, "%s: invalid argument: %s\n", argv[0], argv[i]); | |
| 32 | − | return 1; | |
| 33 | − | } | |
| 34 | − | } | |
| 35 | − | if (n > 0) | |
| 36 | − | printf("\n"); | |
| 37 | − | return 0; | |
| 38 | − | } | |
| @@ -1,15 +1,3 @@ | |||
| 1 | − | #ifdef _FEATURE_CONFIG | |
| 2 | − | ||
| 3 | − | /* auto-orientate jpeg files according to their exif tags? | |
| 4 | − | * (requires libexif [-lexif] to be installed) | |
| 5 | − | */ | |
| 6 | − | #define EXIF_SUPPORT 0 | |
| 7 | − | /* load all frames from gif files and support gif animations? | |
| 8 | − | * (requires giflib [-lgif] to be installed) | |
| 9 | − | */ | |
| 10 | − | #define GIF_SUPPORT 0 | |
| 11 | − | ||
| 12 | − | #endif | |
| 13 | 1 | #ifdef _WINDOW_CONFIG | |
| 14 | 2 | ||
| 15 | 3 | /* default window dimensions (overwritten via -g option): */ | |
| @@ -17,27 +17,19 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | − | #define _FEATURE_CONFIG | |
| 21 | 20 | #define _IMAGE_CONFIG | |
| 22 | 21 | ||
| 22 | + | #include <stdlib.h> | |
| 23 | 23 | #include <string.h> | |
| 24 | + | #include <sys/types.h> | |
| 24 | 25 | #include <unistd.h> | |
| 26 | + | #include <gif_lib.h> | |
| 25 | 27 | ||
| 26 | 28 | #include "image.h" | |
| 27 | 29 | #include "options.h" | |
| 28 | 30 | #include "util.h" | |
| 29 | 31 | #include "config.h" | |
| 30 | 32 | ||
| 31 | − | #if EXIF_SUPPORT | |
| 32 | − | #include <libexif/exif-data.h> | |
| 33 | − | #endif | |
| 34 | − | ||
| 35 | − | #if GIF_SUPPORT | |
| 36 | − | #include <stdlib.h> | |
| 37 | − | #include <sys/types.h> | |
| 38 | − | #include <gif_lib.h> | |
| 39 | − | #endif | |
| 40 | − | ||
| 41 | 33 | enum { MIN_GIF_DELAY = 50 }; | |
| 42 | 34 | ||
| 43 | 35 | float zoom_min; | |
| @@ -72,55 +64,6 @@ void img_init(img_t *img, win_t *win) { | |||
| 72 | 64 | img->multi.animate = false; | |
| 73 | 65 | } | |
| 74 | 66 | ||
| 75 | − | #if EXIF_SUPPORT | |
| 76 | − | void exif_auto_orientate(const fileinfo_t *file) { | |
| 77 | − | ExifData *ed; | |
| 78 | − | ExifEntry *entry; | |
| 79 | − | int byte_order, orientation; | |
| 80 | − | ||
| 81 | − | if ((ed = exif_data_new_from_file(file->path)) == NULL) | |
| 82 | − | return; | |
| 83 | − | entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION); | |
| 84 | − | if (entry != NULL) { | |
| 85 | − | byte_order = exif_data_get_byte_order(ed); | |
| 86 | − | orientation = exif_get_short(entry->data, byte_order); | |
| 87 | − | } | |
| 88 | − | exif_data_unref(ed); | |
| 89 | − | if (entry == NULL) | |
| 90 | − | return; | |
| 91 | − | ||
| 92 | − | switch (orientation) { | |
| 93 | − | case 5: | |
| 94 | − | imlib_image_orientate(1); | |
| 95 | − | case 2: | |
| 96 | − | imlib_image_flip_vertical(); | |
| 97 | − | break; | |
| 98 | − | ||
| 99 | − | case 3: | |
| 100 | − | imlib_image_orientate(2); | |
| 101 | − | break; | |
| 102 | − | ||
| 103 | − | case 7: | |
| 104 | − | imlib_image_orientate(1); | |
| 105 | − | case 4: | |
| 106 | − | imlib_image_flip_horizontal(); | |
| 107 | − | break; | |
| 108 | − | ||
| 109 | − | case 6: | |
| 110 | − | imlib_image_orientate(1); | |
| 111 | − | break; | |
| 112 | − | ||
| 113 | − | case 8: | |
| 114 | − | imlib_image_orientate(3); | |
| 115 | − | break; | |
| 116 | − | } | |
| 117 | − | } | |
| 118 | − | #endif /* EXIF_SUPPORT */ | |
| 119 | − | ||
| 120 | − | #if GIF_SUPPORT | |
| 121 | − | /* Originally based on, but in its current form merely inspired by Imlib2's | |
| 122 | − | * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler. | |
| 123 | − | */ | |
| 124 | 67 | bool img_load_gif(img_t *img, const fileinfo_t *file) { | |
| 125 | 68 | GifFileType *gif; | |
| 126 | 69 | GifRowType *rows = NULL; | |
| @@ -290,7 +233,6 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) { | |||
| 290 | 233 | ||
| 291 | 234 | return !err; | |
| 292 | 235 | } | |
| 293 | − | #endif /* GIF_SUPPORT */ | |
| 294 | 236 | ||
| 295 | 237 | bool img_load(img_t *img, const fileinfo_t *file) { | |
| 296 | 238 | const char *fmt; | |
| @@ -312,14 +254,8 @@ bool img_load(img_t *img, const fileinfo_t *file) { | |||
| 312 | 254 | warn("could not open image: %s", file->name); | |
| 313 | 255 | return false; | |
| 314 | 256 | } | |
| 315 | − | #if EXIF_SUPPORT | |
| 316 | − | if (STREQ(fmt, "jpeg")) | |
| 317 | − | exif_auto_orientate(file); | |
| 318 | − | #endif | |
| 319 | − | #if GIF_SUPPORT | |
| 320 | 257 | if (STREQ(fmt, "gif")) | |
| 321 | 258 | img_load_gif(img, file); | |
| 322 | − | #endif | |
| 323 | 259 | ||
| 324 | 260 | img->w = imlib_image_get_width(); | |
| 325 | 261 | img->h = imlib_image_get_height(); | |
| @@ -17,7 +17,6 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | − | #define _FEATURE_CONFIG | |
| 21 | 20 | #define _IMAGE_CONFIG | |
| 22 | 21 | ||
| 23 | 22 | #include <stdlib.h> | |
| @@ -39,18 +38,6 @@ void print_usage(void) { | |||
| 39 | 38 | ||
| 40 | 39 | void print_version(void) { | |
| 41 | 40 | printf("sxiv %s - Simple X Image Viewer\n", VERSION); | |
| 42 | − | printf("Additional features included (+) or not (-): %s, %s\n", | |
| 43 | − | #if EXIF_SUPPORT | |
| 44 | − | "+exif", | |
| 45 | − | #else | |
| 46 | − | "-exif", | |
| 47 | − | #endif | |
| 48 | − | #if GIF_SUPPORT | |
| 49 | − | "+gif" | |
| 50 | − | #else | |
| 51 | − | "-gif" | |
| 52 | − | #endif | |
| 53 | − | ); | |
| 54 | 41 | } | |
| 55 | 42 | ||
| 56 | 43 | void parse_options(int argc, char **argv) { | |
| @@ -17,7 +17,6 @@ | |||
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | − | #define _FEATURE_CONFIG | |
| 21 | 20 | #define _THUMBS_CONFIG | |
| 22 | 21 | ||
| 23 | 22 | #include <stdlib.h> | |
| @@ -31,10 +30,6 @@ | |||
| 31 | 30 | #include "util.h" | |
| 32 | 31 | #include "config.h" | |
| 33 | 32 | ||
| 34 | − | #if EXIF_SUPPORT | |
| 35 | − | void exif_auto_orientate(const fileinfo_t*); | |
| 36 | − | #endif | |
| 37 | − | ||
| 38 | 33 | const int thumb_dim = THUMB_SIZE + 10; | |
| 39 | 34 | char *cache_dir = NULL; | |
| 40 | 35 | ||
| @@ -211,7 +206,7 @@ void tns_free(tns_t *tns) { | |||
| 211 | 206 | } | |
| 212 | 207 | ||
| 213 | 208 | bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |
| 214 | − | bool force, bool silent) | |
| 209 | + | bool force, bool silent) | |
| 215 | 210 | { | |
| 216 | 211 | int w, h; | |
| 217 | 212 | bool use_cache, cache_hit = false; | |
| @@ -259,10 +254,6 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 259 | 254 | imlib_free_image_and_decache(); | |
| 260 | 255 | return false; | |
| 261 | 256 | } | |
| 262 | − | #if EXIF_SUPPORT | |
| 263 | − | if (!cache_hit && STREQ(fmt, "jpeg")) | |
| 264 | − | exif_auto_orientate(file); | |
| 265 | − | #endif | |
| 266 | 257 | ||
| 267 | 258 | w = imlib_image_get_width(); | |
| 268 | 259 | h = imlib_image_get_height(); | |