mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 13:46:19 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9d196f696 | ||
|
|
2f97d04dfa |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sharp",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.4",
|
||||
"author": "Lovell Fuller",
|
||||
"description": "High performance module to resize JPEG and PNG images using the libvips image processing library",
|
||||
"scripts": {
|
||||
|
||||
37
src/sharp.cc
37
src/sharp.cc
@@ -98,22 +98,21 @@ void resize_async(uv_work_t *work) {
|
||||
int shrink_on_load = 1;
|
||||
if (inputImageType == JPEG) {
|
||||
if (shrink >= 8) {
|
||||
factor = residual * shrink / 8;
|
||||
factor = factor / 8;
|
||||
shrink_on_load = 8;
|
||||
shrink = floor(factor);
|
||||
residual = shrink / factor;
|
||||
} else if (shrink >= 4) {
|
||||
factor = residual * shrink / 4;
|
||||
factor = factor / 4;
|
||||
shrink_on_load = 4;
|
||||
shrink = floor(factor);
|
||||
residual = shrink / factor;
|
||||
} else if (shrink >= 2) {
|
||||
factor = residual * shrink / 2;
|
||||
factor = factor / 2;
|
||||
shrink_on_load = 2;
|
||||
shrink = floor(factor);
|
||||
residual = shrink / factor;
|
||||
}
|
||||
if (shrink_on_load > 1) {
|
||||
// Recalculate integral shrink and double residual
|
||||
factor = std::max(factor, 1.0);
|
||||
shrink = floor(factor);
|
||||
residual = shrink / factor;
|
||||
// Reload input using shrink-on-load
|
||||
g_object_unref(in);
|
||||
in = vips_image_new();
|
||||
if (baton->buffer_in_len > 1) {
|
||||
@@ -152,7 +151,7 @@ void resize_async(uv_work_t *work) {
|
||||
|
||||
VipsImage *canvased = vips_image_new();
|
||||
if (affined->Xsize != baton->width || affined->Ysize != baton->height) {
|
||||
if (baton->crop && affined->Xsize != baton->width && affined->Ysize != baton->height) {
|
||||
if (baton->crop) {
|
||||
// Crop
|
||||
int width = std::min(affined->Xsize, baton->width);
|
||||
int height = std::min(affined->Ysize, baton->height);
|
||||
@@ -192,28 +191,28 @@ void resize_async(uv_work_t *work) {
|
||||
|
||||
if (baton->file_out == "__jpeg") {
|
||||
// Write JPEG to buffer
|
||||
if (vips_jpegsave_buffer(canvased, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "Q", 80, "optimize_coding", TRUE, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, canvased);
|
||||
if (vips_jpegsave_buffer(sharpened, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "Q", 80, "optimize_coding", TRUE, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, sharpened);
|
||||
}
|
||||
} else if (baton->file_out == "__png") {
|
||||
// Write PNG to buffer
|
||||
if (vips_pngsave_buffer(canvased, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "compression", 6, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, canvased);
|
||||
if (vips_pngsave_buffer(sharpened, &baton->buffer_out, &baton->buffer_out_len, "strip", TRUE, "compression", 6, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, sharpened);
|
||||
}
|
||||
} else if (is_jpeg(baton->file_out)) {
|
||||
// Write JPEG to file
|
||||
if (vips_jpegsave(canvased, baton->file_out.c_str(), "strip", TRUE, "Q", 80, "optimize_coding", TRUE, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, canvased);
|
||||
if (vips_jpegsave(sharpened, baton->file_out.c_str(), "strip", TRUE, "Q", 80, "optimize_coding", TRUE, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, sharpened);
|
||||
}
|
||||
} else if (is_png(baton->file_out)) {
|
||||
// Write PNG to file
|
||||
if (vips_pngsave(canvased, baton->file_out.c_str(), "strip", TRUE, "compression", 6, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, canvased);
|
||||
if (vips_pngsave(sharpened, baton->file_out.c_str(), "strip", TRUE, "compression", 6, "interlace", baton->progessive, NULL)) {
|
||||
return resize_error(baton, sharpened);
|
||||
}
|
||||
} else {
|
||||
(baton->err).append("Unsupported output " + baton->file_out);
|
||||
}
|
||||
g_object_unref(canvased);
|
||||
g_object_unref(sharpened);
|
||||
vips_thread_shutdown();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user