Package | com.distriqt.extension.webp |
Class | public final class WebP |
Inheritance | WebP flash.events.EventDispatcher |
This class represents the WebP extension allowing you to load WebP formatted files.
WebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller in size compared to JPEG images at equivalent SSIM index. WebP supports lossless transparency (also known as alpha channel) with just 22% additional bytes. Transparency is also supported with lossy compression and typically provides 3x smaller file sizes compared to PNG when lossy compression is acceptable for the red/green/blue color channels.
For more on information on the format see the following page on Google Developers: WebP
Property | Defined By | ||
---|---|---|---|
height : Number [read-only]
Retrieves the height of the last decoded WebP image
| WebP | ||
implementation : String [read-only]
The implementation currently in use. | WebP | ||
isSupported : Boolean [static] [read-only]
Whether the current device supports the extensions functionality
| WebP | ||
nativeVersion : String [read-only]
The native version string of the native extension. | WebP | ||
service : WebP [static] [read-only]
The singleton instance of the WebP class. | WebP | ||
version : String [read-only]
The version of this extension. | WebP | ||
width : Number [read-only]
Retrieves the width of the last decoded WebP image
| WebP |
Method | Defined By | ||
---|---|---|---|
WebP()
Constructor
You should not call this directly, but instead use the singleton access
| WebP | ||
Creates a new WebPLoader instance to use to
load WebP files. | WebP | ||
decoderVersion():String
The version string of the WebP decoder packaged with this ANE. | WebP | ||
dispose():void
Disposes the extension and releases any allocated resources. | WebP | ||
init(key:String):void Deprecated: You no longer need to use an application key [static]
Initialises the extension class for use with the provided key. | WebP | ||
loadWebP(path:String, decodedData:ByteArray):Boolean
This function loads the specified file and attempts to decode the file
using the WebP format. | WebP | ||
loadWebPBitmapData(path:String):BitmapData
This function loads the specified file and attempts to decode the file
using the WebP format. | WebP | ||
parseWebP(data:ByteArray, decodedData:ByteArray):Boolean
This function implements the raw "parse" functionality allowing you
to convert raw WebP data to decoded bitmap pixel information. | WebP |
Constant | Defined By | ||
---|---|---|---|
EXT_CONTEXT_ID : String = com.distriqt.WebP [static] | WebP | ||
VERSION : String = 4.1.0 [static] | WebP |
height | property |
height:Number
[read-only]
Retrieves the height of the last decoded WebP image
public function get height():Number
implementation | property |
implementation:String
[read-only]
The implementation currently in use. This should be one of the following depending on the platform in use and the functionality supported by this extension:
Android
iOS
default
unknown
public function get implementation():String
isSupported | property |
isSupported:Boolean
[read-only] Whether the current device supports the extensions functionality
public static function get isSupported():Boolean
nativeVersion | property |
nativeVersion:String
[read-only]
The native version string of the native extension.
public function get nativeVersion():String
service | property |
service:WebP
[read-only] The singleton instance of the WebP class.
public static function get service():WebP
Error — If there was a problem creating or accessing the extension, or if the developer key is invalid
|
version | property |
version:String
[read-only]
The version of this extension.
This should be of the format, MAJOR.MINOR.BUILD
public function get version():String
width | property |
width:Number
[read-only]
Retrieves the width of the last decoded WebP image
public function get width():Number
WebP | () | Constructor |
public function WebP()
Constructor You should not call this directly, but instead use the singleton access
createLoader | () | method |
public function createLoader():WebPLoader
Creates a new WebPLoader
instance to use to
load WebP files.
WebPLoader — A WebPLoader instance
|
decoderVersion | () | method |
public function decoderVersion():String
The version string of the WebP decoder packaged with this ANE.
ReturnsString — x
|
dispose | () | method |
public function dispose():void
Disposes the extension and releases any allocated resources. Once this function
has been called, a call to init
is neccesary again before any of the
extensions functionality will work.
init | () | method |
public static function init(key:String):void
Initialises the extension class for use with the provided key.
Parameters
key:String |
Error — If there was a problem creating or accessing the extension, or if the key is invalid
|
loadWebP | () | method |
public function loadWebP(path:String, decodedData:ByteArray):Boolean
This function loads the specified file and attempts to decode the file using the WebP format.
The data is returned as pixel data usable in ARGB order for AIR/Flash
Parameters
path:String — The native file path or app url of the WebP file to load
This needs to either be a native file path to a WebP file
or an app:/assetname.webp link to a locally embedded file.
The url method is provided as on Android files packaged
with your application and referenced via File.applicationDirectory
return an empty native path.
| |
decodedData:ByteArray — The ByteArray instance to store the decoded WebP data
|
Boolean — true on success
|
WebPError When — the file path is invalid or the format could not be interpretted as WebP.
|
try { WebP.init( DEV_KEY ); var path:String = File.applicationDirectory.resolvePath( "assets/image.webp" ).url; var decodedData:ByteArray = new ByteArray(); WebP.service.loadWebP( path, decodedData ); var rect:Rectangle = new Rectangle( 0, 0, WebP.service.width, WebP.service.height ); var bd:BitmapData = new BitmapData( WebP.service.width, WebP.service.height, true ); bd.setPixels( rect, decodedData ); decodedData.clear(); addChild( new Bitmap( bd ) ); } catch (e:WebPError) { trace( e.code + "::" + e.message ); }
loadWebPBitmapData | () | method |
public function loadWebPBitmapData(path:String):BitmapData
This function loads the specified file and attempts to decode the file using the WebP format.
The data is returned as a BitmapData object
Parameters
path:String — The native file path or app url of the WebP file to load
This needs to either be a native file path to a WebP file
or an app:/assetname.webp link to a locally embedded file.
The url method is provided as on Android files packaged
with your application and referenced via File.applicationDirectory
return an empty native path.
|
BitmapData — If successful a BitmapData object containing the pixel information of the WebP file.
If it fails, null will be returned, though normally an error will be thrown.
|
WebPError When — the file path is invalid or the format could not be interpretted as WebP.
|
try { WebP.init( DEV_KEY ); var path:String = File.applicationDirectory.resolvePath( "assets/image.webp" ).url; var bd:BitmapData = WebP.service.loadWebPBitmapData( path ); if (bd != null) { addChild( new Bitmap( bd ) ); } } catch (e:WebPError) { trace( e.code + "::" + e.message ); }
parseWebP | () | method |
public function parseWebP(data:ByteArray, decodedData:ByteArray):Boolean
This function implements the raw "parse" functionality allowing you to convert raw WebP data to decoded bitmap pixel information. This can be used where you have access to the byte data through a method other than as a packaged file.
The data is returned as pixel data usable in ARGB order for AIR/Flash
Parameters
data:ByteArray — The raw file bytes for the WebP image
| |
decodedData:ByteArray — The ByteArray instance to store the decoded WebP data
|
Boolean — true on success
|
WebPError When — the file path is invalid or the format could not be interpretted as WebP.
|
try { WebP.init( DEV_KEY ); var file:File = File.applicationDirectory.resolvePath( "assets/image.webp" ); var fs:FileStream = new FileStream(); fs.open( file, FileMode.READ ); var data:ByteArray = new ByteArray(); fs.readBytes( data, 0, fs.bytesAvailable ); fs.close(); var decodedData:ByteArray = new ByteArray(); WebP.service.parseWebP( data, decodedData ); var rect:Rectangle = new Rectangle( 0, 0, WebP.service.width, WebP.service.height ); var bd:BitmapData = new BitmapData( WebP.service.width, WebP.service.height, true ); bd.setPixels( rect, decodedData ); decodedData.clear(); } catch (e:WebPError) { }
EXT_CONTEXT_ID | Constant |
public static const EXT_CONTEXT_ID:String = com.distriqt.WebP
VERSION | Constant |
public static const VERSION:String = 4.1.0