Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(merge): merging RGB image with Grayscale should result in pixels resembling original images (MAPCO-4547) #161

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion MergerLogic/ImageProcessing/TileMerger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ private void AddTileToImageList(Coord targetCoords, Tile? tile, List<MagickImage
}

var tileBytes = tile.GetImageBytes();
MagickImage? tileImage = new MagickImage(tileBytes);
MagickImage? tileImage = new MagickImage(tileBytes)
{
ColorSpace = ColorSpace.sRGB
asafMasa marked this conversation as resolved.
Show resolved Hide resolved
};

if (tile.Z < targetCoords.Z)
{
var upscale = this._tileScaler.Upscale(tileImage, tile, targetCoords);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions MergerLogicUnitTests/ImageProcessing/TileMergerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,48 @@ public static IEnumerable<object[]> GetMergeTilesTestParameters()
};
#endregion

#region Test cases for grayscale
yield return new object[] {
new Tile[] {
new Tile(targetCoordHighZoom, File.ReadAllBytes("grayscale_paletted.jpeg")),
new Tile(targetCoordHighZoom, File.ReadAllBytes("6_rgb.png"))
}, targetCoordHighZoom, new TileFormatStrategy(TileFormat.Png, TileFormatStrategy.FormatStrategy.Mixed),
TileFormat.Jpeg, false, File.ReadAllBytes("grayscale_paletted_6_rgb_merged.jpeg"),
};

yield return new object[] {
new Tile[] {
new Tile(targetCoordHighZoom, File.ReadAllBytes("grayscale_paletted.jpeg")),
new Tile(targetCoordHighZoom, File.ReadAllBytes("6_paletted.png"))
}, targetCoordHighZoom, new TileFormatStrategy(TileFormat.Png, TileFormatStrategy.FormatStrategy.Mixed),
TileFormat.Jpeg, false, File.ReadAllBytes("grayscale_paletted_6_paletted_merged.jpeg"),
};

yield return new object[] {
new Tile[] {
new Tile(targetCoordHighZoom, File.ReadAllBytes("grayscale_rgb.jpeg")),
new Tile(targetCoordHighZoom, File.ReadAllBytes("6_rgb.png"))
}, targetCoordHighZoom, new TileFormatStrategy(TileFormat.Png, TileFormatStrategy.FormatStrategy.Mixed),
TileFormat.Jpeg, false, File.ReadAllBytes("grayscale_rgb_6_rgb_merged.jpeg"),
};

yield return new object[] {
new Tile[] {
new Tile(targetCoordHighZoom, File.ReadAllBytes("grayscale_rgb.jpeg")),
new Tile(targetCoordHighZoom, File.ReadAllBytes("6_paletted.png"))
}, targetCoordHighZoom, new TileFormatStrategy(TileFormat.Png, TileFormatStrategy.FormatStrategy.Mixed),
TileFormat.Jpeg, false, File.ReadAllBytes("grayscale_rgb_6_paletted_merged.jpeg"),
};

yield return new object[] {
new Tile[] {
new Tile(targetCoordHighZoom, File.ReadAllBytes("grayscale.jpeg")),
new Tile(targetCoordHighZoom, File.ReadAllBytes("6_paletted.png"))
}, targetCoordHighZoom, new TileFormatStrategy(TileFormat.Png, TileFormatStrategy.FormatStrategy.Mixed),
TileFormat.Jpeg, false, File.ReadAllBytes("grayscale_6_paletted_merged.jpeg"),
};
#endregion

#region Test cases for ignoring target
yield return new object[] {
new Tile[] {
Expand Down Expand Up @@ -292,6 +334,8 @@ public void MergeTiles(Tile[] tiles, Coord targetCoord, TileFormatStrategy strat
var tileBuilders = tiles.Select<Tile, CorrespondingTileBuilder>(tile => () => tile).ToList();
var result = this._testTileMerger.MergeTiles(tileBuilders, targetCoord, strategy, uploadOnly);

File.WriteAllBytes("/home/shimonc1/Documents/GpkgMerger/MergerLogicUnitTests/ImageProcessing/TestImages/temp", result.GetImageBytes());
asafMasa marked this conversation as resolved.
Show resolved Hide resolved

Assert.IsNotNull(result);
Assert.AreEqual(expectedForamt, result.Format);
CollectionAssert.AreEqual(expectedTileBytes, result.GetImageBytes());
Expand Down
Loading