public void QueryResolutionRpclTest() { int resolutions = _rpclCodestream.DecompositionLevels + 1; PreciseQuery q = PreciseQuery.Create(_queryContext); IEnumerable <PacketInterval>[] intervals = new IEnumerable <PacketInterval> [resolutions]; for (int r = 0; r < resolutions; r++) { intervals[r] = q.Resolution(r).Execute(); } int packetStart = 0; int layersMulComps = _rpclCodestream.QualityLayers * _rpclCodestream.Components; for (int r = 0; r < resolutions; r++) { int packetsInResolution = layersMulComps; // NOTE TO SELF: I can calculate everything // programatically, but then I would duplicate // the code that I need to test, and may // have two places with possible bugs. PacketInterval[] ivals = intervals[r].ToArray(); Assert.AreEqual(ivals.Length, 1); PacketInterval ival = ivals[0]; var cod = _rpclCodestream.Markers[MarkerType.COD] as CodMarker; int precinctsInRes = GetPrecinctsInResolution(r, cod); packetsInResolution *= precinctsInRes; Assert.AreEqual(packetStart, ival.PacketStart); Assert.AreEqual(packetsInResolution, ival.Count); packetStart += packetsInResolution; } }
public void QueryResolutionLrcpTest() { int resIdx = 1; int precinctsInResolution = 1; int layers = 2; int components = 3; int resolutions = 3; int packetsInLayerResolution = precinctsInResolution * components; int packetsInLayer = packetsInLayerResolution * resolutions; int expectedStartInLayer = resIdx * packetsInLayerResolution; int[] expectedStarts = new int[layers]; for (int ly = 0; ly < layers; ly++) { expectedStarts[ly] = ly * packetsInLayer; expectedStarts[ly] += expectedStartInLayer; } PreciseQuery q = PreciseQuery.Create(_queryContext); PacketInterval[] intervals = q .Resolution(resIdx) .Execute() .ToArray(); Assert.AreEqual(intervals.Length, layers); for (int ly = 0; ly < layers; ly++) { Assert.AreEqual(intervals[ly].PacketStart, expectedStarts[ly]); Assert.AreEqual(intervals[ly].Count, packetsInLayerResolution); } }
private void CopyTileResLevel(JP2Codestream dst, JP2Codestream src, ushort tIdx, int r) { int decomps = src.DecompositionLevels; var dstTilePart = dst.CreateTilePart(tIdx, r == decomps); // get all packets for this resolution level and source tile // currently support only a single tile in source image for every // destination tile. QueryContext queryContext = new QueryContext(src, 0); PreciseQuery preciseQuery = PreciseQuery.Create(queryContext); var intervals = preciseQuery .Resolution(r) .Execute(); JP2Tile srcTile = src.Tiles[0]; // add packet lengths Func <JP2TilePart, int, int, int, int> addPacketLengths = (tpSrc, pckStart, pckCount, voidParam) => { var lengths = tpSrc.GetPacketLengths(pckStart, pckCount); dstTilePart.AddPacketLengths(lengths); return(voidParam); }; EnumerateIntervals <int>(intervals, srcTile, addPacketLengths); // bulk transfer packet data dstTilePart.Flush(); byte[] buffer = new byte[1 << 16]; Func <JP2TilePart, int, int, uint, uint> bulkTransfer = (tpSrc, pckStart, pckCount, dstOffset) => { uint dataCount = JP2TilePart.BulkTransferData( dstTilePart, dstOffset, tpSrc, pckStart, pckCount, buffer); return(dstOffset + dataCount); }; EnumerateIntervals <uint>( intervals, srcTile, bulkTransfer); dstTilePart.Close(); srcTile.Close(); }