*/
private Palette decodePalette(final SubPictureHD pic) throws CoreException {
int ofs = pic.getPaletteOffset();
int alphaOfs = pic.getAlphaOffset();
Palette palette = new Palette(256);
try {
for (int i=0; i < palette.getSize(); i++) {
// each palette entry consists of 3 bytes
int y = buffer.getByte(ofs++);
int cr,cb;
if (configuration.isSwapCrCb()) {
cb = buffer.getByte(ofs++);
cr = buffer.getByte(ofs++);
} else {
cr = buffer.getByte(ofs++);
cb = buffer.getByte(ofs++);
}
// each alpha entry consists of 1 byte
int alpha = 0xff - buffer.getByte(alphaOfs++);
if (alpha < configuration.getAlphaCrop()) { // to not mess with scaling algorithms, make transparent color black
palette.setRGB(i, 0, 0, 0);
} else {
palette.setYCbCr(i, y, cb, cr);
}
palette.setAlpha(i, alpha);
}
return palette;
} catch (FileBufferException ex) {
throw new CoreException (ex.getMessage());
}