/*
 * This is one of the header files of Dynamsoft Capture Vision SDK - Utility module.
 *
 * Copyright © Dynamsoft Corporation.  All rights reserved.
 */

#import <Foundation/Foundation.h>

@class DSImageData;
@class DSRect;
@class DSQuadrilateral;

typedef NS_ENUM(NSInteger, DSFilterType) {
    DSFilterTypeHighPass,
    DSFilterTypeSharpen,
    DSFilterTypeSmooth
} NS_SWIFT_NAME(FilterType);

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(ImageProcessor)
@interface DSImageProcessor : NSObject

/**
 * Crops an image.
 * @param [in] imageData The image data to be cropped.
 * @param [in] rect The rectangle to be cropped.
 * @param [in, out] error The error.
 *
 * @return Returns a DSImageData object representing the cropped image.
 */
- (nullable DSImageData *)cropImage:(DSImageData *)imageData
                               rect:(DSRect *)rect
                              error:(NSError *_Nullable *_Nullable)error
NS_SWIFT_NAME(cropImage(_:rect:));

/**
 * Crops an image.
 * @param [in] imageData The image data to be cropped.
 * @param [in] quad The quadrilateral to be cropped.
 * @param [in, out] error The error.
 *
 * @return Returns a DSImageData object representing the cropped image.
 */
- (nullable DSImageData *)cropImage:(DSImageData *)imageData
                               quad:(DSQuadrilateral *)quad
                              error:(NSError *_Nullable *_Nullable)error
NS_SWIFT_NAME(cropImage(_:quad:)) DEPRECATED_MSG_ATTRIBUTE("DEPRECATED.");

/**
 * Crops the image.
 *
 * @param [in] imageData The image data to be cropped.
 * @param [in] quad The quadrilateral to be cropped.
 * @param [in, out] error The error.
 *
 * @return Returns a DSImageData object representing the cropped image.
 */
- (nullable DSImageData *)cropAndDeskewImage:(DSImageData *)imageData
                                        quad:(DSQuadrilateral *)quad
                                       error:(NSError *_Nullable *_Nullable)error
NS_SWIFT_NAME(cropAndDeskewImage(_:quad:));

/**
 * Crops the image and output it with the specified width, height and padding.
 *
 * @param [in] imageData The image data to be cropped.
 * @param [in] quad The quadrilateral to be cropped.
 * @param [in] dstWidth The width of the output image.
 * @param [in] dstHeight The height of the output image.
 * @param [in] padding Extra padding (in pixels) applied to expand the boundaries of the extracted region.
 * @param [in, out] error The error.
 *
 * @return Returns a DSImageData object representing the cropped image.
 */
- (nullable DSImageData *)cropAndDeskewImage:(DSImageData *)imageData
                                        quad:(DSQuadrilateral *)quad
                                    dstWidth:(NSInteger)dstWidth
                                   dstHeight:(NSInteger)dstHeight
                                     padding:(NSInteger)padding
                                       error:(NSError *_Nullable *_Nullable)error
NS_SWIFT_NAME(cropAndDeskewImage(_:quad:dstWidth:dstHeight:padding:));

/**
 * Adjusts the brightness of the image.
 * @param [In] imageData Input colour image.
 * @param [In] brightness Brightness adjustment value (positive values increase brightness, negative values decrease brightness). The value range is [-100, 100].
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)adjust:(DSImageData *)imageData
             brightness:(NSInteger)brightness
NS_SWIFT_NAME(adjust(image:brightness:));

/**
 * Adjusts the contrast of the image.
 * @param [In] imageData Input colour image.
 * @param [In] contrast adjustment value (positive values enhance, negative values reduce contrast). The value range is [-100, 100].
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)adjust:(DSImageData *)imageData
               contrast:(NSInteger)contrast
NS_SWIFT_NAME(adjust(image:contrast:));

/**
 * Applies a specified image filter to an input image and returns the filtered result.
 * @param [In] imageData Input image.
 * @param [In] filterType Specifies the type of filter to apply to the input image, of type DSFilterType.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)filterImage:(DSImageData *)imageData
                  filterType:(DSFilterType)filterType
NS_SWIFT_NAME(filterImage(_:type:));

/**
 * Converts colour image to grayscale.
 * @param imageData Input colour image.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToGray:(DSImageData *)imageData;

/**
 * Converts colour image to grayscale.
 * @param imageData Input colour image.
 * @param [In] r weight for red channel.
 * @param [In] g weight for green channel.
 * @param [In] b weight for blue channel.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToGray:(DSImageData *)imageData
                             r:(CGFloat)r
                             g:(CGFloat)g
                             b:(CGFloat)b
NS_SWIFT_NAME(convertToGray(_:r:g:b:));

/**
 * Converts the grayscale image to binary image using a global threshold.
 * @param imageData Input image in grayscale.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToBinaryGlobal:(DSImageData *)imageData;

/**
 * Converts the grayscale image to binary image using a global threshold.
 * @param [In] imageData Input image in grayscale.
 * @param [In] threshold Global threshold for binarization(default is -1, automatic calculate the threshold).
 * @param [In] invert If true, invert the binary image (black becomes white and white becomes black).
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToBinaryGlobal:(DSImageData *)imageData
                             threshold:(NSInteger)threshold
                                invert:(BOOL)invert
NS_SWIFT_NAME(convertToBinaryGlobal(_:threshold:invert:));

/**
 * Converts the grayscale image to binary image using local (adaptive) binarization.
 * @param imageData Input image in grayscale.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToBinaryLocal:(DSImageData *)imageData;

/**
 * Converts the grayscale image to binary image using local (adaptive) binarization.
 * @param [In] imageData Input image in grayscale.
 * @param [In] blockSize Size of the block for local binarization(default is 0).
 * @param [In] compensation Adjustment value to modify the threshold (default is 0).
 * @param [In] invert If true, invert the binary image (black becomes white and white becomes black).
 *
 * @return Returns a DSImageData object representing the image.
 */
- (DSImageData *)convertToBinaryLocal:(DSImageData *)imageData
                            blockSize:(NSInteger)blockSize
                         compensation:(NSInteger)compensation
                               invert:(BOOL)invert
NS_SWIFT_NAME(convertToBinaryLocal(_:blockSize:compensation:invert:));

@end

NS_ASSUME_NONNULL_END
