Open GoogleCodeExporter opened 8 years ago
Original comment by mikechambers
on 2 Jul 2008 at 4:52
Original comment by mikechambers
on 22 Sep 2009 at 8:17
I was working with high resolution images at one point, and Actionscript kept
timing
out on the encode() method. As a result, I created an asynchronous version of
encode, which takes a callback function after the encoding is done. It doesn't
do
anything to speed it up, but it prevents Flash from crashing when encoding a
hi-res
image. There are probably better ways to do this than a timer, but it worked:
public function encodeAsync(image:BitmapData, fn:Function,
progressFn:Function=null):void {
var img:BitmapData = image.clone();
img.applyFilter(img, img.rect, orgn, fltrRGB2YUV);
var height:int = img.height;
var width:int = img.width;
// Initialize bit writer
byteout = new ByteArray();
bytenew=0;
bytepos=7;
// Add JPEG headers
writeWord(0xFFD8); // SOI
writeAPP0();
writeDQT();
writeSOF0(width,height);
writeDHT();
writeSOS();
// Encode 8x8 macroblocks
var DCY:int=0;
var DCU:int=0;
var DCV:int=0;
var t:Timer = new Timer(10, 0);
var ypos:int = 0;
var xpos:int = 0;
t.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void
{
for (var xpos:int=0; xpos<width; xpos+=8) {
RGB2YUV(img, xpos, ypos);
DCY = processDU(YDUBlock, fdtbl_YList, DCY, YDC_HT, YAC_HT);
DCU = processDU(UDUBlock, fdtbl_UVList, DCU, UVDC_HT, UVAC_HT);
DCV = processDU(VDUBlock, fdtbl_UVList, DCV, UVDC_HT, UVAC_HT);
}
ypos += 8;
if (ypos >= height)
{
img.dispose();
if ( bytepos >= 0 ) {
writeBits(new BitString((1<<(bytepos+1))-1, bytepos+1));
}
writeWord(0xFFD9);
t.stop();
fn(byteout);
}
if (progressFn) progressFn(Math.min(ypos/height, 1));
});
t.start();
}
Original comment by kopchi...@gmail.com
on 3 Mar 2010 at 4:48
Original issue reported on code.google.com by
trent.ni...@gmail.com
on 7 Mar 2008 at 11:20