Skip to content

Commit

Permalink
Added tiff output to cairoplugin
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRhiem committed Mar 19, 2019
1 parent 8c1e8cf commit 8647b39
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .gitlab-ci.yml
Expand Up @@ -170,7 +170,7 @@ windows-32bit-cross:
- tar xf cmake-3.6.3-Linux-x86_64.tar.gz
- export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake
- make -C 3rdparty default extras
EXTRAS="ogg theora vpx ffmpeg mupdf pixman cairo"
EXTRAS="tiff ogg theora vpx ffmpeg mupdf pixman cairo"
HOST=i686-w64-mingw32
ARCHITECTURE=i686
OS=w64_x86-cross-mingw32
Expand All @@ -184,6 +184,7 @@ windows-32bit-cross:
FFMPEG_EXTRA_CONFIGURE_FLAGS="--cross-prefix=i686-w64-mingw32- --arch=i686 --target-os=mingw32"
PIXMAN_EXTRA_CONFIGURE_FLAGS=--host=i686-w64-mingw32
CAIRO_EXTRA_CONFIGURE_FLAGS=--host=i686-w64-mingw32
TIFF_EXTRA_CONFIGURE_FLAGS=--host=i686-w64-mingw32
- MAKE="make -f makefile.mingw" make -f makefile.mingw
GRDIR=./
CC=i686-w64-mingw32-gcc
Expand Down Expand Up @@ -217,7 +218,7 @@ windows-64bit-cross:
- tar xf cmake-3.6.3-Linux-x86_64.tar.gz
- export CMAKE_CMD=`pwd`/cmake-3.6.3-Linux-x86_64/bin/cmake
- make -C 3rdparty default extras
EXTRAS="ogg theora vpx ffmpeg mupdf pixman cairo"
EXTRAS="tiff ogg theora vpx ffmpeg mupdf pixman cairo"
HOST=x86_64-w64-mingw32
ARCHITECTURE=x86_64
OS=w64_amd64-cross-mingw32
Expand All @@ -231,6 +232,7 @@ windows-64bit-cross:
FFMPEG_EXTRA_CONFIGURE_FLAGS="--cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32"
PIXMAN_EXTRA_CONFIGURE_FLAGS=--host=x86_64-w64-mingw32
CAIRO_EXTRA_CONFIGURE_FLAGS=--host=x86_64-w64-mingw32
TIFF_EXTRA_CONFIGURE_FLAGS=--host=x86_64-w64-mingw32
- MAKE="make -f makefile.mingw" make -f makefile.mingw
GRDIR=./
CC=x86_64-w64-mingw32-gcc
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/Makefile
@@ -1,5 +1,5 @@
TARGETS = freetype jpeg libpng16 zlib qhull bzip2
EXTRAS = mupdf ogg theora vpx ffmpeg glfw zeromq pixman cairo
EXTRAS = tiff mupdf ogg theora vpx ffmpeg glfw zeromq pixman cairo
DIR =

default:
Expand Down
66 changes: 66 additions & 0 deletions 3rdparty/tiff/Makefile
@@ -0,0 +1,66 @@
ifeq ($(strip $(PREFIX)),)
override PREFIX = $(abspath $(CURDIR)/../build)
endif

VERSION = 4.0.10
TIFF_EXTRA_CONFIGURE_FLAGS ?=

ifeq ($(DOWNLOAD_CMD),)
ifneq ($(shell curl --version 2>/dev/null),)
DOWNLOAD_CMD := curl -k -OL
endif
endif
ifeq ($(DOWNLOAD_CMD),)
ifneq ($(shell wget --version 2>/dev/null),)
DOWNLOAD_CMD := wget --no-check-certificate
endif
endif
ifeq ($(DOWNLOAD_CMD),)
DOWNLOAD_CMD := echo "Error: Unable to find curl or wget."; exit 1; \#
endif

default: install

$(PREFIX)/src/tiff-$(VERSION).tar.gz:
mkdir -p $(PREFIX)/src
cd $(PREFIX)/src/ && $(DOWNLOAD_CMD) https://gr-framework.org/downloads/3rdparty/tiff-$(VERSION).tar.gz

$(PREFIX)/src/tiff-$(VERSION)/configure: $(PREFIX)/src/tiff-$(VERSION).tar.gz
cd $(PREFIX)/src/ && tar -xf tiff-$(VERSION).tar.gz
touch $@

$(PREFIX)/src/tiff-$(VERSION)/Makefile: $(PREFIX)/src/tiff-$(VERSION)/configure
cd $(PREFIX)/src/tiff-$(VERSION) && \
./configure \
--prefix=$(PREFIX) \
--libdir=$(PREFIX)/lib \
--enable-static \
--disable-shared \
--with-pic \
--disable-dependency-tracking \
--with-zlib-include-dir=$(PREFIX)/include/ \
--with-zlib-lib-dir=$(PREFIX)/lib/ \
--disable-largefile \
--disable-ccitt \
--disable-packbits \
--disable-lzw \
--disable-thunder \
--disable-next \
--disable-logluv \
--disable-mdi \
--disable-pixarlog \
--disable-jpeg \
--disable-old-jpeg \
--disable-jbig \
--disable-lzma \
--disable-zstd \
--disable-webp \
$(TIFF_EXTRA_CONFIGURE_FLAGS)

$(PREFIX)/lib/libtiff.a: $(PREFIX)/src/tiff-$(VERSION)/Makefile
make -C $(PREFIX)/src/tiff-$(VERSION) -j4
make -C $(PREFIX)/src/tiff-$(VERSION) install

install: $(PREFIX)/lib/libtiff.a

.PHONY: default install
36 changes: 35 additions & 1 deletion lib/Preflight
Expand Up @@ -653,5 +653,39 @@ fi
printf "%12s: %s\n" "Cairo" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver


if [ "$tiff" != "no" ]
then
tmpout=`mktemp /tmp/a.out.XXXXX`
tmpsrc=`mktemp /tmp/a$$XXXXX.c`
tmpver=`mktemp /tmp/a$$XXXXX.txt`
cat >$tmpsrc << eof
#include <stdio.h>
#include <tiffio.h>
int main() {
puts(TIFFGetVersion());
return 0;
}
eof
libs="-lm"
cmd="${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -o $tmpout $tmpsrc -ltiff"
$cmd $libs >/dev/null 2>&1
if [ $? -ne 0 ]; then
tiffdefs="TIFFDEFS=-DNO_TIFF TIFFLIBS="
info="${red} no${normal} [libtiff not found]"
ret=1
else
$tmpout >$tmpver 2>&1
info="${green}yes${normal} [`cat $tmpver | head -1 | sed s/LIBTIFF,\ Version/version/`]"
fi
else
info="${yellow} no${normal} [disabled]"
tiffdefs="TIFFDEFS=-DNO_TIFF TIFFLIBS="
ret=1
fi
printf "%12s: %s\n" "libtiff" "$info" >&2
rm -f $tmpsrc $tmpout $tmpver

echo "" >&2
echo $target $wxdefs $qt4defs $qt5defs $gtkdefs $x11defs $xftdefs $gsdefs $glfwdefs $zmqdefs $avdefs $mupdfdefs $ssldefs $cairodefs $extradefs
echo $target $wxdefs $qt4defs $qt5defs $gtkdefs $x11defs $xftdefs $gsdefs $glfwdefs $zmqdefs $avdefs $mupdfdefs $ssldefs $cairodefs $tiffdefs $extradefs
2 changes: 2 additions & 0 deletions lib/gks/gks.c
Expand Up @@ -57,6 +57,7 @@ static ws_descr_t ws_types[] = {{2, GKS_K_METERS, 1.00000, 1.00000, 65536, 65536
{143, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, NULL, NULL},
{144, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "jpg", NULL},
{145, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "bmp", NULL},
{146, GKS_K_METERS, 0.28575, 0.19685, 6750, 4650, 0, "tif", NULL},
{150, GKS_K_METERS, 0.20320, 0.15240, 560, 420, 0, "six", NULL},
{160, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "mp4", NULL},
{161, GKS_K_METERS, 0.25400, 0.19050, 1024, 768, 0, "webm", NULL},
Expand Down Expand Up @@ -302,6 +303,7 @@ static void gks_ddlk(int fctid, int dx, int dy, int dimx, int *i_arr, int len_f_
case 143:
case 144:
case 145:
case 146:
case 150:
gks_cairo_plugin(fctid, dx, dy, dimx, i_arr, len_f_arr_1, f_arr_1, len_f_arr_2, f_arr_2, len_c_arr, c_arr,
ptr);
Expand Down
5 changes: 3 additions & 2 deletions lib/gks/plugin/Makefile
Expand Up @@ -93,6 +93,7 @@ endif
LIBS = -lc -lm
ZINC = -I../../../3rdparty/zlib
ZLIBS = ../../../3rdparty/zlib/libz.a
TIFFLIBS = -ltiff
GKSLIBS = ../libGKS.a

.SUFFIXES: .o .m .cxx
Expand Down Expand Up @@ -183,10 +184,10 @@ pgfplugin.so: pgfplugin.o
$(CC) -o $@ $(SOFLAGS) $^ $(LDFLAGS) $(GKSLIBS) $(PNGLIBS) $(ZLIBS) $(LIBS)

cairoplugin.o: cairoplugin.c
$(CC) -c -DGRDIR=\"$(GRDIR)\" $(DEFINES) $(INCLUDES) $(FTDEFS) $(FTINC) $(JPEGDEFS) $(CAIRODEFS) $(CXXFLAGS) $(ZINC) -DNO_X11 $<
$(CC) -c -DGRDIR=\"$(GRDIR)\" $(DEFINES) $(INCLUDES) $(FTDEFS) $(FTINC) $(JPEGDEFS) $(CAIRODEFS) $(TIFFDEFS) $(CXXFLAGS) $(ZINC) -DNO_X11 $<

cairoplugin.so: cairoplugin.o
$(CC) -o $@ $(SOFLAGS) $^ $(LDFLAGS) $(GKSLIBS) $(CAIROLIBS) $(FTLIBS) $(JPEGLIBS) $(PNGLIBS) $(ZLIBS) $(LIBS) -DNO_X11
$(CC) -o $@ $(SOFLAGS) $^ $(LDFLAGS) $(GKSLIBS) $(CAIROLIBS) $(FTLIBS) $(JPEGLIBS) $(PNGLIBS) $(TIFFLIBS) $(ZLIBS) $(LIBS) -DNO_X11

videoplugin.so: videoplugin.o vc.o
$(CC) -o $@ $(SOFLAGS) $^ $(LDFLAGS) $(GKSLIBS) $(AVLIBS) $(FTLIBS) $(EXTRALIBS) $(ZLIBS) $(LIBS)
Expand Down
71 changes: 69 additions & 2 deletions lib/gks/plugin/cairoplugin.c
Expand Up @@ -12,6 +12,7 @@ typedef __int64 int64_t;
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include <time.h>

#include <cairo/cairo.h>
#ifndef NO_FT
Expand Down Expand Up @@ -39,6 +40,10 @@ typedef __int64 int64_t;

#include <jpeglib.h>

#ifndef NO_TIFF
#include <tiffio.h>
#endif

#include "gks.h"
#include "gkscore.h"

Expand Down Expand Up @@ -974,7 +979,8 @@ static void open_page(void)
exit(1);
#endif
}
else if (p->wtype == 140 || p->wtype == 143 || p->wtype == 144 || p->wtype == 145 || p->wtype == 150)
else if (p->wtype == 140 || p->wtype == 143 || p->wtype == 144 || p->wtype == 145 || p->wtype == 146 ||
p->wtype == 150)
{
p->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, p->width, p->height);
}
Expand Down Expand Up @@ -1520,6 +1526,67 @@ static void write_page(void)
gks_free(row);
}
}
else if (p->wtype == 146)
{
#ifdef NO_TIFF
gks_perror("Cairo TIFF support not compiled in");
#else
TIFF *fp;

gks_filepath(path, p->path, "tif", p->page_counter, 0);
fp = TIFFOpen(path, "w");
if (!fp)
{
fprintf(stderr, "GKS: Failed to open file: %s\n", path);
}
else
{
time_t current_datetime = time(NULL);
unsigned char *data = cairo_image_surface_get_data(p->surface);
int width = cairo_image_surface_get_width(p->surface);
int height = cairo_image_surface_get_height(p->surface);
int stride = cairo_image_surface_get_stride(p->surface);
int i;
TIFFSetField(fp, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(fp, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(fp, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(fp, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(fp, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(fp, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(fp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(fp, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(fp, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(fp, stride));
TIFFSetField(fp, TIFFTAG_SOFTWARE, "GKS Cairo Plugin");
TIFFSetField(fp, TIFFTAG_XRESOLUTION, p->w * 0.0254 / p->mw);
TIFFSetField(fp, TIFFTAG_YRESOLUTION, p->h * 0.0254 / p->mh);
TIFFSetField(fp, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
if (current_datetime != -1)
{
struct tm *current_datetime_struct = localtime(&current_datetime);
if (current_datetime_struct)
{
char current_datetime_str[20] = {0};
if (strftime(current_datetime_str, 20, "%Y:%m:%d %H:%M:%S", current_datetime_struct))
{
TIFFSetField(fp, TIFFTAG_DATETIME, current_datetime_str);
}
}
}
for (i = 0; i < height; i++)
{
if (TIFFWriteScanline(fp, data + i * stride, i, 0) < 0)
{
break;
}
}
if (i != height)
{
fprintf(stderr, "GKS: Failed to write file: %s\n", path);
}
TIFFClose(fp);
}
#endif
}
else if (p->wtype == 150)
{
cairo_surface_flush(p->surface);
Expand Down Expand Up @@ -1609,7 +1676,7 @@ void gks_cairoplugin(int fctid, int dx, int dy, int dimx, int *ia, int lr1, doub
p->wtype = ia[2];
p->mem = NULL;

if (p->wtype == 140 || p->wtype == 144 || p->wtype == 145)
if (p->wtype == 140 || p->wtype == 144 || p->wtype == 145 || p->wtype == 146)
{
p->mw = 0.28575;
p->mh = 0.19685;
Expand Down
3 changes: 2 additions & 1 deletion lib/gks/plugin/makefile.mingw
Expand Up @@ -14,6 +14,7 @@ CFLAGS = -Wall $(DEFINES) $(INCLUDES)
CXXFLAGS = -Wall $(DEFINES) $(INCLUDES)
GDILIB = -lgdi32
GKSLIB = ../libgks.lib
TIFFLIB = ../../../3rdparty/build/lib/libtiff.a

all: x11plugin.dll svgplugin.dll pgfplugin.dll htmplugin.dll cairoplugin.dll movplugin.dll wxplugin.dll qtplugin.dll qt5plugin.dll gtkplugin.dll figplugin.dll gsplugin.dll wmfplugin.dll glplugin.dll zmqplugin.dll videoplugin.dll

Expand Down Expand Up @@ -44,7 +45,7 @@ movplugin.dll: movplugin.o vc.o gif.o pdf.o $(GKSLIB)

cairoplugin.o: $(CAIROLIB)

cairoplugin.dll: cairoplugin.o $(GKSLIB) $(CAIROLIB) $(PIXMANLIB) $(PNGLIB) $(ZLIB) $(FTLIB) $(JPEGLIB)
cairoplugin.dll: cairoplugin.o $(GKSLIB) $(CAIROLIB) $(PIXMANLIB) $(PNGLIB) $(TIFFLIB) $(ZLIB) $(FTLIB) $(JPEGLIB)
$(CC) -shared -o $@ $^ -Wl,--out-implib,$(@:.dll=.a) $(GDILIB)

videoplugin.o: $(ZLIB) $(JPEGLIB) $(FTLIB) AVLIBS
Expand Down
17 changes: 10 additions & 7 deletions lib/gks/util.c
Expand Up @@ -65,13 +65,13 @@ struct wstypes_t
};

static struct wstypes_t wstypes[] = {
{"cgm", 8}, {"win", 42}, {"ps", 62}, {"eps", 62}, {"nul", 100}, {"pdf", 102},
{"mov", 120}, {"gif", 130}, {"cairopng", 140}, {"cairox11", 141}, {"cairojpg", 144}, {"cairobmp", 145},
{"six", 150}, {"mp4", 160}, {"webm", 161}, {"ogg", 162}, {"x11", 211}, {"pgf", 314},
{"bmp", 320}, {"jpeg", 321}, {"jpg", 321}, {"png", 322}, {"tiff", 323}, {"tif", 323},
{"fig", 370}, {"gtk", 370}, {"wx", 380}, {"qt", 381}, {"svg", 382}, {"wmf", 390},
{"quartz", 400}, {"socket", 410}, {"sock", 410}, {"gksqt", 411}, {"zmq", 415}, {"gl", 420},
{"opengl", 420}, {"html", 430}};
{"cgm", 8}, {"win", 42}, {"ps", 62}, {"eps", 62}, {"nul", 100}, {"pdf", 102},
{"mov", 120}, {"gif", 130}, {"cairopng", 140}, {"cairox11", 141}, {"cairojpg", 144}, {"cairobmp", 145},
{"cairotif", 146}, {"six", 150}, {"mp4", 160}, {"webm", 161}, {"ogg", 162}, {"x11", 211},
{"pgf", 314}, {"bmp", 320}, {"jpeg", 321}, {"jpg", 321}, {"png", 322}, {"tiff", 323},
{"tif", 323}, {"fig", 370}, {"gtk", 370}, {"wx", 380}, {"qt", 381}, {"svg", 382},
{"wmf", 390}, {"quartz", 400}, {"socket", 410}, {"sock", 410}, {"gksqt", 411}, {"zmq", 415},
{"gl", 420}, {"opengl", 420}, {"html", 430}};

static int num_wstypes = sizeof(wstypes) / sizeof(wstypes[0]);

Expand Down Expand Up @@ -1638,6 +1638,7 @@ int gks_get_ws_type(void)
if (wstype == 320) wstype = 145;
if (wstype == 321) wstype = 144;
if (wstype == 322) wstype = 140;
if (wstype == 323) wstype = 146;
#endif

#ifndef NO_CAIRO
Expand All @@ -1646,6 +1647,8 @@ int gks_get_ws_type(void)
if (wstype == 321 && gks_getenv("GKS_USE_CAIRO_JPG") != NULL) wstype = 144;

if (wstype == 322 && gks_getenv("GKS_USE_CAIRO_PNG") != NULL) wstype = 140;

if (wstype == 323 && gks_getenv("GKS_USE_CAIRO_TIF") != NULL) wstype = 146;
#endif

if (wstype == 0) wstype = get_default_ws_type();
Expand Down
8 changes: 8 additions & 0 deletions lib/gr/gr.c
Expand Up @@ -7407,7 +7407,11 @@ static int gks_wstype(char *type)
else if (!str_casecmp(type, "ogg"))
wstype = 162;
else if (!str_casecmp(type, "tiff") || !str_casecmp(type, "tif"))
#ifndef NO_GS
wstype = 323;
#else
wstype = 146;
#endif
else if (!str_casecmp(type, "fig"))
wstype = 370;
else if (!str_casecmp(type, "svg"))
Expand All @@ -7433,12 +7437,16 @@ bmp, eps, fig, html, jpeg, mov, mp4, webm, ogg, pdf, pgf, png, ps, svg, tiff or
if (wstype == 321 && DLLGetEnv("GKS_USE_CAIRO_JPG") != NULL) wstype = 144;

if (wstype == 322 && DLLGetEnv("GKS_USE_CAIRO_PNG") != NULL) wstype = 140;

if (wstype == 323 && DLLGetEnv("GKS_USE_CAIRO_TIF") != NULL) wstype = 146;
#else
if (wstype == 320 && getenv("GKS_USE_CAIRO_BMP") != NULL) wstype = 145;

if (wstype == 321 && getenv("GKS_USE_CAIRO_JPG") != NULL) wstype = 144;

if (wstype == 322 && getenv("GKS_USE_CAIRO_PNG") != NULL) wstype = 140;

if (wstype == 323 && getenv("GKS_USE_CAIRO_TIF") != NULL) wstype = 146;
#endif
#endif

Expand Down
1 change: 1 addition & 0 deletions packaging/debian/debian.rules
Expand Up @@ -33,6 +33,7 @@ override_dh_auto_configure:
cp ../SOURCES/openjpeg-2.0.0.tar.gz ${THIRDPARTY_SRC}
cp ../SOURCES/cairo-1.14.6.tar.xz ${THIRDPARTY_SRC}
cp ../SOURCES/pixman-0.34.0.tar.gz ${THIRDPARTY_SRC}
cp ../SOURCES/tiff-4.0.10.tar.gz ${THIRDPARTY_SRC}

override_dh_auto_build:
make -C 3rdparty GRDIR=${GRDIR} DIR=`pwd`/${THIRDPARTY}
Expand Down
2 changes: 2 additions & 0 deletions packaging/redhat/gr.spec
Expand Up @@ -32,6 +32,7 @@ Source8: https://gr-framework.org/downloads/3rdparty/openjpeg-2.0.0.tar.gz
Source9: https://gr-framework.org/downloads/3rdparty/cmake-2.8.12.2.tar.gz
Source10: https://gr-framework.org/downloads/3rdparty/cairo-1.14.6.tar.xz
Source11: https://gr-framework.org/downloads/3rdparty/pixman-0.34.0.tar.gz
Source12: https://gr-framework.org/downloads/3rdparty/tiff-4.0.10.tar.gz
BuildRequires: git
BuildRequires: gcc-c++
BuildRequires: libX11-devel
Expand Down Expand Up @@ -110,6 +111,7 @@ mkdir -p %{THIRDPARTY_SRC}
%{__cp} %{SOURCE9} %{THIRDPARTY_SRC}
%{__cp} %{SOURCE10} %{THIRDPARTY_SRC}
%{__cp} %{SOURCE11} %{THIRDPARTY_SRC}
%{__cp} %{SOURCE12} %{THIRDPARTY_SRC}

%build
make -C 3rdparty GRDIR=%{grdir} DIR=`pwd`/%{THIRDPARTY}
Expand Down

0 comments on commit 8647b39

Please sign in to comment.