mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Allow floating point density input (#1362)
Metadata output will still remain integer
This commit is contained in:
committed by
Lovell Fuller
parent
bf3254cb16
commit
7d48a5ccf4
@@ -55,7 +55,7 @@ namespace sharp {
|
||||
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
|
||||
// Density for vector-based input
|
||||
if (HasAttr(input, "density")) {
|
||||
descriptor->density = AttrTo<uint32_t>(input, "density");
|
||||
descriptor->density = AttrTo<double>(input, "density");
|
||||
}
|
||||
// Raw pixel input
|
||||
if (HasAttr(input, "rawChannels")) {
|
||||
@@ -228,7 +228,7 @@ namespace sharp {
|
||||
->set("access", accessMethod)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", static_cast<double>(descriptor->density));
|
||||
option->set("dpi", descriptor->density);
|
||||
}
|
||||
if (imageType == ImageType::MAGICK) {
|
||||
option->set("density", std::to_string(descriptor->density).data());
|
||||
@@ -270,7 +270,7 @@ namespace sharp {
|
||||
->set("access", accessMethod)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", static_cast<double>(descriptor->density));
|
||||
option->set("dpi", descriptor->density);
|
||||
}
|
||||
if (imageType == ImageType::MAGICK) {
|
||||
option->set("density", std::to_string(descriptor->density).data());
|
||||
@@ -355,8 +355,8 @@ namespace sharp {
|
||||
/*
|
||||
Set pixels/mm resolution based on a pixels/inch density.
|
||||
*/
|
||||
void SetDensity(VImage image, const int density) {
|
||||
const double pixelsPerMm = static_cast<double>(density) / 25.4;
|
||||
void SetDensity(VImage image, const double density) {
|
||||
const double pixelsPerMm = density / 25.4;
|
||||
image.set("Xres", pixelsPerMm);
|
||||
image.set("Yres", pixelsPerMm);
|
||||
image.set(VIPS_META_RESOLUTION_UNIT, "in");
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace sharp {
|
||||
char *buffer;
|
||||
bool failOnError;
|
||||
size_t bufferLength;
|
||||
int density;
|
||||
double density;
|
||||
int rawChannels;
|
||||
int rawWidth;
|
||||
int rawHeight;
|
||||
@@ -63,7 +63,7 @@ namespace sharp {
|
||||
buffer(nullptr),
|
||||
failOnError(FALSE),
|
||||
bufferLength(0),
|
||||
density(72),
|
||||
density(72.0),
|
||||
rawChannels(0),
|
||||
rawWidth(0),
|
||||
rawHeight(0),
|
||||
@@ -186,7 +186,7 @@ namespace sharp {
|
||||
/*
|
||||
Set pixels/mm resolution based on a pixels/inch density.
|
||||
*/
|
||||
void SetDensity(VImage image, const int density);
|
||||
void SetDensity(VImage image, const double density);
|
||||
|
||||
/*
|
||||
Check the proposed format supports the current dimensions.
|
||||
|
||||
Reference in New Issue
Block a user