Fixed formatting of MPPImage+Utils.mm
This commit is contained in:
parent
4668d683d5
commit
b9c869494d
|
@ -54,9 +54,7 @@ static void FreeDataProviderReleaseCallback(void *buffer, const void *data, size
|
|||
delete[] buffer;
|
||||
}
|
||||
|
||||
static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
||||
delete[] refCon;
|
||||
}
|
||||
static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) { delete[] refCon; }
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -80,9 +78,7 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
+ (std::unique_ptr<ImageFrame>)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer
|
||||
error:(NSError **)error;
|
||||
|
||||
|
||||
+ (CVPixelBufferRef)cvPixelBufferFromImageFrame:(ImageFrame &)imageFrame
|
||||
error:(NSError **)error;
|
||||
+ (CVPixelBufferRef)cvPixelBufferFromImageFrame:(ImageFrame &)imageFrame error:(NSError **)error;
|
||||
@end
|
||||
|
||||
@interface MPPCGImageUtils : NSObject
|
||||
|
@ -177,7 +173,8 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
case ImageFormat::SRGBA: {
|
||||
destinationBuffer =
|
||||
shouldCopy ? EmptyVImageBufferFromImageFrame(imageFrame, true) : sourceBuffer;
|
||||
premultiplyError = vImagePremultiplyData_RGBA8888(&sourceBuffer, &destinationBuffer, kvImageNoFlags);
|
||||
premultiplyError =
|
||||
vImagePremultiplyData_RGBA8888(&sourceBuffer, &destinationBuffer, kvImageNoFlags);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -224,16 +221,15 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
default: {
|
||||
[MPPCommonUtils createCustomError:error
|
||||
withCode:MPPTasksErrorCodeInvalidArgumentError
|
||||
description:@"Unsupported pixel format for CVPixelBuffer. Supported pixel format is kCVPixelFormatType_32BGRA"];
|
||||
description:@"Unsupported pixel format for CVPixelBuffer. Supported "
|
||||
@"pixel format is kCVPixelFormatType_32BGRA"];
|
||||
}
|
||||
}
|
||||
|
||||
return imageFrame;
|
||||
}
|
||||
|
||||
+ (CVPixelBufferRef)cvPixelBufferFromImageFrame:(ImageFrame &)imageFrame
|
||||
error:(NSError **)error {
|
||||
|
||||
+ (CVPixelBufferRef)cvPixelBufferFromImageFrame:(ImageFrame &)imageFrame error:(NSError **)error {
|
||||
// Supporting only RGBA and BGRA since creation of CVPixelBuffers with RGB format
|
||||
// is restrictred in iOS. Thus, the APIs will never receive an input pixel buffer in RGB format
|
||||
// and in turn the resulting image frame will never be of the RGB format. Moreover, writing unit
|
||||
|
@ -261,7 +257,8 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
vImage_Buffer sourceBuffer = EmptyVImageBufferFromImageFrame(imageFrame, NO);
|
||||
sourceBuffer.data = pixelData;
|
||||
|
||||
if (vImagePermuteChannels_ARGB8888(&sourceBuffer, &sourceBuffer, permute_map, kvImageNoFlags) != kvImageNoError) {
|
||||
if (vImagePermuteChannels_ARGB8888(&sourceBuffer, &sourceBuffer, permute_map, kvImageNoFlags) !=
|
||||
kvImageNoError) {
|
||||
[MPPCommonUtils createCustomError:error
|
||||
withCode:MPPTasksErrorCodeInternalError
|
||||
description:@"An internal error occured."];
|
||||
|
@ -272,14 +269,13 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
|
||||
OSType pixelBufferFormatType = kCVPixelFormatType_32BGRA;
|
||||
|
||||
|
||||
// If pixel data is copied, then pass in a release callback that will be invoked when the
|
||||
// pixel buffer is destroyed. If data is not copied, the responsibility of deletion is on the
|
||||
// owner of the data (a.k.a C++ Image Frame).
|
||||
if(CVPixelBufferCreateWithBytes(kCFAllocatorDefault, imageFrame.Width(), imageFrame.Height(),
|
||||
if (CVPixelBufferCreateWithBytes(kCFAllocatorDefault, imageFrame.Width(), imageFrame.Height(),
|
||||
pixelBufferFormatType, pixelData, imageFrame.WidthStep(),
|
||||
FreeRefConReleaseCallback,
|
||||
pixelData, NULL, &outputBuffer) == kCVReturnSuccess) {
|
||||
FreeRefConReleaseCallback, pixelData, NULL,
|
||||
&outputBuffer) == kCVReturnSuccess) {
|
||||
return outputBuffer;
|
||||
}
|
||||
[MPPCommonUtils createCustomError:error
|
||||
|
@ -288,7 +284,6 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPPCGImageUtils
|
||||
|
@ -371,8 +366,8 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
CGDataProviderReleaseDataCallback callback = nullptr;
|
||||
|
||||
CGDataProviderRef provider = CGDataProviderCreateWithData(
|
||||
pixelData, pixelData,
|
||||
internalImageFrame->WidthStep() * internalImageFrame->Height(), callback);
|
||||
pixelData, pixelData, internalImageFrame->WidthStep() * internalImageFrame->Height(),
|
||||
callback);
|
||||
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
|
||||
|
@ -455,9 +450,11 @@ static void FreeRefConReleaseCallback(void *refCon, const void *baseAddress) {
|
|||
}
|
||||
case MPPImageSourceTypePixelBuffer: {
|
||||
if (!shouldCopyPixelData) {
|
||||
[MPPCommonUtils createCustomError:error
|
||||
[MPPCommonUtils
|
||||
createCustomError:error
|
||||
withCode:MPPTasksErrorCodeInvalidArgumentError
|
||||
description:@"When the source type is pixel buffer, you cannot request uncopied data"];
|
||||
description:
|
||||
@"When the source type is pixel buffer, you cannot request uncopied data"];
|
||||
return nil;
|
||||
}
|
||||
CVPixelBufferRef pixelBuffer =
|
||||
|
|
Loading…
Reference in New Issue
Block a user