Packagecom.distriqt.extension.webp
Classpublic final class WebP
InheritanceWebP Inheritance 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



Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined By
  
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
  
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
Public Constants
 ConstantDefined By
  EXT_CONTEXT_ID : String = com.distriqt.WebP
[static]
WebP
  VERSION : String = 4.1.0
[static]
WebP
Property Detail
heightproperty
height:Number  [read-only]

Retrieves the height of the last decoded WebP image


Implementation
    public function get height():Number
implementationproperty 
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:


Implementation
    public function get implementation():String
isSupportedproperty 
isSupported:Boolean  [read-only]

Whether the current device supports the extensions functionality


Implementation
    public static function get isSupported():Boolean
nativeVersionproperty 
nativeVersion:String  [read-only]

The native version string of the native extension.


Implementation
    public function get nativeVersion():String
serviceproperty 
service:WebP  [read-only]

The singleton instance of the WebP class.


Implementation
    public static function get service():WebP

Throws
Error — If there was a problem creating or accessing the extension, or if the developer key is invalid
versionproperty 
version:String  [read-only]

The version of this extension.

This should be of the format, MAJOR.MINOR.BUILD


Implementation
    public function get version():String
widthproperty 
width:Number  [read-only]

Retrieves the width of the last decoded WebP image


Implementation
    public function get width():Number
Constructor Detail
WebP()Constructor
public function WebP()

Constructor You should not call this directly, but instead use the singleton access

Method Detail
createLoader()method
public function createLoader():WebPLoader

Creates a new WebPLoader instance to use to load WebP files.

Returns
WebPLoader — A WebPLoader instance
decoderVersion()method 
public function decoderVersion():String

The version string of the WebP decoder packaged with this ANE.

Returns
String — 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
Deprecated: You no longer need to use an application key

Initialises the extension class for use with the provided key.

Parameters

key:String


Throws
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

Returns
Boolean — true on success

Throws
WebPError When — the file path is invalid or the format could not be interpretted as WebP.

Example
The following example opens a file 'image.webp' packaged in an 'assets' directory of an application.
         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.

Returns
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.

Throws
WebPError When — the file path is invalid or the format could not be interpretted as WebP.

Example
The following example opens a file 'image.webp' packaged in an 'assets' directory of an application.
         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

Returns
Boolean — true on success

Throws
WebPError When — the file path is invalid or the format could not be interpretted as WebP.

Example
This example shows the simple usage of loading the byte data from a file ("assets/image.webp") and converting it to bitmap information.
         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)
         {
         }
         
Constant Detail
EXT_CONTEXT_IDConstant
public static const EXT_CONTEXT_ID:String = com.distriqt.WebP

VERSIONConstant 
public static const VERSION:String = 4.1.0