Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
+12
View File
@@ -0,0 +1,12 @@
import { CompressedImage, CompressParameters } from './types';
/**
* Converts a RAW RGBA image buffer into the provided `mimeType` using the provided `quality`
*
* @category Compression
* @group Compression
* @param params
* @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
* @throws {Error} if the provided source image cannot be decoded
* @throws {Error} if the function fails to create a canvas context
*/
export declare const compress: (params: CompressParameters) => Promise<CompressedImage>;
+61
View File
@@ -0,0 +1,61 @@
import { CompressedImage, EncodingParametersWithCompression } from './types';
/**
* Encodes a Gainmap starting from an HDR file into compressed file formats (`image/jpeg`, `image/webp` or `image/png`).
*
* Uses {@link encode} internally, then pipes the results to {@link compress}.
*
* @remarks
* if a `renderer` parameter is not provided
* This function will automatically dispose its "disposable"
* renderer, no need to dispose it manually later
*
* @category Encoding Functions
* @group Encoding Functions
* @example
* import { encodeAndCompress, findTextureMinMax } from '@monogrid/gainmap-js'
* import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
* import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
*
* // load an HDR file
* const loader = new EXRLoader()
* const image = await loader.loadAsync('image.exr')
*
* // find RAW RGB Max value of a texture
* const textureMax = findTextureMinMax(image)
*
* // Encode the gainmap
* const encodingResult = await encodeAndCompress({
* image,
* maxContentBoost: Math.max.apply(this, textureMax),
* mimeType: 'image/jpeg'
* })
*
* // embed the compressed images + metadata into a single
* // JPEG file
* const jpeg = encodeJPEGMetadata({
* ...encodingResult,
* sdr: encodingResult.sdr,
* gainMap: encodingResult.gainMap
* })
*
* // `jpeg` will be an `Uint8Array` which can be saved somewhere
*
*
* @param params Encoding Parameters
* @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
*/
export declare const encodeAndCompress: (params: EncodingParametersWithCompression) => Promise<{
sdr: CompressedImage;
gainMap: CompressedImage;
rawSDR: Uint8ClampedArray<ArrayBufferLike>;
rawGainMap: Uint8ClampedArray<ArrayBufferLike>;
gamma: [number, number, number];
hdrCapacityMin: number;
hdrCapacityMax: number;
offsetSdr: [number, number, number];
offsetHdr: [number, number, number];
gainMapMin: [number, number, number];
gainMapMax: [number, number, number];
hdr: import("three").DataTexture;
getMetadata: () => import(".").GainMapMetadata;
}>;
+61
View File
@@ -0,0 +1,61 @@
import { GainMapMetadata } from '../core/types';
import { EncodingParametersBase } from './types';
/**
* Encodes a Gainmap starting from an HDR file.
*
* @remarks
* if you do not pass a `renderer` parameter
* you must manually dispose the result
* ```js
* const encodingResult = await encode({ ... })
* // do something with the buffers
* const sdr = encodingResult.sdr.getArray()
* const gainMap = encodingResult.gainMap.getArray()
* // after that
* encodingResult.sdr.dispose()
* encodingResult.gainMap.dispose()
* ```
*
* @category Encoding Functions
* @group Encoding Functions
*
* @example
* import { encode, findTextureMinMax } from '@monogrid/gainmap-js'
* import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
*
* // load an HDR file
* const loader = new EXRLoader()
* const image = await loader.loadAsync('image.exr')
*
* // find RAW RGB Max value of a texture
* const textureMax = findTextureMinMax(image)
*
* // Encode the gainmap
* const encodingResult = encode({
* image,
* // this will encode the full HDR range
* maxContentBoost: Math.max.apply(this, textureMax)
* })
* // can be re-encoded after changing parameters
* encodingResult.sdr.material.exposure = 0.9
* encodingResult.sdr.render()
* // or
* encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
* encodingResult.gainMap.render()
*
* // do something with encodingResult.gainMap.toArray()
* // and encodingResult.sdr.toArray()
*
* // renderers must be manually disposed
* encodingResult.sdr.dispose()
* encodingResult.gainMap.dispose()
*
* @param params Encoding Parameters
* @returns
*/
export declare const encode: (params: EncodingParametersBase) => {
sdr: import("../core").QuadRenderer<1009, import(".").SDRMaterial>;
gainMap: import("../core").QuadRenderer<1009, import(".").GainMapEncoderMaterial>;
hdr: import("three").DataTexture;
getMetadata: () => GainMapMetadata;
};
@@ -0,0 +1,15 @@
import { DataTexture, WebGLRenderer } from 'three';
import { EXR } from 'three/examples/jsm/loaders/EXRLoader.js';
import { HDR } from 'three/examples/jsm/loaders/HDRLoader.js';
import { RGBE } from 'three/examples/jsm/loaders/RGBELoader.js';
/**
*
* @category Utility
* @group Utility
*
* @param image
* @param mode
* @param renderer
* @returns
*/
export declare const findTextureMinMax: (image: EXR | RGBE | HDR | DataTexture, mode?: "min" | "max", renderer?: WebGLRenderer) => number[];
+13
View File
@@ -0,0 +1,13 @@
import { QuadRenderer } from '../core/QuadRenderer';
import { GainMapEncoderMaterial } from './materials/GainMapEncoderMaterial';
import { EncodingParametersBase } from './types';
/**
*
* @param params
* @returns
* @category Encoding Functions
* @group Encoding Functions
*/
export declare const getGainMap: (params: {
sdr: InstanceType<typeof QuadRenderer>;
} & EncodingParametersBase) => QuadRenderer<1009, GainMapEncoderMaterial>;
+17
View File
@@ -0,0 +1,17 @@
import { DataTexture, ToneMapping, UnsignedByteType, WebGLRenderer } from 'three';
import { QuadRenderer } from '../core/QuadRenderer';
import { QuadRendererTextureOptions } from '../decode';
import { SDRMaterial } from './materials/SDRMaterial';
/**
* Renders an SDR Representation of an HDR Image
*
* @category Encoding Functions
* @group Encoding Functions
*
* @param hdrTexture The HDR image to be rendered
* @param renderer (optional) WebGLRenderer to use during the rendering, a disposable renderer will be create and destroyed if this is not provided.
* @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, renderTargetOptions?: QuadRendererTextureOptions) => InstanceType<typeof QuadRenderer<typeof UnsignedByteType, InstanceType<typeof SDRMaterial>>>;
+10
View File
@@ -0,0 +1,10 @@
export * from '../core/types';
export * from './compress';
export * from './encode';
export * from './encode-and-compress';
export * from './find-texture-min-max';
export * from './get-gainmap';
export * from './get-sdr-rendition';
export * from './materials/GainMapEncoderMaterial';
export * from './materials/SDRMaterial';
export * from './types';
@@ -0,0 +1,70 @@
import { ShaderMaterial, Texture } from 'three';
import { GainmapEncodingParameters } from '../types';
/**
* A Material which is able to encode a gainmap
*
* @category Materials
* @group Materials
*/
export declare class GainMapEncoderMaterial extends ShaderMaterial {
private _minContentBoost;
private _maxContentBoost;
private _offsetSdr;
private _offsetHdr;
private _gamma;
/**
*
* @param params
*/
constructor({ sdr, hdr, offsetSdr, offsetHdr, maxContentBoost, minContentBoost, gamma }: {
sdr: Texture;
hdr: Texture;
} & GainmapEncodingParameters);
/**
* @see {@link GainmapEncodingParameters.gamma}
*/
get gamma(): [number, number, number];
set gamma(value: [number, number, number]);
/**
* @see {@link GainmapEncodingParameters.offsetHdr}
*/
get offsetHdr(): [number, number, number];
set offsetHdr(value: [number, number, number]);
/**
* @see {@link GainmapEncodingParameters.offsetSdr}
*/
get offsetSdr(): [number, number, number];
set offsetSdr(value: [number, number, number]);
/**
* @see {@link GainmapEncodingParameters.minContentBoost}
* @remarks Non logarithmic space
*/
get minContentBoost(): number;
set minContentBoost(value: number);
/**
* @see {@link GainmapEncodingParameters.maxContentBoost}
* @remarks Non logarithmic space
*/
get maxContentBoost(): number;
set maxContentBoost(value: number);
/**
* @see {@link GainMapMetadata.gainMapMin}
* @remarks Logarithmic space
*/
get gainMapMin(): [number, number, number];
/**
* @see {@link GainMapMetadata.gainMapMax}
* @remarks Logarithmic space
*/
get gainMapMax(): [number, number, number];
/**
* @see {@link GainMapMetadata.hdrCapacityMin}
* @remarks Logarithmic space
*/
get hdrCapacityMin(): number;
/**
* @see {@link GainMapMetadata.hdrCapacityMax}
* @remarks Logarithmic space
*/
get hdrCapacityMax(): number;
}
@@ -0,0 +1,35 @@
import { ShaderMaterial, Texture, ToneMapping } from 'three';
/**
* A Material used to adjust the SDR representation of an HDR image
*
* @category Materials
* @group Materials
*/
export declare class SDRMaterial extends ShaderMaterial {
private _brightness;
private _contrast;
private _saturation;
private _exposure;
private _toneMapping;
private _map;
/**
*
* @param params
*/
constructor({ map, toneMapping }: {
map: Texture;
toneMapping?: ToneMapping;
});
get toneMapping(): ToneMapping;
set toneMapping(value: ToneMapping);
get brightness(): number;
set brightness(value: number);
get contrast(): number;
set contrast(value: number);
get saturation(): number;
set saturation(value: number);
get exposure(): number;
set exposure(value: number);
get map(): Texture;
set map(value: Texture);
}
+177
View File
@@ -0,0 +1,177 @@
import { type DataTexture, ToneMapping, WebGLRenderer } from 'three';
import { type EXR } from 'three/examples/jsm/loaders/EXRLoader.js';
import { type HDR } from 'three/examples/jsm/loaders/HDRLoader.js';
import { type RGBE } from 'three/examples/jsm/loaders/RGBELoader.js';
import { QuadRendererTextureOptions } from '../decode';
import { WorkerInterfaceImplementation } from '../worker-types';
/**
* Parameters used by content Creators in order to create a GainMap
* @category Specs
* @group Specs
*/
export type GainmapEncodingParameters = {
/**
* This is the offset to apply to the HDR pixel values during gain map generation and application.
* @defaultValue [1/64, 1/64, 1/64]
*/
offsetHdr?: [number, number, number];
/**
* This is the offset to apply to the SDR pixel values during gain map generation and application
* @defaultValue [1/64, 1/64, 1/64]
*/
offsetSdr?: [number, number, number];
/**
* This value lets the content creator constrain how much darker an image can get, when shown on an HDR display, relative to the SDR rendition.
* This value is a constant for a particular image.
* @defaultValue 1
* @remarks
* * If, for example, the value is 0.5, then for any given pixel, the linear luminance of the displayed HDR rendition must be (at the least) 0.5x the linear luminance of the SDR rendition.
* * In practice, this value is typically equal to or just less than 1.0.
* * Always less than or equal to Max content boost.
*
* Non Logarithmic space
*/
minContentBoost?: number;
/**
* This value lets the content creator constrain how much brighter an image can get, when shown on an HDR display, relative to the SDR rendition.
*
* @remarks
* * This value is a constant for a particular image.
* For example, if the value is four, then for any given pixel, the linear luminance of the
* displayed HDR rendition must be, at the most, 4x the linear luminance of the SDR rendition.
* In practice, this means that the brighter parts of the scene can be shown up to 4x brighter.
* * In practice, this value is typically greater than 1.0.
* * Always greater than or equal to Min content boost.
*
* Non Logarithmic space
*/
maxContentBoost: number;
/**
* This is the gamma to apply to the stored map values.
*
* @defaultValue [1, 1, 1]
* @remarks
* * Typically you can use a gamma of 1.0.
* * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
* For example, this might apply if a gain map has a lot of detail just above SDR range
* (represented as small log_recovery(x, y) values), and a very large map_max_log2 for the top
* end of the HDR rendition's desired brightness (represented by large log_recovery(x, y) values).
* In this case, you can use a map_gamma higher than 1.0 so that recovery(x, y)
* can precisely encode the detail in both the low end and high end of log_recovery(x, y).
*/
gamma?: [number, number, number];
};
/**
* Parameters used to Encode a GainMap
*
* @category Encoding Parameters
* @group Encoding Parameters
*/
export type EncodingParametersBase = GainmapEncodingParameters & {
/**
* Input image for encoding, must be an HDR image
*/
image: EXR | RGBE | HDR | DataTexture;
/**
* Optional WebGLRenderer
* @remarks
* will be created and destroyed on demand if not provided.
*/
renderer?: WebGLRenderer;
/**
* Optional tone mapping to apply to the SDR Rendition
* @defaultValue `ACESFilmicToneMapping`
*/
toneMapping?: ToneMapping;
/**
* Options to use when creating the output renderTarget
*/
renderTargetOptions?: QuadRendererTextureOptions;
};
/**
* This library can provide gainmap compressed in these mimeTypes
*
* @category Compression
* @group Compression
*/
export type CompressionMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
/**
* Accepted HDR image buffers, definitions coming from the THREE.js Library types
*
* @category Utility
* @group Utility
*/
export type HDRRawImageBuffer = EXR['data'] | RGBE['data'];
/**
* Raw HDR image data
*
* @category Utility
* @group Utility
*/
export type HDRRawImage = {
data: HDRRawImageBuffer;
width: number;
height: number;
};
/**
* Options for compressing a RAW RGBA image into the specified mimeType
*
* @category Compression
* @group Compression
*/
export type CompressOptions = {
/**
* The mimeType of the output
*/
mimeType: CompressionMimeType;
/**
* Encoding quality [0-1]
*/
quality?: number;
/**
* FlipY of the encoding process
*/
flipY?: boolean;
};
/**
* Data structure representing a compressed image with a mimeType
*
* @category Compression
* @group Compression
*/
export type CompressedImage = {
data: Uint8Array<ArrayBuffer>;
mimeType: CompressionMimeType;
width: number;
height: number;
};
/**
* @category Compression
* @group Compression
*/
export type CompressParameters = CompressOptions & ({
/**
* RAW RGBA Image Data
*/
source: ImageData;
} | {
/**
* Encoded Image Data with a mimeType
*/
source: Uint8Array<ArrayBuffer> | Uint8ClampedArray<ArrayBuffer>;
/**
* mimeType of the encoded input
*/
sourceMimeType: string;
});
/**
* Additional parameters to encode a GainMap compressed with a mimeType
* @category Encoding Parameters
* @group Encoding Parameters
*/
export type EncodingParametersWithCompression = EncodingParametersBase & CompressOptions & {
/**
* Encodes the Gainmap using a Web Worker
*/
withWorker?: WorkerInterfaceImplementation;
};