Пример #1
0
        public void CompareMainHeaderMarkers()
        {
            // Test to see if the SIZ, COD and QCD markers
            // for the source image and the destination image
            // are equal.
            _mem.Seek(0, SeekOrigin.Begin);
            var csout = Jp2File.Open(_mem).OpenCodestream();

            _fs.Seek(_csin.Position, SeekOrigin.Begin);
            _mem.Seek(csout.Position, SeekOrigin.Begin);

            var segmentsIn  = ReadSegments(_fs);
            var segmentsOut = ReadSegments(_mem);

            Assert.IsTrue(segmentsIn.ContainsKey((ushort)MarkerType.SIZ));
            Assert.IsTrue(segmentsOut.ContainsKey((ushort)MarkerType.SIZ));
            Assert.IsTrue(segmentsIn.ContainsKey((ushort)MarkerType.COD));
            Assert.IsTrue(segmentsOut.ContainsKey((ushort)MarkerType.COD));
            Assert.IsTrue(segmentsIn.ContainsKey((ushort)MarkerType.QCD));
            Assert.IsTrue(segmentsOut.ContainsKey((ushort)MarkerType.QCD));

            byte[] sizin  = segmentsIn[(ushort)MarkerType.SIZ];
            byte[] sizout = segmentsOut[(ushort)MarkerType.SIZ];
            byte[] codin  = segmentsIn[(ushort)MarkerType.COD];
            byte[] codout = segmentsOut[(ushort)MarkerType.COD];
            byte[] qcdin  = segmentsIn[(ushort)MarkerType.QCD];
            byte[] qcdout = segmentsOut[(ushort)MarkerType.QCD];

            Assert.IsTrue(sizin.SequenceEqual(sizout));
            Assert.IsTrue(codin.SequenceEqual(codout));
            Assert.IsTrue(qcdin.SequenceEqual(qcdout));
        }
Пример #2
0
        private void Run()
        {
            ThrowIfHasInnerTiles(_firstCodestream);
            ThrowIfTooManyTiles();

            SizMarker siz = GetDestSiz();
            // Lets generate a tile-part for each tile-resolution in the source images
            int       tiles             = _imageCount.Width * _imageCount.Height;
            int       expectedTileParts = tiles * (_firstCodestream.DecompositionLevels + 1);
            CodMarker cod = _firstCodestream.Markers[MarkerType.COD] as CodMarker;
            QcdMarker qcd = _firstCodestream.Markers[MarkerType.QCD] as QcdMarker;

            WarnIfClipped(_firstCodestream, cod);
            ComMarker com     = new ComMarker("https://github.com/plroit/Skyreach");
            var       markers = new List <MarkerSegment>()
            {
                siz, cod, qcd, com
            };
            Jp2File dst = Jp2File.Create(
                markers,
                expectedTileParts,
                false,
                _dest);

            for (ushort tIdx = 0; tIdx < tiles; tIdx++)
            {
                CopyTile(tIdx, dst);
            }
            dst.Flush();
        }
Пример #3
0
        public void CopyTilePartTest()
        {
            _mem.Seek(0, SeekOrigin.Begin);
            var tpout = Jp2File
                        .Open(_mem)
                        .OpenCodestream()
                        .OpenTilePart(0, 0);
            var tpin = _jp2.OpenCodestream().OpenTilePart(0, 0);

            Assert.AreEqual(tpin.FirstChildOffset, tpout.FirstChildOffset);
            Assert.AreEqual(tpin.TotalPacketLength, tpout.TotalPacketLength);
            // lets check if SOT and PLT markers are the same

            _mem.Seek(tpout.Position, SeekOrigin.Begin);
            _fs.Seek(tpin.Position, SeekOrigin.Begin);

            int totalCount = (int)tpin.FirstChildOffset;

            // compare SOT and PLT markers
            CompareStreams(totalCount);
            // compare packet content
            _mem.Seek(tpout.Position + tpout.FirstChildOffset,
                      SeekOrigin.Begin);
            _fs.Seek(tpin.Position + tpin.FirstChildOffset,
                     SeekOrigin.Begin);
            CompareStreams((int)tpin.TotalPacketLength);
        }
Пример #4
0
        public void Initialize()
        {
            string testFile = "test_LRtCP_L2R3T512.jp2";

            _lrcpStream     = File.OpenRead(testFile);
            _lrcpCodestream = Jp2File.Open(_lrcpStream).OpenCodestream();
            _queryContext   = new QueryContext(_lrcpCodestream, _tileIdx);
        }
Пример #5
0
        public void Initialize()
        {
            _mem = new MemoryStream();
            _fs  = File.OpenRead("test.jp2");
            _jp2 = Jp2File.Open(_fs);

            CopyImage();
        }
Пример #6
0
        public void Initialize()
        {
            string testFile = "test_RtPCL_L4R5P128T200.jp2";

            _rpclStream     = File.OpenRead(testFile);
            _rpclCodestream = Jp2File.Open(_rpclStream).OpenCodestream();
            _queryContext   = new QueryContext(_rpclCodestream, _tileIdx);
        }
Пример #7
0
 private Jp2File OpenJp2(int idx)
 {
     if (_jp2s[idx] == null)
     {
         _jp2s[idx] = Jp2File.Open(OpenStream(idx));
     }
     return(_jp2s[idx]);
 }
Пример #8
0
        private void CopyTile(ushort tIdx, Jp2File dstJp2)
        {
            JP2Codestream src = OpenJp2(tIdx).OpenCodestream();
            JP2Codestream dst = dstJp2.OpenCodestream();

            ThrowIfDifferentInputs(_firstCodestream, src);
            for (int r = 0; r <= src.DecompositionLevels; r++)
            {
                CopyTileResLevel(dst, src, tIdx, r);
            }
        }
Пример #9
0
 private static Jp2File Open(
     int idx,
     string[] paths,
     Jp2File[] jp2Files)
 {
     if (jp2Files[idx] == null)
     {
         Stream stream = new FileStream(
             paths[idx],
             FileMode.Open,
             FileAccess.Read,
             FileShare.Read,
             1 << 14);
         jp2Files[idx] = Jp2File.Open(stream);
     }
     return(jp2Files[idx]);
 }
Пример #10
0
        public void ReadBackPacketLengths()
        {
            // Test if the packet lengths we have
            // copied from the source tile-part, and written
            // into the destination tile-part, can be now
            // read back from the destination stream.
            // The source and destination packet lengths
            // should be equal
            _mem.Seek(0, SeekOrigin.Begin);
            var tpout = Jp2File.Open(_mem)
                        .OpenCodestream()
                        .OpenTilePart(0, 0);
            var lengthsOut = tpout.GetPacketLengths(
                0, tpout.Packets);
            var tpin      = _csin.OpenTilePart(0, 0);
            var lengthsIn = tpin.GetPacketLengths(
                0, tpin.Packets);
            bool seqEq = lengthsOut.SequenceEqual(lengthsIn);

            Assert.IsTrue(seqEq);
        }
Пример #11
0
        public void OpenImage()
        {
            Jp2File jp2 = Jp2File.Open(_fs);

            Assert.IsNotNull(jp2);
            JP2Codestream cs = jp2.OpenCodestream();

            Assert.IsNotNull(cs);
            Assert.IsNull(cs.Parent);
            Assert.AreEqual <Size>(cs.ImageSize, Image.Default.ImageSize);
            Assert.AreEqual <Size>(cs.TileSize, Image.Default.ImageSize);
            Assert.AreEqual(cs.TileCount, new Size(1, 1));
            Assert.AreEqual(cs.Components, Image.Default.Components);
            Assert.AreEqual(cs.Progression, Image.Default.Progression);
            Assert.AreEqual(cs.ImageOffset, Point.Empty);
            Assert.AreEqual(cs.TileOffset, Point.Empty);
            Assert.AreEqual(cs.DecompositionLevels, Image.Default.Decompositions);
            Assert.AreEqual(cs.QualityLayers, 1);

            int tileparts = cs.OpenChildren().Count();

            Assert.AreEqual(1, tileparts);

            _fs.Seek(0, SeekOrigin.Begin);
            long socOffset = Find(_fs, (ushort)MarkerType.SOC);
            long sizOffset = Find(_fs, (ushort)MarkerType.SIZ);
            long sotOffset = Find(_fs, (ushort)MarkerType.SOT);
            long sodOffset = Find(_fs, (ushort)MarkerType.SOD);
            long eocOffset = Find(_fs, (ushort)MarkerType.EOC);

            Assert.AreEqual(socOffset, cs.Position);
            Assert.AreEqual(sizOffset, cs.Position + 2);
            Assert.AreEqual(sotOffset, cs.Position + cs.FirstChildOffset);
            long sodOffsetFromCs = cs.Position + cs.FirstChildOffset;

            sodOffsetFromCs += cs.OpenTilePart(0, 0).FirstChildOffset - 2;
            Assert.AreEqual(sodOffset, sodOffsetFromCs);
            Assert.AreEqual(eocOffset, cs.Position + cs.Length - 2);
        }
Пример #12
0
        public void Initialize()
        {
            _fs   = File.OpenRead("test.jp2");
            _mem  = new MemoryStream();
            _csin = Jp2File.Open(_fs).OpenCodestream();
            var siz   = _csin.Markers[MarkerType.SIZ] as SizMarker;
            var cod   = _csin.Markers[MarkerType.COD] as CodMarker;
            var qcd   = _csin.Markers[MarkerType.QCD] as QcdMarker;
            var tpin  = _csin.OpenTilePart(0, 0);
            var csout = new JP2Codestream(new List <MarkerSegment>()
            {
                siz, cod, qcd
            }, 1);

            csout.Bind(_mem, 0);
            var tpout   = csout.CreateTilePart(0, true);
            var lengths = tpin.GetPacketLengths(0, tpin.Packets);

            tpout.AddPacketLengths(lengths);
            tpout.Flush();
            csout.Flush();
            _mem.Seek(0, SeekOrigin.Begin);
        }
Пример #13
0
 public void Initialize()
 {
     _fs  = File.OpenRead("test_LRtCP_L2R3T512.jp2");
     _jp2 = Jp2File.Open(_fs);
     _cs  = _jp2.OpenCodestream();
 }