public unsafe void Convert_PixToBitmap(int depth, bool isGrayscale, bool includeAlpha)
        {
            if (!Directory.Exists(ResultsDirectory)) Directory.CreateDirectory(ResultsDirectory);

            bool hasPalette = depth < 16 && !isGrayscale;
            string pixType;
            if (isGrayscale) pixType = "grayscale";
            else if (hasPalette) pixType = "palette";
            else pixType = "rgb";

            var sourceFile = String.Format("photo_{0}_{1}bpp.tif", pixType, depth);
            var sourceFilePath = Path.Combine(DataDirectory, sourceFile);
            var converter = new PixToBitmapConverter();
            using (var source = Pix.LoadFromFile(sourceFilePath)) {
                Assert.That(source.Depth, Is.EqualTo(depth));
                if (hasPalette) {
                    Assert.That(source.Colormap, Is.Not.Null, "Expected source image to have color map\\palette.");
                } else {
                    Assert.That(source.Colormap, Is.Null, "Expected source image to be grayscale.");
                }
                using (var dest = converter.Convert(source, includeAlpha)) {
                    var destFilename = String.Format("PixToBitmap_{0}_{1}bpp.tif", pixType, depth);
                    dest.Save(Path.Combine(ResultsDirectory, destFilename), System.Drawing.Imaging.ImageFormat.Tiff);

                    AssertAreEquivalent(dest, source, includeAlpha);
                }
            }
        }
        public unsafe void Convert_PixToBitmap(
            [Values("photo.jpg", "photo.bmp", "photo_8.bmp", "photo_24.bmp", "photo.png", "photo_8.png", "photo_24.png", "photo_32.png", "photo.tif", "photo.gif")]
            string sourceFile,
            [Values(true, false)]
            bool includeAlpha)
        {
            var sourceFilePath = Path.Combine(DataDirectory, sourceFile);
            var converter = new PixToBitmapConverter();
            using (var source = Pix.LoadFromFile(sourceFilePath)) {
                using (var dest = converter.Convert(source, includeAlpha)) {
                    AssertAreEquivalent(dest, source, includeAlpha);

                   // dest.Save("converted_pix.bmp");
                }
            }
        }
Exemple #3
0
        public unsafe void Convert_PixToBitmap(int depth, bool isGrayscale, bool includeAlpha)
        {
            if (!Directory.Exists(ResultsDirectory))
            {
                Directory.CreateDirectory(ResultsDirectory);
            }

            bool   hasPalette = depth < 16 && !isGrayscale;
            string pixType;

            if (isGrayscale)
            {
                pixType = "grayscale";
            }
            else if (hasPalette)
            {
                pixType = "palette";
            }
            else
            {
                pixType = "rgb";
            }

            var sourceFile     = String.Format("photo_{0}_{1}bpp.tif", pixType, depth);
            var sourceFilePath = Path.Combine(DataDirectory, sourceFile);
            var converter      = new PixToBitmapConverter();

            using (var source = Pix.LoadFromFile(sourceFilePath)) {
                Assert.That(source.Depth, Is.EqualTo(depth));
                if (hasPalette)
                {
                    Assert.That(source.Colormap, Is.Not.Null, "Expected source image to have color map\\palette.");
                }
                else
                {
                    Assert.That(source.Colormap, Is.Null, "Expected source image to be grayscale.");
                }
                using (var dest = converter.Convert(source, includeAlpha)) {
                    var destFilename = String.Format("PixToBitmap_{0}_{1}bpp.tif", pixType, depth);
                    dest.Save(Path.Combine(ResultsDirectory, destFilename), System.Drawing.Imaging.ImageFormat.Tiff);

                    AssertAreEquivalent(dest, source, includeAlpha);
                }
            }
        }
        public unsafe void Convert_PixToBitmap(int depth, bool isGrayscale, bool includeAlpha)
        {
            var    hasPalette = depth < 16 && !isGrayscale;
            string pixType;

            if (isGrayscale)
            {
                pixType = "grayscale";
            }
            else if (hasPalette)
            {
                pixType = "palette";
            }
            else
            {
                pixType = "rgb";
            }

            var sourceFile = TestFilePath(string.Format("Conversion/photo_{0}_{1}bpp.tif", pixType, depth));
            var converter  = new PixToBitmapConverter();

            using (var source = Pix.LoadFromFile(sourceFile))
            {
                Assert.AreEqual(source.Depth, depth);
                if (hasPalette)
                {
                    Assert.IsNotNull(source.Colormap, "Expected source image to have color map\\palette.");
                }
                else
                {
                    Assert.IsNull(source.Colormap, "Expected source image to be grayscale.");
                }
                using (var dest = converter.Convert(source, includeAlpha))
                {
                    var destFilename = TestResultRunFile(string.Format("Conversion/PixToBitmap_{0}_{1}bpp.tif", pixType, depth));
                    dest.Save(destFilename, System.Drawing.Imaging.ImageFormat.Tiff);

                    AssertAreEquivalent(dest, source, includeAlpha);
                }
            }
        }
 /// <summary>
 /// Converts the specified <paramref name="pix"/> to a Bitmap.
 /// </summary>
 /// <param name="pix">The source image to be converted.</param>
 /// <returns>The converted pix as a <see cref="Bitmap"/>.</returns>
 public static Bitmap ToBitmap(Pix pix)
 {
     return(pixConverter.Convert(pix));
 }