зеркало из https://github.com/mono/SkiaSharp.git
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)
|
||||
{
|
||||
// TODO: instead of working on `destination` directly, we should
|
||||
// create a temporary bitmap and then inject the data
|
||||
|
||||
if (destination == null) {
|
||||
throw new ArgumentNullException (nameof (destination));
|
||||
}
|
||||
|
@ -248,8 +245,10 @@ namespace SkiaSharp
|
|||
break;
|
||||
}
|
||||
|
||||
destination.Reset (); // TODO: is this needed?
|
||||
if (!destination.TryAllocPixels (dstInfo, colorType == SKColorType.Index8 ? ColorTable : null)) {
|
||||
// TODO: handle copying two Index8 images - copy/reference the color tables
|
||||
|
||||
var tmpDst = new SKBitmap ();
|
||||
if (!tmpDst.TryAllocPixels (dstInfo, colorType == SKColorType.Index8 ? ColorTable : null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -274,6 +273,8 @@ namespace SkiaSharp
|
|||
return false;
|
||||
}
|
||||
|
||||
destination.Swap (tmpDst);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -729,6 +730,11 @@ namespace SkiaSharp
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1366,6 +1366,9 @@ namespace SkiaSharp
|
|||
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
|
||||
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
|
||||
|
||||
[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));
|
||||
}
|
||||
|
||||
[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]
|
||||
public void BitmapCopyToAlpha8PreservesData()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче