// close existing subtitleStream
if (subtitleStream != null) {
subtitleStream.close();
}
DvdSubtitleStream substreamDvd;
String fnI;
String fnS;
if (isVobSub) {
// SUB/IDX
if (configuration.getCurrentStreamID() == StreamID.DVDSUB) {
fnS = fname;
fnI = FilenameUtils.removeExtension(fname) + ".idx";
} else {
fnI = fname;
fnS = FilenameUtils.removeExtension(fname) + ".sub";
}
subDVD = new SubDvd(fnS, fnI);
subtitleStream = subDVD;
inMode = InputMode.VOBSUB;
substreamDvd = subDVD;
} else {
// SUP/IFO
if (FilenameUtils.getExtension(fname).equalsIgnoreCase("ifo") ) {
fnI = fname;
fnS = FilenameUtils.removeExtension(fname) + ".sup";
} else {
fnI = FilenameUtils.removeExtension(fname) + ".ifo";
fnS = fname;
}
supDVD = new SupDvd(fnS, fnI);
subtitleStream = supDVD;
inMode = InputMode.SUPIFO;
substreamDvd = supDVD;
}
// decode first frame
subtitleStream.decode(0);
subVobTrg = new SubPictureDVD();
defaultSourceDVDPalette = substreamDvd.getSrcPalette();
currentSourceDVDPalette = new Palette(defaultSourceDVDPalette);
// automatically set luminance thresholds for VobSub conversion
int primColIdx = subtitleStream.getPrimaryColorIndex();
int yMax = subtitleStream.getPalette().getY()[primColIdx] & 0xff;
int[] luminanceThreshold = new int[2];
configuration.setLuminanceThreshold(luminanceThreshold);
if (yMax > 10) {
// find darkest opaque color
int yMin = yMax;
for (int i=0; i < 4; i++) {
int y = subtitleStream.getPalette().getY()[i] & 0xff;
int a = subtitleStream.getPalette().getAlpha(i);
if (y < yMin && a > configuration.getAlphaThreshold()) {
yMin = y;
}
}
luminanceThreshold[0] = yMin + (yMax-yMin)*9/10;
luminanceThreshold[1] = yMin + (yMax-yMin)*3/10;
} else {
luminanceThreshold[0] = 210;
luminanceThreshold[1] = 160;
}
configuration.setLanguageIdx(substreamDvd.getLanguageIndex());
// set frame rate
int h = subtitleStream.getSubPicture(0).getHeight(); //subtitleStream.getBitmap().getHeight();
switch (h) {
case 480: