Skip to content

Commit

Permalink
test: fix test with new parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-pelagatti committed Oct 27, 2023
1 parent ea5b968 commit a9f2a7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/libultrahdr.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { MainModule } from '../libultrahdr-wasm/build/libultrahdr'
// @ts-expect-error untyped
import libultrahdr from '../libultrahdr-wasm/build/libultrahdr-esm'
import { CompressedEncodingResult, GainMapMetadata } from './types'
import { CompressedImage, GainMapMetadata } from './types'

export * from '../libultrahdr-wasm/build/libultrahdr'
let library: MainModule | undefined

/**
* Instances the WASM module and returns it, only one module will be created upon multiple calls
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
* @category General
* @group General
*
* @returns
*/
Expand All @@ -30,7 +32,7 @@ export const getLibrary = async () => {
* @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
* @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
*/
export const encodeJPEGMetadata = async (encodingResult: CompressedEncodingResult) => {
export const encodeJPEGMetadata = async (encodingResult: GainMapMetadata & { sdr: CompressedImage, gainMap: CompressedImage }) => {
const lib = await getLibrary()

if (encodingResult.sdr.mimeType !== 'image/jpeg') throw new Error('This function expects an SDR image compressed in jpeg')
Expand Down
6 changes: 2 additions & 4 deletions tests/libultrahdr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ describe('wasm', () => {
const { page, pageError } = await getTestbed()

const result = await page.evaluate(`
encodeJPEGMetadata(
'memorial.exr',
'image/jpeg'
)`) as Awaited<number[]>
encodeJPEGMetadata('memorial.exr')
`) as Awaited<number[]>

expect(pageError).not.toBeCalled()
// expect(pageLog).not.toBeCalled()
Expand Down
16 changes: 5 additions & 11 deletions tests/testbed.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@
})
}

window.encodeAndCompress = async (url, outMimeType = 'image/jpeg', outQuality = 0.9, sdrToneMapping = ACESFilmicToneMapping) => {
window.encodeAndCompress = async (url, mimeType = 'image/jpeg', quality = 0.9) => {
let loader
if (url.indexOf('.exr') !== -1) loader = new EXRLoader()
if (url.indexOf('.hdr') !== -1) loader = new RGBELoader()
const image = await loader.loadAsync(`https://local/${url}`)
image.flipY = false
const result = await encodeAndCompress({ image, outMimeType, outQuality, sdrToneMapping, flipY: loader instanceof EXRLoader })
const result = await encodeAndCompress({ image, mimeType, quality, flipY: loader instanceof EXRLoader })
// Uint8Arrays can't be transferred outside puppetteer
result.gainMap.data = Array.from(result.gainMap.data)
result.sdr.data = Array.from(result.sdr.data)
return result
}

window.encodeJPEGMetadata = async (url, outMimeType = 'image/jpeg', outQuality = 0.9, sdrToneMapping = ACESFilmicToneMapping) => {
window.encodeJPEGMetadata = async (url, quality = 0.9) => {
let loader
if (url.indexOf('.exr') !== -1) loader = new EXRLoader()
if (url.indexOf('.hdr') !== -1) loader = new RGBELoader()
const image = await loader.loadAsync(`https://local/${url}`)
image.flipY = false
const result = await encodeAndCompress({ image, outMimeType, outQuality, sdrToneMapping, flipY: loader instanceof EXRLoader })
const result = await encodeAndCompress({ image, mimeType: 'image/jpeg', quality, flipY: loader instanceof EXRLoader })

const jpeg = await encodeJPEGMetadata(result)
// Uint8Arrays can't be transferred outside puppetteer
Expand All @@ -69,12 +69,6 @@
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)
}

document.getElementById('hdr').onchange = async (e) => {
Expand All @@ -85,7 +79,7 @@
if (file.name.indexOf('.exr') !== -1) loader = new EXRLoader()
if (file.name.indexOf('.hdr') !== -1) loader = new RGBELoader()
const image = await loader.parse(buf)
const result = await encodeAndCompress({ image, outMimeType: 'image/jpeg', flipY: loader instanceof EXRLoader })
const result = await encodeAndCompress({ image, mimeType: 'image/jpeg', flipY: loader instanceof EXRLoader })

encodeJPEGMetadata(result)
}
Expand Down

0 comments on commit a9f2a7e

Please sign in to comment.