src/main/java/com/mxgraph/util/png/mxPngImageEncoder.java
private mxPngEncodeParam.Gray createGrayParam(byte[] redPalette,
			byte[] greenPalette, byte[] bluePalette, byte[] alphaPalette)
	{
		mxPngEncodeParam.Gray param = new mxPngEncodeParam.Gray();
		int numTransparent = 0;

		int grayFactor = 255 / ((1 << bitDepth) - 1);
		int entries = 1 << bitDepth;
		for (int i = 0; i < entries; i++)
		{
			byte red = redPalette[i];
			if ((red != i * grayFactor) || (red != greenPalette[i])
					|| (red != bluePalette[i]))
			{
				return null;
			}

			// All alphas must be 255 except at most 1 can be 0
			byte alpha = alphaPalette[i];
			if (alpha == (byte) 0)
			{
				param.setTransparentGray(i);

				++numTransparent;
				if (numTransparent > 1)
				{
					return null;
				}
			}
			else if (alpha != (byte) 255)
			{
				return null;
			}
		}

		return param;
	}
/**
	 * Analyzes a set of palettes and determines if it can be expressed
	 * as a standard set of gray values, with zero or one values being
	 * fully transparent and the rest being fully opaque.  If it
	 * is possible to express the data thusly, the method returns
	 * a suitable instance of PNGEncodeParam.Gray; otherwise it
	 * returns null.
	 */
Analyzes a set of palettes and determines if it can be expressed
as a standard set of gray values, with zero or one values being
fully transparent and the rest being fully opaque.  If it
is possible to express the data thusly, the method returns
a suitable instance of PNGEncodeParam.Gray; otherwise it
returns null.
Analyzes a set of palettes and determines if it can be expressed as a standard set of gray values with zero or one values being fully transparent and the rest being fully opaque . If it is possible to express the data thusly the method returns a suitable instance of PNGEncodeParam . Gray ; otherwise it returns null .
private mxPngEncodeParam.Gray createGrayParam(byte[] redPalette,
			byte[] greenPalette, byte[] bluePalette, byte[] alphaPalette)
	{
		mxPngEncodeParam.Gray param = new mxPngEncodeParam.Gray();
		int numTransparent = 0;
		int grayFactor = 255 / ((1 << bitDepth) - 1);
		int entries = 1 << bitDepth;
		for (int i = 0; i < entries; i++)
		{
			byte red = redPalette[i];
			if ((red != i * grayFactor) || (red != greenPalette[i])
					|| (red != bluePalette[i]))
			{
				return null;
			}
			byte alpha = alphaPalette[i];
			if (alpha == (byte) 0)
			{
				param.setTransparentGray(i);
				++numTransparent;
				if (numTransparent > 1)
				{
					return null;
				}
			}
			else if (alpha != (byte) 255)
			{
				return null;
			}
		}
		return param;
	}
private mxPngEncodeParam . Gray createGrayParam ( byte [ ] redPalette , byte [ ] greenPalette , byte [ ] bluePalette , byte [ ] alphaPalette ) { mxPngEncodeParam . Gray param = new mxPngEncodeParam . Gray ( ) ; int numTransparent = 0 ; int grayFactor = 255 / ( ( 1 << bitDepth ) - 1 ) ; int entries = 1 << bitDepth ; for ( int i = 0 ; i < entries ; i ++ ) { byte red = redPalette [ i ] ; if ( ( red != i * grayFactor ) || ( red != greenPalette [ i ] ) || ( red != bluePalette [ i ] ) ) { return null ; } byte alpha = alphaPalette [ i ] ; if ( alpha == ( byte ) 0 ) { param . setTransparentGray ( i ) ; ++ numTransparent ; if ( numTransparent > 1 ) { return null ; } } else if ( alpha != ( byte ) 255 ) { return null ; } } return param ; }
Analyzes a set of palettes and determines if it can be expressed
 as a standard set of gray values, with zero or one values being
 fully transparent and the rest being fully opaque.
Analyzes a set of palettes and determines if it can be expressed as a standard set of gray values with zero or one values being fully transparent and the rest being fully opaque .
// All alphas must be 255 except at most 1 can be 0