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_resolution")]
42 internal static extern ImageUtilError SetResolution(ImageEncoderHandle handle, uint width, uint height);
44 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_colorspace")]
45 internal static extern ImageUtilError SetColorspace(ImageEncoderHandle handle, ImageColorSpace colorspace);
47 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_quality")]
48 internal static extern ImageUtilError SetQuality(ImageEncoderHandle handle, int quality);
50 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_png_compression")]
51 internal static extern ImageUtilError SetPngCompression(ImageEncoderHandle handle, PngCompression compression);
53 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_gif_frame_delay_time")]
54 internal static extern ImageUtilError SetGifFrameDelayTime(ImageEncoderHandle handle, ulong delayTime);
56 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_output_path")]
57 internal static extern ImageUtilError SetOutputPath(ImageEncoderHandle handle, string path);
59 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_input_buffer")]
60 internal static extern ImageUtilError SetInputBuffer(ImageEncoderHandle handle, byte[] srcBuffer);
62 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_output_buffer")]
63 internal static extern ImageUtilError SetOutputBuffer(ImageEncoderHandle handle, out IntPtr dstBuffer);
65 [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run")]
66 internal static extern ImageUtilError Run(ImageEncoderHandle handle, out ulong size);
69 internal class ImageEncoderHandle : SafeHandle
71 protected ImageEncoderHandle() : base(IntPtr.Zero, true)
75 public override bool IsInvalid => handle == IntPtr.Zero;
78 protected override bool ReleaseHandle()
80 var ret = Encode.Destroy(handle);
81 if (ret != ImageUtilError.None)
83 Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}");