Esempio n. 1
0
        public void LevelDimensionsCorrect()
        {
            int width  = 32;
            int height = 32;

            Mipmap2D mipmap = new Mipmap2D(width, height, 1, 32);

            mipmap.GenerateMipmaps();

            Assert.AreEqual(6, mipmap.Levels);

            for (int i = 0; i < mipmap.Levels; i++)
            {
                TextureData2D data = mipmap.GetData(i);

                Assert.IsNotNull(data);
                Assert.AreEqual(mipmap.Channels, data.Channels);
                Assert.AreEqual(mipmap.BitDepth, data.BitDepth);
                Assert.AreEqual(width, data.GetWidth());
                Assert.AreEqual(height, data.GetHeight());

                width  /= 2;
                height /= 2;
            }
        }
Esempio n. 2
0
        public void Index16()
        {
            int width    = 64;
            int height   = 128;
            int channels = 3;
            int bitDepth = 16;

            TextureData2D data = TextureData2D.CreateData(width, height, channels, bitDepth);

            float[,,] arr = new float[width, height, channels];

            Random rnd = new Random(0);

            for (int y = 0; y < data.GetHeight(); y++)
            {
                for (int x = 0; x < data.GetWidth(); x++)
                {
                    for (int c = 0; c < data.Channels; c++)
                    {
                        short v = (short)rnd.Next(short.MinValue, short.MaxValue);
                        arr[x, y, c]  = v / (float)short.MaxValue;
                        data[x, y, c] = arr[x, y, c];
                    }
                }
            }

            EqualsWithError(arr, data, 1e-4f);
        }
Esempio n. 3
0
        public void Index32()
        {
            int width    = 64;
            int height   = 128;
            int channels = 3;
            int bitDepth = 32;

            TextureData2D data = TextureData2D.CreateData(width, height, channels, bitDepth);

            float[,,] arr = new float[width, height, channels];

            Random rnd = new Random(0);

            for (int y = 0; y < data.GetHeight(); y++)
            {
                for (int x = 0; x < data.GetWidth(); x++)
                {
                    for (int c = 0; c < data.Channels; c++)
                    {
                        arr[x, y, c]  = (float)rnd.NextDouble();
                        data[x, y, c] = arr[x, y, c];
                    }
                }
            }

            EqualsWithError(arr, data, 0);
        }
Esempio n. 4
0
        public Texture2D(TextureData2D data)
        {
            if (data.GetWidth() < 1)
            {
                throw new ArgumentException("Data width must be at least 1");
            }
            if (data.GetHeight() < 1)
            {
                throw new ArgumentException("Data height must be at least 1");
            }

            Data = data;
        }
Esempio n. 5
0
        private void CreateData(int width, int height, int channels, int bitDepth, TEXTURE_MIPMAP mode)
        {
            Data = null;

            if (mode != TEXTURE_MIPMAP.NONE)
            {
                Data = new Mipmap2D(width, height, channels, bitDepth, mode);
            }
            else
            {
                Data = TextureData2D.CreateData(width, height, channels, bitDepth);
            }
        }
Esempio n. 6
0
        public void  DimensionsCorrect()
        {
            int width    = 64;
            int height   = 128;
            int channels = 3;
            int bitDepth = 8;

            TextureData2D data = TextureData2D.CreateData(width, height, channels, bitDepth);

            Assert.AreEqual(width, data.GetWidth());
            Assert.AreEqual(height, data.GetHeight());
            Assert.AreEqual(channels, data.Channels);
        }
Esempio n. 7
0
 void EqualsWithError(float[,,] arr, TextureData2D data, float error)
 {
     for (int y = 0; y < data.GetHeight(); y++)
     {
         for (int x = 0; x < data.GetWidth(); x++)
         {
             for (int c = 0; c < data.Channels; c++)
             {
                 float diff = Math.Abs(arr[x, y, c] - data[x, y, c]);
                 Assert.IsTrue(diff <= error, arr[x, y, c] + " and " + data[x, y, c] + " have a error of " + diff);
             }
         }
     }
 }
Esempio n. 8
0
        public void  DataTypeCorrect()
        {
            int           width    = 512;
            int           height   = 128;
            int           channels = 3;
            TextureData2D data     = null;

            data = TextureData2D.CreateData(width, height, channels, 8);
            Assert.IsInstanceOfType(data, typeof(TextureData2D8));

            data = TextureData2D.CreateData(width, height, channels, 16);
            Assert.IsInstanceOfType(data, typeof(TextureData2D16));

            data = TextureData2D.CreateData(width, height, channels, 32);
            Assert.IsInstanceOfType(data, typeof(TextureData2D32));
        }
Esempio n. 9
0
        public void ApplyHorizontal(int y, TextureData2D src, float[] dst, int dstWidth)
        {
            int srcWidth = src.GetWidth();
            int channels = src.Channels;

            float scale  = Length / (float)srcWidth;
            float iscale = 1.0f / scale;
            int   idx;

            for (int i = 0; i < Length; i++)
            {
                float center = (0.5f + i) * iscale;

                int left = (int)Math.Floor(center - Width);

                for (int c = 0; c < channels; c++)
                {
                    float sum = 0;
                    for (int j = 0; j < WindowSize; ++j)
                    {
                        int x = j + left;

                        if (x < 0)
                        {
                            x = 0;
                        }
                        if (x >= srcWidth)
                        {
                            x = srcWidth - 1;
                        }

                        idx  = x + y * srcWidth;
                        sum += ValueAt(i, j) * src[x, y, c];
                    }

                    idx = i + y * dstWidth;
                    dst[idx * channels + c] = sum;
                }
            }
        }
Esempio n. 10
0
        public void ApplyVertical(int x, TextureData2D src, TextureData2D dst)
        {
            int srcHeight = src.GetHeight();
            int channels  = src.Channels;

            float scale  = Length / (float)srcHeight;
            float iscale = 1.0f / scale;

            for (int i = 0; i < Length; i++)
            {
                float center = (0.5f + i) * iscale;

                int left = (int)Math.Floor(center - Width);

                for (int c = 0; c < channels; c++)
                {
                    float sum = 0;
                    for (int j = 0; j < WindowSize; ++j)
                    {
                        int y = j + left;

                        if (y < 0)
                        {
                            y = 0;
                        }
                        if (y >= srcHeight)
                        {
                            y = srcHeight - 1;
                        }

                        sum += ValueAt(i, j) * src[x, y, c];
                    }

                    dst[x, i, c] = sum;
                }
            }
        }
Esempio n. 11
0
        public void ApplyVertical(int x, float[] src, int srcWidth, int srcHeight, int channels, TextureData2D dst)
        {
            int dstWidth = dst.GetWidth();

            float scale  = Length / (float)srcHeight;
            float iscale = 1.0f / scale;
            int   idx;

            for (int i = 0; i < Length; i++)
            {
                float center = (0.5f + i) * iscale;

                int left = (int)Math.Floor(center - Width);

                for (int c = 0; c < channels; c++)
                {
                    float sum = 0;
                    for (int j = 0; j < WindowSize; ++j)
                    {
                        int y = j + left;

                        if (y < 0)
                        {
                            y = 0;
                        }
                        if (y >= srcHeight)
                        {
                            y = srcHeight - 1;
                        }

                        idx  = x + y * srcWidth;
                        sum += ValueAt(i, j) * src[idx * channels + c];
                    }

                    idx          = x + i * dstWidth;
                    dst[x, i, c] = sum;
                }
            }
        }