Coder Social home page Coder Social logo

Comments (9)

zbydown avatar zbydown commented on August 18, 2024 1

The issue with odd-sized images appears to be resolved with new libultrahdr-esm, I think the PR can be merged and this issue can be closed.

However, I've encountered a new issue related to decoding certain gainmap JPEGs. I plan to conduct further investigations on my own and will open a new issue once I have a better understanding of the problem.

Thanks

from gainmap-js.

daniele-pelagatti avatar daniele-pelagatti commented on August 18, 2024

Yes the problem seems the libultrahdr WASM module which, apparently, cannot allocate its memory for some reason.

Can you give more detailed reproducibility steps?

Where are you executing this functions? are you building an app with the library and executing these functions in your code? are you using our tool at https://gainmap-creator.monogrid.com/ ?

Can you attach an example of an .hdr file which fails encodeJPEGMetadata and the code you execute?

from gainmap-js.

zbydown avatar zbydown commented on August 18, 2024

this is the small one
small.hdr.zip
and the big one
https://drive.google.com/file/d/1xRIhNjbb6CLqXiFaAemn7cfcgJ5FYaml/view?usp=sharing

2 samples

from gainmap-js.

daniele-pelagatti avatar daniele-pelagatti commented on August 18, 2024

ok, the big one fails in https://gainmap-creator.monogrid.com (which uses the library).

I'm not sure why this happens because we've tested the library (among others) with 8k versions of this image https://polyhaven.com/a/qwantani_puresky which is 289MB, bigger than yours both in file size and resolution

or this one https://polyhaven.com/a/metro_noord , 8k, exr, 387MB, compressed with 0.99 quality, and an output of nearly 20.3MB jpeg

all with no problems πŸ€”

I'm going to need to investigate this

from gainmap-js.

zbydown avatar zbydown commented on August 18, 2024

and for jpg gainmap repack failed, my code:

	import { GainMapLoader, HDRJPGLoader, extractGainmapFromJPEG } from '@monogrid/gainmap-js'
	import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js/encode'
	import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'

	async function loadImageAndGetDimensions(url) {
		return new Promise((resolve, reject) => {
			const img = new Image();
			img.onload = () => {
				resolve({ width: img.width, height: img.height });
			};
			img.onerror = reject;
			img.src = url;
		});
	}

	async function fetchAndDetermineImageDimensions(url) {
		const response = await fetch(url);
		const arrayBuffer = await response.arrayBuffer();
		const originalJpeg = new Uint8Array(arrayBuffer);
		const blob = new Blob([originalJpeg], { type: 'image/jpeg' });
		const newUrl = URL.createObjectURL(blob);

		const dimensions = await loadImageAndGetDimensions(newUrl);

		return dimensions;
	}

	process();

	async function process() {
		const inputUrl = 'textures/gainmap/03.jpg';
		const { width, height } = await fetchAndDetermineImageDimensions(inputUrl);
		const originalJpeg = new Uint8Array(await (await fetch(inputUrl)).arrayBuffer());

		const decodingResult = await extractGainmapFromJPEG(originalJpeg);

		const mimeType = 'image/jpeg';

		const sdr = {
			data: decodingResult.sdr,
			mimeType,
			width,
			height
		};

		const gainMap = {
			data: decodingResult.gainMap,
			mimeType,
			width,
			height
		};

		const jpeg = await encodeJPEGMetadata({
			...decodingResult.metadata,
			sdr,
			gainMap
		});
	}

failed jpg:
03.zip

in fact 01.jpg and 02.jpg from adobe sample worked, but 03.jpg failed

from gainmap-js.

zbydown avatar zbydown commented on August 18, 2024

https://gainmap-creator.monogrid.com/

smallnew.zip

I think I uploaded wrong small one, this new one does not work in your creator

from gainmap-js.

daniele-pelagatti avatar daniele-pelagatti commented on August 18, 2024

Alright, I found the problem in the code I used to instance the image in memory (which was copy/pasted from the official libultrahdr repository). It apparently didn't allow for odd sized images (width or height not divisible by two πŸ‘€ )

I don't know why this restriction was there but I can't see any (apparent) reason it was needed.

I've opened pull request #31 on branch feature/odd-image-size-fix

Are you able to test your files using that branch and report? (you may need to run git submodule update you may need to cd libultrahdr-wasm and git checkout b077d0 after checking out the branch, make sure your libultrahdr-was folder contains the "fuzzer" folder, not present before)

The two files you sent now work for me but it would be better to have a complete report before merging, thanks!

from gainmap-js.

zbydown avatar zbydown commented on August 18, 2024

image
I can not build libultrahdr-wasm on my mac (any version)
previously I used the wasm/js file from your published npm package

from gainmap-js.

daniele-pelagatti avatar daniele-pelagatti commented on August 18, 2024

libultrahdr-esm.zip
try this one, also that error is present in newer emscripten versions but not the one used by the library, I've yet to understand why it happens (something to do with typescript definition generation?) but, for now, the latest supported emscripten version is 3.1.47 (I'll write it in the README)

from gainmap-js.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.