Clean up internal naming of format-specific input options

This commit is contained in:
Lovell Fuller 2025-06-17 13:24:55 +01:00
parent e286e2bff9
commit 852c7f8663
3 changed files with 36 additions and 33 deletions

View File

@ -30,7 +30,7 @@ const inputStreamParameters = [
// Format-specific // Format-specific
'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff', 'jp2', 'openSlide', 'pdf', 'raw', 'svg', 'tiff',
// Deprecated // Deprecated
'failOnError', 'level', 'pdfBackground', 'subifd' 'failOnError', 'openSlideLevel', 'pdfBackground', 'tiffSubifd'
]; ];
/** /**
@ -246,14 +246,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
// OpenSlide specific options // OpenSlide specific options
if (is.object(inputOptions.openSlide) && is.defined(inputOptions.openSlide.level)) { if (is.object(inputOptions.openSlide) && is.defined(inputOptions.openSlide.level)) {
if (is.integer(inputOptions.openSlide.level) && is.inRange(inputOptions.openSlide.level, 0, 256)) { if (is.integer(inputOptions.openSlide.level) && is.inRange(inputOptions.openSlide.level, 0, 256)) {
inputDescriptor.level = inputOptions.openSlide.level; inputDescriptor.openSlideLevel = inputOptions.openSlide.level;
} else { } else {
throw is.invalidParameterError('openSlide.level', 'integer between 0 and 256', inputOptions.openSlide.level); throw is.invalidParameterError('openSlide.level', 'integer between 0 and 256', inputOptions.openSlide.level);
} }
} else if (is.defined(inputOptions.level)) { } else if (is.defined(inputOptions.level)) {
// Deprecated // Deprecated
if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) { if (is.integer(inputOptions.level) && is.inRange(inputOptions.level, 0, 256)) {
inputDescriptor.level = inputOptions.level; inputDescriptor.openSlideLevel = inputOptions.level;
} else { } else {
throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level); throw is.invalidParameterError('level', 'integer between 0 and 256', inputOptions.level);
} }
@ -261,14 +261,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
// TIFF specific options // TIFF specific options
if (is.object(inputOptions.tiff) && is.defined(inputOptions.tiff.subifd)) { if (is.object(inputOptions.tiff) && is.defined(inputOptions.tiff.subifd)) {
if (is.integer(inputOptions.tiff.subifd) && is.inRange(inputOptions.tiff.subifd, -1, 100000)) { if (is.integer(inputOptions.tiff.subifd) && is.inRange(inputOptions.tiff.subifd, -1, 100000)) {
inputDescriptor.subifd = inputOptions.tiff.subifd; inputDescriptor.tiffSubifd = inputOptions.tiff.subifd;
} else { } else {
throw is.invalidParameterError('tiff.subifd', 'integer between -1 and 100000', inputOptions.tiff.subifd); throw is.invalidParameterError('tiff.subifd', 'integer between -1 and 100000', inputOptions.tiff.subifd);
} }
} else if (is.defined(inputOptions.subifd)) { } else if (is.defined(inputOptions.subifd)) {
// Deprecated // Deprecated
if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) { if (is.integer(inputOptions.subifd) && is.inRange(inputOptions.subifd, -1, 100000)) {
inputDescriptor.subifd = inputOptions.subifd; inputDescriptor.tiffSubifd = inputOptions.subifd;
} else { } else {
throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd); throw is.invalidParameterError('subifd', 'integer between -1 and 100000', inputOptions.subifd);
} }

View File

@ -109,12 +109,12 @@ namespace sharp {
descriptor->svgHighBitdepth = AttrAsBool(input, "svgHighBitdepth"); descriptor->svgHighBitdepth = AttrAsBool(input, "svgHighBitdepth");
} }
// Multi-level input (OpenSlide) // Multi-level input (OpenSlide)
if (HasAttr(input, "level")) { if (HasAttr(input, "openSlideLevel")) {
descriptor->level = AttrAsUint32(input, "level"); descriptor->openSlideLevel = AttrAsUint32(input, "openSlideLevel");
} }
// subIFD (OME-TIFF) // subIFD (OME-TIFF)
if (HasAttr(input, "subifd")) { if (HasAttr(input, "subifd")) {
descriptor->subifd = AttrAsInt32(input, "subifd"); descriptor->tiffSubifd = AttrAsInt32(input, "tiffSubifd");
} }
// // PDF background color // // PDF background color
if (HasAttr(input, "pdfBackground")) { if (HasAttr(input, "pdfBackground")) {
@ -404,31 +404,34 @@ namespace sharp {
if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) { if (descriptor->unlimited && ImageTypeSupportsUnlimited(imageType)) {
option->set("unlimited", true); option->set("unlimited", true);
} }
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
option->set("dpi", descriptor->density);
}
if (imageType == ImageType::MAGICK) {
option->set("density", std::to_string(descriptor->density).data());
}
if (ImageTypeSupportsPage(imageType)) { if (ImageTypeSupportsPage(imageType)) {
option->set("n", descriptor->pages); option->set("n", descriptor->pages);
option->set("page", descriptor->page); option->set("page", descriptor->page);
} }
if (imageType == ImageType::SVG) { switch (imageType) {
option->set("stylesheet", descriptor->svgStylesheet.data()); case ImageType::SVG:
option->set("high_bitdepth", descriptor->svgHighBitdepth); option->set("dpi", descriptor->density)
} ->set("stylesheet", descriptor->svgStylesheet.data())
if (imageType == ImageType::OPENSLIDE) { ->set("high_bitdepth", descriptor->svgHighBitdepth);
option->set("level", descriptor->level); break;
} case ImageType::TIFF:
if (imageType == ImageType::TIFF) { option->set("tiffSubifd", descriptor->tiffSubifd);
option->set("subifd", descriptor->subifd); break;
} case ImageType::PDF:
if (imageType == ImageType::PDF) { option->set("dpi", descriptor->density)
option->set("background", descriptor->pdfBackground); ->set("background", descriptor->pdfBackground);
} break;
if (imageType == ImageType::JP2) { case ImageType::OPENSLIDE:
option->set("openSlideLevel", descriptor->openSlideLevel);
break;
case ImageType::JP2:
option->set("oneshot", descriptor->jp2Oneshot); option->set("oneshot", descriptor->jp2Oneshot);
break;
case ImageType::MAGICK:
option->set("density", std::to_string(descriptor->density).data());
break;
default:
break;
} }
return option; return option;
} }

View File

@ -50,8 +50,6 @@ namespace sharp {
bool rawPremultiplied; bool rawPremultiplied;
int pages; int pages;
int page; int page;
int level;
int subifd;
int createChannels; int createChannels;
int createWidth; int createWidth;
int createHeight; int createHeight;
@ -79,6 +77,8 @@ namespace sharp {
VipsAlign joinValign; VipsAlign joinValign;
std::string svgStylesheet; std::string svgStylesheet;
bool svgHighBitdepth; bool svgHighBitdepth;
int tiffSubifd;
int openSlideLevel;
std::vector<double> pdfBackground; std::vector<double> pdfBackground;
bool jp2Oneshot; bool jp2Oneshot;
@ -100,8 +100,6 @@ namespace sharp {
rawPremultiplied(false), rawPremultiplied(false),
pages(1), pages(1),
page(0), page(0),
level(0),
subifd(-1),
createChannels(0), createChannels(0),
createWidth(0), createWidth(0),
createHeight(0), createHeight(0),
@ -124,6 +122,8 @@ namespace sharp {
joinHalign(VIPS_ALIGN_LOW), joinHalign(VIPS_ALIGN_LOW),
joinValign(VIPS_ALIGN_LOW), joinValign(VIPS_ALIGN_LOW),
svgHighBitdepth(false), svgHighBitdepth(false),
tiffSubifd(-1),
openSlideLevel(0),
pdfBackground{ 255.0, 255.0, 255.0, 255.0 }, pdfBackground{ 255.0, 255.0, 255.0, 255.0 },
jp2Oneshot(false) {} jp2Oneshot(false) {}
}; };