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.
19 using NativeTransform = Interop.ImageUtil.Transform;
21 namespace Tizen.Multimedia.Util
26 /// <since_tizen> 4 </since_tizen>
27 public class CropTransform : ImageTransform
29 private Rectangle _region;
32 /// Initializes a new instance of the <see cref="CropTransform"/> class.
34 /// <param name="region">The crop region.</param>
35 /// <exception cref="ArgumentOutOfRangeException">
36 /// The X-position of <paramref name="region"/> is less than zero.<br/>
38 /// The Y-position of <paramref name="region"/> is less than zero.<br/>
40 /// The width of <paramref name="region"/> is less than or equal to zero.<br/>
42 /// The height of <paramref name="region"/> is less than or equal to zero.
44 /// <since_tizen> 4 </since_tizen>
45 public CropTransform(Rectangle region)
51 /// Gets or sets the crop region.
53 /// <exception cref="ArgumentOutOfRangeException">
54 /// The X-position of <paramref name="value"/> is less than zero.<br/>
56 /// The Y-position of <paramref name="value"/> is less than zero.<br/>
58 /// The width of <paramref name="value"/> is less than or equal to zero.<br/>
60 /// The height of <paramref name="value"/> is less than or equal to zero.
62 /// <since_tizen> 4 </since_tizen>
63 public Rectangle Region
65 get { return _region; }
71 throw new ArgumentOutOfRangeException(nameof(Region), value,
72 "X position of the region can't be less than zero.");
77 throw new ArgumentOutOfRangeException(nameof(Region), value,
78 "Y position of the region can't be less than zero.");
83 throw new ArgumentOutOfRangeException(nameof(Region), value,
84 "Width of the region can't be less than or equal zero.");
89 throw new ArgumentOutOfRangeException(nameof(Region), value,
90 "Height of the region can't be less than or equal to zero.");
97 internal override void Configure(TransformHandle handle)
99 NativeTransform.SetCropArea(handle, Region.Left, Region.Top, Region.Right, Region.Bottom);
102 internal override void ValidateFormat(VideoMediaFormat format)
104 if (format.Size.Width < Region.Right || format.Size.Height < Region.Bottom)
106 throw new InvalidOperationException(
107 $"Crop region is invalid; Source size({format.Size.ToString()}), Crop region({Region.ToString()}).");
111 internal override string GenerateNotSupportedErrorMessage(VideoMediaFormat format)
113 return $"'{format.MimeType}' is not supported by CropTransform.";