#endif
+static i_mutex_t mutex;
+
+void
+i_tiff_init(void) {
+ mutex = i_mutex_new();
+}
+
static int save_tiff_tags(TIFF *tif, i_img *im);
static void
int current_page;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
i_clear_error();
old_handler = TIFFSetErrorHandler(error_handler);
#ifdef USE_EXT_WARN_HANDLER
TIFFSetWarningHandlerExt(old_ext_warn_handler);
#endif
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return NULL;
}
#endif
TIFFClose(tif);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return NULL;
}
}
#endif
TIFFClose(tif);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return im;
}
int result_alloc = 0;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
i_clear_error();
old_handler = TIFFSetErrorHandler(error_handler);
#ifdef USE_EXT_WARN_HANDLER
TIFFSetWarningHandlerExt(old_ext_warn_handler);
#endif
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return NULL;
}
#endif
TIFFClose(tif);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return results;
}
int i;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
old_handler = TIFFSetErrorHandler(error_handler);
i_clear_error();
i_push_error(0, "Could not create TIFF object");
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
}
(void) TIFFClose(tif);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
+
if (i_io_close(ig))
return 0;
TIFFErrorHandler old_handler;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
old_handler = TIFFSetErrorHandler(error_handler);
i_clear_error();
i_push_error(0, "Could not create TIFF object");
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
}
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
+
if (i_io_close(ig))
return 0;
TIFFErrorHandler old_handler;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
old_handler = TIFFSetErrorHandler(error_handler);
i_clear_error();
i_push_error(0, "Could not create TIFF object");
tiffio_context_final(&ctx);
TIFFSetErrorHandler(old_handler);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
tiffio_context_final(&ctx);
TIFFSetErrorHandler(old_handler);
+ i_mutex_unlock(mutex);
return 0;
}
(void) TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
- tiffio_context_final(&ctx);
+ tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
if (i_io_close(ig))
return 0;
TIFFErrorHandler old_handler;
tiffio_context_t ctx;
+ i_mutex_lock(mutex);
+
old_handler = TIFFSetErrorHandler(error_handler);
i_clear_error();
i_push_error(0, "Could not create TIFF object");
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
return 0;
}
(void) TIFFClose(tif);
TIFFSetErrorHandler(old_handler);
tiffio_context_final(&ctx);
+ i_mutex_unlock(mutex);
if (i_io_close(ig))
return 0;
--- /dev/null
+#!perl -w
+use strict;
+use threads;
+use Imager;
+
+++$|;
+Imager->preload;
+
+# as a TIFF this file is large, build it from largeish.jpg if it
+# doesn't exist
+unless (-f "bench/largish.tif") {
+ my $im = Imager->new(file => "bench/largish.jpg")
+ or die "Cannot read bench/largish.jpg:", Imager->errstr;
+ $im->write(file => "bench/largish.tif")
+ or die "Cannot write bench.largish.tif:", $im->errstr;
+}
+
+my @tests =
+ (
+ [ "bench/largish.tif", "" ],
+ [ "TIFF/testimg/grey16.tif", "" ],
+ [ "TIFF/testimg/comp4bad.tif", "(Iolayer): Read error at scanline 120; got 0 bytes, expected 32" ],
+ );
+
+my @threads;
+my $name = "A";
+for my $test (@tests) {
+ push @threads,
+ threads->create
+ (
+ sub {
+ my ($file, $result, $name) = @_;
+ for (1 .. 100000) {
+ print $name;
+ my $im = Imager->new(file => $file);
+ if ($result) {
+ $im and die "Expected error from $file, got image";
+ Imager->errstr eq $result
+ or die "Expected error '$result', got '",Imager->errstr, "'"
+ }
+ else {
+ $im or die "Expected image got error '", Imager->errstr, "'";
+ }
+ }
+ return;
+ },
+ @$test,
+ $name
+ );
+ ++$name;
+}
+
+for my $t (@threads) {
+ $t->join();
+}