objc2-vision 0.3.2

Bindings to the Vision framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

/// Text recognition level options to favor speed over recognition accuracy. The VNRequestTextRecognitionLevelAccurate is the default option used by VNRecognizeTextRequest.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrequesttextrecognitionlevel?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct VNRequestTextRecognitionLevel(pub NSInteger);
impl VNRequestTextRecognitionLevel {
    #[doc(alias = "VNRequestTextRecognitionLevelAccurate")]
    pub const Accurate: Self = Self(0);
    #[doc(alias = "VNRequestTextRecognitionLevelFast")]
    pub const Fast: Self = Self(1);
}

unsafe impl Encode for VNRequestTextRecognitionLevel {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for VNRequestTextRecognitionLevel {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// A request that will detect regions of text and recognize the containing text in an image.
    ///
    ///
    /// This request will generate VNRecognizedTextObservation objects describing the locations of text and the actual text recognized.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequest?language=objc)
    #[unsafe(super(VNImageBasedRequest, VNRequest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[cfg(feature = "VNRequest")]
    pub struct VNRecognizeTextRequest;
);

#[cfg(feature = "VNRequest")]
extern_conformance!(
    unsafe impl NSCopying for VNRecognizeTextRequest {}
);

#[cfg(feature = "VNRequest")]
unsafe impl CopyingHelper for VNRecognizeTextRequest {
    type Result = Self;
}

#[cfg(feature = "VNRequest")]
extern_conformance!(
    unsafe impl NSObjectProtocol for VNRecognizeTextRequest {}
);

#[cfg(feature = "VNRequest")]
extern_conformance!(
    unsafe impl VNRequestProgressProviding for VNRecognizeTextRequest {}
);

#[cfg(feature = "VNRequest")]
impl VNRecognizeTextRequest {
    extern_methods!(
        /// Returns all the supported languages for a given text recognition level. Note that a language supported in one recognition level might not be available in another.
        #[deprecated]
        #[unsafe(method(supportedRecognitionLanguagesForTextRecognitionLevel:revision:error:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn supportedRecognitionLanguagesForTextRecognitionLevel_revision_error(
            recognition_level: VNRequestTextRecognitionLevel,
            request_revision: NSUInteger,
        ) -> Result<Retained<NSArray<NSString>>, Retained<NSError>>;

        /// Obtain the collection of supported recognition languages.
        ///
        /// This method will return the collection of all possible language identifiers that are recognized by the target request based on its current state of configuration at the time of the call.
        ///
        ///
        /// Parameter `error`: The address of the variable that will be populated with the error if the call fails.
        ///
        ///
        /// Returns: The collection of language identifiers, or nil if a failure occurs.
        #[unsafe(method(supportedRecognitionLanguagesAndReturnError:_))]
        #[unsafe(method_family = none)]
        pub unsafe fn supportedRecognitionLanguagesAndReturnError(
            &self,
        ) -> Result<Retained<NSArray<NSString>>, Retained<NSError>>;

        /// Specify the languages used for the detection. The order of the languages in the array defines the order in which languages will be used during the language processing.
        /// The languages are specified as ISO language codes.
        #[unsafe(method(recognitionLanguages))]
        #[unsafe(method_family = none)]
        pub unsafe fn recognitionLanguages(&self) -> Retained<NSArray<NSString>>;

        /// Setter for [`recognitionLanguages`][Self::recognitionLanguages].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setRecognitionLanguages:))]
        #[unsafe(method_family = none)]
        pub fn setRecognitionLanguages(&self, recognition_languages: &NSArray<NSString>);

        /// An array of strings that will be used at the word recognition stage in addition to the recognition languages. The customWords list takes precedence over the standard lexicon.
        #[unsafe(method(customWords))]
        #[unsafe(method_family = none)]
        pub fn customWords(&self) -> Retained<NSArray<NSString>>;

        /// Setter for [`customWords`][Self::customWords].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCustomWords:))]
        #[unsafe(method_family = none)]
        pub fn setCustomWords(&self, custom_words: &NSArray<NSString>);

        /// The recognition level selects which techniques will be used during the text recognition. There are trade-offs between performance and accuracy.
        #[unsafe(method(recognitionLevel))]
        #[unsafe(method_family = none)]
        pub fn recognitionLevel(&self) -> VNRequestTextRecognitionLevel;

        /// Setter for [`recognitionLevel`][Self::recognitionLevel].
        #[unsafe(method(setRecognitionLevel:))]
        #[unsafe(method_family = none)]
        pub fn setRecognitionLevel(&self, recognition_level: VNRequestTextRecognitionLevel);

        /// Determines whether language correction should be applied during the recognition process. Disabling this will return the raw recognition results providing performance benefits but less accurate results.
        #[unsafe(method(usesLanguageCorrection))]
        #[unsafe(method_family = none)]
        pub fn usesLanguageCorrection(&self) -> bool;

        /// Setter for [`usesLanguageCorrection`][Self::usesLanguageCorrection].
        #[unsafe(method(setUsesLanguageCorrection:))]
        #[unsafe(method_family = none)]
        pub fn setUsesLanguageCorrection(&self, uses_language_correction: bool);

        /// Language detection will try to automatically identify the script/langauge during the detection and use the appropiate model for recognition and language correction. This can be particularly helpful, if the nature of the content is unkown and with this flag being set it will for instance determine if text is latin vs chinese so you don't have to pick the language model in the first case. But as the language correction cannot always guarantee the correct detection, it is advisable to set the languages, if you have domain knowledge of what language to expect. The default value is NO. Also note that this feature is only available since VNRecognizeTextRequestRevision3 and is a no-op before that.
        #[unsafe(method(automaticallyDetectsLanguage))]
        #[unsafe(method_family = none)]
        pub fn automaticallyDetectsLanguage(&self) -> bool;

        /// Setter for [`automaticallyDetectsLanguage`][Self::automaticallyDetectsLanguage].
        #[unsafe(method(setAutomaticallyDetectsLanguage:))]
        #[unsafe(method_family = none)]
        pub fn setAutomaticallyDetectsLanguage(&self, automatically_detects_language: bool);

        #[unsafe(method(minimumTextHeight))]
        #[unsafe(method_family = none)]
        pub fn minimumTextHeight(&self) -> c_float;

        /// Setter for [`minimumTextHeight`][Self::minimumTextHeight].
        #[unsafe(method(setMinimumTextHeight:))]
        #[unsafe(method_family = none)]
        pub fn setMinimumTextHeight(&self, minimum_text_height: c_float);

        #[cfg(feature = "VNObservation")]
        /// VNRecognizedTextObservation results.
        #[unsafe(method(results))]
        #[unsafe(method_family = none)]
        pub fn results(&self) -> Option<Retained<NSArray<VNRecognizedTextObservation>>>;
    );
}

/// Methods declared on superclass `VNRequest`.
#[cfg(feature = "VNRequest")]
impl VNRecognizeTextRequest {
    extern_methods!(
        /// Creates a new VNRequest with no completion handler.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// Creates a new VNRequest with an optional completion handler.
        ///
        ///
        /// Parameter `completionHandler`: The block to be invoked after the request has completed its processing. The completion handler gets executed on the same dispatch queue as the request being executed.
        ///
        /// # Safety
        ///
        /// `completion_handler` must be a valid pointer or null.
        #[unsafe(method(initWithCompletionHandler:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCompletionHandler(
            this: Allocated<Self>,
            completion_handler: VNRequestCompletionHandler,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
#[cfg(feature = "VNRequest")]
impl VNRecognizeTextRequest {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

#[cfg(feature = "VNRequest")]
impl DefaultRetained for VNRecognizeTextRequest {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision1?language=objc)
#[deprecated]
pub static VNRecognizeTextRequestRevision1: NSUInteger = 1;

/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision2?language=objc)
#[deprecated]
pub static VNRecognizeTextRequestRevision2: NSUInteger = 2;

/// [Apple's documentation](https://developer.apple.com/documentation/vision/vnrecognizetextrequestrevision3?language=objc)
pub static VNRecognizeTextRequestRevision3: NSUInteger = 3;