Source: package/image/exr.js

import { Reporter } from '../../reporter/reporter.js';
import { LoadableComponent } from '../component/loadable_component.js';
import { checkPropTypes, UUIDRegex } from '../../lib.js';
import { LoadingBase } from '../loader/loading_base.js';

import { 
	UnsignedByteType,
    Texture
} from '../../../node_modules/three/build/three.module.js';


import { EXRLoader } from '../../../node_modules/three/examples/jsm/loaders/EXRLoader.js';


const exrLoader = new EXRLoader();

/** ProductBuilder EXR */
class EXR extends LoadableComponent {

	/**
    * @param {Reporter} reporter
    * @param {Object} settings
    * @param {UUID} [settings.id]
    * @param {string} [settings.name]
    * @param {QualitySourceMap} settings.source
    * @property {...any} [settings.other]
    */

	constructor(reporter, settings) {
        super(reporter, settings);
	}

    static _exportName = {
        singular: 'exr',
        plural: 'exrs'
    };
	
	/**
	* @param {LoadingBase} base
	* @param {LoadingQuality} quality 
	* @returns {Promise<Texture>}
	*/

	async _load(base, quality) {

		/** @type { LoadableComponent } */

		const component = this;
		
		// scoped references to be used from inside the promise

		const componentStatus = this._status;
		const setComponentContent = this._setContent.bind( this );

        const imageURL = new URL(base.url.href + this.source[quality].path);

		this.report({ msg: `Loading image from ${imageURL}` })


        return new Promise((resolve, reject) => {

			exrLoader.setDataType( UnsignedByteType )
            exrLoader.load(

                imageURL.href,
                

                // onLoad callback
                function ( image ) {
					resolve ( image );
                },

                // onProgress callback currently not supported
                undefined,

                // onError callback
                function (err) {
                    reject(err);
                }
            );
        });

	}

}

export { EXR };