@monogrid/gainmap-js
Advanced tools
Comparing version 2.0.7 to 3.0.0
@@ -0,1 +1,18 @@ | ||
# [3.0.0](https://github.com/MONOGRID/gainmap-js/compare/v2.0.7...v3.0.0) (2023-11-29) | ||
### Bug Fixes | ||
* **loaders:** properly catches render errors and calls onError callback ([b9bcdd1](https://github.com/MONOGRID/gainmap-js/commit/b9bcdd127576fa61c6ee92c876f4845cd80b4d34)), closes [#16](https://github.com/MONOGRID/gainmap-js/issues/16) | ||
### Features | ||
* **core:** disables default mipmap generation, enables user to specify renderTarget (and toDataTexture) options ([147d278](https://github.com/MONOGRID/gainmap-js/commit/147d2783224cb0a2039d762abf4e4b972b0e86da)), closes [#14](https://github.com/MONOGRID/gainmap-js/issues/14) [#15](https://github.com/MONOGRID/gainmap-js/issues/15) | ||
### BREAKING CHANGES | ||
* **core:** `generateMipmaps` is no longer `true` by default, both `minFilter` is no longer `LinearMipMapLinearFilter` by default but `LinearFilter`, `wrapS` and `warpT` are no longer `RepeatWrapping` by default but `ClampToEdgeWrapping` | ||
## [2.0.7](https://github.com/MONOGRID/gainmap-js/compare/v2.0.6...v2.0.7) (2023-11-23) | ||
@@ -2,0 +19,0 @@ |
import { ByteType, ColorSpace, DataTexture, FloatType, HalfFloatType, IntType, Material, ShortType, TextureDataType, UnsignedByteType, UnsignedIntType, WebGLRenderer, WebGLRenderTarget } from 'three'; | ||
import { QuadRendererTextureOptions } from './types'; | ||
/** | ||
@@ -9,2 +10,32 @@ * Utility Type that translates `three` texture types to their TypedArray counterparts. | ||
export type TextureDataTypeToBufferType<TType extends TextureDataType> = TType extends typeof UnsignedByteType ? Uint8ClampedArray : TType extends typeof HalfFloatType ? Uint16Array : TType extends typeof UnsignedIntType ? Uint32Array : TType extends typeof ByteType ? Int8Array : TType extends typeof ShortType ? Int16Array : TType extends typeof IntType ? Int32Array : TType extends typeof FloatType ? Float32Array : never; | ||
export type QuadRendererOptions<TType extends TextureDataType, TMaterial extends Material> = { | ||
/** | ||
* Width of the render target | ||
*/ | ||
width: number; | ||
/** | ||
* height of the renderTarget | ||
*/ | ||
height: number; | ||
/** | ||
* TextureDataType of the renderTarget | ||
*/ | ||
type: TType; | ||
/** | ||
* ColorSpace of the renderTarget | ||
*/ | ||
colorSpace: ColorSpace; | ||
/** | ||
* material to use for rendering | ||
*/ | ||
material: TMaterial; | ||
/** | ||
* Renderer instance to use | ||
*/ | ||
renderer?: WebGLRenderer; | ||
/** | ||
* Additional renderTarget options | ||
*/ | ||
renderTargetOptions?: QuadRendererTextureOptions; | ||
}; | ||
/** | ||
@@ -34,3 +65,3 @@ * Utility class used for rendering a texture with a material | ||
*/ | ||
constructor(width: number, height: number, type: TType, colorSpace: ColorSpace, material: TMaterial, renderer?: WebGLRenderer); | ||
constructor(options: QuadRendererOptions<TType, TMaterial>); | ||
/** | ||
@@ -57,5 +88,6 @@ * Instantiates a temporary renderer | ||
* | ||
* @params options | ||
* @returns | ||
*/ | ||
toDataTexture(): DataTexture; | ||
toDataTexture(options?: QuadRendererTextureOptions): DataTexture; | ||
/** | ||
@@ -62,0 +94,0 @@ * If using a disposable renderer, it will dispose it. |
@@ -0,1 +1,2 @@ | ||
import { Mapping, RenderTargetOptions } from 'three'; | ||
/** | ||
@@ -65,1 +66,14 @@ * This is the Metadata stored in an encoded Gainmap which is used | ||
}; | ||
/** | ||
* | ||
*/ | ||
export type QuadRendererTextureOptions = Omit<RenderTargetOptions, 'type' | 'format' | 'colorSpace' | 'encoding' | 'depthTexture' | 'stencilBuffer' | 'depthBuffer' | 'internalFormat'> & { | ||
/** | ||
* @defaultValue {@link UVMapping} | ||
*/ | ||
mapping?: Mapping; | ||
/** | ||
* @defaultValue 1 | ||
*/ | ||
anisotropy?: number; | ||
}; |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { Q as QuadRenderer } from './QuadRenderer-QXcVmgNm.js'; | ||
import { Q as QuadRenderer } from './QuadRenderer-LVKXL-q4.js'; | ||
import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType, Loader, LoadingManager, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three'; | ||
@@ -224,5 +224,15 @@ | ||
}); | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, HalfFloatType, LinearSRGBColorSpace, material, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
width: sdr.image.width, | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
height: sdr.image.height, | ||
type: HalfFloatType, | ||
colorSpace: LinearSRGBColorSpace, | ||
material, | ||
renderer, | ||
renderTargetOptions: params.renderTargetOptions | ||
}); | ||
try { | ||
@@ -545,2 +555,12 @@ quadRenderer.render(); | ||
/** | ||
* Specify the renderTarget options to use when rendering the gain map | ||
* | ||
* @param options | ||
* @returns | ||
*/ | ||
setRenderTargetOptions(options) { | ||
this._renderTargetOptions = options; | ||
return this; | ||
} | ||
/** | ||
* @private | ||
@@ -563,3 +583,11 @@ * @returns | ||
}); | ||
return new QuadRenderer(16, 16, HalfFloatType, LinearSRGBColorSpace, material, this._renderer); | ||
return new QuadRenderer({ | ||
width: 16, | ||
height: 16, | ||
type: HalfFloatType, | ||
colorSpace: LinearSRGBColorSpace, | ||
material, | ||
renderer: this._renderer, | ||
renderTargetOptions: this._renderTargetOptions | ||
}); | ||
} | ||
@@ -690,3 +718,15 @@ /** | ||
if (sdr && gainMap && metadata) { | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
// solves #16 | ||
try { | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
} | ||
catch (error) { | ||
this.manager.itemError(sdrUrl); | ||
this.manager.itemError(gainMapUrl); | ||
this.manager.itemError(metadataUrl); | ||
if (typeof onError === 'function') | ||
onError(error); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
return; | ||
} | ||
if (typeof onLoad === 'function') | ||
@@ -886,3 +926,13 @@ onLoad(quadRenderer); | ||
} | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
// solves #16 | ||
try { | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
} | ||
catch (error) { | ||
this.manager.itemError(url); | ||
if (typeof onError === 'function') | ||
onError(error); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
return; | ||
} | ||
if (typeof onLoad === 'function') | ||
@@ -889,0 +939,0 @@ onLoad(quadRenderer); |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -51,19 +51,9 @@ */ | ||
* @param camera | ||
* @param renderTargetOptions | ||
* @returns | ||
*/ | ||
const canReadPixels = (type, renderer, camera) => { | ||
const canReadPixels = (type, renderer, camera, renderTargetOptions) => { | ||
if (_canReadPixelsResult !== undefined) | ||
return _canReadPixelsResult; | ||
const testRT = new three.WebGLRenderTarget(1, 1, { | ||
type, | ||
colorSpace: three.LinearSRGBColorSpace, | ||
format: three.RGBAFormat, | ||
magFilter: three.LinearFilter, | ||
minFilter: three.LinearFilter, | ||
wrapS: three.RepeatWrapping, | ||
wrapT: three.RepeatWrapping, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
generateMipmaps: true | ||
}); | ||
const testRT = new three.WebGLRenderTarget(1, 1, renderTargetOptions); | ||
renderer.setRenderTarget(testRT); | ||
@@ -93,3 +83,4 @@ const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff })); | ||
*/ | ||
constructor(width, height, type, colorSpace, material, renderer) { | ||
constructor(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; | ||
this._rendererIsDisposable = false; | ||
@@ -111,9 +102,25 @@ this._supportsReadPixels = true; | ||
}; | ||
this._width = width; | ||
this._height = height; | ||
this._type = type; | ||
this._colorSpace = colorSpace; | ||
this._material = material; | ||
if (renderer) { | ||
this._renderer = renderer; | ||
this._width = options.width; | ||
this._height = options.height; | ||
this._type = options.type; | ||
this._colorSpace = options.colorSpace; | ||
const rtOptions = { | ||
// fixed options | ||
format: three.RGBAFormat, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
// user options | ||
type: this._type, | ||
colorSpace: this._colorSpace, | ||
anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== undefined ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1, | ||
generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== undefined ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false, | ||
magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== undefined ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : three.LinearFilter, | ||
minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== undefined ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : three.LinearFilter, | ||
samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== undefined ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : undefined, | ||
wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== undefined ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : three.ClampToEdgeWrapping, | ||
wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== undefined ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : three.ClampToEdgeWrapping | ||
}; | ||
this._material = options.material; | ||
if (options.renderer) { | ||
this._renderer = options.renderer; | ||
} | ||
@@ -132,3 +139,3 @@ else { | ||
this._camera.updateProjectionMatrix(); | ||
if (!canReadPixels(this._type, this._renderer, this._camera)) { | ||
if (!canReadPixels(this._type, this._renderer, this._camera, rtOptions)) { | ||
let alternativeType; | ||
@@ -152,14 +159,4 @@ switch (this._type) { | ||
this._scene.add(this._quad); | ||
this._renderTarget = new three.WebGLRenderTarget(width, height, { | ||
type: this._type, | ||
colorSpace, | ||
format: three.RGBAFormat, | ||
magFilter: three.LinearFilter, | ||
minFilter: three.LinearMipMapLinearFilter, | ||
wrapS: three.RepeatWrapping, | ||
wrapT: three.RepeatWrapping, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
generateMipmaps: true | ||
}); | ||
this._renderTarget = new three.WebGLRenderTarget(this.width, this.height, rtOptions); | ||
this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== undefined ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : three.UVMapping; | ||
} | ||
@@ -197,6 +194,16 @@ /** | ||
* | ||
* @params options | ||
* @returns | ||
*/ | ||
toDataTexture() { | ||
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); | ||
toDataTexture(options) { | ||
const returnValue = new three.DataTexture( | ||
// fixed values | ||
this.toArray(), this.width, this.height, three.RGBAFormat, this._type, | ||
// user values | ||
(options === null || options === void 0 ? void 0 : options.mapping) || three.UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1, | ||
// fixed value | ||
three.LinearSRGBColorSpace); | ||
// set this afterwards, we can't set it in constructor | ||
returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== undefined ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false; | ||
return returnValue; | ||
} | ||
@@ -519,5 +526,15 @@ /** | ||
}); | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access | ||
const quadRenderer = new QuadRenderer(sdr.image.width, sdr.image.height, three.HalfFloatType, three.LinearSRGBColorSpace, material, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
width: sdr.image.width, | ||
// TODO: three types are generic, eslint complains here, see how we can solve | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
height: sdr.image.height, | ||
type: three.HalfFloatType, | ||
colorSpace: three.LinearSRGBColorSpace, | ||
material, | ||
renderer, | ||
renderTargetOptions: params.renderTargetOptions | ||
}); | ||
try { | ||
@@ -840,2 +857,12 @@ quadRenderer.render(); | ||
/** | ||
* Specify the renderTarget options to use when rendering the gain map | ||
* | ||
* @param options | ||
* @returns | ||
*/ | ||
setRenderTargetOptions(options) { | ||
this._renderTargetOptions = options; | ||
return this; | ||
} | ||
/** | ||
* @private | ||
@@ -858,3 +885,11 @@ * @returns | ||
}); | ||
return new QuadRenderer(16, 16, three.HalfFloatType, three.LinearSRGBColorSpace, material, this._renderer); | ||
return new QuadRenderer({ | ||
width: 16, | ||
height: 16, | ||
type: three.HalfFloatType, | ||
colorSpace: three.LinearSRGBColorSpace, | ||
material, | ||
renderer: this._renderer, | ||
renderTargetOptions: this._renderTargetOptions | ||
}); | ||
} | ||
@@ -985,3 +1020,15 @@ /** | ||
if (sdr && gainMap && metadata) { | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
// solves #16 | ||
try { | ||
await this.render(quadRenderer, metadata, sdr, gainMap); | ||
} | ||
catch (error) { | ||
this.manager.itemError(sdrUrl); | ||
this.manager.itemError(gainMapUrl); | ||
this.manager.itemError(metadataUrl); | ||
if (typeof onError === 'function') | ||
onError(error); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
return; | ||
} | ||
if (typeof onLoad === 'function') | ||
@@ -1181,3 +1228,13 @@ onLoad(quadRenderer); | ||
} | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
// solves #16 | ||
try { | ||
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG); | ||
} | ||
catch (error) { | ||
this.manager.itemError(url); | ||
if (typeof onError === 'function') | ||
onError(error); | ||
quadRenderer.disposeOnDemandRenderer(); | ||
return; | ||
} | ||
if (typeof onLoad === 'function') | ||
@@ -1184,0 +1241,0 @@ onLoad(quadRenderer); |
import { HalfFloatType, Loader, LoadingManager, WebGLRenderer } from 'three'; | ||
import { QuadRenderer } from '../../core/QuadRenderer'; | ||
import { type GainMapMetadata } from '../../core/types'; | ||
import { type GainMapMetadata, QuadRendererTextureOptions } from '../../core/types'; | ||
import { GainMapDecoderMaterial } from '../materials/GainMapDecoderMaterial'; | ||
export declare class LoaderBase<TUrl = string> extends Loader<QuadRenderer<typeof HalfFloatType, GainMapDecoderMaterial>, TUrl> { | ||
private _renderer; | ||
private _renderTargetOptions?; | ||
/** | ||
@@ -18,2 +19,9 @@ * @private | ||
/** | ||
* Specify the renderTarget options to use when rendering the gain map | ||
* | ||
* @param options | ||
* @returns | ||
*/ | ||
setRenderTargetOptions(options: QuadRendererTextureOptions): this; | ||
/** | ||
* @private | ||
@@ -20,0 +28,0 @@ * @returns |
import { type Texture, type WebGLRenderer } from 'three'; | ||
import { type GainMapMetadata } from '../core/types'; | ||
import { type GainMapMetadata, type QuadRendererTextureOptions } from '../core/types'; | ||
/** | ||
@@ -38,2 +38,6 @@ * Necessary parameters for decoding a Gainmap | ||
renderer?: WebGLRenderer; | ||
/** | ||
* Options to use when creating the output renderTarget | ||
*/ | ||
renderTargetOptions?: QuadRendererTextureOptions; | ||
} & GainmapDecodingParameters & GainMapMetadata; |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { c as compress } from './compress-MvOX-rlz.js'; | ||
import { c as compress } from './compress-AzvRyeg9.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-QXcVmgNm.js'; | ||
import { Q as QuadRenderer } from './QuadRenderer-LVKXL-q4.js'; | ||
@@ -198,3 +198,11 @@ /** | ||
}); | ||
const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, UnsignedByteType, LinearSRGBColorSpace, material, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: dataTexture.image.width, | ||
height: dataTexture.image.height, | ||
type: UnsignedByteType, | ||
colorSpace: LinearSRGBColorSpace, | ||
material, | ||
renderer, | ||
renderTargetOptions: params.renderTargetOptions | ||
}); | ||
try { | ||
@@ -422,7 +430,16 @@ quadRenderer.render(); | ||
* @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition | ||
* @param renderTargetOptions (optional) Options to use when creating the output renderTarget | ||
* @throws {Error} if the WebGLRenderer fails to render the SDR image | ||
*/ | ||
const getSDRRendition = (hdrTexture, renderer, toneMapping) => { | ||
const getSDRRendition = (hdrTexture, renderer, toneMapping, renderTargetOptions) => { | ||
hdrTexture.needsUpdate = true; | ||
const quadRenderer = new QuadRenderer(hdrTexture.image.width, hdrTexture.image.height, UnsignedByteType, SRGBColorSpace, new SDRMaterial({ map: hdrTexture, toneMapping }), renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: hdrTexture.image.width, | ||
height: hdrTexture.image.height, | ||
type: UnsignedByteType, | ||
colorSpace: SRGBColorSpace, | ||
material: new SDRMaterial({ map: hdrTexture, toneMapping }), | ||
renderer, | ||
renderTargetOptions | ||
}); | ||
try { | ||
@@ -494,3 +511,3 @@ quadRenderer.render(); | ||
const dataTexture = getDataTexture(image); | ||
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping); | ||
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping, params.renderTargetOptions); | ||
const gainMapRenderer = getGainMap({ | ||
@@ -695,3 +712,10 @@ ...params, | ||
let h = srcTex.image.height; | ||
const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: w, | ||
height: h, | ||
type: srcTex.type, | ||
colorSpace: srcTex.colorSpace, | ||
material: mat, | ||
renderer | ||
}); | ||
const frameBuffers = []; | ||
@@ -698,0 +722,0 @@ while (w > 1 || h > 1) { |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -156,19 +156,9 @@ */ | ||
* @param camera | ||
* @param renderTargetOptions | ||
* @returns | ||
*/ | ||
const canReadPixels = (type, renderer, camera) => { | ||
const canReadPixels = (type, renderer, camera, renderTargetOptions) => { | ||
if (_canReadPixelsResult !== undefined) | ||
return _canReadPixelsResult; | ||
const testRT = new three.WebGLRenderTarget(1, 1, { | ||
type, | ||
colorSpace: three.LinearSRGBColorSpace, | ||
format: three.RGBAFormat, | ||
magFilter: three.LinearFilter, | ||
minFilter: three.LinearFilter, | ||
wrapS: three.RepeatWrapping, | ||
wrapT: three.RepeatWrapping, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
generateMipmaps: true | ||
}); | ||
const testRT = new three.WebGLRenderTarget(1, 1, renderTargetOptions); | ||
renderer.setRenderTarget(testRT); | ||
@@ -198,3 +188,4 @@ const mesh = new three.Mesh(new three.PlaneGeometry(), new three.MeshBasicMaterial({ color: 0xffffff })); | ||
*/ | ||
constructor(width, height, type, colorSpace, material, renderer) { | ||
constructor(options) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; | ||
this._rendererIsDisposable = false; | ||
@@ -216,9 +207,25 @@ this._supportsReadPixels = true; | ||
}; | ||
this._width = width; | ||
this._height = height; | ||
this._type = type; | ||
this._colorSpace = colorSpace; | ||
this._material = material; | ||
if (renderer) { | ||
this._renderer = renderer; | ||
this._width = options.width; | ||
this._height = options.height; | ||
this._type = options.type; | ||
this._colorSpace = options.colorSpace; | ||
const rtOptions = { | ||
// fixed options | ||
format: three.RGBAFormat, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
// user options | ||
type: this._type, | ||
colorSpace: this._colorSpace, | ||
anisotropy: ((_a = options.renderTargetOptions) === null || _a === void 0 ? void 0 : _a.anisotropy) !== undefined ? (_b = options.renderTargetOptions) === null || _b === void 0 ? void 0 : _b.anisotropy : 1, | ||
generateMipmaps: ((_c = options.renderTargetOptions) === null || _c === void 0 ? void 0 : _c.generateMipmaps) !== undefined ? (_d = options.renderTargetOptions) === null || _d === void 0 ? void 0 : _d.generateMipmaps : false, | ||
magFilter: ((_e = options.renderTargetOptions) === null || _e === void 0 ? void 0 : _e.magFilter) !== undefined ? (_f = options.renderTargetOptions) === null || _f === void 0 ? void 0 : _f.magFilter : three.LinearFilter, | ||
minFilter: ((_g = options.renderTargetOptions) === null || _g === void 0 ? void 0 : _g.minFilter) !== undefined ? (_h = options.renderTargetOptions) === null || _h === void 0 ? void 0 : _h.minFilter : three.LinearFilter, | ||
samples: ((_j = options.renderTargetOptions) === null || _j === void 0 ? void 0 : _j.samples) !== undefined ? (_k = options.renderTargetOptions) === null || _k === void 0 ? void 0 : _k.samples : undefined, | ||
wrapS: ((_l = options.renderTargetOptions) === null || _l === void 0 ? void 0 : _l.wrapS) !== undefined ? (_m = options.renderTargetOptions) === null || _m === void 0 ? void 0 : _m.wrapS : three.ClampToEdgeWrapping, | ||
wrapT: ((_o = options.renderTargetOptions) === null || _o === void 0 ? void 0 : _o.wrapT) !== undefined ? (_p = options.renderTargetOptions) === null || _p === void 0 ? void 0 : _p.wrapT : three.ClampToEdgeWrapping | ||
}; | ||
this._material = options.material; | ||
if (options.renderer) { | ||
this._renderer = options.renderer; | ||
} | ||
@@ -237,3 +244,3 @@ else { | ||
this._camera.updateProjectionMatrix(); | ||
if (!canReadPixels(this._type, this._renderer, this._camera)) { | ||
if (!canReadPixels(this._type, this._renderer, this._camera, rtOptions)) { | ||
let alternativeType; | ||
@@ -257,14 +264,4 @@ switch (this._type) { | ||
this._scene.add(this._quad); | ||
this._renderTarget = new three.WebGLRenderTarget(width, height, { | ||
type: this._type, | ||
colorSpace, | ||
format: three.RGBAFormat, | ||
magFilter: three.LinearFilter, | ||
minFilter: three.LinearMipMapLinearFilter, | ||
wrapS: three.RepeatWrapping, | ||
wrapT: three.RepeatWrapping, | ||
depthBuffer: false, | ||
stencilBuffer: false, | ||
generateMipmaps: true | ||
}); | ||
this._renderTarget = new three.WebGLRenderTarget(this.width, this.height, rtOptions); | ||
this._renderTarget.texture.mapping = ((_q = options.renderTargetOptions) === null || _q === void 0 ? void 0 : _q.mapping) !== undefined ? (_r = options.renderTargetOptions) === null || _r === void 0 ? void 0 : _r.mapping : three.UVMapping; | ||
} | ||
@@ -302,6 +299,16 @@ /** | ||
* | ||
* @params options | ||
* @returns | ||
*/ | ||
toDataTexture() { | ||
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); | ||
toDataTexture(options) { | ||
const returnValue = new three.DataTexture( | ||
// fixed values | ||
this.toArray(), this.width, this.height, three.RGBAFormat, this._type, | ||
// user values | ||
(options === null || options === void 0 ? void 0 : options.mapping) || three.UVMapping, (options === null || options === void 0 ? void 0 : options.wrapS) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.wrapT) || three.ClampToEdgeWrapping, (options === null || options === void 0 ? void 0 : options.magFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.minFilter) || three.LinearFilter, (options === null || options === void 0 ? void 0 : options.anisotropy) || 1, | ||
// fixed value | ||
three.LinearSRGBColorSpace); | ||
// set this afterwards, we can't set it in constructor | ||
returnValue.generateMipmaps = (options === null || options === void 0 ? void 0 : options.generateMipmaps) !== undefined ? options === null || options === void 0 ? void 0 : options.generateMipmaps : false; | ||
return returnValue; | ||
} | ||
@@ -568,3 +575,11 @@ /** | ||
}); | ||
const quadRenderer = new QuadRenderer(dataTexture.image.width, dataTexture.image.height, three.UnsignedByteType, three.LinearSRGBColorSpace, material, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: dataTexture.image.width, | ||
height: dataTexture.image.height, | ||
type: three.UnsignedByteType, | ||
colorSpace: three.LinearSRGBColorSpace, | ||
material, | ||
renderer, | ||
renderTargetOptions: params.renderTargetOptions | ||
}); | ||
try { | ||
@@ -792,7 +807,16 @@ quadRenderer.render(); | ||
* @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition | ||
* @param renderTargetOptions (optional) Options to use when creating the output renderTarget | ||
* @throws {Error} if the WebGLRenderer fails to render the SDR image | ||
*/ | ||
const getSDRRendition = (hdrTexture, renderer, toneMapping) => { | ||
const getSDRRendition = (hdrTexture, renderer, toneMapping, renderTargetOptions) => { | ||
hdrTexture.needsUpdate = true; | ||
const quadRenderer = new QuadRenderer(hdrTexture.image.width, hdrTexture.image.height, three.UnsignedByteType, three.SRGBColorSpace, new SDRMaterial({ map: hdrTexture, toneMapping }), renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: hdrTexture.image.width, | ||
height: hdrTexture.image.height, | ||
type: three.UnsignedByteType, | ||
colorSpace: three.SRGBColorSpace, | ||
material: new SDRMaterial({ map: hdrTexture, toneMapping }), | ||
renderer, | ||
renderTargetOptions | ||
}); | ||
try { | ||
@@ -864,3 +888,3 @@ quadRenderer.render(); | ||
const dataTexture = getDataTexture(image); | ||
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping); | ||
const sdr = getSDRRendition(dataTexture, renderer, params.toneMapping, params.renderTargetOptions); | ||
const gainMapRenderer = getGainMap({ | ||
@@ -1065,3 +1089,10 @@ ...params, | ||
let h = srcTex.image.height; | ||
const quadRenderer = new QuadRenderer(w, h, srcTex.type, srcTex.colorSpace, mat, renderer); | ||
const quadRenderer = new QuadRenderer({ | ||
width: w, | ||
height: h, | ||
type: srcTex.type, | ||
colorSpace: srcTex.colorSpace, | ||
material: mat, | ||
renderer | ||
}); | ||
const frameBuffers = []; | ||
@@ -1068,0 +1099,0 @@ while (w > 1 || h > 1) { |
import { DataTexture, ToneMapping, WebGLRenderer } from 'three'; | ||
import { QuadRenderer } from '../core/QuadRenderer'; | ||
import { QuadRendererTextureOptions } from '../decode'; | ||
import { SDRMaterial } from './materials/SDRMaterial'; | ||
@@ -13,4 +14,5 @@ /** | ||
* @param toneMapping (optional) Tone mapping to be applied to the SDR Rendition | ||
* @param renderTargetOptions (optional) Options to use when creating the output renderTarget | ||
* @throws {Error} if the WebGLRenderer fails to render the SDR image | ||
*/ | ||
export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping) => QuadRenderer<1009, SDRMaterial>; | ||
export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping, renderTargetOptions?: QuadRendererTextureOptions) => QuadRenderer<1009, SDRMaterial>; |
@@ -5,2 +5,3 @@ import { type DataTexture, ToneMapping, WebGLRenderer } from 'three'; | ||
import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader'; | ||
import { QuadRendererTextureOptions } from '../decode'; | ||
import { WorkerInterfaceImplementation } from '../worker-types'; | ||
@@ -86,2 +87,6 @@ /** | ||
toneMapping?: ToneMapping; | ||
/** | ||
* Options to use when creating the output renderTarget | ||
*/ | ||
renderTargetOptions?: QuadRendererTextureOptions; | ||
}; | ||
@@ -88,0 +93,0 @@ /** |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js'; | ||
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-7LfDr0XA.js'; | ||
@@ -8,0 +8,0 @@ var lib$1; |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -4,0 +4,0 @@ */ |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
*/ | ||
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-ftl_lJMx.js'; | ||
import { c as compress } from './compress-MvOX-rlz.js'; | ||
import { g as getDefaultExportFromCjs } from './_commonjsHelpers-7LfDr0XA.js'; | ||
import { c as compress } from './compress-AzvRyeg9.js'; | ||
@@ -9,0 +9,0 @@ var isPromise$2 = {exports: {}}; |
/** | ||
* @monogrid/gainmap-js v2.0.6 | ||
* @monogrid/gainmap-js v2.0.7 | ||
* With ❤️, by MONOGRID <hello@mono-grid.com> | ||
@@ -4,0 +4,0 @@ */ |
{ | ||
"name": "@monogrid/gainmap-js", | ||
"version": "2.0.7", | ||
"version": "3.0.0", | ||
"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", |
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
4354335
38066