2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Runtime.InteropServices;
20 using Tizen.Multimedia.Util;
22 internal static partial class Interop
24 internal static class Decode
26 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27 internal delegate void DecodeCompletedCallback(ImageUtilError error, IntPtr userData, int width, int height, ulong size);
29 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
30 public static extern ImageUtilError Create(out ImageDecoderHandle handle);
32 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
33 internal static extern ImageUtilError Destroy(IntPtr handle);
35 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
36 internal static extern ImageUtilError SetInputPath(ImageDecoderHandle handle, IntPtr path);
38 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
39 internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize);
41 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_output_buffer")]
42 internal static extern ImageUtilError SetOutputBuffer(ImageDecoderHandle handle, out IntPtr dstBuffer);
44 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
45 internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace);
47 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
48 internal static extern ImageUtilError SetJpegDownscale(ImageDecoderHandle handle, JpegDownscale downscale);
50 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run_async")]
51 internal static extern ImageUtilError DecodeRunAsync(ImageDecoderHandle handle, DecodeCompletedCallback callback,
52 IntPtr userData = default(IntPtr));
54 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run")]
55 internal static extern ImageUtilError DecodeRun(ImageDecoderHandle handle, out int width,
56 out int height, out ulong size);
59 internal class ImageDecoderHandle : SafeHandle
61 protected ImageDecoderHandle() : base(IntPtr.Zero, true)
65 public override bool IsInvalid => handle == IntPtr.Zero;
67 protected override bool ReleaseHandle()
69 var ret = Decode.Destroy(handle);
70 if (ret != ImageUtilError.None)
72 Log.Debug(GetType().FullName, $"Failed to release native {GetType()}");