@monogrid/gainmap-js
Advanced tools
Comparing version 2.0.6 to 2.0.7
@@ -0,1 +1,9 @@ | ||
## [2.0.7](https://github.com/MONOGRID/gainmap-js/compare/v2.0.6...v2.0.7) (2023-11-23) | ||
### Bug Fixes | ||
* **core:** QuadRenderer dispose method now properly disposes of its internal resources ([#13](https://github.com/MONOGRID/gainmap-js/issues/13)) ([8e4473d](https://github.com/MONOGRID/gainmap-js/commit/8e4473da77732080de24f98dd271fecda06f9e53)) | ||
* **HDRJPGLoader:** renders (and returns) an SDR image when provided with a normal jpeg file ([#12](https://github.com/MONOGRID/gainmap-js/issues/12)) ([5222151](https://github.com/MONOGRID/gainmap-js/commit/5222151e6b5c95df79f1c4085cf36f30bd9c2dc4)) | ||
## [2.0.6](https://github.com/MONOGRID/gainmap-js/compare/v2.0.5...v2.0.6) (2023-11-20) | ||
@@ -2,0 +10,0 @@ |
@@ -51,2 +51,8 @@ import { ByteType, ColorSpace, DataTexture, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three'; | ||
toArray(): TextureDataTypeToBufferType<TType>; | ||
/** | ||
* Performs a readPixel operation in the renderTarget | ||
* and returns a DataTexture containing the read data | ||
* | ||
* @returns | ||
*/ | ||
toDataTexture(): DataTexture; | ||
@@ -56,4 +62,35 @@ /** | ||
*/ | ||
dispose(): void; | ||
disposeOnDemandRenderer(): void; | ||
/** | ||
* Will dispose of **all** assets used by this renderer. | ||
* | ||
* | ||
* @param disposeRenderTarget will dispose of the renderTarget which will not be usable later | ||
* set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator` | ||
* or are otherwise done with it. | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) ) | ||
* // DO NOT dispose the renderTarget here, | ||
* // it is used directly in the material | ||
* result.dispose() | ||
* ``` | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const pmremGenerator = new PMREMGenerator( renderer ); | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture) | ||
* const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) ) | ||
* // renderTarget can be disposed here | ||
* // because it was used to generate a PMREM texture | ||
* result.dispose(true) | ||
* ``` | ||
*/ | ||
dispose(disposeRenderTarget?: boolean): void; | ||
/** | ||
* Width of the texture | ||
@@ -60,0 +97,0 @@ */ |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { Q as QuadRenderer } from './QuadRenderer-gqnZPNP-.js'; | ||
import { Q as QuadRenderer } from './QuadRenderer-QXcVmgNm.js'; | ||
import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType, Loader, LoadingManager, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three'; | ||
@@ -199,2 +199,5 @@ | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
@@ -229,3 +232,3 @@ * @param params | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -236,2 +239,8 @@ } | ||
class GainMapNotFoundError extends Error { | ||
} | ||
class XMPMetadataNotFoundError extends Error { | ||
} | ||
const getAttribute = (description, name, defaultValue) => { | ||
@@ -272,3 +281,3 @@ var _a; | ||
let str; | ||
// support node test evnvironment | ||
// support node test environment | ||
if (typeof TextDecoder !== 'undefined') | ||
@@ -500,7 +509,7 @@ str = new TextDecoder().decode(input); | ||
if (!metadata) | ||
throw new Error('Gain map XMP metadata not found'); | ||
throw new XMPMetadataNotFoundError('Gain map XMP metadata not found'); | ||
const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true }); | ||
const images = await mpfExtractor.extract(jpegFile); | ||
if (images.length !== 2) | ||
throw new Error('Gain map recovery image not found'); | ||
throw new GainMapNotFoundError('Gain map recovery image not found'); | ||
return { | ||
@@ -519,3 +528,3 @@ sdr: new Uint8Array(await images[0].arrayBuffer()), | ||
*/ | ||
const getImage = (blob) => { | ||
const getHTMLImageFromBlob = (blob) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -528,2 +537,3 @@ const img = document.createElement('img'); | ||
}; | ||
class LoaderBase extends Loader { | ||
@@ -561,11 +571,11 @@ /** | ||
/** | ||
* | ||
* @private | ||
* @param quadRenderer | ||
* @param gainMapBuffer | ||
* @param sdrBuffer | ||
* @param metadata | ||
*/ | ||
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) { | ||
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' }); | ||
* @private | ||
* @param quadRenderer | ||
* @param metadata | ||
* @param sdrBuffer | ||
* @param gainMapBuffer | ||
*/ | ||
async render(quadRenderer, metadata, sdrBuffer, gainMapBuffer) { | ||
// this is optional, will render a black gain-map if not present | ||
const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: 'image/jpeg' }) : undefined; | ||
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' }); | ||
@@ -577,4 +587,4 @@ let sdrImage; | ||
const res = await Promise.all([ | ||
getImage(gainMapBlob), | ||
getImage(sdrBlob) | ||
gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined), | ||
getHTMLImageFromBlob(sdrBlob) | ||
]); | ||
@@ -587,3 +597,3 @@ gainMapImage = res[0]; | ||
const res = await Promise.all([ | ||
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }), | ||
gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }) : Promise.resolve(undefined), | ||
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' }) | ||
@@ -594,3 +604,3 @@ ]); | ||
} | ||
const gainMap = new Texture(gainMapImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace); | ||
const gainMap = new Texture(gainMapImage || new ImageData(2, 2), UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace); | ||
gainMap.flipY = needsFlip; | ||
@@ -641,3 +651,3 @@ gainMap.needsUpdate = true; | ||
* | ||
* const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* // `result` can be used to populate a Texture | ||
@@ -662,2 +672,6 @@ * | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
@@ -686,3 +700,3 @@ class GainMapLoader extends LoaderBase { | ||
if (sdr && gainMap && metadata) { | ||
await this.render(quadRenderer, gainMap, sdr, metadata); | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
if (typeof onLoad === 'function') | ||
@@ -693,3 +707,3 @@ onLoad(quadRenderer); | ||
this.manager.itemEnd(metadataUrl); | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
} | ||
@@ -790,3 +804,3 @@ }; | ||
* @example | ||
* import { JPEGRLoader } from '@monogrid/gainmap-js' | ||
* import { HDRJPGLoader } from '@monogrid/gainmap-js' | ||
* import { | ||
@@ -805,5 +819,5 @@ * EquirectangularReflectionMapping, | ||
* | ||
* const loader = new JPEGRLoader(renderer) | ||
* const loader = new HDRJPGLoader(renderer) | ||
* | ||
* const result = loader.load('gainmap.jpeg') | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* // `result` can be used to populate a Texture | ||
@@ -827,8 +841,12 @@ * | ||
* scene.background.minFilter = LinearFilter | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
class HDRJPGLoader extends LoaderBase { | ||
/** | ||
* Loads a JPEGR Image | ||
* Loads a JPEG containing gain map metadata | ||
* Renders a normal SDR image if gainmap data is not found | ||
* | ||
@@ -851,9 +869,38 @@ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json] | ||
if (typeof jpeg === 'string') | ||
throw new Error('Invalid buffer'); | ||
const { gainMap: gainMapJPEG, sdr: sdrJPEG, metadata } = await extractGainmapFromJPEG(new Uint8Array(jpeg)); | ||
await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata); | ||
throw new Error('Invalid buffer, received [string], was expecting [ArrayBuffer]'); | ||
const jpegBuffer = new Uint8Array(jpeg); | ||
let sdrJPEG; | ||
let gainMapJPEG; | ||
let metadata; | ||
try { | ||
const extractionResult = await extractGainmapFromJPEG(jpegBuffer); | ||
// gain map is successfully reconstructed | ||
sdrJPEG = extractionResult.sdr; | ||
gainMapJPEG = extractionResult.gainMap; | ||
metadata = extractionResult.metadata; | ||
} | ||
catch (e) { | ||
// render the SDR version if this is not a gainmap | ||
if (e instanceof XMPMetadataNotFoundError || e instanceof GainMapNotFoundError) { | ||
console.warn(`Failure to reconstruct an HDR image from ${url}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`); | ||
metadata = { | ||
gainMapMin: [0, 0, 0], | ||
gainMapMax: [1, 1, 1], | ||
gamma: [1, 1, 1], | ||
hdrCapacityMin: 0, | ||
hdrCapacityMax: 1, | ||
offsetHdr: [0, 0, 0], | ||
offsetSdr: [0, 0, 0] | ||
}; | ||
sdrJPEG = jpegBuffer; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
if (typeof onLoad === 'function') | ||
onLoad(quadRenderer); | ||
this.manager.itemEnd(url); | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
}, onProgress, (error) => { | ||
@@ -860,0 +907,0 @@ this.manager.itemError(url); |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -188,2 +188,8 @@ */ | ||
} | ||
/** | ||
* Performs a readPixel operation in the renderTarget | ||
* and returns a DataTexture containing the read data | ||
* | ||
* @returns | ||
*/ | ||
toDataTexture() { | ||
@@ -195,3 +201,3 @@ return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace); | ||
*/ | ||
dispose() { | ||
disposeOnDemandRenderer() { | ||
this._renderer.setRenderTarget(null); | ||
@@ -204,2 +210,52 @@ if (this._rendererIsDisposable) { | ||
/** | ||
* Will dispose of **all** assets used by this renderer. | ||
* | ||
* | ||
* @param disposeRenderTarget will dispose of the renderTarget which will not be usable later | ||
* set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator` | ||
* or are otherwise done with it. | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) ) | ||
* // DO NOT dispose the renderTarget here, | ||
* // it is used directly in the material | ||
* result.dispose() | ||
* ``` | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const pmremGenerator = new PMREMGenerator( renderer ); | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture) | ||
* const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) ) | ||
* // renderTarget can be disposed here | ||
* // because it was used to generate a PMREM texture | ||
* result.dispose(true) | ||
* ``` | ||
*/ | ||
dispose(disposeRenderTarget) { | ||
this.disposeOnDemandRenderer(); | ||
if (disposeRenderTarget) { | ||
this.renderTarget.dispose(); | ||
} | ||
// dispose shader material texture uniforms | ||
if (this.material instanceof three.ShaderMaterial) { | ||
Object.values(this.material.uniforms).forEach(v => { | ||
if (v.value instanceof three.Texture) | ||
v.value.dispose(); | ||
}); | ||
} | ||
// dispose other material properties | ||
Object.values(this.material).forEach(value => { | ||
if (value instanceof three.Texture) | ||
value.dispose(); | ||
}); | ||
this.material.dispose(); | ||
this._quad.geometry.dispose(); | ||
} | ||
/** | ||
* Width of the texture | ||
@@ -435,2 +491,5 @@ */ | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
@@ -465,3 +524,3 @@ * @param params | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -472,2 +531,8 @@ } | ||
class GainMapNotFoundError extends Error { | ||
} | ||
class XMPMetadataNotFoundError extends Error { | ||
} | ||
const getAttribute = (description, name, defaultValue) => { | ||
@@ -508,3 +573,3 @@ var _a; | ||
let str; | ||
// support node test evnvironment | ||
// support node test environment | ||
if (typeof TextDecoder !== 'undefined') | ||
@@ -736,7 +801,7 @@ str = new TextDecoder().decode(input); | ||
if (!metadata) | ||
throw new Error('Gain map XMP metadata not found'); | ||
throw new XMPMetadataNotFoundError('Gain map XMP metadata not found'); | ||
const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true }); | ||
const images = await mpfExtractor.extract(jpegFile); | ||
if (images.length !== 2) | ||
throw new Error('Gain map recovery image not found'); | ||
throw new GainMapNotFoundError('Gain map recovery image not found'); | ||
return { | ||
@@ -755,3 +820,3 @@ sdr: new Uint8Array(await images[0].arrayBuffer()), | ||
*/ | ||
const getImage = (blob) => { | ||
const getHTMLImageFromBlob = (blob) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -764,2 +829,3 @@ const img = document.createElement('img'); | ||
}; | ||
class LoaderBase extends three.Loader { | ||
@@ -797,11 +863,11 @@ /** | ||
/** | ||
* | ||
* @private | ||
* @param quadRenderer | ||
* @param gainMapBuffer | ||
* @param sdrBuffer | ||
* @param metadata | ||
*/ | ||
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) { | ||
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' }); | ||
* @private | ||
* @param quadRenderer | ||
* @param metadata | ||
* @param sdrBuffer | ||
* @param gainMapBuffer | ||
*/ | ||
async render(quadRenderer, metadata, sdrBuffer, gainMapBuffer) { | ||
// this is optional, will render a black gain-map if not present | ||
const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: 'image/jpeg' }) : undefined; | ||
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' }); | ||
@@ -813,4 +879,4 @@ let sdrImage; | ||
const res = await Promise.all([ | ||
getImage(gainMapBlob), | ||
getImage(sdrBlob) | ||
gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined), | ||
getHTMLImageFromBlob(sdrBlob) | ||
]); | ||
@@ -823,3 +889,3 @@ gainMapImage = res[0]; | ||
const res = await Promise.all([ | ||
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }), | ||
gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }) : Promise.resolve(undefined), | ||
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' }) | ||
@@ -830,3 +896,3 @@ ]); | ||
} | ||
const gainMap = new three.Texture(gainMapImage, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.LinearSRGBColorSpace); | ||
const gainMap = new three.Texture(gainMapImage || new ImageData(2, 2), three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.LinearSRGBColorSpace); | ||
gainMap.flipY = needsFlip; | ||
@@ -877,3 +943,3 @@ gainMap.needsUpdate = true; | ||
* | ||
* const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* // `result` can be used to populate a Texture | ||
@@ -898,2 +964,6 @@ * | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
@@ -922,3 +992,3 @@ class GainMapLoader extends LoaderBase { | ||
if (sdr && gainMap && metadata) { | ||
await this.render(quadRenderer, gainMap, sdr, metadata); | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
if (typeof onLoad === 'function') | ||
@@ -929,3 +999,3 @@ onLoad(quadRenderer); | ||
this.manager.itemEnd(metadataUrl); | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
} | ||
@@ -1026,3 +1096,3 @@ }; | ||
* @example | ||
* import { JPEGRLoader } from '@monogrid/gainmap-js' | ||
* import { HDRJPGLoader } from '@monogrid/gainmap-js' | ||
* import { | ||
@@ -1041,5 +1111,5 @@ * EquirectangularReflectionMapping, | ||
* | ||
* const loader = new JPEGRLoader(renderer) | ||
* const loader = new HDRJPGLoader(renderer) | ||
* | ||
* const result = loader.load('gainmap.jpeg') | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* // `result` can be used to populate a Texture | ||
@@ -1063,8 +1133,12 @@ * | ||
* scene.background.minFilter = LinearFilter | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
class HDRJPGLoader extends LoaderBase { | ||
/** | ||
* Loads a JPEGR Image | ||
* Loads a JPEG containing gain map metadata | ||
* Renders a normal SDR image if gainmap data is not found | ||
* | ||
@@ -1087,9 +1161,38 @@ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json] | ||
if (typeof jpeg === 'string') | ||
throw new Error('Invalid buffer'); | ||
const { gainMap: gainMapJPEG, sdr: sdrJPEG, metadata } = await extractGainmapFromJPEG(new Uint8Array(jpeg)); | ||
await this.render(quadRenderer, gainMapJPEG, sdrJPEG, metadata); | ||
throw new Error('Invalid buffer, received [string], was expecting [ArrayBuffer]'); | ||
const jpegBuffer = new Uint8Array(jpeg); | ||
let sdrJPEG; | ||
let gainMapJPEG; | ||
let metadata; | ||
try { | ||
const extractionResult = await extractGainmapFromJPEG(jpegBuffer); | ||
// gain map is successfully reconstructed | ||
sdrJPEG = extractionResult.sdr; | ||
gainMapJPEG = extractionResult.gainMap; | ||
metadata = extractionResult.metadata; | ||
} | ||
catch (e) { | ||
// render the SDR version if this is not a gainmap | ||
if (e instanceof XMPMetadataNotFoundError || e instanceof GainMapNotFoundError) { | ||
console.warn(`Failure to reconstruct an HDR image from ${url}: Gain map metadata not found in the file, HDRJPGLoader will render the SDR jpeg`); | ||
metadata = { | ||
gainMapMin: [0, 0, 0], | ||
gainMapMax: [1, 1, 1], | ||
gamma: [1, 1, 1], | ||
hdrCapacityMin: 0, | ||
hdrCapacityMax: 1, | ||
offsetHdr: [0, 0, 0], | ||
offsetSdr: [0, 0, 0] | ||
}; | ||
sdrJPEG = jpegBuffer; | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
if (typeof onLoad === 'function') | ||
onLoad(quadRenderer); | ||
this.manager.itemEnd(url); | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
}, onProgress, (error) => { | ||
@@ -1096,0 +1199,0 @@ this.manager.itemError(url); |
@@ -51,2 +51,5 @@ import { QuadRenderer } from '../core/QuadRenderer'; | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
@@ -53,0 +56,0 @@ * @param params |
@@ -28,3 +28,3 @@ import { HalfFloatType } from 'three'; | ||
* | ||
* const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
* // `result` can be used to populate a Texture | ||
@@ -49,2 +49,6 @@ * | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
@@ -51,0 +55,0 @@ export declare class GainMapLoader extends LoaderBase<[string, string, string]> { |
@@ -12,3 +12,3 @@ import { HalfFloatType } from 'three'; | ||
* @example | ||
* import { JPEGRLoader } from '@monogrid/gainmap-js' | ||
* import { HDRJPGLoader } from '@monogrid/gainmap-js' | ||
* import { | ||
@@ -27,5 +27,5 @@ * EquirectangularReflectionMapping, | ||
* | ||
* const loader = new JPEGRLoader(renderer) | ||
* const loader = new HDRJPGLoader(renderer) | ||
* | ||
* const result = loader.load('gainmap.jpeg') | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* // `result` can be used to populate a Texture | ||
@@ -49,8 +49,12 @@ * | ||
* scene.background.minFilter = LinearFilter | ||
* | ||
* // result must be manually disposed | ||
* // when you are done using it | ||
* result.dispose() | ||
* | ||
*/ | ||
export declare class HDRJPGLoader extends LoaderBase<string> { | ||
/** | ||
* Loads a JPEGR Image | ||
* Loads a JPEG containing gain map metadata | ||
* Renders a normal SDR image if gainmap data is not found | ||
* | ||
@@ -57,0 +61,0 @@ * @param url An array in the form of [sdr.jpg, gainmap.jpg, metadata.json] |
@@ -7,2 +7,5 @@ import { HalfFloatType, Loader, LoadingManager, WebGLRenderer } from 'three'; | ||
private _renderer; | ||
/** | ||
* @private | ||
*/ | ||
protected _internalLoadingManager: LoadingManager; | ||
@@ -21,10 +24,9 @@ /** | ||
/** | ||
* | ||
* @private | ||
* @param quadRenderer | ||
* @param gainMapBuffer | ||
* @param sdrBuffer | ||
* @param metadata | ||
*/ | ||
protected render(quadRenderer: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, gainMapBuffer: ArrayBuffer | string, sdrBuffer: ArrayBuffer | string, metadata: GainMapMetadata): Promise<void>; | ||
* @private | ||
* @param quadRenderer | ||
* @param metadata | ||
* @param sdrBuffer | ||
* @param gainMapBuffer | ||
*/ | ||
protected render(quadRenderer: QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, metadata: GainMapMetadata, sdrBuffer: ArrayBuffer, gainMapBuffer?: ArrayBuffer): Promise<void>; | ||
} |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { c as compress } from './compress-_4jEQonS.js'; | ||
import { c as compress } from './compress-MvOX-rlz.js'; | ||
import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, LinearSRGBColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three'; | ||
import { Q as QuadRenderer } from './QuadRenderer-gqnZPNP-.js'; | ||
import { Q as QuadRenderer } from './QuadRenderer-QXcVmgNm.js'; | ||
@@ -203,3 +203,3 @@ /** | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -431,3 +431,3 @@ } | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -481,3 +481,6 @@ } | ||
* | ||
* // must be manually disposed | ||
* // do something with encodingResult.gainMap.toArray() | ||
* // and encodingResult.sdr.toArray() | ||
* | ||
* // renderers must be manually disposed | ||
* encodingResult.sdr.dispose() | ||
@@ -484,0 +487,0 @@ * encodingResult.gainMap.dispose() |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -293,2 +293,8 @@ */ | ||
} | ||
/** | ||
* Performs a readPixel operation in the renderTarget | ||
* and returns a DataTexture containing the read data | ||
* | ||
* @returns | ||
*/ | ||
toDataTexture() { | ||
@@ -300,3 +306,3 @@ return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.LinearSRGBColorSpace); | ||
*/ | ||
dispose() { | ||
disposeOnDemandRenderer() { | ||
this._renderer.setRenderTarget(null); | ||
@@ -309,2 +315,52 @@ if (this._rendererIsDisposable) { | ||
/** | ||
* Will dispose of **all** assets used by this renderer. | ||
* | ||
* | ||
* @param disposeRenderTarget will dispose of the renderTarget which will not be usable later | ||
* set this to true if you passed the `renderTarget.texture` to a `PMREMGenerator` | ||
* or are otherwise done with it. | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const mesh = new Mesh(geometry, new MeshBasicMaterial({ map: result.renderTarget.texture }) ) | ||
* // DO NOT dispose the renderTarget here, | ||
* // it is used directly in the material | ||
* result.dispose() | ||
* ``` | ||
* | ||
* @example | ||
* ```js | ||
* const loader = new HDRJPGLoader(renderer) | ||
* const pmremGenerator = new PMREMGenerator( renderer ); | ||
* const result = await loader.loadAsync('gainmap.jpeg') | ||
* const envMap = pmremGenerator.fromEquirectangular(result.renderTarget.texture) | ||
* const mesh = new Mesh(geometry, new MeshStandardMaterial({ envMap }) ) | ||
* // renderTarget can be disposed here | ||
* // because it was used to generate a PMREM texture | ||
* result.dispose(true) | ||
* ``` | ||
*/ | ||
dispose(disposeRenderTarget) { | ||
this.disposeOnDemandRenderer(); | ||
if (disposeRenderTarget) { | ||
this.renderTarget.dispose(); | ||
} | ||
// dispose shader material texture uniforms | ||
if (this.material instanceof three.ShaderMaterial) { | ||
Object.values(this.material.uniforms).forEach(v => { | ||
if (v.value instanceof three.Texture) | ||
v.value.dispose(); | ||
}); | ||
} | ||
// dispose other material properties | ||
Object.values(this.material).forEach(value => { | ||
if (value instanceof three.Texture) | ||
value.dispose(); | ||
}); | ||
this.material.dispose(); | ||
this._quad.geometry.dispose(); | ||
} | ||
/** | ||
* Width of the texture | ||
@@ -514,3 +570,3 @@ */ | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -742,3 +798,3 @@ } | ||
catch (e) { | ||
quadRenderer.dispose(); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
throw e; | ||
@@ -792,3 +848,6 @@ } | ||
* | ||
* // must be manually disposed | ||
* // do something with encodingResult.gainMap.toArray() | ||
* // and encodingResult.sdr.toArray() | ||
* | ||
* // renderers must be manually disposed | ||
* encodingResult.sdr.dispose() | ||
@@ -795,0 +854,0 @@ * encodingResult.gainMap.dispose() |
@@ -46,3 +46,6 @@ import { GainMapMetadata } from '../core/types'; | ||
* | ||
* // must be manually disposed | ||
* // do something with encodingResult.gainMap.toArray() | ||
* // and encodingResult.sdr.toArray() | ||
* | ||
* // renderers must be manually disposed | ||
* encodingResult.sdr.dispose() | ||
@@ -49,0 +52,0 @@ * encodingResult.gainMap.dispose() |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js'; | ||
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js'; | ||
@@ -8,0 +8,0 @@ var lib$1; |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -4,0 +4,0 @@ */ |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-iRbo2TdN.js'; | ||
import { c as compress } from './compress-_4jEQonS.js'; | ||
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js'; | ||
import { c as compress } from './compress-MvOX-rlz.js'; | ||
@@ -9,0 +9,0 @@ var isPromise$2 = {exports: {}}; |
/** | ||
* @monogrid/gainmap-js v2.0.5 | ||
* @monogrid/gainmap-js v2.0.6 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -4,0 +4,0 @@ */ |
{ | ||
"name": "@monogrid/gainmap-js", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/MONOGRID/gainmap-js#readme", |
@@ -82,3 +82,3 @@ # gainmap-js | ||
const result = loader.load('gainmap.jpeg') | ||
const result = await loader.loadAsync('gainmap.jpeg') | ||
// `result` can be used to populate a Texture | ||
@@ -103,2 +103,7 @@ | ||
// result must be manually disposed | ||
// when you are done using it | ||
result.dispose() | ||
``` | ||
@@ -132,3 +137,3 @@ | ||
const result = loader.load(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
const result = await loader.loadAsync(['sdr.jpeg', 'gainmap.jpeg', 'metadata.json']) | ||
// `result` can be used to populate a Texture | ||
@@ -153,2 +158,5 @@ | ||
// result must be manually disposed | ||
// when you are done using it | ||
result.dispose() | ||
``` | ||
@@ -155,0 +163,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4339552
65
37829
255