public void Setup() { this.tilingProfile = new AbsoluteDateTilingProfile( "Filename", "Tile", new DateTimeOffset(2015, 04, 10, 0, 0, 0, TimeSpan.FromHours(10)), 256, 60); this.tilingProfileNotRoundStart = new AbsoluteDateTilingProfile( "Filename", "Tile", this.dateTimeOffset, 256, 60); this.outputDirectory = PathHelper.GetTempDir(); this.tiler = new Tiler( this.outputDirectory.ToDirectoryEntry(), this.tilingProfile, new SortedSet <double>() { 60.0 }, 60.0, 1440, new SortedSet <double>() { 1 }, 1.0, 256); }
public void TestNamingPattern() { var profile = new AbsoluteDateTilingProfile("Basename", "Tag", this.dateTimeOffset, 256, 300); Assert.AreEqual("Basename__Tag_20150409T173015.123Z_60", profile.GetFileBaseName(this.tiler.CalculatedLayers, this.tiler.CalculatedLayers.First(), new Point(0, 0))); var profile2 = new AbsoluteDateTilingProfile(string.Empty, "Tag", this.dateTimeOffset, 256, 300); Assert.AreEqual("Tag_20150409T173015.123Z_60", profile2.GetFileBaseName(this.tiler.CalculatedLayers, this.tiler.CalculatedLayers.First(), new Point(0, 0))); }
private static void TileOutput(DirectoryInfo outputDirectory, string fileStem, string analysisTag, FileSegment fileSegment, Image <Rgb24> image) { const int TileHeight = 256; const int TileWidth = 60; // seconds per pixel const double Scale = 60.0; TimeSpan scale = Scale.Seconds(); if (image.Height != TileHeight) { throw new InvalidOperationException("Expecting images exactly the same height as the defined tile height"); } // if recording does not start on an absolutely aligned hour of the day // align it, then adjust where the tiling starts from, and calculate the offset for the super tile (the gap) var recordingStartDate = fileSegment.TargetFileStartDate.Value; // TODO: begin remove duplicate code var timeOfDay = recordingStartDate.TimeOfDay; var previousAbsoluteHour = TimeSpan.FromSeconds(Math.Floor(timeOfDay.TotalSeconds / (Scale * TileWidth)) * (Scale * TileWidth)); var gap = timeOfDay - previousAbsoluteHour; var tilingStartDate = recordingStartDate - gap; var tilingStartDate2 = ZoomTiledSpectrograms.GetPreviousTileBoundary(TileWidth, Scale, recordingStartDate); var padding = recordingStartDate - tilingStartDate2; Debug.Assert(tilingStartDate == tilingStartDate2, "tilingStartDate != tilingStartDate2: these methods should be equivalent"); // TODO: end remove duplicate code var tilingProfile = new AbsoluteDateTilingProfile(fileStem, analysisTag, tilingStartDate, TileHeight, TileWidth); // pad out image so it produces a whole number of tiles // this solves the asymmetric right padding of short audio files var width = (int)(Math.Ceiling(image.Width / Scale) * Scale); var tiler = new Tiler(outputDirectory, tilingProfile, Scale, width, 1.0, image.Height); // prepare super tile var tile = new TimeOffsetSingleLayerSuperTile( padding, SpectrogramType.Index, scale, image.CloneAs <Rgba32>(), fileSegment.SegmentStartOffset ?? TimeSpan.Zero); tiler.Tile(tile); }
public void TestLeftPaddingInLowerLayers() { const int TileWidth = 180; var startDate = new DateTimeOffset(2014, 05, 29, 08, 13, 58, TimeSpan.FromHours(10)); var boundary = ZoomTiledSpectrograms.GetPreviousTileBoundary(TileWidth, 0.1, startDate); var padding = startDate - boundary; var profile = new AbsoluteDateTilingProfile( "Filename", "Tile", boundary, 256, TileWidth); var tiler = new Tiler( this.outputDirectory.ToDirectoryEntry(), profile, new SortedSet <double>() { 60.0, 0.1 }, 60.0, 1440, new SortedSet <double>() { 1, 1 }, 1.0, 256); var testBitmap = new Bitmap(1200, 256); using (var graphics = Graphics.FromImage(testBitmap)) { var points = new[] { new Point(0, 0), new Point(180, 256), new Point(360, 0), new Point(540, 256), new Point(720, 0), new Point(900, 256), new Point(1080, 0), new Point(1260, 256), }; graphics.DrawLines( Pens.Red, points); } var superTile = new TimeOffsetSingleLayerSuperTile( padding, SpectrogramType.Index, 0.1.Seconds(), testBitmap, 0.Seconds()); tiler.Tile(superTile); ////Debug.WriteLine(this.outputDirectory.FullName); ////Debug.WriteLine(this.outputDirectory.GetFiles().Length); var actualFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray(); Assert.AreEqual(8, actualFiles.Length); var expectedFiles = new[] { "Filename__Tile_20140528T221348Z_0.1.png", "Filename__Tile_20140528T221406Z_0.1.png", "Filename__Tile_20140528T221424Z_0.1.png", "Filename__Tile_20140528T221442Z_0.1.png", "Filename__Tile_20140528T221500Z_0.1.png", "Filename__Tile_20140528T221518Z_0.1.png", "Filename__Tile_20140528T221536Z_0.1.png", "Filename__Tile_20140528T221554Z_0.1.png", }; var expectedImages = expectedFiles .OrderBy(x => x) .Select((x, i) => testBitmap.Crop(new Rectangle((i * TileWidth) - 100, 0, TileWidth, 256))) .ToArray(); for (var i = 0; i < expectedImages.Length; i++) { Assert.AreEqual(expectedFiles[i], actualFiles[i].Name); var expectedImage = expectedImages[i]; var actualImage = Image.FromFile(actualFiles[i].FullName); var areEqual = TilerTests.BitmapEquals(expectedImage, (Bitmap)actualImage); Assert.IsTrue(areEqual, "Bitmaps were not equal {0}, {1}", expectedFiles[i], actualFiles[i]); } }
private static (TilingProfile Profile, TimeSpan padding) GetTilingProfile( ZoomParameters common, SpectrogramZoomingConfig zoomConfig, IndexGenerationData indexGeneration, double maxScale) { TilingProfile namingPattern; TimeSpan padding; switch (zoomConfig.TilingProfile) { case nameof(PanoJsTilingProfile): namingPattern = new PanoJsTilingProfile(); padding = TimeSpan.Zero; if (zoomConfig.TileWidth != namingPattern.TileWidth) { throw new ConfigFileException( "TileWidth must match the default PanoJS TileWidth of " + namingPattern.TileWidth); } break; case nameof(AbsoluteDateTilingProfile): // Zooming spectrograms use multiple color profiles at different levels // therefore unable to set a useful tag (like ACI-ENT-EVN). if (indexGeneration.RecordingStartDate != null) { var recordingStartDate = (DateTimeOffset)indexGeneration.RecordingStartDate; var tilingStartDate = GetPreviousTileBoundary( zoomConfig.TileWidth, maxScale, recordingStartDate); padding = recordingStartDate - tilingStartDate; // if we're not writing tiles to disk, omit the basename because whatever the container format is // it will have the base name attached namingPattern = new AbsoluteDateTilingProfile( common.OmitBasename ? string.Empty : common.OriginalBasename, "BLENDED.Tile", tilingStartDate, indexGeneration.FrameLength / 2, zoomConfig.TileWidth); } else { throw new ArgumentNullException( nameof(zoomConfig.TilingProfile), "`RecordingStateDate` from the `IndexGenerationData.json` cannot be null when `AbsoluteDateTilingProfile` specified"); } break; default: throw new ConfigFileException( $"The {nameof(zoomConfig.TilingProfile)} configuration property was set to an unsupported value - no profile known by that name"); } Log.Info($"Tiling had a left padding duration of {padding} to align tiles"); Log.Info( $"Tiling using {namingPattern.GetType().Name}, Tile Width: {namingPattern.TileWidth}, Height: {namingPattern.TileHeight}"); return(namingPattern, padding); }
public void TestLeftPaddingInLowerLayers() { const int TileWidth = 180; var startDate = new DateTimeOffset(2014, 05, 29, 08, 13, 58, TimeSpan.FromHours(10)); var boundary = ZoomTiledSpectrograms.GetPreviousTileBoundary(TileWidth, 0.1, startDate); var padding = startDate - boundary; var profile = new AbsoluteDateTilingProfile( "Filename", "Tile", boundary, 256, TileWidth); var tiler = new Tiler( this.outputDirectory, profile, new SortedSet <double>() { 60.0, 0.1 }, 60.0, 1440, new SortedSet <double>() { 1, 1 }, 1.0, 256); var testBitmap = new Image <Rgba32>(1200, 256); testBitmap.Mutate(graphics => { var points = new[] { new PointF(0, 0), new Point(180, 256), new Point(360, 0), new Point(540, 256), new Point(720, 0), new PointF(900, 256), new Point(1080, 0), new Point(1260, 256), }; graphics.DrawLines( new GraphicsOptions(), Brushes.Solid(Color.Red), 1, points); }); var superTile = new TimeOffsetSingleLayerSuperTile( padding, SpectrogramType.Index, 0.1.Seconds(), testBitmap, 0.Seconds()); tiler.Tile(superTile); ////Trace.WriteLine(this.outputDirectory.FullName); ////Trace.WriteLine(this.outputDirectory.GetFiles().Length); var actualFiles = this.outputDirectory.GetFiles().OrderBy(x => x.Name).ToArray(); Assert.AreEqual(8, actualFiles.Length); var expectedFiles = new[] { "Filename__Tile_20140528T221348Z_0.1.png", "Filename__Tile_20140528T221406Z_0.1.png", "Filename__Tile_20140528T221424Z_0.1.png", "Filename__Tile_20140528T221442Z_0.1.png", "Filename__Tile_20140528T221500Z_0.1.png", "Filename__Tile_20140528T221518Z_0.1.png", "Filename__Tile_20140528T221536Z_0.1.png", "Filename__Tile_20140528T221554Z_0.1.png", }; var expectedImages = expectedFiles .OrderBy(x => x) .Select((x, i) => testBitmap.CropInverse(new Rectangle((i * TileWidth) - 100, 0, TileWidth, 256))) .ToArray(); for (var i = 0; i < expectedImages.Length; i++) { Assert.AreEqual(expectedFiles[i], actualFiles[i].Name); var expectedImage = expectedImages[i]; var actualImage = Image.Load <Rgba32>(actualFiles[i].FullName); Assert.That.ImageMatches(expectedImages[i], actualImage, message: $"Bitmaps were not equal {expectedImages[i]}, {actualFiles[i]}"); } }