Added Deep Zoom support.

Added OpenSuse 13.1 and 13.2 support in preinstall.sh script.
Added OpenSlide support in preinstall script.
Added unit tests for Deep Zoom and OpenSlide.
This commit is contained in:
Victor Mateevitsi
2014-12-16 15:46:47 +00:00
committed by Lovell Fuller
parent 5240eeb518
commit 2d1e6f2644
11 changed files with 412 additions and 36 deletions

View File

@@ -28,6 +28,9 @@ namespace sharp {
bool IsTiff(std::string const &str) {
return EndsWith(str, ".tif") || EndsWith(str, ".tiff") || EndsWith(str, ".TIF") || EndsWith(str, ".TIFF");
}
bool IsDz(std::string const &str) {
return EndsWith(str, ".dzi") || EndsWith(str, ".DZI");
}
/*
Determine image format of a buffer.
@@ -103,6 +106,7 @@ namespace sharp {
} else if(vips_foreign_is_a("magickload", file)) {
imageType = ImageType::MAGICK;
}
return imageType;
}

View File

@@ -9,7 +9,8 @@ namespace sharp {
PNG,
WEBP,
TIFF,
MAGICK
MAGICK,
DZ
};
// How many tasks are in the queue?
@@ -23,6 +24,7 @@ namespace sharp {
bool IsPng(std::string const &str);
bool IsWebp(std::string const &str);
bool IsTiff(std::string const &str);
bool IsDz(std::string const &str);
/*
Determine image format of a buffer.

View File

@@ -90,6 +90,7 @@ class MetadataWorker : public NanAsyncWorker {
case ImageType::WEBP: baton->format = "webp"; break;
case ImageType::TIFF: baton->format = "tiff"; break;
case ImageType::MAGICK: baton->format = "magick"; break;
case ImageType::DZ: baton->format = "dzi"; break;
case ImageType::UNKNOWN: break;
}
// VipsImage attributes

View File

@@ -32,6 +32,7 @@ using sharp::IsJpeg;
using sharp::IsPng;
using sharp::IsWebp;
using sharp::IsTiff;
using sharp::IsDz;
using sharp::counterProcess;
using sharp::counterQueue;
@@ -94,6 +95,8 @@ struct ResizeBaton {
bool withoutChromaSubsampling;
std::string err;
bool withMetadata;
int tileSize;
int tileOverlap;
ResizeBaton():
bufferInLength(0),
@@ -120,7 +123,9 @@ struct ResizeBaton {
compressionLevel(6),
withoutAdaptiveFiltering(false),
withoutChromaSubsampling(false),
withMetadata(false) {
withMetadata(false),
tileSize(256),
tileOverlap(0) {
background[0] = 0.0;
background[1] = 0.0;
background[2] = 0.0;
@@ -755,7 +760,8 @@ class ResizeWorker : public NanAsyncWorker {
bool outputPng = IsPng(baton->output);
bool outputWebp = IsWebp(baton->output);
bool outputTiff = IsTiff(baton->output);
bool matchInput = !(outputJpeg || outputPng || outputWebp || outputTiff);
bool outputDz = IsDz(baton->output);
bool matchInput = !(outputJpeg || outputPng || outputWebp || outputTiff || outputDz);
if (outputJpeg || (matchInput && inputImageType == ImageType::JPEG)) {
// Write JPEG to file
if (vips_jpegsave(image, baton->output.c_str(), "strip", !baton->withMetadata,
@@ -795,6 +801,14 @@ class ResizeWorker : public NanAsyncWorker {
return Error(baton, hook);
}
baton->outputFormat = "tiff";
} else if (outputDz || matchInput) {
// Write DZ to file
std::string filename_no_extension = baton->output.substr(0, baton->output.length() - 4);
if (vips_dzsave(image, filename_no_extension.c_str(), "strip", !baton->withMetadata,
"tile_size", baton->tileSize, "overlap", baton->tileOverlap, NULL)) {
return Error(baton, hook);
}
baton->outputFormat = "dz";
} else {
(baton->err).append("Unsupported output " + baton->output);
return Error(baton, hook);
@@ -828,8 +842,13 @@ class ResizeWorker : public NanAsyncWorker {
// Info Object
Local<Object> info = NanNew<Object>();
info->Set(NanNew<String>("format"), NanNew<String>(baton->outputFormat));
info->Set(NanNew<String>("width"), NanNew<Integer>(width));
info->Set(NanNew<String>("height"), NanNew<Integer>(height));
info->Set(NanNew<String>("width"), NanNew<Uint32>(static_cast<uint32_t>(width)));
info->Set(NanNew<String>("height"), NanNew<Uint32>(static_cast<uint32_t>(height)));
if (baton->outputFormat == "dz" ) {
info->Set(NanNew<String>("tileSize"), NanNew<Uint32>(static_cast<uint32_t>(baton->tileSize)));
info->Set(NanNew<String>("tileOverlap"), NanNew<Uint32>(static_cast<uint32_t>(baton->tileOverlap)));
}
if (baton->bufferOutLength > 0) {
// Copy data to new Buffer
@@ -1017,6 +1036,8 @@ NAN_METHOD(resize) {
baton->withMetadata = options->Get(NanNew<String>("withMetadata"))->BooleanValue();
// Output filename or __format for Buffer
baton->output = *String::Utf8Value(options->Get(NanNew<String>("output"))->ToString());
baton->tileSize = options->Get(NanNew<String>("tileSize"))->Int32Value();
baton->tileOverlap = options->Get(NanNew<String>("tileOverlap"))->Int32Value();
// Join queue for worker thread
NanCallback *callback = new NanCallback(args[1].As<Function>());