@babylonjs/core 7.20.0 → 7.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Bones/bone.js +3 -3
- package/Bones/bone.js.map +1 -1
- package/Bones/boneLookController.js +3 -3
- package/Bones/boneLookController.js.map +1 -1
- package/Compat/compatibilityOptions.d.ts +13 -6
- package/Compat/compatibilityOptions.js +20 -4
- package/Compat/compatibilityOptions.js.map +1 -1
- package/Compat/index.d.ts +1 -1
- package/Compat/index.js +1 -1
- package/Compat/index.js.map +1 -1
- package/Culling/boundingBox.js +5 -5
- package/Culling/boundingBox.js.map +1 -1
- package/Culling/boundingInfo.js +2 -2
- package/Culling/boundingInfo.js.map +1 -1
- package/Culling/boundingSphere.js +2 -2
- package/Culling/boundingSphere.js.map +1 -1
- package/Culling/ray.js +2 -2
- package/Culling/ray.js.map +1 -1
- package/Debug/debugLayer.d.ts +3 -0
- package/Debug/debugLayer.js +15 -0
- package/Debug/debugLayer.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.js +11 -2
- package/Engines/engine.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.d.ts +2 -2
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js.map +1 -1
- package/Layers/highlightLayer.js +0 -1
- package/Layers/highlightLayer.js.map +1 -1
- package/Materials/Textures/Loaders/hdrTextureLoader.js +3 -3
- package/Materials/Textures/Loaders/hdrTextureLoader.js.map +1 -1
- package/Materials/Textures/hdrCubeTexture.js +2 -2
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js +2 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/texture.js +3 -3
- package/Materials/Textures/texture.js.map +1 -1
- package/Maths/math.color.js +3 -3
- package/Maths/math.color.js.map +1 -1
- package/Maths/math.vector.js +13 -14
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Builders/boxBuilder.js +5 -5
- package/Meshes/Builders/boxBuilder.js.map +1 -1
- package/Meshes/Builders/capsuleBuilder.js +4 -4
- package/Meshes/Builders/capsuleBuilder.js.map +1 -1
- package/Meshes/Builders/cylinderBuilder.js +8 -8
- package/Meshes/Builders/cylinderBuilder.js.map +1 -1
- package/Meshes/Builders/decalBuilder.js +3 -3
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/Builders/discBuilder.js +3 -3
- package/Meshes/Builders/discBuilder.js.map +1 -1
- package/Meshes/Builders/goldbergBuilder.js +2 -2
- package/Meshes/Builders/goldbergBuilder.js.map +1 -1
- package/Meshes/Builders/groundBuilder.js +2 -2
- package/Meshes/Builders/groundBuilder.js.map +1 -1
- package/Meshes/Builders/icoSphereBuilder.js +2 -2
- package/Meshes/Builders/icoSphereBuilder.js.map +1 -1
- package/Meshes/Builders/planeBuilder.js +5 -5
- package/Meshes/Builders/planeBuilder.js.map +1 -1
- package/Meshes/Builders/polygonBuilder.js +4 -4
- package/Meshes/Builders/polygonBuilder.js.map +1 -1
- package/Meshes/Builders/polyhedronBuilder.js +3 -3
- package/Meshes/Builders/polyhedronBuilder.js.map +1 -1
- package/Meshes/Builders/ribbonBuilder.js +4 -4
- package/Meshes/Builders/ribbonBuilder.js.map +1 -1
- package/Meshes/Builders/sphereBuilder.js +2 -2
- package/Meshes/Builders/sphereBuilder.js.map +1 -1
- package/Meshes/Builders/tiledBoxBuilder.js +2 -2
- package/Meshes/Builders/tiledBoxBuilder.js.map +1 -1
- package/Meshes/Builders/torusBuilder.js +2 -2
- package/Meshes/Builders/torusBuilder.js.map +1 -1
- package/Meshes/Builders/torusKnotBuilder.js +2 -2
- package/Meshes/Builders/torusKnotBuilder.js.map +1 -1
- package/Meshes/geometry.js +7 -7
- package/Meshes/geometry.js.map +1 -1
- package/Misc/HighDynamicRange/hdr.d.ts +40 -42
- package/Misc/HighDynamicRange/hdr.js +209 -202
- package/Misc/HighDynamicRange/hdr.js.map +1 -1
- package/Misc/HighDynamicRange/index.d.ts +1 -1
- package/Misc/HighDynamicRange/index.js +1 -1
- package/Misc/HighDynamicRange/index.js.map +1 -1
- package/Misc/arrayTools.d.ts +12 -17
- package/Misc/arrayTools.js +18 -23
- package/Misc/arrayTools.js.map +1 -1
- package/Misc/dumpTools.d.ts +50 -47
- package/Misc/dumpTools.js +153 -143
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/environmentTextureTools.js +2 -2
- package/Misc/environmentTextureTools.js.map +1 -1
- package/Misc/equirectangularCapture.js +2 -2
- package/Misc/equirectangularCapture.js.map +1 -1
- package/Misc/index.d.ts +2 -1
- package/Misc/index.js +2 -1
- package/Misc/index.js.map +1 -1
- package/Misc/rgbdTextureTools.js +1 -0
- package/Misc/rgbdTextureTools.js.map +1 -1
- package/Misc/screenshotTools.js +3 -3
- package/Misc/screenshotTools.js.map +1 -1
- package/Physics/v1/physicsImpostor.js +2 -2
- package/Physics/v1/physicsImpostor.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js +2 -2
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/PostProcesses/blurPostProcess.js +0 -1
- package/PostProcesses/blurPostProcess.js.map +1 -1
- package/PostProcesses/passPostProcess.js +0 -2
- package/PostProcesses/passPostProcess.js.map +1 -1
- package/PostProcesses/postProcess.d.ts +6 -0
- package/PostProcesses/postProcess.js +22 -1
- package/PostProcesses/postProcess.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDebug.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDebug.js.map +1 -1
- package/ShadersWGSL/background.fragment.js +1 -1
- package/ShadersWGSL/background.fragment.js.map +1 -1
- package/package.json +1 -1
|
@@ -17,46 +17,44 @@ export interface HDRInfo {
|
|
|
17
17
|
dataPosition: number;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Reads header information from an RGBE texture stored in a native array.
|
|
21
|
+
* More information on this format are available here:
|
|
22
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
23
|
+
*
|
|
24
|
+
* @param uint8array The binary file stored in native array.
|
|
25
|
+
* @returns The header information.
|
|
21
26
|
*/
|
|
22
|
-
export declare
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @param hdrInfo The header information of the file.
|
|
57
|
-
* @returns The pixels data in RGB right to left up to down order.
|
|
58
|
-
*/
|
|
59
|
-
static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array;
|
|
60
|
-
private static _RGBEReadPixelsRLE;
|
|
61
|
-
private static _RGBEReadPixelsNOTRLE;
|
|
62
|
-
}
|
|
27
|
+
export declare function RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the cubemap information (each faces texture data) extracted from an RGBE texture.
|
|
30
|
+
* This RGBE texture needs to store the information as a panorama.
|
|
31
|
+
*
|
|
32
|
+
* More information on this format are available here:
|
|
33
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
34
|
+
*
|
|
35
|
+
* @param buffer The binary file stored in an array buffer.
|
|
36
|
+
* @param size The expected size of the extracted cubemap.
|
|
37
|
+
* @param supersample enable supersampling the cubemap (default: false)
|
|
38
|
+
* @returns The Cube Map information.
|
|
39
|
+
*/
|
|
40
|
+
export declare function GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample?: boolean): CubeMapInfo;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the pixels data extracted from an RGBE texture.
|
|
43
|
+
* This pixels will be stored left to right up to down in the R G B order in one array.
|
|
44
|
+
*
|
|
45
|
+
* More information on this format are available here:
|
|
46
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
47
|
+
*
|
|
48
|
+
* @param uint8array The binary file stored in an array buffer.
|
|
49
|
+
* @param hdrInfo The header information of the file.
|
|
50
|
+
* @returns The pixels data in RGB right to left up to down order.
|
|
51
|
+
*/
|
|
52
|
+
export declare function RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use functions separately
|
|
55
|
+
*/
|
|
56
|
+
export declare const HDRTools: {
|
|
57
|
+
RGBE_ReadHeader: typeof RGBE_ReadHeader;
|
|
58
|
+
GetCubeMapTextureData: typeof GetCubeMapTextureData;
|
|
59
|
+
RGBE_ReadPixels: typeof RGBE_ReadPixels;
|
|
60
|
+
};
|
|
@@ -1,225 +1,232 @@
|
|
|
1
1
|
import { PanoramaToCubeMapTools } from "./panoramaToCubemap.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static _Ldexp(mantissa, exponent) {
|
|
7
|
-
if (exponent > 1023) {
|
|
8
|
-
return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);
|
|
9
|
-
}
|
|
10
|
-
if (exponent < -1074) {
|
|
11
|
-
return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);
|
|
12
|
-
}
|
|
13
|
-
return mantissa * Math.pow(2, exponent);
|
|
2
|
+
/* This groups tools to convert HDR texture to native colors array. */
|
|
3
|
+
function ldexp(mantissa, exponent) {
|
|
4
|
+
if (exponent > 1023) {
|
|
5
|
+
return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);
|
|
14
6
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/*nonzero pixel*/
|
|
18
|
-
exponent = this._Ldexp(1.0, exponent - (128 + 8));
|
|
19
|
-
float32array[index + 0] = red * exponent;
|
|
20
|
-
float32array[index + 1] = green * exponent;
|
|
21
|
-
float32array[index + 2] = blue * exponent;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
float32array[index + 0] = 0;
|
|
25
|
-
float32array[index + 1] = 0;
|
|
26
|
-
float32array[index + 2] = 0;
|
|
27
|
-
}
|
|
7
|
+
if (exponent < -1074) {
|
|
8
|
+
return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);
|
|
28
9
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return line;
|
|
10
|
+
return mantissa * Math.pow(2, exponent);
|
|
11
|
+
}
|
|
12
|
+
function rgbe2float(float32array, red, green, blue, exponent, index) {
|
|
13
|
+
if (exponent > 0) {
|
|
14
|
+
/*nonzero pixel*/
|
|
15
|
+
exponent = ldexp(1.0, exponent - (128 + 8));
|
|
16
|
+
float32array[index + 0] = red * exponent;
|
|
17
|
+
float32array[index + 1] = green * exponent;
|
|
18
|
+
float32array[index + 2] = blue * exponent;
|
|
40
19
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (line[0] != "#" || line[1] != "?") {
|
|
55
|
-
// eslint-disable-next-line no-throw-literal
|
|
56
|
-
throw "Bad HDR Format.";
|
|
57
|
-
}
|
|
58
|
-
let endOfHeader = false;
|
|
59
|
-
let findFormat = false;
|
|
60
|
-
let lineIndex = 0;
|
|
61
|
-
do {
|
|
62
|
-
lineIndex += line.length + 1;
|
|
63
|
-
line = this._ReadStringLine(uint8array, lineIndex);
|
|
64
|
-
if (line == "FORMAT=32-bit_rle_rgbe") {
|
|
65
|
-
findFormat = true;
|
|
66
|
-
}
|
|
67
|
-
else if (line.length == 0) {
|
|
68
|
-
endOfHeader = true;
|
|
69
|
-
}
|
|
70
|
-
} while (!endOfHeader);
|
|
71
|
-
if (!findFormat) {
|
|
72
|
-
// eslint-disable-next-line no-throw-literal
|
|
73
|
-
throw "HDR Bad header format, unsupported FORMAT";
|
|
20
|
+
else {
|
|
21
|
+
float32array[index + 0] = 0;
|
|
22
|
+
float32array[index + 1] = 0;
|
|
23
|
+
float32array[index + 2] = 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function readStringLine(uint8array, startIndex) {
|
|
27
|
+
let line = "";
|
|
28
|
+
let character = "";
|
|
29
|
+
for (let i = startIndex; i < uint8array.length - startIndex; i++) {
|
|
30
|
+
character = String.fromCharCode(uint8array[i]);
|
|
31
|
+
if (character == "\n") {
|
|
32
|
+
break;
|
|
74
33
|
}
|
|
34
|
+
line += character;
|
|
35
|
+
}
|
|
36
|
+
return line;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads header information from an RGBE texture stored in a native array.
|
|
40
|
+
* More information on this format are available here:
|
|
41
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
42
|
+
*
|
|
43
|
+
* @param uint8array The binary file stored in native array.
|
|
44
|
+
* @returns The header information.
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
47
|
+
export function RGBE_ReadHeader(uint8array) {
|
|
48
|
+
let height = 0;
|
|
49
|
+
let width = 0;
|
|
50
|
+
let line = readStringLine(uint8array, 0);
|
|
51
|
+
if (line[0] != "#" || line[1] != "?") {
|
|
52
|
+
// eslint-disable-next-line no-throw-literal
|
|
53
|
+
throw "Bad HDR Format.";
|
|
54
|
+
}
|
|
55
|
+
let endOfHeader = false;
|
|
56
|
+
let findFormat = false;
|
|
57
|
+
let lineIndex = 0;
|
|
58
|
+
do {
|
|
75
59
|
lineIndex += line.length + 1;
|
|
76
|
-
line =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// TODO. Support +Y and -X if needed.
|
|
80
|
-
if (!match || match.length < 3) {
|
|
81
|
-
// eslint-disable-next-line no-throw-literal
|
|
82
|
-
throw "HDR Bad header format, no size";
|
|
60
|
+
line = readStringLine(uint8array, lineIndex);
|
|
61
|
+
if (line == "FORMAT=32-bit_rle_rgbe") {
|
|
62
|
+
findFormat = true;
|
|
83
63
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (width < 8 || width > 0x7fff) {
|
|
87
|
-
// eslint-disable-next-line no-throw-literal
|
|
88
|
-
throw "HDR Bad header format, unsupported size";
|
|
64
|
+
else if (line.length == 0) {
|
|
65
|
+
endOfHeader = true;
|
|
89
66
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
dataPosition: lineIndex,
|
|
95
|
-
};
|
|
67
|
+
} while (!endOfHeader);
|
|
68
|
+
if (!findFormat) {
|
|
69
|
+
// eslint-disable-next-line no-throw-literal
|
|
70
|
+
throw "HDR Bad header format, unsupported FORMAT";
|
|
96
71
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @param size The expected size of the extracted cubemap.
|
|
106
|
-
* @param supersample enable supersampling the cubemap (default: false)
|
|
107
|
-
* @returns The Cube Map information.
|
|
108
|
-
*/
|
|
109
|
-
static GetCubeMapTextureData(buffer, size, supersample = false) {
|
|
110
|
-
const uint8array = new Uint8Array(buffer);
|
|
111
|
-
const hdrInfo = this.RGBE_ReadHeader(uint8array);
|
|
112
|
-
const data = this.RGBE_ReadPixels(uint8array, hdrInfo);
|
|
113
|
-
const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);
|
|
114
|
-
return cubeMapData;
|
|
72
|
+
lineIndex += line.length + 1;
|
|
73
|
+
line = readStringLine(uint8array, lineIndex);
|
|
74
|
+
const sizeRegexp = /^-Y (.*) \+X (.*)$/g;
|
|
75
|
+
const match = sizeRegexp.exec(line);
|
|
76
|
+
// TODO. Support +Y and -X if needed.
|
|
77
|
+
if (!match || match.length < 3) {
|
|
78
|
+
// eslint-disable-next-line no-throw-literal
|
|
79
|
+
throw "HDR Bad header format, no size";
|
|
115
80
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
122
|
-
*
|
|
123
|
-
* @param uint8array The binary file stored in an array buffer.
|
|
124
|
-
* @param hdrInfo The header information of the file.
|
|
125
|
-
* @returns The pixels data in RGB right to left up to down order.
|
|
126
|
-
*/
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
128
|
-
static RGBE_ReadPixels(uint8array, hdrInfo) {
|
|
129
|
-
return this._RGBEReadPixelsRLE(uint8array, hdrInfo);
|
|
81
|
+
width = parseInt(match[2]);
|
|
82
|
+
height = parseInt(match[1]);
|
|
83
|
+
if (width < 8 || width > 0x7fff) {
|
|
84
|
+
// eslint-disable-next-line no-throw-literal
|
|
85
|
+
throw "HDR Bad header format, unsupported size";
|
|
130
86
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
87
|
+
lineIndex += line.length + 1;
|
|
88
|
+
return {
|
|
89
|
+
height: height,
|
|
90
|
+
width: width,
|
|
91
|
+
dataPosition: lineIndex,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the cubemap information (each faces texture data) extracted from an RGBE texture.
|
|
96
|
+
* This RGBE texture needs to store the information as a panorama.
|
|
97
|
+
*
|
|
98
|
+
* More information on this format are available here:
|
|
99
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
100
|
+
*
|
|
101
|
+
* @param buffer The binary file stored in an array buffer.
|
|
102
|
+
* @param size The expected size of the extracted cubemap.
|
|
103
|
+
* @param supersample enable supersampling the cubemap (default: false)
|
|
104
|
+
* @returns The Cube Map information.
|
|
105
|
+
*/
|
|
106
|
+
export function GetCubeMapTextureData(buffer, size, supersample = false) {
|
|
107
|
+
const uint8array = new Uint8Array(buffer);
|
|
108
|
+
const hdrInfo = RGBE_ReadHeader(uint8array);
|
|
109
|
+
const data = RGBE_ReadPixels(uint8array, hdrInfo);
|
|
110
|
+
const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);
|
|
111
|
+
return cubeMapData;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns the pixels data extracted from an RGBE texture.
|
|
115
|
+
* This pixels will be stored left to right up to down in the R G B order in one array.
|
|
116
|
+
*
|
|
117
|
+
* More information on this format are available here:
|
|
118
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
119
|
+
*
|
|
120
|
+
* @param uint8array The binary file stored in an array buffer.
|
|
121
|
+
* @param hdrInfo The header information of the file.
|
|
122
|
+
* @returns The pixels data in RGB right to left up to down order.
|
|
123
|
+
*/
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
125
|
+
export function RGBE_ReadPixels(uint8array, hdrInfo) {
|
|
126
|
+
return readRGBEPixelsRLE(uint8array, hdrInfo);
|
|
127
|
+
}
|
|
128
|
+
function readRGBEPixelsRLE(uint8array, hdrInfo) {
|
|
129
|
+
let num_scanlines = hdrInfo.height;
|
|
130
|
+
const scanline_width = hdrInfo.width;
|
|
131
|
+
let a, b, c, d, count;
|
|
132
|
+
let dataIndex = hdrInfo.dataPosition;
|
|
133
|
+
let index = 0, endIndex = 0, i = 0;
|
|
134
|
+
const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E
|
|
135
|
+
const scanLineArray = new Uint8Array(scanLineArrayBuffer);
|
|
136
|
+
// 3 channels of 4 bytes per pixel in float.
|
|
137
|
+
const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);
|
|
138
|
+
const resultArray = new Float32Array(resultBuffer);
|
|
139
|
+
// read in each successive scanline
|
|
140
|
+
while (num_scanlines > 0) {
|
|
141
|
+
a = uint8array[dataIndex++];
|
|
142
|
+
b = uint8array[dataIndex++];
|
|
143
|
+
c = uint8array[dataIndex++];
|
|
144
|
+
d = uint8array[dataIndex++];
|
|
145
|
+
if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {
|
|
146
|
+
return readRGBEPixelsNotRLE(uint8array, hdrInfo);
|
|
147
|
+
}
|
|
148
|
+
if (((c << 8) | d) != scanline_width) {
|
|
149
|
+
// eslint-disable-next-line no-throw-literal
|
|
150
|
+
throw "HDR Bad header format, wrong scan line width";
|
|
151
|
+
}
|
|
152
|
+
index = 0;
|
|
153
|
+
// read each of the four channels for the scanline into the buffer
|
|
154
|
+
for (i = 0; i < 4; i++) {
|
|
155
|
+
endIndex = (i + 1) * scanline_width;
|
|
156
|
+
while (index < endIndex) {
|
|
157
|
+
a = uint8array[dataIndex++];
|
|
158
|
+
b = uint8array[dataIndex++];
|
|
159
|
+
if (a > 128) {
|
|
160
|
+
// a run of the same value
|
|
161
|
+
count = a - 128;
|
|
162
|
+
if (count == 0 || count > endIndex - index) {
|
|
163
|
+
// eslint-disable-next-line no-throw-literal
|
|
164
|
+
throw "HDR Bad Format, bad scanline data (run)";
|
|
172
165
|
}
|
|
173
|
-
|
|
174
|
-
// a non-run
|
|
175
|
-
count = a;
|
|
176
|
-
if (count == 0 || count > endIndex - index) {
|
|
177
|
-
// eslint-disable-next-line no-throw-literal
|
|
178
|
-
throw "HDR Bad Format, bad scanline data (non-run)";
|
|
179
|
-
}
|
|
166
|
+
while (count-- > 0) {
|
|
180
167
|
scanLineArray[index++] = b;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// a non-run
|
|
172
|
+
count = a;
|
|
173
|
+
if (count == 0 || count > endIndex - index) {
|
|
174
|
+
// eslint-disable-next-line no-throw-literal
|
|
175
|
+
throw "HDR Bad Format, bad scanline data (non-run)";
|
|
176
|
+
}
|
|
177
|
+
scanLineArray[index++] = b;
|
|
178
|
+
if (--count > 0) {
|
|
179
|
+
for (let j = 0; j < count; j++) {
|
|
180
|
+
scanLineArray[index++] = uint8array[dataIndex++];
|
|
185
181
|
}
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
|
-
// now convert data from buffer into floats
|
|
190
|
-
for (i = 0; i < scanline_width; i++) {
|
|
191
|
-
a = scanLineArray[i];
|
|
192
|
-
b = scanLineArray[i + scanline_width];
|
|
193
|
-
c = scanLineArray[i + 2 * scanline_width];
|
|
194
|
-
d = scanLineArray[i + 3 * scanline_width];
|
|
195
|
-
this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);
|
|
196
|
-
}
|
|
197
|
-
num_scanlines--;
|
|
198
185
|
}
|
|
199
|
-
|
|
186
|
+
// now convert data from buffer into floats
|
|
187
|
+
for (i = 0; i < scanline_width; i++) {
|
|
188
|
+
a = scanLineArray[i];
|
|
189
|
+
b = scanLineArray[i + scanline_width];
|
|
190
|
+
c = scanLineArray[i + 2 * scanline_width];
|
|
191
|
+
d = scanLineArray[i + 3 * scanline_width];
|
|
192
|
+
rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);
|
|
193
|
+
}
|
|
194
|
+
num_scanlines--;
|
|
200
195
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
num_scanlines
|
|
196
|
+
return resultArray;
|
|
197
|
+
}
|
|
198
|
+
function readRGBEPixelsNotRLE(uint8array, hdrInfo) {
|
|
199
|
+
// this file is not run length encoded
|
|
200
|
+
// read values sequentially
|
|
201
|
+
let num_scanlines = hdrInfo.height;
|
|
202
|
+
const scanline_width = hdrInfo.width;
|
|
203
|
+
let a, b, c, d, i;
|
|
204
|
+
let dataIndex = hdrInfo.dataPosition;
|
|
205
|
+
// 3 channels of 4 bytes per pixel in float.
|
|
206
|
+
const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);
|
|
207
|
+
const resultArray = new Float32Array(resultBuffer);
|
|
208
|
+
// read in each successive scanline
|
|
209
|
+
while (num_scanlines > 0) {
|
|
210
|
+
for (i = 0; i < hdrInfo.width; i++) {
|
|
211
|
+
a = uint8array[dataIndex++];
|
|
212
|
+
b = uint8array[dataIndex++];
|
|
213
|
+
c = uint8array[dataIndex++];
|
|
214
|
+
d = uint8array[dataIndex++];
|
|
215
|
+
rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);
|
|
221
216
|
}
|
|
222
|
-
|
|
217
|
+
num_scanlines--;
|
|
223
218
|
}
|
|
219
|
+
return resultArray;
|
|
224
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated Use functions separately
|
|
223
|
+
*/
|
|
224
|
+
export const HDRTools = {
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
226
|
+
RGBE_ReadHeader,
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
228
|
+
GetCubeMapTextureData,
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
230
|
+
RGBE_ReadPixels,
|
|
231
|
+
};
|
|
225
232
|
//# sourceMappingURL=hdr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hdr.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/hdr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAsB7D;;GAEG;AACH,MAAM,OAAO,QAAQ;IACT,MAAM,CAAC,MAAM,CAAC,QAAgB,EAAE,QAAgB;QACpD,IAAI,QAAQ,GAAG,IAAI,EAAE;YACjB,OAAO,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC;SACtE;QAED,IAAI,QAAQ,GAAG,CAAC,IAAI,EAAE;YAClB,OAAO,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,C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AAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;gBAE5B,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5G;YAED,aAAa,EAAE,CAAC;SACnB;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ","sourcesContent":["import type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { PanoramaToCubeMapTools } from \"./panoramaToCubemap\";\r\n\r\n/**\r\n * Header information of HDR texture files.\r\n */\r\nexport interface HDRInfo {\r\n /**\r\n * The height of the texture in pixels.\r\n */\r\n height: number;\r\n\r\n /**\r\n * The width of the texture in pixels.\r\n */\r\n width: number;\r\n\r\n /**\r\n * The index of the beginning of the data in the binary file.\r\n */\r\n dataPosition: number;\r\n}\r\n\r\n/**\r\n * This groups tools to convert HDR texture to native colors array.\r\n */\r\nexport class HDRTools {\r\n private static _Ldexp(mantissa: number, exponent: number): number {\r\n if (exponent > 1023) {\r\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\r\n }\r\n\r\n if (exponent < -1074) {\r\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\r\n }\r\n\r\n return mantissa * Math.pow(2, exponent);\r\n }\r\n\r\n private static _Rgbe2float(float32array: Float32Array, red: number, green: number, blue: number, exponent: number, index: number) {\r\n if (exponent > 0) {\r\n /*nonzero pixel*/\r\n exponent = this._Ldexp(1.0, exponent - (128 + 8));\r\n\r\n float32array[index + 0] = red * exponent;\r\n float32array[index + 1] = green * exponent;\r\n float32array[index + 2] = blue * exponent;\r\n } else {\r\n float32array[index + 0] = 0;\r\n float32array[index + 1] = 0;\r\n float32array[index + 2] = 0;\r\n }\r\n }\r\n\r\n private static _ReadStringLine(uint8array: Uint8Array, startIndex: number): string {\r\n let line = \"\";\r\n let character = \"\";\r\n\r\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\r\n character = String.fromCharCode(uint8array[i]);\r\n\r\n if (character == \"\\n\") {\r\n break;\r\n }\r\n\r\n line += character;\r\n }\r\n\r\n return line;\r\n }\r\n\r\n /**\r\n * Reads header information from an RGBE texture stored in a native array.\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in native array.\r\n * @returns The header information.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {\r\n let height: number = 0;\r\n let width: number = 0;\r\n\r\n let line = this._ReadStringLine(uint8array, 0);\r\n if (line[0] != \"#\" || line[1] != \"?\") {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"Bad HDR Format.\";\r\n }\r\n\r\n let endOfHeader = false;\r\n let findFormat = false;\r\n let lineIndex: number = 0;\r\n\r\n do {\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\r\n findFormat = true;\r\n } else if (line.length == 0) {\r\n endOfHeader = true;\r\n }\r\n } while (!endOfHeader);\r\n\r\n if (!findFormat) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, unsupported FORMAT\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n line = this._ReadStringLine(uint8array, lineIndex);\r\n\r\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\r\n const match = sizeRegexp.exec(line);\r\n\r\n // TODO. Support +Y and -X if needed.\r\n if (!match || match.length < 3) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, no size\";\r\n }\r\n width = parseInt(match[2]);\r\n height = parseInt(match[1]);\r\n\r\n if (width < 8 || width > 0x7fff) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, unsupported size\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n\r\n return {\r\n height: height,\r\n width: width,\r\n dataPosition: lineIndex,\r\n };\r\n }\r\n\r\n /**\r\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\r\n * This RGBE texture needs to store the information as a panorama.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param buffer The binary file stored in an array buffer.\r\n * @param size The expected size of the extracted cubemap.\r\n * @param supersample enable supersampling the cubemap (default: false)\r\n * @returns The Cube Map information.\r\n */\r\n public static GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample = false): CubeMapInfo {\r\n const uint8array = new Uint8Array(buffer);\r\n const hdrInfo = this.RGBE_ReadHeader(uint8array);\r\n const data = this.RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);\r\n\r\n return cubeMapData;\r\n }\r\n\r\n /**\r\n * Returns the pixels data extracted from an RGBE texture.\r\n * This pixels will be stored left to right up to down in the R G B order in one array.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in an array buffer.\r\n * @param hdrInfo The header information of the file.\r\n * @returns The pixels data in RGB right to left up to down order.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public static RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n return this._RGBEReadPixelsRLE(uint8array, hdrInfo);\r\n }\r\n\r\n private static _RGBEReadPixelsRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, count: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n let index = 0,\r\n endIndex = 0,\r\n i = 0;\r\n\r\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\r\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\r\n return this._RGBEReadPixelsNOTRLE(uint8array, hdrInfo);\r\n }\r\n\r\n if (((c << 8) | d) != scanline_width) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, wrong scan line width\";\r\n }\r\n\r\n index = 0;\r\n\r\n // read each of the four channels for the scanline into the buffer\r\n for (i = 0; i < 4; i++) {\r\n endIndex = (i + 1) * scanline_width;\r\n\r\n while (index < endIndex) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n\r\n if (a > 128) {\r\n // a run of the same value\r\n count = a - 128;\r\n if (count == 0 || count > endIndex - index) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad Format, bad scanline data (run)\";\r\n }\r\n\r\n while (count-- > 0) {\r\n scanLineArray[index++] = b;\r\n }\r\n } else {\r\n // a non-run\r\n count = a;\r\n if (count == 0 || count > endIndex - index) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad Format, bad scanline data (non-run)\";\r\n }\r\n\r\n scanLineArray[index++] = b;\r\n if (--count > 0) {\r\n for (let j = 0; j < count; j++) {\r\n scanLineArray[index++] = uint8array[dataIndex++];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // now convert data from buffer into floats\r\n for (i = 0; i < scanline_width; i++) {\r\n a = scanLineArray[i];\r\n b = scanLineArray[i + scanline_width];\r\n c = scanLineArray[i + 2 * scanline_width];\r\n d = scanLineArray[i + 3 * scanline_width];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n\r\n private static _RGBEReadPixelsNOTRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n // this file is not run length encoded\r\n // read values sequentially\r\n\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, i: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n for (i = 0; i < hdrInfo.width; i++) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n this._Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"hdr.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/hdr.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAsB7D,sEAAsE;AAEtE,SAAS,KAAK,CAAC,QAAgB,EAAE,QAAgB;IAC7C,IAAI,Q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O,aAAa,GAAG,CAAC,EAAE;QACtB,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YAChC,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;YAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;YAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;YAC5B,CAAC,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC,CAAC;YAE5B,UAAU,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SACtG;QAED,aAAa,EAAE,CAAC;KACnB;IAED,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACpB,gEAAgE;IAChE,eAAe;IACf,gEAAgE;IAChE,qBAAqB;IACrB,gEAAgE;IAChE,eAAe;CAClB,CAAC","sourcesContent":["import type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { PanoramaToCubeMapTools } from \"./panoramaToCubemap\";\r\n\r\n/**\r\n * Header information of HDR texture files.\r\n */\r\nexport interface HDRInfo {\r\n /**\r\n * The height of the texture in pixels.\r\n */\r\n height: number;\r\n\r\n /**\r\n * The width of the texture in pixels.\r\n */\r\n width: number;\r\n\r\n /**\r\n * The index of the beginning of the data in the binary file.\r\n */\r\n dataPosition: number;\r\n}\r\n\r\n/* This groups tools to convert HDR texture to native colors array. */\r\n\r\nfunction ldexp(mantissa: number, exponent: number): number {\r\n if (exponent > 1023) {\r\n return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);\r\n }\r\n\r\n if (exponent < -1074) {\r\n return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);\r\n }\r\n\r\n return mantissa * Math.pow(2, exponent);\r\n}\r\n\r\nfunction rgbe2float(float32array: Float32Array, red: number, green: number, blue: number, exponent: number, index: number) {\r\n if (exponent > 0) {\r\n /*nonzero pixel*/\r\n exponent = ldexp(1.0, exponent - (128 + 8));\r\n\r\n float32array[index + 0] = red * exponent;\r\n float32array[index + 1] = green * exponent;\r\n float32array[index + 2] = blue * exponent;\r\n } else {\r\n float32array[index + 0] = 0;\r\n float32array[index + 1] = 0;\r\n float32array[index + 2] = 0;\r\n }\r\n}\r\n\r\nfunction readStringLine(uint8array: Uint8Array, startIndex: number): string {\r\n let line = \"\";\r\n let character = \"\";\r\n\r\n for (let i = startIndex; i < uint8array.length - startIndex; i++) {\r\n character = String.fromCharCode(uint8array[i]);\r\n\r\n if (character == \"\\n\") {\r\n break;\r\n }\r\n\r\n line += character;\r\n }\r\n\r\n return line;\r\n}\r\n\r\n/**\r\n * Reads header information from an RGBE texture stored in a native array.\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in native array.\r\n * @returns The header information.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RGBE_ReadHeader(uint8array: Uint8Array): HDRInfo {\r\n let height: number = 0;\r\n let width: number = 0;\r\n\r\n let line = readStringLine(uint8array, 0);\r\n if (line[0] != \"#\" || line[1] != \"?\") {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"Bad HDR Format.\";\r\n }\r\n\r\n let endOfHeader = false;\r\n let findFormat = false;\r\n let lineIndex: number = 0;\r\n\r\n do {\r\n lineIndex += line.length + 1;\r\n line = readStringLine(uint8array, lineIndex);\r\n\r\n if (line == \"FORMAT=32-bit_rle_rgbe\") {\r\n findFormat = true;\r\n } else if (line.length == 0) {\r\n endOfHeader = true;\r\n }\r\n } while (!endOfHeader);\r\n\r\n if (!findFormat) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, unsupported FORMAT\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n line = readStringLine(uint8array, lineIndex);\r\n\r\n const sizeRegexp = /^-Y (.*) \\+X (.*)$/g;\r\n const match = sizeRegexp.exec(line);\r\n\r\n // TODO. Support +Y and -X if needed.\r\n if (!match || match.length < 3) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, no size\";\r\n }\r\n width = parseInt(match[2]);\r\n height = parseInt(match[1]);\r\n\r\n if (width < 8 || width > 0x7fff) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, unsupported size\";\r\n }\r\n\r\n lineIndex += line.length + 1;\r\n\r\n return {\r\n height: height,\r\n width: width,\r\n dataPosition: lineIndex,\r\n };\r\n}\r\n\r\n/**\r\n * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.\r\n * This RGBE texture needs to store the information as a panorama.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param buffer The binary file stored in an array buffer.\r\n * @param size The expected size of the extracted cubemap.\r\n * @param supersample enable supersampling the cubemap (default: false)\r\n * @returns The Cube Map information.\r\n */\r\nexport function GetCubeMapTextureData(buffer: ArrayBuffer, size: number, supersample = false): CubeMapInfo {\r\n const uint8array = new Uint8Array(buffer);\r\n const hdrInfo = RGBE_ReadHeader(uint8array);\r\n const data = RGBE_ReadPixels(uint8array, hdrInfo);\r\n\r\n const cubeMapData = PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size, supersample);\r\n\r\n return cubeMapData;\r\n}\r\n\r\n/**\r\n * Returns the pixels data extracted from an RGBE texture.\r\n * This pixels will be stored left to right up to down in the R G B order in one array.\r\n *\r\n * More information on this format are available here:\r\n * https://en.wikipedia.org/wiki/RGBE_image_format\r\n *\r\n * @param uint8array The binary file stored in an array buffer.\r\n * @param hdrInfo The header information of the file.\r\n * @returns The pixels data in RGB right to left up to down order.\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RGBE_ReadPixels(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n return readRGBEPixelsRLE(uint8array, hdrInfo);\r\n}\r\n\r\nfunction readRGBEPixelsRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, count: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n let index = 0,\r\n endIndex = 0,\r\n i = 0;\r\n\r\n const scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E\r\n const scanLineArray = new Uint8Array(scanLineArrayBuffer);\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n if (a != 2 || b != 2 || c & 0x80 || hdrInfo.width < 8 || hdrInfo.width > 32767) {\r\n return readRGBEPixelsNotRLE(uint8array, hdrInfo);\r\n }\r\n\r\n if (((c << 8) | d) != scanline_width) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad header format, wrong scan line width\";\r\n }\r\n\r\n index = 0;\r\n\r\n // read each of the four channels for the scanline into the buffer\r\n for (i = 0; i < 4; i++) {\r\n endIndex = (i + 1) * scanline_width;\r\n\r\n while (index < endIndex) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n\r\n if (a > 128) {\r\n // a run of the same value\r\n count = a - 128;\r\n if (count == 0 || count > endIndex - index) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad Format, bad scanline data (run)\";\r\n }\r\n\r\n while (count-- > 0) {\r\n scanLineArray[index++] = b;\r\n }\r\n } else {\r\n // a non-run\r\n count = a;\r\n if (count == 0 || count > endIndex - index) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"HDR Bad Format, bad scanline data (non-run)\";\r\n }\r\n\r\n scanLineArray[index++] = b;\r\n if (--count > 0) {\r\n for (let j = 0; j < count; j++) {\r\n scanLineArray[index++] = uint8array[dataIndex++];\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n // now convert data from buffer into floats\r\n for (i = 0; i < scanline_width; i++) {\r\n a = scanLineArray[i];\r\n b = scanLineArray[i + scanline_width];\r\n c = scanLineArray[i + 2 * scanline_width];\r\n d = scanLineArray[i + 3 * scanline_width];\r\n\r\n rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n}\r\n\r\nfunction readRGBEPixelsNotRLE(uint8array: Uint8Array, hdrInfo: HDRInfo): Float32Array {\r\n // this file is not run length encoded\r\n // read values sequentially\r\n\r\n let num_scanlines = hdrInfo.height;\r\n const scanline_width = hdrInfo.width;\r\n\r\n let a: number, b: number, c: number, d: number, i: number;\r\n let dataIndex = hdrInfo.dataPosition;\r\n\r\n // 3 channels of 4 bytes per pixel in float.\r\n const resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);\r\n const resultArray = new Float32Array(resultBuffer);\r\n\r\n // read in each successive scanline\r\n while (num_scanlines > 0) {\r\n for (i = 0; i < hdrInfo.width; i++) {\r\n a = uint8array[dataIndex++];\r\n b = uint8array[dataIndex++];\r\n c = uint8array[dataIndex++];\r\n d = uint8array[dataIndex++];\r\n\r\n rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);\r\n }\r\n\r\n num_scanlines--;\r\n }\r\n\r\n return resultArray;\r\n}\r\n\r\n/**\r\n * @deprecated Use functions separately\r\n */\r\nexport const HDRTools = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n RGBE_ReadHeader,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n GetCubeMapTextureData,\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n RGBE_ReadPixels,\r\n};\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./cubemapToSphericalPolynomial\";\r\nexport { HDRTools } from \"./hdr\";\r\nexport * from \"./panoramaToCubemap\";\r\n"]}
|