diff --git a/doric-iOS/Pod/Classes/Plugin/DoricImageDecoderPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricImageDecoderPlugin.m index dfa1ac03..e18eaa86 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricImageDecoderPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricImageDecoderPlugin.m @@ -26,14 +26,14 @@ - (void)getImageInfo:(NSDictionary *)resource withPromise:(DoricPromise *)promis DoricResource *doricResource = [self.doricContext.driver.registry.loaderManager load:resource withContext:self.doricContext]; if (doricResource != nil) { DoricAsyncResult *asyncResult = [doricResource fetch]; - [asyncResult setResultCallback:^(id _Nonnull result) { + [asyncResult setResultCallback:^(id _Nonnull result) { UIImage *image = [UIImage imageWithData:result]; [promise resolve:@{ - @"width": @(image.size.width), - @"height": @(image.size.height) + @"width": @(image.size.width), + @"height": @(image.size.height) }]; }]; - [asyncResult setExceptionCallback:^(NSException * _Nonnull e) { + [asyncResult setExceptionCallback:^(NSException *_Nonnull e) { DoricLog(@"Cannot load resource %s, %s", resource.description, e.description); }]; } else { @@ -46,9 +46,9 @@ - (void)decodeToPixels:(NSDictionary *)resource withPromise:(DoricPromise *)prom DoricResource *doricResource = [self.doricContext.driver.registry.loaderManager load:resource withContext:self.doricContext]; if (doricResource != nil) { DoricAsyncResult *asyncResult = [doricResource fetch]; - [asyncResult setResultCallback:^(id _Nonnull result) { + [asyncResult setResultCallback:^(id _Nonnull result) { UIImage *image = [UIImage imageWithData:result]; - + CGImageRef imageRef = image.CGImage; NSUInteger iWidth = CGImageGetWidth(imageRef); NSUInteger iHeight = CGImageGetHeight(imageRef); @@ -56,20 +56,19 @@ - (void)decodeToPixels:(NSDictionary *)resource withPromise:(DoricPromise *)prom NSUInteger iBytesPerRow = iBytesPerPixel * iWidth; NSUInteger iBitsPerComponent = 8; unsigned char *imageBytes = malloc(iWidth * iHeight * iBytesPerPixel); - + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); - + CGContextRef context = CGBitmapContextCreate(imageBytes, iWidth, iHeight, iBitsPerComponent, iBytesPerRow, colorspace, kCGImageAlphaPremultipliedLast); CGRect rect = CGRectMake(0, 0, iWidth, iHeight); CGContextDrawImage(context, rect, imageRef); CGColorSpaceRelease(colorspace); CGContextRelease(context); - - NSData* data = [NSData dataWithBytes:(const void *)imageBytes length:sizeof(unsigned char) * iWidth * iHeight * iBytesPerPixel]; - + + NSData *data = [NSData dataWithBytesNoCopy:(void *) imageBytes length:sizeof(unsigned char) * iWidth * iHeight * iBytesPerPixel freeWhenDone:YES]; [promise resolve:data]; }]; - [asyncResult setExceptionCallback:^(NSException * _Nonnull e) { + [asyncResult setExceptionCallback:^(NSException *_Nonnull e) { DoricLog(@"Cannot load resource %s, %s", resource.description, e.description); }]; } else { diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 0d1f0db2..a29f6258 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -761,7 +761,7 @@ - (NSData *)getImagePixels { CGColorSpaceRelease(colorSpace); CGContextRelease(contextRef); - return [[NSData alloc] initWithBytesNoCopy:imageData length:width * height * bytesPerPixel]; + return [[NSData alloc] initWithBytesNoCopy:imageData length:width * height * bytesPerPixel freeWhenDone:YES]; } - (void)dealloc {