2023-02-21 07:00:48 -07:00
|
|
|
//
|
|
|
|
// SkImageHelpers.h
|
|
|
|
// VisionCamera
|
|
|
|
//
|
|
|
|
// Created by Marc Rousavy on 23.11.22.
|
|
|
|
// Copyright © 2022 mrousavy. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2023-07-31 03:41:47 -06:00
|
|
|
#pragma once
|
2023-02-21 07:00:48 -07:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2023-07-03 04:41:26 -06:00
|
|
|
#import <MetalKit/MetalKit.h>
|
|
|
|
|
2023-02-21 07:00:48 -07:00
|
|
|
#import <include/gpu/GrRecordingContext.h>
|
|
|
|
|
|
|
|
#import "SkImage.h"
|
|
|
|
#import "SkSize.h"
|
|
|
|
#import "SkRect.h"
|
|
|
|
|
|
|
|
class SkImageHelpers {
|
|
|
|
public:
|
|
|
|
SkImageHelpers() = delete;
|
2023-07-31 03:41:47 -06:00
|
|
|
|
2023-02-21 07:00:48 -07:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Convert a CMSampleBuffer to an SkImage. Format has to be RGB.
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> convertCMSampleBufferToSkImage(GrRecordingContext* context, CMSampleBufferRef sampleBuffer);
|
2023-07-03 04:41:26 -06:00
|
|
|
/**
|
|
|
|
Convert a MTLTexture to an SkImage. Format has to be RGB.
|
|
|
|
*/
|
|
|
|
static sk_sp<SkImage> convertMTLTextureToSkImage(GrRecordingContext* context, id<MTLTexture> mtlTexture);
|
2023-02-21 07:00:48 -07:00
|
|
|
/**
|
|
|
|
Creates a Center Crop Transformation Rect so that the source rect fills (aspectRatio: cover) the destination rect.
|
|
|
|
The return value should be passed as a sourceRect to a canvas->draw...Rect(..) function, destinationRect should stay the same.
|
|
|
|
*/
|
|
|
|
static SkRect createCenterCropRect(SkRect source, SkRect destination);
|
2023-07-31 03:41:47 -06:00
|
|
|
|
2023-02-21 07:00:48 -07:00
|
|
|
private:
|
|
|
|
static SkRect inscribe(SkSize size, SkRect rect);
|
|
|
|
};
|