forked from Blendman974/faceclaw
EvenHub compativility fixes: Z-order changes, different text color distribution, text containers scroll
This commit is contained in:
1 parent
c713815694
commit
10a9c85f27
22 files changed
+1545
-610
No files matched your search
@@ -14,4 +14,10 @@
|
||||
+ (NSData *)bgraPacket:(CGImageRef)image maxSize:(NSInteger)maxSize;
|
||||
/** bgraPacket of encoded image bytes (JPEG, PNG, ...); nil when undecodable. */
|
||||
+ (NSData *)bgraPacketFromImageData:(NSData *)data maxSize:(NSInteger)maxSize;
|
||||
/**
|
||||
* [widthLo, widthHi, heightLo, heightHi, RGBA...] of encoded image bytes at native size
|
||||
* (at most 4096 px a side), first frame only; nil when undecodable. CoreGraphics
|
||||
* premultiplies, so transparent pixels come out black. For the EvenHub image pipeline.
|
||||
*/
|
||||
+ (NSData *)rgbaPacketFromImageData:(NSData *)data;
|
||||
@end
|
||||
@@ -158,4 +158,26 @@
|
||||
CGImageRelease(image);
|
||||
return packet;
|
||||
}
|
||||
+ (NSData *)rgbaPacketFromImageData:(NSData *)data {
|
||||
if (!data.length) return nil;
|
||||
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
|
||||
if (!source) return nil;
|
||||
CGImageRef image = CGImageSourceCreateImageAtIndex(source, 0, NULL);
|
||||
CFRelease(source);
|
||||
if (!image) return nil;
|
||||
size_t width = CGImageGetWidth(image), height = CGImageGetHeight(image);
|
||||
if (width == 0 || height == 0 || width > 4096 || height > 4096) { CGImageRelease(image); return nil; }
|
||||
uint8_t dimensions[] = { width & 255, (width >> 8) & 255, height & 255, (height >> 8) & 255 };
|
||||
NSMutableData *packet = [NSMutableData dataWithBytes:dimensions length:4];
|
||||
[packet increaseLengthBy:width * height * 4];
|
||||
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
|
||||
CGContextRef context = CGBitmapContextCreate((uint8_t *)packet.mutableBytes + 4, width, height, 8, width * 4, space,
|
||||
kCGBitmapByteOrder32Big | (CGBitmapInfo)kCGImageAlphaPremultipliedLast);
|
||||
CGColorSpaceRelease(space);
|
||||
if (!context) { CGImageRelease(image); return nil; }
|
||||
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
|
||||
CGContextRelease(context);
|
||||
CGImageRelease(image);
|
||||
return packet;
|
||||
}
|
||||
@end
|
||||
Reference in new issue
Block a user