Exemplo n.º 1
0
        public void TestConvertArgb32Image()
        {
            String imgPath0 = "..\\images\\yilagou_1280_720_24.jpg";
            Bitmap map      = new Bitmap(imgPath0);
            Color  c        = map.GetPixel(0, 0);

            Console.WriteLine(c.ToString());
            ImageArgb32 r  = new ImageArgb32(map);
            Argb32      cr = r[0, 0];

            Console.WriteLine(cr.ToString());
            Bitmap to = r.ToBitmap();
            Color  tc = to.GetPixel(0, 0);

            Console.WriteLine(tc.ToString());
            Assert.AreEqual(c.A, cr.Alpha);
            Assert.AreEqual(c.R, cr.Red);
            Assert.AreEqual(c.G, cr.Green);
            Assert.AreEqual(c.B, cr.Blue);
            Assert.AreEqual(c.R, tc.R);
            Assert.AreEqual(c.G, tc.G);
            Assert.AreEqual(c.B, tc.B);
        }
Exemplo n.º 2
0
        public void CloneAs_ToArgb32(TestImageProvider <Rgba32> provider)
        {
            using (Image <Rgba32> image = provider.GetImage())
                using (Image <Argb32> clone = image.CloneAs <Argb32>())
                {
                    for (int y = 0; y < image.Height; y++)
                    {
                        Span <Rgba32> row      = image.GetPixelRowSpan(y);
                        Span <Argb32> rowClone = clone.GetPixelRowSpan(y);

                        for (int x = 0; x < image.Width; x++)
                        {
                            Rgba32 expected = row[x];
                            Argb32 actual   = rowClone[x];

                            Assert.Equal(expected.R, actual.R);
                            Assert.Equal(expected.G, actual.G);
                            Assert.Equal(expected.B, actual.B);
                            Assert.Equal(expected.A, actual.A);
                        }
                    }
                }
        }
Exemplo n.º 3
0
 public void FromArgb32(Argb32 source) => this.FromScaledVector4(source.ToScaledVector4());
Exemplo n.º 4
0
 public void PackFromArgb32(Argb32 source)
 {
     PackedValue = FromLinearRgb(source.R, source.G, source.B);
 }
Exemplo n.º 5
0
 protected override Argb32 GetDeltaColor(Argb32 baseColor, Argb32 variantColor)
 {
     unchecked {
         return(new Argb32((byte)(variantColor.R - baseColor.R), (byte)(variantColor.G - baseColor.G), (byte)(variantColor.B - baseColor.B), (byte)(variantColor.A - baseColor.A)));
     }
 }
Exemplo n.º 6
0
 protected override Argb32 GetVariantColor(Argb32 baseColor, Argb32 deltaColor)
 {
     unchecked {
         return(new Argb32((byte)(baseColor.R + deltaColor.R), (byte)(baseColor.G + deltaColor.G), (byte)(baseColor.B + deltaColor.B), (byte)(baseColor.A + deltaColor.A)));
     }
 }
 protected override Argb32 GetVariantColor(Argb32 baseColor, Argb32 deltaColor) => deltaColor == new Argb32(0, 0, 0, 0) ? baseColor : deltaColor;
 protected override Argb32 GetDeltaColor(Argb32 baseColor, Argb32 variantColor) => baseColor == variantColor ? new Argb32(0, 0, 0, 0) : variantColor;
Exemplo n.º 9
0
 public void FromArgb32(Argb32 source)
 {
 }
Exemplo n.º 10
0
 public Color(Argb32 pixel)
 {
     this.data = new Rgba64(pixel);
     this.boxedHighPrecisionPixel = null;
 }
Exemplo n.º 11
0
 /// <inheritdoc />
 public void FromArgb32(Argb32 source)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
        // Create a screen from an image.
        public static Screen FromImage(Image <Argb32> img, bool optimizeGraphic, bool affine, bool is4Bpp, bool firstColorTransparent, bool isEnpg, int graphicWidthTiles, int graphicHeightTiles, int colorsPerPalette, Argb32?backgroundColor)
        {
            // TODO: ADD SUPPORT FOR OPTIMIZING THE GRAPHIC! (Identical tiles, flips, etc.)

            // Dimensions check.
            if (!optimizeGraphic)
            {
                if (img.Width != graphicWidthTiles * 8 || img.Height != graphicHeightTiles * 8)
                {
                    throw new Exception("Image size must be " + (graphicWidthTiles * 8) + "x" + (graphicHeightTiles * 8) + "!");
                }
            }
            else
            {
                if (img.Width % 8 != 0 || img.Height % 8 != 0)
                {
                    throw new Exception("Image size must be a multiple of 8 in both dimensions!");
                }
            }

            // Create stuff.
            Screen s = new Screen();

            s.Affine  = affine;
            s.Graphic = new Graphic();
            s.Graphic.FirstColorTransparent = firstColorTransparent;
            s.Graphic.Is4BPP            = is4Bpp;
            s.Graphic.IsEnpg            = isEnpg;
            s.Graphic.Tiles             = new Graphic.Tile[graphicWidthTiles, graphicHeightTiles];
            s.Graphic.Palette           = new Palette();
            s.Graphic.Palette.IndexSize = colorsPerPalette;

            // Take into account background/transparent color.
            bool oneLessColor        = backgroundColor != null || firstColorTransparent;
            int  numColorsToGenerate = colorsPerPalette;

            if (oneLessColor)
            {
                numColorsToGenerate--;
            }
            if (firstColorTransparent)
            {
                backgroundColor = new Argb32(0, 0, 0, 0);
            }

            // Get the graphic.
            int[,] newGraphic;
            s.Graphic.Palette.Colors = Palette.LimitColorPalette(img, numColorsToGenerate, backgroundColor, out newGraphic);
            if (oneLessColor)
            {
                s.Graphic.Palette.Colors.Insert(0, new RGB5(0));
            }
            for (int i = 0; i < graphicWidthTiles * 8; i++)
            {
                for (int j = 0; j < graphicHeightTiles * 8; j++)
                {
                    int tileX  = i / 8;
                    int tileY  = j / 8;
                    int pixelX = i % 8;
                    int pixelY = j % 8;
                    if (pixelX == 0 && pixelY == 0)
                    {
                        s.Graphic.Tiles[tileX, tileY] = new Graphic.Tile();
                    }
                    s.Graphic.Tiles[tileX, tileY].Colors[pixelX, pixelY] = (byte)newGraphic[i, j];
                }
            }
            var sTemp = Screen.GenerateDefault(s.Graphic);

            s.Tiles = sTemp.Tiles;
            while (s.Graphic.Palette.Colors.Count < s.Graphic.Palette.IndexSize)
            {
                s.Graphic.Palette.Colors.Add(new RGB5());
            }

            // Return the final screen.
            return(s);
        }
Exemplo n.º 13
0
 public void PackFromArgb32(Argb32 source)
 {
     this = FromRgba(source.R, source.G, source.B, source.A);
 }
Exemplo n.º 14
0
 public void PackFromArgb32(Argb32 source)
 => Pack(source.R, source.G, source.B);
Exemplo n.º 15
0
 protected abstract Argb32 GetVariantColor(Argb32 baseColor, Argb32 deltaColor);
Exemplo n.º 16
0
        public static void SaveMazeAsImageDeluxePng(InnerMap map, List <MazePointPos> pathPosjes, Stream stream)
        {
            pathPosjes.Sort((first, second) =>
            {
                if (first.Y == second.Y)
                {
                    return(first.X - second.X);
                }
                return(first.Y - second.Y);
            });


            int curpos = 0;

            var w     = Stopwatch.StartNew();
            var image = new Image <Argb32>(map.Width - 1, map.Height - 1);

            using (var pixels = image.Lock())
            {
                for (int y = 0; y < map.Height - 1; y++)
                {
                    for (int x = 0; x < map.Width - 1; x++)
                    {
                        int r = 0;
                        int g = 0;
                        int b = 0;

                        MazePointPos curPathPos;
                        if (curpos < pathPosjes.Count)
                        {
                            curPathPos = pathPosjes[curpos];
                            if (curPathPos.X == x && curPathPos.Y == y)
                            {
                                r = curPathPos.RelativePos;
                                g = 255 - curPathPos.RelativePos;
                                b = 0;
                                curpos++;
                            }
                            else if (map[x, y])
                            {
                                r = 255;
                                g = 255;
                                b = 255;
                            }
                        }
                        else if (map[x, y])
                        {
                            r = 255;
                            g = 255;
                            b = 255;
                        }
                        pixels[x, y] = new Argb32((byte)r, (byte)g, (byte)b);
                    }
                    //lineSavingProgress(y, this.Height - 2);
                }
            }
            var timeForFirstImageSavePart = w.Elapsed;

            w.Restart();

            var pngEncored = new PngEncoder();

            image.Save(stream, pngEncored, new PngEncoderOptions()
            {
                CompressionLevel = 9
            });
            //image.SaveAsPng(stream);
            var timeForSaveAsPng = w.Elapsed;

            Console.WriteLine($"First image conversion time: {timeForFirstImageSavePart}, Time for saving as PNG: {timeForSaveAsPng}");
        }