private static void DitherCalculateAndSave(DitheringBase method, Bitmap input, string filenameWithoutExtension) { Bitmap dithered = method.DoDithering(input); double mse = CalculateMSE(input, dithered); double psrn = CalculatePSRN(mse); Console.WriteLine("Method: " + method.GetMethodName() + " PSRN: " + psrn); dithered.Save(filenameWithoutExtension + method.GetFilenameAddition() + ".png"); }
private static void DitherCalculateAndSave(DitheringBase method, Bitmap input, string filenameWithoutExtension) { Bitmap dithered = method.DoDithering(input); double mse = CalculateMSE(input, dithered); double psrn = CalculatePSRN(mse); Console.WriteLine("Method: " + method.GetMethodName() + " PSRN: " + psrn); dithered.Save(filenameWithoutExtension + method.GetFilenameAddition() + ".png"); }
public static void DitherAndWritePngStream(Stream outputStream, Bitmap bitmap, DitheringBase <byte> ditherer, bool writeToSameBitmap = true) { byte[] bytes = ReadWriteBitmaps.ReadBitmapToColorBytes(bitmap); TempByteImageFormat temp = new TempByteImageFormat(bytes, bitmap.Width, bitmap.Height, 3); temp = (TempByteImageFormat)ditherer.DoDithering(temp); if (writeToSameBitmap) { ReadWriteBitmaps.WriteToBitmap(bitmap, temp.GetPixelChannels); bitmap.Save(outputStream, System.Drawing.Imaging.ImageFormat.Png); } else { Bitmap tempBitmap = new Bitmap(bitmap.Width, bitmap.Height, bitmap.PixelFormat); ReadWriteBitmaps.WriteToBitmap(tempBitmap, temp.GetPixelChannels); tempBitmap.Save(outputStream, System.Drawing.Imaging.ImageFormat.Png); } }
private static DitheringBase <byte> GetDitherer(DitheringMethod method, DitheringBase <byte> .ColorFunction colorfunc) => method switch {
public static Bitmap DitherCalculate(DitheringBase method, Bitmap input) { Bitmap dithered = method.DoDithering(input); return(dithered); }
private static (long checksum, int colorCount) DoDitheringAndGetChecksumAndColorCount(DitheringBase <byte> dithering, Bitmap bitmap) { using (var image = bitmap) { byte[,,] bytes = ReadTo3DBytes(image); TempByteImageFormat temp = new TempByteImageFormat(bytes); dithering.DoDithering(temp); WriteToBitmap(image, temp.GetPixelChannels); //image.Save("temp123.png"); return(GetImageTotalPixelSum(image), CountTotalColors(image)); } }