Properly copy bitmaps. Fixes #497
This commit is contained in:
Родитель
fc89f90e18
Коммит
82cafbece2
|
@ -210,9 +210,6 @@ namespace SkiaSharp
|
||||||
|
|
||||||
public bool CopyTo (SKBitmap destination, SKColorType colorType)
|
public bool CopyTo (SKBitmap destination, SKColorType colorType)
|
||||||
{
|
{
|
||||||
// TODO: instead of working on `destination` directly, we should
|
|
||||||
// create a temporary bitmap and then inject the data
|
|
||||||
|
|
||||||
if (destination == null) {
|
if (destination == null) {
|
||||||
throw new ArgumentNullException (nameof (destination));
|
throw new ArgumentNullException (nameof (destination));
|
||||||
}
|
}
|
||||||
|
@ -248,8 +245,10 @@ namespace SkiaSharp
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
destination.Reset (); // TODO: is this needed?
|
// TODO: handle copying two Index8 images - copy/reference the color tables
|
||||||
if (!destination.TryAllocPixels (dstInfo, colorType == SKColorType.Index8 ? ColorTable : null)) {
|
|
||||||
|
var tmpDst = new SKBitmap ();
|
||||||
|
if (!tmpDst.TryAllocPixels (dstInfo, colorType == SKColorType.Index8 ? ColorTable : null)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +273,8 @@ namespace SkiaSharp
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destination.Swap (tmpDst);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,6 +730,11 @@ namespace SkiaSharp
|
||||||
return PeekPixels (pixmap) && pixmap.Encode (dst, format, quality);
|
return PeekPixels (pixmap) && pixmap.Encode (dst, format, quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Swap (SKBitmap other)
|
||||||
|
{
|
||||||
|
SkiaApi.sk_bitmap_swap (Handle, other.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
private static SKStream WrapManagedStream (Stream stream)
|
private static SKStream WrapManagedStream (Stream stream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1366,6 +1366,9 @@ namespace SkiaSharp
|
||||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public extern static void sk_bitmap_notify_pixels_changed(sk_bitmap_t cbitmap);
|
public extern static void sk_bitmap_notify_pixels_changed(sk_bitmap_t cbitmap);
|
||||||
|
|
||||||
|
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public extern static void sk_bitmap_swap(sk_bitmap_t cbitmap, sk_bitmap_t cother);
|
||||||
|
|
||||||
// SKColor
|
// SKColor
|
||||||
|
|
||||||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 864434895d0487be35d1435ada049870d8664203
|
Subproject commit ceff8e6562f6909837741b7798cd8727c10cf8e6
|
|
@ -25,6 +25,30 @@ namespace SkiaSharp.Tests
|
||||||
Assert.False(bmp.CanCopyTo(SKColorType.Gray8));
|
Assert.False(bmp.CanCopyTo(SKColorType.Gray8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void CopyIndex8ToPlatformPreservesData()
|
||||||
|
{
|
||||||
|
var path = Path.Combine(PathToImages, "index8.png");
|
||||||
|
var bmp = SKBitmap.Decode(path);
|
||||||
|
|
||||||
|
var platform = bmp.Copy(SKImageInfo.PlatformColorType);
|
||||||
|
|
||||||
|
Assert.Equal((SKColor)0x7EA4C639, platform.GetPixel(182, 348));
|
||||||
|
Assert.Equal(SKImageInfo.PlatformColorType, platform.ColorType);
|
||||||
|
}
|
||||||
|
|
||||||
|
[SkippableFact]
|
||||||
|
public void OverwriteIndex8ToPlatformPreservesData()
|
||||||
|
{
|
||||||
|
var path = Path.Combine(PathToImages, "index8.png");
|
||||||
|
var bmp = SKBitmap.Decode(path);
|
||||||
|
|
||||||
|
bmp.CopyTo(bmp, SKImageInfo.PlatformColorType);
|
||||||
|
|
||||||
|
Assert.Equal((SKColor)0x7EA4C639, bmp.GetPixel(182, 348));
|
||||||
|
Assert.Equal(SKImageInfo.PlatformColorType, bmp.ColorType);
|
||||||
|
}
|
||||||
|
|
||||||
[SkippableFact]
|
[SkippableFact]
|
||||||
public void BitmapCopyToAlpha8PreservesData()
|
public void BitmapCopyToAlpha8PreservesData()
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче