default:
f = null;
}
Bitmap tBm;
Palette tPal = trgPal;
// create scaled bitmap
OutputMode outputMode = configuration.getOutputMode();
PaletteMode paletteMode = configuration.getPaletteMode();
if (outputMode == OutputMode.VOBSUB || outputMode == OutputMode.SUPIFO) {
// export 4 color palette
if (w==trgWidth && h==trgHeight) {
// don't scale at all
if ( (inMode == InputMode.VOBSUB || inMode == InputMode.SUPIFO) && paletteMode == PaletteMode.KEEP_EXISTING) {
tBm = subtitleStream.getBitmap(); // no conversion
} else {
tBm = subtitleStream.getBitmap().getBitmapWithNormalizedPalette(subtitleStream.getPalette().getAlpha(), configuration.getAlphaThreshold(), subtitleStream.getPalette().getY(), configuration.getLuminanceThreshold()); // reduce palette
}
} else {
// scale up/down
if ((inMode == InputMode.VOBSUB || inMode == InputMode.SUPIFO) && paletteMode == PaletteMode.KEEP_EXISTING) {
// keep palette
if (f != null) {
tBm = subtitleStream.getBitmap().scaleFilter(trgWidth, trgHeight, subtitleStream.getPalette(), f);
} else {
tBm = subtitleStream.getBitmap().scaleBilinear(trgWidth, trgHeight, subtitleStream.getPalette());
}
} else {
// reduce palette
if (f != null) {
tBm = subtitleStream.getBitmap().scaleFilterLm(trgWidth, trgHeight, subtitleStream.getPalette(), configuration.getAlphaThreshold(), configuration.getLuminanceThreshold(), f);
} else {
tBm = subtitleStream.getBitmap().scaleBilinearLm(trgWidth, trgHeight, subtitleStream.getPalette(), configuration.getAlphaThreshold(), configuration.getLuminanceThreshold());
}
}
}
} else {
// export (up to) 256 color palette
tPal = subtitleStream.getPalette();
if (w==trgWidth && h==trgHeight) {
tBm = subtitleStream.getBitmap(); // no scaling, no conversion
} else {
// scale up/down
if (paletteMode == PaletteMode.KEEP_EXISTING) {
// keep palette
if (f != null) {
tBm = subtitleStream.getBitmap().scaleFilter(trgWidth, trgHeight, subtitleStream.getPalette(), f);
} else {
tBm = subtitleStream.getBitmap().scaleBilinear(trgWidth, trgHeight, subtitleStream.getPalette());
}
} else {
// create new palette
boolean dither = paletteMode == PaletteMode.CREATE_DITHERED;
BitmapWithPalette pb;
if (f != null) {
pb = subtitleStream.getBitmap().scaleFilter(trgWidth, trgHeight, subtitleStream.getPalette(), f, dither);
} else {
pb = subtitleStream.getBitmap().scaleBilinear(trgWidth, trgHeight, subtitleStream.getPalette(), dither);
}
tBm = pb.bitmap;
tPal = pb.palette;
}
}
}
if (!picTrg.getErasePatch().isEmpty()) {
trgBitmapUnpatched = new Bitmap(tBm);
int col = tPal.getIndexOfMostTransparentPaletteEntry();
for (ErasePatch ep : picTrg.getErasePatch()) {
tBm.fillRectangularWithColorIndex(ep.x, ep.y, ep.width, ep.height, (byte)col);
}
} else {
trgBitmapUnpatched = tBm;