public static int GetMinimumColorDepthForDisplay(Image <Rgba32> image) { if (IsAnyPartialTransparency(image)) { return(32); } if (!IsAnyPixel(image, (x, y, pixel) => !IsBlack(pixel) && !IsWhite(pixel))) { return(1); } var bpc = new NumBitsPerChannel(); ForeachPixel(image, (x, y, pixel) => UpdateNumBitsPerChannel(pixel, bpc)); if (bpc.RgbLessThan(2)) { return(3 * 1); } if (bpc.RgbLessThan(3)) { return(3 * 2); } if (bpc.RgbLessThan(5)) { return(3 * 3); } return(3 * 4); }
public static BitmapEncoding GetIdealBitmapEncoding(Image <Rgba32> image, bool hasIcoMask) { if (IsAnyPartialTransparency(image)) { return(BitmapEncoding.Pixel_argb32); } var numColors = GetNumberOfDistinctColors(image, !hasIcoMask); if (numColors <= 2) { return(BitmapEncoding.Pixel_indexed1); } if (numColors <= 4) { return(BitmapEncoding.Pixel_indexed2); } if (numColors <= 16) { return(BitmapEncoding.Pixel_indexed4); } if (numColors <= 256) { return(BitmapEncoding.Pixel_indexed8); } var bpc = new NumBitsPerChannel(); ForeachPixel(image, (x, y, pixel) => UpdateNumBitsPerChannel(pixel, bpc)); if (hasIcoMask || !IsAnyAlphaChannel(image)) { if (bpc.RgbLessThan(6)) { return(BitmapEncoding.Pixel_rgb15); } return(BitmapEncoding.Pixel_rgb24); } return(BitmapEncoding.Pixel_argb32); }