コード例 #1
0
        public void Rg32()
        {
            // Test the limits.
            Assert.AreEqual(0x0, new Rg32(Vector2.Zero).PackedValue);
            Assert.AreEqual(0xFFFFFFFF, new Rg32(Vector2.One).PackedValue);

            // Test ToVector2
            Assert.AreEqual(Vector2.Zero, new Rg32(Vector2.Zero).ToVector2());
            Assert.AreEqual(Vector2.One, new Rg32(Vector2.One).ToVector2());

            // Test clamping.
            Assert.AreEqual(Vector2.Zero, new Rg32(Vector2.One * -1234.0f).ToVector2());
            Assert.AreEqual(Vector2.One, new Rg32(Vector2.One * 1234.0f).ToVector2());

            //Test Ordering
            float x = 0xb6dc;
            float y = 0xA59f;

            Assert.AreEqual(0xa59fb6dc, new Rg32(x / 0xffff, y / 0xffff).PackedValue);
            x = 0.1f;
            y = -0.3f;
            Assert.AreEqual(6554, new Rg32(x, y).PackedValue);

            var packed   = new Rg32(x, y).PackedValue;
            var unpacked = new Rg32()
            {
                PackedValue = packed
            }.ToVector2();

            Assert.AreEqual(x, unpacked.X, 0.01f);
            Assert.AreEqual(0f, unpacked.Y);
        }
コード例 #2
0
        public void Rg32()
        {
            // Test the limits.
            Assert.Equal((uint)0x0, new Rg32(Vector2.Zero).PackedValue);
            Assert.Equal(0xFFFFFFFF, new Rg32(Vector2.One).PackedValue);

            // Test ToVector2
            Assert.True(Equal(Vector2.Zero, new Rg32(Vector2.Zero).ToVector2()));
            Assert.True(Equal(Vector2.One, new Rg32(Vector2.One).ToVector2()));

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

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

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

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

            // Test clamping.
            Assert.True(Equal(Vector2.Zero, new Rg32(Vector2.One * -1234.0f).ToVector2()));
            Assert.True(Equal(Vector2.One, new Rg32(Vector2.One * 1234.0f).ToVector2()));

            // Test Ordering
            float x = 0xb6dc;
            float y = 0xA59f;

            Assert.Equal(0xa59fb6dc, new Rg32(x / 0xffff, y / 0xffff).PackedValue);
            x = 0.1f;
            y = -0.3f;
            Assert.Equal((uint)6554, new Rg32(x, y).PackedValue);

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

            new Rg32(x, y).ToRgb24(ref rgb);
            Assert.Equal(rgb, new Rgb24(25, 0, 0));

            new Rg32(x, y).ToRgba32(ref rgba);
            Assert.Equal(rgba, new Rgba32(25, 0, 0, 255));

            new Rg32(x, y).ToBgr24(ref bgr);
            Assert.Equal(bgr, new Bgr24(25, 0, 0));

            new Rg32(x, y).ToBgra32(ref bgra);
            Assert.Equal(bgra, new Bgra32(25, 0, 0, 255));
        }
コード例 #3
0
        public void Rg32_FromBgra5551()
        {
            // arrange
            var  rg32     = new Rg32(Vector2.One);
            uint expected = 0xFFFFFFFF;

            // act
            rg32.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));

            // assert
            Assert.Equal(expected, rg32.PackedValue);
        }
コード例 #4
0
        public void Rg32_ToRgba32()
        {
            // arrange
            var rg32     = new Rg32(0.1f, -0.3f);
            var actual   = default(Rgba32);
            var expected = new Rgba32(25, 0, 0, 255);

            // act
            rg32.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void Rg32_ToBgr24()
        {
            // arrange
            var rg32     = new Rg32(0.1f, -0.3f);
            var actual   = default(Bgr24);
            var expected = new Bgr24(25, 0, 0);

            // act
            rg32.ToBgr24(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public void Rg32_ToScaledVector4()
        {
            // arrange
            var rg32 = new Rg32(Vector2.One);

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

            // assert
            Assert.Equal(1, actual.X);
            Assert.Equal(1, actual.Y);
            Assert.Equal(0, actual.Z);
            Assert.Equal(1, actual.W);
        }
コード例 #7
0
        public void Rg32_FromScaledVector4()
        {
            // arrange
            var  rg32     = new Rg32(Vector2.One);
            var  pixel    = default(Rg32);
            uint expected = 0xFFFFFFFF;

            // act
            Vector4 scaled = rg32.ToScaledVector4();

            pixel.FromScaledVector4(scaled);
            uint actual = pixel.PackedValue;

            // assert
            Assert.Equal(expected, actual);
        }
コード例 #8
0
ファイル: Fudge.Tests.cs プロジェクト: gitter-badger/blimey
 public void TestMemberFn_ToString_i()
 {
     var testCase = new Rg32();
     testCase.PackFrom(0.222f, 0.861f);
     String s = testCase.ToString ();
     Assert.That(s, Is.EqualTo("DC6A38D5"));
 }
コード例 #9
0
ファイル: Fudge.Tests.cs プロジェクト: gitter-badger/blimey
        public void TestRandomValues_i()
        {
            var rand = new System.Random();
            var buff = new Byte[4];

            for(Int32 i = 0; i < Settings.NumTests; ++i)
            {
                rand.NextBytes(buff);
                UInt32 packed = BitConverter.ToUInt32(buff, 0);
                var packedObj = new Rg32();
                packedObj.PackedValue = packed;
                Single realR, realG = 0f;
                packedObj.UnpackTo(out realR, out realG);
                var newPackedObj = new Rg32(realR, realG);
                Assert.That(newPackedObj.PackedValue, Is.EqualTo(packed));
            }
        }
コード例 #10
0
ファイル: TerrainHelper.cs プロジェクト: Zolniu/DigitalRune
        public static void SetTextureLevel(Texture2D texture, int level, float[] data)
        {
            if (texture == null)
            throw new ArgumentNullException("texture");
              if (data == null)
            throw new ArgumentNullException("data");

              if (texture.Format == SurfaceFormat.Alpha8)
              {
            var buffer = new byte[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = (byte)(data[i] * 255.0f);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Color)
              {
            var buffer = new Color[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Color(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Rg32)
              {
            var buffer = new Rg32[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Rg32(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Rgba64)
              {
            var buffer = new Rgba64[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Rgba64(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Single)
              {
            texture.SetData(level, null, data, 0, data.Length);
              }
              else if (texture.Format == SurfaceFormat.Vector2)
              {
            var buffer = new Vector2[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Vector2(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.Vector4)
              {
            var buffer = new Vector4[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new Vector4(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfSingle)
              {
            var buffer = new HalfSingle[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfSingle(data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfVector2)
              {
            var buffer = new HalfVector2[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfVector2(data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else if (texture.Format == SurfaceFormat.HalfVector4)
              {
            var buffer = new HalfVector4[data.Length];
            for (int i = 0; i < buffer.Length; i++)
              buffer[i] = new HalfVector4(data[i], data[i], data[i], data[i]);
            texture.SetData(level, null, buffer, 0, buffer.Length);
              }
              else
              {
            throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported.");
              }
        }
コード例 #11
0
ファイル: TerrainHelper.cs プロジェクト: Zolniu/DigitalRune
        //--------------------------------------------------------------
        /// <summary>
        /// Gets the texture data of the specified mipmap level as a <see cref="Vector4"/> array.
        /// </summary>
        /// <param name="texture">The texture.</param>
        /// <param name="level">The mipmap level to read. Currently only 0 is supported!</param>
        /// <returns>
        /// The array containing the data of the specified mipmap level.
        /// (One <see cref="Vector4"/> element per pixel.)
        /// </returns>
        /// <remarks>
        /// <para>
        /// This method can be used with following texture surface formats:
        /// <see cref="SurfaceFormat.Alpha8"/>, <see cref="SurfaceFormat.Color"/>, 
        /// <see cref="SurfaceFormat.Rg32"/>, <see cref="SurfaceFormat.Rgba64"/>,
        /// <see cref="SurfaceFormat.Single"/>, <see cref="SurfaceFormat.Vector2"/>,
        /// <see cref="SurfaceFormat.Vector4"/>, <see cref="SurfaceFormat.HalfSingle"/>,
        /// <see cref="SurfaceFormat.HalfVector2"/>, <see cref="SurfaceFormat.HalfVector4"/>
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="texture"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="NotImplementedException">
        /// Invalid mipmap level. Extracting mipmap levels other than 0 is not yet implemented.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// Texture format is not yet supported.
        /// </exception>
        public static Vector4[] GetTextureLevelVector4(Texture2D texture, int level)
        {
            if (texture == null)
            throw new ArgumentNullException("texture");
              if (level < 0)
            throw new ArgumentOutOfRangeException("level");
              if (level > 0)
            throw new NotImplementedException("GetTextureLevelVector4 for levels other than 0 is not yet implemented.");

              var bufferLevel0 = new Vector4[texture.Width * texture.Height];

              if (texture.Format == SurfaceFormat.Alpha8)
              {
            var buffer = new byte[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(0, 0, 0, buffer[i] / 255.0f);
              }
              else if (texture.Format == SurfaceFormat.Color)
              {
            var buffer = new Color[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else if (texture.Format == SurfaceFormat.Rg32)
              {
            var buffer = new Rg32[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
            {
              var v = buffer[i].ToVector2();
              bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0);
            }
              }
              else if (texture.Format == SurfaceFormat.Rgba64)
              {
            var buffer = new Rgba64[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else if (texture.Format == SurfaceFormat.Single)
              {
            var buffer = new Single[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i]);
              }
              else if (texture.Format == SurfaceFormat.Vector2)
              {
            var buffer = new Vector2[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i].X, buffer[i].Y, 0, 0);
              }
              else if (texture.Format == SurfaceFormat.Vector4)
              {
            texture.GetData(bufferLevel0);
              }
              else if (texture.Format == SurfaceFormat.HalfSingle)
              {
            var buffer = new HalfSingle[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = new Vector4(buffer[i].ToSingle(), 0, 0, 0);
              }
              else if (texture.Format == SurfaceFormat.HalfVector2)
              {
            var buffer = new HalfVector2[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
            {
              var v = buffer[i].ToVector2();
              bufferLevel0[i] = new Vector4(v.X, v.Y, 0, 0);
            }
              }
              else if (texture.Format == SurfaceFormat.HalfVector4)
              {
            var buffer = new HalfVector4[bufferLevel0.Length];
            texture.GetData(buffer);
            for (int i = 0; i < buffer.Length; i++)
              bufferLevel0[i] = buffer[i].ToVector4();
              }
              else
              {
            throw new NotSupportedException("Texture format '" + texture.Format + "' is not yet supported.");
              }

              return bufferLevel0;
        }
コード例 #12
0
ファイル: PngWriter.cs プロジェクト: Cardanis/MonoGame
        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");
            }
        }
コード例 #13
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");
            }
        }
コード例 #14
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);
        }
コード例 #15
0
ファイル: Game1.cs プロジェクト: luqui/luqui-misc
        private void ReloadDistortionMap()
        {
            if (euclideanMap != null) { euclideanMap.Dispose(); }
            euclideanMap = new Texture2D(graphics.GraphicsDevice, Tweaks.DISTORTION_RESX, Tweaks.DISTORTION_RESY, 0, TextureUsage.None, SurfaceFormat.Rg32);
            Vector2[,] mapData = metric.getEuclideanMap(new Vector2(-0.3f, -0.3f), new Vector2(1.3f, 1.3f), Tweaks.DISTORTION_RESX, Tweaks.DISTORTION_RESY, Tweaks.DISTORTION_RESX / 2, Tweaks.DISTORTION_RESY / 2, new Vector2(0.5f, 0.5f));
            Rg32[] pixBuffer = new Rg32[Tweaks.DISTORTION_RESX * Tweaks.DISTORTION_RESY];
            int ix = 0;
            for (int j = 0; j < Tweaks.DISTORTION_RESX; j++) {
                for (int i = 0; i < Tweaks.DISTORTION_RESY; i++) {
                    pixBuffer[ix] = new Rg32(mapData[i, j].X, mapData[i, j].Y);
                    ix++;
                }
            }

            euclideanMap.SetData(pixBuffer);
        }