Skip to content

Commit

Permalink
Loaders: Bubble parsing errors in remaining data texture loaders. (#2…
Browse files Browse the repository at this point in the history
…6499)

* Loaders: Bubble parsing errors in remaining data texture loaders.

* DataTextureLoader: Remove obsolete line.
  • Loading branch information
Mugen87 authored Jul 28, 2023
1 parent b447ff2 commit 680ce88
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 74 deletions.
8 changes: 4 additions & 4 deletions examples/jsm/loaders/EXRLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ class EXRLoader extends DataTextureLoader {

if ( dataView.getUint32( 0, true ) != 20000630 ) { // magic

throw new Error( 'THREE.EXRLoader: provided file doesn\'t appear to be in OpenEXR format.' );
throw new Error( 'THREE.EXRLoader: Provided file doesn\'t appear to be in OpenEXR format.' );

}

Expand Down Expand Up @@ -2033,7 +2033,7 @@ class EXRLoader extends DataTextureLoader {

if ( attributeValue === undefined ) {

console.warn( `EXRLoader.parse: skipped unknown header attribute type \'${attributeType}\'.` );
console.warn( `THREE.EXRLoader: Skipped unknown header attribute type \'${attributeType}\'.` );

} else {

Expand All @@ -2047,8 +2047,8 @@ class EXRLoader extends DataTextureLoader {

if ( ( spec & ~ 0x04 ) != 0 ) { // unsupported tiled, deep-image, multi-part

console.error( 'EXRHeader:', EXRHeader );
throw new Error( 'THREE.EXRLoader: provided file is currently unsupported.' );
console.error( 'THREE.EXRHeader:', EXRHeader );
throw new Error( 'THREE.EXRLoader: Provided file is currently unsupported.' );

}

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/loaders/LogLuvLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ UTIF.toRGBA = function ( out, type ) {
break;

default:
console.error( 'THREE.LogLuvLoader: Unsupported texture data type:', type );
throw new Error( 'THREE.LogLuvLoader: Unsupported texture data type: ' + type );

}

Expand Down Expand Up @@ -451,7 +451,7 @@ UTIF.toRGBA = function ( out, type ) {

} else {

console.log( 'Unsupported Photometric interpretation: ' + intp );
throw new Error( 'THREE.LogLuvLoader: Unsupported Photometric interpretation: ' + intp );

}

Expand Down
114 changes: 48 additions & 66 deletions examples/jsm/loaders/RGBELoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class RGBELoader extends DataTextureLoader {
parse( buffer ) {

const
/* return codes for rgbe routines */
//RGBE_RETURN_SUCCESS = 0,
RGBE_RETURN_FAILURE = - 1,

/* default error routine. change this to change error handling */
rgbe_read_error = 1,
rgbe_write_error = 2,
Expand All @@ -38,19 +34,14 @@ class RGBELoader extends DataTextureLoader {

switch ( rgbe_error_code ) {

case rgbe_read_error: console.error( 'THREE.RGBELoader Read Error: ' + ( msg || '' ) );
break;
case rgbe_write_error: console.error( 'THREE.RGBELoader Write Error: ' + ( msg || '' ) );
break;
case rgbe_format_error: console.error( 'THREE.RGBELoader Bad File Format: ' + ( msg || '' ) );
break;
case rgbe_read_error: throw new Error( 'THREE.RGBELoader: Read Error: ' + ( msg || '' ) );
case rgbe_write_error: throw new Error( 'THREE.RGBELoader: Write Error: ' + ( msg || '' ) );
case rgbe_format_error: throw new Error( 'THREE.RGBELoader: Bad File Format: ' + ( msg || '' ) );
default:
case rgbe_memory_error: console.error( 'THREE.RGBELoader: Error: ' + ( msg || '' ) );
case rgbe_memory_error: throw new Error( 'THREE.RGBELoader: Memory Error: ' + ( msg || '' ) );

}

return RGBE_RETURN_FAILURE;

},

/* offsets to red, green, and blue components in a data (float) pixel */
Expand Down Expand Up @@ -138,14 +129,14 @@ class RGBELoader extends DataTextureLoader {

if ( buffer.pos >= buffer.byteLength || ! ( line = fgets( buffer ) ) ) {

return rgbe_error( rgbe_read_error, 'no header found' );
rgbe_error( rgbe_read_error, 'no header found' );

}

/* if you want to require the magic token then uncomment the next line */
if ( ! ( match = line.match( magic_token_re ) ) ) {

return rgbe_error( rgbe_format_error, 'bad initial token' );
rgbe_error( rgbe_format_error, 'bad initial token' );

}

Expand Down Expand Up @@ -199,13 +190,13 @@ class RGBELoader extends DataTextureLoader {

if ( ! ( header.valid & RGBE_VALID_FORMAT ) ) {

return rgbe_error( rgbe_format_error, 'missing format specifier' );
rgbe_error( rgbe_format_error, 'missing format specifier' );

}

if ( ! ( header.valid & RGBE_VALID_DIMENSIONS ) ) {

return rgbe_error( rgbe_format_error, 'missing image size specifier' );
rgbe_error( rgbe_format_error, 'missing image size specifier' );

}

Expand All @@ -231,15 +222,15 @@ class RGBELoader extends DataTextureLoader {

if ( scanline_width !== ( ( buffer[ 2 ] << 8 ) | buffer[ 3 ] ) ) {

return rgbe_error( rgbe_format_error, 'wrong scanline width' );
rgbe_error( rgbe_format_error, 'wrong scanline width' );

}

const data_rgba = new Uint8Array( 4 * w * h );

if ( ! data_rgba.length ) {

return rgbe_error( rgbe_memory_error, 'unable to allocate buffer space' );
rgbe_error( rgbe_memory_error, 'unable to allocate buffer space' );

}

Expand All @@ -255,7 +246,7 @@ class RGBELoader extends DataTextureLoader {

if ( pos + 4 > buffer.byteLength ) {

return rgbe_error( rgbe_read_error );
rgbe_error( rgbe_read_error );

}

Expand All @@ -266,7 +257,7 @@ class RGBELoader extends DataTextureLoader {

if ( ( 2 != rgbeStart[ 0 ] ) || ( 2 != rgbeStart[ 1 ] ) || ( ( ( rgbeStart[ 2 ] << 8 ) | rgbeStart[ 3 ] ) != scanline_width ) ) {

return rgbe_error( rgbe_format_error, 'bad rgbe scanline format' );
rgbe_error( rgbe_format_error, 'bad rgbe scanline format' );

}

Expand All @@ -282,7 +273,7 @@ class RGBELoader extends DataTextureLoader {

if ( ( 0 === count ) || ( ptr + count > ptr_end ) ) {

return rgbe_error( rgbe_format_error, 'bad scanline data' );
rgbe_error( rgbe_format_error, 'bad scanline data' );

}

Expand Down Expand Up @@ -362,70 +353,61 @@ class RGBELoader extends DataTextureLoader {
byteArray.pos = 0;
const rgbe_header_info = RGBE_ReadHeader( byteArray );

if ( RGBE_RETURN_FAILURE !== rgbe_header_info ) {

const w = rgbe_header_info.width,
h = rgbe_header_info.height,
image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );

if ( RGBE_RETURN_FAILURE !== image_rgba_data ) {

let data, type;
let numElements;

switch ( this.type ) {

case FloatType:
const w = rgbe_header_info.width,
h = rgbe_header_info.height,
image_rgba_data = RGBE_ReadPixels_RLE( byteArray.subarray( byteArray.pos ), w, h );

numElements = image_rgba_data.length / 4;
const floatArray = new Float32Array( numElements * 4 );

for ( let j = 0; j < numElements; j ++ ) {
let data, type;
let numElements;

RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 4 );
switch ( this.type ) {

}
case FloatType:

data = floatArray;
type = FloatType;
break;
numElements = image_rgba_data.length / 4;
const floatArray = new Float32Array( numElements * 4 );

case HalfFloatType:
for ( let j = 0; j < numElements; j ++ ) {

numElements = image_rgba_data.length / 4;
const halfArray = new Uint16Array( numElements * 4 );
RGBEByteToRGBFloat( image_rgba_data, j * 4, floatArray, j * 4 );

for ( let j = 0; j < numElements; j ++ ) {
}

RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 4 );
data = floatArray;
type = FloatType;
break;

}
case HalfFloatType:

data = halfArray;
type = HalfFloatType;
break;
numElements = image_rgba_data.length / 4;
const halfArray = new Uint16Array( numElements * 4 );

default:
for ( let j = 0; j < numElements; j ++ ) {

console.error( 'THREE.RGBELoader: unsupported type: ', this.type );
break;
RGBEByteToRGBHalf( image_rgba_data, j * 4, halfArray, j * 4 );

}

return {
width: w, height: h,
data: data,
header: rgbe_header_info.string,
gamma: rgbe_header_info.gamma,
exposure: rgbe_header_info.exposure,
type: type
};
data = halfArray;
type = HalfFloatType;
break;

}
default:

throw new Error( 'THREE.RGBELoader: unsupported type: ', this.type );
break;

}

return null;
return {
width: w, height: h,
data: data,
header: rgbe_header_info.string,
gamma: rgbe_header_info.gamma,
exposure: rgbe_header_info.exposure,
type: type
};

}

Expand Down
2 changes: 0 additions & 2 deletions src/loaders/DataTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class DataTextureLoader extends Loader {

}

if ( ! texData ) return onError(); // TODO: Remove this when all loaders properly throw errors

if ( texData.image !== undefined ) {

texture.image = texData.image;
Expand Down

0 comments on commit 680ce88

Please sign in to comment.