--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ // Image Decoder
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_path")]
+ internal static extern ErrorCode SetInputPath(this ImageDecoderHandle /* image_util_decode_h */ handle, string path);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_input_buffer")]
+ internal static extern ErrorCode SetInputBuffer(this ImageDecoderHandle /* image_util_decode_h */ handle, byte[] srcBuffer, ulong srcSize);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_output_buffer")]
+ internal static extern ErrorCode SetOutputBuffer(this ImageDecoderHandle /* image_util_decode_h */ handle, out IntPtr dstBuffer);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_colorspace")]
+ internal static extern ErrorCode SetColorspace(this ImageDecoderHandle /* image_util_encode_h */ handle, ImageColorSpace /* image_util_colorspace_e */ colorspace);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_set_jpeg_downscale")]
+ internal static extern ErrorCode SetJpegDownscale(this ImageDecoderHandle /* image_util_encode_h */ handle, JpegDownscale /* image_util_scale_e */ downscale);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run")]
+ internal static extern ErrorCode DecodeRun(this ImageDecoderHandle /* image_util_decode_h */ handle, out int width, out int height, out ulong size);
+
+ internal class ImageDecoderHandle : SafeMultimediaHandle
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DecodeCompletedCallback(ErrorCode errorCode, IntPtr /* void */ userData, int width, int height, ulong size);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_run_async")]
+ internal static extern ErrorCode DecodeRunAsync(ImageDecoderHandle /* image_util_decode_h */ handle, DecodeCompletedCallback callback, IntPtr /* void */ userData);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_create")]
+ internal static extern ErrorCode Create(out IntPtr /* image_util_decode_h */ handle);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_decode_destroy")]
+ internal static extern ErrorCode Destroy(IntPtr /* image_util_decode_h */ handle);
+
+ internal ImageColorSpace Colorspace
+ {
+ set { NativeSet(this.SetColorspace, value); }
+ }
+
+ internal JpegDownscale JpegDownscale
+ {
+ set { NativeSet(this.SetJpegDownscale, value); }
+ }
+
+ internal ImageDecoderHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease)
+ {
+ }
+
+ internal ImageDecoderHandle() : this(CreateNativeHandle(), true)
+ {
+ }
+
+ internal static IntPtr CreateNativeHandle()
+ {
+ IntPtr handle;
+ Create(out handle).ThrowIfFailed("Failed to create native handle");
+ return handle;
+ }
+
+ internal override ErrorCode DisposeNativeHandle()
+ {
+ return Destroy(handle);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ // Image Encoder
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_resolution")]
+ internal static extern ErrorCode SetResolution(this ImageEncoderHandle /* image_util_encode_h */ handle, uint width, uint height);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_colorspace")]
+ internal static extern ErrorCode SetColorspace(this ImageEncoderHandle /* image_util_encode_h */ handle, ImageColorSpace /* image_util_colorspace_e */ colorspace);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_quality")]
+ internal static extern ErrorCode SetQuality(this ImageEncoderHandle /* image_util_encode_h */ handle, int quality);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_png_compression")]
+ internal static extern ErrorCode SetPngCompression(this ImageEncoderHandle /* image_util_encode_h */ handle, PngCompression /* image_util_png_compression_e */ compression);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_gif_frame_delay_time")]
+ internal static extern ErrorCode SetGifFrameDelayTime(this ImageEncoderHandle /* image_util_encode_h */ handle, ulong delayTime);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_output_path")]
+ internal static extern ErrorCode SetOutputPath(this ImageEncoderHandle /* image_util_encode_h */ handle, string path);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_input_buffer")]
+ internal static extern ErrorCode SetInputBuffer(this ImageEncoderHandle /* image_util_encode_h */ handle, byte[] srcBuffer);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_output_buffer")]
+ internal static extern ErrorCode SetOutputBuffer(this ImageEncoderHandle /* image_util_encode_h */ handle, out IntPtr dstBuffer);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run")]
+ internal static extern ErrorCode EncodeRun(this ImageEncoderHandle /* image_util_encode_h */ handle, out ulong size);
+
+ internal class ImageEncoderHandle : SafeMultimediaHandle
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void EncodeCompletedCallback(ErrorCode errorCode, IntPtr /* void */ userData, ulong size);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run_async")]
+ internal static extern ErrorCode EncodeRunAsync(ImageEncoderHandle /* image_util_encode_h */ handle, EncodeCompletedCallback callback, IntPtr /* void */ userData);
+
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_create")]
+ internal static extern ErrorCode Create(ImageType /* image_util_type_e */ type, out IntPtr /* image_util_encode_h */ handle);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_destroy")]
+ internal static extern ErrorCode Destroy(IntPtr /* image_util_encode_h */ handle);
+
+ internal ImageEncoderHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease)
+ {
+ }
+
+ internal ImageEncoderHandle(ImageType type) : this(CreateNativeHandle(type), true)
+ {
+ }
+
+ internal ImageColorSpace Colorspace
+ {
+ set { NativeSet(this.SetColorspace, value); }
+ }
+
+ internal int Quality
+ {
+ set { NativeSet(this.SetQuality, value); }
+ }
+
+ internal PngCompression PngCompression
+ {
+ set { NativeSet(this.SetPngCompression, value); }
+ }
+
+ internal ulong GifFrameDelay
+ {
+ set { NativeSet(this.SetGifFrameDelayTime, value); }
+ }
+
+ internal string OutputPath
+ {
+ set { NativeSet(this.SetOutputPath, value); }
+ }
+
+ internal byte[] InputBuffer
+ {
+ set { NativeSet(this.SetInputBuffer, value); }
+ }
+
+ internal static IntPtr CreateNativeHandle(ImageType type)
+ {
+ IntPtr handle;
+ Create(type, out handle).ThrowIfFailed("Failed to create native handle");
+ return handle;
+ }
+
+ internal override ErrorCode DisposeNativeHandle()
+ {
+ return Destroy(handle);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_hardware_acceleration")]
+ internal static extern ErrorCode SetHardwareAcceleration(this ImageTransformHandle /* transformation_h */ handle, bool mode);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_get_colorspace")]
+ internal static extern ErrorCode GetColorspace(this ImageTransformHandle /* transformation_h */ handle, out ImageColorSpace /* image_util_colorspace_e */ colorspace);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_colorspace")]
+ internal static extern ErrorCode SetColorspace(this ImageTransformHandle /* transformation_h */ handle, ImageColorSpace /* image_util_colorspace_e */ colorspace);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_get_rotation")]
+ internal static extern ErrorCode GetRotation(this ImageTransformHandle /* transformation_h */ handle, out ImageRotation /* image_util_rotation_e */ rotation);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_rotation")]
+ internal static extern ErrorCode SetRotation(this ImageTransformHandle /* transformation_h */ handle, ImageRotation /* image_util_rotation_e */ rotation);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_get_resolution")]
+ internal static extern ErrorCode GetResolution(this ImageTransformHandle /* transformation_h */ handle, out uint width, out uint height);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_resolution")]
+ internal static extern ErrorCode SetResolution(this ImageTransformHandle /* transformation_h */ handle, uint width, uint height);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_get_crop_area")]
+ internal static extern ErrorCode GetCropArea(this ImageTransformHandle /* transformation_h */ handle, out uint startX, out uint startY, out uint endX, out uint endY);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_set_crop_area")]
+ internal static extern ErrorCode SetCropArea(this ImageTransformHandle /* transformation_h */ handle, int startX, int startY, int endX, int endY);
+
+ internal class ImageTransformHandle : SafeMultimediaHandle
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void TransformCompletedCallback(IntPtr /* media_packet_h */ dst, ErrorCode errorCode, IntPtr /* void */ userData);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_run")]
+ internal static extern ErrorCode Transform(ImageTransformHandle /* transformation_h */ handle, IntPtr /* media_packet_h */ src, TransformCompletedCallback callback, IntPtr /* void */ userData);
+
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_create")]
+ internal static extern ErrorCode Create(out IntPtr /* transformation_h */ handle);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_transform_destroy")]
+ internal static extern ErrorCode Destroy(IntPtr /* transformation_h */ handle);
+
+ internal ImageTransformHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease)
+ {
+ }
+
+ internal ImageTransformHandle() : this(CreateNativeHandle(), true)
+ {
+ }
+
+ internal bool HardwareAccelerationEnabled
+ {
+ set { NativeSet(this.SetHardwareAcceleration, value); }
+ }
+
+ internal ImageColorSpace Colorspace
+ {
+ get { return NativeGet<ImageColorSpace>(this.GetColorspace); }
+ set { NativeSet(this.SetColorspace, value); }
+ }
+
+ internal ImageRotation Rotation
+ {
+ get { return NativeGet<ImageRotation>(this.GetRotation); }
+ set { NativeSet(this.SetRotation, value); }
+ }
+
+ internal static IntPtr CreateNativeHandle()
+ {
+ IntPtr handle;
+ Create(out handle).ThrowIfFailed("Failed to create native handle");
+ return handle;
+ }
+
+ internal override ErrorCode DisposeNativeHandle()
+ {
+ return Destroy(handle);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal enum ImageColorSpace
+ {
+ Yv12, // IMAGE_UTIL_COLORSPACE_YV12
+ Yuv422, // IMAGE_UTIL_COLORSPACE_YUV422
+ I420, // IMAGE_UTIL_COLORSPACE_I420
+ Nv12, // IMAGE_UTIL_COLORSPACE_NV12
+ Uyvy, // IMAGE_UTIL_COLORSPACE_UYVY
+ Yuyv, // IMAGE_UTIL_COLORSPACE_YUYV
+ Rgb565, // IMAGE_UTIL_COLORSPACE_RGB565
+ Rgb888, // IMAGE_UTIL_COLORSPACE_RGB888
+ Argb8888, // IMAGE_UTIL_COLORSPACE_ARGB8888
+ Bgra8888, // IMAGE_UTIL_COLORSPACE_BGRA8888
+ Rgba8888, // IMAGE_UTIL_COLORSPACE_RGBA8888
+ Bgrx8888, // IMAGE_UTIL_COLORSPACE_BGRX8888
+ Nv21, // IMAGE_UTIL_COLORSPACE_NV21
+ Nv16, // IMAGE_UTIL_COLORSPACE_NV16
+ Nv61, // IMAGE_UTIL_COLORSPACE_NV61
+ }
+
+ internal enum ImageRotation
+ {
+ None, // IMAGE_UTIL_ROTATION_NONE
+ Rotate90, // IMAGE_UTIL_ROTATION_90
+ Rotate180, // IMAGE_UTIL_ROTATION_180
+ Rotate270, // IMAGE_UTIL_ROTATION_270
+ FlipHorizontal, // IMAGE_UTIL_ROTATION_FLIP_HORZ
+ FlipVertical, // IMAGE_UTIL_ROTATION_FLIP_VERT
+ }
+
+ internal enum ImageType
+ {
+ Jpeg, // IMAGE_UTIL_JPEG
+ Png, // IMAGE_UTIL_PNG
+ Gif, // IMAGE_UTIL_GIF
+ Bmp, // IMAGE_UTIL_BMP
+ }
+
+ internal enum JpegDownscale
+ {
+ NoDownscale, // IMAGE_UTIL_DOWNSCALE_1_1
+ OneHalf, // IMAGE_UTIL_DOWNSCALE_1_2
+ OneFourth, // IMAGE_UTIL_DOWNSCALE_1_4
+ OneEighth, // IMAGE_UTIL_DOWNSCALE_1_8
+ }
+
+ internal enum PngCompression
+ {
+ NoCompression, // IMAGE_UTIL_PNG_COMPRESSION_0
+ Level1, // IMAGE_UTIL_PNG_COMPRESSION_1
+ Level2, // IMAGE_UTIL_PNG_COMPRESSION_2
+ Level3, // IMAGE_UTIL_PNG_COMPRESSION_3
+ Level4, // IMAGE_UTIL_PNG_COMPRESSION_4
+ Level5, // IMAGE_UTIL_PNG_COMPRESSION_5
+ Level6, // IMAGE_UTIL_PNG_COMPRESSION_6
+ Level7, // IMAGE_UTIL_PNG_COMPRESSION_7
+ Level8, // IMAGE_UTIL_PNG_COMPRESSION_8
+ Level9, // IMAGE_UTIL_PNG_COMPRESSION_9
+ }
+
+ internal class ImageUtil
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool SupportedColorspaceCallback(ImageColorSpace /* image_util_colorspace_e */ colorspace, IntPtr /* void */ userData);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_foreach_supported_colorspace")]
+ internal static extern ErrorCode ForeachSupportedColorspace(ImageType /* image_util_type_e */ type, SupportedColorspaceCallback callback, IntPtr /* void */ userData);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_calculate_buffer_size")]
+ internal static extern ErrorCode CalculateBufferSize(int width, int height, ImageColorSpace /* image_util_colorspace_e */ colorspace, out uint size);
+
+ [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_extract_color_from_memory")]
+ internal static extern ErrorCode ExtractColorFromMemory(byte[] buffer, int width, int height, out byte rgbR, out byte rgbG, out byte rgbB);
+
+ internal static void ForeachSupportedColorspace(ImageType type, Action<ImageColorSpace> action)
+ {
+ SupportedColorspaceCallback callback = (codec, userData) =>
+ {
+ action(codec);
+ return true;
+ };
+
+ ForeachSupportedColorspace(type, callback, IntPtr.Zero).WarnIfFailed("Failed to get supported color-space list from native handle");
+ }
+
+ internal static uint CalculateBufferSize(int width, int height, ImageColorSpace colorSpace)
+ {
+ uint size;
+ CalculateBufferSize(width, height, colorSpace, out size).ThrowIfFailed("Failed to calculate buffer size");
+ return size;
+ }
+
+ internal static ElmSharp.Color ExtractColorFromMemory(byte[] buffer, int width, int height)
+ {
+ byte r, g, b;
+ ExtractColorFromMemory(buffer, width, height, out r, out g, out b);
+ return new ElmSharp.Color(r, g, b);
+ }
+
+ internal static byte[] NativeToByteArray(IntPtr nativeBuffer, int size)
+ {
+ Debug.Assert(nativeBuffer != IntPtr.Zero);
+
+ byte[] managedArray = new byte[size];
+ Marshal.Copy(nativeBuffer, managedArray, 0, size);
+
+ Libc.Free(nativeBuffer);
+ return managedArray;
+ }
+ }
+}
public const string StreamRecorder = "libcapi-media-streamrecorder.so.0";
public const string Radio = "libcapi-media-radio.so.0";
public const string VideoUtil = "libcapi-media-video-util.so.0";
+ public const string ImageUtil = "libcapi-media-image-util.so.0";
public const string ThumbnailExtractor = "libcapi-media-thumbnail-util.so";
public const string WavPlayer = "libcapi-media-wav-player.so.0";
public const string TonePlayer = "libcapi-media-tone-player.so.0";
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image color space
+ /// </summary>
+ public enum ImageColorSpace
+ {
+ /// <summary>
+ /// YV12 - YCrCb planar format
+ /// </summary>
+ Yv12 = Interop.ImageColorSpace.Yv12,
+ /// <summary>
+ /// UYVY - packed
+ /// </summary>
+ Uyvy = Interop.ImageColorSpace.Uyvy,
+ /// <summary>
+ /// YUYV - packed
+ /// </summary>
+ Yuyv = Interop.ImageColorSpace.Yuyv,
+ /// <summary>
+ /// YUV422 - planar
+ /// </summary>
+ Yuv422 = Interop.ImageColorSpace.Yuv422,
+ /// <summary>
+ /// YUV420 - planar
+ /// </summary>
+ I420 = Interop.ImageColorSpace.I420,
+ /// <summary>
+ /// RGB565, high-byte is Blue
+ /// </summary>
+ Rgb565 = Interop.ImageColorSpace.Rgb565,
+ /// <summary>
+ /// RGB888, high-byte is Blue
+ /// </summary>
+ Rgb888 = Interop.ImageColorSpace.Rgb888,
+ /// <summary>
+ /// ARGB8888, high-byte is Blue
+ /// </summary>
+ Argb8888 = Interop.ImageColorSpace.Argb8888,
+ /// <summary>
+ /// BGRA8888, high-byte is Alpha
+ /// </summary>
+ Bgra8888 = Interop.ImageColorSpace.Bgra8888,
+ /// <summary>
+ /// RGBA8888, high-byte is Alpha
+ /// </summary>
+ Rgba8888 = Interop.ImageColorSpace.Rgba8888,
+ /// <summary>
+ /// BGRX8888, high-byte is X
+ /// </summary>
+ Bgrx8888 = Interop.ImageColorSpace.Bgrx8888,
+ /// <summary>
+ /// NV12- planar
+ /// </summary>
+ Nv12 = Interop.ImageColorSpace.Nv12,
+ /// <summary>
+ /// NV16- planar
+ /// </summary>
+ Nv16 = Interop.ImageColorSpace.Nv16,
+ /// <summary>
+ /// NV21- planar
+ /// </summary>
+ Nv21 = Interop.ImageColorSpace.Nv21,
+ /// <summary>
+ /// NV61- planar
+ /// </summary>
+ Nv61 = Interop.ImageColorSpace.Nv61,
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Diagnostics;
+using Tizen.Common;
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image data class used with ImageDecoder
+ /// </summary>
+ public class ImageData
+ {
+ private Lazy<Color> _color;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="buffer">Image buffer</param>
+ /// <param name="width">Width</param>
+ /// <param name="height">Height</param>
+ /// <param name="size">Buffer size</param>
+ public ImageData(byte[] buffer, int width, int height)
+ {
+ Buffer = buffer ?? throw new ArgumentNullException("buffer");
+ Width = width;
+ Height = height;
+
+ _color = new Lazy<Color>(() => GetColor());
+ }
+
+ internal ImageData(IntPtr nativeBuffer, int width, int height, int size)
+ {
+ Buffer = Interop.ImageUtil.NativeToByteArray(nativeBuffer, size);
+ Width = width;
+ Height = height;
+ }
+
+ /// <summary>
+ /// Image buffer
+ /// </summary>
+ public byte[] Buffer { get; }
+
+ /// <summary>
+ /// Image width
+ /// </summary>
+ public int Width { get; }
+
+ /// <summary>
+ /// Image height
+ /// </summary>
+ public int Height { get; }
+
+ /// <summary>
+ /// Image color
+ /// </summary>
+ public Color color
+ {
+ get
+ {
+ return _color.Value;
+ }
+ }
+
+ private Color GetColor()
+ {
+ byte r, g, b, a = 0;
+ Interop.ImageUtil.ExtractColorFromMemory(Buffer, Width, Height, out r, out g, out b)
+ .ThrowIfFailed("Failed to extract color from buffer");
+ return new Color(r, g, b, a);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Threading.Tasks;
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image decoder utility
+ /// </summary>
+ public class ImageDecoder : IDisposable
+ {
+ public const ImageColorSpace DefaultColorspace = ImageColorSpace.Rgba8888;
+ public const JpegDownscale DefaultJpegDownscale = JpegDownscale.NoDownscale;
+
+ internal Interop.ImageDecoderHandle _handle;
+ private ImageColorSpace _colorspace = DefaultColorspace;
+ private JpegDownscale _jpegDownscale = DefaultJpegDownscale;
+
+ internal ImageDecoder()
+ {
+ _handle = new Interop.ImageDecoderHandle();
+ }
+
+ /// <summary>
+ /// Color-space format to decode into, default is <ref>ImageColorspace.Rgba8888</ref>
+ /// </summary>
+ public ImageColorSpace ColorSpace
+ {
+ get { return _colorspace; }
+ set
+ {
+ ValidateObjectNotDisposed();
+ _handle.Colorspace = (Interop.ImageColorSpace)value;
+ _colorspace = value;
+ }
+ }
+
+ /// <summary>
+ /// Downscale value at which JPEG image should be decoded.
+ /// </summary>
+ public JpegDownscale Downscale
+ {
+ get { return _jpegDownscale; }
+ set { _jpegDownscale = value; }
+ }
+
+ /// <summary>
+ /// Decode image
+ /// </summary>
+ /// <param name="inputFilePath">Input file path from which to decode</param>
+ /// <returns>Decoded image data</returns>
+ public Task<ImageData> DecodeAsync(string inputFilePath)
+ {
+ ValidateObjectNotDisposed();
+ if (inputFilePath == null) throw new ArgumentNullException("inputFilePath");
+
+ _handle.SetInputPath(inputFilePath).ThrowIfFailed("Failed to set input file path for decoding");
+ return DecodeAsync();
+ }
+
+ /// <summary>
+ /// Decode image
+ /// </summary>
+ /// <param name="inputBuffer">Input buffer from which to decode</param>
+ /// <returns>Decoded image data</returns>
+ public Task<ImageData> DecodeAsync(byte[] inputBuffer)
+ {
+ ValidateObjectNotDisposed();
+ if (inputBuffer == null) throw new ArgumentNullException("inputBuffer");
+
+ _handle.SetInputBuffer(inputBuffer, (ulong)inputBuffer.Length).ThrowIfFailed("Failed to set input buffer for decoding");
+ return DecodeAsync();
+ }
+
+ internal virtual void Initialize()
+ {
+ if (_colorspace != DefaultColorspace)
+ {
+ _handle.Colorspace = (Interop.ImageColorSpace)_colorspace;
+ }
+
+ if (_jpegDownscale != DefaultJpegDownscale)
+ {
+ _handle.SetJpegDownscale((Interop.JpegDownscale)_jpegDownscale).ThrowIfFailed("Failed to set JPEG Downscale for decoding");
+ }
+ }
+
+ internal Task<ImageData> DecodeAsync()
+ {
+ IntPtr nativeBuffer = IntPtr.Zero;
+ _handle.SetOutputBuffer(out nativeBuffer).ThrowIfFailed("Failed to set output buffer for decoding");
+
+ Initialize();
+
+ TaskCompletionSource<ImageData> tcs = new TaskCompletionSource<ImageData>();
+ Interop.ImageDecoderHandle.DecodeCompletedCallback callback = (errorCode, userData, width, height, size) =>
+ {
+ if (errorCode.IsSuccess())
+ {
+ var decodedImage = new ImageData(nativeBuffer, width, height, (int)size);
+ tcs.TrySetResult(decodedImage);
+ }
+ else
+ {
+ tcs.TrySetException(errorCode.GetException("Image decoding failed."));
+ }
+ };
+
+ Interop.ImageDecoderHandle.DecodeRunAsync(_handle, callback, IntPtr.Zero).ThrowIfFailed("Failed to decode given image");
+ return Interop.PinnedTask(tcs);
+ }
+
+ private void ValidateObjectNotDisposed()
+ {
+ if (_disposedValue)
+ {
+ throw new ObjectDisposedException(GetType().Name);
+ }
+ }
+
+ #region IDisposable Support
+ private bool _disposedValue = false; // To detect redundant calls
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ _handle.Dispose();
+ _disposedValue = true;
+ }
+ }
+
+ ~ImageDecoder()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ #endregion
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Threading.Tasks;
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image Encoder Utility
+ /// </summary>
+ public class ImageEncoder
+ {
+ public const ImageColorSpace DefaultColorspace = ImageColorSpace.Rgba8888;
+
+ private ImageColorSpace _colorspace = DefaultColorspace;
+ private Size _resolution;
+ private ImageFormat _type;
+
+ internal ImageEncoder(ImageFormat type)
+ {
+ _type = type;
+ }
+
+ /// <summary>
+ /// Color-space format to encode into, default is <ref>ImageColorspace.Rgba8888</ref>
+ /// </summary>
+ public ImageColorSpace ColorSpace
+ {
+ get { return _colorspace; }
+ set { _colorspace = value; }
+ }
+
+ /// <summary>
+ /// Resolution of the encoded image
+ /// </summary>
+ public Size Resolution
+ {
+ get { return _resolution; }
+ set { _resolution = value; }
+ }
+
+ /// <summary>
+ /// Encode image
+ /// </summary>
+ /// <param name="inputBuffer">Input buffer from which to encode</param>
+ /// <returns>Encoded image buffer</returns>
+ public Task<byte[]> EncodeAsync(byte[] inputBuffer)
+ {
+ using (var handle = new Interop.ImageEncoderHandle((Interop.ImageType)_type))
+ {
+ handle.SetInputBuffer(inputBuffer).ThrowIfFailed("Failed to set input buffer for encoding");
+
+ IntPtr nativeBuffer = IntPtr.Zero;
+ handle.SetOutputBuffer(out nativeBuffer).ThrowIfFailed("Failed to set output buffer for encoding");
+
+ Initialize(handle);
+
+ TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
+ Interop.ImageEncoderHandle.EncodeCompletedCallback callback = (errorCode, userData, size) =>
+ {
+ if (errorCode.IsSuccess())
+ {
+ tcs.TrySetResult(Interop.ImageUtil.NativeToByteArray(nativeBuffer, (int)size));
+ }
+ else
+ {
+ tcs.TrySetException(errorCode.GetException("Image encoding failed."));
+ }
+ };
+
+ Interop.ImageEncoderHandle.EncodeRunAsync(handle, callback, IntPtr.Zero).ThrowIfFailed("Failed to encode given image");
+ return Interop.PinnedTask(tcs);
+ }
+ }
+
+ /// <summary>
+ /// Encode image
+ /// </summary>
+ /// <param name="inputBuffer">Input buffer from which to encode</param>
+ /// <param name="outputFilePath">Output path to which to encoded buffer will be written to</param>
+ /// <returns>true if encoding is successful</returns>
+ public Task EncodeAsync(byte[] inputBuffer, string outputFilePath)
+ {
+ using (var handle = new Interop.ImageEncoderHandle((Interop.ImageType)_type))
+ {
+ handle.SetInputBuffer(inputBuffer).ThrowIfFailed("Failed to set input buffer for encoding");
+ handle.SetOutputPath(outputFilePath).ThrowIfFailed("Failed to set output file path for encoding");
+
+ Initialize(handle);
+
+ TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+ Interop.ImageEncoderHandle.EncodeCompletedCallback callback = (errorCode, userData, size) =>
+ {
+ if (errorCode.IsSuccess())
+ {
+ tcs.TrySetResult(true);
+ }
+ else
+ {
+ tcs.TrySetException(errorCode.GetException("Image encoding failed."));
+ }
+ };
+
+ Interop.ImageEncoderHandle.EncodeRunAsync(handle, callback, IntPtr.Zero).ThrowIfFailed("Failed to encode given image");
+ return Interop.PinnedTask(tcs);
+ }
+ }
+
+ internal virtual void Initialize(Interop.ImageEncoderHandle handle)
+ {
+ if (_colorspace != DefaultColorspace)
+ {
+ handle.Colorspace = (Interop.ImageColorSpace)_colorspace;
+ }
+
+ if (_resolution.Width != 0 && _resolution.Height != 0)
+ {
+ handle.SetResolution((uint)_resolution.Width, (uint)_resolution.Height);
+ }
+ }
+
+ internal static void ValidateInputRange<T>(T actualValue, T min, T max, string paramName) where T : IComparable<T>
+ {
+ if (min.CompareTo(actualValue) == 1 || max.CompareTo(actualValue) == -1)
+ {
+ throw new ArgumentOutOfRangeException(paramName, actualValue, $"Valid Range [{min} - {max}]");
+ }
+ }
+
+ internal static void ValidateInputRange<T>(T actualValue, Func<bool> verifier, string paramName, string message)
+ {
+ if (verifier() == false)
+ {
+ throw new ArgumentOutOfRangeException(paramName, actualValue, message);
+ }
+ }
+ }
+
+ /// <summary>
+ /// BMP image encoder
+ /// </summary>
+ public class BmpEncoder : ImageEncoder
+ {
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public BmpEncoder() : base(ImageFormat.Bmp)
+ {
+ }
+ }
+
+ /// <summary>
+ /// JPEG image encoder
+ /// </summary>
+ public class JpegEncoder : ImageEncoder
+ {
+ public const int DefaultQuality = 75;
+ private int _quality = DefaultQuality;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public JpegEncoder() : base(ImageFormat.Jpeg)
+ {
+ }
+
+ /// <summary>
+ /// Encoding quality from 1~100, default is 75
+ /// </summary>
+ public int Quality
+ {
+ get { return _quality; }
+ set
+ {
+ ValidateInputRange<int>(value, 1, 100, "Quality");
+ _quality = value;
+ }
+ }
+
+ internal override void Initialize(Interop.ImageEncoderHandle handle)
+ {
+ if (_quality != DefaultQuality)
+ {
+ base.Initialize(handle);
+ handle.Quality = _quality;
+ }
+ }
+ }
+
+ /// <summary>
+ /// PNG image encoder
+ /// </summary>
+ public class PngEncoder : ImageEncoder
+ {
+ public const PngCompression DefaultPngCompressionLevel = PngCompression.Level6;
+ private PngCompression _pngCompressionLevel = DefaultPngCompressionLevel;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public PngEncoder() : base(ImageFormat.Png)
+ {
+ }
+
+ /// <summary>
+ /// Compression value of PNG image encoding
+ /// </summary>
+ public PngCompression CompressionLevel
+ {
+ get { return _pngCompressionLevel; }
+ set {_pngCompressionLevel = value; }
+ }
+
+ internal override void Initialize(Interop.ImageEncoderHandle handle)
+ {
+ if (_pngCompressionLevel != DefaultPngCompressionLevel)
+ {
+ base.Initialize(handle);
+ handle.PngCompression = (Interop.PngCompression)_pngCompressionLevel;
+ }
+ }
+ }
+
+ /// <summary>
+ /// GIF image encoder
+ /// </summary>
+ public class GifEncoder : ImageEncoder
+ {
+ public const int DefaultGifFrameDelay = 0;
+ private ulong _gifFrameDelay = DefaultGifFrameDelay;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ public GifEncoder() : base(ImageFormat.Gif)
+ {
+ }
+
+ /// <summary>
+ /// Time delay between each frame in the encoded image, in 0.01sec units
+ /// </summary>
+ public ulong FrameDelay
+ {
+ get { return _gifFrameDelay; }
+ set { _gifFrameDelay = value; }
+ }
+
+ internal override void Initialize(Interop.ImageEncoderHandle handle)
+ {
+ if (_gifFrameDelay != DefaultGifFrameDelay)
+ {
+ base.Initialize(handle);
+ handle.GifFrameDelay = _gifFrameDelay;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image Format
+ /// </summary>
+ public enum ImageFormat
+ {
+ /// <summary>
+ /// JPEG image
+ /// </summary>
+ Jpeg = Interop.ImageType.Jpeg,
+ /// <summary>
+ /// PNG image
+ /// </summary>
+ Png = Interop.ImageType.Png,
+ /// <summary>
+ /// GIF image
+ /// </summary>
+ Gif = Interop.ImageType.Gif,
+ /// <summary>
+ /// BMP image
+ /// </summary>
+ Bmp = Interop.ImageType.Bmp,
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image rotation options
+ /// </summary>
+ public enum ImageRotation
+ {
+ /// <summary>
+ /// No rotation
+ /// </summary>
+ None = Interop.ImageRotation.None,
+ /// <summary>
+ /// Rotate 90 degree
+ /// </summary>
+ Rotate90 = Interop.ImageRotation.Rotate90,
+ /// <summary>
+ /// Rotate 180 degree
+ /// </summary>
+ Rotate180 = Interop.ImageRotation.Rotate180,
+ /// <summary>
+ /// Rotate 270 degree
+ /// </summary>
+ Rotate270 = Interop.ImageRotation.Rotate270,
+ /// <summary>
+ /// Flip horizontal
+ /// </summary>
+ FlipHorizontal = Interop.ImageRotation.FlipHorizontal,
+ /// <summary>
+ /// Flip vertical
+ /// </summary>
+ FlipVertical = Interop.ImageRotation.FlipVertical,
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Threading.Tasks;
+
+namespace Tizen.Multimedia.Utility
+{
+ public static class ImageTransformer
+ {
+ public static Task<MediaPacket> ConvertColorspaceAsync(this MediaPacket packet, ImageColorSpace colorspace, bool useHardwareAcceleration)
+ {
+ using (var handle = new Interop.ImageTransformHandle())
+ {
+ handle.Colorspace = (Interop.ImageColorSpace)colorspace;
+ return TransformAsync(handle, packet, useHardwareAcceleration);
+ }
+ }
+
+ public static Task<MediaPacket> ConvertColorspaceAsync(this MediaPacket packet, ImageColorSpace colorspace)
+ {
+ return ConvertColorspaceAsync(packet, colorspace, false);
+ }
+
+ public static Task<MediaPacket> ResizeAsync(this MediaPacket packet, Size resolution, bool useHardwareAcceleration)
+ {
+ using (var handle = new Interop.ImageTransformHandle())
+ {
+ handle.SetResolution((uint)resolution.Width, (uint)resolution.Height)
+ .ThrowIfFailed("Failed to set image resolution for transformation");
+ return TransformAsync(handle, packet, useHardwareAcceleration);
+ }
+ }
+
+ public static Task<MediaPacket> ResizeAsync(this MediaPacket packet, Size resolution)
+ {
+ return ResizeAsync(packet, resolution, false);
+ }
+
+ public static Task<MediaPacket> RotateAsync(this MediaPacket packet, ImageRotation rotation, bool useHardwareAcceleration)
+ {
+ using (var handle = new Interop.ImageTransformHandle())
+ {
+ handle.Rotation = (Interop.ImageRotation)rotation;
+ return TransformAsync(handle, packet, useHardwareAcceleration);
+ }
+ }
+
+ public static Task<MediaPacket> RotateAsync(this MediaPacket packet, ImageRotation rotation)
+ {
+ return RotateAsync(packet, rotation, false);
+ }
+
+ public static Task<MediaPacket> CropAsync(this MediaPacket packet, Rectangle cropArea, bool useHardwareAcceleration)
+ {
+ using (var handle = new Interop.ImageTransformHandle())
+ {
+ handle.SetCropArea(cropArea.X, cropArea.Y, cropArea.X + cropArea.Width, cropArea.Y + cropArea.Height)
+ .ThrowIfFailed("Failed to set crop area for transformation");
+ return TransformAsync(handle, packet, useHardwareAcceleration);
+ }
+ }
+
+ public static Task<MediaPacket> CropAsync(this MediaPacket packet, Rectangle cropArea)
+ {
+ return CropAsync(packet, cropArea, false);
+ }
+
+ private static Task<MediaPacket> TransformAsync(Interop.ImageTransformHandle handle, MediaPacket packet, bool useHardwareAcceleration)
+ {
+ if (useHardwareAcceleration)
+ {
+ handle.HardwareAccelerationEnabled = true;
+ }
+
+ TaskCompletionSource<MediaPacket> tcs = new TaskCompletionSource<MediaPacket>();
+ Interop.ImageTransformHandle.TransformCompletedCallback callback = (nativehandle, errorCode, userData) =>
+ {
+ if (errorCode.IsSuccess())
+ {
+ tcs.TrySetResult(MediaPacket.From(nativehandle));
+ }
+ else
+ {
+ tcs.TrySetException(errorCode.GetException("Image transformation failed."));
+ }
+ };
+
+ Interop.ImageTransformHandle.Transform(handle, packet.GetHandle(), callback, IntPtr.Zero)
+ .ThrowIfFailed("Failed to transform given packet");
+ return Interop.PinnedTask(tcs);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System.Collections.Generic;
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// Image utility class
+ /// </summary>
+ public struct ImageUtility
+ {
+ /// <summary>
+ /// Supported color-space for image encoding/ decoding
+ /// </summary>
+ /// <param name="type">image type</param>
+ /// <returns>Supported color-space</returns>
+ public static IEnumerable<ImageColorSpace> GetSupportedColorspace(ImageFormat type)
+ {
+ var colorspaces = new List<ImageColorSpace>();
+ Interop.ImageUtil.ForeachSupportedColorspace((Interop.ImageType)type, (colorspace) => colorspaces.Add((ImageColorSpace)colorspace));
+ return colorspaces;
+ }
+
+ /// <summary>
+ /// Calculates the size of the image buffer for the specified resolution and color-space
+ /// </summary>
+ /// <param name="width">Image width</param>
+ /// <param name="height">Image height</param>
+ /// <param name="colorspace">Image color-space</param>
+ /// <returns>Buffer size</returns>
+ public static uint CalculateBufferSize(int width, int height, ImageColorSpace colorspace)
+ {
+ uint bufferSize;
+ Interop.ImageUtil.CalculateBufferSize(width, height, (Interop.ImageColorSpace)colorspace, out bufferSize)
+ .ThrowIfFailed("Failed to calculate buffer size for given parameter");
+ return bufferSize;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// JPEG Downscale options for decoding
+ /// </summary>
+ public enum JpegDownscale
+ {
+ /// <summary>
+ /// No downscale
+ /// </summary>
+ NoDownscale = Interop.JpegDownscale.NoDownscale,
+ /// <summary>
+ /// 1/2 downscale
+ /// </summary>
+ OneHalf = Interop.JpegDownscale.OneHalf,
+ /// <summary>
+ /// 1/4 downscale
+ /// </summary>
+ OneFourth = Interop.JpegDownscale.OneFourth,
+ /// <summary>
+ /// 1/8 downscale
+ /// </summary>
+ OneEighth = Interop.JpegDownscale.OneEighth,
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Multimedia.Utility
+{
+ /// <summary>
+ /// PNG Image Compression Level
+ /// </summary>
+ public enum PngCompression
+ {
+ /// <summary>
+ /// No Compression
+ /// </summary>
+ NoCompression = Interop.PngCompression.NoCompression,
+ /// <summary>
+ /// Compression Level 1. Best speed
+ /// </summary>
+ Level1 = Interop.PngCompression.Level1,
+ /// <summary>
+ /// Compression Level 2
+ /// </summary>
+ Level2 = Interop.PngCompression.Level2,
+ /// <summary>
+ /// Compression Level 3
+ /// </summary>
+ Level3 = Interop.PngCompression.Level3,
+ /// <summary>
+ /// Compression Level 4
+ /// </summary>
+ Level4 = Interop.PngCompression.Level4,
+ /// <summary>
+ /// Compression Level 5
+ /// </summary>
+ Level5 = Interop.PngCompression.Level5,
+ /// <summary>
+ /// Compression Level 6
+ /// </summary>
+ Level6 = Interop.PngCompression.Level6,
+ /// <summary>
+ /// Compression Level 7
+ /// </summary>
+ Level7 = Interop.PngCompression.Level7,
+ /// <summary>
+ /// Compression Level 8
+ /// </summary>
+ Level8 = Interop.PngCompression.Level8,
+ /// <summary>
+ /// Compression Level 9
+ /// </summary>
+ Level9 = Interop.PngCompression.Level9,
+ }
+}