Klasse Palette

java.lang.Object
libsidplay.components.mos656x.Palette
Alle implementierten Schnittstellen:
IPalette

public class Palette extends Object implements 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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
  • Felddetails

    • saturation

      private float saturation
    • phaseShift

      private float phaseShift
    • offset

      private float offset
    • tint

      private float tint
    • luminanceC

      private float luminanceC
      Gauss 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_GAMMA
      The 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_PURITY
      This 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[] evenFiltered
      4x1 raster block to palette at even rows
    • oddFiltered

      private byte[] oddFiltered
      4x1 raster block to palette at odd rows
    • oddLineTable

      private int[] oddLineTable
      Blend of 2 yuvPalette values targeting odd rows
    • evenLineTable

      private int[] evenLineTable
      Blend 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

      public void calculatePalette(Palette.PaletteEntry[] colors)
    • 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 origo
      c - Width of peak
      Gibt zurück:
      Gaussian value
    • luminanceFilter

      private float luminanceFilter(float y0, float y1, float y2, float y3)
    • generateFilteredPalette

      private int[] generateFilteredPalette(Palette.YUVEntry[] p)
    • 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)
      Angegeben von:
      setGamma in Schnittstelle IPalette
    • getContrast

      public float getContrast()
    • setContrast

      public void setContrast(float contrast)
      Angegeben von:
      setContrast in Schnittstelle IPalette
    • getBrightness

      public float getBrightness()
    • setBrightness

      public void setBrightness(float brightness)
      Angegeben von:
      setBrightness in Schnittstelle IPalette
    • getLuminanceC

      public float getLuminanceC()
    • setLuminanceC

      public void setLuminanceC(float luminanceC)
      Angegeben von:
      setLuminanceC in Schnittstelle IPalette
    • getTint

      public float getTint()
    • setTint

      public void setTint(float tint)
      Angegeben von:
      setTint in Schnittstelle IPalette
    • getPhaseShift

      public float getPhaseShift()
    • setPhaseShift

      public void setPhaseShift(float phaseShift)
      Angegeben von:
      setPhaseShift in Schnittstelle IPalette
    • getOffset

      public float getOffset()
    • setOffset

      public void setOffset(float offset)
      Angegeben von:
      setOffset in Schnittstelle IPalette
    • getSaturation

      public float getSaturation()
    • setSaturation

      public void setSaturation(float saturation)
      Angegeben von:
      setSaturation in Schnittstelle IPalette
    • getDotCreep

      public float getDotCreep()
    • setDotCreep

      public void setDotCreep(float dotCreep)
      Angegeben von:
      setDotCreep in Schnittstelle IPalette
    • buildPaletteVariant

      public static Palette.PaletteEntry[] buildPaletteVariant(VICChipModel model)