Beispiel #1
0
        public void AreNotEqual()
        {
            var color1 = new Bgra4444(0.0f, 0.0f, 0.0f, 0.0f);
            var color2 = new Bgra4444(new Vector4(1.0f));
            var color3 = new Bgra4444(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            var color4 = new Bgra4444(1.0f, 1.0f, 0.0f, 1.0f);

            Assert.NotEqual(color1, color2);
            Assert.NotEqual(color3, color4);
        }
Beispiel #2
0
        public void Bgra4444_ToRgba32()
        {
            // arrange
            var bgra     = new Bgra4444(Vector4.One);
            var expected = new Rgba32(Vector4.One);
            var actual   = default(Rgba32);

            // act
            bgra.ToRgba32(ref actual);

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void Bgra4444_ToRgba32()
        {
            // arrange
            var bgra     = new Bgra4444(0.1f, -0.3f, 0.5f, -0.7f);
            var actual   = default(Rgba32);
            var expected = new Rgba32(34, 0, 136, 0);

            // act
            bgra.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public void Bgra4444_ToBgr24()
        {
            // arrange
            var bgra     = new Bgra4444(0.1f, -0.3f, 0.5f, -0.7f);
            var actual   = default(Bgr24);
            var expected = new Bgr24(34, 0, 136);

            // act
            bgra.ToBgr24(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void Bgra4444_FromScaledVector4()
        {
            // arrange
            Vector4 scaled   = new Bgra4444(Vector4.One).ToScaledVector4();
            int     expected = 0xFFFF;
            var     bgra     = default(Bgra4444);

            // act
            bgra.FromScaledVector4(scaled);
            ushort actual = bgra.PackedValue;

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void Bgra4444_ToScaledVector4()
        {
            // arrange
            var bgra = new Bgra4444(Vector4.One);

            // act
            Vector4 actual = bgra.ToScaledVector4();

            // assert
            Assert.Equal(1, actual.X);
            Assert.Equal(1, actual.Y);
            Assert.Equal(1, actual.Z);
            Assert.Equal(1, actual.W);
        }
Beispiel #7
0
        public void Bgra4444()
        {
            // Test the limits.
            Assert.AreEqual(0x0, new Bgra4444(Vector4.Zero).PackedValue);
            Assert.AreEqual(0xFFFF, new Bgra4444(Vector4.One).PackedValue);

            // Test ToVector4.
            Assert.AreEqual(Vector4.One, new Bgra4444(Vector4.One).ToVector4());
            Assert.AreEqual(Vector4.Zero, new Bgra4444(Vector4.Zero).ToVector4());
            Assert.AreEqual(Vector4.UnitX, new Bgra4444(Vector4.UnitX).ToVector4());
            Assert.AreEqual(Vector4.UnitY, new Bgra4444(Vector4.UnitY).ToVector4());
            Assert.AreEqual(Vector4.UnitZ, new Bgra4444(Vector4.UnitZ).ToVector4());
            Assert.AreEqual(Vector4.UnitW, new Bgra4444(Vector4.UnitW).ToVector4());

            // Test clamping.
            Assert.AreEqual(Vector4.Zero, new Bgra4444(Vector4.One * -1234.0f).ToVector4());
            Assert.AreEqual(Vector4.One, new Bgra4444(Vector4.One * 1234.0f).ToVector4());

            // Make sure the swizzle is correct.
            Assert.AreEqual(0x0F00, new Bgra4444(Vector4.UnitX).PackedValue);
            Assert.AreEqual(0x00F0, new Bgra4444(Vector4.UnitY).PackedValue);
            Assert.AreEqual(0x000F, new Bgra4444(Vector4.UnitZ).PackedValue);
            Assert.AreEqual(0xF000, new Bgra4444(Vector4.UnitW).PackedValue);

            float x = 0.1f;
            float y = -0.3f;
            float z = 0.5f;
            float w = -0.7f;

            Assert.AreEqual(520, new Bgra4444(x, y, z, w).PackedValue);

            var packed   = new Bgra4444(x, y, z, w).PackedValue;
            var unpacked = new Bgra4444()
            {
                PackedValue = packed
            }.ToVector4();

            Assert.AreEqual(0.13f, unpacked.X, 0.01f);
            Assert.AreEqual(0f, unpacked.Y);
            Assert.AreEqual(0.53f, unpacked.Z, 0.01f);
            Assert.AreEqual(0f, unpacked.W);
        }
Beispiel #8
0
    private Image <Bgra4444> DecodeFont(IBinaryStream reader)
    {
        // from https://github.com/vn-tools/arc_unpacker/issues/54
        IsFontAtlas = true;

        var data         = reader.ReadBytesExact(_alignedWidth * _alignedHeight * 2);
        var encodedWidth = Width;

        Width *= 4;
        var encodedHeight = Height;
        var pixels        = new Bgra4444[Width * Height];

        foreach (var i in Range(_alignedWidth * _alignedHeight))
        {
            var absX = GetX(i, _alignedWidth, 2);
            var absY = GetY(i, _alignedWidth, 2);
            if (absX >= encodedWidth || absY >= encodedHeight)
            {
                continue;
            }

            var src = i * 2;

            var blockX     = (absX / BlockSize) * BlockSize;
            var blockY     = (absY / BlockSize) * BlockSize;
            var x          = absX % BlockSize;
            var y          = absY % BlockSize;
            var targetY    = blockY + y;
            var targetBase = blockX * 4 + x + targetY * Width;
            var target1    = targetBase;
            var target2    = targetBase + BlockSize;
            var target3    = targetBase + BlockSize * 2;
            var target4    = targetBase + BlockSize * 3;

            pixels[target1].PackedValue = (ushort)(0x0FFFu | ((data[src] >> 4) << 12));
            pixels[target2].PackedValue = (ushort)(0x0FFFu | ((data[src] & 0xF) << 12));
            pixels[target3].PackedValue = (ushort)(0x0FFFu | ((data[src + 1] >> 4) << 12));
            pixels[target4].PackedValue = (ushort)(0x0FFFu | ((data[src + 1] & 0xF) << 12));
        }
        return(Image.LoadPixelData(pixels, Width, Height));
    }
        public void Bgra4444()
        {
            // Test the limits.
            Assert.Equal(0x0, new Bgra4444(Vector4.Zero).PackedValue);
            Assert.Equal(0xFFFF, new Bgra4444(Vector4.One).PackedValue);

            // Test ToVector4.
            Assert.True(Equal(Vector4.One, new Bgra4444(Vector4.One).ToVector4()));
            Assert.True(Equal(Vector4.Zero, new Bgra4444(Vector4.Zero).ToVector4()));
            Assert.True(Equal(Vector4.UnitX, new Bgra4444(Vector4.UnitX).ToVector4()));
            Assert.True(Equal(Vector4.UnitY, new Bgra4444(Vector4.UnitY).ToVector4()));
            Assert.True(Equal(Vector4.UnitZ, new Bgra4444(Vector4.UnitZ).ToVector4()));
            Assert.True(Equal(Vector4.UnitW, new Bgra4444(Vector4.UnitW).ToVector4()));

            // Test ToScaledVector4.
            Vector4 scaled = new Bgra4444(Vector4.One).ToScaledVector4();

            Assert.Equal(1, scaled.X);
            Assert.Equal(1, scaled.Y);
            Assert.Equal(1, scaled.Z);
            Assert.Equal(1, scaled.W);

            // Test PackFromScaledVector4.
            var pixel = default(Bgra4444);

            pixel.PackFromScaledVector4(scaled);
            Assert.Equal(0xFFFF, pixel.PackedValue);

            // Test clamping.
            Assert.True(Equal(Vector4.Zero, new Bgra4444(Vector4.One * -1234.0f).ToVector4()));
            Assert.True(Equal(Vector4.One, new Bgra4444(Vector4.One * 1234.0f).ToVector4()));

            // Make sure the swizzle is correct.
            Assert.Equal(0x0F00, new Bgra4444(Vector4.UnitX).PackedValue);
            Assert.Equal(0x00F0, new Bgra4444(Vector4.UnitY).PackedValue);
            Assert.Equal(0x000F, new Bgra4444(Vector4.UnitZ).PackedValue);
            Assert.Equal(0xF000, new Bgra4444(Vector4.UnitW).PackedValue);

            float x = 0.1f;
            float y = -0.3f;
            float z = 0.5f;
            float w = -0.7f;

            Assert.Equal(520, new Bgra4444(x, y, z, w).PackedValue);

            // Test ordering
            var rgb  = default(Rgb24);
            var rgba = default(Rgba32);
            var bgr  = default(Bgr24);
            var bgra = default(Bgra32);

            new Bgra4444(x, y, z, w).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(34, 0, 136));

            new Bgra4444(x, y, z, w).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(34, 0, 136, 0));

            new Bgra4444(x, y, z, w).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(34, 0, 136));

            new Bgra4444(x, y, z, w).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(34, 0, 136, 0));
        }
Beispiel #10
0
        private void GetColorData(Texture2D texture2D)
        {
            int colorDataLength = texture2D.Width * texture2D.Height;
            colorData = new Color[colorDataLength];

            switch (texture2D.Format)
            {
                case SurfaceFormat.Color:
                    texture2D.GetData<Color>(colorData);
                    break;

                case SurfaceFormat.Alpha8:
                    var alpha8Data = new Alpha8[colorDataLength];
                    texture2D.GetData<Alpha8>(alpha8Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)alpha8Data[i]).ToVector4());
                    }

                    break;
                
                case SurfaceFormat.Bgr565:
                    var bgr565Data = new Bgr565[colorDataLength];
                    texture2D.GetData<Bgr565>(bgr565Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgr565Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Bgra4444:
                    var bgra4444Data = new Bgra4444[colorDataLength];
                    texture2D.GetData<Bgra4444>(bgra4444Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgra4444Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Bgra5551:
                    var bgra5551Data = new Bgra5551[colorDataLength];
                    texture2D.GetData<Bgra5551>(bgra5551Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)bgra5551Data[i]).ToVector4());
                    }
                    break;

                case SurfaceFormat.HalfSingle:
                    var halfSingleData = new HalfSingle[colorDataLength];
                    texture2D.GetData<HalfSingle>(halfSingleData);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfSingleData[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.HalfVector2:
                    var halfVector2Data = new HalfVector2[colorDataLength];
                    texture2D.GetData<HalfVector2>(halfVector2Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfVector2Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.HalfVector4:
                    var halfVector4Data = new HalfVector4[colorDataLength];
                    texture2D.GetData<HalfVector4>(halfVector4Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)halfVector4Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.NormalizedByte2:
                    var normalizedByte2Data = new NormalizedByte2[colorDataLength];
                    texture2D.GetData<NormalizedByte2>(normalizedByte2Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)normalizedByte2Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.NormalizedByte4:
                    var normalizedByte4Data = new NormalizedByte4[colorDataLength];
                    texture2D.GetData<NormalizedByte4>(normalizedByte4Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)normalizedByte4Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rg32:
                    var rg32Data = new Rg32[colorDataLength];
                    texture2D.GetData<Rg32>(rg32Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rg32Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rgba64:
                    var rgba64Data = new Rgba64[colorDataLength];
                    texture2D.GetData<Rgba64>(rgba64Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rgba64Data[i]).ToVector4());
                    }

                    break;

                case SurfaceFormat.Rgba1010102:
                    var rgba1010102Data = new Rgba1010102[colorDataLength];
                    texture2D.GetData<Rgba1010102>(rgba1010102Data);

                    for (int i = 0; i < colorDataLength; i++)
                    {
                        colorData[i] = new Color(((IPackedVector)rgba1010102Data[i]).ToVector4());
                    }

                    break;

                default:
                    throw new Exception("Texture surface format not supported");
            }
        }
Beispiel #11
0
        private void GetColorData(Texture2D texture2D)
        {
            int colorDataLength = texture2D.Width * texture2D.Height;

            colorData = new Color[colorDataLength];

            switch (texture2D.Format)
            {
            case SurfaceFormat.Single:
                var floatData = new float[colorDataLength];
                texture2D.GetData <float>(floatData);

                for (int i = 0; i < colorDataLength; i++)
                {
                    float brightness = floatData[i];
                    // Export as a greyscale image.
                    colorData[i] = new Color(brightness, brightness, brightness);
                }
                break;

            case SurfaceFormat.Color:
                texture2D.GetData <Color>(colorData);
                break;

            case SurfaceFormat.Alpha8:
                var alpha8Data = new Alpha8[colorDataLength];
                texture2D.GetData <Alpha8>(alpha8Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)alpha8Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Bgr565:
                var bgr565Data = new Bgr565[colorDataLength];
                texture2D.GetData <Bgr565>(bgr565Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)bgr565Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Bgra4444:
                var bgra4444Data = new Bgra4444[colorDataLength];
                texture2D.GetData <Bgra4444>(bgra4444Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)bgra4444Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Bgra5551:
                var bgra5551Data = new Bgra5551[colorDataLength];
                texture2D.GetData <Bgra5551>(bgra5551Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)bgra5551Data[i]).ToVector4());
                }
                break;

            case SurfaceFormat.HalfSingle:
                var halfSingleData = new HalfSingle[colorDataLength];
                texture2D.GetData <HalfSingle>(halfSingleData);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)halfSingleData[i]).ToVector4());
                }

                break;

            case SurfaceFormat.HalfVector2:
                var halfVector2Data = new HalfVector2[colorDataLength];
                texture2D.GetData <HalfVector2>(halfVector2Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)halfVector2Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.HalfVector4:
                var halfVector4Data = new HalfVector4[colorDataLength];
                texture2D.GetData <HalfVector4>(halfVector4Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)halfVector4Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.NormalizedByte2:
                var normalizedByte2Data = new NormalizedByte2[colorDataLength];
                texture2D.GetData <NormalizedByte2>(normalizedByte2Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)normalizedByte2Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.NormalizedByte4:
                var normalizedByte4Data = new NormalizedByte4[colorDataLength];
                texture2D.GetData <NormalizedByte4>(normalizedByte4Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)normalizedByte4Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Rg32:
                var rg32Data = new Rg32[colorDataLength];
                texture2D.GetData <Rg32>(rg32Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)rg32Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Rgba64:
                var rgba64Data = new Rgba64[colorDataLength];
                texture2D.GetData <Rgba64>(rgba64Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)rgba64Data[i]).ToVector4());
                }

                break;

            case SurfaceFormat.Rgba1010102:
                var rgba1010102Data = new Rgba1010102[colorDataLength];
                texture2D.GetData <Rgba1010102>(rgba1010102Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(((IPackedVector)rgba1010102Data[i]).ToVector4());
                }

                break;

            default:
                throw new Exception("Texture surface format not supported");
            }
        }
Beispiel #12
0
        public Frame AssignFrames(int i)
        {
            iSizeX = 1;
            iSizeY = 1;

            Vector2 center;

            Frame frame;

            Color[] masterI = new Color[iSizeX * iSizeY];

            bool   hasLine  = true;
            bool   hasShade = true;
            bool   hasColor = true;
            int    setNum   = 1;
            string name     = "";

            if (fileName[i].EndsWith("_colors.pcx") || fileName[i].EndsWith("_colors.png"))
            {
                name = fileName[i].Remove(fileName[i].Length - 11);
            }
            else if (fileName[i].EndsWith("_colors2.pcx") || fileName[i].EndsWith("_colors2.png"))
            {
                name   = fileName[i].Remove(fileName[i].Length - 12);
                setNum = 2;
            }
            else if (fileName[i].EndsWith("_colors3.pcx") || fileName[i].EndsWith("_colors3.png"))
            {
                name   = fileName[i].Remove(fileName[i].Length - 12);
                setNum = 3;
            }

            //Determine when a color2 is taken in.
            if (setNum == 2)
            {
                if (File.Exists(path + name + "_colors2.pcx"))
                {
                    AssignImage(ref masterI, 2, path, name, "_colors2.pcx");
                }
                else if (File.Exists(path + name + "_colors2.png"))
                {
                    AssignImage(ref masterI, 2, path, name, "_colors2.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_colors2 NOT FOUND");
                    hasColor = false;
                }

                if (File.Exists(path + name + "_lines2.pcx"))
                {
                    AssignImage(ref masterI, 1, path, name, "_lines2.pcx");
                }
                else if (File.Exists(path + name + "_lines2.png"))
                {
                    AssignImage(ref masterI, 1, path, name, "_lines2.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_lines2 NOT FOUND");
                    hasLine = false;
                }

                if (File.Exists(path + name + "_shade2.pcx"))
                {
                    AssignImage(ref masterI, 3, path, name, "_shade2.pcx");
                }
                else if (File.Exists(path + name + "_shade2.png"))
                {
                    AssignImage(ref masterI, 3, path, name, "_shade2.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_shade2 NOT FOUND");
                    hasShade = false;
                }

                if (File.Exists(path + name + "_dye2.pcx"))
                {
                    AssignImage(ref masterI, 4, path, name, "_dye2.pcx");
                }
                else if (File.Exists(path + name + "_dye2.png"))
                {
                    AssignImage(ref masterI, 4, path, name, "_dye2.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_dye2 NOT FOUND");
                }
            }
            else
            {
                if (File.Exists(path + name + "_colors.pcx"))
                {
                    AssignImage(ref masterI, 2, path, name, "_colors.pcx");
                }
                else if (File.Exists(path + name + "_colors.png"))
                {
                    AssignImage(ref masterI, 2, path, name, "_colors.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_colors NOT FOUND");
                    hasColor = false;
                }

                if (File.Exists(path + name + "_lines.pcx"))
                {
                    AssignImage(ref masterI, 1, path, name, "_lines.pcx");
                }
                else if (File.Exists(path + name + "_lines.png"))
                {
                    AssignImage(ref masterI, 1, path, name, "_lines.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_lines NOT FOUND");
                    hasLine = false;
                }

                if (File.Exists(path + name + "_shade.pcx"))
                {
                    AssignImage(ref masterI, 3, path, name, "_shade.pcx");
                }
                else if (File.Exists(path + name + "_shade.png"))
                {
                    AssignImage(ref masterI, 3, path, name, "_shade.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_shade NOT FOUND");
                    hasShade = false;
                }

                if (File.Exists(path + name + "_dye.pcx"))
                {
                    AssignImage(ref masterI, 4, path, name, "_dye.pcx");
                }
                else if (File.Exists(path + name + "_dye.png"))
                {
                    AssignImage(ref masterI, 4, path, name, "_dye.png");
                }
                else
                {
                    Console.WriteLine("FILE " + fileName[i] + "_dye NOT FOUND");
                }
            }

            if (!hasColor)
            {
                for (int c = 0; c < masterI.Length; c++)
                {
                    masterI[c].G = 255;
                }
            }
            if (!hasLine)
            {
                for (int c = 0; c < masterI.Length; c++)
                {
                    masterI[c].R = 255;
                }
            }
            if (!hasShade)
            {
                for (int c = 0; c < masterI.Length; c++)
                {
                    masterI[c].B = 0;
                }
            }

            if (!txtFile)
            {
                frameRate.Add(4);
            }
            if (!frmFile)
            {
                frameCenter.Add(new Vector2((int)iSizeX / 2, (int)iSizeY * .9f));
            }

            //Size it
            if (iSizeX > 1 || iSizeY > 1)
            {
                if (spriteSize > 1)
                {
                    HalfSizeImage(ref masterI);
                    frameCenter[i] = new Vector2((int)(frameCenter[i].X / spriteSize), (int)(frameCenter[i].Y / spriteSize));
                }
            }

            //Create a Texture2D
            center = frameCenter[i];
            CropImage(ref masterI, ref center);
            frameCenter[i] = center;

            Texture2D textureOut;

            int swap = 1;

            if (swap == 0)
            {
                Bgra4444[] mBGRA = new Bgra4444[masterI.Length];
                for (int m = 0; m < masterI.Length; m++)
                {
                    float b = (masterI[m].B + 1) / 2;
                    float g = (masterI[m].G + 1) / 2;
                    float r = (masterI[m].R + 1) / 2;
                    mBGRA[m] = new Bgra4444(r, g, b, 0);
                }
                textureOut = new Texture2D(lGraphics.GraphicsDevice, iSizeX, iSizeY, false, SurfaceFormat.Bgra4444);
                textureOut.SetData(mBGRA);
            }
            else
            {
                textureOut = new Texture2D(lGraphics.GraphicsDevice, iSizeX, iSizeY, false, SurfaceFormat.Color);
                textureOut.SetData(masterI);
            }
            //SaveToPNG(textureOut, path + "..\\out\\", fileName[i] + "_merged.png");

            masterI = null;
            iSizeX  = 1;
            iSizeY  = 1;

            frame = new Frame(name, frameCenter[i], frameRate[i], hasColor, hasLine, hasShade, textureOut);
            return(frame);
        }
Beispiel #13
0
        internal Color[] GetColorData()
        {
            int colorDataLength = Width * Height;
            var colorData       = new Color[colorDataLength];

            switch (Format)
            {
            case SurfaceFormat.Single:
                var floatData = new float[colorDataLength];
                GetData(floatData);

                for (int i = 0; i < colorDataLength; i++)
                {
                    float brightness = floatData[i];
                    // Export as a greyscale image.
                    colorData[i] = new Color(brightness, brightness, brightness);
                }
                break;

            case SurfaceFormat.Color:
                GetData(colorData);
                break;

            case SurfaceFormat.Alpha8:
                var alpha8Data = new Alpha8[colorDataLength];
                GetData(alpha8Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(alpha8Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Bgr565:
                var bgr565Data = new Bgr565[colorDataLength];
                GetData(bgr565Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(bgr565Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Bgra4444:
                var bgra4444Data = new Bgra4444[colorDataLength];
                GetData(bgra4444Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(bgra4444Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Bgra5551:
                var bgra5551Data = new Bgra5551[colorDataLength];
                GetData(bgra5551Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(bgra5551Data[i].ToVector4());
                }
                break;

            case SurfaceFormat.HalfSingle:
                var halfSingleData = new HalfSingle[colorDataLength];
                GetData(halfSingleData);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(halfSingleData[i].ToVector4());
                }

                break;

            case SurfaceFormat.HalfVector2:
                var halfVector2Data = new HalfVector2[colorDataLength];
                GetData(halfVector2Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(halfVector2Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.HalfVector4:
                var halfVector4Data = new HalfVector4[colorDataLength];
                GetData(halfVector4Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(halfVector4Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.NormalizedByte2:
                var normalizedByte2Data = new NormalizedByte2[colorDataLength];
                GetData(normalizedByte2Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(normalizedByte2Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.NormalizedByte4:
                var normalizedByte4Data = new NormalizedByte4[colorDataLength];
                GetData(normalizedByte4Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(normalizedByte4Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Rg32:
                var rg32Data = new Rg32[colorDataLength];
                GetData(rg32Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(rg32Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Rgba64:
                var rgba64Data = new Rgba64[colorDataLength];
                GetData(rgba64Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(rgba64Data[i].ToVector4());
                }

                break;

            case SurfaceFormat.Rgba1010102:
                var rgba1010102Data = new Rgba1010102[colorDataLength];
                GetData(rgba1010102Data);

                for (int i = 0; i < colorDataLength; i++)
                {
                    colorData[i] = new Color(rgba1010102Data[i].ToVector4());
                }

                break;

            default:
                throw new Exception("Texture surface format not supported");
            }

            return(colorData);
        }