Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,13 @@ class PipelineWorker : public Napi::AsyncWorker {
if (baton->input->autoOrient) {
image = sharp::RemoveExifOrientation(image);
}
VImage gainMapSource;
VImage gainMap;
int gainMapScaleFactor = 1;
if (sharp::HasGainMap(image)) {
if (baton->keepGainMap) {
// Keep source-owned gain-map bytes alive for lazy decoding.
gainMapSource = image;
gainMap = image.gainmap();
if (image.get_typeof("gainmap-scale-factor") == G_TYPE_INT) {
gainMapScaleFactor = image.get_int("gainmap-scale-factor");
Expand Down
25 changes: 25 additions & 0 deletions test/unit/gain-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ const sharp = require('../../');
const fixtures = require('../fixtures');

suite('Gain maps', () => {
test('Can rotate while keeping gain map with cache disabled', async (t) => {
const previousCache = sharp.cache();
sharp.cache(false);
try {
const data = await sharp(fixtures.inputJpgWithGainMap)
.keepGainMap()
.rotate(90)
.toBuffer();
const metadata = await sharp(data).metadata();
t.assert.deepStrictEqual([metadata.width, metadata.height], [2160, 3840]);
t.assert.ok(metadata.gainMap);
const { data: gainMapPixels, info: gainMapInfo } = await sharp(metadata.gainMap.image)
.raw()
.toBuffer({ resolveWithObject: true });
t.assert.ok(gainMapPixels.length > 0);
t.assert.deepStrictEqual([gainMapInfo.width, gainMapInfo.height], [540, 960]);
} finally {
sharp.cache({
memory: previousCache.memory.max,
files: previousCache.files.max,
items: previousCache.items.max
});
}
});

test('Metadata contains gainMap', async (t) => {
t.plan(4);

Expand Down