Merge branch 'master' into update-m58

# Conflicts:
#	externals/skia
This commit is contained in:
Matthew Leibowitz 2017-05-11 20:15:14 -05:00
Родитель 402d0bf3fa 478a8665ec
Коммит 81491dd62a
18 изменённых файлов: 693 добавлений и 186 удалений

Просмотреть файл

@ -20,6 +20,7 @@
<Compile Include="$(MSBuildThisFileDirectory)SKObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKImageFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKColorFilter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKColorSpace.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKPaint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKDocument.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SKPathEffect.cs" />

Просмотреть файл

@ -1828,124 +1828,124 @@ namespace SkiaSharp
[StructLayout(LayoutKind.Sequential)]
public struct GRContextOptions {
[MarshalAs(UnmanagedType.I1)]
private bool suppressPrints;
private int maxTextureSizeOverride;
private int maxTileSizeOverride;
private bool fSuppressPrints;
private int fMaxTextureSizeOverride;
private int fMaxTileSizeOverride;
[MarshalAs(UnmanagedType.I1)]
private bool suppressDualSourceBlending;
private int bufferMapThreshold;
private bool fSuppressDualSourceBlending;
private int fBufferMapThreshold;
[MarshalAs(UnmanagedType.I1)]
private bool useDrawInsteadOfPartialRenderTargetWrite;
private bool fUseDrawInsteadOfPartialRenderTargetWrite;
[MarshalAs(UnmanagedType.I1)]
private bool immediateMode;
private bool fImmediateMode;
[MarshalAs(UnmanagedType.I1)]
private bool clipBatchToBounds;
private bool fClipDrawOpsToBounds;
private int fMaxOpCombineLookback;
private int fMaxOpCombineLookahead;
[MarshalAs(UnmanagedType.I1)]
private bool drawBatchBounds;
private int maxBatchLookback;
private int maxBatchLookahead;
private bool fUseShaderSwizzling;
[MarshalAs(UnmanagedType.I1)]
private bool useShaderSwizzling;
private bool fDoManualMipmapping;
[MarshalAs(UnmanagedType.I1)]
private bool doManualMipmapping;
private bool fEnableInstancedRendering;
[MarshalAs(UnmanagedType.I1)]
private bool enableInstancedRendering;
private bool fDisableDistanceFieldPaths;
[MarshalAs(UnmanagedType.I1)]
private bool disableDistanceFieldPaths;
private bool fAllowPathMaskCaching;
[MarshalAs(UnmanagedType.I1)]
private bool allowPathMaskCaching;
private bool fForceSWPathMasks;
[MarshalAs(UnmanagedType.I1)]
private bool forceSWPathMasks;
private bool fRequireDecodeDisableForSRGB;
public bool SuppressPrints {
get { return suppressPrints; }
set { suppressPrints = value; }
get { return fSuppressPrints; }
set { fSuppressPrints = value; }
}
public int MaxTextureSizeOverride {
get { return maxTextureSizeOverride; }
set { maxTextureSizeOverride = value; }
get { return fMaxTextureSizeOverride; }
set { fMaxTextureSizeOverride = value; }
}
public int MaxTileSizeOverride {
get { return maxTileSizeOverride; }
set { maxTileSizeOverride = value; }
get { return fMaxTileSizeOverride; }
set { fMaxTileSizeOverride = value; }
}
public bool SuppressDualSourceBlending {
get { return suppressDualSourceBlending; }
set { suppressDualSourceBlending = value; }
get { return fSuppressDualSourceBlending; }
set { fSuppressDualSourceBlending = value; }
}
public int BufferMapThreshold {
get { return bufferMapThreshold; }
set { bufferMapThreshold = value; }
get { return fBufferMapThreshold; }
set { fBufferMapThreshold = value; }
}
public bool UseDrawInsteadOfPartialRenderTargetWrite {
get { return useDrawInsteadOfPartialRenderTargetWrite; }
set { useDrawInsteadOfPartialRenderTargetWrite = value; }
get { return fUseDrawInsteadOfPartialRenderTargetWrite; }
set { fUseDrawInsteadOfPartialRenderTargetWrite = value; }
}
public bool ImmediateMode {
get { return immediateMode; }
set { immediateMode = value; }
get { return fImmediateMode; }
set { fImmediateMode = value; }
}
public bool ClipBatchToBounds {
get { return clipBatchToBounds; }
set { clipBatchToBounds = value; }
public bool ClipDrawOpsToBounds {
get { return fClipDrawOpsToBounds; }
set { fClipDrawOpsToBounds = value; }
}
public bool DrawBatchBounds {
get { return drawBatchBounds; }
set { drawBatchBounds = value; }
public int MaxOpCombineLookback {
get { return fMaxOpCombineLookback; }
set { fMaxOpCombineLookback = value; }
}
public int MaxBatchLookback {
get { return maxBatchLookback; }
set { maxBatchLookback = value; }
}
public int MaxBatchLookahead {
get { return maxBatchLookahead; }
set { maxBatchLookahead = value; }
public int MaxOpCombineLookahead {
get { return fMaxOpCombineLookahead; }
set { fMaxOpCombineLookahead = value; }
}
public bool UseShaderSwizzling {
get { return useShaderSwizzling; }
set { useShaderSwizzling = value; }
get { return fUseShaderSwizzling; }
set { fUseShaderSwizzling = value; }
}
public bool DoManualMipmapping {
get { return doManualMipmapping; }
set { doManualMipmapping = value; }
get { return fDoManualMipmapping; }
set { fDoManualMipmapping = value; }
}
public bool EnableInstancedRendering {
get { return enableInstancedRendering; }
set { enableInstancedRendering = value; }
get { return fEnableInstancedRendering; }
set { fEnableInstancedRendering = value; }
}
public bool DisableDistanceFieldPaths {
get { return disableDistanceFieldPaths; }
set { disableDistanceFieldPaths = value; }
get { return fDisableDistanceFieldPaths; }
set { fDisableDistanceFieldPaths = value; }
}
public bool AllowPathMaskCaching {
get { return allowPathMaskCaching; }
set { allowPathMaskCaching = value; }
get { return fAllowPathMaskCaching; }
set { fAllowPathMaskCaching = value; }
}
public bool ForceSWPathMasks {
get { return forceSWPathMasks; }
set { forceSWPathMasks = value; }
public bool ForceSoftwarePathMasks {
get { return fForceSWPathMasks; }
set { fForceSWPathMasks = value; }
}
public bool RequireDecodeDisableForSrgb {
get { return fRequireDecodeDisableForSRGB; }
set { fRequireDecodeDisableForSRGB = value; }
}
public static GRContextOptions Default {
get {
return new GRContextOptions {
suppressPrints = false,
maxTextureSizeOverride = int.MaxValue,
maxTileSizeOverride = 0,
suppressDualSourceBlending = false,
bufferMapThreshold = -1,
useDrawInsteadOfPartialRenderTargetWrite = false,
immediateMode = false,
clipBatchToBounds = false,
drawBatchBounds = false,
maxBatchLookback = -1,
maxBatchLookahead = -1,
useShaderSwizzling = false,
doManualMipmapping = false,
enableInstancedRendering = false,
disableDistanceFieldPaths = false,
allowPathMaskCaching = false,
forceSWPathMasks = false
fSuppressPrints = false,
fMaxTextureSizeOverride = 0x7FFFFFFF,
fMaxTileSizeOverride = 0,
fSuppressDualSourceBlending = false,
fBufferMapThreshold = -1,
fUseDrawInsteadOfPartialRenderTargetWrite = false,
fImmediateMode = false,
fClipDrawOpsToBounds = false,
fMaxOpCombineLookback = -1,
fMaxOpCombineLookahead = -1,
fUseShaderSwizzling = false,
fDoManualMipmapping = false,
fEnableInstancedRendering = false,
fDisableDistanceFieldPaths = false,
fAllowPathMaskCaching = false,
fForceSWPathMasks = false,
fRequireDecodeDisableForSRGB = true,
};
}
}
@ -2165,6 +2165,121 @@ namespace SkiaSharp
Binary,
}
public enum SKColorSpaceNamed {
Srgb,
AdobeRgb,
SrgbLinear,
}
public enum SKColorSpaceRenderTargetGamma {
Linear,
Srgb,
}
[StructLayout(LayoutKind.Sequential)]
public struct SKColorSpacePrimaries {
private float fRX, fRY;
private float fGX, fGY;
private float fBX, fBY;
private float fWX, fWY;
public SKColorSpacePrimaries (float rx, float ry, float gx, float gy, float bx, float by, float wx, float wy)
{
fRX = rx;
fRY = ry;
fGX = gx;
fGY = gy;
fBX = bx;
fBY = by;
fWX = wx;
fWY = wy;
}
public float RX {
get { return fRX; }
set { fRX = value; }
}
public float RY {
get { return fRY; }
set { fRY = value; }
}
public float GX {
get { return fGX; }
set { fGX = value; }
}
public float GY {
get { return fGY; }
set { fGY = value; }
}
public float BX {
get { return fBX; }
set { fBX = value; }
}
public float BY {
get { return fBY; }
set { fBY = value; }
}
public float WX {
get { return fWX; }
set { fWX = value; }
}
public float WY {
get { return fWY; }
set { fWY = value; }
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SKColorSpaceTransferFn {
private float fG;
private float fA;
private float fB;
private float fC;
private float fD;
private float fE;
private float fF;
public SKColorSpaceTransferFn (float g, float a, float b, float c, float d, float e, float f)
{
fG = g;
fA = a;
fB = b;
fC = c;
fD = d;
fE = e;
fF = f;
}
public float G {
get { return fG; }
set { fG = value; }
}
public float A {
get { return fA; }
set { fA = value; }
}
public float B {
get { return fB; }
set { fB = value; }
}
public float C {
get { return fC; }
set { fC = value; }
}
public float D {
get { return fD; }
set { fD = value; }
}
public float E {
get { return fE; }
set { fE = value; }
}
public float F {
get { return fF; }
set { fF = value; }
}
}
public enum SKEncodedInfoColor {
Gray,
GrayAlpha,

Просмотреть файл

@ -67,7 +67,8 @@ namespace SkiaSharp
public SKBitmap (SKImageInfo info, int rowBytes)
: this ()
{
if (!SkiaApi.sk_bitmap_try_alloc_pixels (Handle, ref info, (IntPtr)rowBytes)) {
var cinfo = SKImageInfoNative.FromManaged (ref info);
if (!SkiaApi.sk_bitmap_try_alloc_pixels (Handle, ref cinfo, (IntPtr)rowBytes)) {
throw new Exception (UnableToAllocatePixelsMessage);
}
}
@ -75,7 +76,8 @@ namespace SkiaSharp
public SKBitmap (SKImageInfo info, SKColorTable ctable)
: this ()
{
if (!SkiaApi.sk_bitmap_try_alloc_pixels_with_color_table (Handle, ref info, IntPtr.Zero, ctable != null ? ctable.Handle : IntPtr.Zero)) {
var cinfo = SKImageInfoNative.FromManaged (ref info);
if (!SkiaApi.sk_bitmap_try_alloc_pixels_with_color_table (Handle, ref cinfo, IntPtr.Zero, ctable != null ? ctable.Handle : IntPtr.Zero)) {
throw new Exception (UnableToAllocatePixelsMessage);
}
}
@ -211,9 +213,9 @@ namespace SkiaSharp
public SKImageInfo Info {
get {
SKImageInfo info;
SkiaApi.sk_bitmap_get_info (Handle, out info);
return info;
SKImageInfoNative cinfo;
SkiaApi.sk_bitmap_get_info (Handle, out cinfo);
return SKImageInfoNative.ToManaged (ref cinfo);
}
}
@ -233,6 +235,10 @@ namespace SkiaSharp
get { return Info.AlphaType; }
}
public SKColorSpace ColorSpace {
get { return Info.ColorSpace; }
}
public int BytesPerPixel {
get { return Info.BytesPerPixel; }
}
@ -335,7 +341,7 @@ namespace SkiaSharp
if (stream == null) {
throw new ArgumentNullException (nameof (stream));
}
return DecodeBounds (WrapManagedStream (stream));
return DecodeBounds (SKStream.WrapManagedStream (stream));
}
public static SKImageInfo DecodeBounds (SKStream stream)
@ -412,7 +418,7 @@ namespace SkiaSharp
if (stream == null) {
throw new ArgumentNullException (nameof (stream));
}
return Decode (WrapManagedStream (stream));
return Decode (SKStream.WrapManagedStream (stream));
}
public static SKBitmap Decode (Stream stream, SKImageInfo bitmapInfo)
@ -420,7 +426,7 @@ namespace SkiaSharp
if (stream == null) {
throw new ArgumentNullException (nameof (stream));
}
return Decode (WrapManagedStream (stream), bitmapInfo);
return Decode (SKStream.WrapManagedStream (stream), bitmapInfo);
}
public static SKBitmap Decode (SKStream stream)
@ -524,12 +530,13 @@ namespace SkiaSharp
public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKColorTable ctable, SKBitmapReleaseDelegate releaseProc, object context)
{
var cinfo = SKImageInfoNative.FromManaged (ref info);
IntPtr ct = ctable == null ? IntPtr.Zero : ctable.Handle;
if (releaseProc == null) {
return SkiaApi.sk_bitmap_install_pixels (Handle, ref info, pixels, (IntPtr)rowBytes, ct, IntPtr.Zero, IntPtr.Zero);
return SkiaApi.sk_bitmap_install_pixels (Handle, ref cinfo, pixels, (IntPtr)rowBytes, ct, IntPtr.Zero, IntPtr.Zero);
} else {
var ctx = new NativeDelegateContext (context, releaseProc);
return SkiaApi.sk_bitmap_install_pixels (Handle, ref info, pixels, (IntPtr)rowBytes, ct, releaseDelegate, ctx.NativeContext);
return SkiaApi.sk_bitmap_install_pixels (Handle, ref cinfo, pixels, (IntPtr)rowBytes, ct, releaseDelegate, ctx.NativeContext);
}
}
@ -618,21 +625,6 @@ namespace SkiaSharp
}
}
private static SKStream WrapManagedStream (Stream stream)
{
if (stream == null) {
throw new ArgumentNullException (nameof (stream));
}
// we will need a seekable stream, so buffer it if need be
if (stream.CanSeek) {
return new SKManagedStream (stream, true);
} else {
var buffered = new SKFrontBufferedStream (stream, SKCodec.MinBufferedBytesNeeded, true);
return new SKManagedStream (buffered, true);
}
}
// internal proxy
#if __IOS__

Просмотреть файл

@ -35,9 +35,9 @@ namespace SkiaSharp
public SKImageInfo Info {
get {
SKImageInfo info;
SkiaApi.sk_codec_get_info (Handle, out info);
return info;
SKImageInfoNative cinfo;
SkiaApi.sk_codec_get_info (Handle, out cinfo);
return SKImageInfoNative.ToManaged (ref cinfo);
}
}
@ -141,7 +141,8 @@ namespace SkiaSharp
var subset = options.Subset.Value;
nativeOptions.fSubset = &subset;
}
return SkiaApi.sk_codec_get_pixels (Handle, ref info, pixels, (IntPtr)rowBytes, ref nativeOptions, colorTable, ref colorTableCount);
var cinfo = SKImageInfoNative.FromManaged (ref info);
return SkiaApi.sk_codec_get_pixels (Handle, ref cinfo, pixels, (IntPtr)rowBytes, ref nativeOptions, colorTable, ref colorTableCount);
}
public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, SKCodecOptions options)
@ -196,7 +197,8 @@ namespace SkiaSharp
var subset = options.Subset.Value;
nativeOptions.fSubset = &subset;
}
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref info, pixels, (IntPtr)rowBytes, ref nativeOptions, colorTable, ref colorTableCount);
var cinfo = SKImageInfoNative.FromManaged (ref info);
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref cinfo, pixels, (IntPtr)rowBytes, ref nativeOptions, colorTable, ref colorTableCount);
}
public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, int rowBytes, SKCodecOptions options)
@ -207,7 +209,8 @@ namespace SkiaSharp
public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, int rowBytes)
{
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref info, pixels, (IntPtr)rowBytes, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
var cinfo = SKImageInfoNative.FromManaged (ref info);
return SkiaApi.sk_codec_start_incremental_decode (Handle, ref cinfo, pixels, (IntPtr)rowBytes, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
public unsafe SKCodecResult StartIncrementalDecode(SKImageInfo info, IntPtr pixels, int rowBytes, SKCodecOptions options, SKColorTable colorTable, ref int colorTableCount)
@ -238,7 +241,8 @@ namespace SkiaSharp
var subset = options.Subset.Value;
nativeOptions.fSubset = &subset;
}
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref info, ref nativeOptions, colorTable, ref colorTableCount);
var cinfo = SKImageInfoNative.FromManaged (ref info);
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref cinfo, ref nativeOptions, colorTable, ref colorTableCount);
}
public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions options)
@ -249,7 +253,8 @@ namespace SkiaSharp
public SKCodecResult StartScanlineDecode (SKImageInfo info)
{
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref info, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
var cinfo = SKImageInfoNative.FromManaged (ref info);
return SkiaApi.sk_codec_start_scanline_decode (Handle, ref cinfo, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions options, SKColorTable colorTable, ref int colorTableCount)

Просмотреть файл

@ -0,0 +1,102 @@
//
// Bindings for SKColorSpace
//
// Author:
// Matthew Leibowitz
//
// Copyright 2017 Xamarin Inc
//
using System;
namespace SkiaSharp
{
public class SKColorSpace : SKObject
{
[Preserve]
internal SKColorSpace (IntPtr handle, bool owns)
: base (handle, owns)
{
}
protected override void Dispose (bool disposing)
{
if (Handle != IntPtr.Zero && OwnsHandle) {
SkiaApi.sk_colorspace_unref (Handle);
}
base.Dispose (disposing);
}
public bool GammaIsCloseToSrgb => SkiaApi.sk_colorspace_gamma_close_to_srgb (Handle);
public bool GammaIsLinear => SkiaApi.sk_colorspace_gamma_is_linear (Handle);
public static bool Equal (SKColorSpace left, SKColorSpace right)
{
if (left == null) {
throw new ArgumentNullException (nameof (left));
}
if (right == null) {
throw new ArgumentNullException (nameof (right));
}
return SkiaApi.sk_colorspace_equals (left.Handle, right.Handle);
}
public static SKColorSpace CreateNamed (SKColorSpaceNamed name)
{
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_named (name));
}
public static SKColorSpace CreateIcc (IntPtr input, long length)
{
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_icc (input, (IntPtr)length));
}
public static SKColorSpace CreateIcc (byte[] input, long length)
{
if (input == null)
throw new ArgumentNullException (nameof (input));
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_icc (input, (IntPtr)length));
}
public static SKColorSpace CreateIcc (byte[] input)
{
if (input == null)
throw new ArgumentNullException (nameof (input));
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_icc (input, (IntPtr)input.Length));
}
public static SKColorSpace CreateRgb (SKColorSpaceRenderTargetGamma gamma, SKMatrix44 toXyzD50)
{
if (toXyzD50 == null)
throw new ArgumentNullException (nameof (toXyzD50));
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_rgb_with_gamma (gamma, toXyzD50.Handle));
}
public static SKColorSpace CreateRgb (SKColorSpaceTransferFn coeffs, SKMatrix44 toXyzD50)
{
if (toXyzD50 == null)
throw new ArgumentNullException (nameof (toXyzD50));
return GetObject<SKColorSpace> (SkiaApi.sk_colorspace_new_rgb_with_coeffs (ref coeffs, toXyzD50.Handle));
}
public static bool ConvertPrimariesToXyzD50 (SKColorSpacePrimaries primaries, SKMatrix44 toXyzD50)
{
if (toXyzD50 == null)
throw new ArgumentNullException (nameof (toXyzD50));
return SkiaApi.sk_colorspaceprimaries_to_xyzd50 (ref primaries, toXyzD50.Handle);
}
public static SKMatrix44 ConvertPrimariesToXyzD50 (SKColorSpacePrimaries primaries)
{
var xyzD50 = new SKMatrix44 ();
if (!ConvertPrimariesToXyzD50 (primaries, xyzD50)) {
xyzD50.Dispose ();
xyzD50 = null;
}
return xyzD50;
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
//
//
// Bindings for SKData
//
// Author:
@ -122,6 +122,77 @@ namespace SkiaSharp
return GetObject<SKData> (SkiaApi.sk_data_new_uninitialized ((IntPtr) size));
}
public static SKData Create (string filename)
{
if (string.IsNullOrEmpty (filename))
throw new ArgumentException ("The filename cannot be empty.", nameof (filename));
return GetObject<SKData> (SkiaApi.sk_data_new_from_file (filename));
}
public static SKData Create (Stream stream)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return Create (stream, stream.Length);
}
public static SKData Create (Stream stream, int length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return Create (SKStream.WrapManagedStream (stream), length);
}
public static SKData Create (Stream stream, ulong length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return Create (SKStream.WrapManagedStream (stream), length);
}
public static SKData Create (Stream stream, long length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return Create (SKStream.WrapManagedStream (stream), length);
}
public static SKData Create (SKStream stream)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return Create (stream, stream.Length);
}
public static SKData Create (SKStream stream, int length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return GetObject<SKData> (SkiaApi.sk_data_new_from_stream (stream.Handle, (IntPtr) length));
}
public static SKData Create (SKStream stream, ulong length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return GetObject<SKData> (SkiaApi.sk_data_new_from_stream (stream.Handle, (IntPtr) length));
}
public static SKData Create (SKStream stream, long length)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
return GetObject<SKData> (SkiaApi.sk_data_new_from_stream (stream.Handle, (IntPtr) length));
}
public static SKData Create (IntPtr address, int length)
{
return Create (address, length, null, null);

Просмотреть файл

@ -94,7 +94,8 @@ namespace SkiaSharp
throw new ArgumentNullException (nameof (pixels));
var ct = (ctable == null ? IntPtr.Zero : ctable.Handle);
var handle = SkiaApi.sk_image_new_raster_copy_with_colortable (ref info, pixels, (IntPtr) rowBytes, ct);
var cinfo = SKImageInfoNative.FromManaged (ref info);
var handle = SkiaApi.sk_image_new_raster_copy_with_colortable (ref cinfo, pixels, (IntPtr) rowBytes, ct);
return GetObject<SKImage> (handle);
}
@ -109,7 +110,8 @@ namespace SkiaSharp
{
if (data == null)
throw new ArgumentNullException (nameof (data));
return GetObject<SKImage> (SkiaApi.sk_image_new_raster_data (ref info, data.Handle, (IntPtr) rowBytes));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKImage> (SkiaApi.sk_image_new_raster_data (ref cinfo, data.Handle, (IntPtr) rowBytes));
}
public static SKImage FromPixels (SKImageInfo info, IntPtr pixels)
@ -307,7 +309,7 @@ namespace SkiaSharp
public int Height => SkiaApi.sk_image_get_height (Handle);
public uint UniqueId => SkiaApi.sk_image_get_unique_id (Handle);
public SKAlphaType AlphaType => SkiaApi.sk_image_get_alpha_type (Handle);
public bool IsAlphaOnly => SkiaApi.sk_image_is_alpha_only (Handle);
public bool IsAlphaOnly => SkiaApi.sk_image_is_alpha_only(Handle);
public SKShader ToShader (SKShaderTileMode tileX, SKShaderTileMode tileY)
{
@ -345,7 +347,8 @@ namespace SkiaSharp
public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX, int srcY, SKImageCachingHint cachingHint)
{
return SkiaApi.sk_image_read_pixels (Handle, ref dstInfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY, cachingHint);
var cinfo = SKImageInfoNative.FromManaged (ref dstInfo);
return SkiaApi.sk_image_read_pixels (Handle, ref cinfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY, cachingHint);
}
public bool ReadPixels (SKPixmap pixmap, int srcX, int srcY)

Просмотреть файл

@ -13,6 +13,48 @@ using System.Runtime.InteropServices;
namespace SkiaSharp
{
[StructLayout(LayoutKind.Sequential)]
internal struct SKImageInfoNative
{
public IntPtr fColorSpace;
public int fWidth;
public int fHeight;
public SKColorType fColorType;
public SKAlphaType fAlphaType;
public static void UpdateNative (ref SKImageInfo managed, ref SKImageInfoNative native)
{
native.fColorSpace = managed.ColorSpace == null ? IntPtr.Zero : managed.ColorSpace.Handle;
native.fWidth = managed.Width;
native.fHeight = managed.Height;
native.fColorType = managed.ColorType;
native.fAlphaType = managed.AlphaType;
}
public static SKImageInfoNative FromManaged (ref SKImageInfo managed)
{
return new SKImageInfoNative
{
fColorSpace = managed.ColorSpace == null ? IntPtr.Zero : managed.ColorSpace.Handle,
fWidth = managed.Width,
fHeight = managed.Height,
fColorType = managed.ColorType,
fAlphaType = managed.AlphaType,
};
}
public static SKImageInfo ToManaged (ref SKImageInfoNative native)
{
return new SKImageInfo
{
ColorSpace = SKObject.GetObject<SKColorSpace> (native.fColorSpace),
Width = native.fWidth,
Height = native.fHeight,
ColorType = native.fColorType,
AlphaType = native.fAlphaType,
};
}
}
public struct SKImageInfo
{
public static readonly SKImageInfo Empty;
@ -22,59 +64,56 @@ namespace SkiaSharp
public static readonly int PlatformColorGreenShift;
public static readonly int PlatformColorBlueShift;
private int width;
private int height;
private SKColorType colorType;
private SKAlphaType alphaType;
static SKImageInfo ()
{
PlatformColorType = SkiaApi.sk_colortype_get_default_8888 ();
SkiaApi.sk_color_get_bit_shift (out PlatformColorAlphaShift, out PlatformColorRedShift, out PlatformColorGreenShift, out PlatformColorBlueShift);
}
public int Width {
get { return width; }
set { width = value; }
}
public int Width { get; set; }
public int Height {
get { return height; }
set { height = value; }
}
public int Height { get; set; }
public SKColorType ColorType {
get { return colorType; }
set { colorType = value; }
}
public SKColorType ColorType { get; set; }
public SKAlphaType AlphaType {
get { return alphaType; }
set { alphaType = value; }
}
public SKAlphaType AlphaType { get; set; }
public SKColorSpace ColorSpace { get; set; }
public SKImageInfo (int width, int height)
{
this.width = width;
this.height = height;
this.colorType = PlatformColorType;
this.alphaType = SKAlphaType.Premul;
Width = width;
Height = height;
ColorType = PlatformColorType;
AlphaType = SKAlphaType.Premul;
ColorSpace = null;
}
public SKImageInfo (int width, int height, SKColorType colorType)
{
this.width = width;
this.height = height;
this.colorType = colorType;
this.alphaType = SKAlphaType.Premul;
Width = width;
Height = height;
ColorType = colorType;
AlphaType = SKAlphaType.Premul;
ColorSpace = null;
}
public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType alphaType)
{
this.width = width;
this.height = height;
this.colorType = colorType;
this.alphaType = alphaType;
Width = width;
Height = height;
ColorType = colorType;
AlphaType = alphaType;
ColorSpace = null;
}
public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType alphaType, SKColorSpace colorspace)
{
Width = width;
Height = height;
ColorType = colorType;
AlphaType = alphaType;
ColorSpace = colorspace;
}
public int BytesPerPixel {

Просмотреть файл

@ -37,8 +37,10 @@ namespace SkiaSharp
}
public SKPixmap (SKImageInfo info, IntPtr addr, int rowBytes, SKColorTable ctable = null)
: this (SkiaApi.sk_pixmap_new_with_params (ref info, addr, (IntPtr)rowBytes, ctable == null ? IntPtr.Zero : ctable.Handle), true)
: this (IntPtr.Zero, true)
{
var cinfo = SKImageInfoNative.FromManaged (ref info);
Handle = SkiaApi.sk_pixmap_new_with_params (ref cinfo, addr, (IntPtr)rowBytes, ctable == null ? IntPtr.Zero : ctable.Handle);
if (Handle == IntPtr.Zero) {
throw new InvalidOperationException (UnableToCreateInstanceMessage);
}
@ -60,14 +62,15 @@ namespace SkiaSharp
public void Reset (SKImageInfo info, IntPtr addr, int rowBytes, SKColorTable ctable = null)
{
SkiaApi.sk_pixmap_reset_with_params (Handle, ref info, addr, (IntPtr)rowBytes, ctable == null ? IntPtr.Zero : ctable.Handle);
var cinfo = SKImageInfoNative.FromManaged (ref info);
SkiaApi.sk_pixmap_reset_with_params (Handle, ref cinfo, addr, (IntPtr)rowBytes, ctable == null ? IntPtr.Zero : ctable.Handle);
}
public SKImageInfo Info {
get {
SKImageInfo info;
SkiaApi.sk_pixmap_get_info (Handle, out info);
return info;
SKImageInfoNative cinfo;
SkiaApi.sk_pixmap_get_info (Handle, out cinfo);
return SKImageInfoNative.ToManaged (ref cinfo);
}
}
@ -87,6 +90,10 @@ namespace SkiaSharp
get { return Info.AlphaType; }
}
public SKColorSpace ColorSpace {
get { return Info.ColorSpace; }
}
public int BytesPerPixel {
get { return Info.BytesPerPixel; }
}

Просмотреть файл

@ -7,6 +7,7 @@
// Copyright 2016 Xamarin Inc
//
using System;
using System.IO;
namespace SkiaSharp
{
@ -118,6 +119,21 @@ namespace SkiaSharp
return (int)SkiaApi.sk_stream_get_length (Handle);
}
}
internal static SKStream WrapManagedStream (Stream stream)
{
if (stream == null) {
throw new ArgumentNullException (nameof (stream));
}
// we will need a seekable stream, so buffer it if need be
if (stream.CanSeek) {
return new SKManagedStream (stream, true);
} else {
var buffered = new SKFrontBufferedStream (stream, SKCodec.MinBufferedBytesNeeded, true);
return new SKManagedStream (buffered, true);
}
}
}
public abstract class SKStreamRewindable : SKStream

Просмотреть файл

@ -26,22 +26,26 @@ namespace SkiaSharp
public static SKSurface Create (SKImageInfo info)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster (ref info, IntPtr.Zero));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster (ref cinfo, IntPtr.Zero));
}
public static SKSurface Create (SKImageInfo info, SKSurfaceProps props)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster (ref info, ref props));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster (ref cinfo, ref props));
}
public static SKSurface Create (SKImageInfo info, IntPtr pixels, int rowBytes)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster_direct (ref info, pixels, (IntPtr)rowBytes, IntPtr.Zero));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster_direct (ref cinfo, pixels, (IntPtr)rowBytes, IntPtr.Zero));
}
public static SKSurface Create (SKImageInfo info, IntPtr pixels, int rowBytes, SKSurfaceProps props)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster_direct (ref info, pixels, (IntPtr)rowBytes, ref props));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_raster_direct (ref cinfo, pixels, (IntPtr)rowBytes, ref props));
}
public static SKSurface Create (GRContext context, GRBackendRenderTargetDesc desc, SKSurfaceProps props)
@ -76,17 +80,20 @@ namespace SkiaSharp
public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, SKSurfaceProps props)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref info, sampleCount, ref props));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref cinfo, sampleCount, ref props));
}
public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref info, sampleCount, IntPtr.Zero));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref cinfo, sampleCount, IntPtr.Zero));
}
public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info)
{
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref info, 0, IntPtr.Zero));
var cinfo = SKImageInfoNative.FromManaged (ref info);
return GetObject<SKSurface> (SkiaApi.sk_surface_new_render_target (context.Handle, budgeted, ref cinfo, 0, IntPtr.Zero));
}
protected override void Dispose (bool disposing)
@ -147,7 +154,8 @@ namespace SkiaSharp
public bool ReadPixels (SKImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX, int srcY)
{
return SkiaApi.sk_surface_read_pixels (Handle, ref dstInfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY);
var cinfo = SKImageInfoNative.FromManaged (ref dstInfo);
return SkiaApi.sk_surface_read_pixels (Handle, ref cinfo, dstPixels, (IntPtr)dstRowBytes, srcX, srcY);
}
}
}

Просмотреть файл

@ -81,19 +81,50 @@ namespace SkiaSharp
private const string SKIA = "libSkiaSharp";
#endif
// ColorSpace
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_colorspace_unref(sk_colorspace_t cColorSpace);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_colorspace_gamma_close_to_srgb(sk_colorspace_t cColorSpace);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_colorspace_gamma_is_linear(sk_colorspace_t cColorSpace);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_colorspace_equals(sk_colorspace_t src, sk_colorspace_t dst);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colorspace_t sk_colorspace_new_named(SKColorSpaceNamed named);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colorspace_t sk_colorspace_new_icc(IntPtr input, IntPtr len);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colorspace_t sk_colorspace_new_icc(byte[] input, IntPtr len);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colorspace_t sk_colorspace_new_rgb_with_gamma(SKColorSpaceRenderTargetGamma gamma, sk_matrix44_t toXYZD50);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colorspace_t sk_colorspace_new_rgb_with_coeffs(ref SKColorSpaceTransferFn coeffs, sk_matrix44_t toXYZD50);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_colorspaceprimaries_to_xyzd50(ref SKColorSpacePrimaries primaries, sk_matrix44_t toXYZD50);
// ColorType
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKColorType sk_colortype_get_default_8888();
// Surface
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_surface_unref(sk_surface_t t);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_raster(ref SKImageInfo info, ref SKSurfaceProps pros);
public extern static sk_surface_t sk_surface_new_raster(ref SKImageInfoNative info, ref SKSurfaceProps pros);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_raster(ref SKImageInfo info, IntPtr propsZero);
public extern static sk_surface_t sk_surface_new_raster(ref SKImageInfoNative info, IntPtr propsZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_raster_direct(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, ref SKSurfaceProps props);
public extern static sk_surface_t sk_surface_new_raster_direct(ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, ref SKSurfaceProps props);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_raster_direct(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, IntPtr propsZero);
public extern static sk_surface_t sk_surface_new_raster_direct(ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, IntPtr propsZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_canvas_t sk_surface_get_canvas(sk_surface_t t);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -111,9 +142,9 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_backend_texture_as_render_target (gr_context_t context, ref GRBackendTextureDesc desc, IntPtr propsZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_render_target (gr_context_t context, bool budgeted, ref SKImageInfo info, int sampleCount, ref SKSurfaceProps props);
public extern static sk_surface_t sk_surface_new_render_target (gr_context_t context, bool budgeted, ref SKImageInfoNative info, int sampleCount, ref SKSurfaceProps props);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_surface_t sk_surface_new_render_target (gr_context_t context, bool budgeted, ref SKImageInfo info, int sampleCount, IntPtr propsZero);
public extern static sk_surface_t sk_surface_new_render_target (gr_context_t context, bool budgeted, ref SKImageInfoNative info, int sampleCount, IntPtr propsZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_surface_draw(sk_surface_t surface, sk_canvas_t canvas, float x, float y, sk_paint_t paint);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -121,7 +152,7 @@ namespace SkiaSharp
public extern static bool sk_surface_peek_pixels(sk_surface_t surface, sk_pixmap_t pixmap);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_surface_read_pixels(sk_surface_t surface, ref SKImageInfo dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY);
public extern static bool sk_surface_read_pixels(sk_surface_t surface, ref SKImageInfoNative dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_surface_get_props(sk_surface_t surface, out SKSurfaceProps props);
@ -436,13 +467,13 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_image_unref(sk_image_t image);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster_copy(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes);
public extern static sk_image_t sk_image_new_raster_copy(ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster_copy_with_pixmap(sk_pixmap_t pixmap);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster_copy_with_colortable(ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, sk_colortable_t ctable);
public extern static sk_image_t sk_image_new_raster_copy_with_colortable(ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, sk_colortable_t ctable);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster_data(ref SKImageInfo info, sk_data_t pixels, IntPtr rowBytes);
public extern static sk_image_t sk_image_new_raster_data(ref SKImageInfoNative info, sk_data_t pixels, IntPtr rowBytes);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_image_t sk_image_new_raster(sk_pixmap_t pixmap, IntPtr releaseProc, IntPtr context);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -482,7 +513,7 @@ namespace SkiaSharp
public extern static bool sk_image_is_texture_backed(sk_image_t image);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_image_read_pixels(sk_image_t image, ref SKImageInfo dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY, SKImageCachingHint cachingHint);
public extern static bool sk_image_read_pixels(sk_image_t image, ref SKImageInfoNative dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY, SKImageCachingHint cachingHint);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_image_read_pixels_into_pixmap(sk_image_t image, sk_pixmap_t dst, int srcX, int srcY, SKImageCachingHint cachingHint);
@ -1142,7 +1173,7 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_codec_destroy(sk_codec_t codec);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_codec_get_info(sk_codec_t codec, out SKImageInfo info);
public extern static void sk_codec_get_info(sk_codec_t codec, out SKImageInfoNative info);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_codec_get_encodedinfo(sk_codec_t codec, out SKEncodedInfo info);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -1155,15 +1186,15 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKEncodedImageFormat sk_codec_get_encoded_format(sk_codec_t codec);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_get_pixels(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
public extern static SKCodecResult sk_codec_get_pixels(sk_codec_t codec, ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_get_pixels_using_defaults(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes);
public extern static SKCodecResult sk_codec_get_pixels_using_defaults(sk_codec_t codec, ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctableZero, IntPtr ctableCountZero);
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, ref SKCodecOptionsInternal options, IntPtr ctableZero, IntPtr ctableCountZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, IntPtr optionsZero, IntPtr ctableZero, IntPtr ctableCountZero);
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfoNative info, IntPtr pixels, IntPtr rowBytes, IntPtr optionsZero, IntPtr ctableZero, IntPtr ctableCountZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_incremental_decode(sk_codec_t codec, out int rowsDecoded);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -1173,11 +1204,11 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_codec_get_frame_info(sk_codec_t codec, [Out] SKCodecFrameInfo[] frameInfo);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfo info, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfoNative info, ref SKCodecOptionsInternal options, IntPtr ctable, ref int ctableCount);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfo info, ref SKCodecOptionsInternal options, IntPtr ctableZero, IntPtr ctableCountZero);
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfoNative info, ref SKCodecOptionsInternal options, IntPtr ctableZero, IntPtr ctableCountZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfo info, IntPtr optionsZero, IntPtr ctableZero, IntPtr ctableCountZero);
public extern static SKCodecResult sk_codec_start_scanline_decode(sk_codec_t codec, ref SKImageInfoNative info, IntPtr optionsZero, IntPtr ctableZero, IntPtr ctableCountZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_codec_get_scanlines(sk_codec_t codec, IntPtr dst, int countLines, IntPtr rowBytes);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -1196,7 +1227,7 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_bitmap_destructor(sk_bitmap_t b);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_bitmap_get_info(sk_bitmap_t b, out SKImageInfo info);
public extern static void sk_bitmap_get_info(sk_bitmap_t b, out SKImageInfoNative info);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr sk_bitmap_get_pixels(sk_bitmap_t b, out IntPtr length);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -1258,7 +1289,7 @@ namespace SkiaSharp
public extern static void sk_bitmap_unlock_pixels(sk_bitmap_t b);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_bitmap_install_pixels(sk_bitmap_t cbitmap, ref SKImageInfo cinfo, IntPtr pixels, IntPtr rowBytes, sk_colortable_t ctable, IntPtr releaseProc, IntPtr context);
public extern static bool sk_bitmap_install_pixels(sk_bitmap_t cbitmap, ref SKImageInfoNative cinfo, IntPtr pixels, IntPtr rowBytes, sk_colortable_t ctable, IntPtr releaseProc, IntPtr context);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_bitmap_install_pixels_with_pixmap(sk_bitmap_t cbitmap, sk_pixmap_t cpixmap);
@ -1267,10 +1298,10 @@ namespace SkiaSharp
public extern static bool sk_bitmap_install_mask_pixels(sk_bitmap_t cbitmap, ref SKMask cmask);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_bitmap_try_alloc_pixels(sk_bitmap_t cbitmap, ref SKImageInfo requestedInfo, IntPtr rowBytes);
public extern static bool sk_bitmap_try_alloc_pixels(sk_bitmap_t cbitmap, ref SKImageInfoNative requestedInfo, IntPtr rowBytes);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_bitmap_try_alloc_pixels_with_color_table(sk_bitmap_t cbitmap, ref SKImageInfo requestedInfo, sk_pixelref_factory_t factory, sk_colortable_t ctable);
public extern static bool sk_bitmap_try_alloc_pixels_with_color_table(sk_bitmap_t cbitmap, ref SKImageInfoNative requestedInfo, sk_pixelref_factory_t factory, sk_colortable_t ctable);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_colortable_t sk_bitmap_get_colortable(sk_bitmap_t cbitmap);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@ -1311,13 +1342,13 @@ namespace SkiaSharp
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_pixmap_t sk_pixmap_new();
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_pixmap_t sk_pixmap_new_with_params(ref SKImageInfo cinfo, IntPtr addr, IntPtr rowBytes, sk_colortable_t ctable);
public extern static sk_pixmap_t sk_pixmap_new_with_params(ref SKImageInfoNative cinfo, IntPtr addr, IntPtr rowBytes, sk_colortable_t ctable);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_pixmap_reset(sk_pixmap_t cpixmap);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_pixmap_reset_with_params(sk_pixmap_t cpixmap, ref SKImageInfo cinfo, IntPtr addr, IntPtr rowBytes, sk_colortable_t ctable);
public extern static void sk_pixmap_reset_with_params(sk_pixmap_t cpixmap, ref SKImageInfoNative cinfo, IntPtr addr, IntPtr rowBytes, sk_colortable_t ctable);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_pixmap_get_info(sk_pixmap_t cpixmap, out SKImageInfo cinfo);
public extern static void sk_pixmap_get_info(sk_pixmap_t cpixmap, out SKImageInfoNative cinfo);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr sk_pixmap_get_row_bytes(sk_pixmap_t cpixmap);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]

2
externals/skia поставляемый

@ -1 +1 @@
Subproject commit fac4578a01692174a354a4b18cf24e23f4ef6d3c
Subproject commit 801343076bc02c67ed64845ffc8b0cd9f96477ec

Просмотреть файл

@ -13,6 +13,7 @@
#include "sk_canvas.h"
#include "sk_codec.h"
#include "sk_colorfilter.h"
#include "sk_colorspace.h"
#include "sk_colortable.h"
#include "sk_data.h"
#include "sk_document.h"
@ -50,6 +51,7 @@ void** KeepSkiaCSymbols ()
(void*)sk_canvas_destroy,
(void*)sk_codec_min_buffered_bytes_needed,
(void*)sk_colorfilter_unref,
(void*)sk_colorspace_unref,
(void*)sk_colortable_unref,
(void*)sk_data_new_empty,
(void*)sk_document_unref,

Двоичные данные
tests/Content/images/map.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 791 KiB

Просмотреть файл

@ -170,6 +170,10 @@
<Link>images\CMYK.jpg</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\Content\images\map.png">
<Link>images\map.png</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -0,0 +1,39 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using NUnit.Framework;
namespace SkiaSharp.Tests
{
public class SKColorSpaceTest : SKTest
{
[Test]
public void CanCreateSrgb()
{
var colorspace = SKColorSpace.CreateNamed(SKColorSpaceNamed.Srgb);
Assert.IsNotNull(colorspace);
Assert.IsTrue(SKColorSpace.Equal(colorspace, colorspace));
}
[Test]
public void ImageInfoHasColorSpace()
{
var colorspace = SKColorSpace.CreateNamed(SKColorSpaceNamed.Srgb);
var info = new SKImageInfo(100, 100, SKImageInfo.PlatformColorType, SKAlphaType.Premul, colorspace);
Assert.AreEqual(colorspace, info.ColorSpace);
var image = SKImage.Create(info);
Assert.AreEqual(colorspace, image.PeekPixels().ColorSpace);
}
[Test]
public void SrgbColorSpaceIsCloseToSrgb()
{
var colorspace = SKColorSpace.CreateNamed(SKColorSpaceNamed.Srgb);
Assert.IsTrue(colorspace.GammaIsCloseToSrgb);
}
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
@ -97,5 +98,76 @@ namespace SkiaSharp.Tests
Assert.AreEqual(SKColors.Black, bitmap.GetPixel(100, 89), "Non-Antialias (3)");
}
}
// Test for issue #282
[Ignore("Known to fail, see: https://github.com/mono/SkiaSharp/issues/282")]
[Test]
public void DrawTransparentImageWithHighFilterQualityWithUnpremul()
{
var oceanColor = (SKColor)0xFF9EB4D6;
var landColor = (SKColor)0xFFACB69B;
using (var bitmap = new SKBitmap(new SKImageInfo(300, 300)))
using (var canvas = new SKCanvas(bitmap))
{
canvas.Clear(oceanColor);
// decode the bitmap
var path = Path.Combine(PathToImages, "map.png");
using (var mapBitmap = SKBitmap.Decode(path))
using (var mapImage = SKImage.FromBitmap(mapBitmap))
{
var bounds = SKRect.Create(-259.9664f, -260.4489f, 1221.1876f, 1020.23273f);
// draw the bitmap
using (var paint = new SKPaint { FilterQuality = SKFilterQuality.High })
{
canvas.DrawImage(mapImage, bounds, paint);
}
}
// check values
Assert.AreEqual(oceanColor, bitmap.GetPixel(30, 30), "Ocean color");
Assert.AreEqual(landColor, bitmap.GetPixel(270, 270), "Land color");
}
}
// Test for the "workaround" for issue #282
[Test]
public void DrawTransparentImageWithHighFilterQualityWithPremul()
{
var oceanColor = (SKColor)0xFF9EB4D6;
var landColor = (SKColor)0xFFACB69B;
using (var bitmap = new SKBitmap(new SKImageInfo(300, 300)))
using (var canvas = new SKCanvas(bitmap))
{
canvas.Clear(oceanColor);
// decode the bitmap
var path = Path.Combine(PathToImages, "map.png");
using (var codec = SKCodec.Create(new SKFileStream(path)))
{
var info = new SKImageInfo(codec.Info.Width, codec.Info.Height);
using (var mapBitmap = SKBitmap.Decode(codec, info))
using (var mapImage = SKImage.FromBitmap(mapBitmap))
{
var bounds = SKRect.Create(-259.9664f, -260.4489f, 1221.1876f, 1020.23273f);
// draw the bitmap
using (var paint = new SKPaint { FilterQuality = SKFilterQuality.High })
{
canvas.DrawImage(mapImage, bounds, paint);
}
}
}
// check values
Assert.AreEqual(oceanColor, bitmap.GetPixel(30, 30), "Ocean color");
Assert.AreEqual(landColor, bitmap.GetPixel(270, 270), "Land color");
}
}
}
}