Skip to content

Commit 165d8b1

Browse files
authored
Fix the SKImage.FromPicture implementation (#3231)
* Update the externals to fix C++ API Fixes #3157 * Update the externals to get the new API * the colorspace is NOT optional it seems
1 parent 9753259 commit 165d8b1

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

binding/SkiaSharp/SKImage.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,26 @@ public static SKImage FromAdoptedTexture (GRRecordingContext context, GRBackendT
330330
// create a new image from a picture
331331

332332
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions) =>
333-
FromPicture (picture, dimensions, null, null, false, null, null);
333+
FromPicture (picture, dimensions, null, null, false, SKColorSpace.CreateSrgb (), null);
334334

335335
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKMatrix matrix) =>
336-
FromPicture (picture, dimensions, &matrix, null, false, null, null);
336+
FromPicture (picture, dimensions, &matrix, null, false, SKColorSpace.CreateSrgb (), null);
337337

338338
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKPaint paint) =>
339-
FromPicture (picture, dimensions, null, paint, false, null, null);
339+
FromPicture (picture, dimensions, null, paint, false, SKColorSpace.CreateSrgb (), null);
340340

341341
public static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKMatrix matrix, SKPaint paint) =>
342-
FromPicture (picture, dimensions, &matrix, paint, false, null, null);
342+
FromPicture (picture, dimensions, &matrix, paint, false, SKColorSpace.CreateSrgb (), null);
343343

344344
private static SKImage FromPicture (SKPicture picture, SKSizeI dimensions, SKMatrix* matrix, SKPaint paint, bool useFloatingPointBitDepth, SKColorSpace colorspace, SKSurfaceProperties props)
345345
{
346346
if (picture == null)
347347
throw new ArgumentNullException (nameof (picture));
348348

349349
var p = paint?.Handle ?? IntPtr.Zero;
350-
return GetObject (SkiaApi.sk_image_new_from_picture (picture.Handle, &dimensions, matrix, p, useFloatingPointBitDepth, colorspace?.Handle ?? IntPtr.Zero, props?.Handle ?? IntPtr.Zero));
350+
var cs = colorspace?.Handle ?? IntPtr.Zero;
351+
var prps = props?.Handle ?? IntPtr.Zero;
352+
return GetObject (SkiaApi.sk_image_new_from_picture (picture.Handle, &dimensions, matrix, p, useFloatingPointBitDepth, cs, prps));
351353
}
352354

353355
public SKData Encode ()

externals/skia

tests/Tests/SkiaSharp/SKImageTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,5 +925,18 @@ public void CannotCreateRawShaderWithBicubicSampling()
925925
using var shader = image.ToRawShader(SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, sampling);
926926
Assert.Null(shader);
927927
}
928+
929+
[SkippableFact]
930+
public void FromPictureDoesNotCrash()
931+
{
932+
using var picture = CreateTestPicture();
933+
934+
using var image = SKImage.FromPicture(picture, new SKSizeI(40, 40));
935+
936+
using var data = image.Encode(SKEncodedImageFormat.Png, 100);
937+
using var bmp = SKBitmap.Decode(data);
938+
939+
ValidateTestBitmap(bmp);
940+
}
928941
}
929942
}

tests/Tests/SkiaSharp/SKTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected static SKPicture CreateTestPicture(byte alpha = 255)
139139
return recorder.EndRecording();
140140
}
141141

142-
private static void DrawTestBitmap(SKCanvas canvas, int width, int height, byte alpha = 255)
142+
protected static void DrawTestBitmap(SKCanvas canvas, int width, int height, byte alpha = 255)
143143
{
144144
using var paint = new SKPaint();
145145

0 commit comments

Comments
 (0)