Example #1
0
        public void TestCreateOverlayData_16BitsAllocated()
        {
            // 1 frame, 5x3
            // 11111
            // 10010
            // 00000
            // continuous bit stream: 11111100 1000000x
            // continuous LE byte stream: 00111111 x0000001

            const string expectedResult = "111111001000000";
            var          overlayPixels  = SwapBytes(new byte[]
            {
                // column1 |   column2 |   column3 |   column4 |   column5
                0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
                0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
            });                                             // written here in big endian for easy reading

            // little endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, 12, 16, 15, false, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, false).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 16-bit case (little endian)");
            }

            // big endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, 12, 16, 15, true, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, true).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 16-bit case (big endian)");
            }
        }
Example #2
0
        public void TestCreateOverlayData_16BitsAllocatedWithJunk()
        {
            // 1 frame, 5x3
            // 11111
            // 10010
            // 00000
            // continuous bit stream: 11111100 1000000x
            // continuous LE byte stream: 00111111 x0000001

            const string expectedResult = "111111001000000";

            // simulating the junk by specifying that we're using the middle 8 bits and the first and last 4 bits are to be ignored
            var overlayPixels = SwapBytes(new byte[]
            {
                // column1 |   column2 |   column3 |   column4 |   column5
                0x09, 0x10, 0x09, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00, 0x10,
                0x00, 0x10, 0x80, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0F, 0x00, 0x00
            });                                             // written here in big endian for easy reading

            // little endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, 8, 16, 11, false, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, false).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 16-bit w/junk case (little endian)");
            }

            // big endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, 8, 16, 11, true, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, true).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 16-bit w/junk case (big endian)");
            }
        }
Example #3
0
        public void TestCreateOverlayData_8BitsAllocated()
        {
            // 1 frame, 5x3
            // 11111
            // 10010
            // 00000
            // continuous bit stream: 11111100 1000000x
            // continuous LE byte stream: 00111111 x0000001

            const string expectedResult = "111111001000000";
            var          overlayPixels  = new byte[]
            {
                0x10, 0x10, 0x10, 0x10, 0x10,
                0x10, 0x00, 0x00, 0x10, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00
            };

            // little endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, false, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, false).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 8-bit case (little endian)");
            }

            // big endian test
            {
                var packedBits   = OverlayData.CreateOverlayData(3, 5, true, overlayPixels).Raw;
                var actualResult = FormatBits(packedBits, true).Substring(0, 15);
                Assert.AreEqual(expectedResult, actualResult, "Error in packed bits for 8-bit case (big endian)");
            }
        }
        /// <summary>
        /// Creates a packed overlay data object from the contents of this overlay plane.
        /// </summary>
        /// <param name="bigEndianWords">A value indciating if the packed overlay data should be encoded as 16-bit words with big endian byte ordering.</param>
        /// <returns>A packed overlay data object.</returns>
        public OverlayData CreateOverlayData(bool bigEndianWords)
        {
            if (_overlayGraphic == null)
            {
                return(null);
            }

            GrayscalePixelData pixelData = _overlayGraphic.PixelData;

            return(OverlayData.CreateOverlayData(
                       pixelData.Rows, pixelData.Columns,
                       pixelData.BitsStored,
                       pixelData.BitsAllocated,
                       pixelData.HighBit,
                       bigEndianWords,
                       pixelData.Raw));
        }