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 partial class ImageUtil
26 internal static partial class Decode
28 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29 internal delegate void DecodeCompletedCallback(ImageUtilError error, IntPtr userData, int width, int height, ulong size);
31 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
32 public static extern ImageUtilError Create(out ImageDecoderHandle handle);
34 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
35 internal static extern ImageUtilError Destroy(IntPtr handle);
37 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
38 internal static extern ImageUtilError SetInputPath(ImageDecoderHandle handle, IntPtr path);
40 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
41 internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize);
43 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
44 internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace);
46 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
47 internal static extern ImageUtilError SetJpegDownscale(ImageDecoderHandle handle, JpegDownscale downscale);
49 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run2")]
50 internal static extern ImageUtilError DecodeRun(ImageDecoderHandle handle, out IntPtr imageHandle);
54 internal class ImageDecoderHandle : SafeHandle
56 protected ImageDecoderHandle() : base(IntPtr.Zero, true)
60 public override bool IsInvalid => handle == IntPtr.Zero;
62 protected override bool ReleaseHandle()
64 var ret = ImageUtil.Decode.Destroy(handle);
65 if (ret != ImageUtilError.None)
67 Log.Debug(GetType().FullName, $"Failed to release native {GetType()}");