diff --git a/src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs b/src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs index 1c386bc6..0baf96c3 100644 --- a/src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs +++ b/src/Aardvark.Base.Tensors.CSharp/PixImage/PixImage.cs @@ -1129,7 +1129,7 @@ public PixImage(Col.Format format, PixImage pixImage) var volume = CreateVolume(srcInfo.Size.X, srcInfo.Size.Y, dstChannels.Length); volume.F = srcInfo.F; - if (format == pixImage.Format) + if (format == pixImage.Format && srcInfo.Size == volume.Size) { pixImage.CopyVolumeTo(volume); } diff --git a/src/Aardvark.Base.Tensors.CSharp/PixImage/PixVolume.cs b/src/Aardvark.Base.Tensors.CSharp/PixImage/PixVolume.cs index 2a2ea2f1..6a43b2ca 100644 --- a/src/Aardvark.Base.Tensors.CSharp/PixImage/PixVolume.cs +++ b/src/Aardvark.Base.Tensors.CSharp/PixImage/PixVolume.cs @@ -192,7 +192,7 @@ public PixVolume(Col.Format format, PixVolume pixVolume) var tensor4 = CreateTensor4(srcInfo.Size.X, srcInfo.Size.Y, srcInfo.Size.Z, dstChannels.Length); tensor4.F = pixVolume.Tensor4Info.F; - if (format == pixVolume.Format) + if (format == pixVolume.Format && srcInfo.Size == tensor4.Size) { pixVolume.CopyTensor4To(tensor4); } diff --git a/src/Tests/Aardvark.Base.Tests/Images/PixImageTests.cs b/src/Tests/Aardvark.Base.Tests/Images/PixImageTests.cs index c26dce65..01b77c0c 100644 --- a/src/Tests/Aardvark.Base.Tests/Images/PixImageTests.cs +++ b/src/Tests/Aardvark.Base.Tests/Images/PixImageTests.cs @@ -448,6 +448,23 @@ public void FormatConversionBGRAToRG() #region From RGB + [Test] + public void FormatConversionRGBToRGBWithAdditionalChannel() + { + var getRandom = s_randomValues[typeof(byte)]; + var volume = ImageTensors.CreateImageVolume(new V3l(54, 23, 4)); + volume.Data.SetByIndex((_) => (byte)getRandom(rnd)); + var src = new PixImage(Col.Format.RGB, volume); + var dst = new PixImage(Col.Format.RGB, src); + + src.GetChannel(0L).ForeachCoord((coord) => + { + var expected = GetColor(src, coord); + var actual = GetColor(dst, coord); + Assert.AreEqual(expected, actual); + }); + } + [Test] public void FormatConversionRGBToBGRA() => FormatConversion(Col.Format.RGB, Col.Format.BGRA, c => c.ToC4b()); diff --git a/src/Tests/Aardvark.Base.Tests/Images/PixVolumeTests.cs b/src/Tests/Aardvark.Base.Tests/Images/PixVolumeTests.cs index cb4f924c..fab2e4dc 100644 --- a/src/Tests/Aardvark.Base.Tests/Images/PixVolumeTests.cs +++ b/src/Tests/Aardvark.Base.Tests/Images/PixVolumeTests.cs @@ -356,6 +356,23 @@ public void TypeConversionDoubleToFloat() #region From RGB + [Test] + public void FormatConversionRGBToRGBWithAdditionalChannel() + { + var getRandom = PixImageTests.s_randomValues[typeof(byte)]; + var tensor = ImageTensors.CreateImageTensor4(new V4l(54, 23, 11, 4)); + tensor.Data.SetByIndex((_) => (byte)getRandom(rnd)); + var src = new PixVolume(Col.Format.RGB, tensor); + var dst = new PixVolume(Col.Format.RGB, src); + + src.GetChannel(0L).ForeachCoord((coord) => + { + var expected = GetColor(src, coord); + var actual = GetColor(dst, coord); + Assert.AreEqual(expected, actual); + }); + } + [Test] public void FormatConversionRGBToBGRA() => FormatConversion(Col.Format.RGB, Col.Format.BGRA, c => c.ToC4b());