GPUImageOutput.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #import "GPUImageContext.h"
  2. #import "GPUImageFramebuffer.h"
  3. #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
  4. #import <UIKit/UIKit.h>
  5. #else
  6. // For now, just redefine this on the Mac
  7. typedef NS_ENUM(NSInteger, UIImageOrientation) {
  8. UIImageOrientationUp, // default orientation
  9. UIImageOrientationDown, // 180 deg rotation
  10. UIImageOrientationLeft, // 90 deg CCW
  11. UIImageOrientationRight, // 90 deg CW
  12. UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip
  13. UIImageOrientationDownMirrored, // horizontal flip
  14. UIImageOrientationLeftMirrored, // vertical flip
  15. UIImageOrientationRightMirrored, // vertical flip
  16. };
  17. #endif
  18. void runOnMainQueueWithoutDeadlocking(void (^block)(void));
  19. void runSynchronouslyOnVideoProcessingQueue(void (^block)(void));
  20. void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void));
  21. void runSynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void));
  22. void runAsynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void));
  23. void reportAvailableMemoryForGPUImage(NSString *tag);
  24. @class GPUImageMovieWriter;
  25. /** GPUImage's base source object
  26. Images or frames of video are uploaded from source objects, which are subclasses of GPUImageOutput. These include:
  27. - GPUImageVideoCamera (for live video from an iOS camera)
  28. - GPUImageStillCamera (for taking photos with the camera)
  29. - GPUImagePicture (for still images)
  30. - GPUImageMovie (for movies)
  31. Source objects upload still image frames to OpenGL ES as textures, then hand those textures off to the next objects in the processing chain.
  32. */
  33. @interface GPUImageOutput : NSObject
  34. {
  35. GPUImageFramebuffer *outputFramebuffer;
  36. NSMutableArray *targets, *targetTextureIndices;
  37. CGSize inputTextureSize, cachedMaximumOutputSize, forcedMaximumSize;
  38. BOOL overrideInputSize;
  39. BOOL allTargetsWantMonochromeData;
  40. BOOL usingNextFrameForImageCapture;
  41. }
  42. @property(readwrite, nonatomic) BOOL shouldSmoothlyScaleOutput;
  43. @property(readwrite, nonatomic) BOOL shouldIgnoreUpdatesToThisTarget;
  44. @property(readwrite, nonatomic, retain) GPUImageMovieWriter *audioEncodingTarget;
  45. @property(readwrite, nonatomic, unsafe_unretained) id<GPUImageInput> targetToIgnoreForUpdates;
  46. @property(nonatomic, copy) void(^frameProcessingCompletionBlock)(GPUImageOutput*, CMTime);
  47. @property(nonatomic) BOOL enabled;
  48. @property(readwrite, nonatomic) GPUTextureOptions outputTextureOptions;
  49. /// @name Managing targets
  50. - (void)setInputFramebufferForTarget:(id<GPUImageInput>)target atIndex:(NSInteger)inputTextureIndex;
  51. - (GPUImageFramebuffer *)framebufferForOutput;
  52. - (void)removeOutputFramebuffer;
  53. - (void)notifyTargetsAboutNewOutputTexture;
  54. /** Returns an array of the current targets.
  55. */
  56. - (NSArray*)targets;
  57. /** Adds a target to receive notifications when new frames are available.
  58. The target will be asked for its next available texture.
  59. See [GPUImageInput newFrameReadyAtTime:]
  60. @param newTarget Target to be added
  61. */
  62. - (void)addTarget:(id<GPUImageInput>)newTarget;
  63. /** Adds a target to receive notifications when new frames are available.
  64. See [GPUImageInput newFrameReadyAtTime:]
  65. @param newTarget Target to be added
  66. */
  67. - (void)addTarget:(id<GPUImageInput>)newTarget atTextureLocation:(NSInteger)textureLocation;
  68. /** Removes a target. The target will no longer receive notifications when new frames are available.
  69. @param targetToRemove Target to be removed
  70. */
  71. - (void)removeTarget:(id<GPUImageInput>)targetToRemove;
  72. /** Removes all targets.
  73. */
  74. - (void)removeAllTargets;
  75. /// @name Manage the output texture
  76. - (void)forceProcessingAtSize:(CGSize)frameSize;
  77. - (void)forceProcessingAtSizeRespectingAspectRatio:(CGSize)frameSize;
  78. /// @name Still image processing
  79. - (void)useNextFrameForImageCapture;
  80. - (CGImageRef)newCGImageFromCurrentlyProcessedOutput;
  81. - (CGImageRef)newCGImageByFilteringCGImage:(CGImageRef)imageToFilter;
  82. // Platform-specific image output methods
  83. // If you're trying to use these methods, remember that you need to set -useNextFrameForImageCapture before running -processImage or running video and calling any of these methods, or you will get a nil image
  84. #if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
  85. - (UIImage *)imageFromCurrentFramebuffer;
  86. - (UIImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation;
  87. - (UIImage *)imageByFilteringImage:(UIImage *)imageToFilter;
  88. - (CGImageRef)newCGImageByFilteringImage:(UIImage *)imageToFilter;
  89. #else
  90. - (NSImage *)imageFromCurrentFramebuffer;
  91. - (NSImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation;
  92. - (NSImage *)imageByFilteringImage:(NSImage *)imageToFilter;
  93. - (CGImageRef)newCGImageByFilteringImage:(NSImage *)imageToFilter;
  94. #endif
  95. - (BOOL)providesMonochromeOutput;
  96. @end