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;
	}