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 class Encode
28 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29 internal delegate void EncodeCompletedCallback(ImageUtilError ImageUtilError, IntPtr userData, ulong size);
31 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run_async")]
32 internal static extern ImageUtilError EncodeRunAsync(ImageEncoderHandle handle,
33 EncodeCompletedCallback callback, IntPtr userData = default(IntPtr));
35 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_create")]
36 internal static extern ImageUtilError Create(ImageFormat type, out ImageEncoderHandle handle);
38 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_destroy")]
39 internal static extern ImageUtilError Destroy(IntPtr handle);
41 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_quality")]
42 internal static extern ImageUtilError SetQuality(ImageEncoderHandle handle, int quality);
44 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_png_compression")]
45 internal static extern ImageUtilError SetPngCompression(ImageEncoderHandle handle, PngCompression compression);
47 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run_to_buffer")]
48 internal static extern ImageUtilError RunToBuffer(ImageEncoderHandle handle, IntPtr imageUtilHandle, out IntPtr buffer, out int size);
50 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_lossless")]
51 internal static extern ImageUtilError SetLossless(ImageEncoderHandle handle, bool lossless);
53 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_create")]
54 internal static extern ImageUtilError AnimationCreate(AnimationType type, out IntPtr animHandle);
56 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_set_loop_count")]
57 internal static extern ImageUtilError AnimationSetLoopCount(IntPtr animHandle, uint count);
59 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_set_background_color")]
60 internal static extern ImageUtilError AnimationSetBackgroundColor(IntPtr animHandle, byte r, byte g, byte b, byte a);
62 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_set_lossless")]
63 internal static extern ImageUtilError AnimationSetLossless(IntPtr animHandle, bool isLossless);
65 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_add_frame")]
66 internal static extern ImageUtilError AnimationAddFrame(IntPtr animHandle, IntPtr utilHandle, uint delayTime);
68 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_save_to_file")]
69 internal static extern ImageUtilError AnimationSaveToFile(IntPtr animHandle, string path);
71 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_save_to_buffer")]
72 internal static extern ImageUtilError AnimationSaveToBuffer(IntPtr animHandle, out IntPtr dstBuffer, out ulong size);
74 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_anim_encode_destroy")]
75 internal static extern ImageUtilError AnimationDestroy(IntPtr animHandle);
79 internal class ImageEncoderHandle : SafeHandle
81 protected ImageEncoderHandle() : base(IntPtr.Zero, true)
85 public override bool IsInvalid => handle == IntPtr.Zero;
88 protected override bool ReleaseHandle()
90 var ret = ImageUtil.Encode.Destroy(handle);
91 if (ret != ImageUtilError.None)
93 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");
101 internal class AgifImageEncoderHandle : SafeHandle
103 protected AgifImageEncoderHandle() : base(IntPtr.Zero, true)
107 public override bool IsInvalid => handle == IntPtr.Zero;
110 protected override bool ReleaseHandle()
112 var ret = ImageUtil.Encode.Destroy(handle);
113 if (ret != ImageUtilError.None)
115 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");