Debian Codegraph @

doc/miscellaneous_notes/additional_image_formats.md

raw symbols SCIP
1 # Additional image formats
2
3 ## Introduction
4
5 In _Castle Game Engine_ we rely on [Vampyre Imaging Library](https://imaginglib.sourceforge.io/) to support most of our image formats.
6
7 ( There are some exceptions, the most prominent are [KTX](https://castle-engine.io/ktx) and [DDS](https://castle-engine.io/dds) formats that are implemented directly in our engine, to exercise all of their special 3D-related features. And PNG format, that is implemented using _LibPng_ (for maximum read speed), and _Vampyre Imaging Library_ PNG reader is only used as a fallback. In the past, the situation was more complicated, we also used _FpImage_ (but it is slower at reading and FPC-specific) and we had more formats implemented directly in CGE (but we removed them, in favor of delegating more to _Vampyre Imaging Library_). )
8
9 However, some image formats supported by _Vampyre Imaging Library_ are *not* supported out-of-the-box in _Castle Game Engine_. This concerns:
10
11 - TIFF
12 - JPEG2000
13
14 Reasons:
15
16 1. Their implementation in _Vampyre Imaging Library_ is platform-specific, and doesn't support all compilers and platforms we support, at least not easily.
17
18 2. Not trivial to use, as you need _LibTiff_ shared library in case of FPC + Linux, macOS, or Delphi + Win64.
19
20 For example, the TIFF format relies on a shared library _LibTiff_ for some platform/compiler combinations. It is uncertain can we support it on mobile (Android, iOS). We don't want a situation in which you design your graphics using TIFF on a desktop, and are surprised that on mobile you need to convert everything to PNG.
21
22 It is also an extra burden to implement, due to need to deploy _LibTiff_ to all the potential platforms. We have to limit such work, esp. when we can recommend a better replacement -- in case of TIFF, we recommend using PNG.
23
24 ## Example project for things below
25
26 Clone https://github.com/castle-engine/castle-image-viewer and switch to branch `extra-image-formats`.
27
28 It has all things described below, including:
29
30 - modifications in `CastleEngineManifest.xml` to enable TIFF support and package all new libraries and scripts added below,
31 - `run.sh` to set `LD_LIBRARY_PATH` to find `libtiff.so.5` on Linux,
32 - Linux libraries in `libraries/x86_64-linux/` .
33
34 ## Activating extra support
35
36 That said, you can compile the engine with `CASTLE_ENABLE_PLATFORM_SPECIFIC_IMAGE_FORMATS` symbol, so add suppport for TIFF. Define `CASTLE_ENABLE_PLATFORM_SPECIFIC_IMAGE_FORMATS` e.g. inside `CastleEngineManifest.xml` (see https://castle-engine.io/project_manifest#_compiler_options_and_paths ).
37
38 ## Getting LibTiff on Linux
39
40 Loading TIFF images on FPC + Linux requires `libtiff.so.5`.
41
42 Note: The _LibTiff_ "so" suffix naming (API version) is inconsistent with source code versioning.
43
44 - Compiling _LibTiff_ 3.9.6 (latest 3.x) -> results in `libtiff.so.3`.
45 - Compiling _LibTiff_ 4.6.0 (latest now) -> results in `libtiff.so.6`.
46 - See https://libtiff.gitlab.io/libtiff/releases/v4.5.0.html : _SONAME version bumped to 6 due to changes in symbol versioning._
47 - So... 4.4.0 is the latest that makes `libtiff.so.5`.
48
49 Follow https://libtiff.gitlab.io/libtiff/ to download the latest source code, right now it is https://download.osgeo.org/libtiff/tiff-4.4.0.zip .
50
51 Unpack and compile yourself, it follows the usual procedure for compiling C libraries on Linux. Below is just an example command-line, following personal preference of Michalis to put resulting lib in `~/installed/libtiff`:
52
53 ```
54 ./configure
55 make
56 mkdir -p ~/installed/libtiff
57 make install DESTDIR=$HOME/installed/libtiff
58 ```
59
60 Now you have libraries in `~/installed/libtiff/usr/local/lib` (you could also get them from `libtiff/.libs` directory in source, but using `make install ...` seems cleaner, allows to do any necessary processing). Copy them to your project, and setup `run.sh` to set `LD_LIBRARY_PATH` to this directory. Our CGE build tool and editor will automatically run your project through this script.
61
62 Example `run.sh` contents:
63
64 ```
65 #!/bin/bash
66 set -e
67 # Include additional directory in LD_LIBRARY_PATH, to find libtiff
68 export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:libraries/x86_64-linux/"
69 ./castle-image-viewer "$@"
70 ```
71
72 Example how to copy `libtiff.*` libraries to your project and test:
73
74 ```
75 cd ~/sources/castle-engine/castle-image-viewer
76 chmod +x run.sh
77 mkdir -p libraries/x86_64-linux
78 cp -Rf ~/installed/libtiff/usr/local/lib/* libraries/x86_64-linux/
79 # make sure it makes sense, should show libtiff.so and valid symlinks
80 ls -Flah libraries/x86_64-linux/
81 castle-engine compile
82 castle-engine run # will run run.sh
83 ```
84
85 ## Getting LibTiff on Windows
86
87 Loading TIFF images on Windows requires `libtiff.dll` in case of compiling with Delphi for Win64.
88
89 NOTE: The DLL is not necessary for Delphi + Win32 or FPC + any Windows (32 or 64). These combinations use ready TIFF support compiled-in (the `obj` files in `src/vampyre_imaginglib/src/Extensions/LibTiff/Compiled/`) and it should just work out-of-the-box. You can ignore this section if you don't care about Delphi + Win64.
90
91 Following http://www.libtiff.org/build.html :
92
93 - Get CMake, from https://cmake.org/download/ . I found it easiest to use Windows installer. Allow it to modify PATH, to have `cmake` on command-line.
94
95 - TODO: Finish this.
96
97 And commit resulting DLL to castle-image-viewer in extra-image-formats branch.
98
99 And mention it has DLL in "## Example project for things below" section above.
100
101 ## Packacking LibTiff linbraries and run.sh script
102
103 Extend your `CastleEngineManifest.xml` to package extra libraries and scripts:
104
105 ```xml
106 <package>
107 <include path="libtiff.dll" /> <!-- necessary if you use Delphi + Win64 -->
108 <include path="run.sh" />
109 <include path="libraries/x86_64-linux/" recursive="True" />
110 </package>
111 ```