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

#import <Foundation/Foundation.h>
#import <DynamsoftCaptureVisionBundle/DSImageFileFormat.h>

@class DSImageData;

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(ImageIO)
@interface DSImageIO : NSObject

/**
 * Save an ImageData object as an image file.
 *
 * @param [in] imageData The ImageData object to save to an image file.
 * @param [in] path The targeting file path with the file name and extension name.
 * @param [in] overWrite A flag indicating whether to overwrite the file if it already exists. Defaults to true.
 * @param [in,out] error A NSError pointer. An error occurs when the file path is unavailable.
 *
 * @return A BOOL value that indicates whether the file is saved successfully.
 */
- (BOOL)saveToFile:(DSImageData *)imageData
              path:(NSString *)path
         overWrite:(BOOL)overWrite
             error:(NSError * _Nullable * _Nullable)error
NS_SWIFT_NAME(saveToFile(_:path:overWrite:));

/**
 * Reads an image from a file.
 * @param [in] filePath The path of the image file.
 * @param [in,out] error An NSError pointer.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (nullable DSImageData *)readFromFile:(NSString *)filePath
                                 error:(NSError * _Nullable * _Nullable)error;

/**
 * Saves an image to a file in memory.
 * @param [in] imageData The image data to be saved.
 * @param [in] imageFormat The image file format to be saved
 * @param [in,out] error An NSError pointer.
 *
 * @return Returns 0 if succeeds, nonzero otherwise.
 */
- (nullable NSData *)saveToMemory:(DSImageData *)imageData
                      imageFormat:(DSImageFileFormat)imageFormat
                            error:(NSError *_Nullable *_Nullable)error
NS_SWIFT_NAME(saveToMemory(_:imageFormat:));

/**
 * Reads an image from a file in memory.
 * @param [in] fileBytes A NSData object that points to a file in memory.
 * @param [in,out] error An NSError pointer.
 *
 * @return Returns a DSImageData object representing the image.
 */
- (nullable DSImageData *)readFromMemory:(NSData *)fileBytes
                          error:(NSError * _Nullable * _Nullable)error;

@end

NS_ASSUME_NONNULL_END
