From 61b86744d7fbcebc4796d89063ca87b38c9c649c Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 23 Dec 2015 20:46:49 +0000 Subject: [PATCH] Ensure 16-bit input images work with embed option #325 --- docs/changelog.md | 6 ++++++ package.json | 2 +- src/pipeline.cc | 27 ++++++++++++------------- test/fixtures/expected/embed-16bit.png | Bin 0 -> 827 bytes test/unit/embed.js | 14 +++++++++++++ 5 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 test/fixtures/expected/embed-16bit.png diff --git a/docs/changelog.md b/docs/changelog.md index 5bcdd147..93eb1904 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,12 @@ ### v0.12 - "*look*" +#### v0.12.2 - TBD + +* Ensure 16-bit input images work with embed option. + [#325](https://github.com/lovell/sharp/issues/325) + [@janaz](https://github.com/janaz) + #### v0.12.1 - 12th December 2015 * Allow use of SIMD vector instructions (via liborc) to be toggled on/off. diff --git a/package.json b/package.json index dab15784..a26863d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sharp", - "version": "0.12.1", + "version": "0.12.2", "author": "Lovell Fuller ", "contributors": [ "Pierre Inglebert ", diff --git a/src/pipeline.cc b/src/pipeline.cc index 1558b425..91a62662 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -627,16 +627,6 @@ class PipelineWorker : public AsyncWorker { // Crop/embed if (image->Xsize != baton->width || image->Ysize != baton->height) { if (baton->canvas == Canvas::EMBED) { - // Match background colour space, namely sRGB - if (image->Type != VIPS_INTERPRETATION_sRGB) { - // Convert to sRGB colour space - VipsImage *colourspaced; - if (vips_colourspace(image, &colourspaced, VIPS_INTERPRETATION_sRGB, nullptr)) { - return Error(); - } - vips_object_local(hook, colourspaced); - image = colourspaced; - } // Add non-transparent alpha channel, if required if (baton->background[3] < 255.0 && !HasAlpha(image)) { // Create single-channel transparency @@ -661,13 +651,22 @@ class PipelineWorker : public AsyncWorker { } // Create background VipsArrayDouble *background; + // Scale up 8-bit values to match 16-bit input image + double multiplier = (image->Type == VIPS_INTERPRETATION_RGB16) ? 256.0 : 1.0; if (baton->background[3] < 255.0 || HasAlpha(image)) { - background = vips_array_double_newv( - 4, baton->background[0], baton->background[1], baton->background[2], baton->background[3] + // RGBA + background = vips_array_double_newv(4, + baton->background[0] * multiplier, + baton->background[1] * multiplier, + baton->background[2] * multiplier, + baton->background[3] * multiplier ); } else { - background = vips_array_double_newv( - 3, baton->background[0], baton->background[1], baton->background[2] + // RGB + background = vips_array_double_newv(3, + baton->background[0] * multiplier, + baton->background[1] * multiplier, + baton->background[2] * multiplier ); } // Embed diff --git a/test/fixtures/expected/embed-16bit.png b/test/fixtures/expected/embed-16bit.png new file mode 100644 index 0000000000000000000000000000000000000000..9b49e8cbf08ae2a2f78fabfb5f290862901799c7 GIT binary patch literal 827 zcmV-B1H}A^P)K^%tP?QZHJiICl-NfuLTVg+LlQUZ#YiXs*Y ztyBx1?4bu++V4>M0eTDALlG%dC`i3Xi$M{+6_V0u(}imPYIaOaLN&?gvf0_~$y33s z))(e9@XW*fhIa%27ETV=V82mLO>g7xMkD|!#wKW)}5*$wFc6NH2d|p^!hd$qEw6l}A-EMMj0>xtS z!|d#Ah-`1muEj-&ih{6d!f%@R4Pe*hLNS|_7sto3_vlf|N}N!Jo?w_nrir7Yi%^tdT)FZFJbx2{(2dpA)zNbm5D!Ig6%N{-h8<%E9OGaz z6O1wB^H*V-A3X1>-hDn4T7)& zQ7nPuIxsX8As&y%Ru9+`;CY@sd-!Z;s5->rnK(F!1IIWpgMm^CO3UDRid^m~L)h06@4U-1B_+c`P1|GneiH41gI7wOS2!0lJ@AJiCF_lOp zjLFGKYi4HV)4{=kd{+Lc1&));<+>C_Nu|^2lPdQ_{$H@{ZQ60VRMY?f002ovPDHLk FV1h-fdA 0); + assert.strictEqual('png', info.format); + assert.strictEqual(32, info.width); + assert.strictEqual(16, info.height); + fixtures.assertSimilar(fixtures.expected('embed-16bit.png'), data, done); + }); + }); + it('Enlarge and embed', function(done) { sharp(fixtures.inputPngWithOneColor) .embed()