Skip to content

Commit 5d4c1e4

Browse files
committed
ChicleTiffLoader: Accept BigTIFF images
BigTIFF has 43 in the TIFF version field. Fixes #328 (GitHub).
1 parent dd4d4c1 commit 5d4c1e4

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

tools/chafa/chicle-tiff-loader.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ my_tiff_warning_handler (G_GNUC_UNUSED const char *module, G_GNUC_UNUSED const c
151151

152152
/* --- Loader --- */
153153

154+
#define STDTIFF_HEADER_VERSION 42
155+
#define BIGTIFF_HEADER_VERSION 43
156+
157+
static gboolean
158+
have_tiff_magic (ChicleFileMapping *mapping, gchar tiff_version)
159+
{
160+
gchar magic_le [4] = { 'I', 'I', 0, 0 };
161+
gchar magic_be [4] = { 'M', 'M', 0, 0 };
162+
163+
magic_le [2] = tiff_version;
164+
magic_be [3] = tiff_version;
165+
166+
return chicle_file_mapping_has_magic (mapping, 0, magic_le, 4)
167+
|| chicle_file_mapping_has_magic (mapping, 0, magic_be, 4);
168+
}
169+
154170
static ChicleTiffLoader *
155171
chicle_tiff_loader_new (void)
156172
{
@@ -169,10 +185,8 @@ chicle_tiff_loader_new_from_mapping (ChicleFileMapping *mapping)
169185

170186
g_return_val_if_fail (mapping != NULL, NULL);
171187

172-
if (!((chicle_file_mapping_has_magic (mapping, 0, "II", 2)
173-
&& chicle_file_mapping_has_magic (mapping, 2, "\x2a\x00", 2))
174-
|| (chicle_file_mapping_has_magic (mapping, 0, "MM", 2)
175-
&& chicle_file_mapping_has_magic (mapping, 2, "\x00\x2a", 2))))
188+
if (!(have_tiff_magic (mapping, STDTIFF_HEADER_VERSION)
189+
|| have_tiff_magic (mapping, BIGTIFF_HEADER_VERSION)))
176190
goto out;
177191

178192
loader = chicle_tiff_loader_new ();

0 commit comments

Comments
 (0)