Skip to content

Commit eea4f4f

Browse files
committed
Merge support for different backends into master branch
See bug #29. Over the last month, I've been refactoring an abstraction layer around the gdk-pixbuf backend handling the actual image loading and displaying, allowing pqiv to support other backends besides that one. The main reason for this was that I've found that I frequently need to display plots that I typically store in a vector format (PDF/eps/ps) for LaTεχ inclusion, but that direct integration of libpoppler (the freedesktop library used for PDF display by most linux programs nowadays) led to too hackish code (see commits 06e84f3 ff). For starters, poppler and libspectre are included as additional backends. libspectre is the library Evince from the Gnome project uses to display Postscript files. Both backends have unfixed upstream bugs and will need some maintenance. I've commented the code accordingly. I can think of some more backends which might come in handy, but I won't implement them soon unless someone really needs them: * MagickWand (ImageMagick) for even more formats * ffmpeg for still more formats * libdjvu - but that library has an awfully complicated, event driven API With the changes, there also come some bugfixes and general improvements. There are less (hopefully no) race conditions left in the code, because I moved image unloading into the image loader thread. Issue #27 has been worked around with a more complete solution. Especially, pqiv checks now if the WM claims to support _NET_WM_ACTION_FULLSCREEN and manages the fullscreen changes on its own if it does not; so fullscreen mode will now also work on plain X11 displays without a WM. When reworking the Makefile/configure for backend support, FreeBSD compilation was fixed, such that pqiv can now be compiled without changes in Linux distributions, also statically [1], in MingW using mxe [2] for Windows 32/64 and in FreeBSD / hopefully *BSD. [1] https://gist.github.com/phillipberndt/2726a790d9bb1f30e3ed [2] http://mxe.cc/
2 parents 1c5bc3f + 1175dd9 commit eea4f4f

File tree

13 files changed

+2002
-835
lines changed

13 files changed

+2002
-835
lines changed

GNUmakefile

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# pqiv Makefile
2+
#
3+
4+
# Default flags, overridden by values in config.make
5+
CFLAGS=-O2 -g
6+
CROSS=
7+
DESTDIR=
8+
GTK_VERSION=0
9+
PQIV_WARNING_FLAGS=-Wall -Wextra -Wfloat-equal -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Waggregate-return -Wunreachable-code -Wno-unused-parameter
10+
LDLIBS=-lm
11+
PREFIX=/usr
12+
MANDIR=$(PREFIX)/share/man
13+
EXECUTABLE_EXTENSION=
14+
PKG_CONFIG=$(CROSS)pkg-config
15+
OBJECTS=pqiv.o lib/strnatcmp.o lib/bostree.o lib/filebuffer.o
16+
BACKENDS=gdkpixbuf
17+
18+
# Load config.make (created by configure)
19+
ifeq ($(wildcard config.make),config.make)
20+
include config.make
21+
endif
22+
23+
# pkg-config lines for the main program
24+
LIBS_GENERAL=glib-2.0 >= 2.8 cairo >= 1.6 gio-2.0
25+
LIBS_GTK3=gtk+-3.0 gdk-3.0
26+
LIBS_GTK2=gtk+-2.0 >= 2.6 gdk-2.0 >= 2.8
27+
28+
# pkg-config libraries for the backends
29+
LIBS_gdkpixbuf=gdk-pixbuf-2.0 >= 2.2
30+
LIBS_poppler=poppler-glib
31+
LIBS_spectre=libspectre
32+
33+
# This might be required if you use mingw, and is required as of
34+
# Aug 2014 for mxe, but IMHO shouldn't be required / is a bug in
35+
# poppler (which does not specify this dependency). If it isn't
36+
# or throws an error for you, please report this as a bug:
37+
#
38+
ifeq ($(EXECUTABLE_EXTENSION),.exe)
39+
LDLIBS_poppler+=-llcms2 -lstdc++
40+
endif
41+
42+
# If no GTK_VERSION is set, try to auto-determine, with GTK 3 preferred
43+
ifeq ($(GTK_VERSION), 0)
44+
ifeq ($(shell $(PKG_CONFIG) --errors-to-stdout --print-errors "$(LIBS_GTK3)"), )
45+
LIBS=$(LIBS_GTK3)
46+
else
47+
LIBS=$(LIBS_GTK2)
48+
endif
49+
endif
50+
ifeq ($(GTK_VERSION), 2)
51+
LIBS=$(LIBS_GTK2)
52+
endif
53+
ifeq ($(GTK_VERSION), 3)
54+
LIBS=$(LIBS_GTK3)
55+
endif
56+
LIBS+=$(LIBS_GENERAL)
57+
58+
# Add platform specific libraries
59+
# GIo for stdin loading,
60+
# X11 to workaround a bug, see http://stackoverflow.com/questions/18647475
61+
ifeq ($(EXECUTABLE_EXTENSION), .exe)
62+
LIBS+=gio-windows-2.0
63+
else
64+
LIBS+=gio-unix-2.0 x11
65+
endif
66+
67+
# Add backend-specific libraries and objects
68+
BACKENDS_INITIALIZER:=backends/initializer
69+
define handle-backend
70+
ifneq ($(origin LIBS_$(1)),undefined)
71+
ifneq ($(findstring $(1), $(BACKENDS)),)
72+
LIBS+=$(LIBS_$(1))
73+
OBJECTS+=backends/$(1).o
74+
LDLIBS+=$(LDLIBS_$(1))
75+
BACKENDS_INITIALIZER:=$(BACKENDS_INITIALIZER)-$(1)
76+
endif
77+
endif
78+
endef
79+
$(foreach BACKEND_C, $(wildcard backends/*.c), $(eval $(call handle-backend,$(basename $(notdir $(BACKEND_C))))))
80+
81+
OBJECTS+=$(BACKENDS_INITIALIZER).o
82+
83+
CFLAGS_REAL=-std=gnu99 $(PQIV_WARNING_FLAGS) $(CFLAGS) $(shell $(PKG_CONFIG) --cflags "$(LIBS)")
84+
LDLIBS_REAL=$(shell $(PKG_CONFIG) --libs "$(LIBS)") $(LDLIBS)
85+
LDFLAGS_REAL=$(LDFLAGS)
86+
87+
all: pqiv$(EXECUTABLE_EXTENSION)
88+
.PHONY: get_libs get_available_backends _build_variables clean distclean install uninstall all
89+
90+
pqiv$(EXECUTABLE_EXTENSION): $(OBJECTS)
91+
$(CROSS)$(CC) $(CPPFLAGS) -o $@ $+ $(LDLIBS_REAL) $(LDFLAGS_REAL)
92+
93+
%.o: %.c
94+
$(CROSS)$(CC) $(CPPFLAGS) -c -o $@ $(CFLAGS_REAL) $+
95+
96+
$(BACKENDS_INITIALIZER).c:
97+
@$(foreach BACKEND, $(sort $(BACKENDS)), [ -e backends/$(BACKEND).c ] || { echo; echo "Backend $(BACKEND) not found!" >&2; exit 1; };)
98+
( \
99+
echo '/* Auto-Generated file by Make. */'; \
100+
echo '#include "../pqiv.h"'; \
101+
$(foreach BACKEND, $(sort $(BACKENDS)), echo "void file_type_$(BACKEND)_initializer(file_type_handler_t *info);";) \
102+
echo "void initialize_file_type_handlers() {"; \
103+
echo " int i = 0;"; \
104+
echo " file_type_handlers = g_new0(file_type_handler_t, $(words $(BACKENDS)) + 1);"; \
105+
$(foreach BACKEND, $(sort $(BACKENDS)), echo " file_type_$(BACKEND)_initializer(&file_type_handlers[i++]);";) \
106+
echo "}" \
107+
) > $@
108+
109+
install: pqiv$(EXECUTABLE_EXTENSION)
110+
mkdir -p $(DESTDIR)$(PREFIX)/bin
111+
install pqiv$(EXECUTABLE_EXTENSION) $(DESTDIR)$(PREFIX)/bin/pqiv$(EXECUTABLE_EXTENSION)
112+
-mkdir -p $(DESTDIR)$(MANDIR)/man1
113+
-install pqiv.1 $(DESTDIR)$(MANDIR)/man1/pqiv.1
114+
115+
uninstall:
116+
rm -f $(DESTDIR)$(PREFIX)/bin/pqiv$(EXECUTABLE_EXTENSION)
117+
rm -f $(DESTDIR)$(MANDIR)/man1/pqiv.1
118+
119+
clean:
120+
rm -f pqiv$(EXECUTABLE_EXTENSION) $(OBJECTS) $(BACKENDS_INITIALIZER).c
121+
122+
distclean: clean
123+
rm -f config.make backends/initializer-*
124+
125+
get_libs:
126+
$(info $(LIBS))
127+
@true
128+
129+
get_available_backends:
130+
@$(foreach BACKEND_C, $(wildcard backends/*.c), [ -n "$(LIBS_$(basename $(notdir $(BACKEND_C))))" ] && $(PKG_CONFIG) --exists "$(LIBS_$(basename $(notdir $(BACKEND_C))))" && echo -n "$(basename $(notdir $(BACKEND_C))) ";) echo
131+
@true

Makefile

Lines changed: 0 additions & 57 deletions
This file was deleted.

README.markdown

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,30 @@ Features
3939
* Supports external image filters (e.g. `convert`)
4040
* Preloads the next image in the background
4141
* Fade between images
42+
* Optional PDF/eps/ps support (useful e.g. for scientific plots)
4243

4344

4445
Installation
4546
------------
4647

47-
Usual stuff. `./configure && make && make install`. Actually, the configure
48-
script is optional for now.
48+
Usual stuff. `./configure && make && make install`. The configure script is
49+
optional if you only want gdk-pixbuf support and will autodetermine which
50+
backends to build if invoked without parameters.
4951

5052
You'll need
51-
* gtk+ 3.0 *or* gtk+ 2.8
53+
* gtk+ 3.0 *or* gtk+ 2.6
5254
* gdk-pixbuf 2.2 (included in gtk+)
53-
* glib 2.8
55+
* glib 2.6
5456
* cairo 1.6
5557
* gio 2.0
5658
* gdk 2.8
59+
* libspectre (any version, optional, for ps/eps support)
60+
* poppler (any version, optional, for pdf support)
61+
62+
The backends are currently statically linked into the code, so all backend
63+
related build-time dependencies are also run-time dependencies. If you need
64+
a shared version of the backends, for example for separate packaging of
65+
the binaries, let me know. It's quite easy to implement that.
5766

5867
Thanks
5968
------
@@ -100,6 +109,15 @@ Known bugs
100109
Changelog
101110
---------
102111

112+
pqiv 2.3 (Work in progress)
113+
* Refactored an abstraction layer around the image backend
114+
* Added optional support for PDF-files through
115+
[poppler](http://poppler.freedesktop.org/)
116+
* Added optional support for PS-files through
117+
[libspectre](http://www.freedesktop.org/wiki/Software/libspectre/)
118+
* Support for gtk+ 3.14
119+
* configure/Makefile updated to support (Free-)BSD
120+
103121
pqiv 2.2
104122
* Accept URLs as command line arguments
105123
* Revived -r for reading additional files from stdin (by J.P. Reed)

0 commit comments

Comments
 (0)