Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions binding/SkiaSharp/SKBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public byte[] Bytes {
public SKColor[] Pixels {
get {
var info = Info;
var pixels = new SKColor[info.Width * info.Height];
var pixels = new SKColor[checked(info.Width * info.Height)];
fixed (SKColor* p = pixels) {
SkiaApi.sk_bitmap_get_pixel_colors (Handle, (uint*)p);
}
Expand All @@ -339,8 +339,9 @@ public SKColor[] Pixels {
throw new ArgumentNullException (nameof (value));

var info = Info;
if (info.Width * info.Height != value.Length)
throw new ArgumentException ($"The number of pixels must equal Width x Height, or {info.Width * info.Height}.", nameof (value));
var expected = (long)info.Width * info.Height;
if (expected != value.Length)
throw new ArgumentException ($"The number of pixels must equal Width x Height, or {expected}.", nameof (value));

fixed (SKColor* v = value) {
var tempInfo = new SKImageInfo (info.Width, info.Height, SKColorType.Bgra8888, SKAlphaType.Unpremul);
Expand Down Expand Up @@ -653,11 +654,11 @@ public bool PeekPixels (SKPixmap pixmap)

// Resize

[Obsolete ("Use Resize(SKImageInfo info, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use Resize(SKImageInfo info, SKSamplingOptions sampling) instead.", error: true)]
public SKBitmap Resize (SKImageInfo info, SKFilterQuality quality) =>
Resize (info, quality.ToSamplingOptions ());

[Obsolete ("Use Resize(SKSizeI size, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use Resize(SKSizeI size, SKSamplingOptions sampling) instead.", error: true)]
public SKBitmap Resize (SKSizeI size, SKFilterQuality quality) =>
Resize (size, quality.ToSamplingOptions ());

Expand All @@ -680,11 +681,11 @@ public SKBitmap Resize (SKSizeI size, SKSamplingOptions sampling) =>

// ScalePixels

[Obsolete ("Use ScalePixels(SKBitmap destination, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use ScalePixels(SKBitmap destination, SKSamplingOptions sampling) instead.", error: true)]
public bool ScalePixels (SKBitmap destination, SKFilterQuality quality) =>
ScalePixels (destination, quality.ToSamplingOptions ());

[Obsolete ("Use ScalePixels(SKPixmap destination, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use ScalePixels(SKPixmap destination, SKSamplingOptions sampling) instead.", error: true)]
public bool ScalePixels (SKPixmap destination, SKFilterQuality quality) =>
ScalePixels (destination, quality.ToSamplingOptions ());

Expand Down Expand Up @@ -767,7 +768,7 @@ public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy) =>
public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling) =>
ToShader (tmx, tmy, sampling, null);

[Obsolete ("Use ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling) instead.", error: true)]
public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy, SKFilterQuality quality) =>
ToShader (tmx, tmy, quality.ToSamplingOptions(), null);

Expand All @@ -777,7 +778,7 @@ public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy, SKMatrix l
public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling, SKMatrix localMatrix) =>
ToShader (tmx, tmy, sampling, &localMatrix);

[Obsolete ("Use ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling, SKMatrix localMatrix) instead.")]
[Obsolete ("Use ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKSamplingOptions sampling, SKMatrix localMatrix) instead.", error: true)]
public SKShader ToShader (SKShaderTileMode tmx, SKShaderTileMode tmy, SKFilterQuality quality, SKMatrix localMatrix) =>
ToShader (tmx, tmy, quality.ToSamplingOptions(), &localMatrix);

Expand Down
60 changes: 19 additions & 41 deletions binding/SkiaSharp/SKCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@ public void DrawPoint (float x, float y, SKColor color)

public void DrawImage (SKImage image, SKPoint p, SKPaint paint = null)
{
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, p.X, p.Y, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, p.X, p.Y, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, paint);
}

public void DrawImage (SKImage image, SKPoint p, SKSamplingOptions sampling, SKPaint paint = null)
Expand All @@ -466,9 +464,7 @@ public void DrawImage (SKImage image, SKPoint p, SKSamplingOptions sampling, SKP

public void DrawImage (SKImage image, float x, float y, SKPaint paint = null)
{
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, x, y, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, x, y, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, paint);
}

public void DrawImage (SKImage image, float x, float y, SKSamplingOptions sampling, SKPaint paint = null)
Expand All @@ -480,9 +476,7 @@ public void DrawImage (SKImage image, float x, float y, SKSamplingOptions sampli

public void DrawImage (SKImage image, SKRect dest, SKPaint paint = null)
{
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, null, &dest, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, null, &dest, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, paint);
}

public void DrawImage (SKImage image, SKRect dest, SKSamplingOptions sampling, SKPaint paint = null)
Expand All @@ -492,9 +486,7 @@ public void DrawImage (SKImage image, SKRect dest, SKSamplingOptions sampling, S

public void DrawImage (SKImage image, SKRect source, SKRect dest, SKPaint paint = null)
{
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, &source, &dest, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawImage (image, &source, &dest, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, paint);
}

public void DrawImage (SKImage image, SKRect source, SKRect dest, SKSamplingOptions sampling, SKPaint paint = null)
Expand Down Expand Up @@ -628,26 +620,24 @@ public void DrawText (SKTextBlob text, float x, float y, SKPaint paint)

// DrawText

[Obsolete ("Use DrawText(string text, SKPoint p, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
[Obsolete ("Use DrawText(string text, SKPoint p, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.", error: true)]
public void DrawText (string text, SKPoint p, SKPaint paint) =>
DrawText (text, p, paint.TextAlign, paint.GetFont (), paint);

[Obsolete ("Use DrawText(string text, float x, float y, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
[Obsolete ("Use DrawText(string text, float x, float y, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.", error: true)]
public void DrawText (string text, float x, float y, SKPaint paint) =>
DrawText (text, x, y, paint.TextAlign, paint.GetFont (), paint);

[Obsolete ("Use DrawText(string text, SKPoint p, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
public void DrawText (string text, SKPoint p, SKFont font, SKPaint paint) =>
#pragma warning disable CS0618 // Type or member is obsolete (TODO: replace paint.TextAlign with SKTextAlign.Left)
DrawText (text, p, paint.TextAlign, font, paint);
#pragma warning restore CS0618 // Type or member is obsolete
DrawText (text, p, paint.GetLegacyTextAlign (), font, paint);

public void DrawText (string text, SKPoint p, SKTextAlign textAlign, SKFont font, SKPaint paint) =>
DrawText (text, p.X, p.Y, textAlign, font, paint);

[Obsolete ("Use DrawText(string text, float x, float y, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
public void DrawText (string text, float x, float y, SKFont font, SKPaint paint) =>
#pragma warning disable CS0618 // Type or member is obsolete (TODO: replace paint.TextAlign with SKTextAlign.Left)
DrawText (text, x, y, paint.TextAlign, font, paint);
#pragma warning restore CS0618 // Type or member is obsolete
DrawText (text, x, y, paint.GetLegacyTextAlign (), font, paint);

public void DrawText (string text, float x, float y, SKTextAlign textAlign, SKFont font, SKPaint paint)
{
Expand All @@ -674,38 +664,32 @@ public void DrawText (string text, float x, float y, SKTextAlign textAlign, SKFo

// DrawTextOnPath

[Obsolete ("Use DrawTextOnPath(string text, SKPath path, float hOffset, float vOffset, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
[Obsolete ("Use DrawTextOnPath(string text, SKPath path, float hOffset, float vOffset, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.", error: true)]
public void DrawTextOnPath (string text, SKPath path, SKPoint offset, SKPaint paint) =>
DrawTextOnPath (text, path, offset, true, paint);

[Obsolete ("Use DrawTextOnPath(string text, SKPath path, float hOffset, float vOffset, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
[Obsolete ("Use DrawTextOnPath(string text, SKPath path, float hOffset, float vOffset, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.", error: true)]
public void DrawTextOnPath (string text, SKPath path, float hOffset, float vOffset, SKPaint paint) =>
DrawTextOnPath (text, path, new SKPoint (hOffset, vOffset), true, paint);

[Obsolete ("Use DrawTextOnPath(string text, SKPath path, SKPoint offset, bool warpGlyphs, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.")]
[Obsolete ("Use DrawTextOnPath(string text, SKPath path, SKPoint offset, bool warpGlyphs, SKTextAlign textAlign, SKFont font, SKPaint paint) instead.", error: true)]
public void DrawTextOnPath (string text, SKPath path, SKPoint offset, bool warpGlyphs, SKPaint paint) =>
DrawTextOnPath (text, path, offset, warpGlyphs, paint.GetFont (), paint);

public void DrawTextOnPath (string text, SKPath path, SKPoint offset, SKFont font, SKPaint paint) =>
#pragma warning disable CS0618 // Type or member is obsolete (TODO: replace paint.TextAlign with SKTextAlign.Left)
DrawTextOnPath (text, path, offset, true, paint.TextAlign, font, paint);
#pragma warning restore CS0618 // Type or member is obsolete
DrawTextOnPath (text, path, offset, true, paint.GetLegacyTextAlign (), font, paint);

public void DrawTextOnPath (string text, SKPath path, SKPoint offset, SKTextAlign textAlign, SKFont font, SKPaint paint) =>
DrawTextOnPath (text, path, offset, true, textAlign, font, paint);

public void DrawTextOnPath (string text, SKPath path, float hOffset, float vOffset, SKFont font, SKPaint paint) =>
#pragma warning disable CS0618 // Type or member is obsolete (TODO: replace paint.TextAlign with SKTextAlign.Left)
DrawTextOnPath (text, path, new SKPoint (hOffset, vOffset), true, paint.TextAlign, font, paint);
#pragma warning restore CS0618 // Type or member is obsolete
DrawTextOnPath (text, path, new SKPoint (hOffset, vOffset), true, paint.GetLegacyTextAlign (), font, paint);

public void DrawTextOnPath (string text, SKPath path, float hOffset, float vOffset, SKTextAlign textAlign, SKFont font, SKPaint paint) =>
DrawTextOnPath (text, path, new SKPoint (hOffset, vOffset), true, textAlign, font, paint);

public void DrawTextOnPath (string text, SKPath path, SKPoint offset, bool warpGlyphs, SKFont font, SKPaint paint) =>
#pragma warning disable CS0618 // Type or member is obsolete (TODO: replace paint.TextAlign with SKTextAlign.Left)
DrawTextOnPath (text, path, offset, warpGlyphs, paint.TextAlign, font, paint);
#pragma warning restore CS0618 // Type or member is obsolete
DrawTextOnPath (text, path, offset, warpGlyphs, paint.GetLegacyTextAlign (), font, paint);

public void DrawTextOnPath (string text, SKPath path, SKPoint offset, bool warpGlyphs, SKTextAlign textAlign, SKFont font, SKPaint paint)
{
Expand Down Expand Up @@ -981,25 +965,19 @@ public void DrawRoundRectDifference (SKRoundRect outer, SKRoundRect inner, SKPai
// DrawAtlas

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKPaint paint = null) =>
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, null, SKBlendMode.Dst, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, null, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, null, SKBlendMode.Dst, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, null, paint);

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKSamplingOptions sampling, SKPaint paint = null) =>
DrawAtlas (atlas, sprites, transforms, null, SKBlendMode.Dst, sampling, null, paint);

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKPaint paint = null) =>
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, colors, mode, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, null, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, colors, mode, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, null, paint);

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKSamplingOptions sampling, SKPaint paint = null) =>
DrawAtlas (atlas, sprites, transforms, colors, mode, sampling, null, paint);

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKRect cullRect, SKPaint paint = null) =>
#pragma warning disable CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, colors, mode, paint?.FilterQuality.ToSamplingOptions() ?? SKSamplingOptions.Default, &cullRect, paint);
#pragma warning restore CS0618 // 'SKPaint.FilterQuality' is obsolete: 'Use SKSamplingOptions instead.'
DrawAtlas (atlas, sprites, transforms, colors, mode, paint?.GetLegacyFilterQualitySampling () ?? SKSamplingOptions.Default, &cullRect, paint);

public void DrawAtlas (SKImage atlas, SKRect[] sprites, SKRotationScaleMatrix[] transforms, SKColor[] colors, SKBlendMode mode, SKSamplingOptions sampling, SKRect cullRect, SKPaint paint = null) =>
DrawAtlas (atlas, sprites, transforms, colors, mode, sampling, &cullRect, paint);
Expand Down
8 changes: 4 additions & 4 deletions binding/SkiaSharp/SKImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,14 @@ public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKMatr
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling) =>
ToShader (tileX, tileY, sampling, null);

[Obsolete ("Use ToShader(SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling) instead.")]
[Obsolete ("Use ToShader(SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling) instead.", error: true)]
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKFilterQuality quality) =>
ToShader (tileX, tileY, quality.ToSamplingOptions(), null);

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

[Obsolete ("Use ToShader(SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling, SKMatrix localMatrix) instead.")]
[Obsolete ("Use ToShader(SKShaderTileMode tileX, SKShaderTileMode tileY, SKSamplingOptions sampling, SKMatrix localMatrix) instead.", error: true)]
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY, SKFilterQuality quality, SKMatrix localMatrix) =>
ToShader (tileX, tileY, quality.ToSamplingOptions(), &localMatrix);

Expand Down Expand Up @@ -515,11 +515,11 @@ public bool ReadPixels (SKPixmap pixmap, int srcX, int srcY, SKImageCachingHint

// ScalePixels

[Obsolete("Use ScalePixels(SKPixmap dst, SKSamplingOptions sampling) instead.")]
[Obsolete("Use ScalePixels(SKPixmap dst, SKSamplingOptions sampling) instead.", error: true)]
public bool ScalePixels (SKPixmap dst, SKFilterQuality quality) =>
ScalePixels (dst, quality.ToSamplingOptions ());

[Obsolete("Use ScalePixels(SKPixmap dst, SKSamplingOptions sampling, SKImageCachingHint cachingHint) instead.")]
[Obsolete("Use ScalePixels(SKPixmap dst, SKSamplingOptions sampling, SKImageCachingHint cachingHint) instead.", error: true)]
public bool ScalePixels (SKPixmap dst, SKFilterQuality quality, SKImageCachingHint cachingHint) =>
ScalePixels (dst, quality.ToSamplingOptions (), cachingHint);

Expand Down
6 changes: 3 additions & 3 deletions binding/SkiaSharp/SKImageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType al

public readonly int BitsPerPixel => BytesPerPixel * 8;

public readonly int BytesSize => Width * Height * BytesPerPixel;
public readonly int BytesSize => checked(Width * Height * BytesPerPixel);

public readonly long BytesSize64 => (long)Width * (long)Height * (long)BytesPerPixel;

public readonly int RowBytes => Width * BytesPerPixel;
public readonly int RowBytes => checked(Width * BytesPerPixel);

public readonly long RowBytes64 => (long)Width * (long)BytesPerPixel;

Expand All @@ -128,7 +128,7 @@ public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType al
internal readonly int GetPixelBytesOffset (int x, int y) =>
ColorType == SKColorType.Unknown
? 0
: y * RowBytes + (x << ColorType.GetBitShiftPerPixel ());
: checked(y * RowBytes + (x << ColorType.GetBitShiftPerPixel ()));

public readonly SKImageInfo WithSize (SKSizeI size) =>
WithSize (size.Width, size.Height);
Expand Down
Loading
Loading