Skip to content

BitsPerSample Being an Array #159

@ilan-gold

Description

@ilan-gold

Hello @constantinius,

I have run into a case where bitsPerSample seems to be an array. At first I thought this should not be allowed but after googling it, it appears to be fair play (http://www.fileformat.info/format/tiff/corion.htm).

--- BitsPerSample
Tag  = 258  (102)
Type = word
N    = SamplesPerPixel
Default = 1

Number of bits per sample. Note that this tag allows a different number of
bits per sample for each sample corresponding to a pixel. For example, RGB
color data could use a different number of bits per sample for each of the
three color planes.

I think without going overboard, we can just be clear that we only support the same bit-depth for each channel - then all we need to do is add a check for an Array here and then take the first value. We can even check to confirm they are all the same value and if not, just exit.

function arrayForType(format, bitsPerSample, size) {
switch (format) {
case 1: // unsigned integer data
switch (bitsPerSample) {
case 8:
return new Uint8Array(size);
case 16:
return new Uint16Array(size);
case 32:
return new Uint32Array(size);
default:
break;
}
break;
case 2: // twos complement signed integer data
switch (bitsPerSample) {
case 8:
return new Int8Array(size);
case 16:
return new Int16Array(size);
case 32:
return new Int32Array(size);
default:
break;
}
break;
case 3: // floating point data
switch (bitsPerSample) {
case 32:
return new Float32Array(size);
case 64:
return new Float64Array(size);
default:
break;
}
break;
default:
break;
}
throw Error('Unsupported data format/bitsPerSample');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions