* [ImageUtil] Replace deprecated pinvoke func.
using System;
using System.Collections.Generic;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
internal override void Configure(TransformHandle handle)
{
- SetColorspace(handle, _imageColorSpace);
+ NativeTransform.SetColorspace(handle, _imageColorSpace);
}
*/
using System;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
internal override void Configure(TransformHandle handle)
{
- SetCropArea(handle, Region.Left, Region.Top, Region.Right, Region.Bottom);
+ NativeTransform.SetCropArea(handle, Region.Left, Region.Top, Region.Right, Region.Bottom);
}
internal override void ValidateFormat(VideoMediaFormat format)
using System;
using System.Threading.Tasks;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
private async Task<MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source,
ImageRotation rotation)
{
- SetRotation(handle, rotation);
+ NativeTransform.SetRotation(handle, rotation);
return await RunAsync(handle, source);
}
using System.Threading;
using System.Threading.Tasks;
using static Interop;
-using static Interop.Decode;
+using NativeUtil = Interop.ImageUtil;
+using NativeDecoder = Interop.ImageUtil.Decode;
namespace Tizen.Multimedia.Util
{
internal ImageDecoder(ImageFormat format)
{
- Create(out _handle).ThrowIfFailed("Failed to create ImageDecoder");
+ NativeDecoder.Create(out _handle).ThrowIfFailed("Failed to create ImageDecoder");
Debug.Assert(_handle != null);
var pathPtr = Marshal.StringToHGlobalAnsi(inputFilePath);
try
{
- SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");
+ NativeDecoder.SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");
+
return await DecodeAsync();
}
finally
throw new FileFormatException("buffer has an invalid header.");
}
- SetInputBuffer(Handle, inputBuffer, (ulong)inputBuffer.Length).
+ NativeDecoder.SetInputBuffer(Handle, inputBuffer, (ulong)inputBuffer.Length).
ThrowIfFailed("Failed to set input buffer for decoding");
return DecodeAsync();
private IEnumerable<BitmapFrame> RunDecoding()
{
- IntPtr outBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
- Marshal.WriteIntPtr(outBuffer, IntPtr.Zero);
+ IntPtr imageHandle = IntPtr.Zero;
+ IntPtr outBuffer = IntPtr.Zero;
try
{
- SetOutputBuffer(Handle, outBuffer).ThrowIfFailed("Failed to decode given image");
+ NativeDecoder.DecodeRun(Handle, out imageHandle).ThrowIfFailed("Failed to decode");
- DecodeRun(Handle, out var width, out var height, out var size).
- ThrowIfFailed("Failed to decode");
+ NativeUtil.GetImage(imageHandle, out int width, out int height, out ImageColorSpace colorspace,
+ out outBuffer, out int size).ThrowIfFailed("Failed to get decoded image.");
- yield return new BitmapFrame(Marshal.ReadIntPtr(outBuffer), width, height, (int)size);
+ yield return new BitmapFrame(outBuffer, width, height, size);
}
finally
{
- if (Marshal.ReadIntPtr(outBuffer) != IntPtr.Zero)
+ if (outBuffer != IntPtr.Zero)
{
- LibcSupport.Free(Marshal.ReadIntPtr(outBuffer));
+ LibcSupport.Free(outBuffer);
}
- Marshal.FreeHGlobal(outBuffer);
+ if (imageHandle != IntPtr.Zero)
+ {
+ NativeUtil.Destroy(imageHandle).ThrowIfFailed("Failed to destroy handle");
+ }
}
}
{
if (_colorSpace.HasValue)
{
- SetColorspace(Handle, _colorSpace.Value.ToImageColorSpace()).ThrowIfFailed("Failed to set color space");
+ NativeDecoder.SetColorspace(Handle, _colorSpace.Value.ToImageColorSpace()).ThrowIfFailed("Failed to set color space");
}
}
{
base.Initialize(handle);
- SetJpegDownscale(handle, Downscale).ThrowIfFailed("Failed to set downscale for decoding");
+ NativeDecoder.SetJpegDownscale(handle, Downscale).ThrowIfFailed("Failed to set downscale for decoding");
}
internal override byte[] Header => _header;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
-using static Interop.ImageUtil;
-using Unmanaged = Interop.ImageUtil.Encode;
+using static Interop;
+using NativeEncoder = Interop.ImageUtil.Encode;
namespace Tizen.Multimedia.Util
{
internal ImageEncoder(ImageFormat format)
{
- Unmanaged.Create(format, out _handle).ThrowIfFailed("Failed to create ImageEncoder");
+ NativeEncoder.Create(format, out _handle).ThrowIfFailed("Failed to create ImageEncoder");
Debug.Assert(_handle != null);
"The height of resolution can't be less than or equal to zero.");
}
- Unmanaged.SetResolution(Handle, (uint)resolution.Width, (uint)resolution.Height).
+ NativeEncoder.SetResolution(Handle, (uint)resolution.Width, (uint)resolution.Height).
ThrowIfFailed("Failed to set the resolution");
_hasResolution = true;
throw new NotSupportedException($"{colorSpace.ToString()} is not supported for {OutputFormat}.");
}
- Unmanaged.SetColorspace(Handle, colorSpace.ToImageColorSpace()).
+ NativeEncoder.SetColorspace(Handle, colorSpace.ToImageColorSpace()).
ThrowIfFailed("Failed to set the color space");
}
try
{
- Unmanaged.SetOutputBuffer(Handle, out outBuffer).ThrowIfFailed("Failed to initialize encoder");
+ NativeEncoder.SetOutputBuffer(Handle, out outBuffer).ThrowIfFailed("Failed to initialize encoder");
- Unmanaged.Run(Handle, out var size).ThrowIfFailed("Failed to encode given image");
+ NativeEncoder.Run(Handle, out var size).ThrowIfFailed("Failed to encode given image");
byte[] buf = new byte[size];
Marshal.Copy(outBuffer, buf, 0, (int)size);
return EncodeAsync(handle =>
{
- Unmanaged.SetInputBuffer(handle, inputBuffer).
+ NativeEncoder.SetInputBuffer(handle, inputBuffer).
ThrowIfFailed("Failed to configure encoder; InputBuffer");
}, outStream);
}
{
if (_compression.HasValue)
{
- Unmanaged.SetPngCompression(handle, _compression.Value).
+ NativeEncoder.SetPngCompression(handle, _compression.Value).
ThrowIfFailed("Failed to configure encoder; PngCompression");
}
}
{
if (_quality.HasValue)
{
- Unmanaged.SetQuality(handle, _quality.Value).
+ NativeEncoder.SetQuality(handle, _quality.Value).
ThrowIfFailed("Failed to configure encoder; Quality");
}
}
{
throw new ArgumentNullException(nameof(frames));
}
- Unmanaged.SetInputBuffer(handle, frame.Buffer).
+ NativeEncoder.SetInputBuffer(handle, frame.Buffer).
ThrowIfFailed("Failed to configure encoder; Buffer");
- Unmanaged.SetGifFrameDelayTime(handle, (ulong)frame.Delay).
+ NativeEncoder.SetGifFrameDelayTime(handle, (ulong)frame.Delay).
ThrowIfFailed("Failed to configure encoder; Delay");
}
}, outStream);
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
using (var cbKeeper = ObjectKeeper.Get(GetCallback(tcs, source)))
{
- var result = Run(handle, source.GetHandle(), cbKeeper.Target);
+ var result = NativeTransform.Run(handle, source.GetHandle(), cbKeeper.Target);
if (result == ImageUtilError.NotSupportedFormat)
{
}
}
- private TransformCompletedCallback GetCallback(TaskCompletionSource<MediaPacket> tcs,
+ private NativeTransform.TransformCompletedCallback GetCallback(TaskCompletionSource<MediaPacket> tcs,
MediaPacket source)
{
return (nativehandle, errorCode, _) =>
internal static TransformHandle CreateHandle()
{
- Create(out var handle).ThrowIfFailed("Failed to run ImageTransformer");
+ NativeTransform.Create(out var handle).ThrowIfFailed("Failed to run ImageTransformer");
Debug.Assert(handle != null);
return handle;
}
*/
using System.Threading.Tasks;
-using static Interop.ImageUtil;
+using static Interop;
namespace Tizen.Multimedia.Util
{
using System;
using System.Collections.Generic;
using Tizen.Common;
-using static Interop.ImageUtil;
+using NativeUtil = Interop.ImageUtil;
namespace Tizen.Multimedia.Util
{
var colorspaces = new List<ColorSpace>();
- ForeachSupportedColorspace(format,
+ NativeUtil.ForeachSupportedColorspace(format,
(colorspace, _) => { colorspaces.Add(colorspace.ToCommonColorSpace()); return true; }).
ThrowIfFailed("Failed to get supported color-space list from native handle");
"height can't be less than or equal to zero.");
}
- ExtractColorFromMemory(buffer, size.Width, size.Height, out var r, out var g, out var b)
+ NativeUtil.ExtractColorFromMemory(buffer, size.Width, size.Height, out var r, out var g, out var b)
.ThrowIfFailed("Failed to extract color from buffer");
return Color.FromRgb(r, g, b);
*/
using System;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
internal override void Configure(TransformHandle handle)
{
- SetResolution(handle, (uint)Size.Width, (uint)Size.Height);
+ NativeTransform.SetResolution(handle, (uint)Size.Width, (uint)Size.Height);
}
}
}
using System;
using System.Diagnostics;
-using static Interop.ImageUtil;
-using static Interop.ImageUtil.Transform;
+using static Interop;
+using NativeTransform = Interop.ImageUtil.Transform;
namespace Tizen.Multimedia.Util
{
internal override void Configure(TransformHandle handle)
{
- SetRotation(handle, GetImageRotation());
+ NativeTransform.SetRotation(handle, GetImageRotation());
}
private ImageRotation GetImageRotation()
internal static partial class Interop
{
- internal static class Decode
+ internal static partial class ImageUtil
{
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void DecodeCompletedCallback(ImageUtilError error, IntPtr userData, int width, int height, ulong size);
-
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
- public static extern ImageUtilError Create(out ImageDecoderHandle handle);
-
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
- internal static extern ImageUtilError Destroy(IntPtr handle);
+ internal static partial class Decode
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DecodeCompletedCallback(ImageUtilError error, IntPtr userData, int width, int height, ulong size);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
- internal static extern ImageUtilError SetInputPath(ImageDecoderHandle handle, IntPtr path);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
+ public static extern ImageUtilError Create(out ImageDecoderHandle handle);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
- internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
+ internal static extern ImageUtilError Destroy(IntPtr handle);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_output_buffer")]
- internal static extern ImageUtilError SetOutputBuffer(ImageDecoderHandle handle, IntPtr dstBuffer);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
+ internal static extern ImageUtilError SetInputPath(ImageDecoderHandle handle, IntPtr path);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
- internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
+ internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
- internal static extern ImageUtilError SetJpegDownscale(ImageDecoderHandle handle, JpegDownscale downscale);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
+ internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run_async")]
- internal static extern ImageUtilError DecodeRunAsync(ImageDecoderHandle handle, DecodeCompletedCallback callback,
- IntPtr userData = default(IntPtr));
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
+ internal static extern ImageUtilError SetJpegDownscale(ImageDecoderHandle handle, JpegDownscale downscale);
- [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run")]
- internal static extern ImageUtilError DecodeRun(ImageDecoderHandle handle, out int width,
- out int height, out ulong size);
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run2")]
+ internal static extern ImageUtilError DecodeRun(ImageDecoderHandle handle, out IntPtr imageHandle);
+ }
}
internal class ImageDecoderHandle : SafeHandle
protected override bool ReleaseHandle()
{
- var ret = Decode.Destroy(handle);
+ var ret = ImageUtil.Decode.Destroy(handle);
if (ret != ImageUtilError.None)
{
Log.Debug(GetType().FullName, $"Failed to release native {GetType()}");
return true;
}
-
}
}
[DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run")]
internal static extern ImageUtilError Run(ImageEncoderHandle handle, out ulong size);
}
+ }
- internal class ImageEncoderHandle : SafeHandle
+ internal class ImageEncoderHandle : SafeHandle
+ {
+ protected ImageEncoderHandle() : base(IntPtr.Zero, true)
{
- protected ImageEncoderHandle() : base(IntPtr.Zero, true)
- {
- }
+ }
- public override bool IsInvalid => handle == IntPtr.Zero;
+ public override bool IsInvalid => handle == IntPtr.Zero;
- protected override bool ReleaseHandle()
+ protected override bool ReleaseHandle()
+ {
+ var ret = ImageUtil.Encode.Destroy(handle);
+ if (ret != ImageUtilError.None)
{
- var ret = Encode.Destroy(handle);
- if (ret != ImageUtilError.None)
- {
- Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
- return false;
- }
-
- return true;
+ Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
+ return false;
}
+
+ return true;
}
}
}
[DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_resolution")]
internal static extern ImageUtilError SetResolution(TransformHandle handle, uint width, uint height);
}
+ }
- internal class TransformHandle : SafeHandle
+ internal class TransformHandle : SafeHandle
+ {
+ protected TransformHandle() : base(IntPtr.Zero, true)
{
- protected TransformHandle() : base(IntPtr.Zero, true)
- {
- }
+ }
- public override bool IsInvalid => handle == IntPtr.Zero;
+ public override bool IsInvalid => handle == IntPtr.Zero;
- protected override bool ReleaseHandle()
+ protected override bool ReleaseHandle()
+ {
+ var ret = ImageUtil.Transform.Destroy(handle);
+ if (ret != ImageUtilError.None)
{
- var ret = Transform.Destroy(handle);
- if (ret != ImageUtilError.None)
- {
- Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
- return false;
- }
-
- return true;
+ Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
+ return false;
}
+
+ return true;
}
}
-
}
using System;
using System.Runtime.InteropServices;
+using Tizen;
using Tizen.Multimedia.Util;
internal static partial class Interop
[DllImport(Libraries.ImageUtil, EntryPoint = "image_util_extract_color_from_memory")]
internal static extern ImageUtilError ExtractColorFromMemory(byte[] buffer, int width, int height, out byte rgbR, out byte rgbG, out byte rgbB);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_get_image")]
+ internal static extern ImageUtilError GetImage(IntPtr handle, out int width, out int height,
+ out ImageColorSpace colorspace, out IntPtr data, out int size);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_destroy_image")]
+ internal static extern ImageUtilError Destroy(IntPtr handle);
}
}