diff --git a/binding/Binding/Definitions.cs b/binding/Binding/Definitions.cs index 50906149fb..e44f97b61e 100644 --- a/binding/Binding/Definitions.cs +++ b/binding/Binding/Definitions.cs @@ -312,6 +312,83 @@ public readonly override int GetHashCode () } } + public struct SKAndroidCodecOptions : IEquatable + { + public static readonly SKAndroidCodecOptions Default; + + static SKAndroidCodecOptions() + { + Default = new SKAndroidCodecOptions(SKZeroInitialized.No); + } + + public SKAndroidCodecOptions(SKZeroInitialized zeroInitialized) + { + ZeroInitialized = zeroInitialized; + Subset = null; + SampleSize = 1; + } + public SKAndroidCodecOptions(SKZeroInitialized zeroInitialized, SKRectI subset) + { + ZeroInitialized = zeroInitialized; + Subset = subset; + SampleSize = 1; + } + public SKAndroidCodecOptions(SKRectI subset) + { + ZeroInitialized = SKZeroInitialized.No; + Subset = subset; + SampleSize = 1; + } + public SKAndroidCodecOptions(int frameIndex) + { + ZeroInitialized = SKZeroInitialized.No; + Subset = null; + SampleSize = 1; + } + public SKAndroidCodecOptions(int frameIndex, int priorFrame) + { + ZeroInitialized = SKZeroInitialized.No; + Subset = null; + SampleSize = 1; + } + + public SKZeroInitialized ZeroInitialized { readonly get; set; } + public SKRectI? Subset { readonly get; set; } + public readonly bool HasSubset => Subset != null; + public int SampleSize { readonly get; set; } + + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete] + public SKTransferFunctionBehavior PremulBehavior + { + readonly get => SKTransferFunctionBehavior.Respect; + set { } + } + + public readonly bool Equals(SKAndroidCodecOptions obj) => + ZeroInitialized == obj.ZeroInitialized && + Subset == obj.Subset && + SampleSize == obj.SampleSize; + + public readonly override bool Equals(object obj) => + obj is SKAndroidCodecOptions f && Equals(f); + + public static bool operator ==(SKAndroidCodecOptions left, SKAndroidCodecOptions right) => + left.Equals(right); + + public static bool operator !=(SKAndroidCodecOptions left, SKAndroidCodecOptions right) => + !left.Equals(right); + + public readonly override int GetHashCode() + { + var hash = new HashCode(); + hash.Add(ZeroInitialized); + hash.Add(Subset); + hash.Add(SampleSize); + return hash.ToHashCode(); + } + } + public partial struct SKFontMetrics { private const uint flagsUnderlineThicknessIsValid = (1U << 0); diff --git a/binding/Binding/SKAndroidCodec.cs b/binding/Binding/SKAndroidCodec.cs new file mode 100644 index 0000000000..cf5f22e598 --- /dev/null +++ b/binding/Binding/SKAndroidCodec.cs @@ -0,0 +1,286 @@ +using System; +using System.ComponentModel; +using System.IO; + +namespace SkiaSharp +{ + public unsafe class SKAndroidCodec : SKObject, ISKSkipObjectRegistration + { + internal SKAndroidCodec(IntPtr handle, bool owns) + : base(handle, owns) + { + } + + protected override void Dispose(bool disposing) => + base.Dispose(disposing); + + protected override void DisposeNative() => + SkiaApi.sk_android_codec_destroy(Handle); + + public SKImageInfo Info + { + get + { + SKImageInfoNative cinfo; + SkiaApi.sk_android_codec_get_info(Handle, &cinfo); + return SKImageInfoNative.ToManaged(ref cinfo); + } + } + + public SKCodec Codec => + SKCodec.GetObject(SkiaApi.sk_android_codec_get_codec(Handle)); + + public SKColorSpaceIccProfile ICCProfile => + SKColorSpaceIccProfile.GetObject(SkiaApi.sk_android_codec_get_icc_profile(Handle)); + + public SKEncodedImageFormat EncodedFormat => + SkiaApi.sk_android_codec_get_encoded_format(Handle); + + public SKColorType ComputeOutputColorType(SKColorType requestedColorType) + { + return SkiaApi.sk_android_codec_compute_output_color_type(Handle, requestedColorType.ToNative()).FromNative(); + } + + public SKAlphaType ComputeOutputAlphaType(bool requestedUnpremul) + { + return SkiaApi.sk_android_codec_compute_output_alpha(Handle, requestedUnpremul); + } + + public SKColorSpace ComputeOutputColorSpace(SKColorType outputColorType, SKColorSpace preferredColorSpace) + { + return SKColorSpace.GetObject(SkiaApi.sk_android_codec_compute_output_color_space(Handle, outputColorType.ToNative(), preferredColorSpace == null ? IntPtr.Zero : preferredColorSpace.Handle)); + } + + public SKSizeI GetSampledDimensions(int sampleSize) + { + SKSizeI dimensions; + SkiaApi.sk_android_codec_get_sampled_dimensions(Handle, sampleSize, &dimensions); + return dimensions; + } + + public bool GetSupportedSubset(ref SKRectI desiredSubset) + { + fixed (SKRectI* ds = &desiredSubset) + { + return SkiaApi.sk_android_codec_get_supported_subset(Handle, ds); + } + } + + public SKSizeI GetSampledSubsetDimensions(int sampleSize, ref SKRectI desiredSubset) + { + SKSizeI dimensions; + fixed (SKRectI* ds = &desiredSubset) + { + SkiaApi.sk_android_codec_get_sampled_subset_dimensions(Handle, sampleSize, &dimensions, ds); + } + return dimensions; + } + + // android pixels + + public SKCodecResult GetAndroidPixels (out byte[] pixels, SKAndroidCodecOptions options) => + GetAndroidPixels (Info, out pixels, options); + + public SKCodecResult GetAndroidPixels (SKImageInfo info, out byte[] pixels, SKAndroidCodecOptions options) + { + pixels = new byte[info.BytesSize]; + return GetAndroidPixels (info, pixels, options); + } + + public SKCodecResult GetAndroidPixels (SKImageInfo info, byte[] pixels, SKAndroidCodecOptions options) + { + if (pixels == null) + throw new ArgumentNullException (nameof (pixels)); + + fixed (byte* p = pixels) { + return GetAndroidPixels (info, (IntPtr)p, info.RowBytes, options); + } + } + + public SKCodecResult GetAndroidPixels (SKImageInfo info, IntPtr pixels, SKAndroidCodecOptions options) => + GetAndroidPixels (info, pixels, info.RowBytes, options); + + public SKCodecResult GetAndroidPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKAndroidCodecOptions options) + { + if (pixels == IntPtr.Zero) + throw new ArgumentNullException (nameof (pixels)); + + if (options == null) + throw new ArgumentNullException (nameof (options)); + + var nInfo = SKImageInfoNative.FromManaged (ref info); + var nOptions = new SKAndroidCodecOptionsInternal { + fZeroInitialized = options.ZeroInitialized, + fSubset = null, + fSampleSize = options.SampleSize, + }; + var subset = default (SKRectI); + if (options.HasSubset) { + subset = options.Subset.Value; + nOptions.fSubset = ⊂ + } + return SkiaApi.sk_android_codec_get_android_pixels (Handle, &nInfo, (void*)pixels, (IntPtr)rowBytes, &nOptions); + } + + // android pixels simplified + + public byte[] AndroidPixelsSimplified { + get { + var result = GetAndroidPixelsSimplified (out var pixels); + if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) { + throw new Exception (result.ToString ()); + } + return pixels; + } + } + + public SKCodecResult GetAndroidPixelsSimplified (out byte[] pixels) => + GetAndroidPixelsSimplified (Info, out pixels); + + public SKCodecResult GetAndroidPixelsSimplified (SKImageInfo info, out byte[] pixels) + { + pixels = new byte[info.BytesSize]; + return GetAndroidPixelsSimplified (info, pixels); + } + + public SKCodecResult GetAndroidPixelsSimplified (SKImageInfo info, byte[] pixels) + { + if (pixels == null) + throw new ArgumentNullException (nameof (pixels)); + + fixed (byte* p = pixels) { + return GetAndroidPixelsSimplified (info, (IntPtr)p, info.RowBytes); + } + } + + public SKCodecResult GetAndroidPixelsSimplified (SKImageInfo info, IntPtr pixels) => + GetAndroidPixelsSimplified (info, pixels, info.RowBytes); + + public SKCodecResult GetAndroidPixelsSimplified (SKImageInfo info, IntPtr pixels, int rowBytes) + { + if (pixels == IntPtr.Zero) + throw new ArgumentNullException (nameof (pixels)); + + var nInfo = SKImageInfoNative.FromManaged (ref info); + return SkiaApi.sk_android_codec_get_android_pixels_simplified (Handle, &nInfo, (void*)pixels, (IntPtr)rowBytes); + } + + + // pixels + + public byte[] Pixels + { + get + { + var result = GetPixels(out var pixels); + if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) + { + throw new Exception(result.ToString()); + } + return pixels; + } + } + + public SKCodecResult GetPixels(out byte[] pixels) => + GetPixels(Info, out pixels); + + public SKCodecResult GetPixels(SKImageInfo info, out byte[] pixels) + { + pixels = new byte[info.BytesSize]; + return GetPixels(info, pixels); + } + + public SKCodecResult GetPixels(SKImageInfo info, byte[] pixels) + { + if (pixels == null) + throw new ArgumentNullException(nameof(pixels)); + + fixed (byte* p = pixels) + { + return GetPixels(info, (IntPtr)p, info.RowBytes); + } + } + + public SKCodecResult GetPixels(SKImageInfo info, IntPtr pixels, int rowBytes) + { + if (pixels == IntPtr.Zero) + throw new ArgumentNullException(nameof(pixels)); + + var nInfo = SKImageInfoNative.FromManaged(ref info); + return SkiaApi.sk_android_codec_get_pixels(Handle, &nInfo, (void*)pixels, (IntPtr)rowBytes); + } + + // create (Codec) + + public static SKAndroidCodec Create(SKCodec codec) + { + return Create(codec, SKAndroidCodecExifOrientationBehavior.KIgnore); + } + + public static SKAndroidCodec Create(SKCodec codec, SKAndroidCodecExifOrientationBehavior behavior) + { + if (codec == null) + throw new ArgumentNullException(nameof(codec)); + var handle = SkiaApi.sk_android_codec_new_from_codec(codec.Handle, behavior); + SKAndroidCodec c = GetObject(handle); + codec.RevokeOwnership(c); + return c; + } + + // create (streams) + + public static SKAndroidCodec Create(string filename) => + Create(filename, null); + + public static SKAndroidCodec Create(string filename, SKPngChunkReader chunkReader) + { + if (filename == null) + throw new ArgumentNullException (nameof(filename)); + + var stream = SKFileStream.OpenStream(filename); + if (stream == null) + { + return null; + } + + return Create(stream, chunkReader); + } + + + public static SKAndroidCodec Create(SKStream stream) => + Create(stream, null); + + public static SKAndroidCodec Create(SKStream stream, SKPngChunkReader chunkReader) + { + if (stream == null) + throw new ArgumentNullException(nameof(stream)); + if (stream is SKFileStream filestream && !filestream.IsValid) + throw new ArgumentException("File stream was not valid.", nameof(stream)); + + var codec = GetObject(SkiaApi.sk_android_codec_new_from_stream(stream.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); + stream.RevokeOwnership(codec); + return codec; + } + + + // create (data) + + public static SKAndroidCodec Create(SKData data) + { + return Create(data, null); + } + + public static SKAndroidCodec Create(SKData data, SKPngChunkReader chunkReader) + { + if (data == null) + throw new ArgumentNullException(nameof(data)); + + return GetObject(SkiaApi.sk_android_codec_new_from_data(data.Handle, chunkReader == null ? IntPtr.Zero : chunkReader.Handle)); + } + + // utils + + internal static SKAndroidCodec GetObject(IntPtr handle) => + handle == IntPtr.Zero ? null : new SKAndroidCodec(handle, true); + } +} diff --git a/binding/Binding/SKColorSpaceStructs.cs b/binding/Binding/SKColorSpaceStructs.cs index 973ca9847e..5aa81e850f 100644 --- a/binding/Binding/SKColorSpaceStructs.cs +++ b/binding/Binding/SKColorSpaceStructs.cs @@ -527,5 +527,8 @@ public static SKColorSpaceIccProfile Create (IntPtr data, long length) } return icc; } + + internal static SKColorSpaceIccProfile GetObject(IntPtr handle) => + handle == IntPtr.Zero ? null : new SKColorSpaceIccProfile(handle, true); } } diff --git a/binding/Binding/SkiaApi.generated.cs b/binding/Binding/SkiaApi.generated.cs index 8a70b54134..77e9d14b86 100644 --- a/binding/Binding/SkiaApi.generated.cs +++ b/binding/Binding/SkiaApi.generated.cs @@ -17,6 +17,7 @@ using gr_vk_memory_allocator_t = System.IntPtr; using gr_vkinterface_t = System.IntPtr; using sk_3dview_t = System.IntPtr; +using sk_android_codec_t = System.IntPtr; using sk_bitmap_t = System.IntPtr; using sk_canvas_t = System.IntPtr; using sk_codec_t = System.IntPtr; @@ -2356,6 +2357,260 @@ internal static sk_overdraw_canvas_t sk_overdraw_canvas_new (sk_canvas_t canvas) #region sk_codec.h + // sk_alphatype_t sk_android_codec_compute_output_alpha(sk_android_codec_t* codec, bool requestedUnpremul) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKAlphaType sk_android_codec_compute_output_alpha (sk_android_codec_t codec, [MarshalAs (UnmanagedType.I1)] bool requestedUnpremul); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKAlphaType sk_android_codec_compute_output_alpha (sk_android_codec_t codec, [MarshalAs (UnmanagedType.I1)] bool requestedUnpremul); + } + private static Delegates.sk_android_codec_compute_output_alpha sk_android_codec_compute_output_alpha_delegate; + internal static SKAlphaType sk_android_codec_compute_output_alpha (sk_android_codec_t codec, [MarshalAs (UnmanagedType.I1)] bool requestedUnpremul) => + (sk_android_codec_compute_output_alpha_delegate ??= GetSymbol ("sk_android_codec_compute_output_alpha")).Invoke (codec, requestedUnpremul); + #endif + + // sk_colorspace_t* sk_android_codec_compute_output_color_space(sk_android_codec_t* codec, sk_colortype_t output_color_type, sk_colorspace_t* prefColorSpace) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_colorspace_t sk_android_codec_compute_output_color_space (sk_android_codec_t codec, SKColorTypeNative output_color_type, sk_colorspace_t prefColorSpace); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_colorspace_t sk_android_codec_compute_output_color_space (sk_android_codec_t codec, SKColorTypeNative output_color_type, sk_colorspace_t prefColorSpace); + } + private static Delegates.sk_android_codec_compute_output_color_space sk_android_codec_compute_output_color_space_delegate; + internal static sk_colorspace_t sk_android_codec_compute_output_color_space (sk_android_codec_t codec, SKColorTypeNative output_color_type, sk_colorspace_t prefColorSpace) => + (sk_android_codec_compute_output_color_space_delegate ??= GetSymbol ("sk_android_codec_compute_output_color_space")).Invoke (codec, output_color_type, prefColorSpace); + #endif + + // sk_colortype_t sk_android_codec_compute_output_color_type(sk_android_codec_t* codec, sk_colortype_t requested_color_type) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKColorTypeNative sk_android_codec_compute_output_color_type (sk_android_codec_t codec, SKColorTypeNative requested_color_type); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKColorTypeNative sk_android_codec_compute_output_color_type (sk_android_codec_t codec, SKColorTypeNative requested_color_type); + } + private static Delegates.sk_android_codec_compute_output_color_type sk_android_codec_compute_output_color_type_delegate; + internal static SKColorTypeNative sk_android_codec_compute_output_color_type (sk_android_codec_t codec, SKColorTypeNative requested_color_type) => + (sk_android_codec_compute_output_color_type_delegate ??= GetSymbol ("sk_android_codec_compute_output_color_type")).Invoke (codec, requested_color_type); + #endif + + // int32_t sk_android_codec_compute_sample_size(sk_android_codec_t* codec, sk_isize_t* size) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern Int32 sk_android_codec_compute_sample_size (sk_android_codec_t codec, SKSizeI* size); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate Int32 sk_android_codec_compute_sample_size (sk_android_codec_t codec, SKSizeI* size); + } + private static Delegates.sk_android_codec_compute_sample_size sk_android_codec_compute_sample_size_delegate; + internal static Int32 sk_android_codec_compute_sample_size (sk_android_codec_t codec, SKSizeI* size) => + (sk_android_codec_compute_sample_size_delegate ??= GetSymbol ("sk_android_codec_compute_sample_size")).Invoke (codec, size); + #endif + + // void sk_android_codec_destroy(sk_android_codec_t* codec) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_android_codec_destroy (sk_android_codec_t codec); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_android_codec_destroy (sk_android_codec_t codec); + } + private static Delegates.sk_android_codec_destroy sk_android_codec_destroy_delegate; + internal static void sk_android_codec_destroy (sk_android_codec_t codec) => + (sk_android_codec_destroy_delegate ??= GetSymbol ("sk_android_codec_destroy")).Invoke (codec); + #endif + + // sk_codec_result_t sk_android_codec_get_android_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes, const sk_android_codec_options_t* options) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKCodecResult sk_android_codec_get_android_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes, SKAndroidCodecOptionsInternal* options); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKCodecResult sk_android_codec_get_android_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes, SKAndroidCodecOptionsInternal* options); + } + private static Delegates.sk_android_codec_get_android_pixels sk_android_codec_get_android_pixels_delegate; + internal static SKCodecResult sk_android_codec_get_android_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes, SKAndroidCodecOptionsInternal* options) => + (sk_android_codec_get_android_pixels_delegate ??= GetSymbol ("sk_android_codec_get_android_pixels")).Invoke (codec, info, pixels, rowBytes, options); + #endif + + // sk_codec_result_t sk_android_codec_get_android_pixels_simplified(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKCodecResult sk_android_codec_get_android_pixels_simplified (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKCodecResult sk_android_codec_get_android_pixels_simplified (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes); + } + private static Delegates.sk_android_codec_get_android_pixels_simplified sk_android_codec_get_android_pixels_simplified_delegate; + internal static SKCodecResult sk_android_codec_get_android_pixels_simplified (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes) => + (sk_android_codec_get_android_pixels_simplified_delegate ??= GetSymbol ("sk_android_codec_get_android_pixels_simplified")).Invoke (codec, info, pixels, rowBytes); + #endif + + // sk_codec_t* sk_android_codec_get_codec(sk_android_codec_t* codec) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_codec_t sk_android_codec_get_codec (sk_android_codec_t codec); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_codec_t sk_android_codec_get_codec (sk_android_codec_t codec); + } + private static Delegates.sk_android_codec_get_codec sk_android_codec_get_codec_delegate; + internal static sk_codec_t sk_android_codec_get_codec (sk_android_codec_t codec) => + (sk_android_codec_get_codec_delegate ??= GetSymbol ("sk_android_codec_get_codec")).Invoke (codec); + #endif + + // sk_encoded_image_format_t sk_android_codec_get_encoded_format(sk_android_codec_t* codec) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKEncodedImageFormat sk_android_codec_get_encoded_format (sk_android_codec_t codec); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKEncodedImageFormat sk_android_codec_get_encoded_format (sk_android_codec_t codec); + } + private static Delegates.sk_android_codec_get_encoded_format sk_android_codec_get_encoded_format_delegate; + internal static SKEncodedImageFormat sk_android_codec_get_encoded_format (sk_android_codec_t codec) => + (sk_android_codec_get_encoded_format_delegate ??= GetSymbol ("sk_android_codec_get_encoded_format")).Invoke (codec); + #endif + + // const sk_colorspace_icc_profile_t* sk_android_codec_get_icc_profile(sk_android_codec_t* codec) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_colorspace_icc_profile_t sk_android_codec_get_icc_profile (sk_android_codec_t codec); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_colorspace_icc_profile_t sk_android_codec_get_icc_profile (sk_android_codec_t codec); + } + private static Delegates.sk_android_codec_get_icc_profile sk_android_codec_get_icc_profile_delegate; + internal static sk_colorspace_icc_profile_t sk_android_codec_get_icc_profile (sk_android_codec_t codec) => + (sk_android_codec_get_icc_profile_delegate ??= GetSymbol ("sk_android_codec_get_icc_profile")).Invoke (codec); + #endif + + // void sk_android_codec_get_info(sk_android_codec_t* codec, sk_imageinfo_t* info) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_android_codec_get_info (sk_android_codec_t codec, SKImageInfoNative* info); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_android_codec_get_info (sk_android_codec_t codec, SKImageInfoNative* info); + } + private static Delegates.sk_android_codec_get_info sk_android_codec_get_info_delegate; + internal static void sk_android_codec_get_info (sk_android_codec_t codec, SKImageInfoNative* info) => + (sk_android_codec_get_info_delegate ??= GetSymbol ("sk_android_codec_get_info")).Invoke (codec, info); + #endif + + // sk_codec_result_t sk_android_codec_get_pixels(sk_android_codec_t* codec, const sk_imageinfo_t* info, void* pixels, size_t rowBytes) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern SKCodecResult sk_android_codec_get_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate SKCodecResult sk_android_codec_get_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes); + } + private static Delegates.sk_android_codec_get_pixels sk_android_codec_get_pixels_delegate; + internal static SKCodecResult sk_android_codec_get_pixels (sk_android_codec_t codec, SKImageInfoNative* info, void* pixels, /* size_t */ IntPtr rowBytes) => + (sk_android_codec_get_pixels_delegate ??= GetSymbol ("sk_android_codec_get_pixels")).Invoke (codec, info, pixels, rowBytes); + #endif + + // void sk_android_codec_get_sampled_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_android_codec_get_sampled_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_android_codec_get_sampled_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions); + } + private static Delegates.sk_android_codec_get_sampled_dimensions sk_android_codec_get_sampled_dimensions_delegate; + internal static void sk_android_codec_get_sampled_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions) => + (sk_android_codec_get_sampled_dimensions_delegate ??= GetSymbol ("sk_android_codec_get_sampled_dimensions")).Invoke (codec, sampleSize, dimensions); + #endif + + // void sk_android_codec_get_sampled_subset_dimensions(sk_android_codec_t* codec, int32_t sampleSize, sk_isize_t* dimensions, sk_irect_t* subset) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern void sk_android_codec_get_sampled_subset_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions, SKRectI* subset); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate void sk_android_codec_get_sampled_subset_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions, SKRectI* subset); + } + private static Delegates.sk_android_codec_get_sampled_subset_dimensions sk_android_codec_get_sampled_subset_dimensions_delegate; + internal static void sk_android_codec_get_sampled_subset_dimensions (sk_android_codec_t codec, Int32 sampleSize, SKSizeI* dimensions, SKRectI* subset) => + (sk_android_codec_get_sampled_subset_dimensions_delegate ??= GetSymbol ("sk_android_codec_get_sampled_subset_dimensions")).Invoke (codec, sampleSize, dimensions, subset); + #endif + + // bool sk_android_codec_get_supported_subset(sk_android_codec_t* codec, sk_irect_t* desiredSubset) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal static extern bool sk_android_codec_get_supported_subset (sk_android_codec_t codec, SKRectI* desiredSubset); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + [return: MarshalAs (UnmanagedType.I1)] + internal delegate bool sk_android_codec_get_supported_subset (sk_android_codec_t codec, SKRectI* desiredSubset); + } + private static Delegates.sk_android_codec_get_supported_subset sk_android_codec_get_supported_subset_delegate; + internal static bool sk_android_codec_get_supported_subset (sk_android_codec_t codec, SKRectI* desiredSubset) => + (sk_android_codec_get_supported_subset_delegate ??= GetSymbol ("sk_android_codec_get_supported_subset")).Invoke (codec, desiredSubset); + #endif + + // sk_android_codec_t* sk_android_codec_new_from_codec(sk_codec_t* codec, sk_android_codec_exif_orientation_behavior_t behaviour) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_android_codec_t sk_android_codec_new_from_codec (sk_codec_t codec, SKAndroidCodecExifOrientationBehavior behaviour); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_android_codec_t sk_android_codec_new_from_codec (sk_codec_t codec, SKAndroidCodecExifOrientationBehavior behaviour); + } + private static Delegates.sk_android_codec_new_from_codec sk_android_codec_new_from_codec_delegate; + internal static sk_android_codec_t sk_android_codec_new_from_codec (sk_codec_t codec, SKAndroidCodecExifOrientationBehavior behaviour) => + (sk_android_codec_new_from_codec_delegate ??= GetSymbol ("sk_android_codec_new_from_codec")).Invoke (codec, behaviour); + #endif + + // sk_android_codec_t* sk_android_codec_new_from_data(sk_data_t* data, sk_png_chunk_reader_t* chunk_reader) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_android_codec_t sk_android_codec_new_from_data (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_android_codec_t sk_android_codec_new_from_data (sk_data_t data, sk_png_chunk_reader_t chunk_reader); + } + private static Delegates.sk_android_codec_new_from_data sk_android_codec_new_from_data_delegate; + internal static sk_android_codec_t sk_android_codec_new_from_data (sk_data_t data, sk_png_chunk_reader_t chunk_reader) => + (sk_android_codec_new_from_data_delegate ??= GetSymbol ("sk_android_codec_new_from_data")).Invoke (data, chunk_reader); + #endif + + // sk_android_codec_t* sk_android_codec_new_from_stream(sk_stream_t* stream, sk_png_chunk_reader_t* chunk_reader) + #if !USE_DELEGATES + [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] + internal static extern sk_android_codec_t sk_android_codec_new_from_stream (sk_stream_t stream, sk_png_chunk_reader_t chunk_reader); + #else + private partial class Delegates { + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + internal delegate sk_android_codec_t sk_android_codec_new_from_stream (sk_stream_t stream, sk_png_chunk_reader_t chunk_reader); + } + private static Delegates.sk_android_codec_new_from_stream sk_android_codec_new_from_stream_delegate; + internal static sk_android_codec_t sk_android_codec_new_from_stream (sk_stream_t stream, sk_png_chunk_reader_t chunk_reader) => + (sk_android_codec_new_from_stream_delegate ??= GetSymbol ("sk_android_codec_new_from_stream")).Invoke (stream, chunk_reader); + #endif + // void sk_codec_destroy(sk_codec_t* codec) #if !USE_DELEGATES [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -14039,6 +14294,41 @@ public readonly override int GetHashCode () } + // sk_android_codec_options_t + [StructLayout (LayoutKind.Sequential)] + internal unsafe partial struct SKAndroidCodecOptionsInternal : IEquatable { + // public sk_codec_zero_initialized_t fZeroInitialized + public SKZeroInitialized fZeroInitialized; + + // public sk_irect_t* fSubset + public SKRectI* fSubset; + + // public int fSampleSize + public Int32 fSampleSize; + + public readonly bool Equals (SKAndroidCodecOptionsInternal obj) => + fZeroInitialized == obj.fZeroInitialized && fSubset == obj.fSubset && fSampleSize == obj.fSampleSize; + + public readonly override bool Equals (object obj) => + obj is SKAndroidCodecOptionsInternal f && Equals (f); + + public static bool operator == (SKAndroidCodecOptionsInternal left, SKAndroidCodecOptionsInternal right) => + left.Equals (right); + + public static bool operator != (SKAndroidCodecOptionsInternal left, SKAndroidCodecOptionsInternal right) => + !left.Equals (right); + + public readonly override int GetHashCode () + { + var hash = new HashCode (); + hash.Add (fZeroInitialized); + hash.Add (fSubset); + hash.Add (fSampleSize); + return hash.ToHashCode (); + } + + } + // sk_codec_frameinfo_t [StructLayout (LayoutKind.Sequential)] public unsafe partial struct SKCodecFrameInfo : IEquatable { @@ -15646,6 +15936,14 @@ public enum SKAlphaType { Unpremul = 3, } + // sk_android_codec_exif_orientation_behavior_t + public enum SKAndroidCodecExifOrientationBehavior { + // kIgnore = 0 + KIgnore = 0, + // kRespect = 1 + KRespect = 1, + } + // sk_bitmap_allocflags_t [Flags] public enum SKBitmapAllocFlags { diff --git a/binding/libSkiaSharp.json b/binding/libSkiaSharp.json index cf4cc50988..543e80f7ed 100644 --- a/binding/libSkiaSharp.json +++ b/binding/libSkiaSharp.json @@ -365,6 +365,10 @@ "cs": "SKCodecOptionsInternal", "internal": true }, + "sk_android_codec_options_t": { + "cs": "SKAndroidCodecOptionsInternal", + "internal": true + }, "sk_document_pdf_metadata_t": { "cs": "SKDocumentPdfMetadataInternal", "internal": true