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`.
95 lines
4.8 KiB
Swift
95 lines
4.8 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_Options
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@available(iOS 9999, OSX 9999, tvOS 9999, watchOS 9999, *)
|
|
extension vImage {
|
|
|
|
/// An option set that represents `vImage_Flags`.
|
|
///
|
|
/// You can also use this option set with the existing vImage API with the
|
|
/// `flags` property. For example:
|
|
///
|
|
/// vImageTentConvolve_ARGB8888(&src, &dst, nil,
|
|
/// 0, 0, 11, 11,
|
|
/// [0,0,0,0],
|
|
/// vImage_Options([.backgroundColorFill,
|
|
/// .doNotTile]).flags)
|
|
public struct Options: OptionSet {
|
|
|
|
public init(rawValue: vImage_Flags) {
|
|
self.rawValue = rawValue
|
|
}
|
|
|
|
public let rawValue: vImage_Flags
|
|
|
|
public static let noFlags = Options(rawValue: vImage_Flags(kvImageNoFlags))
|
|
|
|
/// Operate on red, green and blue channels only. Alpha is copied from source
|
|
/// to destination. For Interleaved formats only
|
|
public static let leaveAlphaUnchanged = Options(rawValue: vImage_Flags(kvImageLeaveAlphaUnchanged))
|
|
|
|
/// Copy edge pixels. Convolution Only.
|
|
public static let copyInPlace = Options(rawValue: vImage_Flags(kvImageCopyInPlace))
|
|
|
|
/// Use the background color for missing pixels.
|
|
public static let backgroundColorFill = Options(rawValue: vImage_Flags(kvImageBackgroundColorFill))
|
|
|
|
/// Use the nearest pixel for missing pixels.
|
|
public static let imageExtend = Options(rawValue: vImage_Flags(kvImageEdgeExtend))
|
|
|
|
/// Pass to turn off internal tiling and disable internal multithreading. Use this if
|
|
/// you want to do your own tiling, or to use the Min/Max filters in place.
|
|
public static let doNotTile = Options(rawValue: vImage_Flags(kvImageDoNotTile))
|
|
|
|
/// Use a higher quality, slower resampling filter for Geometry operations
|
|
/// (shear, scale, rotate, affine transform, etc.)
|
|
public static let highQualityResampling = Options(rawValue: vImage_Flags(kvImageHighQualityResampling))
|
|
|
|
/// Use only the part of the kernel that overlaps the image. For integer kernels,
|
|
/// real_divisor = divisor * (sum of used kernel elements) / (sum of kernel elements).
|
|
/// This should preserve image brightness at the edges. Convolution only.
|
|
public static let truncateKernel = Options(rawValue: vImage_Flags(kvImageTruncateKernel))
|
|
|
|
/// The function will return the number of bytes required for the temp buffer.
|
|
/// If this value is negative, it is an error, per standard usage.
|
|
public static let getTempBufferSize = Options(rawValue: vImage_Flags(kvImageGetTempBufferSize))
|
|
|
|
/// Some functions such as vImageConverter_CreateWithCGImageFormat have so many possible error conditions
|
|
/// that developers may need more help than a simple error code to diagnose problems. When this
|
|
/// flag is set and an error is encountered, an informative error message will be logged to the Apple
|
|
/// System Logger (ASL). The output should be visible in Console.app.
|
|
public static let printDiagnosticsToConsole = Options(rawValue: vImage_Flags(kvImagePrintDiagnosticsToConsole))
|
|
|
|
/// Pass this flag to prevent vImage from allocating additional storage.
|
|
public static let noAllocate = Options(rawValue: vImage_Flags(kvImageNoAllocate))
|
|
|
|
/// Use methods that are HDR-aware, capable of providing correct results for input images with pixel values
|
|
/// outside the otherwise limited (typically [-2,2]) range. This may be slower.
|
|
public static let hdrContent = Options(rawValue: vImage_Flags(kvImageHDRContent))
|
|
|
|
/// Pass to disable clamping is some conversions to floating point formats. Use this if the input data
|
|
/// may describe values outside [0,1] which should be preserved.
|
|
public static let doNotClamp = Options(rawValue: vImage_Flags(kvImageDoNotClamp))
|
|
|
|
public var flags: vImage_Flags {
|
|
return self.rawValue
|
|
}
|
|
}
|
|
|
|
}
|