Esempio n. 1
0
        public void TestRandomValues_i()
        {
            var rand = new System.Random();
            var buff = new Byte[8];

            for(Int32 i = 0; i < Settings.NumTests; ++i)
            {
                rand.NextBytes(buff);
                UInt64 packed = BitConverter.ToUInt64(buff, 0);
                var packedObj = new Rgba64();
                packedObj.PackedValue = packed;
                Single realR, realG, realB, realA = 0f;
                packedObj.UnpackTo(out realR, out realG, out realB, out realA);
                var newPackedObj = new Rgba64(realR, realG, realB, realA);
                Assert.That(newPackedObj.PackedValue, Is.EqualTo(packed));
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------
        /// <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;
        }
Esempio n. 3
0
        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.");
              }
        }
 private static int GetManhattanDistanceInRgbaSpace(ref Rgba64 a, ref Rgba64 b)
 {
     return(Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A));
 }
Esempio n. 5
0
        /// <summary>
        /// Collects a row of grayscale pixels.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="rowSpan">The image row span.</param>
        private void CollectGrayscaleBytes <TPixel>(ReadOnlySpan <TPixel> rowSpan)
            where TPixel : struct, IPixel <TPixel>
        {
            // Use ITU-R recommendation 709 to match libpng.
            const float RX = .2126F;
            const float GX = .7152F;
            const float BX = .0722F;
            Span <byte> rawScanlineSpan = this.rawScanline.GetSpan();

            if (this.pngColorType.Equals(PngColorType.Grayscale))
            {
                // TODO: Realistically we should support 1, 2, 4, 8, and 16 bit grayscale images.
                // we currently do the other types via palette. Maybe RC as I don't understand how the data is packed yet
                // for 1, 2, and 4 bit grayscale images.
                if (this.use16Bit)
                {
                    // 16 bit grayscale
                    Rgb48 rgb = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 2)
                    {
                        rowSpan[x].ToRgb48(ref rgb);
                        ushort luminance = (ushort)((RX * rgb.R) + (GX * rgb.G) + (BX * rgb.B));
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
                    }
                }
                else
                {
                    // 8 bit grayscale
                    Rgb24 rgb = default;
                    for (int x = 0; x < rowSpan.Length; x++)
                    {
                        rowSpan[x].ToRgb24(ref rgb);
                        rawScanlineSpan[x] = (byte)((RX * rgb.R) + (GX * rgb.G) + (BX * rgb.B));
                    }
                }
            }
            else
            {
                if (this.use16Bit)
                {
                    // 16 bit grayscale + alpha
                    Rgba64 rgba = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 4)
                    {
                        rowSpan[x].ToRgba64(ref rgba);
                        ushort luminance = (ushort)((RX * rgba.R) + (GX * rgba.G) + (BX * rgba.B));
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A);
                    }
                }
                else
                {
                    // 8 bit grayscale + alpha
                    Rgba32 rgba = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 2)
                    {
                        rowSpan[x].ToRgba32(ref rgba);
                        rawScanlineSpan[o]     = (byte)((RX * rgba.R) + (GX * rgba.G) + (BX * rgba.B));
                        rawScanlineSpan[o + 1] = rgba.A;
                    }
                }
            }
        }
Esempio n. 6
0
        private void generateRandTexture()
        {
            Random rand = new Random();

            //generate a random texture for initial particle locations and colors
            Rgba64[] pointsarray = new Rgba64[rootOrganismCount * rootOrganismCount];
            for (int i = 0; i < rootOrganismCount * rootOrganismCount; i++)
            {
                Vector4 temp = new Vector4(
                    (float)rand.NextDouble(),   //R
                    (float)rand.NextDouble(),   //G
                    (float)rand.NextDouble(),   //B
                    (float)rand.NextDouble()    //A
                );
                pointsarray[i] = new Rgba64(temp);
            }
            randomTexture.SetData<Rgba64>(pointsarray);
        }
Esempio n. 7
0
 public void FromRgba64(Rgba64 source) => this.FromScaledVector4(source.ToScaledVector4());
 /// <inheritdoc />
 public void FromRgba64(Rgba64 source)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 public Color(Rgba64 pixel) => this.data = pixel;
Esempio n. 10
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");
            }
        }
Esempio n. 11
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");
            }
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
 public PixelDifference(Point position, Rgba64 expected, Rgba64 actual) : this(position, actual.R - expected.R, actual.G - expected.G, actual.B - expected.B, actual.A - expected.A)
 {
 }
Esempio n. 14
0
        private Vector4 getFirstPixel(string label, Texture2D tex, bool print)
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, 1, 1);
            Rgba64[] retrievedColor = new Rgba64[1];
            tex.GetData<Rgba64>(
                0,
                sourceRectangle,
                retrievedColor,
                0,
                1);

            if(print)
                Console.WriteLine("{0,14} : {1}", label, retrievedColor[0].ToVector4());
            return retrievedColor[0].ToVector4();
        }
Esempio n. 15
0
 public void TestMemberFn_ToString_i()
 {
     var testCase = new Rgba64();
     testCase.PackFrom(0.656f, 0.125f, 0.222f, 0.861f);
     String s = testCase.ToString ();
     Assert.That(s, Is.EqualTo("DC6A38D52000A7EF"));
 }
Esempio n. 16
0
 public void FromRgba64(Rgba64 source)
 {
 }
Esempio n. 17
0
 public void TestMemberFn_GetHashCode_i ()
 {
     HashSet<Int32> hs = new HashSet<Int32>();
     var rand = new System.Random();
     var buff = new Byte[4];
     UInt32 collisions = 0;
     for(Int32 i = 0; i < Settings.NumTests; ++i)
     {
         rand.NextBytes(buff);
         UInt32 packed = BitConverter.ToUInt32(buff, 0);
         var packedObj = new Rgba64();
         packedObj.PackedValue = packed;
         Int32 hc = packedObj.GetHashCode ();
         if(hs.Contains(hc)) ++collisions;
         hs.Add(hc);
     }
     Assert.That(collisions, Is.LessThan(10));
 }
Esempio n. 18
0
 private Color(IPixel pixel)
 {
     this.boxedHighPrecisionPixel = pixel;
     this.data = default;
 }