├── .gitignore ├── Classes ├── ImageToWebPDataTransformer.h ├── ImageToWebPDataTransformer.m ├── UIImage+WebP.h └── UIImage+WebP.m ├── LICENSE ├── Podfile ├── README.md ├── WebP-UIImage Example.xcodeproj └── project.pbxproj ├── WebP.framework ├── Headers │ ├── decode.h │ ├── encode.h │ └── types.h └── WebP └── iOS WebP Alpha Example ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── NEAppDelegate.h ├── NEAppDelegate.m ├── NEViewController.h ├── NEViewController.m ├── WebP-UIImage Example-Info.plist ├── WebP-UIImage Example-Prefix.pch ├── background0.webp ├── en.lproj ├── InfoPlist.strings ├── iPad.storyboard └── iPhone.storyboard ├── layer0.webp └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /Classes/ImageToWebPDataTransformer.h: -------------------------------------------------------------------------------- 1 | // ImageToWebPDataTransformer.h 2 | // 3 | // Created by Dmitry Shmidt on 01.08.13. 4 | // Copyright (c) 2013 Dmitry Shmidt. All rights reserved. 5 | 6 | #import 7 | 8 | @interface ImageToWebPDataTransformer : NSValueTransformer { 9 | } 10 | @end 11 | -------------------------------------------------------------------------------- /Classes/ImageToWebPDataTransformer.m: -------------------------------------------------------------------------------- 1 | // ImageToWebPDataTransformer.m 2 | // 3 | // Created by Dmitry Shmidt on 01.08.13. 4 | // Copyright (c) 2013 Dmitry Shmidt. All rights reserved. 5 | 6 | #import "ImageToWebPDataTransformer.h" 7 | #import "UIImage+WebP.h" 8 | @implementation ImageToWebPDataTransformer 9 | 10 | + (Class)transformedValueClass 11 | { 12 | return NSData.class; 13 | } 14 | 15 | + (BOOL)allowsReverseTransformation 16 | { 17 | return YES; 18 | } 19 | 20 | - (id)transformedValue:(id)value 21 | { 22 | if (value == nil) 23 | return nil; 24 | 25 | if ([value isKindOfClass:NSData.class]) 26 | return value; 27 | 28 | return [(UIImage *)value dataWebPWithQuality:75];//75 is default by Google 29 | } 30 | 31 | - (id)reverseTransformedValue:(id)value 32 | { 33 | return [UIImage imageWithWebPData:(NSData *)value]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Classes/UIImage+WebP.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.h 3 | // 4 | // Created by Gabriel Harrison 5 | // Much inspiration for code comes from Carson McDonald 6 | // his website is http://www.ioncannon.net 7 | // 8 | // Modified (encoding added) by Dmitry Shmidt, mail@shmidtlab.com 9 | 10 | #import 11 | #import 12 | @interface UIImage (WebP) 13 | 14 | - (NSData *)dataWebPWithQuality:(float)quality;//quality = 0..100 15 | + (UIImage*)imageWithWebPAtPath:(NSString *)filePath; 16 | 17 | + (UIImage *)imageWithWebPData:(NSData *)imgData; 18 | @property (nonatomic, readonly) NSData *dataWebPLossless; 19 | 20 | - (BOOL)writeWebPToDocumentsWithFileName:(NSString *)filename quality:(float)quality; 21 | - (BOOL)writeWebPLosslessToDocumentsWithFileName:(NSString *)filename; 22 | @end 23 | -------------------------------------------------------------------------------- /Classes/UIImage+WebP.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.m 3 | // 4 | // Created by Gabriel Harrison 5 | // Much inspiration for code comes from Carson McDonald 6 | // his website is http://www.ioncannon.net 7 | // 8 | // Modified (encoding added) by Dmitry Shmidt, mail@shmidtlab.com 9 | #define kWebPLossless 146 10 | #import "UIImage+WebP.h" 11 | 12 | /** 13 | * This gets called when the UIImage gets collected and frees the 14 | * underlying image. 15 | */ 16 | static void free_image_data(void *info, const void *data, size_t size) 17 | { 18 | free((void *)data); 19 | } 20 | 21 | @implementation UIImage (WebP) 22 | 23 | /** 24 | * The imageFromWebP function loads a file with the specified filePath. It 25 | * makes the assumption that the file exists within the main bundle. If the 26 | * main screen is running at a scale greater than 1.0, it will automatically 27 | * attempt to append @2x to the file name as per the convention that Apple 28 | * follows (as I understand it). 29 | * 30 | * If it does change the name from pic.webp to pic@2x.webp and there is no 31 | * file by that name, it will revert and try to load the lo-res image name 32 | * instead. 33 | * 34 | * If for any reason we end up without a path after asking the main bundle for 35 | * the file name with the supplied extension, nil will be returned. 36 | * 37 | * @param filePath a path, relative to the main bundle, where the file resides 38 | * @return a valid UIImage or nil if there was a problem locating the image. 39 | */ 40 | + (UIImage *)imageWithWebPAtPath:(NSString *)filePath { 41 | NSString *path = NULL; 42 | NSString *name = [filePath stringByDeletingPathExtension]; 43 | NSString *ext = [filePath pathExtension]; 44 | 45 | BOOL isRetina = [[UIScreen mainScreen] respondsToSelector:@selector(scale)] 46 | == YES && [[UIScreen mainScreen] scale] > 1.f; 47 | 48 | if (isRetina) { 49 | NSString *at2XName = [NSString stringWithFormat:@"%@@2x", name]; 50 | BOOL at2XExists = [[NSFileManager defaultManager] 51 | fileExistsAtPath: [NSString stringWithFormat:@"%@.%@", 52 | at2XName, ext]]; 53 | 54 | if (at2XExists) { 55 | name = at2XName; 56 | } 57 | } 58 | 59 | // Now, finally, get the path relative to the bundle 60 | path = [[NSBundle mainBundle] pathForResource:name ofType:ext]; 61 | 62 | // Return nil if we don't have a path 63 | if (!path) { 64 | return nil; 65 | } 66 | 67 | // Find the path of the selected WebP image in the bundle and read 68 | // it into memory. 69 | NSData *imgData = [NSData dataWithContentsOfFile:path]; 70 | 71 | return [self imageWithWebPData:imgData]; 72 | } 73 | + (UIImage *)imageWithWebPData:(NSData *)imgData{ 74 | int rc = WebPGetDecoderVersion(); 75 | NSLog(@"WebP decoder version: %d", rc); 76 | // Get width and height of the selected WebP image 77 | int width = 0, height = 0; 78 | WebPGetInfo(imgData.bytes, imgData.length, &width, &height); 79 | //NSLog(@"Image Width: %d Height: %d", width, height); 80 | 81 | // Decode the WebP image data into a RGBA value array 82 | uint8_t *data = WebPDecodeRGBA([imgData bytes], [imgData length], &width, 83 | &height); 84 | 85 | // Construct a UIImage from the decoded RGBA value array 86 | CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, data, 87 | width * height * 4, free_image_data); 88 | CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 89 | CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | 90 | kCGImageAlphaLast; 91 | CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 92 | CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, 93 | colorSpaceRef, bitmapInfo, provider, NULL, YES, renderingIntent); 94 | UIImage *result = [UIImage imageWithCGImage:imageRef]; 95 | 96 | // Clean up 97 | CGImageRelease(imageRef); 98 | CGColorSpaceRelease(colorSpaceRef); 99 | CGDataProviderRelease(provider); 100 | 101 | 102 | return result; 103 | } 104 | 105 | - (NSData *)dataWebPWithQuality:(float)quality{ 106 | int rc = WebPGetEncoderVersion(); 107 | NSLog(@"WebP encoder version: %d", rc); 108 | 109 | CGImageRef imageRef = self.CGImage; 110 | CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef); 111 | if (CGColorSpaceGetModel(colorSpace) != kCGColorSpaceModelRGB) { 112 | NSLog(@"Sorry, we need RGB"); 113 | } 114 | CGDataProviderRef dataProvider = CGImageGetDataProvider(imageRef); 115 | CFDataRef imageData = CGDataProviderCopyData(dataProvider); 116 | const UInt8 *rawData = CFDataGetBytePtr(imageData); 117 | 118 | size_t width = CGImageGetWidth(imageRef); 119 | size_t height = CGImageGetHeight(imageRef); 120 | uint8_t *output; 121 | NSUInteger stride = CGImageGetBytesPerRow(imageRef); 122 | size_t ret_size; 123 | 124 | if (quality == kWebPLossless) { 125 | ret_size = WebPEncodeLosslessRGB(rawData, width, height, stride, &output); 126 | }else ret_size = WebPEncodeRGBA(rawData, width, height, stride, quality, &output); 127 | 128 | if (ret_size == 0) { 129 | NSLog(@"Oops, no data"); 130 | } 131 | CFRelease(imageData); 132 | CGColorSpaceRelease(colorSpace); 133 | NSData *data = [NSData dataWithBytes:(const void *)output length:ret_size]; 134 | 135 | return data; 136 | } 137 | 138 | - (NSData *)dataWebPLossless{ 139 | 140 | return [self dataWebPWithQuality:kWebPLossless]; 141 | } 142 | 143 | - (BOOL)writeWebPToDocumentsWithFileName:(NSString *)filename quality:(float)quality{ 144 | NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@.webp",filename]]; 145 | 146 | NSData *imgData = [self dataWebPWithQuality:quality]; 147 | 148 | return [imgData writeToFile:filePath atomically:YES]; 149 | } 150 | - (BOOL)writeWebPLosslessToDocumentsWithFileName:(NSString *)filename{ 151 | 152 | return [self writeWebPToDocumentsWithFileName:filename quality:kWebPLossless]; 153 | } 154 | @end 155 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Dmitry Shmidt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '5.0' 2 | pod 'libwebp' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WebP-UIImage 2 | ============ 3 | 4 | UIImage category to work with WebP image files in iOS. 5 | 6 | ## Installation ## 7 | 8 | Drag and drop the Classes folder and WebP.framework into your project. 9 | 10 | ## Usage ## 11 | 12 | Getting started with WebP-UIImage is simple. 13 | Import framework #import "UIImage+WebP.h" and call following methods: 14 | 15 | ```objc 16 | - (NSData *)dataWebPWithQuality:(float)quality;//quality = 0..100 17 | + (UIImage*)imageWithWebPAtPath:(NSString *)filePath; 18 | 19 | + (UIImage *)imageWithWebPData:(NSData *)imgData; 20 | @property (nonatomic, readonly) NSData *dataWebPLossless; 21 | 22 | - (BOOL)writeWebPToDocumentsWithFileName:(NSString *)filename quality:(float)quality; 23 | - (BOOL)writeWebPLosslessToDocumentsWithFileName:(NSString *)filename; 24 | ``` 25 | 26 | ## Bonus ## 27 | I made also an NSValueTransformer subclass called ImageToWebPDataTransformer. 28 | You can use it in CoreData to store images with less sizes than jpeg. 29 | I use 75 quality value as it is default Google value. 30 | 31 | ## Thanks ## 32 | The project is heavily based on [nyteshade/iOSWebPWithAlphaExample](https://github.com/nyteshade/iOSWebPWithAlphaExample) 33 | 34 | ## License ## 35 | MIT 36 | 37 | ## Tests ## 38 | No speed/size tests were done. You can make your own and commit it here. 39 | 40 | -------------------------------------------------------------------------------- /WebP-UIImage Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00B6846B16F53E60002EA9EE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B6846A16F53E60002EA9EE /* UIKit.framework */; }; 11 | 00B6846D16F53E60002EA9EE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B6846C16F53E60002EA9EE /* Foundation.framework */; }; 12 | 00B6846F16F53E60002EA9EE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00B6846E16F53E60002EA9EE /* CoreGraphics.framework */; }; 13 | 00B6847516F53E60002EA9EE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 00B6847316F53E60002EA9EE /* InfoPlist.strings */; }; 14 | 00B6847716F53E60002EA9EE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 00B6847616F53E60002EA9EE /* main.m */; }; 15 | 00B6847B16F53E60002EA9EE /* NEAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00B6847A16F53E60002EA9EE /* NEAppDelegate.m */; }; 16 | 00B6847D16F53E60002EA9EE /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 00B6847C16F53E60002EA9EE /* Default.png */; }; 17 | 00B6847F16F53E61002EA9EE /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 00B6847E16F53E61002EA9EE /* Default@2x.png */; }; 18 | 00B6848116F53E61002EA9EE /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 00B6848016F53E61002EA9EE /* Default-568h@2x.png */; }; 19 | 00B6848A16F53E61002EA9EE /* NEViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 00B6848916F53E61002EA9EE /* NEViewController.m */; }; 20 | 00B6849B16F548C1002EA9EE /* UIImage+WebP.m in Sources */ = {isa = PBXBuildFile; fileRef = 00B6849516F53E81002EA9EE /* UIImage+WebP.m */; }; 21 | 00B6849E16F549EB002EA9EE /* background0.webp in Resources */ = {isa = PBXBuildFile; fileRef = 00B6849C16F5496E002EA9EE /* background0.webp */; }; 22 | 00B6849F16F549ED002EA9EE /* layer0.webp in Resources */ = {isa = PBXBuildFile; fileRef = 00B6849D16F5496E002EA9EE /* layer0.webp */; }; 23 | D04F119E17ABA17D0012B476 /* ImageToWebPDataTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = D04F119D17ABA17D0012B476 /* ImageToWebPDataTransformer.m */; }; 24 | D04F11A417ABA3D50012B476 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D04F11A017ABA3D50012B476 /* iPad.storyboard */; }; 25 | D04F11A517ABA3D50012B476 /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D04F11A217ABA3D50012B476 /* iPhone.storyboard */; }; 26 | D04F11A717ABEEDA0012B476 /* WebP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D04F11A617ABEEDA0012B476 /* WebP.framework */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 00B6846716F53E60002EA9EE /* WebP-UIImage Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "WebP-UIImage Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 00B6846A16F53E60002EA9EE /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 32 | 00B6846C16F53E60002EA9EE /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 33 | 00B6846E16F53E60002EA9EE /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 34 | 00B6847216F53E60002EA9EE /* WebP-UIImage Example-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WebP-UIImage Example-Info.plist"; sourceTree = ""; }; 35 | 00B6847416F53E60002EA9EE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 36 | 00B6847616F53E60002EA9EE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 37 | 00B6847816F53E60002EA9EE /* WebP-UIImage Example-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WebP-UIImage Example-Prefix.pch"; sourceTree = ""; }; 38 | 00B6847916F53E60002EA9EE /* NEAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NEAppDelegate.h; sourceTree = ""; }; 39 | 00B6847A16F53E60002EA9EE /* NEAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NEAppDelegate.m; sourceTree = ""; }; 40 | 00B6847C16F53E60002EA9EE /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = ""; }; 41 | 00B6847E16F53E61002EA9EE /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = ""; }; 42 | 00B6848016F53E61002EA9EE /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 43 | 00B6848816F53E61002EA9EE /* NEViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NEViewController.h; sourceTree = ""; }; 44 | 00B6848916F53E61002EA9EE /* NEViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NEViewController.m; sourceTree = ""; }; 45 | 00B6849416F53E81002EA9EE /* UIImage+WebP.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImage+WebP.h"; sourceTree = ""; }; 46 | 00B6849516F53E81002EA9EE /* UIImage+WebP.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImage+WebP.m"; sourceTree = ""; }; 47 | 00B6849C16F5496E002EA9EE /* background0.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = background0.webp; sourceTree = ""; }; 48 | 00B6849D16F5496E002EA9EE /* layer0.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = layer0.webp; sourceTree = ""; }; 49 | D04F119C17ABA17D0012B476 /* ImageToWebPDataTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageToWebPDataTransformer.h; sourceTree = ""; }; 50 | D04F119D17ABA17D0012B476 /* ImageToWebPDataTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageToWebPDataTransformer.m; sourceTree = ""; }; 51 | D04F11A117ABA3D50012B476 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/iPad.storyboard; sourceTree = ""; }; 52 | D04F11A317ABA3D50012B476 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/iPhone.storyboard; sourceTree = ""; }; 53 | D04F11A617ABEEDA0012B476 /* WebP.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebP.framework; sourceTree = ""; }; 54 | /* End PBXFileReference section */ 55 | 56 | /* Begin PBXFrameworksBuildPhase section */ 57 | 00B6846416F53E60002EA9EE /* Frameworks */ = { 58 | isa = PBXFrameworksBuildPhase; 59 | buildActionMask = 2147483647; 60 | files = ( 61 | 00B6846B16F53E60002EA9EE /* UIKit.framework in Frameworks */, 62 | 00B6846D16F53E60002EA9EE /* Foundation.framework in Frameworks */, 63 | 00B6846F16F53E60002EA9EE /* CoreGraphics.framework in Frameworks */, 64 | D04F11A717ABEEDA0012B476 /* WebP.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | 00B6845E16F53E60002EA9EE = { 72 | isa = PBXGroup; 73 | children = ( 74 | D04F11A617ABEEDA0012B476 /* WebP.framework */, 75 | 00B6847016F53E60002EA9EE /* iOS WebP Alpha Example */, 76 | 00B6846916F53E60002EA9EE /* Frameworks */, 77 | 00B6846816F53E60002EA9EE /* Products */, 78 | ); 79 | sourceTree = ""; 80 | }; 81 | 00B6846816F53E60002EA9EE /* Products */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 00B6846716F53E60002EA9EE /* WebP-UIImage Example.app */, 85 | ); 86 | name = Products; 87 | sourceTree = ""; 88 | }; 89 | 00B6846916F53E60002EA9EE /* Frameworks */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 00B6846A16F53E60002EA9EE /* UIKit.framework */, 93 | 00B6846C16F53E60002EA9EE /* Foundation.framework */, 94 | 00B6846E16F53E60002EA9EE /* CoreGraphics.framework */, 95 | ); 96 | name = Frameworks; 97 | sourceTree = ""; 98 | }; 99 | 00B6847016F53E60002EA9EE /* iOS WebP Alpha Example */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | 00B6847916F53E60002EA9EE /* NEAppDelegate.h */, 103 | 00B6847A16F53E60002EA9EE /* NEAppDelegate.m */, 104 | D04F11A017ABA3D50012B476 /* iPad.storyboard */, 105 | D04F11A217ABA3D50012B476 /* iPhone.storyboard */, 106 | D04F119F17ABA22B0012B476 /* Classes */, 107 | 00B6848816F53E61002EA9EE /* NEViewController.h */, 108 | 00B6848916F53E61002EA9EE /* NEViewController.m */, 109 | 00B6847116F53E60002EA9EE /* Supporting Files */, 110 | ); 111 | path = "iOS WebP Alpha Example"; 112 | sourceTree = ""; 113 | }; 114 | 00B6847116F53E60002EA9EE /* Supporting Files */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 00B6849C16F5496E002EA9EE /* background0.webp */, 118 | 00B6849D16F5496E002EA9EE /* layer0.webp */, 119 | 00B6847216F53E60002EA9EE /* WebP-UIImage Example-Info.plist */, 120 | 00B6847316F53E60002EA9EE /* InfoPlist.strings */, 121 | 00B6847616F53E60002EA9EE /* main.m */, 122 | 00B6847816F53E60002EA9EE /* WebP-UIImage Example-Prefix.pch */, 123 | 00B6847C16F53E60002EA9EE /* Default.png */, 124 | 00B6847E16F53E61002EA9EE /* Default@2x.png */, 125 | 00B6848016F53E61002EA9EE /* Default-568h@2x.png */, 126 | ); 127 | name = "Supporting Files"; 128 | sourceTree = ""; 129 | }; 130 | D04F119F17ABA22B0012B476 /* Classes */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 00B6849416F53E81002EA9EE /* UIImage+WebP.h */, 134 | 00B6849516F53E81002EA9EE /* UIImage+WebP.m */, 135 | D04F119C17ABA17D0012B476 /* ImageToWebPDataTransformer.h */, 136 | D04F119D17ABA17D0012B476 /* ImageToWebPDataTransformer.m */, 137 | ); 138 | name = Classes; 139 | path = ../Classes; 140 | sourceTree = ""; 141 | }; 142 | /* End PBXGroup section */ 143 | 144 | /* Begin PBXNativeTarget section */ 145 | 00B6846616F53E60002EA9EE /* WebP-UIImage Example */ = { 146 | isa = PBXNativeTarget; 147 | buildConfigurationList = 00B6848D16F53E61002EA9EE /* Build configuration list for PBXNativeTarget "WebP-UIImage Example" */; 148 | buildPhases = ( 149 | 00B6846316F53E60002EA9EE /* Sources */, 150 | 00B6846416F53E60002EA9EE /* Frameworks */, 151 | 00B6846516F53E60002EA9EE /* Resources */, 152 | ); 153 | buildRules = ( 154 | ); 155 | dependencies = ( 156 | ); 157 | name = "WebP-UIImage Example"; 158 | productName = "iOS WebP Alpha Example"; 159 | productReference = 00B6846716F53E60002EA9EE /* WebP-UIImage Example.app */; 160 | productType = "com.apple.product-type.application"; 161 | }; 162 | /* End PBXNativeTarget section */ 163 | 164 | /* Begin PBXProject section */ 165 | 00B6845F16F53E60002EA9EE /* Project object */ = { 166 | isa = PBXProject; 167 | attributes = { 168 | CLASSPREFIX = NE; 169 | LastUpgradeCheck = 0460; 170 | ORGANIZATIONNAME = "Nyteshade Enterprises"; 171 | }; 172 | buildConfigurationList = 00B6846216F53E60002EA9EE /* Build configuration list for PBXProject "WebP-UIImage Example" */; 173 | compatibilityVersion = "Xcode 3.2"; 174 | developmentRegion = English; 175 | hasScannedForEncodings = 0; 176 | knownRegions = ( 177 | en, 178 | ); 179 | mainGroup = 00B6845E16F53E60002EA9EE; 180 | productRefGroup = 00B6846816F53E60002EA9EE /* Products */; 181 | projectDirPath = ""; 182 | projectRoot = ""; 183 | targets = ( 184 | 00B6846616F53E60002EA9EE /* WebP-UIImage Example */, 185 | ); 186 | }; 187 | /* End PBXProject section */ 188 | 189 | /* Begin PBXResourcesBuildPhase section */ 190 | 00B6846516F53E60002EA9EE /* Resources */ = { 191 | isa = PBXResourcesBuildPhase; 192 | buildActionMask = 2147483647; 193 | files = ( 194 | 00B6847516F53E60002EA9EE /* InfoPlist.strings in Resources */, 195 | 00B6847D16F53E60002EA9EE /* Default.png in Resources */, 196 | 00B6847F16F53E61002EA9EE /* Default@2x.png in Resources */, 197 | 00B6848116F53E61002EA9EE /* Default-568h@2x.png in Resources */, 198 | 00B6849F16F549ED002EA9EE /* layer0.webp in Resources */, 199 | 00B6849E16F549EB002EA9EE /* background0.webp in Resources */, 200 | D04F11A417ABA3D50012B476 /* iPad.storyboard in Resources */, 201 | D04F11A517ABA3D50012B476 /* iPhone.storyboard in Resources */, 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | /* End PBXResourcesBuildPhase section */ 206 | 207 | /* Begin PBXSourcesBuildPhase section */ 208 | 00B6846316F53E60002EA9EE /* Sources */ = { 209 | isa = PBXSourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | 00B6847716F53E60002EA9EE /* main.m in Sources */, 213 | 00B6847B16F53E60002EA9EE /* NEAppDelegate.m in Sources */, 214 | 00B6848A16F53E61002EA9EE /* NEViewController.m in Sources */, 215 | 00B6849B16F548C1002EA9EE /* UIImage+WebP.m in Sources */, 216 | D04F119E17ABA17D0012B476 /* ImageToWebPDataTransformer.m in Sources */, 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXSourcesBuildPhase section */ 221 | 222 | /* Begin PBXVariantGroup section */ 223 | 00B6847316F53E60002EA9EE /* InfoPlist.strings */ = { 224 | isa = PBXVariantGroup; 225 | children = ( 226 | 00B6847416F53E60002EA9EE /* en */, 227 | ); 228 | name = InfoPlist.strings; 229 | sourceTree = ""; 230 | }; 231 | D04F11A017ABA3D50012B476 /* iPad.storyboard */ = { 232 | isa = PBXVariantGroup; 233 | children = ( 234 | D04F11A117ABA3D50012B476 /* en */, 235 | ); 236 | name = iPad.storyboard; 237 | sourceTree = ""; 238 | }; 239 | D04F11A217ABA3D50012B476 /* iPhone.storyboard */ = { 240 | isa = PBXVariantGroup; 241 | children = ( 242 | D04F11A317ABA3D50012B476 /* en */, 243 | ); 244 | name = iPhone.storyboard; 245 | sourceTree = ""; 246 | }; 247 | /* End PBXVariantGroup section */ 248 | 249 | /* Begin XCBuildConfiguration section */ 250 | 00B6848B16F53E61002EA9EE /* Debug */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | ALWAYS_SEARCH_USER_PATHS = NO; 254 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 255 | CLANG_CXX_LIBRARY = "libc++"; 256 | CLANG_ENABLE_OBJC_ARC = YES; 257 | CLANG_WARN_CONSTANT_CONVERSION = YES; 258 | CLANG_WARN_EMPTY_BODY = YES; 259 | CLANG_WARN_ENUM_CONVERSION = YES; 260 | CLANG_WARN_INT_CONVERSION = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | GCC_C_LANGUAGE_STANDARD = gnu99; 265 | GCC_DYNAMIC_NO_PIC = NO; 266 | GCC_OPTIMIZATION_LEVEL = 0; 267 | GCC_PREPROCESSOR_DEFINITIONS = ( 268 | "DEBUG=1", 269 | "$(inherited)", 270 | ); 271 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 272 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 273 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 6.1; 276 | ONLY_ACTIVE_ARCH = YES; 277 | SDKROOT = iphoneos; 278 | TARGETED_DEVICE_FAMILY = "1,2"; 279 | }; 280 | name = Debug; 281 | }; 282 | 00B6848C16F53E61002EA9EE /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ALWAYS_SEARCH_USER_PATHS = NO; 286 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 287 | CLANG_CXX_LIBRARY = "libc++"; 288 | CLANG_ENABLE_OBJC_ARC = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_EMPTY_BODY = YES; 291 | CLANG_WARN_ENUM_CONVERSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 295 | COPY_PHASE_STRIP = YES; 296 | GCC_C_LANGUAGE_STANDARD = gnu99; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 298 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | IPHONEOS_DEPLOYMENT_TARGET = 6.1; 301 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 302 | SDKROOT = iphoneos; 303 | TARGETED_DEVICE_FAMILY = "1,2"; 304 | VALIDATE_PRODUCT = YES; 305 | }; 306 | name = Release; 307 | }; 308 | 00B6848E16F53E61002EA9EE /* Debug */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | FRAMEWORK_SEARCH_PATHS = ( 312 | "$(inherited)", 313 | "\"$(SRCROOT)\"", 314 | ); 315 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 316 | GCC_PREFIX_HEADER = "iOS WebP Alpha Example/WebP-UIImage Example-Prefix.pch"; 317 | INFOPLIST_FILE = "iOS WebP Alpha Example/WebP-UIImage Example-Info.plist"; 318 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 319 | PRODUCT_NAME = "WebP-UIImage Example"; 320 | TARGETED_DEVICE_FAMILY = "1,2"; 321 | WRAPPER_EXTENSION = app; 322 | }; 323 | name = Debug; 324 | }; 325 | 00B6848F16F53E61002EA9EE /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | FRAMEWORK_SEARCH_PATHS = ( 329 | "$(inherited)", 330 | "\"$(SRCROOT)\"", 331 | ); 332 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 333 | GCC_PREFIX_HEADER = "iOS WebP Alpha Example/WebP-UIImage Example-Prefix.pch"; 334 | INFOPLIST_FILE = "iOS WebP Alpha Example/WebP-UIImage Example-Info.plist"; 335 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 336 | PRODUCT_NAME = "WebP-UIImage Example"; 337 | TARGETED_DEVICE_FAMILY = "1,2"; 338 | WRAPPER_EXTENSION = app; 339 | }; 340 | name = Release; 341 | }; 342 | /* End XCBuildConfiguration section */ 343 | 344 | /* Begin XCConfigurationList section */ 345 | 00B6846216F53E60002EA9EE /* Build configuration list for PBXProject "WebP-UIImage Example" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | 00B6848B16F53E61002EA9EE /* Debug */, 349 | 00B6848C16F53E61002EA9EE /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | 00B6848D16F53E61002EA9EE /* Build configuration list for PBXNativeTarget "WebP-UIImage Example" */ = { 355 | isa = XCConfigurationList; 356 | buildConfigurations = ( 357 | 00B6848E16F53E61002EA9EE /* Debug */, 358 | 00B6848F16F53E61002EA9EE /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | /* End XCConfigurationList section */ 364 | }; 365 | rootObject = 00B6845F16F53E60002EA9EE /* Project object */; 366 | } 367 | -------------------------------------------------------------------------------- /WebP.framework/Headers/decode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010 Google Inc. All Rights Reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the COPYING file in the root of the source 5 | // tree. An additional intellectual property rights grant can be found 6 | // in the file PATENTS. All contributing project authors may 7 | // be found in the AUTHORS file in the root of the source tree. 8 | // ----------------------------------------------------------------------------- 9 | // 10 | // Main decoding functions for WebP images. 11 | // 12 | // Author: Skal (pascal.massimino@gmail.com) 13 | 14 | #ifndef WEBP_WEBP_DECODE_H_ 15 | #define WEBP_WEBP_DECODE_H_ 16 | 17 | #include "./types.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define WEBP_DECODER_ABI_VERSION 0x0203 // MAJOR(8b) + MINOR(8b) 24 | 25 | // Note: forward declaring enumerations is not allowed in (strict) C and C++, 26 | // the types are left here for reference. 27 | // typedef enum VP8StatusCode VP8StatusCode; 28 | // typedef enum WEBP_CSP_MODE WEBP_CSP_MODE; 29 | typedef struct WebPRGBABuffer WebPRGBABuffer; 30 | typedef struct WebPYUVABuffer WebPYUVABuffer; 31 | typedef struct WebPDecBuffer WebPDecBuffer; 32 | typedef struct WebPIDecoder WebPIDecoder; 33 | typedef struct WebPBitstreamFeatures WebPBitstreamFeatures; 34 | typedef struct WebPDecoderOptions WebPDecoderOptions; 35 | typedef struct WebPDecoderConfig WebPDecoderConfig; 36 | 37 | // Return the decoder's version number, packed in hexadecimal using 8bits for 38 | // each of major/minor/revision. E.g: v2.5.7 is 0x020507. 39 | WEBP_EXTERN(int) WebPGetDecoderVersion(void); 40 | 41 | // Retrieve basic header information: width, height. 42 | // This function will also validate the header and return 0 in 43 | // case of formatting error. 44 | // Pointers 'width' and 'height' can be passed NULL if deemed irrelevant. 45 | WEBP_EXTERN(int) WebPGetInfo(const uint8_t* data, size_t data_size, 46 | int* width, int* height); 47 | 48 | // Decodes WebP images pointed to by 'data' and returns RGBA samples, along 49 | // with the dimensions in *width and *height. The ordering of samples in 50 | // memory is R, G, B, A, R, G, B, A... in scan order (endian-independent). 51 | // The returned pointer should be deleted calling free(). 52 | // Returns NULL in case of error. 53 | WEBP_EXTERN(uint8_t*) WebPDecodeRGBA(const uint8_t* data, size_t data_size, 54 | int* width, int* height); 55 | 56 | // Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data. 57 | WEBP_EXTERN(uint8_t*) WebPDecodeARGB(const uint8_t* data, size_t data_size, 58 | int* width, int* height); 59 | 60 | // Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data. 61 | WEBP_EXTERN(uint8_t*) WebPDecodeBGRA(const uint8_t* data, size_t data_size, 62 | int* width, int* height); 63 | 64 | // Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data. 65 | // If the bitstream contains transparency, it is ignored. 66 | WEBP_EXTERN(uint8_t*) WebPDecodeRGB(const uint8_t* data, size_t data_size, 67 | int* width, int* height); 68 | 69 | // Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data. 70 | WEBP_EXTERN(uint8_t*) WebPDecodeBGR(const uint8_t* data, size_t data_size, 71 | int* width, int* height); 72 | 73 | 74 | // Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer 75 | // returned is the Y samples buffer. Upon return, *u and *v will point to 76 | // the U and V chroma data. These U and V buffers need NOT be free()'d, 77 | // unlike the returned Y luma one. The dimension of the U and V planes 78 | // are both (*width + 1) / 2 and (*height + 1)/ 2. 79 | // Upon return, the Y buffer has a stride returned as '*stride', while U and V 80 | // have a common stride returned as '*uv_stride'. 81 | // Return NULL in case of error. 82 | // (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr 83 | WEBP_EXTERN(uint8_t*) WebPDecodeYUV(const uint8_t* data, size_t data_size, 84 | int* width, int* height, 85 | uint8_t** u, uint8_t** v, 86 | int* stride, int* uv_stride); 87 | 88 | // These five functions are variants of the above ones, that decode the image 89 | // directly into a pre-allocated buffer 'output_buffer'. The maximum storage 90 | // available in this buffer is indicated by 'output_buffer_size'. If this 91 | // storage is not sufficient (or an error occurred), NULL is returned. 92 | // Otherwise, output_buffer is returned, for convenience. 93 | // The parameter 'output_stride' specifies the distance (in bytes) 94 | // between scanlines. Hence, output_buffer_size is expected to be at least 95 | // output_stride x picture-height. 96 | WEBP_EXTERN(uint8_t*) WebPDecodeRGBAInto( 97 | const uint8_t* data, size_t data_size, 98 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 99 | WEBP_EXTERN(uint8_t*) WebPDecodeARGBInto( 100 | const uint8_t* data, size_t data_size, 101 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 102 | WEBP_EXTERN(uint8_t*) WebPDecodeBGRAInto( 103 | const uint8_t* data, size_t data_size, 104 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 105 | 106 | // RGB and BGR variants. Here too the transparency information, if present, 107 | // will be dropped and ignored. 108 | WEBP_EXTERN(uint8_t*) WebPDecodeRGBInto( 109 | const uint8_t* data, size_t data_size, 110 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 111 | WEBP_EXTERN(uint8_t*) WebPDecodeBGRInto( 112 | const uint8_t* data, size_t data_size, 113 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 114 | 115 | // WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly 116 | // into pre-allocated luma/chroma plane buffers. This function requires the 117 | // strides to be passed: one for the luma plane and one for each of the 118 | // chroma ones. The size of each plane buffer is passed as 'luma_size', 119 | // 'u_size' and 'v_size' respectively. 120 | // Pointer to the luma plane ('*luma') is returned or NULL if an error occurred 121 | // during decoding (or because some buffers were found to be too small). 122 | WEBP_EXTERN(uint8_t*) WebPDecodeYUVInto( 123 | const uint8_t* data, size_t data_size, 124 | uint8_t* luma, size_t luma_size, int luma_stride, 125 | uint8_t* u, size_t u_size, int u_stride, 126 | uint8_t* v, size_t v_size, int v_stride); 127 | 128 | //------------------------------------------------------------------------------ 129 | // Output colorspaces and buffer 130 | 131 | // Colorspaces 132 | // Note: the naming describes the byte-ordering of packed samples in memory. 133 | // For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,... 134 | // Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels. 135 | // RGBA-4444 and RGB-565 colorspaces are represented by following byte-order: 136 | // RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ... 137 | // RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ... 138 | // In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for 139 | // these two modes: 140 | // RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ... 141 | // RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ... 142 | 143 | typedef enum WEBP_CSP_MODE { 144 | MODE_RGB = 0, MODE_RGBA = 1, 145 | MODE_BGR = 2, MODE_BGRA = 3, 146 | MODE_ARGB = 4, MODE_RGBA_4444 = 5, 147 | MODE_RGB_565 = 6, 148 | // RGB-premultiplied transparent modes (alpha value is preserved) 149 | MODE_rgbA = 7, 150 | MODE_bgrA = 8, 151 | MODE_Argb = 9, 152 | MODE_rgbA_4444 = 10, 153 | // YUV modes must come after RGB ones. 154 | MODE_YUV = 11, MODE_YUVA = 12, // yuv 4:2:0 155 | MODE_LAST = 13 156 | } WEBP_CSP_MODE; 157 | 158 | // Some useful macros: 159 | static WEBP_INLINE int WebPIsPremultipliedMode(WEBP_CSP_MODE mode) { 160 | return (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || 161 | mode == MODE_rgbA_4444); 162 | } 163 | 164 | static WEBP_INLINE int WebPIsAlphaMode(WEBP_CSP_MODE mode) { 165 | return (mode == MODE_RGBA || mode == MODE_BGRA || mode == MODE_ARGB || 166 | mode == MODE_RGBA_4444 || mode == MODE_YUVA || 167 | WebPIsPremultipliedMode(mode)); 168 | } 169 | 170 | static WEBP_INLINE int WebPIsRGBMode(WEBP_CSP_MODE mode) { 171 | return (mode < MODE_YUV); 172 | } 173 | 174 | //------------------------------------------------------------------------------ 175 | // WebPDecBuffer: Generic structure for describing the output sample buffer. 176 | 177 | struct WebPRGBABuffer { // view as RGBA 178 | uint8_t* rgba; // pointer to RGBA samples 179 | int stride; // stride in bytes from one scanline to the next. 180 | size_t size; // total size of the *rgba buffer. 181 | }; 182 | 183 | struct WebPYUVABuffer { // view as YUVA 184 | uint8_t* y, *u, *v, *a; // pointer to luma, chroma U/V, alpha samples 185 | int y_stride; // luma stride 186 | int u_stride, v_stride; // chroma strides 187 | int a_stride; // alpha stride 188 | size_t y_size; // luma plane size 189 | size_t u_size, v_size; // chroma planes size 190 | size_t a_size; // alpha-plane size 191 | }; 192 | 193 | // Output buffer 194 | struct WebPDecBuffer { 195 | WEBP_CSP_MODE colorspace; // Colorspace. 196 | int width, height; // Dimensions. 197 | int is_external_memory; // If true, 'internal_memory' pointer is not used. 198 | union { 199 | WebPRGBABuffer RGBA; 200 | WebPYUVABuffer YUVA; 201 | } u; // Nameless union of buffer parameters. 202 | uint32_t pad[4]; // padding for later use 203 | 204 | uint8_t* private_memory; // Internally allocated memory (only when 205 | // is_external_memory is false). Should not be used 206 | // externally, but accessed via the buffer union. 207 | }; 208 | 209 | // Internal, version-checked, entry point 210 | WEBP_EXTERN(int) WebPInitDecBufferInternal(WebPDecBuffer*, int); 211 | 212 | // Initialize the structure as empty. Must be called before any other use. 213 | // Returns false in case of version mismatch 214 | static WEBP_INLINE int WebPInitDecBuffer(WebPDecBuffer* buffer) { 215 | return WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION); 216 | } 217 | 218 | // Free any memory associated with the buffer. Must always be called last. 219 | // Note: doesn't free the 'buffer' structure itself. 220 | WEBP_EXTERN(void) WebPFreeDecBuffer(WebPDecBuffer* buffer); 221 | 222 | //------------------------------------------------------------------------------ 223 | // Enumeration of the status codes 224 | 225 | typedef enum VP8StatusCode { 226 | VP8_STATUS_OK = 0, 227 | VP8_STATUS_OUT_OF_MEMORY, 228 | VP8_STATUS_INVALID_PARAM, 229 | VP8_STATUS_BITSTREAM_ERROR, 230 | VP8_STATUS_UNSUPPORTED_FEATURE, 231 | VP8_STATUS_SUSPENDED, 232 | VP8_STATUS_USER_ABORT, 233 | VP8_STATUS_NOT_ENOUGH_DATA 234 | } VP8StatusCode; 235 | 236 | //------------------------------------------------------------------------------ 237 | // Incremental decoding 238 | // 239 | // This API allows streamlined decoding of partial data. 240 | // Picture can be incrementally decoded as data become available thanks to the 241 | // WebPIDecoder object. This object can be left in a SUSPENDED state if the 242 | // picture is only partially decoded, pending additional input. 243 | // Code example: 244 | // 245 | // WebPInitDecBuffer(&buffer); 246 | // buffer.colorspace = mode; 247 | // ... 248 | // WebPIDecoder* idec = WebPINewDecoder(&buffer); 249 | // while (has_more_data) { 250 | // // ... (get additional data) 251 | // status = WebPIAppend(idec, new_data, new_data_size); 252 | // if (status != VP8_STATUS_SUSPENDED || 253 | // break; 254 | // } 255 | // 256 | // // The above call decodes the current available buffer. 257 | // // Part of the image can now be refreshed by calling to 258 | // // WebPIDecGetRGB()/WebPIDecGetYUVA() etc. 259 | // } 260 | // WebPIDelete(idec); 261 | 262 | // Creates a new incremental decoder with the supplied buffer parameter. 263 | // This output_buffer can be passed NULL, in which case a default output buffer 264 | // is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer' 265 | // is kept, which means that the lifespan of 'output_buffer' must be larger than 266 | // that of the returned WebPIDecoder object. 267 | // The supplied 'output_buffer' content MUST NOT be changed between calls to 268 | // WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is 269 | // set to 1. In such a case, it is allowed to modify the pointers, size and 270 | // stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain 271 | // within valid bounds. 272 | // All other fields of WebPDecBuffer MUST remain constant between calls. 273 | // Returns NULL if the allocation failed. 274 | WEBP_EXTERN(WebPIDecoder*) WebPINewDecoder(WebPDecBuffer* output_buffer); 275 | 276 | // This function allocates and initializes an incremental-decoder object, which 277 | // will output the RGB/A samples specified by 'csp' into a preallocated 278 | // buffer 'output_buffer'. The size of this buffer is at least 279 | // 'output_buffer_size' and the stride (distance in bytes between two scanlines) 280 | // is specified by 'output_stride'. 281 | // Additionally, output_buffer can be passed NULL in which case the output 282 | // buffer will be allocated automatically when the decoding starts. The 283 | // colorspace 'csp' is taken into account for allocating this buffer. All other 284 | // parameters are ignored. 285 | // Returns NULL if the allocation failed, or if some parameters are invalid. 286 | WEBP_EXTERN(WebPIDecoder*) WebPINewRGB( 287 | WEBP_CSP_MODE csp, 288 | uint8_t* output_buffer, size_t output_buffer_size, int output_stride); 289 | 290 | // This function allocates and initializes an incremental-decoder object, which 291 | // will output the raw luma/chroma samples into a preallocated planes if 292 | // supplied. The luma plane is specified by its pointer 'luma', its size 293 | // 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane 294 | // is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v 295 | // plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer 296 | // can be pass NULL in case one is not interested in the transparency plane. 297 | // Conversely, 'luma' can be passed NULL if no preallocated planes are supplied. 298 | // In this case, the output buffer will be automatically allocated (using 299 | // MODE_YUVA) when decoding starts. All parameters are then ignored. 300 | // Returns NULL if the allocation failed or if a parameter is invalid. 301 | WEBP_EXTERN(WebPIDecoder*) WebPINewYUVA( 302 | uint8_t* luma, size_t luma_size, int luma_stride, 303 | uint8_t* u, size_t u_size, int u_stride, 304 | uint8_t* v, size_t v_size, int v_stride, 305 | uint8_t* a, size_t a_size, int a_stride); 306 | 307 | // Deprecated version of the above, without the alpha plane. 308 | // Kept for backward compatibility. 309 | WEBP_EXTERN(WebPIDecoder*) WebPINewYUV( 310 | uint8_t* luma, size_t luma_size, int luma_stride, 311 | uint8_t* u, size_t u_size, int u_stride, 312 | uint8_t* v, size_t v_size, int v_stride); 313 | 314 | // Deletes the WebPIDecoder object and associated memory. Must always be called 315 | // if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded. 316 | WEBP_EXTERN(void) WebPIDelete(WebPIDecoder* idec); 317 | 318 | // Copies and decodes the next available data. Returns VP8_STATUS_OK when 319 | // the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more 320 | // data is expected. Returns error in other cases. 321 | WEBP_EXTERN(VP8StatusCode) WebPIAppend( 322 | WebPIDecoder* idec, const uint8_t* data, size_t data_size); 323 | 324 | // A variant of the above function to be used when data buffer contains 325 | // partial data from the beginning. In this case data buffer is not copied 326 | // to the internal memory. 327 | // Note that the value of the 'data' pointer can change between calls to 328 | // WebPIUpdate, for instance when the data buffer is resized to fit larger data. 329 | WEBP_EXTERN(VP8StatusCode) WebPIUpdate( 330 | WebPIDecoder* idec, const uint8_t* data, size_t data_size); 331 | 332 | // Returns the RGB/A image decoded so far. Returns NULL if output params 333 | // are not initialized yet. The RGB/A output type corresponds to the colorspace 334 | // specified during call to WebPINewDecoder() or WebPINewRGB(). 335 | // *last_y is the index of last decoded row in raster scan order. Some pointers 336 | // (*last_y, *width etc.) can be NULL if corresponding information is not 337 | // needed. 338 | WEBP_EXTERN(uint8_t*) WebPIDecGetRGB( 339 | const WebPIDecoder* idec, int* last_y, 340 | int* width, int* height, int* stride); 341 | 342 | // Same as above function to get a YUVA image. Returns pointer to the luma 343 | // plane or NULL in case of error. If there is no alpha information 344 | // the alpha pointer '*a' will be returned NULL. 345 | WEBP_EXTERN(uint8_t*) WebPIDecGetYUVA( 346 | const WebPIDecoder* idec, int* last_y, 347 | uint8_t** u, uint8_t** v, uint8_t** a, 348 | int* width, int* height, int* stride, int* uv_stride, int* a_stride); 349 | 350 | // Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the 351 | // alpha information (if present). Kept for backward compatibility. 352 | static WEBP_INLINE uint8_t* WebPIDecGetYUV( 353 | const WebPIDecoder* idec, int* last_y, uint8_t** u, uint8_t** v, 354 | int* width, int* height, int* stride, int* uv_stride) { 355 | return WebPIDecGetYUVA(idec, last_y, u, v, NULL, width, height, 356 | stride, uv_stride, NULL); 357 | } 358 | 359 | // Generic call to retrieve information about the displayable area. 360 | // If non NULL, the left/right/width/height pointers are filled with the visible 361 | // rectangular area so far. 362 | // Returns NULL in case the incremental decoder object is in an invalid state. 363 | // Otherwise returns the pointer to the internal representation. This structure 364 | // is read-only, tied to WebPIDecoder's lifespan and should not be modified. 365 | WEBP_EXTERN(const WebPDecBuffer*) WebPIDecodedArea( 366 | const WebPIDecoder* idec, int* left, int* top, int* width, int* height); 367 | 368 | //------------------------------------------------------------------------------ 369 | // Advanced decoding parametrization 370 | // 371 | // Code sample for using the advanced decoding API 372 | /* 373 | // A) Init a configuration object 374 | WebPDecoderConfig config; 375 | CHECK(WebPInitDecoderConfig(&config)); 376 | 377 | // B) optional: retrieve the bitstream's features. 378 | CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); 379 | 380 | // C) Adjust 'config', if needed 381 | config.no_fancy_upsampling = 1; 382 | config.output.colorspace = MODE_BGRA; 383 | // etc. 384 | 385 | // Note that you can also make config.output point to an externally 386 | // supplied memory buffer, provided it's big enough to store the decoded 387 | // picture. Otherwise, config.output will just be used to allocate memory 388 | // and store the decoded picture. 389 | 390 | // D) Decode! 391 | CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); 392 | 393 | // E) Decoded image is now in config.output (and config.output.u.RGBA) 394 | 395 | // F) Reclaim memory allocated in config's object. It's safe to call 396 | // this function even if the memory is external and wasn't allocated 397 | // by WebPDecode(). 398 | WebPFreeDecBuffer(&config.output); 399 | */ 400 | 401 | // Features gathered from the bitstream 402 | struct WebPBitstreamFeatures { 403 | int width; // Width in pixels, as read from the bitstream. 404 | int height; // Height in pixels, as read from the bitstream. 405 | int has_alpha; // True if the bitstream contains an alpha channel. 406 | int has_animation; // True if the bitstream is an animation. 407 | int format; // 0 = undefined (/mixed), 1 = lossy, 2 = lossless 408 | 409 | // Unused for now: 410 | int no_incremental_decoding; // if true, using incremental decoding is not 411 | // recommended. 412 | int rotate; // TODO(later) 413 | int uv_sampling; // should be 0 for now. TODO(later) 414 | uint32_t pad[2]; // padding for later use 415 | }; 416 | 417 | // Internal, version-checked, entry point 418 | WEBP_EXTERN(VP8StatusCode) WebPGetFeaturesInternal( 419 | const uint8_t*, size_t, WebPBitstreamFeatures*, int); 420 | 421 | // Retrieve features from the bitstream. The *features structure is filled 422 | // with information gathered from the bitstream. 423 | // Returns VP8_STATUS_OK when the features are successfully retrieved. Returns 424 | // VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the 425 | // features from headers. Returns error in other cases. 426 | static WEBP_INLINE VP8StatusCode WebPGetFeatures( 427 | const uint8_t* data, size_t data_size, 428 | WebPBitstreamFeatures* features) { 429 | return WebPGetFeaturesInternal(data, data_size, features, 430 | WEBP_DECODER_ABI_VERSION); 431 | } 432 | 433 | // Decoding options 434 | struct WebPDecoderOptions { 435 | int bypass_filtering; // if true, skip the in-loop filtering 436 | int no_fancy_upsampling; // if true, use faster pointwise upsampler 437 | int use_cropping; // if true, cropping is applied _first_ 438 | int crop_left, crop_top; // top-left position for cropping. 439 | // Will be snapped to even values. 440 | int crop_width, crop_height; // dimension of the cropping area 441 | int use_scaling; // if true, scaling is applied _afterward_ 442 | int scaled_width, scaled_height; // final resolution 443 | int use_threads; // if true, use multi-threaded decoding 444 | int dithering_strength; // dithering strength (0=Off, 100=full) 445 | 446 | // Unused for now: 447 | int force_rotation; // forced rotation (to be applied _last_) 448 | int no_enhancement; // if true, discard enhancement layer 449 | uint32_t pad[5]; // padding for later use 450 | }; 451 | 452 | // Main object storing the configuration for advanced decoding. 453 | struct WebPDecoderConfig { 454 | WebPBitstreamFeatures input; // Immutable bitstream features (optional) 455 | WebPDecBuffer output; // Output buffer (can point to external mem) 456 | WebPDecoderOptions options; // Decoding options 457 | }; 458 | 459 | // Internal, version-checked, entry point 460 | WEBP_EXTERN(int) WebPInitDecoderConfigInternal(WebPDecoderConfig*, int); 461 | 462 | // Initialize the configuration as empty. This function must always be 463 | // called first, unless WebPGetFeatures() is to be called. 464 | // Returns false in case of mismatched version. 465 | static WEBP_INLINE int WebPInitDecoderConfig(WebPDecoderConfig* config) { 466 | return WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION); 467 | } 468 | 469 | // Instantiate a new incremental decoder object with the requested 470 | // configuration. The bitstream can be passed using 'data' and 'data_size' 471 | // parameter, in which case the features will be parsed and stored into 472 | // config->input. Otherwise, 'data' can be NULL and no parsing will occur. 473 | // Note that 'config' can be NULL too, in which case a default configuration 474 | // is used. 475 | // The return WebPIDecoder object must always be deleted calling WebPIDelete(). 476 | // Returns NULL in case of error (and config->status will then reflect 477 | // the error condition). 478 | WEBP_EXTERN(WebPIDecoder*) WebPIDecode(const uint8_t* data, size_t data_size, 479 | WebPDecoderConfig* config); 480 | 481 | // Non-incremental version. This version decodes the full data at once, taking 482 | // 'config' into account. Returns decoding status (which should be VP8_STATUS_OK 483 | // if the decoding was successful). 484 | WEBP_EXTERN(VP8StatusCode) WebPDecode(const uint8_t* data, size_t data_size, 485 | WebPDecoderConfig* config); 486 | 487 | #ifdef __cplusplus 488 | } // extern "C" 489 | #endif 490 | 491 | #endif /* WEBP_WEBP_DECODE_H_ */ 492 | -------------------------------------------------------------------------------- /WebP.framework/Headers/encode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Google Inc. All Rights Reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the COPYING file in the root of the source 5 | // tree. An additional intellectual property rights grant can be found 6 | // in the file PATENTS. All contributing project authors may 7 | // be found in the AUTHORS file in the root of the source tree. 8 | // ----------------------------------------------------------------------------- 9 | // 10 | // WebP encoder: main interface 11 | // 12 | // Author: Skal (pascal.massimino@gmail.com) 13 | 14 | #ifndef WEBP_WEBP_ENCODE_H_ 15 | #define WEBP_WEBP_ENCODE_H_ 16 | 17 | #include "./types.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #define WEBP_ENCODER_ABI_VERSION 0x0202 // MAJOR(8b) + MINOR(8b) 24 | 25 | // Note: forward declaring enumerations is not allowed in (strict) C and C++, 26 | // the types are left here for reference. 27 | // typedef enum WebPImageHint WebPImageHint; 28 | // typedef enum WebPEncCSP WebPEncCSP; 29 | // typedef enum WebPPreset WebPPreset; 30 | // typedef enum WebPEncodingError WebPEncodingError; 31 | typedef struct WebPConfig WebPConfig; 32 | typedef struct WebPPicture WebPPicture; // main structure for I/O 33 | typedef struct WebPAuxStats WebPAuxStats; 34 | typedef struct WebPMemoryWriter WebPMemoryWriter; 35 | 36 | // Return the encoder's version number, packed in hexadecimal using 8bits for 37 | // each of major/minor/revision. E.g: v2.5.7 is 0x020507. 38 | WEBP_EXTERN(int) WebPGetEncoderVersion(void); 39 | 40 | //------------------------------------------------------------------------------ 41 | // One-stop-shop call! No questions asked: 42 | 43 | // Returns the size of the compressed data (pointed to by *output), or 0 if 44 | // an error occurred. The compressed data must be released by the caller 45 | // using the call 'free(*output)'. 46 | // These functions compress using the lossy format, and the quality_factor 47 | // can go from 0 (smaller output, lower quality) to 100 (best quality, 48 | // larger output). 49 | WEBP_EXTERN(size_t) WebPEncodeRGB(const uint8_t* rgb, 50 | int width, int height, int stride, 51 | float quality_factor, uint8_t** output); 52 | WEBP_EXTERN(size_t) WebPEncodeBGR(const uint8_t* bgr, 53 | int width, int height, int stride, 54 | float quality_factor, uint8_t** output); 55 | WEBP_EXTERN(size_t) WebPEncodeRGBA(const uint8_t* rgba, 56 | int width, int height, int stride, 57 | float quality_factor, uint8_t** output); 58 | WEBP_EXTERN(size_t) WebPEncodeBGRA(const uint8_t* bgra, 59 | int width, int height, int stride, 60 | float quality_factor, uint8_t** output); 61 | 62 | // These functions are the equivalent of the above, but compressing in a 63 | // lossless manner. Files are usually larger than lossy format, but will 64 | // not suffer any compression loss. 65 | WEBP_EXTERN(size_t) WebPEncodeLosslessRGB(const uint8_t* rgb, 66 | int width, int height, int stride, 67 | uint8_t** output); 68 | WEBP_EXTERN(size_t) WebPEncodeLosslessBGR(const uint8_t* bgr, 69 | int width, int height, int stride, 70 | uint8_t** output); 71 | WEBP_EXTERN(size_t) WebPEncodeLosslessRGBA(const uint8_t* rgba, 72 | int width, int height, int stride, 73 | uint8_t** output); 74 | WEBP_EXTERN(size_t) WebPEncodeLosslessBGRA(const uint8_t* bgra, 75 | int width, int height, int stride, 76 | uint8_t** output); 77 | 78 | //------------------------------------------------------------------------------ 79 | // Coding parameters 80 | 81 | // Image characteristics hint for the underlying encoder. 82 | typedef enum WebPImageHint { 83 | WEBP_HINT_DEFAULT = 0, // default preset. 84 | WEBP_HINT_PICTURE, // digital picture, like portrait, inner shot 85 | WEBP_HINT_PHOTO, // outdoor photograph, with natural lighting 86 | WEBP_HINT_GRAPH, // Discrete tone image (graph, map-tile etc). 87 | WEBP_HINT_LAST 88 | } WebPImageHint; 89 | 90 | // Compression parameters. 91 | struct WebPConfig { 92 | int lossless; // Lossless encoding (0=lossy(default), 1=lossless). 93 | float quality; // between 0 (smallest file) and 100 (biggest) 94 | int method; // quality/speed trade-off (0=fast, 6=slower-better) 95 | 96 | WebPImageHint image_hint; // Hint for image type (lossless only for now). 97 | 98 | // Parameters related to lossy compression only: 99 | int target_size; // if non-zero, set the desired target size in bytes. 100 | // Takes precedence over the 'compression' parameter. 101 | float target_PSNR; // if non-zero, specifies the minimal distortion to 102 | // try to achieve. Takes precedence over target_size. 103 | int segments; // maximum number of segments to use, in [1..4] 104 | int sns_strength; // Spatial Noise Shaping. 0=off, 100=maximum. 105 | int filter_strength; // range: [0 = off .. 100 = strongest] 106 | int filter_sharpness; // range: [0 = off .. 7 = least sharp] 107 | int filter_type; // filtering type: 0 = simple, 1 = strong (only used 108 | // if filter_strength > 0 or autofilter > 0) 109 | int autofilter; // Auto adjust filter's strength [0 = off, 1 = on] 110 | int alpha_compression; // Algorithm for encoding the alpha plane (0 = none, 111 | // 1 = compressed with WebP lossless). Default is 1. 112 | int alpha_filtering; // Predictive filtering method for alpha plane. 113 | // 0: none, 1: fast, 2: best. Default if 1. 114 | int alpha_quality; // Between 0 (smallest size) and 100 (lossless). 115 | // Default is 100. 116 | int pass; // number of entropy-analysis passes (in [1..10]). 117 | 118 | int show_compressed; // if true, export the compressed picture back. 119 | // In-loop filtering is not applied. 120 | int preprocessing; // preprocessing filter: 121 | // 0=none, 1=segment-smooth, 2=pseudo-random dithering 122 | int partitions; // log2(number of token partitions) in [0..3]. Default 123 | // is set to 0 for easier progressive decoding. 124 | int partition_limit; // quality degradation allowed to fit the 512k limit 125 | // on prediction modes coding (0: no degradation, 126 | // 100: maximum possible degradation). 127 | int emulate_jpeg_size; // If true, compression parameters will be remapped 128 | // to better match the expected output size from 129 | // JPEG compression. Generally, the output size will 130 | // be similar but the degradation will be lower. 131 | int thread_level; // If non-zero, try and use multi-threaded encoding. 132 | int low_memory; // If set, reduce memory usage (but increase CPU use). 133 | 134 | uint32_t pad[5]; // padding for later use 135 | }; 136 | 137 | // Enumerate some predefined settings for WebPConfig, depending on the type 138 | // of source picture. These presets are used when calling WebPConfigPreset(). 139 | typedef enum WebPPreset { 140 | WEBP_PRESET_DEFAULT = 0, // default preset. 141 | WEBP_PRESET_PICTURE, // digital picture, like portrait, inner shot 142 | WEBP_PRESET_PHOTO, // outdoor photograph, with natural lighting 143 | WEBP_PRESET_DRAWING, // hand or line drawing, with high-contrast details 144 | WEBP_PRESET_ICON, // small-sized colorful images 145 | WEBP_PRESET_TEXT // text-like 146 | } WebPPreset; 147 | 148 | // Internal, version-checked, entry point 149 | WEBP_EXTERN(int) WebPConfigInitInternal(WebPConfig*, WebPPreset, float, int); 150 | 151 | // Should always be called, to initialize a fresh WebPConfig structure before 152 | // modification. Returns false in case of version mismatch. WebPConfigInit() 153 | // must have succeeded before using the 'config' object. 154 | // Note that the default values are lossless=0 and quality=75. 155 | static WEBP_INLINE int WebPConfigInit(WebPConfig* config) { 156 | return WebPConfigInitInternal(config, WEBP_PRESET_DEFAULT, 75.f, 157 | WEBP_ENCODER_ABI_VERSION); 158 | } 159 | 160 | // This function will initialize the configuration according to a predefined 161 | // set of parameters (referred to by 'preset') and a given quality factor. 162 | // This function can be called as a replacement to WebPConfigInit(). Will 163 | // return false in case of error. 164 | static WEBP_INLINE int WebPConfigPreset(WebPConfig* config, 165 | WebPPreset preset, float quality) { 166 | return WebPConfigInitInternal(config, preset, quality, 167 | WEBP_ENCODER_ABI_VERSION); 168 | } 169 | 170 | // Returns true if 'config' is non-NULL and all configuration parameters are 171 | // within their valid ranges. 172 | WEBP_EXTERN(int) WebPValidateConfig(const WebPConfig* config); 173 | 174 | //------------------------------------------------------------------------------ 175 | // Input / Output 176 | // Structure for storing auxiliary statistics (mostly for lossy encoding). 177 | 178 | struct WebPAuxStats { 179 | int coded_size; // final size 180 | 181 | float PSNR[5]; // peak-signal-to-noise ratio for Y/U/V/All/Alpha 182 | int block_count[3]; // number of intra4/intra16/skipped macroblocks 183 | int header_bytes[2]; // approximate number of bytes spent for header 184 | // and mode-partition #0 185 | int residual_bytes[3][4]; // approximate number of bytes spent for 186 | // DC/AC/uv coefficients for each (0..3) segments. 187 | int segment_size[4]; // number of macroblocks in each segments 188 | int segment_quant[4]; // quantizer values for each segments 189 | int segment_level[4]; // filtering strength for each segments [0..63] 190 | 191 | int alpha_data_size; // size of the transparency data 192 | int layer_data_size; // size of the enhancement layer data 193 | 194 | // lossless encoder statistics 195 | uint32_t lossless_features; // bit0:predictor bit1:cross-color transform 196 | // bit2:subtract-green bit3:color indexing 197 | int histogram_bits; // number of precision bits of histogram 198 | int transform_bits; // precision bits for transform 199 | int cache_bits; // number of bits for color cache lookup 200 | int palette_size; // number of color in palette, if used 201 | int lossless_size; // final lossless size 202 | 203 | uint32_t pad[4]; // padding for later use 204 | }; 205 | 206 | // Signature for output function. Should return true if writing was successful. 207 | // data/data_size is the segment of data to write, and 'picture' is for 208 | // reference (and so one can make use of picture->custom_ptr). 209 | typedef int (*WebPWriterFunction)(const uint8_t* data, size_t data_size, 210 | const WebPPicture* picture); 211 | 212 | // WebPMemoryWrite: a special WebPWriterFunction that writes to memory using 213 | // the following WebPMemoryWriter object (to be set as a custom_ptr). 214 | struct WebPMemoryWriter { 215 | uint8_t* mem; // final buffer (of size 'max_size', larger than 'size'). 216 | size_t size; // final size 217 | size_t max_size; // total capacity 218 | uint32_t pad[1]; // padding for later use 219 | }; 220 | 221 | // The following must be called first before any use. 222 | WEBP_EXTERN(void) WebPMemoryWriterInit(WebPMemoryWriter* writer); 223 | 224 | // The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon 225 | // completion, writer.mem and writer.size will hold the coded data. 226 | // writer.mem must be freed using the call 'free(writer.mem)'. 227 | WEBP_EXTERN(int) WebPMemoryWrite(const uint8_t* data, size_t data_size, 228 | const WebPPicture* picture); 229 | 230 | // Progress hook, called from time to time to report progress. It can return 231 | // false to request an abort of the encoding process, or true otherwise if 232 | // everything is OK. 233 | typedef int (*WebPProgressHook)(int percent, const WebPPicture* picture); 234 | 235 | // Color spaces. 236 | typedef enum WebPEncCSP { 237 | // chroma sampling 238 | WEBP_YUV420 = 0, // 4:2:0 239 | WEBP_YUV422 = 1, // 4:2:2 240 | WEBP_YUV444 = 2, // 4:4:4 241 | WEBP_YUV400 = 3, // grayscale 242 | WEBP_CSP_UV_MASK = 3, // bit-mask to get the UV sampling factors 243 | // alpha channel variants 244 | WEBP_YUV420A = 4, 245 | WEBP_YUV422A = 5, 246 | WEBP_YUV444A = 6, 247 | WEBP_YUV400A = 7, // grayscale + alpha 248 | WEBP_CSP_ALPHA_BIT = 4 // bit that is set if alpha is present 249 | } WebPEncCSP; 250 | 251 | // Encoding error conditions. 252 | typedef enum WebPEncodingError { 253 | VP8_ENC_OK = 0, 254 | VP8_ENC_ERROR_OUT_OF_MEMORY, // memory error allocating objects 255 | VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY, // memory error while flushing bits 256 | VP8_ENC_ERROR_NULL_PARAMETER, // a pointer parameter is NULL 257 | VP8_ENC_ERROR_INVALID_CONFIGURATION, // configuration is invalid 258 | VP8_ENC_ERROR_BAD_DIMENSION, // picture has invalid width/height 259 | VP8_ENC_ERROR_PARTITION0_OVERFLOW, // partition is bigger than 512k 260 | VP8_ENC_ERROR_PARTITION_OVERFLOW, // partition is bigger than 16M 261 | VP8_ENC_ERROR_BAD_WRITE, // error while flushing bytes 262 | VP8_ENC_ERROR_FILE_TOO_BIG, // file is bigger than 4G 263 | VP8_ENC_ERROR_USER_ABORT, // abort request by user 264 | VP8_ENC_ERROR_LAST // list terminator. always last. 265 | } WebPEncodingError; 266 | 267 | // maximum width/height allowed (inclusive), in pixels 268 | #define WEBP_MAX_DIMENSION 16383 269 | 270 | // Main exchange structure (input samples, output bytes, statistics) 271 | struct WebPPicture { 272 | // INPUT 273 | ////////////// 274 | // Main flag for encoder selecting between ARGB or YUV input. 275 | // It is recommended to use ARGB input (*argb, argb_stride) for lossless 276 | // compression, and YUV input (*y, *u, *v, etc.) for lossy compression 277 | // since these are the respective native colorspace for these formats. 278 | int use_argb; 279 | 280 | // YUV input (mostly used for input to lossy compression) 281 | WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr). 282 | int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION) 283 | uint8_t *y, *u, *v; // pointers to luma/chroma planes. 284 | int y_stride, uv_stride; // luma/chroma strides. 285 | uint8_t* a; // pointer to the alpha plane 286 | int a_stride; // stride of the alpha plane 287 | uint32_t pad1[2]; // padding for later use 288 | 289 | // ARGB input (mostly used for input to lossless compression) 290 | uint32_t* argb; // Pointer to argb (32 bit) plane. 291 | int argb_stride; // This is stride in pixels units, not bytes. 292 | uint32_t pad2[3]; // padding for later use 293 | 294 | // OUTPUT 295 | /////////////// 296 | // Byte-emission hook, to store compressed bytes as they are ready. 297 | WebPWriterFunction writer; // can be NULL 298 | void* custom_ptr; // can be used by the writer. 299 | 300 | // map for extra information (only for lossy compression mode) 301 | int extra_info_type; // 1: intra type, 2: segment, 3: quant 302 | // 4: intra-16 prediction mode, 303 | // 5: chroma prediction mode, 304 | // 6: bit cost, 7: distortion 305 | uint8_t* extra_info; // if not NULL, points to an array of size 306 | // ((width + 15) / 16) * ((height + 15) / 16) that 307 | // will be filled with a macroblock map, depending 308 | // on extra_info_type. 309 | 310 | // STATS AND REPORTS 311 | /////////////////////////// 312 | // Pointer to side statistics (updated only if not NULL) 313 | WebPAuxStats* stats; 314 | 315 | // Error code for the latest error encountered during encoding 316 | WebPEncodingError error_code; 317 | 318 | // If not NULL, report progress during encoding. 319 | WebPProgressHook progress_hook; 320 | 321 | void* user_data; // this field is free to be set to any value and 322 | // used during callbacks (like progress-report e.g.). 323 | 324 | uint32_t pad3[3]; // padding for later use 325 | 326 | // Unused for now: original samples (for non-YUV420 modes) 327 | uint8_t *u0, *v0; 328 | int uv0_stride; 329 | 330 | uint32_t pad4[7]; // padding for later use 331 | 332 | // PRIVATE FIELDS 333 | //////////////////// 334 | void* memory_; // row chunk of memory for yuva planes 335 | void* memory_argb_; // and for argb too. 336 | void* pad5[2]; // padding for later use 337 | }; 338 | 339 | // Internal, version-checked, entry point 340 | WEBP_EXTERN(int) WebPPictureInitInternal(WebPPicture*, int); 341 | 342 | // Should always be called, to initialize the structure. Returns false in case 343 | // of version mismatch. WebPPictureInit() must have succeeded before using the 344 | // 'picture' object. 345 | // Note that, by default, use_argb is false and colorspace is WEBP_YUV420. 346 | static WEBP_INLINE int WebPPictureInit(WebPPicture* picture) { 347 | return WebPPictureInitInternal(picture, WEBP_ENCODER_ABI_VERSION); 348 | } 349 | 350 | //------------------------------------------------------------------------------ 351 | // WebPPicture utils 352 | 353 | // Convenience allocation / deallocation based on picture->width/height: 354 | // Allocate y/u/v buffers as per colorspace/width/height specification. 355 | // Note! This function will free the previous buffer if needed. 356 | // Returns false in case of memory error. 357 | WEBP_EXTERN(int) WebPPictureAlloc(WebPPicture* picture); 358 | 359 | // Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*(). 360 | // Note that this function does _not_ free the memory used by the 'picture' 361 | // object itself. 362 | // Besides memory (which is reclaimed) all other fields of 'picture' are 363 | // preserved. 364 | WEBP_EXTERN(void) WebPPictureFree(WebPPicture* picture); 365 | 366 | // Copy the pixels of *src into *dst, using WebPPictureAlloc. Upon return, *dst 367 | // will fully own the copied pixels (this is not a view). The 'dst' picture need 368 | // not be initialized as its content is overwritten. 369 | // Returns false in case of memory allocation error. 370 | WEBP_EXTERN(int) WebPPictureCopy(const WebPPicture* src, WebPPicture* dst); 371 | 372 | // Compute PSNR, SSIM or LSIM distortion metric between two pictures. 373 | // Result is in dB, stores in result[] in the Y/U/V/Alpha/All order. 374 | // Returns false in case of error (src and ref don't have same dimension, ...) 375 | // Warning: this function is rather CPU-intensive. 376 | WEBP_EXTERN(int) WebPPictureDistortion( 377 | const WebPPicture* src, const WebPPicture* ref, 378 | int metric_type, // 0 = PSNR, 1 = SSIM, 2 = LSIM 379 | float result[5]); 380 | 381 | // self-crops a picture to the rectangle defined by top/left/width/height. 382 | // Returns false in case of memory allocation error, or if the rectangle is 383 | // outside of the source picture. 384 | // The rectangle for the view is defined by the top-left corner pixel 385 | // coordinates (left, top) as well as its width and height. This rectangle 386 | // must be fully be comprised inside the 'src' source picture. If the source 387 | // picture uses the YUV420 colorspace, the top and left coordinates will be 388 | // snapped to even values. 389 | WEBP_EXTERN(int) WebPPictureCrop(WebPPicture* picture, 390 | int left, int top, int width, int height); 391 | 392 | // Extracts a view from 'src' picture into 'dst'. The rectangle for the view 393 | // is defined by the top-left corner pixel coordinates (left, top) as well 394 | // as its width and height. This rectangle must be fully be comprised inside 395 | // the 'src' source picture. If the source picture uses the YUV420 colorspace, 396 | // the top and left coordinates will be snapped to even values. 397 | // Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed 398 | // ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so, 399 | // the original dimension will be lost). Picture 'dst' need not be initialized 400 | // with WebPPictureInit() if it is different from 'src', since its content will 401 | // be overwritten. 402 | // Returns false in case of memory allocation error or invalid parameters. 403 | WEBP_EXTERN(int) WebPPictureView(const WebPPicture* src, 404 | int left, int top, int width, int height, 405 | WebPPicture* dst); 406 | 407 | // Returns true if the 'picture' is actually a view and therefore does 408 | // not own the memory for pixels. 409 | WEBP_EXTERN(int) WebPPictureIsView(const WebPPicture* picture); 410 | 411 | // Rescale a picture to new dimension width x height. 412 | // Now gamma correction is applied. 413 | // Returns false in case of error (invalid parameter or insufficient memory). 414 | WEBP_EXTERN(int) WebPPictureRescale(WebPPicture* pic, int width, int height); 415 | 416 | // Colorspace conversion function to import RGB samples. 417 | // Previous buffer will be free'd, if any. 418 | // *rgb buffer should have a size of at least height * rgb_stride. 419 | // Returns false in case of memory error. 420 | WEBP_EXTERN(int) WebPPictureImportRGB( 421 | WebPPicture* picture, const uint8_t* rgb, int rgb_stride); 422 | // Same, but for RGBA buffer. 423 | WEBP_EXTERN(int) WebPPictureImportRGBA( 424 | WebPPicture* picture, const uint8_t* rgba, int rgba_stride); 425 | // Same, but for RGBA buffer. Imports the RGB direct from the 32-bit format 426 | // input buffer ignoring the alpha channel. Avoids needing to copy the data 427 | // to a temporary 24-bit RGB buffer to import the RGB only. 428 | WEBP_EXTERN(int) WebPPictureImportRGBX( 429 | WebPPicture* picture, const uint8_t* rgbx, int rgbx_stride); 430 | 431 | // Variants of the above, but taking BGR(A|X) input. 432 | WEBP_EXTERN(int) WebPPictureImportBGR( 433 | WebPPicture* picture, const uint8_t* bgr, int bgr_stride); 434 | WEBP_EXTERN(int) WebPPictureImportBGRA( 435 | WebPPicture* picture, const uint8_t* bgra, int bgra_stride); 436 | WEBP_EXTERN(int) WebPPictureImportBGRX( 437 | WebPPicture* picture, const uint8_t* bgrx, int bgrx_stride); 438 | 439 | // Converts picture->argb data to the YUVA format specified by 'colorspace'. 440 | // Upon return, picture->use_argb is set to false. The presence of real 441 | // non-opaque transparent values is detected, and 'colorspace' will be 442 | // adjusted accordingly. Note that this method is lossy. 443 | // Returns false in case of error. 444 | WEBP_EXTERN(int) WebPPictureARGBToYUVA(WebPPicture* picture, 445 | WebPEncCSP colorspace); 446 | 447 | // Same as WebPPictureARGBToYUVA(), but the conversion is done using 448 | // pseudo-random dithering with a strength 'dithering' between 449 | // 0.0 (no dithering) and 1.0 (maximum dithering). This is useful 450 | // for photographic picture. 451 | WEBP_EXTERN(int) WebPPictureARGBToYUVADithered( 452 | WebPPicture* picture, WebPEncCSP colorspace, float dithering); 453 | 454 | // Converts picture->yuv to picture->argb and sets picture->use_argb to true. 455 | // The input format must be YUV_420 or YUV_420A. 456 | // Note that the use of this method is discouraged if one has access to the 457 | // raw ARGB samples, since using YUV420 is comparatively lossy. Also, the 458 | // conversion from YUV420 to ARGB incurs a small loss too. 459 | // Returns false in case of error. 460 | WEBP_EXTERN(int) WebPPictureYUVAToARGB(WebPPicture* picture); 461 | 462 | // Helper function: given a width x height plane of YUV(A) samples 463 | // (with stride 'stride'), clean-up the YUV samples under fully transparent 464 | // area, to help compressibility (no guarantee, though). 465 | WEBP_EXTERN(void) WebPCleanupTransparentArea(WebPPicture* picture); 466 | 467 | // Scan the picture 'picture' for the presence of non fully opaque alpha values. 468 | // Returns true in such case. Otherwise returns false (indicating that the 469 | // alpha plane can be ignored altogether e.g.). 470 | WEBP_EXTERN(int) WebPPictureHasTransparency(const WebPPicture* picture); 471 | 472 | // Remove the transparency information (if present) by blending the color with 473 | // the background color 'background_rgb' (specified as 24bit RGB triplet). 474 | // After this call, all alpha values are reset to 0xff. 475 | WEBP_EXTERN(void) WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb); 476 | 477 | //------------------------------------------------------------------------------ 478 | // Main call 479 | 480 | // Main encoding call, after config and picture have been initialized. 481 | // 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION), 482 | // and the 'config' object must be a valid one. 483 | // Returns false in case of error, true otherwise. 484 | // In case of error, picture->error_code is updated accordingly. 485 | // 'picture' can hold the source samples in both YUV(A) or ARGB input, depending 486 | // on the value of 'picture->use_argb'. It is highly recommended to use 487 | // the former for lossy encoding, and the latter for lossless encoding 488 | // (when config.lossless is true). Automatic conversion from one format to 489 | // another is provided but they both incur some loss. 490 | WEBP_EXTERN(int) WebPEncode(const WebPConfig* config, WebPPicture* picture); 491 | 492 | //------------------------------------------------------------------------------ 493 | 494 | #ifdef __cplusplus 495 | } // extern "C" 496 | #endif 497 | 498 | #endif /* WEBP_WEBP_ENCODE_H_ */ 499 | -------------------------------------------------------------------------------- /WebP.framework/Headers/types.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010 Google Inc. All Rights Reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license 4 | // that can be found in the COPYING file in the root of the source 5 | // tree. An additional intellectual property rights grant can be found 6 | // in the file PATENTS. All contributing project authors may 7 | // be found in the AUTHORS file in the root of the source tree. 8 | // ----------------------------------------------------------------------------- 9 | // 10 | // Common types 11 | // 12 | // Author: Skal (pascal.massimino@gmail.com) 13 | 14 | #ifndef WEBP_WEBP_TYPES_H_ 15 | #define WEBP_WEBP_TYPES_H_ 16 | 17 | #include // for size_t 18 | 19 | #ifndef _MSC_VER 20 | #include 21 | #ifdef __STRICT_ANSI__ 22 | #define WEBP_INLINE 23 | #else /* __STRICT_ANSI__ */ 24 | #define WEBP_INLINE inline 25 | #endif 26 | #else 27 | typedef signed char int8_t; 28 | typedef unsigned char uint8_t; 29 | typedef signed short int16_t; 30 | typedef unsigned short uint16_t; 31 | typedef signed int int32_t; 32 | typedef unsigned int uint32_t; 33 | typedef unsigned long long int uint64_t; 34 | typedef long long int int64_t; 35 | #define WEBP_INLINE __forceinline 36 | #endif /* _MSC_VER */ 37 | 38 | #ifndef WEBP_EXTERN 39 | // This explicitly marks library functions and allows for changing the 40 | // signature for e.g., Windows DLL builds. 41 | #define WEBP_EXTERN(type) extern type 42 | #endif /* WEBP_EXTERN */ 43 | 44 | // Macro to check ABI compatibility (same major revision number) 45 | #define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8)) 46 | 47 | #endif /* WEBP_WEBP_TYPES_H_ */ 48 | -------------------------------------------------------------------------------- /WebP.framework/WebP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/WebP.framework/WebP -------------------------------------------------------------------------------- /iOS WebP Alpha Example/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/iOS WebP Alpha Example/Default-568h@2x.png -------------------------------------------------------------------------------- /iOS WebP Alpha Example/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/iOS WebP Alpha Example/Default.png -------------------------------------------------------------------------------- /iOS WebP Alpha Example/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/iOS WebP Alpha Example/Default@2x.png -------------------------------------------------------------------------------- /iOS WebP Alpha Example/NEAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // NEAppDelegate.h 3 | // iOS WebP Alpha Example 4 | // 5 | // Created by Gabrielle on 3/16/13. 6 | // Copyright (c) 2013 Nyteshade Enterprises. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NEAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/NEAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // NEAppDelegate.m 3 | // iOS WebP Alpha Example 4 | // 5 | // Created by Gabrielle on 3/16/13. 6 | // Copyright (c) 2013 Nyteshade Enterprises. All rights reserved. 7 | // 8 | 9 | #import "NEAppDelegate.h" 10 | 11 | @implementation NEAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/NEViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // NEViewController.h 3 | // iOS WebP Alpha Example 4 | // 5 | // Created by Gabrielle on 3/16/13. 6 | // Copyright (c) 2013 Nyteshade Enterprises. All rights reserved. 7 | // 8 | // Modified (encoding added) by Dmitry Shmidt, mail@shmidtlab.com 9 | 10 | #import 11 | #import "UIImage+WebP.h" 12 | 13 | @interface NEViewController : UIViewController 14 | 15 | @property (strong, nonatomic) IBOutlet UIImageView *background; 16 | @property (strong, nonatomic) IBOutlet UIImageView *topLayer; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/NEViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // NEViewController.m 3 | // iOS WebP Alpha Example 4 | // 5 | // Created by Gabrielle on 3/16/13. 6 | // Copyright (c) 2013 Nyteshade Enterprises. All rights reserved. 7 | // 8 | // Modified (encoding added) by Dmitry Shmidt, mail@shmidtlab.com 9 | 10 | #import "NEViewController.h" 11 | #import "UIImage+WebP.h" 12 | 13 | @implementation NEViewController 14 | 15 | - (void)viewDidLoad 16 | { 17 | [super viewDidLoad]; 18 | // Load the webp image for the background. Image comes from 19 | // http://wallpapersget.com/art-wallpaper-stores-water-best-ofthe-week-albums 20 | // 21 | _background.image = [UIImage imageWithWebPAtPath:@"background0.webp"]; 22 | 23 | // Load the webp image for the top layer. Image comes from 24 | // http://www.officialpsds.com/Rusty-Sign-PSD19143.html 25 | // 26 | _topLayer.image = [UIImage imageWithWebPAtPath:@"layer0.webp"]; 27 | } 28 | - (void)viewDidAppear:(BOOL)animated{ 29 | UIImage *tmpImage = [UIImage imageNamed:@"background0"]; 30 | [tmpImage writeWebPToDocumentsWithFileName:@"background1" quality:100]; 31 | [tmpImage writeWebPLosslessToDocumentsWithFileName:@"background2"]; 32 | 33 | // NSString *webpPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/background0.webp"]]; 34 | // NSData *imgData = [tmpImage dataWebPWithQuality:100]; 35 | // [imgData writeToFile:webpPath atomically:YES]; 36 | 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/WebP-UIImage Example-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.nyteshade.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | iPhone 29 | UIMainStoryboardFile~ipad 30 | iPad 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/WebP-UIImage Example-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iOS WebP Alpha Example' target in the 'iOS WebP Alpha Example' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/background0.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/iOS WebP Alpha Example/background0.webp -------------------------------------------------------------------------------- /iOS WebP Alpha Example/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/en.lproj/iPad.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/en.lproj/iPhone.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /iOS WebP Alpha Example/layer0.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shmidt/WebP-UIImage/d957a10e0dc5f3fdc88f46c34341aef4a5aed74f/iOS WebP Alpha Example/layer0.webp -------------------------------------------------------------------------------- /iOS WebP Alpha Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iOS WebP Alpha Example 4 | // 5 | // Created by Gabrielle on 3/16/13. 6 | // Copyright (c) 2013 Nyteshade Enterprises. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "NEAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([NEAppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------