mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'beta'
This commit is contained in:
commit
9941c499c6
@ -6,6 +6,7 @@
|
||||
#import "libswresample/swresample.h"
|
||||
|
||||
@interface FFMpegSWResample () {
|
||||
int _sourceChannelCount;
|
||||
SwrContext *_context;
|
||||
NSUInteger _ratio;
|
||||
NSInteger _destinationChannelCount;
|
||||
@ -21,6 +22,7 @@
|
||||
- (instancetype)initWithSourceChannelCount:(NSInteger)sourceChannelCount sourceSampleRate:(NSInteger)sourceSampleRate sourceSampleFormat:(enum FFMpegAVSampleFormat)sourceSampleFormat destinationChannelCount:(NSInteger)destinationChannelCount destinationSampleRate:(NSInteger)destinationSampleRate destinationSampleFormat:(enum FFMpegAVSampleFormat)destinationSampleFormat {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_sourceChannelCount = sourceChannelCount;
|
||||
_destinationChannelCount = destinationChannelCount;
|
||||
_destinationSampleFormat = destinationSampleFormat;
|
||||
_context = swr_alloc_set_opts(NULL,
|
||||
@ -47,6 +49,12 @@
|
||||
|
||||
- (NSData * _Nullable)resample:(FFMpegAVFrame *)frame {
|
||||
AVFrame *frameImpl = (AVFrame *)[frame impl];
|
||||
|
||||
int numChannels = frameImpl->channels;
|
||||
if (numChannels != _sourceChannelCount) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
int bufSize = av_samples_get_buffer_size(NULL,
|
||||
(int)_destinationChannelCount,
|
||||
frameImpl->nb_samples * (int)_ratio,
|
||||
|
@ -71,7 +71,9 @@ public func adjustSaturationInContext(context: DrawingContext, saturation: CGFlo
|
||||
vImageMatrixMultiply_ARGB8888(&buffer, &buffer, &matrix, divisor, nil, nil, vImage_Flags(kvImageDoNotTile))
|
||||
}
|
||||
|
||||
private func generateGradient(size: CGSize, colors: [UIColor], positions: [CGPoint], adjustSaturation: CGFloat = 1.0) -> UIImage {
|
||||
private func generateGradient(size: CGSize, colors inputColors: [UIColor], positions: [CGPoint], adjustSaturation: CGFloat = 1.0) -> UIImage {
|
||||
let colors: [UIColor] = inputColors.count == 1 ? [inputColors[0], inputColors[0], inputColors[0]] : inputColors
|
||||
|
||||
let width = Int(size.width)
|
||||
let height = Int(size.height)
|
||||
|
||||
@ -146,10 +148,29 @@ private func generateGradient(size: CGSize, colors: [UIColor], positions: [CGPoi
|
||||
b = b + distance * rgb[i * 3 + 2]
|
||||
}
|
||||
|
||||
if distanceSum < 0.00001 {
|
||||
distanceSum = 0.00001
|
||||
}
|
||||
|
||||
var pixelB = b / distanceSum * 255.0
|
||||
if pixelB > 255.0 {
|
||||
pixelB = 255.0
|
||||
}
|
||||
|
||||
var pixelG = g / distanceSum * 255.0
|
||||
if pixelG > 255.0 {
|
||||
pixelG = 255.0
|
||||
}
|
||||
|
||||
var pixelR = r / distanceSum * 255.0
|
||||
if pixelR > 255.0 {
|
||||
pixelR = 255.0
|
||||
}
|
||||
|
||||
let pixelBytes = lineBytes.advanced(by: x * 4)
|
||||
pixelBytes.advanced(by: 0).pointee = UInt8(b / distanceSum * 255.0)
|
||||
pixelBytes.advanced(by: 1).pointee = UInt8(g / distanceSum * 255.0)
|
||||
pixelBytes.advanced(by: 2).pointee = UInt8(r / distanceSum * 255.0)
|
||||
pixelBytes.advanced(by: 0).pointee = UInt8(pixelB)
|
||||
pixelBytes.advanced(by: 1).pointee = UInt8(pixelG)
|
||||
pixelBytes.advanced(by: 2).pointee = UInt8(pixelR)
|
||||
pixelBytes.advanced(by: 3).pointee = 0xff
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user