Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read support for Radiance .hdr files #4316

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ namespace sharp {
case ImageType::JXL: id = "jxl"; break;
case ImageType::VIPS: id = "vips"; break;
case ImageType::RAW: id = "raw"; break;
case ImageType::RAD: id = "rad"; break;
case ImageType::UNKNOWN: id = "unknown"; break;
case ImageType::MISSING: id = "missing"; break;
}
Expand Down Expand Up @@ -296,7 +297,9 @@ namespace sharp {
{ "VipsForeignLoadJxlBuffer", ImageType::JXL },
{ "VipsForeignLoadVips", ImageType::VIPS },
{ "VipsForeignLoadVipsFile", ImageType::VIPS },
{ "VipsForeignLoadRaw", ImageType::RAW }
{ "VipsForeignLoadRaw", ImageType::RAW },
{ "VipsForeignLoadRadFile", ImageType::RAD },
{ "VipsForeignLoadRadBuffer", ImageType::RAD }
};

/*
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace sharp {
JXL,
VIPS,
RAW,
RAD,
UNKNOWN,
MISSING
};
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Napi::Value format(const Napi::CallbackInfo& info) {
Napi::Object format = Napi::Object::New(env);
for (std::string const f : {
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl"
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad"
}) {
// Input
const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ module.exports = {
testPattern: getPath('test-pattern.png'),

inputPngWithTransparent: getPath('d.png'),

inputHdr: getPath('rogland_moonlit_night_1k.hdr'), // CC0 https://polyhaven.com/a/rogland_moonlit_night

// Path for tests requiring human inspection
path: getPath,

Expand Down
Binary file added test/fixtures/rogland_moonlit_night_1k.hdr
Binary file not shown.
36 changes: 36 additions & 0 deletions test/unit/hdr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const fs = require('fs');
const assert = require('assert');

const sharp = require('../../');
const fixtures = require('../fixtures');

describe('RAD', function () {
it('Load rad from file', function (done) {
sharp(fixtures.inputHdr)
.jpeg()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual('jpeg', info.format);
assert.strictEqual(1024, info.width);
assert.strictEqual(512, info.height);
done();
});
});

it('Load rad from buffer', function (done) {
const buffer = fs.readFileSync(fixtures.inputHdr);
sharp(buffer)
.jpeg()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual('jpeg', info.format);
assert.strictEqual(1024, info.width);
assert.strictEqual(512, info.height);
done();
});
});
});