From a07cfc5b3bd369712e9f00df0e28e57f3177dc63 Mon Sep 17 00:00:00 2001 From: Tyler Hoeflicker Date: Thu, 17 Nov 2016 10:59:48 -0800 Subject: [PATCH] add guards to setting colortable --- binding/Binding/SKBitmap.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 4839aeec..fa964b59 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -14,6 +14,8 @@ namespace SkiaSharp { public class SKBitmap : SKObject { + const string UNSUPPORTED_CLR_TYPE_MSG = "Setting the ColorTable is only supported for bitmaps with ColorTypes of Index8"; + [Preserve] internal SKBitmap (IntPtr handle, bool owns) : base (handle, owns) @@ -195,10 +197,18 @@ namespace SkiaSharp } public void SetPixels(IntPtr pixels, SKColorTable ct = null) { + if (ct != null && ColorType != SKColorType.Index8) + { + throw new NotSupportedException(UNSUPPORTED_CLR_TYPE_MSG); + } SkiaApi.sk_bitmap_set_pixels(Handle, pixels, ct != null ? ct.Handle : IntPtr.Zero); } public void SetColorTable(SKColorTable ct) { + if (ColorType != SKColorType.Index8) + { + throw new NotSupportedException(UNSUPPORTED_CLR_TYPE_MSG); + } IntPtr length; SetPixels(this.GetPixels(out length), ct); }