Skip to content

Commit

Permalink
Add SKImage.ToRawShader
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Feb 9, 2024
1 parent 9bb8b23 commit f8a11e8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
20 changes: 20 additions & 0 deletions binding/SkiaSharp/SKImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,26 @@ public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamp
private SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling, SKMatrix* localMatrix) =>
SKShader.GetObject (SkiaApi.sk_image_make_shader (Handle, tileX, tileY, &sampling, localMatrix));

// ToRawShader

public SKShader ToRawShader () =>
ToRawShader (SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, SKSamplingOptions.Default, null);

public SKShader ToRawShader (SKShaderTileMode tileX, SKShaderTileMode tileY) =>
ToRawShader (tileX, tileY, SKSamplingOptions.Default, null);

public SKShader ToRawShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKMatrix localMatrix) =>
ToRawShader (tileX, tileY, SKSamplingOptions.Default, &localMatrix);

public SKShader ToRawShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling) =>
ToRawShader (tileX, tileY, sampling, null);

public SKShader ToRawShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling, SKMatrix localMatrix) =>
ToRawShader (tileX, tileY, sampling, &localMatrix);

private SKShader ToRawShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling, SKMatrix* localMatrix) =>
SKShader.GetObject (SkiaApi.sk_image_make_raw_shader (Handle, tileX, tileY, &sampling, localMatrix));

// PeekPixels

public bool PeekPixels (SKPixmap pixmap)
Expand Down
14 changes: 14 additions & 0 deletions binding/SkiaSharp/SkiaApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4960,6 +4960,20 @@ internal static sk_shader_t sk_image_make_shader (sk_image_t image, SKShaderTile
(sk_image_make_shader_delegate ??= GetSymbol<Delegates.sk_image_make_shader> ("sk_image_make_shader")).Invoke (image, tileX, tileY, sampling, cmatrix);
#endif

// sk_shader_t* sk_image_make_raw_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_sampling_options_t* sampling, const sk_matrix_t* cmatrix)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern sk_shader_t sk_image_make_raw_shader (sk_image_t image, SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions* sampling, SKMatrix* cmatrix);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate sk_shader_t sk_image_make_raw_shader (sk_image_t image, SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions* sampling, SKMatrix* cmatrix);
}
private static Delegates.sk_image_make_raw_shader sk_image_make_raw_shader_delegate;
internal static sk_shader_t sk_image_make_raw_shader (sk_image_t image, SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions* sampling, SKMatrix* cmatrix) =>
(sk_image_make_raw_shader_delegate ??= GetSymbol<Delegates.sk_image_make_raw_shader> ("sk_image_make_raw_shader")).Invoke (image, tileX, tileY, sampling, cmatrix);
#endif

// sk_image_t* sk_image_make_subset(const sk_image_t* cimage, gr_direct_context_t* context, const sk_irect_t* subset)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand Down
2 changes: 1 addition & 1 deletion externals/skia
25 changes: 25 additions & 0 deletions tests/Tests/SkiaSharp/SKImageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -900,5 +900,30 @@ public void CanDecodePotentiallyCorruptPngFiles(string filename, int x, int y, u

Assert.Equal((SKColor)color, pixmap.GetPixelColor(x, y));
}

[SkippableFact]
public void CanCreateRawShader()
{
var path = Path.Combine(PathToImages, "baboon.png");

using var image = SKImage.FromEncodedData(path);
Assert.NotNull(image);

using var shader = image.ToRawShader();
Assert.NotNull(shader);
}

[SkippableFact]
public void CannotCreateRawShaderWithBicubicSampling()
{
var path = Path.Combine(PathToImages, "baboon.png");

using var image = SKImage.FromEncodedData(path);
Assert.NotNull(image);

var sampling = new SKSamplingOptions(SKCubicResampler.Mitchell);
using var shader = image.ToRawShader(SKShaderTileMode.Clamp, SKShaderTileMode.Clamp, sampling);
Assert.Null(shader);
}
}
}

0 comments on commit f8a11e8

Please sign in to comment.