Packagecom.threerings.display
Classpublic class JPGEncoder

Class for compressing bitmaps into jpegs. Each instance may only be used for a single image. When the encoder is constructed, the headers are generated, but no pixel encoding is done. Subsequent calls to 'process' will encode pixels for a specified length of time. Once the encoding is done (determined by process returning true, or a call to isComplete), the jpeg data can be accessed via getJpeg.



Protected Properties
 PropertyDefined by
  _bytenew : int = 0
JPGEncoder
  _byteout : ByteArray
Byte array to contain the jpg while encoding is in progress.
JPGEncoder
  _bytepos : int = 7
JPGEncoder
  _DCU : Number = 0
JPGEncoder
  _DCV : Number = 0
JPGEncoder
  _DCY : Number = 0
JPGEncoder
  _encodedJpeg : ByteArray
Byte array to contain the resuling jpg
JPGEncoder
  _image : BitmapData
The image to encode
JPGEncoder
  _pixelGranularity : int
The minumum number of pixels that will be processed at a time.
JPGEncoder
  pixelsDone : Boolean = false
JPGEncoder
  _xpos : int = 0
JPGEncoder
  _ypos : int = 0
JPGEncoder
Public Methods
 MethodDefined by
  
JPGEncoder(image:BitmapData, quality:Number = 50, pixelGranularity:int = 100)
Construct a new JPGEncoder object.
JPGEncoder
  
getJpeg():ByteArray
Return a byte array containing the encoded jpeg.
JPGEncoder
  
isComplete():Boolean
Return true if the encoding is complete.
JPGEncoder
  
process(timeSlice:int):Boolean
Work on encoding the image for a specified number of milliseconds.
JPGEncoder
Protected Methods
 MethodDefined by
  
Add the EOI marker to the end of the buffer, and make the result available to the consumer of this class.
JPGEncoder
  
encodePixels(unitSize:int):void
Encode a specified number of pixels.
JPGEncoder
  
JPGEncoder
  
writeHeader():void
Write the jpeg header into the byte array for output.
JPGEncoder
Property detail
_bytenewproperty
protected var _bytenew:int = 0
_byteoutproperty 
protected var _byteout:ByteArray

Byte array to contain the jpg while encoding is in progress.

_byteposproperty 
protected var _bytepos:int = 7
_DCUproperty 
protected var _DCU:Number = 0
_DCVproperty 
protected var _DCV:Number = 0
_DCYproperty 
protected var _DCY:Number = 0
_encodedJpegproperty 
protected var _encodedJpeg:ByteArray

Byte array to contain the resuling jpg

_imageproperty 
protected var _image:BitmapData

The image to encode

_pixelGranularityproperty 
protected var _pixelGranularity:int

The minumum number of pixels that will be processed at a time.

pixelsDoneproperty 
protected var pixelsDone:Boolean = false
_xposproperty 
protected var _xpos:int = 0
_yposproperty 
protected var _ypos:int = 0
Constructor detail
JPGEncoder()constructor
public function JPGEncoder(image:BitmapData, quality:Number = 50, pixelGranularity:int = 100)

Construct a new JPGEncoder object.

Parameters
image:BitmapData — The image to encode
 
quality:Number (default = 50) — Quality level between 1 and 100 determining the level of compression.s
 
pixelGranularity:int (default = 100) — The minumum number of pixels to process at a time.
Method detail
completeEncoding()method
protected function completeEncoding():void

Add the EOI marker to the end of the buffer, and make the result available to the consumer of this class.

encodePixels()method 
protected function encodePixels(unitSize:int):void

Encode a specified number of pixels. Fewer pixels will be encoded if the end of the image is reached first.

Parameters
unitSize:int
getJpeg()method 
public function getJpeg():ByteArray

Return a byte array containing the encoded jpeg.

Returns
ByteArray
initializeEncoding()method 
protected function initializeEncoding():void
isComplete()method 
public function isComplete():Boolean

Return true if the encoding is complete.

Returns
Boolean
process()method 
public function process(timeSlice:int):Boolean

Work on encoding the image for a specified number of milliseconds. Return true if there is no more processing to do.

Parameters
timeSlice:int

Returns
Boolean
writeHeader()method 
protected function writeHeader():void

Write the jpeg header into the byte array for output.