Klasse Palette
- Alle implementierten Schnittstellen:
IPalette
Generates PAL VIC colors from first principles. The VIC colors are constructed on a YUV color wheel at certain luminance levels that depend on precise chip revision, and at certain fixed angles in the UV plane, which are fixed for all chips. Additionally, several effects observed on true PAL systems are emulated.
- The construction of the S-video signal reduces bandwidth of both luminance and chrominance. This is achieved by filtering these components in the horizontal direction. The luminance component is modified in order to allow dot-creep or black bleed like effects by shifting the filter kernel at bright colors towards right.
- PAL encoding which the VIC implements only partially and which causes color blending effects: the U and V components of succeeding lines become in effect averaged by the monitor's PAL decoder, because in PAL the color is encoded as difference to the previous line's color, but VIC keeps no memory of the color angles it generated for the preceding line.
- The imperfect generation of the color angles for the odd lines. The color wheel should be inverted between each row to allow difference encoding, but in practice the odd rows are not rotated perfectly.
- Color saturation for every second line is allowed to vary subtly.
To implement these effects, U and V are simply averaged within each 3x2 pixel block, and Y is filtered according to a gaussian at the top row's 3x1 pixel block.
To do this, helper tables are constructed which describe the filtered colors and luminances in the 3x1 block, and another helper table that can quickly look up averages between succeeding rows to achieve the full 3x2 filter. The YUV colors are converted to RGB colors on the second conversion.
To keep table sizes small, the pal emulation works on a 128 color palette per line. Any 3 pixel block is reduced to a single color on a 128-color palette, and two such colors (from current line and preceding line) are put side by side and used as index to look up the final color.
Since odd and even rows have slightly different colors, the colors 0..127 are assigned for even rows and colors 128..255 for odd rows. They are treated independently at the color generation and quantization procedure. The highest bit of the current row's generated color is used to identify odd/even rows.
- Autor:
- Antti Lankila
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungprotected static classSimulate VIC chip colors and some common distortions to the colors.protected static class -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprivate static final floatprivate static final floatprivate static final floatprivate static final floatprivate static final floatprivate floatprivate floatprivate floatprivate byte[]4x1 raster block to palette at even rowsprivate int[]Blend of 2 yuvPalette values targeting even rowsprivate floatprivate floatGauss parameter C for luminance spreadprivate static final floatThe nominal PAL gamma is 2.8.private byte[]4x1 raster block to palette at odd rowsprivate int[]Blend of 2 yuvPalette values targeting odd rowsprivate floatprivate static final intThis tunable is used to trade between the reproduced accuracy of rarely used colors to the accuracy of common blends. 256 colors per line are nowhere near enough, so this kind of tunable is surprisingly necessary.private floatprivate floatprivate float -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic Palette.PaletteEntry[]buildPaletteVariant(VICChipModel model) voidcalculatePalette(Palette.PaletteEntry[] colors) private byte[]calculatePaletteInternal(Palette.PaletteEntry[] colors, Palette.YUVEntry[] yuv, float saturation, float phaseShift, float tint) private static floatgauss(float b, float c) Gaussprivate int[]floatfloatfloatbyte[]int[]floatgetGamma()floatbyte[]int[]floatfloatfloatfloatgetTint()private floatluminanceFilter(float y0, float y1, float y2, float y3) private static byte[]replaceColorsByPalette(int[] filtered, OctreeQuantization q, Map<Integer, Byte> colorIndex) Find closest color according to root mean square from palette.voidsetBrightness(float brightness) voidsetContrast(float contrast) voidsetDotCreep(float dotCreep) voidsetGamma(float gamma) voidsetLuminanceC(float luminanceC) voidsetOffset(float offset) voidsetPhaseShift(float phaseShift) voidsetSaturation(float saturation) voidsetTint(float tint)
-
Felddetails
-
saturation
private float saturation -
phaseShift
private float phaseShift -
offset
private float offset -
tint
private float tint -
luminanceC
private float luminanceCGauss parameter C for luminance spread -
dotCreep
private float dotCreep -
brightness
private float brightness -
contrast
private float contrast -
gamma
private float gamma -
NOMINAL_PAL_GAMMA
private static final float NOMINAL_PAL_GAMMAThe nominal PAL gamma is 2.8. However, there is some disagreement with what the value really is. 2.8 makes bright colors painfully bright. Many emulators have chosen 2.5. I will follow suit to not appear too different.- Siehe auch:
-
PALETTE_PURITY
private static final int PALETTE_PURITYThis tunable is used to trade between the reproduced accuracy of rarely used colors to the accuracy of common blends. 256 colors per line are nowhere near enough, so this kind of tunable is surprisingly necessary.- Siehe auch:
-
ANGLE_RED
private static final float ANGLE_RED- Siehe auch:
-
ANGLE_GRN
private static final float ANGLE_GRN- Siehe auch:
-
ANGLE_BLU
private static final float ANGLE_BLU- Siehe auch:
-
ANGLE_ORN
private static final float ANGLE_ORN- Siehe auch:
-
ANGLE_BRN
private static final float ANGLE_BRN- Siehe auch:
-
evenFiltered
private byte[] evenFiltered4x1 raster block to palette at even rows -
oddFiltered
private byte[] oddFiltered4x1 raster block to palette at odd rows -
oddLineTable
private int[] oddLineTableBlend of 2 yuvPalette values targeting odd rows -
evenLineTable
private int[] evenLineTableBlend of 2 yuvPalette values targeting even rows
-
-
Konstruktordetails
-
Palette
public Palette()
-
-
Methodendetails
-
calculatePaletteInternal
private byte[] calculatePaletteInternal(Palette.PaletteEntry[] colors, Palette.YUVEntry[] yuv, float saturation, float phaseShift, float tint) -
calculatePalette
-
replaceColorsByPalette
private static byte[] replaceColorsByPalette(int[] filtered, OctreeQuantization q, Map<Integer, Byte> colorIndex) Find closest color according to root mean square from palette.- Parameter:
filtered-q-colorIndex-
-
gauss
private static float gauss(float b, float c) Gauss- Parameter:
b- Position with respect to origoc- Width of peak- Gibt zurück:
- Gaussian value
-
luminanceFilter
private float luminanceFilter(float y0, float y1, float y2, float y3) -
generateFilteredPalette
-
getEvenFiltered
public byte[] getEvenFiltered() -
getOddFiltered
public byte[] getOddFiltered() -
getEvenLines
public int[] getEvenLines() -
getOddLines
public int[] getOddLines() -
getGamma
public float getGamma() -
setGamma
public void setGamma(float gamma) -
getContrast
public float getContrast() -
setContrast
public void setContrast(float contrast) - Angegeben von:
setContrastin SchnittstelleIPalette
-
getBrightness
public float getBrightness() -
setBrightness
public void setBrightness(float brightness) - Angegeben von:
setBrightnessin SchnittstelleIPalette
-
getLuminanceC
public float getLuminanceC() -
setLuminanceC
public void setLuminanceC(float luminanceC) - Angegeben von:
setLuminanceCin SchnittstelleIPalette
-
getTint
public float getTint() -
setTint
public void setTint(float tint) -
getPhaseShift
public float getPhaseShift() -
setPhaseShift
public void setPhaseShift(float phaseShift) - Angegeben von:
setPhaseShiftin SchnittstelleIPalette
-
getOffset
public float getOffset() -
setOffset
public void setOffset(float offset) -
getSaturation
public float getSaturation() -
setSaturation
public void setSaturation(float saturation) - Angegeben von:
setSaturationin SchnittstelleIPalette
-
getDotCreep
public float getDotCreep() -
setDotCreep
public void setDotCreep(float dotCreep) - Angegeben von:
setDotCreepin SchnittstelleIPalette
-
buildPaletteVariant
-