Search in sources :

Example 1 with PaletteBox

use of com.sun.media.imageioimpl.plugins.jpeg2000.PaletteBox in project bioformats by ome.

the class FileFormatReader method readPaletteBox.

/**
 * This method reads the content of the palette box
 */
public void readPaletteBox(int length) throws IOException {
    // Get current position in file
    int pos = in.getPos();
    int lutSize = in.readShort();
    int numComp = in.readByte();
    compSize = new byte[numComp];
    for (int i = 0; i < numComp; i++) {
        compSize[i] = (byte) in.readByte();
    }
    lut = new byte[numComp][lutSize];
    for (int n = 0; n < lutSize; n++) {
        for (int c = 0; c < numComp; c++) {
            int depth = 1 + (compSize[c] & 0x7F);
            if (depth > 32)
                depth = 32;
            int numBytes = (depth + 7) >> 3;
            int mask = (1 << depth) - 1;
            byte[] buf = new byte[numBytes];
            in.readFully(buf, 0, numBytes);
            int val = 0;
            for (int k = 0; k < numBytes; k++) {
                val = buf[k] + (val << 8);
            }
            lut[c][n] = (byte) val;
        }
    }
    if (metadata != null) {
        metadata.addNode(new PaletteBox(length, compSize, lut));
    }
}
Also used : PaletteBox(com.sun.media.imageioimpl.plugins.jpeg2000.PaletteBox)

Example 2 with PaletteBox

use of com.sun.media.imageioimpl.plugins.jpeg2000.PaletteBox in project bioformats by openmicroscopy.

the class FileFormatReader method readPaletteBox.

/**
 * This method reads the content of the palette box
 */
public void readPaletteBox(int length) throws IOException {
    // Get current position in file
    int pos = in.getPos();
    int lutSize = in.readShort();
    int numComp = in.readByte();
    compSize = new byte[numComp];
    for (int i = 0; i < numComp; i++) {
        compSize[i] = (byte) in.readByte();
    }
    lut = new byte[numComp][lutSize];
    for (int n = 0; n < lutSize; n++) {
        for (int c = 0; c < numComp; c++) {
            int depth = 1 + (compSize[c] & 0x7F);
            if (depth > 32)
                depth = 32;
            int numBytes = (depth + 7) >> 3;
            int mask = (1 << depth) - 1;
            byte[] buf = new byte[numBytes];
            in.readFully(buf, 0, numBytes);
            int val = 0;
            for (int k = 0; k < numBytes; k++) {
                val = buf[k] + (val << 8);
            }
            lut[c][n] = (byte) val;
        }
    }
    if (metadata != null) {
        metadata.addNode(new PaletteBox(length, compSize, lut));
    }
}
Also used : PaletteBox(com.sun.media.imageioimpl.plugins.jpeg2000.PaletteBox)

Aggregations

PaletteBox (com.sun.media.imageioimpl.plugins.jpeg2000.PaletteBox)2