Removed exif support; made gif support non-optional

This commit is contained in:
Bert Münnich 2012-02-11 02:42:52 +01:00
parent c3c95ab218
commit ef0ed32264
7 changed files with 16 additions and 160 deletions

View file

@ -3,7 +3,7 @@ VERSION = git-20120211
CC = gcc CC = gcc
CFLAGS = -ansi -Wall -pedantic -O2 CFLAGS = -ansi -Wall -pedantic -O2
LDFLAGS = LDFLAGS =
LIBS = -lX11 -lImlib2 LIBS = -lX11 -lImlib2 -lgif
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man
@ -24,22 +24,19 @@ options:
@echo "CC $<" @echo "CC $<"
@$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $< @$(CC) $(CFLAGS) -DVERSION=\"$(VERSION)\" -c -o $@ $<
$(OBJ) config: Makefile config.h $(OBJ): Makefile config.h
config: config.c
@$(CC) $(CFLAGS) -o $@ $@.c
config.h: config.h:
@echo "creating $@ from config.def.h" @echo "creating $@ from config.def.h"
@cp config.def.h $@ @cp config.def.h $@
sxiv: $(OBJ) config sxiv: $(OBJ)
@echo "CC -o $@" @echo "CC -o $@"
@$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $$(./config -l) @$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
clean: clean:
@echo "cleaning" @echo "cleaning"
@rm -f $(OBJ) config sxiv sxiv-$(VERSION).tar.gz @rm -f $(OBJ) sxiv sxiv-$(VERSION).tar.gz
install: all install: all
@echo "installing executable file to $(DESTDIR)$(PREFIX)/bin" @echo "installing executable file to $(DESTDIR)$(PREFIX)/bin"

View file

@ -1,11 +1,11 @@
sxiv: Simple (or small or suckless) X Image Viewer sxiv: Simple (or small or suckless) X Image Viewer
sxiv is an alternative to feh and qiv. Its only dependency besides xlib is sxiv is an alternative to feh and qiv. Its only dependencies besides xlib are
imlib2. The primary goal for writing sxiv is to create an image viewer, which imlib2 and giflib. The primary goal for writing sxiv is to create an image
only has the most basic features required for fast image viewing (the ones I viewer, which only has the most basic features required for fast image viewing
want). It has vi key bindings and works nicely with tiling window managers. (the ones I want). It has vi key bindings and works nicely with tiling window
Its code base should be kept small and clean to make it easy for you to dig managers. Its code base should be kept small and clean to make it easy for you
into it and customize it for your needs. to dig into it and customize it for your needs.
Features Features
-------- --------
@ -15,14 +15,9 @@ Features
* Thumbnail mode: grid of selectable previews of all images * Thumbnail mode: grid of selectable previews of all images
* Ability to cache thumbnails for fast re-loading * Ability to cache thumbnails for fast re-loading
* Basic support for multi-frame images * Basic support for multi-frame images
* Load all frames from GIF files and play GIF animations
* Display image information in window title * Display image information in window title
Additional features, that need to be enabled at compile-time (in *config.h*),
because they depend on additional libraries:
* Load all frames from GIF files and play GIF animations (requires giflib)
* Auto-orientate JPEG images according to their EXIF tags (requires libexif)
Screenshots Screenshots
----------- -----------

View file

@ -1,38 +0,0 @@
#define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#include <stdio.h>
#include "config.h"
#define QUOTE(m) #m
#define PUT_MACRO(m) \
printf(" -D%s=%s", #m, QUOTE(m))
int puts_if(const char *s, int c) {
return c ? printf(" %s", s) : 0;
}
int main(int argc, char **argv) {
int i;
unsigned int n = 0;
for (i = 1; i < argc; i++) {
switch ((argv[i][0] != '-' || argv[i][2] != '\0') ? -1 : argv[i][1]) {
case 'D':
n += PUT_MACRO(EXIF_SUPPORT);
n += PUT_MACRO(GIF_SUPPORT);
break;
case 'l':
n += puts_if("-lexif", EXIF_SUPPORT);
n += puts_if("-lgif", GIF_SUPPORT);
break;
default:
fprintf(stderr, "%s: invalid argument: %s\n", argv[0], argv[i]);
return 1;
}
}
if (n > 0)
printf("\n");
return 0;
}

View file

@ -1,15 +1,3 @@
#ifdef _FEATURE_CONFIG
/* auto-orientate jpeg files according to their exif tags?
* (requires libexif [-lexif] to be installed)
*/
#define EXIF_SUPPORT 0
/* load all frames from gif files and support gif animations?
* (requires giflib [-lgif] to be installed)
*/
#define GIF_SUPPORT 0
#endif
#ifdef _WINDOW_CONFIG #ifdef _WINDOW_CONFIG
/* default window dimensions (overwritten via -g option): */ /* default window dimensions (overwritten via -g option): */

70
image.c
View file

@ -17,27 +17,19 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _IMAGE_CONFIG #define _IMAGE_CONFIG
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <gif_lib.h>
#include "image.h" #include "image.h"
#include "options.h" #include "options.h"
#include "util.h" #include "util.h"
#include "config.h" #include "config.h"
#if EXIF_SUPPORT
#include <libexif/exif-data.h>
#endif
#if GIF_SUPPORT
#include <stdlib.h>
#include <sys/types.h>
#include <gif_lib.h>
#endif
enum { MIN_GIF_DELAY = 50 }; enum { MIN_GIF_DELAY = 50 };
float zoom_min; float zoom_min;
@ -72,55 +64,6 @@ void img_init(img_t *img, win_t *win) {
img->multi.animate = false; img->multi.animate = false;
} }
#if EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t *file) {
ExifData *ed;
ExifEntry *entry;
int byte_order, orientation;
if ((ed = exif_data_new_from_file(file->path)) == NULL)
return;
entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION);
if (entry != NULL) {
byte_order = exif_data_get_byte_order(ed);
orientation = exif_get_short(entry->data, byte_order);
}
exif_data_unref(ed);
if (entry == NULL)
return;
switch (orientation) {
case 5:
imlib_image_orientate(1);
case 2:
imlib_image_flip_vertical();
break;
case 3:
imlib_image_orientate(2);
break;
case 7:
imlib_image_orientate(1);
case 4:
imlib_image_flip_horizontal();
break;
case 6:
imlib_image_orientate(1);
break;
case 8:
imlib_image_orientate(3);
break;
}
}
#endif /* EXIF_SUPPORT */
#if GIF_SUPPORT
/* Originally based on, but in its current form merely inspired by Imlib2's
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
*/
bool img_load_gif(img_t *img, const fileinfo_t *file) { bool img_load_gif(img_t *img, const fileinfo_t *file) {
GifFileType *gif; GifFileType *gif;
GifRowType *rows = NULL; GifRowType *rows = NULL;
@ -290,7 +233,6 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
return !err; return !err;
} }
#endif /* GIF_SUPPORT */
bool img_load(img_t *img, const fileinfo_t *file) { bool img_load(img_t *img, const fileinfo_t *file) {
const char *fmt; const char *fmt;
@ -312,14 +254,8 @@ bool img_load(img_t *img, const fileinfo_t *file) {
warn("could not open image: %s", file->name); warn("could not open image: %s", file->name);
return false; return false;
} }
#if EXIF_SUPPORT
if (STREQ(fmt, "jpeg"))
exif_auto_orientate(file);
#endif
#if GIF_SUPPORT
if (STREQ(fmt, "gif")) if (STREQ(fmt, "gif"))
img_load_gif(img, file); img_load_gif(img, file);
#endif
img->w = imlib_image_get_width(); img->w = imlib_image_get_width();
img->h = imlib_image_get_height(); img->h = imlib_image_get_height();

View file

@ -17,7 +17,6 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _IMAGE_CONFIG #define _IMAGE_CONFIG
#include <stdlib.h> #include <stdlib.h>
@ -39,18 +38,6 @@ void print_usage(void) {
void print_version(void) { void print_version(void) {
printf("sxiv %s - Simple X Image Viewer\n", VERSION); printf("sxiv %s - Simple X Image Viewer\n", VERSION);
printf("Additional features included (+) or not (-): %s, %s\n",
#if EXIF_SUPPORT
"+exif",
#else
"-exif",
#endif
#if GIF_SUPPORT
"+gif"
#else
"-gif"
#endif
);
} }
void parse_options(int argc, char **argv) { void parse_options(int argc, char **argv) {

View file

@ -17,7 +17,6 @@
*/ */
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _FEATURE_CONFIG
#define _THUMBS_CONFIG #define _THUMBS_CONFIG
#include <stdlib.h> #include <stdlib.h>
@ -31,10 +30,6 @@
#include "util.h" #include "util.h"
#include "config.h" #include "config.h"
#if EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t*);
#endif
const int thumb_dim = THUMB_SIZE + 10; const int thumb_dim = THUMB_SIZE + 10;
char *cache_dir = NULL; char *cache_dir = NULL;
@ -211,7 +206,7 @@ void tns_free(tns_t *tns) {
} }
bool tns_load(tns_t *tns, int n, const fileinfo_t *file, bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
bool force, bool silent) bool force, bool silent)
{ {
int w, h; int w, h;
bool use_cache, cache_hit = false; bool use_cache, cache_hit = false;
@ -259,10 +254,6 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
imlib_free_image_and_decache(); imlib_free_image_and_decache();
return false; return false;
} }
#if EXIF_SUPPORT
if (!cache_hit && STREQ(fmt, "jpeg"))
exif_auto_orientate(file);
#endif
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();