2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7 KiB

  1. //
  2. // SCExposureAdjustProcessingModule.m
  3. // Snapchat
  4. //
  5. // Created by Yu-Kuan (Anthony) Lai on 6/1/17.
  6. // Copyright © 2017 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCExposureAdjustProcessingModule.h"
  9. #import "SCProcessingModuleUtils.h"
  10. @import CoreImage;
  11. @import CoreMedia;
  12. static const CGFloat kSCExposureAdjustProcessingModuleMaxEVValue = 2.0;
  13. @implementation SCExposureAdjustProcessingModule {
  14. CIContext *_context;
  15. CIFilter *_filter;
  16. CFMutableDictionaryRef _attributes;
  17. CVPixelBufferPoolRef _bufferPool;
  18. }
  19. - (instancetype)init
  20. {
  21. if (self = [super init]) {
  22. _context = [CIContext context];
  23. _filter = [CIFilter filterWithName:@"CIExposureAdjust"];
  24. [_filter setValue:@0.0 forKey:@"inputEV"];
  25. }
  26. return self;
  27. }
  28. - (void)setEVValue:(CGFloat)value
  29. {
  30. CGFloat newEVValue = value * kSCExposureAdjustProcessingModuleMaxEVValue;
  31. [_filter setValue:@(newEVValue) forKey:@"inputEV"];
  32. }
  33. - (void)dealloc
  34. {
  35. CVPixelBufferPoolFlush(_bufferPool, kCVPixelBufferPoolFlushExcessBuffers);
  36. CVPixelBufferPoolRelease(_bufferPool);
  37. }
  38. - (BOOL)requiresDepthData
  39. {
  40. return NO;
  41. }
  42. - (CMSampleBufferRef)render:(RenderData)renderData
  43. {
  44. CMSampleBufferRef input = renderData.sampleBuffer;
  45. CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(input);
  46. CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer];
  47. [_filter setValue:image forKey:kCIInputImageKey];
  48. CIImage *result = [_filter outputImage];
  49. return [SCProcessingModuleUtils sampleBufferFromImage:result
  50. oldSampleBuffer:input
  51. bufferPool:_bufferPool
  52. context:_context];
  53. }
  54. @end