mirror of
https://github.com/opencv/opencv.git
synced 2026-07-21 19:33:03 +04:00
Merge pull request #29138 from Licardo-du:fix-imgcodecs-apple-avfoundation
imgcodecs: fix Apple conversions build without AVFoundation #29138 Fixes #28553. This PR fixes Apple imgcodecs conversion builds when AVFoundation is disabled or unavailable on older macOS SDKs. Changes: - Guard AVFoundation import with HAVE_AVFOUNDATION. - Use older macOS-compatible framework imports when ImageIO is unavailable. - Add __bridge compatibility for older Objective-C++ compilers. - Use NSMakeSize for older macOS instead of passing CGSize to NSImage API. Testing: - Not tested locally: no macOS environment available. - Patch follows the fix confirmed in #28555 discussion.
This commit is contained in:
@@ -2,10 +2,27 @@
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_IMGCODECS_APPLE_CONVERSIONS_H
|
||||
#define OPENCV_IMGCODECS_APPLE_CONVERSIONS_H
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#import <Accelerate/Accelerate.h>
|
||||
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
#ifdef HAVE_AVFOUNDATION
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE || (defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080)
|
||||
#import <ImageIO/ImageIO.h>
|
||||
#else
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
CV_EXPORTS CGImageRef MatToCGImage(const cv::Mat& image) CF_RETURNS_RETAINED;
|
||||
CV_EXPORTS void CGImageToMat(const CGImageRef image, cv::Mat& m, bool alphaExist);
|
||||
|
||||
#endif // OPENCV_IMGCODECS_APPLE_CONVERSIONS_H
|
||||
@@ -5,6 +5,12 @@
|
||||
#include "apple_conversions.h"
|
||||
#include "precomp.hpp"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifndef __bridge
|
||||
#define __bridge
|
||||
#endif
|
||||
|
||||
CGImageRef MatToCGImage(const cv::Mat& image) {
|
||||
NSData *data = [NSData dataWithBytes:image.data
|
||||
length:image.step.p[0] * image.rows];
|
||||
|
||||
@@ -13,9 +13,11 @@ NSImage* MatToNSImage(const cv::Mat& image) {
|
||||
CGImageRef imageRef = MatToCGImage(image);
|
||||
|
||||
// Getting NSImage from CGImage
|
||||
NSImage *nsImage = [[NSImage alloc] initWithCGImage:imageRef size:CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef))];
|
||||
NSSize imageSize = NSMakeSize(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
|
||||
NSImage *nsImage = [[NSImage alloc] initWithCGImage:imageRef size:imageSize];
|
||||
CGImageRelease(imageRef);
|
||||
|
||||
|
||||
return nsImage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user