public void TestFromImage_DimensionsNotDivisibleByDefault(int width, int height) { var image = GraphicUtils.GetImageByDimensions(width, height); var chips = Chip.FromImage(image).ToList(); var numWidth = width / SharedConstants.DefaultChipWidth + 1; var numHeight = height / SharedConstants.DefaultChipHeight + 1; for (var i = 0; i < numWidth; i++) { var subWidth = i + 1 < numWidth ? SharedConstants.DefaultChipWidth : width % SharedConstants.DefaultChipWidth; for (var j = 0; j < numHeight; j++) { var subHeight = j + 1 < numHeight ? SharedConstants.DefaultChipHeight : height % SharedConstants.DefaultChipHeight; var left = i * SharedConstants.DefaultChipWidth; var top = j * SharedConstants.DefaultChipHeight; var expectedRegion = new SKRectI(left, top, left + subWidth, top + subHeight); var expectedPixels = GraphicUtils.GetPixelsByDimensions(subWidth, subHeight); Assert.AreEqual(expectedRegion, chips[i * numHeight + j].Region); Assert.AreEqual(expectedPixels, chips[i * numHeight + j].Pixels); } } }
/// <summary> /// Analyzes the specified <see cref="SKImage"/> using the specified chip-analyzer function. /// </summary> /// <param name="image">The specified <see cref="SKImage"/> to analyze.</param> /// <param name="chipAnalyzer">The specified chip-analyzer function to analyze a single chip.</param> /// <param name="ct">The external <see cref="CancellationToken"/>.</param> /// <param name="progressUpdater">The specified function to update the progress bar on the analyzing page.</param> /// <returns><see cref="CategoryManager"/>s that represent the results of the chips of the specified <see cref="SKImage"/>.</returns> public static IEnumerable <CategoryManager> AnalyzeImage(SKImage image, Func <Chip, CategoryManager> chipAnalyzer, CancellationToken ct, Action progressUpdater) { var chips = Chip.FromImage(image).ToList(); return(chips.AsParallel().WithCancellation(ct).Select(chip => { var result = chipAnalyzer(chip); progressUpdater(); return result; })); }
public void TestFromImage_DimensionsLessThanDefault(int width, int height) { var image = GraphicUtils.GetImageByDimensions(width, height); var chips = Chip.FromImage(image).ToList(); Assert.AreEqual(1, chips.Count); var expectedRegion = new SKRectI(0, 0, width, height); var expectedPixels = GraphicUtils.GetPixelsByDimensions(width, height); Assert.AreEqual(expectedRegion, chips[0].Region); Assert.AreEqual(expectedPixels, chips[0].Pixels); }
public void TestFromImage_DimensionsDivisibleByDefault(int widthMultiplier, int heightMultiplier) { var image = GraphicUtils.GetImageByDimensions(widthMultiplier * SharedConstants.DefaultChipWidth, heightMultiplier * SharedConstants.DefaultChipHeight); var chips = Chip.FromImage(image).ToList(); Assert.AreEqual(widthMultiplier * heightMultiplier, chips.Count); for (var i = 0; i < widthMultiplier; i++) { for (var j = 0; j < heightMultiplier; j++) { var left = i * SharedConstants.DefaultChipWidth; var top = j * SharedConstants.DefaultChipHeight; var expectedRegion = new SKRectI(left, top, left + SharedConstants.DefaultChipWidth, top + SharedConstants.DefaultChipHeight); var expectedPixels = GraphicUtils.GetPixelsByDimensions(SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight); Assert.AreEqual(expectedRegion, chips[i * heightMultiplier + j].Region); Assert.AreEqual(expectedPixels, chips[i * heightMultiplier + j].Pixels); } } }