mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Accelerate vImage Swift Overlays A suite of functions, enumerations, and option sets to make working with vImage in Swift simpler. * vImage_Buffer - new initializers to instantiate and initialize buffers with a single function call. * vImage_Buffer - new functions to copy buffers and create CGImage instances from contents. * vImage_CGImageFormat - new initializers. * vImage_CGImageFormat - new equivalence operator. * vImageConverter - methods to wrap free functions. * vImageConverter - new make and convert functions. * vImageCVImageFormat - new make functions. * vImageCVImageFormat - methods to wrap free functions. * vImage_Error - errorDescription function. * vImage flags as an option set. * Add new methods for generating CV -> CG and CG -> CV converters. * update comments: `height` and `width` to `size`. * `vImage_CGImageFormat.componentCount` should be `Int`. * `vImage_CGImageFormat.componentCount` should be `Int` * Move `self.init()` to after the size check for kvImageNoAllocate init. * Buffer initializers to width and height rather than size. * change vImage_CGImageFormat lightweight initializer to accept Int for `bitsPerComponent` and `bitsPerPixel`. * Flesh out docs for vImage_Buffer.size * Remove faux initializer in favor of new static function: `preferredAlignmentAndRowBytes`. * Change functions to use proper error handling rather than inout error codes. * Removed `flags` from basic init. The only real flag to pass here is print diagnostics to console, and I now throw proper errors. * Tests to check error throwing for buffer copy. * remove unnecessary import, add missing docs. * Add comments to error enums. * Fix bug creating string from format code. * Make `vImageCVImageFormat.formatCode` a `UInt32`. * Remove equivalence operator from `CGImageFormat`.
98 lines
4.0 KiB
Swift
98 lines
4.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// vImage_Error
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
|
|
extension vImage {
|
|
|
|
/// Error codes returned by vImage operations.
|
|
public enum Error: Int, Swift.Error {
|
|
/// The vImage function completed without error.
|
|
case noError = 0
|
|
|
|
// The region of interest, as specified by the `srcOffsetToROI_X` and
|
|
// `srcOffsetToROI_Y` parameters and the height and width of the destination
|
|
// buffer, extends beyond the bottom edge or right edge of the source buffer.
|
|
case roiLargerThanInputBuffer = -21766
|
|
|
|
/// Either the kernel height, the kernel width, or both, are even.
|
|
case invalidKernelSize = -21767
|
|
|
|
/// The edge style specified is invalid.
|
|
case invalidEdgeStyle = -21768
|
|
|
|
/// The `srcOffsetToROI_X` parameter that specifies the left edge of
|
|
/// the region of interest is greater than the width of the source image.
|
|
case invalidOffset_X = -21769
|
|
|
|
/// The `srcOffsetToROI_X` parameter that specifies the left edge of
|
|
/// the region of interest is greater than the height of the source image.
|
|
case invalidOffset_Y = -21770
|
|
|
|
/// An attempt to allocate memory failed.
|
|
case memoryAllocationError = -21771
|
|
|
|
/// A pointer parameter is NULL and it must not be.
|
|
case nullPointerArgument = -21772
|
|
|
|
/// Invalid parameter.
|
|
case invalidParameter = -21773
|
|
|
|
/// The function requires the source and destination buffers to have
|
|
/// the same height and the same width, but they do not.
|
|
case bufferSizeMismatch = -21774
|
|
|
|
/// The flag is not recognized.
|
|
case unknownFlagsBit = -21775
|
|
|
|
/// A serious error occured inside vImage, which prevented vImage
|
|
/// from continuing.
|
|
case internalError = -21776
|
|
|
|
/// The vImage_Buffer.rowBytes field is invalid.
|
|
case invalidRowBytes = -21777
|
|
|
|
/// a `vImage_CGImageFormat` or `vImageCVImageFormatRef` contains
|
|
/// an invalid format.
|
|
case invalidImageFormat = -21778
|
|
|
|
/// ColorSync.framework is completely missing.
|
|
case colorSyncIsAbsent = -21779
|
|
|
|
/// The source images and destination images may not alias the same image data.
|
|
case outOfPlaceOperationRequired = -21780
|
|
|
|
/// An invalid `CGImageRef` or `CVPixelBufferRef` was passed to the function.
|
|
case invalidImageObject = -21781
|
|
|
|
/// A `vImageCVImageFormatRef` contains an invalid format.
|
|
case invalidCVImageFormat = -21782
|
|
|
|
/// Some lower level conversion APIs only support conversion among a
|
|
/// sparse matrix of image formats.
|
|
case unsupportedConversion = -21783
|
|
|
|
/// Core Video is absent.
|
|
case coreVideoIsAbsent = -21784
|
|
|
|
public init(vImageError: vImage_Error) {
|
|
self = Error(rawValue: vImageError) ?? .internalError
|
|
}
|
|
}
|
|
|
|
}
|