Ejemplo n.º 1
0
        public void Signed9Bit()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 9;
            int  highBit         = 8;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            pixelData[0] = 255;
            pixelData[1] = 1;

            int actualValue = pixelDataWrapper.GetPixel(0, 0);

            Assert.AreEqual(-1, actualValue);

            int expectedValue = -1;

            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = -256;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = 255;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);

            expectedValue = 0;
            pixelDataWrapper.SetPixel(0, 0, expectedValue);
            actualValue = pixelDataWrapper.GetPixel(0, 0);
            Assert.AreEqual(expectedValue, actualValue);
        }
Ejemplo n.º 2
0
        public void ForEachPixel()
        {
            int  columns         = 5;
            int  rows            = 4;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int i = 0;

            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    pixelDataWrapper.SetPixel(x, y, i);
                    i++;
                }
            }

            int left = 1, top = 1, right = 3, bottom = 3;

            int pixelCount = 0;

            pixelDataWrapper.ForEachPixel(left, top, right, bottom,
                                          delegate(int j, int x, int y, int pixelIndex)
            {
                if (j == 0)
                {
                    Assert.AreEqual(6, pixelDataWrapper.GetPixel(pixelIndex));
                }
                else if (j == 1)
                {
                    Assert.AreEqual(7, pixelDataWrapper.GetPixel(pixelIndex));
                }
                else if (j == 3)
                {
                    Assert.AreEqual(11, pixelDataWrapper.GetPixel(pixelIndex));
                }

                pixelCount++;
            });

            Assert.AreEqual(9, pixelCount);
        }
Ejemplo n.º 3
0
        public void SetPixelSigned16()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            // Test the API
            int testValue = -1234;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            // Make sure it works with unsafe code too
            fixed(byte *pPixelData = pixelDataWrapper.Raw)
            {
                short *pShortPixelData = (short *)pPixelData;
                int    i = y * columns + x;

                actualValue = pShortPixelData[i];
            }

            Assert.AreEqual(testValue, actualValue);
        }
Ejemplo n.º 4
0
        public void SetPixelUnsigned8()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 8;
            int  bitsStored      = 8;
            int  highBit         = 7;
            bool isSigned        = false;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            int testValue = 0xab;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            // Make sure it works with unsafe code too
            fixed(byte *pPixelData = pixelDataWrapper.Raw)
            {
                int i = y * columns + x;

                actualValue = pPixelData[i];
            }

            Assert.AreEqual(testValue, actualValue);
        }
Ejemplo n.º 5
0
        public void SetPixelSigned16Grayscale()
        {
            int  columns         = 7;
            int  rows            = 19;
            int  bitsAllocated   = 16;
            int  bitsStored      = 16;
            int  highBit         = 15;
            bool isSigned        = true;
            int  samplesPerPixel = 1;
            int  imageSize       = columns * rows * bitsAllocated / 8 * samplesPerPixel;

            byte[] pixelData = new byte[imageSize];

            PixelData pixelDataWrapper = new GrayscalePixelData(
                rows,
                columns,
                bitsAllocated,
                bitsStored,
                highBit,
                isSigned,
                pixelData);

            int x = 3;
            int y = 4;

            // Test the API
            int testValue = -1234;

            pixelDataWrapper.SetPixel(x, y, testValue);
            int actualValue = pixelDataWrapper.GetPixel(x, y);

            Assert.AreEqual(testValue, actualValue);

            int index = y * columns + x;

            actualValue = pixelDataWrapper.GetPixel(index);
            Assert.AreEqual(testValue, actualValue);
        }