Class DitherUtil


  • public final class DitherUtil
    extends java.lang.Object
    Utility methods for dithering.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int[] BAYER_D2  
      private static int[] BAYER_D4  
      private static int[] BAYER_D8  
      static int DITHER_MATRIX_2X2
      Selects a 2x2 Bayer dither matrix (5 grayscales)
      static int DITHER_MATRIX_4X4
      Selects a 4x4 Bayer dither matrix (17 grayscales)
      static int DITHER_MATRIX_8X8
      Selects a 8x8 Bayer dither matrix (65 grayscales)
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DitherUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int[] deriveBayerMatrix​(int[] d)  
      static int[] getBayerBasePattern​(int matrix)
      Returns the Bayer dither base pattern for a particular matrix size.
      static byte[] getBayerDither​(int matrix, int gray255, boolean doubleMatrix)
      Returns a byte array containing the dither pattern for the given 8-bit gray value.
      static byte[] getBayerDither​(int matrix, java.awt.Color col, boolean doubleMatrix)
      Returns a byte array containing the dither pattern for the given 8-bit gray value.
      private static void setValueInMatrix​(int[] dn, int half, int part, int idx, int value)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DITHER_MATRIX_2X2

        public static final int DITHER_MATRIX_2X2
        Selects a 2x2 Bayer dither matrix (5 grayscales)
        See Also:
        Constant Field Values
      • DITHER_MATRIX_4X4

        public static final int DITHER_MATRIX_4X4
        Selects a 4x4 Bayer dither matrix (17 grayscales)
        See Also:
        Constant Field Values
      • DITHER_MATRIX_8X8

        public static final int DITHER_MATRIX_8X8
        Selects a 8x8 Bayer dither matrix (65 grayscales)
        See Also:
        Constant Field Values
      • BAYER_D2

        private static final int[] BAYER_D2
      • BAYER_D4

        private static final int[] BAYER_D4
      • BAYER_D8

        private static final int[] BAYER_D8
    • Constructor Detail

      • DitherUtil

        private DitherUtil()
    • Method Detail

      • deriveBayerMatrix

        private static int[] deriveBayerMatrix​(int[] d)
      • setValueInMatrix

        private static void setValueInMatrix​(int[] dn,
                                             int half,
                                             int part,
                                             int idx,
                                             int value)
      • getBayerBasePattern

        public static int[] getBayerBasePattern​(int matrix)
        Returns the Bayer dither base pattern for a particular matrix size.
        Parameters:
        matrix - the matrix size (DITHER_MATRIX_2X2, DITHER_MATRIX_4X4 or DITHER_MATRIX_8X8)
        Returns:
        the base pattern for the given size
      • getBayerDither

        public static byte[] getBayerDither​(int matrix,
                                            int gray255,
                                            boolean doubleMatrix)
        Returns a byte array containing the dither pattern for the given 8-bit gray value.
        Parameters:
        matrix - the matrix size (DITHER_MATRIX_2X2, DITHER_MATRIX_4X4 or DITHER_MATRIX_8X8)
        gray255 - the gray value (0-255)
        doubleMatrix - true if the 4x4 matrix shall be doubled to a 8x8
        Returns:
        the dither pattern
      • getBayerDither

        public static byte[] getBayerDither​(int matrix,
                                            java.awt.Color col,
                                            boolean doubleMatrix)
        Returns a byte array containing the dither pattern for the given 8-bit gray value.
        Parameters:
        matrix - the matrix size (DITHER_MATRIX_2X2, DITHER_MATRIX_4X4 or DITHER_MATRIX_8X8)
        col - the color
        doubleMatrix - true if the 4x4 matrix shall be doubled to a 8x8
        Returns:
        the dither pattern