Skip to content

Commit

Permalink
test(libultrahdr): adds initial tests for decoding gainmap embedded i…
Browse files Browse the repository at this point in the history
…n jpeg files
  • Loading branch information
daniele-pelagatti committed Oct 24, 2023
1 parent f360f36 commit 86a4efb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
14 changes: 7 additions & 7 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
setupFilesAfterEnv: ['jest-extended/all'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
},
transformIgnorePatterns: ['node_modules/(?!(three))'],
// moduleNameMapper: {
// '^(\\.{1,2}/.*)\\.js$': '$1'
// },
transformIgnorePatterns: [
'node_modules/(?!(three|image-info-extractor))'
],
transform: {
// '^.+\\.jsx?$': 'babel-jest', // Adding this line solved the issue
'^.+\\.[tj]sx?$': 'ts-jest' // to process js/ts with `ts-jest`
// '^.+\\.tsx?$': 'ts-jest'
'^.+\\.[tj]s[xm]?$': ['ts-jest', { tsconfig: 'tests/tsconfig.json' }]
}
}
Binary file added tests/fixtures/01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/memorial.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions tests/libultrahdr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync } from 'fs'
import { mkdir, writeFile } from 'fs/promises'
import path from 'path'

import { type UltraHDRUnpacked } from '../libultrahdr-wasm/build/libultrahdr'
import { getTestbed } from './common'

describe('wasm', () => {
Expand All @@ -25,4 +26,22 @@ describe('wasm', () => {
}
await writeFile(path.join(__dirname, './results/result-embedded.jpg'), Buffer.from(jpeg))
}, 100000)

it('extracts metadata', async () => {
const { page, pageError } = await getTestbed()

const result = await page.evaluate(`decodeJPEGMetadata(
'memorial.jpg'
)`) as UltraHDRUnpacked

result.gainMap = Uint8Array.from(result.gainMap)
result.sdr = Uint8Array.from(result.sdr)

expect(pageError).not.toBeCalled()
console.log(result)
// const file = await readFile(join(__dirname, './fixtures/memorial.jpg'))

// const meta = await decodeJPEGMetadata(file)
// console.log(meta)
})
})
19 changes: 18 additions & 1 deletion tests/testbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"imports": {
"three": "https://unpkg.com/three@0.157.0/build/three.module.js",
"three/examples/": "https://unpkg.com/three@0.157.0/examples/",

"gainmap-js": "../dist/index.js",
"gainmap-js/libultrahdr": "../dist/libultrahdr.js"
}
}
</script>
<script type="module">
import { encode } from 'gainmap-js';
import { encodeJPEGMetadata } from 'gainmap-js/libultrahdr';
import { encodeJPEGMetadata, decodeJPEGMetadata } from 'gainmap-js/libultrahdr';
import { ACESFilmicToneMapping } from 'three'
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader'
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader'
Expand Down Expand Up @@ -49,6 +50,22 @@
// Uint8Arrays can't be transferred outside puppetteer
return Array.from(jpeg)
}
window.decodeJPEGMetadata = async (url) => {
const response = await fetch(`https://local/${url}`)
const buf = await response.arrayBuffer()
const result = await decodeJPEGMetadata(new Uint8Array(buf))

// Uint8Arrays can't be transferred outside puppetteer
result.gainMap = Array.from(result.gainMap)
result.sdr = Array.from(result.sdr)
return result
// image.flipY = false
// const result = await encode({ image, outMimeType, outQuality, sdrToneMapping, flipY: loader instanceof EXRLoader})

// const jpeg = await encodeJPEGMetadata(result)
// // Uint8Arrays can't be transferred outside puppetteer
// return Array.from(jpeg)
}

</script>
</body>
Expand Down
4 changes: 3 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
"esModuleInterop": true,
"allowJs": true,
"checkJs": false
}
}

0 comments on commit 86a4efb

Please sign in to comment.