Swiftgram/submodules/TelegramUI/TelegramUI/LegacyImageProcessors.m
Peter b317aab568 Add 'submodules/TelegramUI/' from commit 'fa3ac0b61a27c8dd3296518a15891a6f9750cbf2'
git-subtree-dir: submodules/TelegramUI
git-subtree-mainline: 5c1613d1048026b9e00a6ce753775cef87eb53fa
git-subtree-split: fa3ac0b61a27c8dd3296518a15891a6f9750cbf2
2019-06-11 19:00:46 +01:00

57 lines
1.6 KiB
Objective-C

#import "LegacyImageProcessors.h"
#import <LegacyComponents/LegacyComponents.h>
@implementation LegacyImageProcessors
+ (void)load {
[TGRemoteImageView registerImageUniversalProcessor:^UIImage *(NSString *name, UIImage *source) {
CGSize size = CGSizeZero;
int n = 7;
bool invalid = false;
for (int i = n; i < (int)name.length; i++) {
unichar c = [name characterAtIndex:i];
if (c == 'x')
{
if (i == n)
invalid = true;
else
{
size.width = [[name substringWithRange:NSMakeRange(n, i - n)] intValue];
n = i + 1;
}
break;
}
else if (c < '0' || c > '9')
{
invalid = true;
break;
}
}
if (!invalid)
{
for (int i = n; i < (int)name.length; i++)
{
unichar c = [name characterAtIndex:i];
if (c < '0' || c > '9')
{
invalid = true;
break;
}
else if (i == (int)name.length - 1)
{
size.height = [[name substringFromIndex:n] intValue];
}
}
}
if (!invalid)
{
return TGScaleAndRoundCornersWithOffsetAndFlags(source, size, CGPointZero, size, (int)size.width / 2, nil, false, nil, TGScaleImageScaleSharper);
}
return nil;
} withBaseName:@"circle"];
}
@end