forked from Blendman974/faceclaw
Add EvenHub icon to phone preview screen
This commit is contained in:
1 parent
14d1f7f509
commit
ccbf523e9a
8 files changed
+100
-8
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
@interface FaceclawGraphics : NSObject
|
||||
+ (UIImage *)preview:(NSData *)gray width:(NSInteger)width height:(NSInteger)height green:(BOOL)green;
|
||||
/** A glasses icon as white-on-transparent (gray becomes alpha), for the dark header. */
|
||||
+ (UIImage *)whiteIcon:(NSData *)gray width:(NSInteger)width height:(NSInteger)height;
|
||||
+ (NSData *)renderSVG:(NSString *)svg size:(NSInteger)size;
|
||||
+ (NSData *)decodeImage:(NSData *)data width:(NSInteger)width height:(NSInteger)height;
|
||||
+ (NSData *)decodeImageFile:(NSString *)path maxWidth:(NSInteger)maxWidth maxHeight:(NSInteger)maxHeight;
|
||||
|
||||
@@ -76,6 +76,23 @@
|
||||
CGColorSpaceRelease(space);
|
||||
return result;
|
||||
}
|
||||
+ (UIImage *)whiteIcon:(NSData *)gray width:(NSInteger)width height:(NSInteger)height {
|
||||
if (width <= 0 || height <= 0 || gray.length != width * height) return nil;
|
||||
NSMutableData *rgba = [NSMutableData dataWithLength:width * height * 4];
|
||||
const uint8_t *src = gray.bytes;
|
||||
uint8_t *dst = rgba.mutableBytes;
|
||||
// Premultiplied white: every channel equals the alpha.
|
||||
for (NSInteger i = 0; i < width * height; i++) memset(dst + i * 4, src[i], 4);
|
||||
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
|
||||
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)rgba);
|
||||
CGImageRef image = CGImageCreate(width, height, 8, 32, width * 4, space,
|
||||
kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaPremultipliedLast, provider, NULL, false, kCGRenderingIntentDefault);
|
||||
UIImage *result = image ? [UIImage imageWithCGImage:image scale:1 orientation:UIImageOrientationUp] : nil;
|
||||
if (image) CGImageRelease(image);
|
||||
CGDataProviderRelease(provider);
|
||||
CGColorSpaceRelease(space);
|
||||
return result;
|
||||
}
|
||||
+ (NSData *)renderSVG:(NSString *)svg size:(NSInteger)size {
|
||||
if (size <= 0 || size > 1024) return nil;
|
||||
SVGKImage *image = [SVGKImage imageWithData:[svg dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
Reference in new issue
Block a user