@monogrid/gainmap-js 1.0.2

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/CODE_OF_CONDUCT.md +128 -0
  3. package/CONTRIBUTING.md +130 -0
  4. package/LICENSE +21 -0
  5. package/README.md +149 -0
  6. package/dist/_commonjsHelpers-1789f0cf.js +12 -0
  7. package/dist/compress-a4b59cab.js +82 -0
  8. package/dist/decode.d.ts +37 -0
  9. package/dist/encode-utils/compress.d.ts +12 -0
  10. package/dist/encode-utils/find-texture-min-max.d.ts +15 -0
  11. package/dist/encode-utils/get-gainmap.d.ts +13 -0
  12. package/dist/encode-utils/get-sdr-rendition.d.ts +16 -0
  13. package/dist/encode.d.ts +117 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.js +976 -0
  16. package/dist/index.umd.js +1069 -0
  17. package/dist/libultrahdr-esm.wasm +0 -0
  18. package/dist/libultrahdr.d.ts +129 -0
  19. package/dist/libultrahdr.js +6728 -0
  20. package/dist/libultrahdr.umd.js +6740 -0
  21. package/dist/materials/GainMapDecoderMaterial.d.ts +26 -0
  22. package/dist/materials/GainMapEncoderMaterial.d.ts +43 -0
  23. package/dist/materials/SDRMaterial.d.ts +35 -0
  24. package/dist/materials/index.d.ts +3 -0
  25. package/dist/types.d.ts +252 -0
  26. package/dist/utils/QuadRenderer.d.ts +73 -0
  27. package/dist/utils/get-data-texture.d.ts +14 -0
  28. package/dist/worker-interface.d.ts +26 -0
  29. package/dist/worker-interface.js +501 -0
  30. package/dist/worker-interface.umd.js +516 -0
  31. package/dist/worker-types.d.ts +24 -0
  32. package/dist/worker.d.ts +1 -0
  33. package/dist/worker.js +123 -0
  34. package/dist/worker.umd.js +207 -0
  35. package/examples/README.md +3 -0
  36. package/examples/compress.ts +43 -0
  37. package/examples/decode-from-jpeg.ts +40 -0
  38. package/examples/decode-from-separate-data.ts +41 -0
  39. package/examples/decode-to-datatexture.ts +65 -0
  40. package/examples/encode-and-compress.ts +29 -0
  41. package/examples/encode-jpeg-metadata.ts +57 -0
  42. package/examples/encode.ts +28 -0
  43. package/examples/globals.d.ts +6 -0
  44. package/examples/worker.ts +41 -0
  45. package/libultrahdr-wasm/LICENSE +202 -0
  46. package/libultrahdr-wasm/README.md +99 -0
  47. package/libultrahdr-wasm/build/libultrahdr-debug.js +7156 -0
  48. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  49. package/libultrahdr-wasm/build/libultrahdr-esm.js +6633 -0
  50. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  51. package/libultrahdr-wasm/build/libultrahdr.d.ts +30 -0
  52. package/libultrahdr-wasm/build/libultrahdr.js +6591 -0
  53. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  54. package/package.json +143 -0
  55. package/reports/eslint-examples.json +1 -0
  56. package/reports/eslint-src.json +1 -0
  57. package/reports/eslint-tests.json +1 -0
  58. package/reports/junit.xml +35 -0
  59. package/reports/typecheck-examples.log +0 -0
  60. package/reports/typecheck-tests.log +0 -0
  61. package/reports/typecheck.log +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## [1.0.2](https://github.com/MONOGRID/gainmap-js/compare/v1.0.1...v1.0.2) (2023-11-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **release:** add publishConfig to package.json ([cffff0b](https://github.com/MONOGRID/gainmap-js/commit/cffff0b31050ab54040922748b82d97e6aa820a3))
7
+
8
+ ## [1.0.1](https://github.com/MONOGRID/gainmap-js/compare/v1.0.0...v1.0.1) (2023-11-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **release:** scoped package for NPM publishing ([0e30758](https://github.com/MONOGRID/gainmap-js/commit/0e307589e51dd05e160062f2ae78fc746cbdf5aa))
14
+
15
+ # 1.0.0 (2023-11-03)
16
+
17
+ First Release
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ rnd@mono-grid.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,130 @@
1
+ <!-- omit in toc -->
2
+ # Contributing to gainmap-js
3
+
4
+ First off, thanks for taking the time to contribute! ❤️
5
+
6
+ All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉
7
+
8
+ > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
9
+ > - Star the project
10
+ > - Tweet about it
11
+ > - Refer this project in your project's readme
12
+ > - Mention the project at local meetups and tell your friends/colleagues
13
+
14
+ <!-- omit in toc -->
15
+ ## Table of Contents
16
+
17
+ - [I Have a Question](#i-have-a-question)
18
+ - [I Want To Contribute](#i-want-to-contribute)
19
+ - [Reporting Bugs](#reporting-bugs)
20
+ - [Suggesting Enhancements](#suggesting-enhancements)
21
+ - [Your First Code Contribution](#your-first-code-contribution)
22
+ - [Improving The Documentation](#improving-the-documentation)
23
+ - [Styleguides](#styleguides)
24
+ - [Commit Messages](#commit-messages)
25
+ - [Join The Project Team](#join-the-project-team)
26
+
27
+
28
+
29
+ ## I Have a Question
30
+
31
+ > If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/MONOGRID/gainmap-js/wiki).
32
+
33
+ Before you ask a question, it is best to search for existing [Issues](https://github.com/MONOGRID/gainmap-js/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
34
+
35
+ If you then still feel the need to ask a question and need clarification, we recommend the following:
36
+
37
+ - Open an [Issue](https://github.com/MONOGRID/gainmap-js/issues/new).
38
+ - Provide as much context as you can about what you're running into.
39
+ - Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
40
+
41
+ We will then take care of the issue as soon as possible.
42
+
43
+ <!--
44
+ You might want to create a separate issue tag for questions and include it in this description. People should then tag their issues accordingly.
45
+
46
+ Depending on how large the project is, you may want to outsource the questioning, e.g. to Stack Overflow or Gitter. You may add additional contact and information possibilities:
47
+ - IRC
48
+ - Slack
49
+ - Gitter
50
+ - Stack Overflow tag
51
+ - Blog
52
+ - FAQ
53
+ - Roadmap
54
+ - E-Mail List
55
+ - Forum
56
+ -->
57
+
58
+ ## I Want To Contribute
59
+
60
+ > ### Legal Notice <!-- omit in toc -->
61
+ > When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
62
+
63
+ ### Reporting Bugs
64
+
65
+ <!-- omit in toc -->
66
+ #### Before Submitting a Bug Report
67
+
68
+ A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
69
+
70
+ - Make sure that you are using the latest version.
71
+ - Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/MONOGRID/gainmap-js/wiki). If you are looking for support, you might want to check [this section](#i-have-a-question)).
72
+ - To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/MONOGRID/gainmap-jsissues?q=label%3Abug).
73
+ - Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
74
+ - Collect information about the bug:
75
+ - Stack trace (Traceback)
76
+ - OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
77
+ - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
78
+ - Possibly your input and the output
79
+ - Can you reliably reproduce the issue? And can you also reproduce it with older versions?
80
+
81
+ <!-- omit in toc -->
82
+ #### How Do I Submit a Good Bug Report?
83
+
84
+ > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <rnd@mono-grid.com>.
85
+ <!-- You may add a PGP key to allow the messages to be sent encrypted as well. -->
86
+
87
+ We use GitHub issues to track bugs and errors. If you run into an issue with the project:
88
+
89
+ - Open an [Issue](https://github.com/MONOGRID/gainmap-js/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
90
+ - Explain the behavior you would expect and the actual behavior.
91
+ - Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
92
+ - Provide the information you collected in the previous section.
93
+
94
+ Once it's filed:
95
+
96
+ - The project team will label the issue accordingly.
97
+ - A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced.
98
+ - If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution).
99
+
100
+ <!-- You might want to create an issue template for bugs and errors that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
101
+
102
+
103
+ ### Suggesting Enhancements
104
+
105
+ This section guides you through submitting an enhancement suggestion for gainmap-js, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions.
106
+
107
+ <!-- omit in toc -->
108
+ #### Before Submitting an Enhancement
109
+
110
+ - Make sure that you are using the latest version.
111
+ - Read the [documentation](https://github.com/MONOGRID/gainmap-js/wiki) carefully and find out if the functionality is already covered, maybe by an individual configuration.
112
+ - Perform a [search](https://github.com/MONOGRID/gainmap-js/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
113
+ - Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
114
+
115
+ <!-- omit in toc -->
116
+ #### How Do I Submit a Good Enhancement Suggestion?
117
+
118
+ Enhancement suggestions are tracked as [GitHub issues](https://github.com/MONOGRID/gainmap-js/issues).
119
+
120
+ - Use a **clear and descriptive title** for the issue to identify the suggestion.
121
+ - Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
122
+ - **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
123
+ - You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. <!-- this should only be included if the project has a GUI -->
124
+ - **Explain why this enhancement would be useful** to most gainmap-js users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
125
+
126
+
127
+
128
+ <!-- omit in toc -->
129
+ ## Attribution
130
+ This guide is based on the **contributing-gen**. [Make your own](https://github.com/bttger/contributing-gen)!
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MONOGRID
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # gainmap-js
2
+ A Javascript (TypeScript) Encoder/Decoder Implementation of Adobe's Gain Map Technology for storing HDR Images using an SDR Image + a "Gain map"
3
+
4
+ > :warning: This library **is primarly intended** for encoding and decoding gain map images for the [three.js](https://github.com/mrdoob/three.js/) 3D Library
5
+ >
6
+ > It can be used for general encode/decode of gain maps but it depends on the three.js library which, in itself, is quite heavy if you only use it to encode/decode gainmaps.
7
+
8
+ ## Installing
9
+ ```bash
10
+ $ npm install @monogrid/gainmap-js threejs
11
+ ```
12
+
13
+ ## What is a Gain map?
14
+
15
+ [See here](https://gregbenzphotography.com/hdr-images/jpg-hdr-gain-maps-in-adobe-camera-raw/) for a detailed explanation, here are some relevant parts:
16
+
17
+ > A gain map is a single file with a second pseudo-image embedded in it to create an optimized result for a specific monitor. It can be used to generate the HDR version (which looks dramatically better where supported), the SDR version (without tone mapping to ensures great quality), or anything in between (to better support less capable HDR displays).
18
+
19
+ > Gain maps are not a new type of file, but rather a technology which can be embedded into a variety of image formats. There are reference specs already for the JPG, AVIF, JXL, and HEIF file formats. JPG is especially notable as it could not properly support HDR without gain maps and it offers a very useful bridge to the future (i.e. highly compatible with today’s software).
20
+
21
+ > A gain map includes:
22
+ >
23
+ > * A **base (default) image**. This can be an SDR or an HDR image (JPG gain maps are always encoded with SDR as the base). If the browser or viewing software does not understand gain maps, it will just the treat file as if it were just the base image.
24
+ > * The **gain map**. This is a secondary “image” embedded in the file. It is not a real image, but rather contains data to convert each pixel from the base image into the other (SDR or HDR) version of the image.
25
+ >* Gain map **metadata**. This tells the browser how the gain map is encoded as well as critical information to optimize rendering on any display.
26
+
27
+ ## API
28
+
29
+ Refer to the [WIKI](https://github.com/MONOGRID/gainmap-js/wiki) for detailed documentation about the API.
30
+
31
+ ## Examples
32
+
33
+ ### Decoding
34
+
35
+ The main use case of this library is to decode a JPEG file that contains gain map data
36
+ and use it instead of a traditional `.exr` or `.hdr` image.
37
+
38
+ ```ts
39
+ import { decode } from '@monogrid/gainmap-js'
40
+ import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
41
+ import {
42
+ Mesh,
43
+ MeshBasicMaterial,
44
+ PerspectiveCamera,
45
+ PlaneGeometry,
46
+ Scene,
47
+ WebGLRenderer
48
+ } from 'three'
49
+
50
+ const renderer = new WebGLRenderer()
51
+
52
+ // fetch a JPEG image containing a gainmap as ArrayBuffer
53
+ const gainmap = await (await fetch('gainmap.jpeg')).arrayBuffer()
54
+
55
+ // extract data from the JPEG
56
+ const { sdr, gainMap, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(gainmap))
57
+
58
+ // restore the HDR texture
59
+ const result = await decode({
60
+ sdr,
61
+ gainMap,
62
+ // this allows to use `result.renderTarget.texture` directly
63
+ renderer,
64
+ // this will restore the full HDR range
65
+ maxDisplayBoost: Math.pow(2, parsedMetadata.hdrCapacityMax),
66
+ ...parsedMetadata
67
+ })
68
+
69
+ const scene = new Scene()
70
+ // `result` can be used to populate a Texture
71
+ const mesh = new Mesh(
72
+ new PlaneGeometry(),
73
+ new MeshBasicMaterial({ map: result.renderTarget.texture })
74
+ )
75
+ scene.add(mesh)
76
+ renderer.render(scene, new PerspectiveCamera())
77
+ ```
78
+
79
+ ### Encoding
80
+
81
+ Encoding a Gain map starting from an EXR file.
82
+
83
+ This is generally not useful in a `three.js` site but this library exposes methods
84
+ that allow to encode an `.exr` or `hdr` file into a `jpeg` with an embedded gain map.
85
+
86
+ ```ts
87
+ import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
88
+ import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
89
+ import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
90
+
91
+ // load an HDR file
92
+ const loader = new EXRLoader()
93
+ const image = await loader.loadAsync('image.exr')
94
+
95
+ // find RAW RGB Max value of a texture
96
+ const textureMax = await findTextureMinMax(image)
97
+
98
+ // Encode the gainmap
99
+ const encodingResult = encode({
100
+ image,
101
+ // this will encode the full HDR range
102
+ maxContentBoost: Math.max.apply(this, textureMax)
103
+ })
104
+
105
+ // obtain the RAW RGBA SDR buffer and create an ImageData
106
+ const sdrImageData = new ImageData(encodingResult.sdr.toArray(), encodingResult.sdr.width, encodingResult.sdr.height)
107
+ // obtain the RAW RGBA Gain map buffer and create an ImageData
108
+ const gainMapImageData = new ImageData(encodingResult.gainMap.toArray(), encodingResult.gainMap.width, encodingResult.gainMap.height)
109
+
110
+ // parallel compress the RAW buffers into the specified mimeType
111
+ const mimeType = 'image/jpeg'
112
+ const quality = 0.9
113
+
114
+ const [sdr, gainMap] = await Promise.all([
115
+ compress({
116
+ source: sdrImageData,
117
+ mimeType,
118
+ quality,
119
+ flipY: true // output needs to be flipped
120
+ }),
121
+ compress({
122
+ source: gainMapImageData,
123
+ mimeType,
124
+ quality,
125
+ flipY: true // output needs to be flipped
126
+ })
127
+ ])
128
+
129
+ // obtain the metadata which will be embedded into
130
+ // and XMP tag inside the final JPEG file
131
+ const metadata = encodingResult.getMetadata()
132
+
133
+ // embed the compressed images + metadata into a single
134
+ // JPEG file
135
+ const jpeg = await encodeJPEGMetadata({
136
+ ...encodingResult,
137
+ ...metadata,
138
+ sdr,
139
+ gainMap
140
+ })
141
+
142
+ // `jpeg` will be an `Uint8Array` which can be saved somewhere
143
+ ```
144
+
145
+
146
+ ## References
147
+
148
+ * [Adobe Gainmap Specification](https://helpx.adobe.com/camera-raw/using/gain-map.html)
149
+ * [Ultra HDR Image Format v1.0](https://developer.android.com/guide/topics/media/platform/hdr-image-format)
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @monogrid/gainmap-js v1.0.1
3
+ * With ❤️, by MONOGRID <hello@mono-grid.com>
4
+ */
5
+
6
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
+
8
+ function getDefaultExportFromCjs (x) {
9
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
10
+ }
11
+
12
+ export { commonjsGlobal as c, getDefaultExportFromCjs as g };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @monogrid/gainmap-js v1.0.1
3
+ * With ❤️, by MONOGRID <hello@mono-grid.com>
4
+ */
5
+
6
+ /**
7
+ * Used internally
8
+ *
9
+ * @internal
10
+ * @param canvas
11
+ * @param mimeType
12
+ * @param quality
13
+ * @returns
14
+ */
15
+ const canvasToBlob = async (canvas, mimeType, quality) => {
16
+ if (canvas instanceof OffscreenCanvas) {
17
+ return canvas.convertToBlob({ type: mimeType, quality: quality || 0.9 });
18
+ }
19
+ return new Promise((resolve, reject) => {
20
+ canvas.toBlob((res) => {
21
+ if (res)
22
+ resolve(res);
23
+ else
24
+ reject('Failed to convert canvas to blob');
25
+ }, mimeType, quality || 0.9);
26
+ });
27
+ };
28
+ /**
29
+ * Converts a RAW RGBA image buffer into the provided `mimeType` using the provided `quality`
30
+ *
31
+ * @category Compression
32
+ * @group Compression
33
+ * @param params
34
+ * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
35
+ * @throws {Error} if the provided source image cannot be decoded
36
+ * @throws {Error} if the function fails to create a canvas context
37
+ */
38
+ const compress = async (params) => {
39
+ if (typeof createImageBitmap === 'undefined')
40
+ throw new Error('createImageBitmap() not supported.');
41
+ const { source, mimeType, quality, flipY } = params;
42
+ // eslint-disable-next-line no-undef
43
+ let imageBitmapSource;
44
+ if ((source instanceof Uint8Array || source instanceof Uint8ClampedArray) && 'sourceMimeType' in params) {
45
+ imageBitmapSource = new Blob([source], { type: params.sourceMimeType });
46
+ }
47
+ else if (source instanceof ImageData) {
48
+ imageBitmapSource = source;
49
+ }
50
+ else {
51
+ throw new Error('Invalid source image');
52
+ }
53
+ const img = await createImageBitmap(imageBitmapSource);
54
+ const width = img.width;
55
+ const height = img.height;
56
+ let canvas;
57
+ if (typeof OffscreenCanvas !== 'undefined') {
58
+ canvas = new OffscreenCanvas(width, height);
59
+ }
60
+ else {
61
+ canvas = document.createElement('canvas');
62
+ }
63
+ const ctx = canvas.getContext('2d');
64
+ if (!ctx)
65
+ throw new Error('Failed to create canvas Context');
66
+ // flip Y
67
+ if (flipY === true) {
68
+ ctx.translate(0, height);
69
+ ctx.scale(1, -1);
70
+ }
71
+ ctx.drawImage(img, 0, 0, width, height);
72
+ const blob = await canvasToBlob(canvas, mimeType, quality || 0.9);
73
+ const data = new Uint8Array(await blob.arrayBuffer());
74
+ return {
75
+ data,
76
+ mimeType,
77
+ width,
78
+ height
79
+ };
80
+ };
81
+
82
+ export { compress as c };
@@ -0,0 +1,37 @@
1
+ import { GainMapDecoderMaterial } from './materials/GainMapDecoderMaterial';
2
+ import { DecodeParameters } from './types';
3
+ import { QuadRenderer } from './utils/QuadRenderer';
4
+ /**
5
+ * Decodes a gain map using a WebGLRenderTarget
6
+ *
7
+ * @category Decoding
8
+ * @group Decoding
9
+ * @example
10
+ * import { decode } from '@monogrid/gainmap-js'
11
+ * import { Mesh, MeshBasicMaterial, PlaneGeometry, TextureLoader } from 'three'
12
+ *
13
+ * const loader = new TextureLoader()
14
+ *
15
+ * // load SDR Representation
16
+ * const sdr = await loader.loadAsync('sdr.jpg')
17
+ * // load Gain map recovery image
18
+ * const gainMap = await loader.loadAsync('gainmap.jpg')
19
+ * // load metadata
20
+ * const metadata = await (await fetch('metadata.json')).json()
21
+ *
22
+ * const result = await decode({
23
+ * sdr,
24
+ * gainMap,
25
+ * // this will restore the full HDR range
26
+ * maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
27
+ * ...metadata
28
+ * })
29
+ *
30
+ * // result can be used to populate a Texture
31
+ * const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
32
+ *
33
+ * @param params
34
+ * @returns
35
+ * @throws {Error} if the WebGLRenderer fails to render the gain map
36
+ */
37
+ export declare const decode: (params: DecodeParameters) => QuadRenderer<1016, GainMapDecoderMaterial>;
@@ -0,0 +1,12 @@
1
+ import { CompressedImage, CompressParameters } from '../types';
2
+ /**
3
+ * Converts a RAW RGBA image buffer into the provided `mimeType` using the provided `quality`
4
+ *
5
+ * @category Compression
6
+ * @group Compression
7
+ * @param params
8
+ * @throws {Error} if the browser does not support [createImageBitmap](https://caniuse.com/createimagebitmap)
9
+ * @throws {Error} if the provided source image cannot be decoded
10
+ * @throws {Error} if the function fails to create a canvas context
11
+ */
12
+ export declare const compress: (params: CompressParameters) => Promise<CompressedImage>;
@@ -0,0 +1,15 @@
1
+ import { DataTexture, WebGLRenderer } from 'three';
2
+ import { EXR } from 'three/examples/jsm/loaders/EXRLoader';
3
+ import { LogLuv } from 'three/examples/jsm/loaders/LogLuvLoader';
4
+ import { RGBE } from 'three/examples/jsm/loaders/RGBELoader';
5
+ /**
6
+ *
7
+ * @category Encoding Functions
8
+ * @group Encoding Functions
9
+ *
10
+ * @param srcTex
11
+ * @param mode
12
+ * @param renderer
13
+ * @returns
14
+ */
15
+ export declare const findTextureMinMax: (image: EXR | RGBE | LogLuv | DataTexture, mode?: 'min' | 'max', renderer?: WebGLRenderer) => number[];
@@ -0,0 +1,13 @@
1
+ import { GainMapEncoderMaterial } from '../materials/GainMapEncoderMaterial';
2
+ import { EncodingParametersBase } from '../types';
3
+ import { QuadRenderer } from '../utils/QuadRenderer';
4
+ /**
5
+ *
6
+ * @param params
7
+ * @returns
8
+ * @category Encoding Functions
9
+ * @group Encoding Functions
10
+ */
11
+ export declare const getGainMap: (params: {
12
+ sdr: InstanceType<typeof QuadRenderer>;
13
+ } & EncodingParametersBase) => QuadRenderer<1009, GainMapEncoderMaterial>;
@@ -0,0 +1,16 @@
1
+ import { DataTexture, ToneMapping, WebGLRenderer } from 'three';
2
+ import { SDRMaterial } from '../materials/SDRMaterial';
3
+ import { QuadRenderer } from '../utils/QuadRenderer';
4
+ export { SDRMaterial };
5
+ /**
6
+ * Renders an SDR Representation of an HDR Image
7
+ *
8
+ * @category Encoding Functions
9
+ * @group Encoding Functions
10
+ *
11
+ * @param hdrTexture The HDR image to be rendered
12
+ * @param renderer (optional) WebGLRenderer to use diring the rendering, a disposable renderer will be create and destroyed if this is not provided.
13
+ * @param toneMapping (optional) Tonemapping to be applied to the SDR Rendition
14
+ * @throws {Error} if the WebGLRenderer fails to render the SDR image
15
+ */
16
+ export declare const getSDRRendition: (hdrTexture: DataTexture, renderer?: WebGLRenderer, toneMapping?: ToneMapping) => QuadRenderer<1009, SDRMaterial>;