[ImageUtil] Replace deprecated decode pinvoke func. (#929)
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / Interop / Interop.ImageUtil.Decode.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using Tizen;
20 using Tizen.Multimedia.Util;
21
22 internal static partial class Interop
23 {
24     internal static partial class ImageUtil
25     {
26         internal static partial class Decode
27         {
28             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29             internal delegate void DecodeCompletedCallback(ImageUtilError error, IntPtr userData, int width, int height, ulong size);
30
31             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
32             public static extern ImageUtilError Create(out ImageDecoderHandle handle);
33
34             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
35             internal static extern ImageUtilError Destroy(IntPtr handle);
36
37             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
38             internal static extern ImageUtilError SetInputPath(ImageDecoderHandle handle, IntPtr path);
39
40             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
41             internal static extern ImageUtilError SetInputBuffer(ImageDecoderHandle handle, byte[] srcBuffer, ulong srcSize);
42
43             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
44             internal static extern ImageUtilError SetColorspace(ImageDecoderHandle handle, ImageColorSpace colorspace);
45
46             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
47             internal static extern ImageUtilError SetJpegDownscale(ImageDecoderHandle handle, JpegDownscale downscale);
48
49             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run2")]
50             internal static extern ImageUtilError DecodeRun(ImageDecoderHandle handle, out IntPtr imageHandle);
51         }
52     }
53
54     internal class ImageDecoderHandle : SafeHandle
55     {
56         protected ImageDecoderHandle() : base(IntPtr.Zero, true)
57         {
58         }
59
60         public override bool IsInvalid => handle == IntPtr.Zero;
61
62         protected override bool ReleaseHandle()
63         {
64             var ret = ImageUtil.Decode.Destroy(handle);
65             if (ret != ImageUtilError.None)
66             {
67                 Log.Debug(GetType().FullName, $"Failed to release native {GetType()}");
68                 return false;
69             }
70
71             return true;
72         }
73     }
74 }