From 504a32e5d29aa103b6a103d57076d74b4131ae96 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 1 Jul 2022 17:34:05 +1000 Subject: [PATCH 01/33] add /.idea to git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c358466167..be8ad6baab 100644 --- a/.gitignore +++ b/.gitignore @@ -299,3 +299,4 @@ Carthage/Build fastlane/report.xml fastlane/screenshots +/.idea From de972eb09eb89fc97d4380580e10454b23722bf7 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 20:11:08 +1000 Subject: [PATCH 02/33] add SKPngChunkReader --- binding/Binding/SKPngChunkReader.cs | 159 ++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 binding/Binding/SKPngChunkReader.cs diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs new file mode 100644 index 0000000000..629980bc74 --- /dev/null +++ b/binding/Binding/SKPngChunkReader.cs @@ -0,0 +1,159 @@ +using System; +using System.ComponentModel; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; + +namespace SkiaSharp +{ + /// + /// Base class for optional callbacks to retrieve meta/chunk data out of a PNG + ///

encoded image as it is being decoded. + ///

Used by SkCodec. + ///
+ public unsafe abstract class SKPngChunkReader : SKObject, ISKSkipObjectRegistration + { + private static readonly SKManagedPngChunkReaderDelegates delegates; + private readonly IntPtr userData; + private int fromNative; + + static SKPngChunkReader() + { + delegates = new SKManagedPngChunkReaderDelegates + { + fReadChunk = ReadChunkInternal, + fDestroy = DestroyInternal, + }; + + SkiaApi.sk_managed_png_chunk_reader_set_procs(delegates); + } + + protected SKPngChunkReader() + : base(IntPtr.Zero, true) + { + userData = DelegateProxies.CreateUserData(this, true); + Handle = SkiaApi.sk_managed_png_chunk_reader_new((void*)userData); + + if (Handle == IntPtr.Zero) + throw new InvalidOperationException("Unable to create a new SKManagedAllocator instance."); + } + + protected override void Dispose(bool disposing) => + base.Dispose(disposing); + + protected override void DisposeNative() + { + if (Interlocked.CompareExchange(ref fromNative, 0, 0) == 0) + { + SkiaApi.sk_managed_png_chunk_reader_delete(Handle); + } + } + + /// + /// This will be called by the decoder when it sees an unknown chunk. + ///

+ ///

Use by SkCodec: + ///

Depending on the location of the unknown chunks, this callback may be + ///

called by + ///

- the factory (NewFromStream/NewFromData) + ///

- getPixels + ///

- startScanlineDecode + ///

- the first call to getScanlines/skipScanlines + ///

The callback may be called from a different thread (e.g. if the SkCodec + ///

is passed to another thread), and it may be called multiple times, if + ///

the SkCodec is used multiple times. + ///

+ ///

@param tag Name for this type of chunk. + ///

@param data Data to be interpreted by the subclass. + ///

@param length Number of bytes of data in the chunk. + ///

@return true to continue decoding, or false to indicate an error, which + ///

will cause the decoder to not return the image. + ///
+ /// Name for this type of chunk. + /// Data to be interpreted by the subclass. + /// Number of bytes of data in the chunk. + /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. + public abstract bool ReadChunk(string tag, void* data, IntPtr length); + + /// + /// This will be called by the decoder when it sees an unknown chunk. + ///

+ ///

Use by SkCodec: + ///

Depending on the location of the unknown chunks, this callback may be + ///

called by + ///

- the factory (NewFromStream/NewFromData) + ///

- getPixels + ///

- startScanlineDecode + ///

- the first call to getScanlines/skipScanlines + ///

The callback may be called from a different thread (e.g. if the SkCodec + ///

is passed to another thread), and it may be called multiple times, if + ///

the SkCodec is used multiple times. + ///

+ ///

@param tag Name for this type of chunk. + ///

@param data Data to be interpreted by the subclass. + ///

@param length Number of bytes of data in the chunk. + ///

@return true to continue decoding, or false to indicate an error, which + ///

will cause the decoder to not return the image. + ///
+ /// Name for this type of chunk. + /// Data to be interpreted by the subclass. + /// Number of bytes of data in the chunk. + /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. + public virtual bool ReadChunk (string tag, IntPtr data, IntPtr length) + { + return ReadChunk (tag, data.ToPointer(), length); + } + + /// + /// This will be called by the decoder when it sees an unknown chunk. + ///

+ ///

Override this is you want to pass to C interop. + ///

+ ///

Use by SkCodec: + ///

Depending on the location of the unknown chunks, this callback may be + ///

called by + ///

- the factory (NewFromStream/NewFromData) + ///

- getPixels + ///

- startScanlineDecode + ///

- the first call to getScanlines/skipScanlines + ///

The callback may be called from a different thread (e.g. if the SkCodec + ///

is passed to another thread), and it may be called multiple times, if + ///

the SkCodec is used multiple times. + ///

+ ///

@param tag Name for this type of chunk. + ///

@param data Data to be interpreted by the subclass. + ///

@param length Number of bytes of data in the chunk. + ///

@return true to continue decoding, or false to indicate an error, which + ///

will cause the decoder to not return the image. + ///
+ /// Name for this type of chunk. + /// Data to be interpreted by the subclass. + /// Number of bytes of data in the chunk. + /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. + public virtual bool ReadChunk (void* tag, void* data, IntPtr length) + { + return ReadChunk (Marshal.PtrToStringAnsi((IntPtr)tag), data, length); + } + + // impl + + [MonoPInvokeCallback (typeof(SKManagedPngChunkReaderReadChunkProxyDelegate))] + private static bool ReadChunkInternal(IntPtr d, void* context, void* tag, void* data, IntPtr length) + { + var dump = DelegateProxies.GetUserData((IntPtr)context, out _); + return dump.ReadChunk(tag, data, length); + } + + [MonoPInvokeCallback(typeof(SKManagedPngChunkReaderDestroyProxyDelegate))] + private static void DestroyInternal(IntPtr s, void* context) + { + var id = DelegateProxies.GetUserData((IntPtr)context, out var gch); + if (id != null) + { + Interlocked.Exchange(ref id.fromNative, 1); + id.Dispose(); + } + gch.Free(); + } + } +} From bcf7b543b2698bd6275fc136bb409ca886d9aab7 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 20:32:12 +1000 Subject: [PATCH 03/33] add SKPngChunkReader bindings --- binding/Binding/SkiaApi.generated.cs | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index 8a70b54134..ea13186744 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -35,6 +35,7 @@ using sk_image_t = System.IntPtr; using sk_imagefilter_croprect_t = System.IntPtr; using sk_imagefilter_t = System.IntPtr; +using sk_managed_png_chunk_reader_t = System.IntPtr; using sk_manageddrawable_t = System.IntPtr; using sk_managedtracememorydump_t = System.IntPtr; using sk_maskfilter_t = System.IntPtr; @@ -54,6 +55,7 @@ using sk_picture_t = System.IntPtr; using sk_pixelref_factory_t = System.IntPtr; using sk_pixmap_t = System.IntPtr; +using sk_png_chunk_reader_t = System.IntPtr; using sk_refcnt_t = System.IntPtr; using sk_region_cliperator_t = System.IntPtr; using sk_region_iterator_t = System.IntPtr; @@ -13168,6 +13170,52 @@ internal static void sk_compatpaint_set_text_encoding (sk_compatpaint_t paint, S #endregion + #region sk_managed_png_chunk_reader.h + + // void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + } + private static Delegates.sk_managed_png_chunk_reader_delete sk_managed_png_chunk_reader_delete_delegate; + internal static void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0) => + (sk_managed_png_chunk_reader_delete_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_delete")).Invoke (param0); + #endif + + // sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + } + private static Delegates.sk_managed_png_chunk_reader_new sk_managed_png_chunk_reader_new_delegate; + internal static sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context) => + (sk_managed_png_chunk_reader_new_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_new")).Invoke (context); + #endif + + // void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs); + } + private static Delegates.sk_managed_png_chunk_reader_set_procs sk_managed_png_chunk_reader_set_procs_delegate; + internal static void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs) => + (sk_managed_png_chunk_reader_set_procs_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_set_procs")).Invoke (procs); + #endif + + #endregion + #region sk_manageddrawable.h // sk_manageddrawable_t* sk_manageddrawable_new(void* context) @@ -13392,6 +13440,15 @@ namespace SkiaSharp { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate void SKImageTextureReleaseProxyDelegate(void* context); + // typedef void (*)(sk_managed_png_chunk_reader_t* d, void* context)* sk_managed_png_chunk_reader_destroy_proc + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal unsafe delegate void SKManagedPngChunkReaderDestroyProxyDelegate(sk_managed_png_chunk_reader_t d, void* context); + + // typedef bool (*)(sk_managed_png_chunk_reader_t* d, void* context, const char[-1] tag, const void* data, size_t length)* sk_managed_png_chunk_reader_read_chunk_proc + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal unsafe delegate bool SKManagedPngChunkReaderReadChunkProxyDelegate(sk_managed_png_chunk_reader_t d, void* context, /* char */ void* tag, void* data, /* size_t */ IntPtr length); + // typedef void (*)(sk_manageddrawable_t* d, void* context)* sk_manageddrawable_destroy_proc [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate void SKManagedDrawableDestroyProxyDelegate(sk_manageddrawable_t d, void* context); @@ -14884,6 +14941,45 @@ public readonly override int GetHashCode () } + // sk_managed_png_chunk_reader_procs_t + [StructLayout (LayoutKind.Sequential)] + public unsafe partial struct SKManagedPngChunkReaderProcs : IEquatable { + // public sk_managed_png_chunk_reader_read_chunk_proc fReadChunk + private SKManagedPngChunkReaderReadChunkProxyDelegate fReadChunk; + public SKManagedPngChunkReaderReadChunkProxyDelegate ReadChunk { + readonly get => fReadChunk; + set => fReadChunk = value; + } + + // public sk_managed_png_chunk_reader_destroy_proc fDestroy + private SKManagedPngChunkReaderDestroyProxyDelegate fDestroy; + public SKManagedPngChunkReaderDestroyProxyDelegate Destroy { + readonly get => fDestroy; + set => fDestroy = value; + } + + public readonly bool Equals (SKManagedPngChunkReaderProcs obj) => + fReadChunk == obj.fReadChunk && fDestroy == obj.fDestroy; + + public readonly override bool Equals (object obj) => + obj is SKManagedPngChunkReaderProcs f && Equals (f); + + public static bool operator == (SKManagedPngChunkReaderProcs left, SKManagedPngChunkReaderProcs right) => + left.Equals (right); + + public static bool operator != (SKManagedPngChunkReaderProcs left, SKManagedPngChunkReaderProcs right) => + !left.Equals (right); + + public readonly override int GetHashCode () + { + var hash = new HashCode (); + hash.Add (fReadChunk); + hash.Add (fDestroy); + return hash.ToHashCode (); + } + + } + // sk_manageddrawable_procs_t [StructLayout (LayoutKind.Sequential)] internal unsafe partial struct SKManagedDrawableDelegates : IEquatable { From f7600dab4a2107929e8973de068208a8493dff34 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 20:56:38 +1000 Subject: [PATCH 04/33] add renamed SKPngChunkReader bindings --- binding/Binding/SkiaApi.generated.cs | 68 ++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index ea13186744..bc6f2a6bcd 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -13262,6 +13262,52 @@ internal static void sk_manageddrawable_unref (sk_manageddrawable_t param0) => #endregion + #region sk_managedpngchunkreader.h + + // void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + } + private static Delegates.sk_managed_png_chunk_reader_delete sk_managed_png_chunk_reader_delete_delegate; + internal static void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0) => + (sk_managed_png_chunk_reader_delete_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_delete")).Invoke (param0); + #endif + + // sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + } + private static Delegates.sk_managed_png_chunk_reader_new sk_managed_png_chunk_reader_new_delegate; + internal static sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context) => + (sk_managed_png_chunk_reader_new_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_new")).Invoke (context); + #endif + + // void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs); + } + private static Delegates.sk_managed_png_chunk_reader_set_procs sk_managed_png_chunk_reader_set_procs_delegate; + internal static void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs) => + (sk_managed_png_chunk_reader_set_procs_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_set_procs")).Invoke (procs); + #endif + + #endregion + #region sk_managedstream.h // void sk_managedstream_destroy(sk_stream_managedstream_t* s) @@ -14943,31 +14989,23 @@ public readonly override int GetHashCode () // sk_managed_png_chunk_reader_procs_t [StructLayout (LayoutKind.Sequential)] - public unsafe partial struct SKManagedPngChunkReaderProcs : IEquatable { + internal unsafe partial struct SKManagedPngChunkReaderDelegates : IEquatable { // public sk_managed_png_chunk_reader_read_chunk_proc fReadChunk - private SKManagedPngChunkReaderReadChunkProxyDelegate fReadChunk; - public SKManagedPngChunkReaderReadChunkProxyDelegate ReadChunk { - readonly get => fReadChunk; - set => fReadChunk = value; - } + public SKManagedPngChunkReaderReadChunkProxyDelegate fReadChunk; // public sk_managed_png_chunk_reader_destroy_proc fDestroy - private SKManagedPngChunkReaderDestroyProxyDelegate fDestroy; - public SKManagedPngChunkReaderDestroyProxyDelegate Destroy { - readonly get => fDestroy; - set => fDestroy = value; - } + public SKManagedPngChunkReaderDestroyProxyDelegate fDestroy; - public readonly bool Equals (SKManagedPngChunkReaderProcs obj) => + public readonly bool Equals (SKManagedPngChunkReaderDelegates obj) => fReadChunk == obj.fReadChunk && fDestroy == obj.fDestroy; public readonly override bool Equals (object obj) => - obj is SKManagedPngChunkReaderProcs f && Equals (f); + obj is SKManagedPngChunkReaderDelegates f && Equals (f); - public static bool operator == (SKManagedPngChunkReaderProcs left, SKManagedPngChunkReaderProcs right) => + public static bool operator == (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => left.Equals (right); - public static bool operator != (SKManagedPngChunkReaderProcs left, SKManagedPngChunkReaderProcs right) => + public static bool operator != (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => !left.Equals (right); public readonly override int GetHashCode () From 155a87aba37925661dbbf42cac2e33ec2ac08dc0 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 21:25:39 +1000 Subject: [PATCH 05/33] expose more of SKCodec --- binding/Binding/SKCodec.cs | 118 +++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 11 deletions(-) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 45f3c8ce49..9e748fac71 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -4,7 +4,6 @@ namespace SkiaSharp { - // TODO: `Create(...)` should have overloads that accept a SKPngChunkReader // TODO: missing the `QueryYuv8` and `GetYuv8Planes` members public unsafe class SKCodec : SKObject, ISKSkipObjectRegistration @@ -14,6 +13,25 @@ internal SKCodec (IntPtr handle, bool owns) { } + /// + /// For container formats that contain both still images and image sequences, + ///

instruct the decoder how the output should be selected. (Refer to comments + ///

for each value for more details.) + ///
+ public enum SelectionPolicy + { + /// + /// If the container format contains both still images and image sequences, + ///

SKCodec should choose one of the still images. This is the default. + ///
+ preferStillImage, + /// + /// If the container format contains both still images and image sequences, + ///

SKCodec should choose one of the image sequences for animation. + ///
+ preferAnimation + } + protected override void Dispose (bool disposing) => base.Dispose (disposing); @@ -42,6 +60,13 @@ public SKImageInfo Info { public SKEncodedImageFormat EncodedFormat => SkiaApi.sk_codec_get_encoded_format (Handle); + public SKSizeI Dimensions + { + get { + return Info.Size; + } + } + public SKSizeI GetScaledDimensions (float desiredScale) { SKSizeI dimensions; @@ -282,7 +307,27 @@ public int GetOutputScanline (int inputScanline) => public static SKCodec Create (string filename) => Create (filename, out var result); - public static SKCodec Create (string filename, out SKCodecResult result) + public static SKCodec Create(string filename, SKPngChunkReader chunkReader) => + Create(filename, out var result, chunkReader, SelectionPolicy.preferStillImage); + + public static SKCodec Create(string filename, SelectionPolicy selectionPolicy) => + Create(filename, out var result, null, selectionPolicy); + + public static SKCodec Create(string filename, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => + Create(filename, out var result, chunkReader, selectionPolicy); + + + + public static SKCodec Create(string filename, out SKCodecResult result) => + Create(filename, out result, null, SelectionPolicy.preferStillImage); + + public static SKCodec Create(string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => + Create (filename, out result, chunkReader, SelectionPolicy.preferStillImage); + + public static SKCodec Create(string filename, out SKCodecResult result, SelectionPolicy selectionPolicy) => + Create (filename, out result, null, selectionPolicy); + + public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) { var stream = SKFileStream.OpenStream (filename); if (stream == null) { @@ -290,40 +335,91 @@ public static SKCodec Create (string filename, out SKCodecResult result) return null; } - return Create (stream, out result); + return Create (stream, out result, chunkReader, selectionPolicy); } + + public static SKCodec Create (Stream stream) => Create (stream, out var result); + public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader) => + Create(stream, out var result, chunkReader); + + public static SKCodec Create(Stream stream, SelectionPolicy selectionPolicy) => + Create(stream, out var result, selectionPolicy); + + public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => + Create(stream, out var result, chunkReader, selectionPolicy); + + + public static SKCodec Create (Stream stream, out SKCodecResult result) => Create (WrapManagedStream (stream), out result); + public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => + Create(WrapManagedStream(stream), out result, chunkReader); + + public static SKCodec Create(Stream stream, out SKCodecResult result, SelectionPolicy selectionPolicy) => + Create(WrapManagedStream(stream), out result, selectionPolicy); + + public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => + Create(WrapManagedStream(stream), out result, chunkReader, selectionPolicy); + + + public static SKCodec Create (SKStream stream) => Create (stream, out var result); - public static SKCodec Create (SKStream stream, out SKCodecResult result) + public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader) => + Create(stream, out var result, chunkReader); + + public static SKCodec Create(SKStream stream, SelectionPolicy selectionPolicy) => + Create(stream, out var result, selectionPolicy); + + public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => + Create(stream, out var result, chunkReader, selectionPolicy); + + + + public static SKCodec Create(SKStream stream, out SKCodecResult result) => + Create(stream, out result, null); + + public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => + Create(stream, out result, chunkReader, SelectionPolicy.preferStillImage); + + public static SKCodec Create(SKStream stream, out SKCodecResult result, SelectionPolicy selectionPolicy) => + Create(stream, out result, null, selectionPolicy); + + public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) { if (stream == null) - throw new ArgumentNullException (nameof (stream)); + throw new ArgumentNullException(nameof(stream)); if (stream is SKFileStream filestream && !filestream.IsValid) - throw new ArgumentException ("File stream was not valid.", nameof(stream)); + throw new ArgumentException("File stream was not valid.", nameof(stream)); - fixed (SKCodecResult* r = &result) { - var codec = GetObject (SkiaApi.sk_codec_new_from_stream (stream.Handle, r)); - stream.RevokeOwnership (codec); + fixed (SKCodecResult* r = &result) + { + var codec = GetObject(SkiaApi.sk_codec_new_from_stream(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SKCodecSelectionPolicy)selectionPolicy)); + stream.RevokeOwnership(codec); return codec; } } + // create (data) public static SKCodec Create (SKData data) + { + return Create(data, null); + } + + public static SKCodec Create(SKData data, SKPngChunkReader chunkReader) { if (data == null) - throw new ArgumentNullException (nameof (data)); + throw new ArgumentNullException(nameof(data)); - return GetObject (SkiaApi.sk_codec_new_from_data (data.Handle)); + return GetObject(SkiaApi.sk_codec_new_from_data(data.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); } // utils From 996d8cf8bfcc80c4daa20257b0d65fdb604c4b11 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 21:28:45 +1000 Subject: [PATCH 06/33] expose more SKCodec bindings --- binding/Binding/SkiaApi.generated.cs | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index bc6f2a6bcd..80bce77658 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -2586,6 +2586,20 @@ internal static sk_codec_t sk_codec_new_from_data (sk_data_t data) => (sk_codec_new_from_data_delegate ??= GetSymbol ("sk_codec_new_from_data")).Invoke (data); #endif + // sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + } + private static Delegates.sk_codec_new_from_data_with_png_chunk_reader sk_codec_new_from_data_with_png_chunk_reader_delegate; + internal static sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader) => + (sk_codec_new_from_data_with_png_chunk_reader_delegate ??= GetSymbol ("sk_codec_new_from_data_with_png_chunk_reader")).Invoke (data, chunk_reader); + #endif + // sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -2600,6 +2614,20 @@ internal static sk_codec_t sk_codec_new_from_stream (sk_stream_t stream, SKCodec (sk_codec_new_from_stream_delegate ??= GetSymbol ("sk_codec_new_from_stream")).Invoke (stream, result); #endif + // sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy); + } + private static Delegates.sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy_delegate; + internal static sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy) => + (sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy_delegate ??= GetSymbol ("sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy")).Invoke (stream, result, chunk_reader, policy); + #endif + // int sk_codec_next_scanline(sk_codec_t* codec) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -15903,6 +15931,14 @@ public enum SKCodecScanlineOrder { BottomUp = 1, } + // sk_codec_selection_policy_t + public enum SKCodecSelectionPolicy { + // PREFER_STILL_IMAGE_SK_CODEC_SELECTION_POLICY = 0 + PreferStillImage = 0, + // PREFER_ANIMATION_SK_CODEC_SELECTION_POLICY = 1 + PreferAnimation = 1, + } + // sk_codec_zero_initialized_t public enum SKZeroInitialized { // YES_SK_CODEC_ZERO_INITIALIZED = 0 From 2285f86e0b667514d1149398b767f3d66adc0ca2 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 21:49:28 +1000 Subject: [PATCH 07/33] expose more of SKBitmap --- binding/Binding/SKBitmap.cs | 108 +++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 2 deletions(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 5883fa93c5..57b07169a2 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.IO; +using System.Threading; namespace SkiaSharp { @@ -37,8 +38,6 @@ public static SKFilterQuality ToFilterQuality (this SKBitmapResizeMethod method) } // TODO: keep in mind SKBitmap may be going away (according to Google) - // TODO: `ComputeIsOpaque` may be useful - // TODO: `GenerationID` may be useful // TODO: `GetAddr` and `GetPixel` are confusing public unsafe class SKBitmap : SKObject, ISKSkipObjectRegistration @@ -115,6 +114,76 @@ protected override void Dispose (bool disposing) => protected override void DisposeNative () => SkiaApi.sk_bitmap_destructor (Handle); + // Other + + internal static SKBitmap GetObject(IntPtr handle, bool owns = true, bool unrefExisting = true) => + GetOrAddObject(handle, owns, unrefExisting, (h, o) => new SKBitmap(h, o)); + + public bool SetInfo(SKImageInfo info) + { + // bool setInfo (const SkImageInfo &imageInfo, size_t rowBytes=0) + return SetInfo(info, 0); + } + + public bool SetInfo(SKImageInfo info, int rowBytes) + { + var cinfo = SKImageInfoNative.FromManaged(ref info); + return SkiaApi.sk_bitmap_set_info(Handle, &cinfo, (IntPtr)rowBytes); + } + + public bool ComputeIsOpaque() + { + return SkiaApi.sk_bitmap_compute_is_opaque(Handle); + } + + // AllocPixels + + public void AllocPixels() + { + AllocPixels((Allocator)null); + } + + public void AllocPixels(Allocator allocator) + { + if (!TryAllocPixels(allocator)) + { + SKImageInfo i = Info; + throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " + + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + + "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes + ); + } + } + + public void AllocPixels(SKImageInfo info) + { + AllocPixels(info, info.RowBytes); + } + + public void AllocPixels(SKImageInfo info, int rowBytes) + { + if (!TryAllocPixels(info, rowBytes)) + { + SKImageInfo i = Info; + throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " + + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + + "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes + ); + } + } + + public void AllocPixels(SKImageInfo info, SKBitmapAllocFlags flags) + { + if (!TryAllocPixels(info, flags)) + { + SKImageInfo i = Info; + throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " + + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + + "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes + ); + } + } + // TryAllocPixels public bool TryAllocPixels (SKImageInfo info) @@ -317,6 +386,8 @@ public bool ExtractAlpha (SKBitmap destination, SKPaint paint, out SKPointI offs } } + public SKImage AsImage () => SKImage.FromBitmap (this); + // properties public bool ReadyToDraw => SkiaApi.sk_bitmap_ready_to_draw (Handle); @@ -361,6 +432,10 @@ public int ByteCount { get { return (int)SkiaApi.sk_bitmap_get_byte_count (Handle); } } + public uint GenerationId { + get { return (uint)SkiaApi.sk_bitmap_get_generation_id(Handle); } + } + // *Pixels* public IntPtr GetPixels () => @@ -401,6 +476,14 @@ public void SetColorTable (SKColorTable ct) // more properties + public SKPixmap Pixmap { + get { + var pixmap = new SKPixmap (SkiaApi.sk_bitmap_get_pixmap (Handle), false); // pixmap is owned by this + pixmap.pixelSource = this; + return pixmap; + } + } + public byte[] Bytes { get { var array = GetPixelSpan ().ToArray (); @@ -723,6 +806,27 @@ public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKBitm return SkiaApi.sk_bitmap_install_pixels (Handle, &cinfo, (void*)pixels, (IntPtr)rowBytes, proxy, (void*)ctx); } + public bool ReadPixels (SKImageInfo info, IntPtr dstpixels, int rowBytes, int x, int y) + { + if (GetPixels() == null) return false; + return Pixmap.ReadPixels(info, dstPixels, rowBytes, x, y); + } + + public bool ReadPixels(SKPixmap dstPixmap) => ReadPixels(dstPixmap, 0, 0); + + public bool ReadPixels(SKPixmap pixmap, int x, int y) + { + if (GetPixels() == null) return false; + return Pixmap.ReadPixels(dst.Info, dst.Pixels, dst.RowBytes, srcX, srcY); + } + + public bool WritePixels(SKPixmap pixmap) => WritePixels(pixmap, 0, 0); + + public bool WritePixels(SKPixmap dstPixmap, int x, int y) + { + return SkiaApi.sk_bitmap_write_pixels_at_location(Handle, dstPixmap.Handle, x, y); + } + public bool InstallPixels (SKPixmap pixmap) { return SkiaApi.sk_bitmap_install_pixels_with_pixmap (Handle, pixmap.Handle); From bd7ee47b801cf3aee7275daa347696f5eabde9e9 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 21:53:35 +1000 Subject: [PATCH 08/33] expose more SKBitmap bindings --- binding/Binding/SkiaApi.generated.cs | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index 80bce77658..6d638aed06 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -932,6 +932,22 @@ internal static gr_vk_extensions_t gr_vk_extensions_new () => #region sk_bitmap.h + // bool sk_bitmap_compute_is_opaque(sk_bitmap_t* cbitmap) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal static extern bool sk_bitmap_compute_is_opaque (sk_bitmap_t cbitmap); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal delegate bool sk_bitmap_compute_is_opaque (sk_bitmap_t cbitmap); + } + private static Delegates.sk_bitmap_compute_is_opaque sk_bitmap_compute_is_opaque_delegate; + internal static bool sk_bitmap_compute_is_opaque (sk_bitmap_t cbitmap) => + (sk_bitmap_compute_is_opaque_delegate ??= GetSymbol ("sk_bitmap_compute_is_opaque")).Invoke (cbitmap); + #endif + // void sk_bitmap_destructor(sk_bitmap_t* cbitmap) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1076,6 +1092,20 @@ private partial class Delegates { (sk_bitmap_get_byte_count_delegate ??= GetSymbol ("sk_bitmap_get_byte_count")).Invoke (cbitmap); #endif + // uint32_t sk_bitmap_get_generation_id(sk_bitmap_t* cbitmap) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern UInt32 sk_bitmap_get_generation_id (sk_bitmap_t cbitmap); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate UInt32 sk_bitmap_get_generation_id (sk_bitmap_t cbitmap); + } + private static Delegates.sk_bitmap_get_generation_id sk_bitmap_get_generation_id_delegate; + internal static UInt32 sk_bitmap_get_generation_id (sk_bitmap_t cbitmap) => + (sk_bitmap_get_generation_id_delegate ??= GetSymbol ("sk_bitmap_get_generation_id")).Invoke (cbitmap); + #endif + // void sk_bitmap_get_info(sk_bitmap_t* cbitmap, sk_imageinfo_t* info) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1132,6 +1162,20 @@ private partial class Delegates { (sk_bitmap_get_pixels_delegate ??= GetSymbol ("sk_bitmap_get_pixels")).Invoke (cbitmap, length); #endif + // const sk_pixmap_t* sk_bitmap_get_pixmap(sk_bitmap_t* cbitmap) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_pixmap_t sk_bitmap_get_pixmap (sk_bitmap_t cbitmap); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_pixmap_t sk_bitmap_get_pixmap (sk_bitmap_t cbitmap); + } + private static Delegates.sk_bitmap_get_pixmap sk_bitmap_get_pixmap_delegate; + internal static sk_pixmap_t sk_bitmap_get_pixmap (sk_bitmap_t cbitmap) => + (sk_bitmap_get_pixmap_delegate ??= GetSymbol ("sk_bitmap_get_pixmap")).Invoke (cbitmap); + #endif + // size_t sk_bitmap_get_row_bytes(sk_bitmap_t* cbitmap) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1328,6 +1372,22 @@ internal static void sk_bitmap_set_immutable (sk_bitmap_t cbitmap) => (sk_bitmap_set_immutable_delegate ??= GetSymbol ("sk_bitmap_set_immutable")).Invoke (cbitmap); #endif + // bool sk_bitmap_set_info(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requestedInfo, size_t rowBytes) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal static extern bool sk_bitmap_set_info (sk_bitmap_t cbitmap, SKImageInfoNative* requestedInfo, /* size_t */ IntPtr rowBytes); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal delegate bool sk_bitmap_set_info (sk_bitmap_t cbitmap, SKImageInfoNative* requestedInfo, /* size_t */ IntPtr rowBytes); + } + private static Delegates.sk_bitmap_set_info sk_bitmap_set_info_delegate; + internal static bool sk_bitmap_set_info (sk_bitmap_t cbitmap, SKImageInfoNative* requestedInfo, /* size_t */ IntPtr rowBytes) => + (sk_bitmap_set_info_delegate ??= GetSymbol ("sk_bitmap_set_info")).Invoke (cbitmap, requestedInfo, rowBytes); + #endif + // void sk_bitmap_set_pixels(sk_bitmap_t* cbitmap, void* pixels) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -1388,6 +1448,22 @@ internal static bool sk_bitmap_try_alloc_pixels_with_flags (sk_bitmap_t cbitmap, (sk_bitmap_try_alloc_pixels_with_flags_delegate ??= GetSymbol ("sk_bitmap_try_alloc_pixels_with_flags")).Invoke (cbitmap, requestedInfo, flags); #endif + // bool sk_bitmap_write_pixels_at_location(sk_bitmap_t* cbitmap, const sk_pixmap_t* cpixmap, int x, int y) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal static extern bool sk_bitmap_write_pixels_at_location (sk_bitmap_t cbitmap, sk_pixmap_t cpixmap, Int32 x, Int32 y); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal delegate bool sk_bitmap_write_pixels_at_location (sk_bitmap_t cbitmap, sk_pixmap_t cpixmap, Int32 x, Int32 y); + } + private static Delegates.sk_bitmap_write_pixels_at_location sk_bitmap_write_pixels_at_location_delegate; + internal static bool sk_bitmap_write_pixels_at_location (sk_bitmap_t cbitmap, sk_pixmap_t cpixmap, Int32 x, Int32 y) => + (sk_bitmap_write_pixels_at_location_delegate ??= GetSymbol ("sk_bitmap_write_pixels_at_location")).Invoke (cbitmap, cpixmap, x, y); + #endif + #endregion #region sk_canvas.h From 4c198f67630226a3a72d57bed9dbcaad9cee7a91 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Thu, 7 Jul 2022 22:04:52 +1000 Subject: [PATCH 09/33] remove api meant for other PR --- binding/Binding/SKBitmap.cs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 57b07169a2..f186c0ff16 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -116,9 +116,6 @@ protected override void DisposeNative () => // Other - internal static SKBitmap GetObject(IntPtr handle, bool owns = true, bool unrefExisting = true) => - GetOrAddObject(handle, owns, unrefExisting, (h, o) => new SKBitmap(h, o)); - public bool SetInfo(SKImageInfo info) { // bool setInfo (const SkImageInfo &imageInfo, size_t rowBytes=0) @@ -138,23 +135,6 @@ public bool ComputeIsOpaque() // AllocPixels - public void AllocPixels() - { - AllocPixels((Allocator)null); - } - - public void AllocPixels(Allocator allocator) - { - if (!TryAllocPixels(allocator)) - { - SKImageInfo i = Info; - throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " - + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + - "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes - ); - } - } - public void AllocPixels(SKImageInfo info) { AllocPixels(info, info.RowBytes); From c5cd679d83bd57cdd6e956596dc6db23a00ceaee Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 8 Jul 2022 00:13:05 +1000 Subject: [PATCH 10/33] add cpp files to tizen --- native/tizen/libSkiaSharp/project_def.prop | 2 ++ 1 file changed, 2 insertions(+) diff --git a/native/tizen/libSkiaSharp/project_def.prop b/native/tizen/libSkiaSharp/project_def.prop index 8b62533891..4e10a7fda4 100644 --- a/native/tizen/libSkiaSharp/project_def.prop +++ b/native/tizen/libSkiaSharp/project_def.prop @@ -51,4 +51,6 @@ USER_SRCS = $(skia_root)/src/xamarin/sk_xamarin.cpp \ $(skia_root)/src/xamarin/sk_manageddrawable.cpp \ $(skia_root)/src/xamarin/SkManagedDrawable.cpp \ $(skia_root)/src/xamarin/sk_managedtracememorydump.cpp \ + $(skia_root)/src/xamarin/sk_managed_png_chunk_reader.cpp \ + $(skia_root)/src/xamarin/SkManaged_Png_Chunk_Reader.cpp \ $(skia_root)/src/xamarin/SkManagedTraceMemoryDump.cpp From afc7a9f5b3e3bbf56c7a3998d345d5c7fb28e091 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 8 Jul 2022 13:09:46 +1000 Subject: [PATCH 11/33] add json changes --- binding/libSkiaSharp.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/binding/libSkiaSharp.json b/binding/libSkiaSharp.json index cf4cc50988..9ce9edfd1a 100644 --- a/binding/libSkiaSharp.json +++ b/binding/libSkiaSharp.json @@ -341,6 +341,10 @@ "cs": "SKRunBufferInternal", "internal": true }, + "sk_managed_png_chunk_reader_procs_t": { + "cs": "SKManagedPngChunkReaderDelegates", + "internal": true + }, "sk_managedstream_procs_t": { "cs": "SKManagedStreamDelegates", "internal": true @@ -391,6 +395,13 @@ "-1": "IntPtr" } }, + "sk_managed_png_chunk_reader_read_chunk_proc": { + "cs": "SKManagedPngChunkReaderReadChunkProxyDelegate" + }, + "sk_managed_png_chunk_reader_destroy_procs_t": { + "cs": "SKManagedPngChunkReaderDestroyProxyDelegate", + "internal": true + }, "sk_managedwstream_write_proc": { "cs": "SKManagedWStreamWriteProxyDelegate" }, From 0c000d4226e97531236874ff73b40ef5f053be8c Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 8 Jul 2022 14:37:20 +1000 Subject: [PATCH 12/33] rename to match --- native/tizen/libSkiaSharp/project_def.prop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/tizen/libSkiaSharp/project_def.prop b/native/tizen/libSkiaSharp/project_def.prop index 4e10a7fda4..094784298b 100644 --- a/native/tizen/libSkiaSharp/project_def.prop +++ b/native/tizen/libSkiaSharp/project_def.prop @@ -51,6 +51,6 @@ USER_SRCS = $(skia_root)/src/xamarin/sk_xamarin.cpp \ $(skia_root)/src/xamarin/sk_manageddrawable.cpp \ $(skia_root)/src/xamarin/SkManagedDrawable.cpp \ $(skia_root)/src/xamarin/sk_managedtracememorydump.cpp \ - $(skia_root)/src/xamarin/sk_managed_png_chunk_reader.cpp \ - $(skia_root)/src/xamarin/SkManaged_Png_Chunk_Reader.cpp \ + $(skia_root)/src/xamarin/sk_managed_pngchunkreader.cpp \ + $(skia_root)/src/xamarin/SkManagedPngChunkReader.cpp \ $(skia_root)/src/xamarin/SkManagedTraceMemoryDump.cpp From 1fc7c6ef3ef10d697ecaab365958cfe701a22de1 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 8 Jul 2022 14:39:32 +1000 Subject: [PATCH 13/33] rename to match --- native/tizen/libSkiaSharp/project_def.prop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/tizen/libSkiaSharp/project_def.prop b/native/tizen/libSkiaSharp/project_def.prop index 094784298b..bbbd04fcc3 100644 --- a/native/tizen/libSkiaSharp/project_def.prop +++ b/native/tizen/libSkiaSharp/project_def.prop @@ -51,6 +51,6 @@ USER_SRCS = $(skia_root)/src/xamarin/sk_xamarin.cpp \ $(skia_root)/src/xamarin/sk_manageddrawable.cpp \ $(skia_root)/src/xamarin/SkManagedDrawable.cpp \ $(skia_root)/src/xamarin/sk_managedtracememorydump.cpp \ - $(skia_root)/src/xamarin/sk_managed_pngchunkreader.cpp \ + $(skia_root)/src/xamarin/sk_managedpngchunkreader.cpp \ $(skia_root)/src/xamarin/SkManagedPngChunkReader.cpp \ $(skia_root)/src/xamarin/SkManagedTraceMemoryDump.cpp From c618eecad366acf4bc19fbfebf80575bee2ced41 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 18:35:05 +1000 Subject: [PATCH 14/33] rename to match --- binding/libSkiaSharp.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binding/libSkiaSharp.json b/binding/libSkiaSharp.json index 9ce9edfd1a..62c346c609 100644 --- a/binding/libSkiaSharp.json +++ b/binding/libSkiaSharp.json @@ -341,7 +341,7 @@ "cs": "SKRunBufferInternal", "internal": true }, - "sk_managed_png_chunk_reader_procs_t": { + "sk_managedpngchunkreader_procs_t": { "cs": "SKManagedPngChunkReaderDelegates", "internal": true }, @@ -395,10 +395,10 @@ "-1": "IntPtr" } }, - "sk_managed_png_chunk_reader_read_chunk_proc": { + "sk_managedpngchunkreader_read_chunk_proc": { "cs": "SKManagedPngChunkReaderReadChunkProxyDelegate" }, - "sk_managed_png_chunk_reader_destroy_procs_t": { + "sk_managedpngchunkreader_destroy_procs_t": { "cs": "SKManagedPngChunkReaderDestroyProxyDelegate", "internal": true }, From 3a55937f82232664c2875b7769051bcdf725a5a0 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 19:24:59 +1000 Subject: [PATCH 15/33] fix bindings json --- binding/libSkiaSharp.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/binding/libSkiaSharp.json b/binding/libSkiaSharp.json index 62c346c609..68e70438c0 100644 --- a/binding/libSkiaSharp.json +++ b/binding/libSkiaSharp.json @@ -398,9 +398,8 @@ "sk_managedpngchunkreader_read_chunk_proc": { "cs": "SKManagedPngChunkReaderReadChunkProxyDelegate" }, - "sk_managedpngchunkreader_destroy_procs_t": { - "cs": "SKManagedPngChunkReaderDestroyProxyDelegate", - "internal": true + "sk_managedpngchunkreader_destroy_proc": { + "cs": "SKManagedPngChunkReaderDestroyProxyDelegate" }, "sk_managedwstream_write_proc": { "cs": "SKManagedWStreamWriteProxyDelegate" From 5c3586bb8cfe37921a254eca30a134da4e1e66de Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 20:14:29 +1000 Subject: [PATCH 16/33] fix params --- binding/Binding/SKBitmap.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index f186c0ff16..498fd4cc12 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -786,7 +786,7 @@ public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKBitm return SkiaApi.sk_bitmap_install_pixels (Handle, &cinfo, (void*)pixels, (IntPtr)rowBytes, proxy, (void*)ctx); } - public bool ReadPixels (SKImageInfo info, IntPtr dstpixels, int rowBytes, int x, int y) + public bool ReadPixels (SKImageInfo info, IntPtr dstPixels, int rowBytes, int x, int y) { if (GetPixels() == null) return false; return Pixmap.ReadPixels(info, dstPixels, rowBytes, x, y); @@ -794,10 +794,10 @@ public bool ReadPixels (SKImageInfo info, IntPtr dstpixels, int rowBytes, int x, public bool ReadPixels(SKPixmap dstPixmap) => ReadPixels(dstPixmap, 0, 0); - public bool ReadPixels(SKPixmap pixmap, int x, int y) + public bool ReadPixels(SKPixmap dstPixmap, int x, int y) { if (GetPixels() == null) return false; - return Pixmap.ReadPixels(dst.Info, dst.Pixels, dst.RowBytes, srcX, srcY); + return Pixmap.ReadPixels(dstPixmap.Info, dstPixmap.Pixels, dstPixmap.RowBytes, x, y); } public bool WritePixels(SKPixmap pixmap) => WritePixels(pixmap, 0, 0); From dca69e244d50eeef6bcc47ed5aa5cd6ce36a393c Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 20:27:36 +1000 Subject: [PATCH 17/33] fix bindings --- binding/Binding/SKCodec.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 9e748fac71..8dc733ad85 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -400,7 +400,7 @@ public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChu fixed (SKCodecResult* r = &result) { - var codec = GetObject(SkiaApi.sk_codec_new_from_stream(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SKCodecSelectionPolicy)selectionPolicy)); + var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SelectionPolicy)SKCodecSelectionPolicy)); stream.RevokeOwnership(codec); return codec; } @@ -419,7 +419,7 @@ public static SKCodec Create(SKData data, SKPngChunkReader chunkReader) if (data == null) throw new ArgumentNullException(nameof(data)); - return GetObject(SkiaApi.sk_codec_new_from_data(data.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); + return GetObject(SkiaApi.sk_codec_new_from_data_with_pngchunkreader(data.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); } // utils From 5dfbf18d8d0c5635abf7324ae00c52c913c98c68 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 20:28:38 +1000 Subject: [PATCH 18/33] SKCodec.SelectionPolicy -> SKCodecSelectionPolicy --- binding/Binding/SKCodec.cs | 75 ++++++++------------- binding/SkiaSharp/SKCodecSelectionPolicy.cs | 21 ++++++ 2 files changed, 49 insertions(+), 47 deletions(-) create mode 100644 binding/SkiaSharp/SKCodecSelectionPolicy.cs diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 8dc733ad85..fe75f75bce 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -13,25 +13,6 @@ internal SKCodec (IntPtr handle, bool owns) { } - /// - /// For container formats that contain both still images and image sequences, - ///

instruct the decoder how the output should be selected. (Refer to comments - ///

for each value for more details.) - ///
- public enum SelectionPolicy - { - /// - /// If the container format contains both still images and image sequences, - ///

SKCodec should choose one of the still images. This is the default. - ///
- preferStillImage, - /// - /// If the container format contains both still images and image sequences, - ///

SKCodec should choose one of the image sequences for animation. - ///
- preferAnimation - } - protected override void Dispose (bool disposing) => base.Dispose (disposing); @@ -308,26 +289,26 @@ public static SKCodec Create (string filename) => Create (filename, out var result); public static SKCodec Create(string filename, SKPngChunkReader chunkReader) => - Create(filename, out var result, chunkReader, SelectionPolicy.preferStillImage); + Create(filename, out var result, chunkReader, SKCodecSelectionPolicy.preferStillImage); - public static SKCodec Create(string filename, SelectionPolicy selectionPolicy) => - Create(filename, out var result, null, selectionPolicy); + public static SKCodec Create(string filename, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(filename, out var result, null, SKCodecSelectionPolicy); - public static SKCodec Create(string filename, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => - Create(filename, out var result, chunkReader, selectionPolicy); + public static SKCodec Create(string filename, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(filename, out var result, chunkReader, SKCodecSelectionPolicy); public static SKCodec Create(string filename, out SKCodecResult result) => - Create(filename, out result, null, SelectionPolicy.preferStillImage); + Create(filename, out result, null, SKCodecSelectionPolicy.preferStillImage); public static SKCodec Create(string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create (filename, out result, chunkReader, SelectionPolicy.preferStillImage); + Create (filename, out result, chunkReader, SKCodecSelectionPolicy.preferStillImage); - public static SKCodec Create(string filename, out SKCodecResult result, SelectionPolicy selectionPolicy) => - Create (filename, out result, null, selectionPolicy); + public static SKCodec Create(string filename, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (filename, out result, null, SKCodecSelectionPolicy); - public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) + public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) { var stream = SKFileStream.OpenStream (filename); if (stream == null) { @@ -335,7 +316,7 @@ public static SKCodec Create (string filename, out SKCodecResult result, SKPngCh return null; } - return Create (stream, out result, chunkReader, selectionPolicy); + return Create (stream, out result, chunkReader, SKCodecSelectionPolicy); } @@ -346,11 +327,11 @@ public static SKCodec Create (Stream stream) => public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader) => Create(stream, out var result, chunkReader); - public static SKCodec Create(Stream stream, SelectionPolicy selectionPolicy) => - Create(stream, out var result, selectionPolicy); + public static SKCodec Create(Stream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(stream, out var result, SKCodecSelectionPolicy); - public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => - Create(stream, out var result, chunkReader, selectionPolicy); + public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(stream, out var result, chunkReader, SKCodecSelectionPolicy); @@ -360,11 +341,11 @@ public static SKCodec Create (Stream stream, out SKCodecResult result) => public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => Create(WrapManagedStream(stream), out result, chunkReader); - public static SKCodec Create(Stream stream, out SKCodecResult result, SelectionPolicy selectionPolicy) => - Create(WrapManagedStream(stream), out result, selectionPolicy); + public static SKCodec Create(Stream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(WrapManagedStream(stream), out result, SKCodecSelectionPolicy); - public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => - Create(WrapManagedStream(stream), out result, chunkReader, selectionPolicy); + public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(WrapManagedStream(stream), out result, chunkReader, SKCodecSelectionPolicy); @@ -374,11 +355,11 @@ public static SKCodec Create (SKStream stream) => public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader) => Create(stream, out var result, chunkReader); - public static SKCodec Create(SKStream stream, SelectionPolicy selectionPolicy) => - Create(stream, out var result, selectionPolicy); + public static SKCodec Create(SKStream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(stream, out var result, SKCodecSelectionPolicy); - public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) => - Create(stream, out var result, chunkReader, selectionPolicy); + public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(stream, out var result, chunkReader, SKCodecSelectionPolicy); @@ -386,12 +367,12 @@ public static SKCodec Create(SKStream stream, out SKCodecResult result) => Create(stream, out result, null); public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create(stream, out result, chunkReader, SelectionPolicy.preferStillImage); + Create(stream, out result, chunkReader, SKCodecSelectionPolicy.preferStillImage); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SelectionPolicy selectionPolicy) => - Create(stream, out result, null, selectionPolicy); + public static SKCodec Create(SKStream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create(stream, out result, null, SKCodecSelectionPolicy); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SelectionPolicy selectionPolicy) + public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) { if (stream == null) throw new ArgumentNullException(nameof(stream)); @@ -400,7 +381,7 @@ public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChu fixed (SKCodecResult* r = &result) { - var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SelectionPolicy)SKCodecSelectionPolicy)); + var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SKCodecSKCodecSelectionPolicy)SKCodecSelectionPolicy)); stream.RevokeOwnership(codec); return codec; } diff --git a/binding/SkiaSharp/SKCodecSelectionPolicy.cs b/binding/SkiaSharp/SKCodecSelectionPolicy.cs new file mode 100644 index 0000000000..6ac2c19590 --- /dev/null +++ b/binding/SkiaSharp/SKCodecSelectionPolicy.cs @@ -0,0 +1,21 @@ +namespace SkiaSharp +{ + /// + /// For container formats that contain both still images and image sequences, + ///

instruct the decoder how the output should be selected. (Refer to comments + ///

for each value for more details.) + ///
+ public enum SKCodecSelectionPolicy + { + /// + /// If the container format contains both still images and image sequences, + ///

SKCodec should choose one of the still images. This is the default. + ///
+ preferStillImage, + /// + /// If the container format contains both still images and image sequences, + ///

SKCodec should choose one of the image sequences for animation. + ///
+ preferAnimation + } +} From 4307413bbd3d79ce173eea19e20ef46feea0d6c7 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 20:53:54 +1000 Subject: [PATCH 19/33] fix enum --- binding/Binding/SKCodec.cs | 6 +++--- binding/SkiaSharp/SKCodecSelectionPolicy.cs | 21 --------------------- 2 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 binding/SkiaSharp/SKCodecSelectionPolicy.cs diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index fe75f75bce..ee52987cf5 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -367,12 +367,12 @@ public static SKCodec Create(SKStream stream, out SKCodecResult result) => Create(stream, out result, null); public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create(stream, out result, chunkReader, SKCodecSelectionPolicy.preferStillImage); + Create(stream, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); public static SKCodec Create(SKStream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => Create(stream, out result, null, SKCodecSelectionPolicy); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) + public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy) { if (stream == null) throw new ArgumentNullException(nameof(stream)); @@ -381,7 +381,7 @@ public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChu fixed (SKCodecResult* r = &result) { - var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, (SKCodecSKCodecSelectionPolicy)SKCodecSelectionPolicy)); + var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, selectionPolicy)); stream.RevokeOwnership(codec); return codec; } diff --git a/binding/SkiaSharp/SKCodecSelectionPolicy.cs b/binding/SkiaSharp/SKCodecSelectionPolicy.cs deleted file mode 100644 index 6ac2c19590..0000000000 --- a/binding/SkiaSharp/SKCodecSelectionPolicy.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SkiaSharp -{ - /// - /// For container formats that contain both still images and image sequences, - ///

instruct the decoder how the output should be selected. (Refer to comments - ///

for each value for more details.) - ///
- public enum SKCodecSelectionPolicy - { - /// - /// If the container format contains both still images and image sequences, - ///

SKCodec should choose one of the still images. This is the default. - ///
- preferStillImage, - /// - /// If the container format contains both still images and image sequences, - ///

SKCodec should choose one of the image sequences for animation. - ///
- preferAnimation - } -} From cf7eee8d1fd0a7b9f442ed1e81428f3c5c706b6a Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 21:03:42 +1000 Subject: [PATCH 20/33] regenerate bindings --- binding/Binding/SkiaApi.generated.cs | 190 ++++++++++----------------- 1 file changed, 72 insertions(+), 118 deletions(-) diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index 6d638aed06..43e7420c99 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -35,8 +35,8 @@ using sk_image_t = System.IntPtr; using sk_imagefilter_croprect_t = System.IntPtr; using sk_imagefilter_t = System.IntPtr; -using sk_managed_png_chunk_reader_t = System.IntPtr; using sk_manageddrawable_t = System.IntPtr; +using sk_managedpngchunkreader_t = System.IntPtr; using sk_managedtracememorydump_t = System.IntPtr; using sk_maskfilter_t = System.IntPtr; using sk_matrix44_t = System.IntPtr; @@ -55,7 +55,7 @@ using sk_picture_t = System.IntPtr; using sk_pixelref_factory_t = System.IntPtr; using sk_pixmap_t = System.IntPtr; -using sk_png_chunk_reader_t = System.IntPtr; +using sk_pngchunkreader_t = System.IntPtr; using sk_refcnt_t = System.IntPtr; using sk_region_cliperator_t = System.IntPtr; using sk_region_iterator_t = System.IntPtr; @@ -2662,18 +2662,18 @@ internal static sk_codec_t sk_codec_new_from_data (sk_data_t data) => (sk_codec_new_from_data_delegate ??= GetSymbol ("sk_codec_new_from_data")).Invoke (data); #endif - // sk_codec_t* sk_codec_new_from_data_with_png_chunk_reader(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) + // sk_codec_t* sk_codec_new_from_data_with_pngchunkreader(sk_data_t* data, sk_pngchunkreader_t* chunk_reader) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + internal static extern sk_codec_t sk_codec_new_from_data_with_pngchunkreader (sk_data_t data, sk_pngchunkreader_t chunk_reader); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + internal delegate sk_codec_t sk_codec_new_from_data_with_pngchunkreader (sk_data_t data, sk_pngchunkreader_t chunk_reader); } - private static Delegates.sk_codec_new_from_data_with_png_chunk_reader sk_codec_new_from_data_with_png_chunk_reader_delegate; - internal static sk_codec_t sk_codec_new_from_data_with_png_chunk_reader (sk_data_t data, sk_png_chunk_reader_t chunk_reader) => - (sk_codec_new_from_data_with_png_chunk_reader_delegate ??= GetSymbol ("sk_codec_new_from_data_with_png_chunk_reader")).Invoke (data, chunk_reader); + private static Delegates.sk_codec_new_from_data_with_pngchunkreader sk_codec_new_from_data_with_pngchunkreader_delegate; + internal static sk_codec_t sk_codec_new_from_data_with_pngchunkreader (sk_data_t data, sk_pngchunkreader_t chunk_reader) => + (sk_codec_new_from_data_with_pngchunkreader_delegate ??= GetSymbol ("sk_codec_new_from_data_with_pngchunkreader")).Invoke (data, chunk_reader); #endif // sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream, sk_codec_result_t* result) @@ -2690,18 +2690,18 @@ internal static sk_codec_t sk_codec_new_from_stream (sk_stream_t stream, SKCodec (sk_codec_new_from_stream_delegate ??= GetSymbol ("sk_codec_new_from_stream")).Invoke (stream, result); #endif - // sk_codec_t* sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_png_chunk_reader_t* chunk_reader, sk_codec_selection_policy_t policy) + // sk_codec_t* sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(sk_stream_t* stream, sk_codec_result_t* result, sk_pngchunkreader_t* chunk_reader, sk_codec_selection_policy_t policy) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy); + internal static extern sk_codec_t sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_pngchunkreader_t chunk_reader, SKCodecSelectionPolicy policy); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy); + internal delegate sk_codec_t sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_pngchunkreader_t chunk_reader, SKCodecSelectionPolicy policy); } - private static Delegates.sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy_delegate; - internal static sk_codec_t sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_png_chunk_reader_t chunk_reader, SKCodecSelectionPolicy policy) => - (sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy_delegate ??= GetSymbol ("sk_codec_new_from_stream_with_png_chunk_reader_and_selection_policy")).Invoke (stream, result, chunk_reader, policy); + private static Delegates.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy_delegate; + internal static sk_codec_t sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy (sk_stream_t stream, SKCodecResult* result, sk_pngchunkreader_t chunk_reader, SKCodecSelectionPolicy policy) => + (sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy_delegate ??= GetSymbol ("sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy")).Invoke (stream, result, chunk_reader, policy); #endif // int sk_codec_next_scanline(sk_codec_t* codec) @@ -13274,52 +13274,6 @@ internal static void sk_compatpaint_set_text_encoding (sk_compatpaint_t paint, S #endregion - #region sk_managed_png_chunk_reader.h - - // void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*) - #if !USE_DELEGATES - [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); - #else - private partial class Delegates { - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); - } - private static Delegates.sk_managed_png_chunk_reader_delete sk_managed_png_chunk_reader_delete_delegate; - internal static void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0) => - (sk_managed_png_chunk_reader_delete_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_delete")).Invoke (param0); - #endif - - // sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) - #if !USE_DELEGATES - [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); - #else - private partial class Delegates { - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); - } - private static Delegates.sk_managed_png_chunk_reader_new sk_managed_png_chunk_reader_new_delegate; - internal static sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context) => - (sk_managed_png_chunk_reader_new_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_new")).Invoke (context); - #endif - - // void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) - #if !USE_DELEGATES - [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs); - #else - private partial class Delegates { - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs); - } - private static Delegates.sk_managed_png_chunk_reader_set_procs sk_managed_png_chunk_reader_set_procs_delegate; - internal static void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderProcs procs) => - (sk_managed_png_chunk_reader_set_procs_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_set_procs")).Invoke (procs); - #endif - - #endregion - #region sk_manageddrawable.h // sk_manageddrawable_t* sk_manageddrawable_new(void* context) @@ -13368,46 +13322,46 @@ internal static void sk_manageddrawable_unref (sk_manageddrawable_t param0) => #region sk_managedpngchunkreader.h - // void sk_managed_png_chunk_reader_delete(sk_managed_png_chunk_reader_t*) + // void sk_managedpngchunkreader_delete(sk_managedpngchunkreader_t*) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + internal static extern void sk_managedpngchunkreader_delete (sk_managedpngchunkreader_t param0); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0); + internal delegate void sk_managedpngchunkreader_delete (sk_managedpngchunkreader_t param0); } - private static Delegates.sk_managed_png_chunk_reader_delete sk_managed_png_chunk_reader_delete_delegate; - internal static void sk_managed_png_chunk_reader_delete (sk_managed_png_chunk_reader_t param0) => - (sk_managed_png_chunk_reader_delete_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_delete")).Invoke (param0); + private static Delegates.sk_managedpngchunkreader_delete sk_managedpngchunkreader_delete_delegate; + internal static void sk_managedpngchunkreader_delete (sk_managedpngchunkreader_t param0) => + (sk_managedpngchunkreader_delete_delegate ??= GetSymbol ("sk_managedpngchunkreader_delete")).Invoke (param0); #endif - // sk_managed_png_chunk_reader_t* sk_managed_png_chunk_reader_new(void* context) + // sk_managedpngchunkreader_t* sk_managedpngchunkreader_new(void* context) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + internal static extern sk_managedpngchunkreader_t sk_managedpngchunkreader_new (void* context); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context); + internal delegate sk_managedpngchunkreader_t sk_managedpngchunkreader_new (void* context); } - private static Delegates.sk_managed_png_chunk_reader_new sk_managed_png_chunk_reader_new_delegate; - internal static sk_managed_png_chunk_reader_t sk_managed_png_chunk_reader_new (void* context) => - (sk_managed_png_chunk_reader_new_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_new")).Invoke (context); + private static Delegates.sk_managedpngchunkreader_new sk_managedpngchunkreader_new_delegate; + internal static sk_managedpngchunkreader_t sk_managedpngchunkreader_new (void* context) => + (sk_managedpngchunkreader_new_delegate ??= GetSymbol ("sk_managedpngchunkreader_new")).Invoke (context); #endif - // void sk_managed_png_chunk_reader_set_procs(sk_managed_png_chunk_reader_procs_t procs) + // void sk_managedpngchunkreader_set_procs(sk_managedpngchunkreader_procs_t procs) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - internal static extern void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs); + internal static extern void sk_managedpngchunkreader_set_procs (SKManagedPngChunkReaderDelegates procs); #else private partial class Delegates { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs); + internal delegate void sk_managedpngchunkreader_set_procs (SKManagedPngChunkReaderDelegates procs); } - private static Delegates.sk_managed_png_chunk_reader_set_procs sk_managed_png_chunk_reader_set_procs_delegate; - internal static void sk_managed_png_chunk_reader_set_procs (SKManagedPngChunkReaderDelegates procs) => - (sk_managed_png_chunk_reader_set_procs_delegate ??= GetSymbol ("sk_managed_png_chunk_reader_set_procs")).Invoke (procs); + private static Delegates.sk_managedpngchunkreader_set_procs sk_managedpngchunkreader_set_procs_delegate; + internal static void sk_managedpngchunkreader_set_procs (SKManagedPngChunkReaderDelegates procs) => + (sk_managedpngchunkreader_set_procs_delegate ??= GetSymbol ("sk_managedpngchunkreader_set_procs")).Invoke (procs); #endif #endregion @@ -13590,15 +13544,6 @@ namespace SkiaSharp { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate void SKImageTextureReleaseProxyDelegate(void* context); - // typedef void (*)(sk_managed_png_chunk_reader_t* d, void* context)* sk_managed_png_chunk_reader_destroy_proc - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal unsafe delegate void SKManagedPngChunkReaderDestroyProxyDelegate(sk_managed_png_chunk_reader_t d, void* context); - - // typedef bool (*)(sk_managed_png_chunk_reader_t* d, void* context, const char[-1] tag, const void* data, size_t length)* sk_managed_png_chunk_reader_read_chunk_proc - [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - [return: MarshalAs (UnmanagedType.I1)] - internal unsafe delegate bool SKManagedPngChunkReaderReadChunkProxyDelegate(sk_managed_png_chunk_reader_t d, void* context, /* char */ void* tag, void* data, /* size_t */ IntPtr length); - // typedef void (*)(sk_manageddrawable_t* d, void* context)* sk_manageddrawable_destroy_proc [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate void SKManagedDrawableDestroyProxyDelegate(sk_manageddrawable_t d, void* context); @@ -13615,6 +13560,15 @@ namespace SkiaSharp { [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate sk_picture_t SKManagedDrawableNewPictureSnapshotProxyDelegate(sk_manageddrawable_t d, void* context); + // typedef void (*)(sk_managedpngchunkreader_t* d, void* context)* sk_managedpngchunkreader_destroy_proc + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal unsafe delegate void SKManagedPngChunkReaderDestroyProxyDelegate(sk_managedpngchunkreader_t d, void* context); + + // typedef bool (*)(sk_managedpngchunkreader_t* d, void* context, const char[-1] tag, const void* data, size_t length)* sk_managedpngchunkreader_read_chunk_proc + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal unsafe delegate bool SKManagedPngChunkReaderReadChunkProxyDelegate(sk_managedpngchunkreader_t d, void* context, /* char */ void* tag, void* data, /* size_t */ IntPtr length); + // typedef void (*)(sk_stream_managedstream_t* s, void* context)* sk_managedstream_destroy_proc [UnmanagedFunctionPointer (CallingConvention.Cdecl)] internal unsafe delegate void SKManagedStreamDestroyProxyDelegate(sk_stream_managedstream_t s, void* context); @@ -15091,37 +15045,6 @@ public readonly override int GetHashCode () } - // sk_managed_png_chunk_reader_procs_t - [StructLayout (LayoutKind.Sequential)] - internal unsafe partial struct SKManagedPngChunkReaderDelegates : IEquatable { - // public sk_managed_png_chunk_reader_read_chunk_proc fReadChunk - public SKManagedPngChunkReaderReadChunkProxyDelegate fReadChunk; - - // public sk_managed_png_chunk_reader_destroy_proc fDestroy - public SKManagedPngChunkReaderDestroyProxyDelegate fDestroy; - - public readonly bool Equals (SKManagedPngChunkReaderDelegates obj) => - fReadChunk == obj.fReadChunk && fDestroy == obj.fDestroy; - - public readonly override bool Equals (object obj) => - obj is SKManagedPngChunkReaderDelegates f && Equals (f); - - public static bool operator == (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => - left.Equals (right); - - public static bool operator != (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => - !left.Equals (right); - - public readonly override int GetHashCode () - { - var hash = new HashCode (); - hash.Add (fReadChunk); - hash.Add (fDestroy); - return hash.ToHashCode (); - } - - } - // sk_manageddrawable_procs_t [StructLayout (LayoutKind.Sequential)] internal unsafe partial struct SKManagedDrawableDelegates : IEquatable { @@ -15161,6 +15084,37 @@ public readonly override int GetHashCode () } + // sk_managedpngchunkreader_procs_t + [StructLayout (LayoutKind.Sequential)] + internal unsafe partial struct SKManagedPngChunkReaderDelegates : IEquatable { + // public sk_managedpngchunkreader_read_chunk_proc fReadChunk + public SKManagedPngChunkReaderReadChunkProxyDelegate fReadChunk; + + // public sk_managedpngchunkreader_destroy_proc fDestroy + public SKManagedPngChunkReaderDestroyProxyDelegate fDestroy; + + public readonly bool Equals (SKManagedPngChunkReaderDelegates obj) => + fReadChunk == obj.fReadChunk && fDestroy == obj.fDestroy; + + public readonly override bool Equals (object obj) => + obj is SKManagedPngChunkReaderDelegates f && Equals (f); + + public static bool operator == (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => + left.Equals (right); + + public static bool operator != (SKManagedPngChunkReaderDelegates left, SKManagedPngChunkReaderDelegates right) => + !left.Equals (right); + + public readonly override int GetHashCode () + { + var hash = new HashCode (); + hash.Add (fReadChunk); + hash.Add (fDestroy); + return hash.ToHashCode (); + } + + } + // sk_managedstream_procs_t [StructLayout (LayoutKind.Sequential)] internal unsafe partial struct SKManagedStreamDelegates : IEquatable { From 0c9f33b0f7fda835bf0c393401e940e773e2740a Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 21:14:18 +1000 Subject: [PATCH 21/33] fix enum --- binding/Binding/SKCodec.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index ee52987cf5..0fe3b2f72b 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -289,7 +289,7 @@ public static SKCodec Create (string filename) => Create (filename, out var result); public static SKCodec Create(string filename, SKPngChunkReader chunkReader) => - Create(filename, out var result, chunkReader, SKCodecSelectionPolicy.preferStillImage); + Create(filename, out var result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); public static SKCodec Create(string filename, SKCodecSelectionPolicy SKCodecSelectionPolicy) => Create(filename, out var result, null, SKCodecSelectionPolicy); @@ -300,10 +300,10 @@ public static SKCodec Create(string filename, SKPngChunkReader chunkReader, SKCo public static SKCodec Create(string filename, out SKCodecResult result) => - Create(filename, out result, null, SKCodecSelectionPolicy.preferStillImage); + Create(filename, out result, null, SKCodecSelectionPolicy.PreferStillImage); public static SKCodec Create(string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create (filename, out result, chunkReader, SKCodecSelectionPolicy.preferStillImage); + Create (filename, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); public static SKCodec Create(string filename, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => Create (filename, out result, null, SKCodecSelectionPolicy); From c134ffbfe47dde57a65e99e172fe5eb8feb0dce3 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 22:01:06 +1000 Subject: [PATCH 22/33] fix C# binding callbacks --- binding/Binding/SKPngChunkReader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index 629980bc74..a97d194605 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -25,14 +25,14 @@ static SKPngChunkReader() fDestroy = DestroyInternal, }; - SkiaApi.sk_managed_png_chunk_reader_set_procs(delegates); + SkiaApi.sk_managedpngchunkreader_set_procs(delegates); } protected SKPngChunkReader() : base(IntPtr.Zero, true) { userData = DelegateProxies.CreateUserData(this, true); - Handle = SkiaApi.sk_managed_png_chunk_reader_new((void*)userData); + Handle = SkiaApi.sk_managedpngchunkreader_new((void*)userData); if (Handle == IntPtr.Zero) throw new InvalidOperationException("Unable to create a new SKManagedAllocator instance."); @@ -45,7 +45,7 @@ protected override void DisposeNative() { if (Interlocked.CompareExchange(ref fromNative, 0, 0) == 0) { - SkiaApi.sk_managed_png_chunk_reader_delete(Handle); + SkiaApi.sk_managedpngchunkreader_delete(Handle); } } From 334b7c3e853965ccd5ff9de3d12a4918107d0f47 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sat, 9 Jul 2022 22:07:25 +1000 Subject: [PATCH 23/33] fix incorrect member name --- binding/Binding/SKBitmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 498fd4cc12..43961460a9 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -797,7 +797,7 @@ public bool ReadPixels (SKImageInfo info, IntPtr dstPixels, int rowBytes, int x, public bool ReadPixels(SKPixmap dstPixmap, int x, int y) { if (GetPixels() == null) return false; - return Pixmap.ReadPixels(dstPixmap.Info, dstPixmap.Pixels, dstPixmap.RowBytes, x, y); + return Pixmap.ReadPixels(dstPixmap.Info, dstPixmap.GetPixels(), dstPixmap.RowBytes, x, y); } public bool WritePixels(SKPixmap pixmap) => WritePixels(pixmap, 0, 0); From e8bdd7584d64c3aecb3d19a99f650c061e3b3210 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Tue, 12 Jul 2022 23:26:58 +1000 Subject: [PATCH 24/33] remove comments, cleanup ReadChunk api --- binding/Binding/SKPngChunkReader.cs | 91 +---------------------------- 1 file changed, 2 insertions(+), 89 deletions(-) diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index a97d194605..e1a6d2b33a 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -6,11 +6,6 @@ namespace SkiaSharp { - /// - /// Base class for optional callbacks to retrieve meta/chunk data out of a PNG - ///

encoded image as it is being decoded. - ///

Used by SkCodec. - ///
public unsafe abstract class SKPngChunkReader : SKObject, ISKSkipObjectRegistration { private static readonly SKManagedPngChunkReaderDelegates delegates; @@ -49,90 +44,8 @@ protected override void DisposeNative() } } - /// - /// This will be called by the decoder when it sees an unknown chunk. - ///

- ///

Use by SkCodec: - ///

Depending on the location of the unknown chunks, this callback may be - ///

called by - ///

- the factory (NewFromStream/NewFromData) - ///

- getPixels - ///

- startScanlineDecode - ///

- the first call to getScanlines/skipScanlines - ///

The callback may be called from a different thread (e.g. if the SkCodec - ///

is passed to another thread), and it may be called multiple times, if - ///

the SkCodec is used multiple times. - ///

- ///

@param tag Name for this type of chunk. - ///

@param data Data to be interpreted by the subclass. - ///

@param length Number of bytes of data in the chunk. - ///

@return true to continue decoding, or false to indicate an error, which - ///

will cause the decoder to not return the image. - ///
- /// Name for this type of chunk. - /// Data to be interpreted by the subclass. - /// Number of bytes of data in the chunk. - /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. - public abstract bool ReadChunk(string tag, void* data, IntPtr length); - - /// - /// This will be called by the decoder when it sees an unknown chunk. - ///

- ///

Use by SkCodec: - ///

Depending on the location of the unknown chunks, this callback may be - ///

called by - ///

- the factory (NewFromStream/NewFromData) - ///

- getPixels - ///

- startScanlineDecode - ///

- the first call to getScanlines/skipScanlines - ///

The callback may be called from a different thread (e.g. if the SkCodec - ///

is passed to another thread), and it may be called multiple times, if - ///

the SkCodec is used multiple times. - ///

- ///

@param tag Name for this type of chunk. - ///

@param data Data to be interpreted by the subclass. - ///

@param length Number of bytes of data in the chunk. - ///

@return true to continue decoding, or false to indicate an error, which - ///

will cause the decoder to not return the image. - ///
- /// Name for this type of chunk. - /// Data to be interpreted by the subclass. - /// Number of bytes of data in the chunk. - /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. - public virtual bool ReadChunk (string tag, IntPtr data, IntPtr length) - { - return ReadChunk (tag, data.ToPointer(), length); - } - - /// - /// This will be called by the decoder when it sees an unknown chunk. - ///

- ///

Override this is you want to pass to C interop. - ///

- ///

Use by SkCodec: - ///

Depending on the location of the unknown chunks, this callback may be - ///

called by - ///

- the factory (NewFromStream/NewFromData) - ///

- getPixels - ///

- startScanlineDecode - ///

- the first call to getScanlines/skipScanlines - ///

The callback may be called from a different thread (e.g. if the SkCodec - ///

is passed to another thread), and it may be called multiple times, if - ///

the SkCodec is used multiple times. - ///

- ///

@param tag Name for this type of chunk. - ///

@param data Data to be interpreted by the subclass. - ///

@param length Number of bytes of data in the chunk. - ///

@return true to continue decoding, or false to indicate an error, which - ///

will cause the decoder to not return the image. - ///
- /// Name for this type of chunk. - /// Data to be interpreted by the subclass. - /// Number of bytes of data in the chunk. - /// true to continue decoding, or false to indicate an error, which will cause the decoder to not return the image. - public virtual bool ReadChunk (void* tag, void* data, IntPtr length) + protected abstract bool ReadChunk (string tag, IntPtr data, IntPtr length) { - return ReadChunk (Marshal.PtrToStringAnsi((IntPtr)tag), data, length); } // impl @@ -141,7 +54,7 @@ public virtual bool ReadChunk (void* tag, void* data, IntPtr length) private static bool ReadChunkInternal(IntPtr d, void* context, void* tag, void* data, IntPtr length) { var dump = DelegateProxies.GetUserData((IntPtr)context, out _); - return dump.ReadChunk(tag, data, length); + return dump.ReadChunk(Marshal.PtrToStringAnsi((IntPtr)tag), (IntPtr)data, length); } [MonoPInvokeCallback(typeof(SKManagedPngChunkReaderDestroyProxyDelegate))] From b362f1aa92a3152f136d130d03eb8648c1c76cab Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Tue, 12 Jul 2022 23:29:55 +1000 Subject: [PATCH 25/33] removed needlessly overriden Dispose --- binding/Binding/SKPngChunkReader.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index e1a6d2b33a..cb994adaf0 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -33,9 +33,6 @@ protected SKPngChunkReader() throw new InvalidOperationException("Unable to create a new SKManagedAllocator instance."); } - protected override void Dispose(bool disposing) => - base.Dispose(disposing); - protected override void DisposeNative() { if (Interlocked.CompareExchange(ref fromNative, 0, 0) == 0) From 052ee1c8d217aa71094c725a7037b71659ae3072 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sun, 7 Aug 2022 06:14:09 +1000 Subject: [PATCH 26/33] fix abstract ReadChunk having method body --- binding/Binding/SKPngChunkReader.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index cb994adaf0..1bbc15cc6b 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -41,9 +41,7 @@ protected override void DisposeNative() } } - protected abstract bool ReadChunk (string tag, IntPtr data, IntPtr length) - { - } + protected abstract bool ReadChunk (string tag, IntPtr data, IntPtr length); // impl From 60776088b0a5f320849f4cee186cc18b4a4cf91d Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sun, 14 Aug 2022 15:40:52 +0200 Subject: [PATCH 27/33] Run code formatter --- binding/Binding/SKBitmap.cs | 74 ++++++++---------- binding/Binding/SKCodec.cs | 113 ++++++++++++---------------- binding/Binding/SKPngChunkReader.cs | 49 ++++++------ 3 files changed, 103 insertions(+), 133 deletions(-) diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 43961460a9..58ef4dc96c 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using System.IO; -using System.Threading; namespace SkiaSharp { @@ -116,48 +115,39 @@ protected override void DisposeNative () => // Other - public bool SetInfo(SKImageInfo info) - { - // bool setInfo (const SkImageInfo &imageInfo, size_t rowBytes=0) - return SetInfo(info, 0); - } + public bool SetInfo (SKImageInfo info) => + SetInfo (info, 0); - public bool SetInfo(SKImageInfo info, int rowBytes) + public bool SetInfo (SKImageInfo info, int rowBytes) { - var cinfo = SKImageInfoNative.FromManaged(ref info); - return SkiaApi.sk_bitmap_set_info(Handle, &cinfo, (IntPtr)rowBytes); + var cinfo = SKImageInfoNative.FromManaged (ref info); + return SkiaApi.sk_bitmap_set_info (Handle, &cinfo, (IntPtr)rowBytes); } - public bool ComputeIsOpaque() - { - return SkiaApi.sk_bitmap_compute_is_opaque(Handle); - } + public bool ComputeIsOpaque () => + SkiaApi.sk_bitmap_compute_is_opaque (Handle); // AllocPixels - public void AllocPixels(SKImageInfo info) - { - AllocPixels(info, info.RowBytes); - } + public void AllocPixels (SKImageInfo info) => + AllocPixels (info, info.RowBytes); - public void AllocPixels(SKImageInfo info, int rowBytes) + public void AllocPixels (SKImageInfo info, int rowBytes) { - if (!TryAllocPixels(info, rowBytes)) - { + if (!TryAllocPixels (info, rowBytes)) { SKImageInfo i = Info; - throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " + throw new OutOfMemoryException ("SkBitmap::tryAllocPixels failed " + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes ); } } - public void AllocPixels(SKImageInfo info, SKBitmapAllocFlags flags) + public void AllocPixels (SKImageInfo info, SKBitmapAllocFlags flags) { - if (!TryAllocPixels(info, flags)) - { + if (!TryAllocPixels (info, flags)) { SKImageInfo i = Info; - throw new OutOfMemoryException("SkBitmap::tryAllocPixels failed " + throw new OutOfMemoryException ("SkBitmap::tryAllocPixels failed " + "ColorType:" + i.ColorType + "AlphaType:" + i.AlphaType + "[w:" + i.Width + " h:" + i.Height + "] rb:" + RowBytes ); @@ -366,8 +356,6 @@ public bool ExtractAlpha (SKBitmap destination, SKPaint paint, out SKPointI offs } } - public SKImage AsImage () => SKImage.FromBitmap (this); - // properties public bool ReadyToDraw => SkiaApi.sk_bitmap_ready_to_draw (Handle); @@ -412,9 +400,8 @@ public int ByteCount { get { return (int)SkiaApi.sk_bitmap_get_byte_count (Handle); } } - public uint GenerationId { - get { return (uint)SkiaApi.sk_bitmap_get_generation_id(Handle); } - } + public uint GenerationId => + (uint)SkiaApi.sk_bitmap_get_generation_id (Handle); // *Pixels* @@ -788,24 +775,26 @@ public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKBitm public bool ReadPixels (SKImageInfo info, IntPtr dstPixels, int rowBytes, int x, int y) { - if (GetPixels() == null) return false; - return Pixmap.ReadPixels(info, dstPixels, rowBytes, x, y); + if (GetPixels () == null) + return false; + return Pixmap.ReadPixels (info, dstPixels, rowBytes, x, y); } - public bool ReadPixels(SKPixmap dstPixmap) => ReadPixels(dstPixmap, 0, 0); + public bool ReadPixels (SKPixmap dstPixmap) => + ReadPixels (dstPixmap, 0, 0); - public bool ReadPixels(SKPixmap dstPixmap, int x, int y) + public bool ReadPixels (SKPixmap dstPixmap, int x, int y) { - if (GetPixels() == null) return false; - return Pixmap.ReadPixels(dstPixmap.Info, dstPixmap.GetPixels(), dstPixmap.RowBytes, x, y); + if (GetPixels () == null) + return false; + return Pixmap.ReadPixels (dstPixmap.Info, dstPixmap.GetPixels (), dstPixmap.RowBytes, x, y); } - public bool WritePixels(SKPixmap pixmap) => WritePixels(pixmap, 0, 0); + public bool WritePixels (SKPixmap pixmap) => + WritePixels (pixmap, 0, 0); - public bool WritePixels(SKPixmap dstPixmap, int x, int y) - { - return SkiaApi.sk_bitmap_write_pixels_at_location(Handle, dstPixmap.Handle, x, y); - } + public bool WritePixels (SKPixmap dstPixmap, int x, int y) => + SkiaApi.sk_bitmap_write_pixels_at_location (Handle, dstPixmap.Handle, x, y); public bool InstallPixels (SKPixmap pixmap) { @@ -926,6 +915,9 @@ public static SKBitmap FromImage (SKImage image) return bmp; } + public SKImage ToImage () => + SKImage.FromBitmap (this); + // Encode public SKData Encode (SKEncodedImageFormat format, int quality) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 0fe3b2f72b..2304e90b2b 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -41,12 +41,7 @@ public SKImageInfo Info { public SKEncodedImageFormat EncodedFormat => SkiaApi.sk_codec_get_encoded_format (Handle); - public SKSizeI Dimensions - { - get { - return Info.Size; - } - } + public SKSizeI EncodedDimensions => Info.Size; public SKSizeI GetScaledDimensions (float desiredScale) { @@ -283,29 +278,27 @@ public bool SkipScanlines (int countLines) => public int GetOutputScanline (int inputScanline) => SkiaApi.sk_codec_output_scanline (Handle, inputScanline); - // create (streams) + // create (filename) public static SKCodec Create (string filename) => Create (filename, out var result); - public static SKCodec Create(string filename, SKPngChunkReader chunkReader) => - Create(filename, out var result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); + public static SKCodec Create (string filename, SKPngChunkReader chunkReader) => + Create (filename, out var result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); - public static SKCodec Create(string filename, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(filename, out var result, null, SKCodecSelectionPolicy); + public static SKCodec Create (string filename, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (filename, out var result, null, SKCodecSelectionPolicy); - public static SKCodec Create(string filename, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(filename, out var result, chunkReader, SKCodecSelectionPolicy); + public static SKCodec Create (string filename, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (filename, out var result, chunkReader, SKCodecSelectionPolicy); + public static SKCodec Create (string filename, out SKCodecResult result) => + Create (filename, out result, null, SKCodecSelectionPolicy.PreferStillImage); - - public static SKCodec Create(string filename, out SKCodecResult result) => - Create(filename, out result, null, SKCodecSelectionPolicy.PreferStillImage); - - public static SKCodec Create(string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => + public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => Create (filename, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); - public static SKCodec Create(string filename, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + public static SKCodec Create (string filename, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => Create (filename, out result, null, SKCodecSelectionPolicy); public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) @@ -319,88 +312,78 @@ public static SKCodec Create (string filename, out SKCodecResult result, SKPngCh return Create (stream, out result, chunkReader, SKCodecSelectionPolicy); } - + // create (streams) public static SKCodec Create (Stream stream) => Create (stream, out var result); - public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader) => - Create(stream, out var result, chunkReader); - - public static SKCodec Create(Stream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(stream, out var result, SKCodecSelectionPolicy); - - public static SKCodec Create(Stream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(stream, out var result, chunkReader, SKCodecSelectionPolicy); + public static SKCodec Create (Stream stream, SKPngChunkReader chunkReader) => + Create (stream, out var result, chunkReader); + public static SKCodec Create (Stream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (stream, out var result, SKCodecSelectionPolicy); + public static SKCodec Create (Stream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (stream, out var result, chunkReader, SKCodecSelectionPolicy); public static SKCodec Create (Stream stream, out SKCodecResult result) => Create (WrapManagedStream (stream), out result); - public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create(WrapManagedStream(stream), out result, chunkReader); - - public static SKCodec Create(Stream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(WrapManagedStream(stream), out result, SKCodecSelectionPolicy); - - public static SKCodec Create(Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(WrapManagedStream(stream), out result, chunkReader, SKCodecSelectionPolicy); + public static SKCodec Create (Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => + Create (WrapManagedStream (stream), out result, chunkReader); + public static SKCodec Create (Stream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (WrapManagedStream (stream), out result, SKCodecSelectionPolicy); + public static SKCodec Create (Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (WrapManagedStream (stream), out result, chunkReader, SKCodecSelectionPolicy); public static SKCodec Create (SKStream stream) => Create (stream, out var result); - public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader) => - Create(stream, out var result, chunkReader); - - public static SKCodec Create(SKStream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(stream, out var result, SKCodecSelectionPolicy); - - public static SKCodec Create(SKStream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(stream, out var result, chunkReader, SKCodecSelectionPolicy); + public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader) => + Create (stream, out var result, chunkReader); + public static SKCodec Create (SKStream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (stream, out var result, SKCodecSelectionPolicy); + public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (stream, out var result, chunkReader, SKCodecSelectionPolicy); - public static SKCodec Create(SKStream stream, out SKCodecResult result) => - Create(stream, out result, null); + public static SKCodec Create (SKStream stream, out SKCodecResult result) => + Create (stream, out result, null); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create(stream, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); + public static SKCodec Create (SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => + Create (stream, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create(stream, out result, null, SKCodecSelectionPolicy); + public static SKCodec Create (SKStream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => + Create (stream, out result, null, SKCodecSelectionPolicy); - public static SKCodec Create(SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy) + public static SKCodec Create (SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy) { if (stream == null) - throw new ArgumentNullException(nameof(stream)); + throw new ArgumentNullException (nameof (stream)); if (stream is SKFileStream filestream && !filestream.IsValid) - throw new ArgumentException("File stream was not valid.", nameof(stream)); + throw new ArgumentException ("File stream was not valid.", nameof (stream)); - fixed (SKCodecResult* r = &result) - { - var codec = GetObject(SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy(stream.Handle, r, chunkReader == null ? IntPtr.Zero : chunkReader.Handle, selectionPolicy)); - stream.RevokeOwnership(codec); + fixed (SKCodecResult* r = &result) { + var codec = GetObject (SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy (stream.Handle, r, chunkReader?.Handle ?? IntPtr.Zero, selectionPolicy)); + stream.RevokeOwnership (codec); return codec; } } - // create (data) - public static SKCodec Create (SKData data) - { - return Create(data, null); - } + public static SKCodec Create (SKData data) => + Create (data, null); - public static SKCodec Create(SKData data, SKPngChunkReader chunkReader) + public static SKCodec Create (SKData data, SKPngChunkReader chunkReader) { if (data == null) - throw new ArgumentNullException(nameof(data)); + throw new ArgumentNullException (nameof (data)); - return GetObject(SkiaApi.sk_codec_new_from_data_with_pngchunkreader(data.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); + return GetObject (SkiaApi.sk_codec_new_from_data_with_pngchunkreader (data.Handle, chunkReader?.Handle ?? IntPtr.Zero)); } // utils diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index 1bbc15cc6b..9ce874971b 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -1,6 +1,4 @@ using System; -using System.ComponentModel; -using System.IO; using System.Runtime.InteropServices; using System.Threading; @@ -12,32 +10,30 @@ public unsafe abstract class SKPngChunkReader : SKObject, ISKSkipObjectRegistrat private readonly IntPtr userData; private int fromNative; - static SKPngChunkReader() + static SKPngChunkReader () { - delegates = new SKManagedPngChunkReaderDelegates - { + delegates = new SKManagedPngChunkReaderDelegates { fReadChunk = ReadChunkInternal, fDestroy = DestroyInternal, }; - SkiaApi.sk_managedpngchunkreader_set_procs(delegates); + SkiaApi.sk_managedpngchunkreader_set_procs (delegates); } - protected SKPngChunkReader() - : base(IntPtr.Zero, true) + protected SKPngChunkReader () + : base (IntPtr.Zero, true) { - userData = DelegateProxies.CreateUserData(this, true); - Handle = SkiaApi.sk_managedpngchunkreader_new((void*)userData); + userData = DelegateProxies.CreateUserData (this, true); + Handle = SkiaApi.sk_managedpngchunkreader_new ((void*)userData); if (Handle == IntPtr.Zero) - throw new InvalidOperationException("Unable to create a new SKManagedAllocator instance."); + throw new InvalidOperationException ("Unable to create a new SKManagedAllocator instance."); } - protected override void DisposeNative() + protected override void DisposeNative () { - if (Interlocked.CompareExchange(ref fromNative, 0, 0) == 0) - { - SkiaApi.sk_managedpngchunkreader_delete(Handle); + if (Interlocked.CompareExchange (ref fromNative, 0, 0) == 0) { + SkiaApi.sk_managedpngchunkreader_delete (Handle); } } @@ -45,23 +41,22 @@ protected override void DisposeNative() // impl - [MonoPInvokeCallback (typeof(SKManagedPngChunkReaderReadChunkProxyDelegate))] - private static bool ReadChunkInternal(IntPtr d, void* context, void* tag, void* data, IntPtr length) + [MonoPInvokeCallback (typeof (SKManagedPngChunkReaderReadChunkProxyDelegate))] + private static bool ReadChunkInternal (IntPtr d, void* context, void* tag, void* data, IntPtr length) { - var dump = DelegateProxies.GetUserData((IntPtr)context, out _); - return dump.ReadChunk(Marshal.PtrToStringAnsi((IntPtr)tag), (IntPtr)data, length); + var dump = DelegateProxies.GetUserData ((IntPtr)context, out _); + return dump.ReadChunk (Marshal.PtrToStringAnsi ((IntPtr)tag), (IntPtr)data, length); } - [MonoPInvokeCallback(typeof(SKManagedPngChunkReaderDestroyProxyDelegate))] - private static void DestroyInternal(IntPtr s, void* context) + [MonoPInvokeCallback (typeof (SKManagedPngChunkReaderDestroyProxyDelegate))] + private static void DestroyInternal (IntPtr s, void* context) { - var id = DelegateProxies.GetUserData((IntPtr)context, out var gch); - if (id != null) - { - Interlocked.Exchange(ref id.fromNative, 1); - id.Dispose(); + var id = DelegateProxies.GetUserData ((IntPtr)context, out var gch); + if (id != null) { + Interlocked.Exchange (ref id.fromNative, 1); + id.Dispose (); } - gch.Free(); + gch.Free (); } } } From 09a7d2b2f17595278102add6b43a74dd12f7af9e Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sun, 14 Aug 2022 15:52:48 +0200 Subject: [PATCH 28/33] reduce overloads --- binding/Binding/SKCodec.cs | 69 +++++++------------------------------- 1 file changed, 13 insertions(+), 56 deletions(-) diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 2304e90b2b..9c2ec6edaf 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -281,27 +281,12 @@ public int GetOutputScanline (int inputScanline) => // create (filename) public static SKCodec Create (string filename) => - Create (filename, out var result); - - public static SKCodec Create (string filename, SKPngChunkReader chunkReader) => - Create (filename, out var result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); - - public static SKCodec Create (string filename, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (filename, out var result, null, SKCodecSelectionPolicy); - - public static SKCodec Create (string filename, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (filename, out var result, chunkReader, SKCodecSelectionPolicy); + Create (filename, null, SKCodecSelectionPolicy.PreferStillImage, out _); public static SKCodec Create (string filename, out SKCodecResult result) => - Create (filename, out result, null, SKCodecSelectionPolicy.PreferStillImage); - - public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create (filename, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); + Create (filename, null, SKCodecSelectionPolicy.PreferStillImage, out result); - public static SKCodec Create (string filename, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (filename, out result, null, SKCodecSelectionPolicy); - - public static SKCodec Create (string filename, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) + public static SKCodec Create (string filename, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy, out SKCodecResult result) { var stream = SKFileStream.OpenStream (filename); if (stream == null) { @@ -309,57 +294,29 @@ public static SKCodec Create (string filename, out SKCodecResult result, SKPngCh return null; } - return Create (stream, out result, chunkReader, SKCodecSelectionPolicy); + return Create (stream, chunkReader, selectionPolicy, out result); } - // create (streams) + // create (Stream) public static SKCodec Create (Stream stream) => - Create (stream, out var result); - - public static SKCodec Create (Stream stream, SKPngChunkReader chunkReader) => - Create (stream, out var result, chunkReader); - - public static SKCodec Create (Stream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (stream, out var result, SKCodecSelectionPolicy); - - public static SKCodec Create (Stream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (stream, out var result, chunkReader, SKCodecSelectionPolicy); + Create (WrapManagedStream (stream), null, SKCodecSelectionPolicy.PreferStillImage, out _); public static SKCodec Create (Stream stream, out SKCodecResult result) => - Create (WrapManagedStream (stream), out result); - - public static SKCodec Create (Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create (WrapManagedStream (stream), out result, chunkReader); + Create (WrapManagedStream (stream), null, SKCodecSelectionPolicy.PreferStillImage, out result); - public static SKCodec Create (Stream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (WrapManagedStream (stream), out result, SKCodecSelectionPolicy); + public static SKCodec Create (Stream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy, out SKCodecResult result) => + Create (WrapManagedStream (stream), chunkReader, selectionPolicy, out result); - public static SKCodec Create (Stream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (WrapManagedStream (stream), out result, chunkReader, SKCodecSelectionPolicy); + // create (SKStream) public static SKCodec Create (SKStream stream) => - Create (stream, out var result); - - public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader) => - Create (stream, out var result, chunkReader); - - public static SKCodec Create (SKStream stream, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (stream, out var result, SKCodecSelectionPolicy); - - public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (stream, out var result, chunkReader, SKCodecSelectionPolicy); + Create (stream, null, SKCodecSelectionPolicy.PreferStillImage, out _); public static SKCodec Create (SKStream stream, out SKCodecResult result) => - Create (stream, out result, null); - - public static SKCodec Create (SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader) => - Create (stream, out result, chunkReader, SKCodecSelectionPolicy.PreferStillImage); - - public static SKCodec Create (SKStream stream, out SKCodecResult result, SKCodecSelectionPolicy SKCodecSelectionPolicy) => - Create (stream, out result, null, SKCodecSelectionPolicy); + Create (stream, null, SKCodecSelectionPolicy.PreferStillImage, out result); - public static SKCodec Create (SKStream stream, out SKCodecResult result, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy) + public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader, SKCodecSelectionPolicy selectionPolicy, out SKCodecResult result) { if (stream == null) throw new ArgumentNullException (nameof (stream)); From 80b5fd1a540a66aaab9a35fb8816671a1eac0964 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 16 Aug 2022 00:06:13 +0200 Subject: [PATCH 29/33] Adding some tests --- binding/Binding/SKBitmap.cs | 4 +-- binding/Binding/SKCodec.cs | 5 +++- binding/Binding/SKObject.cs | 2 +- native/android/build.cake | 2 +- native/ios/build.cake | 2 +- native/linux/build.cake | 2 +- native/macos/build.cake | 4 ++- native/tizen/build.cake | 2 +- native/tvos/build.cake | 2 +- native/uwp/build.cake | 3 +- native/wasm/build.cake | 1 + native/watchos/build.cake | 2 +- native/windows/build.cake | 4 ++- .../images/png_chunks/good_idat_multiple.png | Bin 0 -> 82 bytes .../png_chunks/good_idat_some-empty.png | Bin 0 -> 94 bytes tests/Content/images/png_chunks/good_itxt.png | Bin 0 -> 125 bytes .../images/png_chunks/good_phys_96-dpi.png | Bin 0 -> 91 bytes tests/Content/images/png_chunks/good_splt.png | Bin 0 -> 150 bytes tests/Content/images/png_chunks/good_srgb.png | Bin 0 -> 83 bytes tests/Content/images/png_chunks/good_text.png | Bin 0 -> 134 bytes .../png_chunks/good_time_unix-epoch.png | Bin 0 -> 89 bytes tests/Content/images/png_chunks/good_ztxt.png | Bin 0 -> 408 bytes tests/Tests/SKCodecTest.cs | 28 ++++++++++++++++++ 23 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 tests/Content/images/png_chunks/good_idat_multiple.png create mode 100644 tests/Content/images/png_chunks/good_idat_some-empty.png create mode 100644 tests/Content/images/png_chunks/good_itxt.png create mode 100644 tests/Content/images/png_chunks/good_phys_96-dpi.png create mode 100644 tests/Content/images/png_chunks/good_splt.png create mode 100644 tests/Content/images/png_chunks/good_srgb.png create mode 100644 tests/Content/images/png_chunks/good_text.png create mode 100644 tests/Content/images/png_chunks/good_time_unix-epoch.png create mode 100644 tests/Content/images/png_chunks/good_ztxt.png diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 58ef4dc96c..23d9dbf1cd 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -775,7 +775,7 @@ public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKBitm public bool ReadPixels (SKImageInfo info, IntPtr dstPixels, int rowBytes, int x, int y) { - if (GetPixels () == null) + if (GetPixels () == IntPtr.Zero) return false; return Pixmap.ReadPixels (info, dstPixels, rowBytes, x, y); } @@ -785,7 +785,7 @@ public bool ReadPixels (SKPixmap dstPixmap) => public bool ReadPixels (SKPixmap dstPixmap, int x, int y) { - if (GetPixels () == null) + if (GetPixels () == IntPtr.Zero) return false; return Pixmap.ReadPixels (dstPixmap.Info, dstPixmap.GetPixels (), dstPixmap.RowBytes, x, y); } diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs index 9c2ec6edaf..21776e320a 100644 --- a/binding/Binding/SKCodec.cs +++ b/binding/Binding/SKCodec.cs @@ -326,6 +326,7 @@ public static SKCodec Create (SKStream stream, SKPngChunkReader chunkReader, SKC fixed (SKCodecResult* r = &result) { var codec = GetObject (SkiaApi.sk_codec_new_from_stream_with_pngchunkreader_and_selection_policy (stream.Handle, r, chunkReader?.Handle ?? IntPtr.Zero, selectionPolicy)); stream.RevokeOwnership (codec); + Referenced (codec, chunkReader); return codec; } } @@ -340,7 +341,9 @@ public static SKCodec Create (SKData data, SKPngChunkReader chunkReader) if (data == null) throw new ArgumentNullException (nameof (data)); - return GetObject (SkiaApi.sk_codec_new_from_data_with_pngchunkreader (data.Handle, chunkReader?.Handle ?? IntPtr.Zero)); + var codec = GetObject (SkiaApi.sk_codec_new_from_data_with_pngchunkreader (data.Handle, chunkReader?.Handle ?? IntPtr.Zero)); + Referenced (codec, chunkReader); + return codec; } // utils diff --git a/binding/Binding/SKObject.cs b/binding/Binding/SKObject.cs index d2e21c092d..b07fdc8d54 100644 --- a/binding/Binding/SKObject.cs +++ b/binding/Binding/SKObject.cs @@ -193,7 +193,7 @@ internal static T Owned (T owner, SKObject child) return owner; } - // indicate that the chile should not be garbage collected while + // indicate that the child should not be garbage collected while // the owner still lives internal static T Referenced (T owner, SKObject child) where T : SKObject diff --git a/native/android/build.cake b/native/android/build.cake index 7da2b657bb..5e58268421 100644 --- a/native/android/build.cake +++ b/native/android/build.cake @@ -36,7 +36,7 @@ Task("libSkiaSharp") $"skia_use_system_zlib=false " + $"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower () + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " + + $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] " + $"ndk='{ANDROID_NDK_HOME}' " + $"ndk_api={(skiaArch == "x64" || skiaArch == "arm64" ? 21 : 16)}"); diff --git a/native/ios/build.cake b/native/ios/build.cake index 8a3f3e51bf..742712e514 100644 --- a/native/ios/build.cake +++ b/native/ios/build.cake @@ -42,7 +42,7 @@ Task("libSkiaSharp") $"skia_use_system_libwebp=false " + $"skia_use_system_zlib=false " + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF' ] "); + $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] "); RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", sdk, arch, platform: VARIANT); diff --git a/native/linux/build.cake b/native/linux/build.cake index 2c1427aae5..890d8186d9 100644 --- a/native/linux/build.cake +++ b/native/linux/build.cake @@ -108,7 +108,7 @@ Task("libHarfBuzzSharp") $"target_cpu='{arch}' " + $"visibility_hidden=false " + $"extra_asmflags=[] " + - $"extra_cflags=[] " + + $"extra_cflags=[ '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] " + $"extra_ldflags=[ '-static-libstdc++', '-static-libgcc', '-Wl,--version-script={map}' ] " + COMPILERS + $"linux_soname_version='{soname}' " + diff --git a/native/macos/build.cake b/native/macos/build.cake index d52bb74cac..bdc399a96f 100644 --- a/native/macos/build.cake +++ b/native/macos/build.cake @@ -36,7 +36,9 @@ Task("libSkiaSharp") $"skia_use_system_libwebp=false " + $"skia_use_system_zlib=false " + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-stdlib=libc++' ] " + + $"extra_cflags=[ " + + $" '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED', " + + $" '-stdlib=libc++' ] " + $"extra_ldflags=[ '-stdlib=libc++' ]"); RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", "macosx", arch); diff --git a/native/tizen/build.cake b/native/tizen/build.cake index 2b0078e337..c2f7d3dd05 100644 --- a/native/tizen/build.cake +++ b/native/tizen/build.cake @@ -35,7 +35,7 @@ Task("libSkiaSharp") $"skia_use_system_libwebp=false " + $"skia_use_system_zlib=true " + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DXML_DEV_URANDOM', '-DSK_NO_MAKE_SHARED_PTR' ] " + + $"extra_cflags=[ '-DSKIA_C_DLL', '-DXML_DEV_URANDOM', '-DSK_NO_MAKE_SHARED_PTR', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] " + $"ncli='{TIZEN_STUDIO_HOME}' " + $"ncli_version='4.0'"); diff --git a/native/tvos/build.cake b/native/tvos/build.cake index 92beaae768..1f5097f272 100644 --- a/native/tvos/build.cake +++ b/native/tvos/build.cake @@ -31,7 +31,7 @@ Task("libSkiaSharp") $"skia_use_system_libwebp=false " + $"skia_use_system_zlib=false " + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF' ] "); + $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] "); RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", sdk, arch); diff --git a/native/uwp/build.cake b/native/uwp/build.cake index d7a4c6f78f..2f9273a236 100644 --- a/native/uwp/build.cake +++ b/native/uwp/build.cake @@ -41,7 +41,8 @@ Task("libSkiaSharp") win_vcvars_version + $"extra_cflags=[ " + $" '-DSKIA_C_DLL', '/MD{d}', '/EHsc', '/Z7', " + - $" '-DSK_HAS_DWRITE_1_H', '-DSK_HAS_DWRITE_2_H', '-DNO_GETENV', '-D_HAS_AUTO_PTR_ETC=1' ] " + + $" '-DSK_HAS_DWRITE_1_H', '-DSK_HAS_DWRITE_2_H', '-DNO_GETENV', '-D_HAS_AUTO_PTR_ETC=1', " + + $" '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] " + $"extra_ldflags=[ '/DEBUG:FULL' ]"); var outDir = OUTPUT_PATH.Combine(dir); diff --git a/native/wasm/build.cake b/native/wasm/build.cake index dd3ad00549..902aef45a8 100644 --- a/native/wasm/build.cake +++ b/native/wasm/build.cake @@ -52,6 +52,7 @@ Task("libSkiaSharp") $"extra_cflags=[ " + $" '-DSKIA_C_DLL', '-DXML_POOR_ENTROPY', " + $" '-DSKNX_NO_SIMD', '-DSK_DISABLE_AAA', '-DGR_GL_CHECK_ALLOC_WITH_GET_ERROR=0', " + + $" '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED', " + $" '-s', 'WARN_UNALIGNED=1' " + // '-s', 'USE_WEBGL2=1' (experimental) $"] " + $"extra_cflags_cc=[ '-frtti' ] " + diff --git a/native/watchos/build.cake b/native/watchos/build.cake index 645bd5f272..cb85370854 100644 --- a/native/watchos/build.cake +++ b/native/watchos/build.cake @@ -33,7 +33,7 @@ Task("libSkiaSharp") $"skia_use_system_libwebp=false " + $"skia_use_system_zlib=false " + $"skia_enable_skottie=true " + - $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF' ] "); + $"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_ARC4RANDOM_BUF', '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] "); RunXCodeBuild("libSkiaSharp/libSkiaSharp.xcodeproj", "libSkiaSharp", sdk, arch); diff --git a/native/windows/build.cake b/native/windows/build.cake index 0cda591bd3..f2fb3fda22 100644 --- a/native/windows/build.cake +++ b/native/windows/build.cake @@ -52,7 +52,9 @@ Task("libSkiaSharp") $"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower () + clang + win_vcvars_version + - $"extra_cflags=[ '-DSKIA_C_DLL', '/MT{d}', '/EHsc', '/Z7', '-D_HAS_AUTO_PTR_ETC=1' ] " + + $"extra_cflags=[ " + + $" '-DSKIA_C_DLL', '/MT{d}', '/EHsc', '/Z7', '-D_HAS_AUTO_PTR_ETC=1', "+ + $" '-DPNG_READ_UNKNOWN_CHUNKS_SUPPORTED' ] " + $"extra_ldflags=[ '/DEBUG:FULL' ] " + ADDITIONAL_GN_ARGS); diff --git a/tests/Content/images/png_chunks/good_idat_multiple.png b/tests/Content/images/png_chunks/good_idat_multiple.png new file mode 100644 index 0000000000000000000000000000000000000000..35f0c9e1de89155f4ac68bf093e1f5803e7738f0 GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`_bPHcuDF5Dr;JCWgN@55JlKMc6?i Z|A7o92FCS|OWy!l44$rjF6*2UngBx|5izopr0Mk_w*Z=?k literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_itxt.png b/tests/Content/images/png_chunks/good_itxt.png new file mode 100644 index 0000000000000000000000000000000000000000..0238718bd4de0b414b16d8b274fd833b3f19071d GIT binary patch literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`_bPUQZXt5Dr;JCWgQNfm|jA#nhPv@$$yp8mLb?c=5$kDHc1Zd(7ix#Q`C-j}mi UNwW&?1uA6lboFyt=akR{0D(^@`v3p{ literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_phys_96-dpi.png b/tests/Content/images/png_chunks/good_phys_96-dpi.png new file mode 100644 index 0000000000000000000000000000000000000000..3bb80fce72ebe99e204838c669d8578f27ccec4d GIT binary patch literal 91 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`_bP&H|6fVg?4jBOuH;Rhv&5D9G#S i;uyjq%gDs=_dk%!#K3s=@kMPQi^0>?&t;ucLK6U`AQ7Jc literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_splt.png b/tests/Content/images/png_chunks/good_splt.png new file mode 100644 index 0000000000000000000000000000000000000000..de93a1fe30f4a6252d823d8293f0cef143970fad GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`_bP@!|lV5ZBD~j1t|X%n}BW)PDxX z|3JXNn7eiVF(6+Nq$D`Aq9ipn53EQ)$OHs|N*Lbm0YMP!>1x>mpkiK67sn6|Sw<#? azd%6-CI-f{k1uKiSqz@8elF{r5}E*iAuG)Q literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_srgb.png b/tests/Content/images/png_chunks/good_srgb.png new file mode 100644 index 0000000000000000000000000000000000000000..1450fd5a3b61478c4e439829ed8daf3b1b0c6080 GIT binary patch literal 83 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`}|}#X;^)%;v{^gMl1gPZ!4!4p~Mf bhQI%TTqXv_vyU%o16d57u6{1-oD!MofTH}Y)Z`Kc zzr@PY?93lbeJMZ%yq+$OAsn)dObmbj1G!8LjAtKT)CRJIK{|u;(@M${i&7apQY#cv ZQ!-2Pi*ldvn*gO5JYD@<);T3K0RS4xBPaj> literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_time_unix-epoch.png b/tests/Content/images/png_chunks/good_time_unix-epoch.png new file mode 100644 index 0000000000000000000000000000000000000000..b14449ccf5b219faf5941f1873602cacb8f76411 GIT binary patch literal 89 zcmeAS@N?(olHy`uVBq!ia0vp^j3CSbBp9sfW`_bPUQZXt5Dr;JCWgQNfm|jA#mdKI;Vst0EiV39smFU literal 0 HcmV?d00001 diff --git a/tests/Content/images/png_chunks/good_ztxt.png b/tests/Content/images/png_chunks/good_ztxt.png new file mode 100644 index 0000000000000000000000000000000000000000..374334fe7980ac540d187d573e291c2fa364614b GIT binary patch literal 408 zcmV;J0cZY+P)8ey!zx2r!GAt^#u6@G9L6v<$>CLz}drZ(KL##;K z!79GusW&b-#EDVKT@2qr^@iGmVSOWI12yLr&ka=2_&X;t8?E?|gKC_hL>dj@b}uX5 zq7_)=x{+cIIe1P&-=sg(;mWge^QbE>teRK0lfBZ9oV=CH2+nn+CyL@(j?fWKr=ZIx zS;EeT>Cd2N4huqkN|Dt4Sd{M5Ib>TflnPJsjDY3JZG*}lnr`01M)qQs{v663`Rp&& zE5|O`8SQfBboa-5lILMgcF*LMxNyt1N}^P3xfw`#$r-9tOP_<&&jP7=*(5n~_7&#+ zzbOLE5~w}Dz=ap|TrfH5ZsT+Jf}?BrNM*0c literal 0 HcmV?d00001 diff --git a/tests/Tests/SKCodecTest.cs b/tests/Tests/SKCodecTest.cs index e7619e621f..c2c6db2f8a 100644 --- a/tests/Tests/SKCodecTest.cs +++ b/tests/Tests/SKCodecTest.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; using System.Net.Http; +using System.Runtime.CompilerServices; using System.Threading.Tasks; using Xunit; @@ -491,5 +493,31 @@ public void CanDecodeData(string image) Assert.Equal(SKCodecResult.Success, codec.GetPixels(out var pixels)); Assert.NotEmpty(pixels); } + + [SkippableFact] + public void CanReadPngChunks_iTXt() + { + var path = Path.Combine(PathToImages, "png_chunks/good_itxt.png"); + + using var chunkReader = new TestPngChunkReader(); + using var codec = SKCodec.Create(path, chunkReader, SKCodecSelectionPolicy.PreferStillImage, out var codecResult); + using var bmp = SKBitmap.Decode(codec); + + var chunks = chunkReader.Chunks; + + Assert.NotEmpty(chunks); + } + + unsafe class TestPngChunkReader : SKPngChunkReader + { + protected override bool ReadChunk(string tag, IntPtr data, IntPtr length) + { + var d = new ReadOnlySpan((void*)data, (int)length).ToArray(); + Chunks.Add((tag, d)); + return true; + } + + public List<(string, byte[])> Chunks { get; } = new List<(string, byte[])>(); + } } } From 44a5ecca9854662bbf62fa77c2ca20a99fb32785 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Sun, 21 Aug 2022 22:37:53 +1000 Subject: [PATCH 30/33] Update SKPngChunkReader.cs fix string for unable to create instance --- binding/Binding/SKPngChunkReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding/Binding/SKPngChunkReader.cs b/binding/Binding/SKPngChunkReader.cs index 9ce874971b..a737161c5c 100644 --- a/binding/Binding/SKPngChunkReader.cs +++ b/binding/Binding/SKPngChunkReader.cs @@ -27,7 +27,7 @@ protected SKPngChunkReader () Handle = SkiaApi.sk_managedpngchunkreader_new ((void*)userData); if (Handle == IntPtr.Zero) - throw new InvalidOperationException ("Unable to create a new SKManagedAllocator instance."); + throw new InvalidOperationException ("Unable to create a new SKPngChunkReader instance."); } protected override void DisposeNative () From 64241d9d989aebe532736c1f9257aff3bf849b66 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 26 Aug 2022 15:19:04 +1000 Subject: [PATCH 31/33] modify for Non Standard chunk --- tests/Tests/SKCodecTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Tests/SKCodecTest.cs b/tests/Tests/SKCodecTest.cs index c2c6db2f8a..c7fa0bc6d2 100644 --- a/tests/Tests/SKCodecTest.cs +++ b/tests/Tests/SKCodecTest.cs @@ -495,9 +495,9 @@ public void CanDecodeData(string image) } [SkippableFact] - public void CanReadPngChunks_iTXt() + public void CanReadPngChunks_NonStandard() { - var path = Path.Combine(PathToImages, "png_chunks/good_itxt.png"); + var path = Path.Combine(PathToImages, "png_chunks/NPatch.png"); using var chunkReader = new TestPngChunkReader(); using var codec = SKCodec.Create(path, chunkReader, SKCodecSelectionPolicy.PreferStillImage, out var codecResult); From b6ad3dd85627e1182d35da4f1ccf71feac000551 Mon Sep 17 00:00:00 2001 From: mgood7123 Date: Fri, 26 Aug 2022 15:21:16 +1000 Subject: [PATCH 32/33] Add files via upload --- tests/Content/images/png_chunks/circle.9.png | Bin 0 -> 493 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/Content/images/png_chunks/circle.9.png diff --git a/tests/Content/images/png_chunks/circle.9.png b/tests/Content/images/png_chunks/circle.9.png new file mode 100644 index 0000000000000000000000000000000000000000..9ae9518db88ec0569fca724e15cb718aa7d26951 GIT binary patch literal 493 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1|;R|J2nC-iM#^;97Z4m8UHlg@Aw}mmbvzo zDv%1vD+ozuU}EA_0CF^d7zjj>u>n{JEG7#T2hqqzGXDQxuZ}L3)2-bBRA%7m;uw-~ z@9nLFf=r4$tO1kUuCTp1w)$x0R%z(~?TeG;%4B{hDzdb^ey3A8*Xh;SKCgJb8GpfN8PdEM9+>Ni%c9ETYu1oHeFCrBHa-7w zJt0q=zx-NmDj8d1*U^O^{d?seE}$v&&q!e4Z|W>C>K9O+05>F1%a)SWPtJ z!HA|=d0!St@Sezh?c3xSc-PE1+u+)Kg=GTz0iT(f Date: Fri, 26 Aug 2022 15:23:05 +1000 Subject: [PATCH 33/33] Update SKCodecTest.cs --- tests/Tests/SKCodecTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Tests/SKCodecTest.cs b/tests/Tests/SKCodecTest.cs index c7fa0bc6d2..adc674293f 100644 --- a/tests/Tests/SKCodecTest.cs +++ b/tests/Tests/SKCodecTest.cs @@ -497,7 +497,7 @@ public void CanDecodeData(string image) [SkippableFact] public void CanReadPngChunks_NonStandard() { - var path = Path.Combine(PathToImages, "png_chunks/NPatch.png"); + var path = Path.Combine(PathToImages, "png_chunks/circle.9.png"); using var chunkReader = new TestPngChunkReader(); using var codec = SKCodec.Create(path, chunkReader, SKCodecSelectionPolicy.PreferStillImage, out var codecResult);