diegosae / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

JPGEncoder Poor Performance #49

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Initialize JPGEncoder (try various quality settings)
2. Encode
3. Track time spent encoding

What is the expected output? What do you see instead?
I would expect no more than a few seconds @ quality 70 for a 1MB x 1MB
picture (real imagery as opposed to cartoon or vector generated images)

What version of the product are you using? On what operating system?
.90, WinXP SP2

Please provide any additional information below.
Sample Image that took 21 seconds with image quality 70. (3.4 GHz Pentium
CPU, 1 GB RAM)
http://compression.ca/act/files/DSCN3974.jpg

Original issue reported on code.google.com by trent.ni...@gmail.com on 7 Mar 2008 at 11:20

GoogleCodeExporter commented 9 years ago

Original comment by mikechambers on 2 Jul 2008 at 4:52

GoogleCodeExporter commented 9 years ago

Original comment by mikechambers on 22 Sep 2009 at 8:17

GoogleCodeExporter commented 9 years ago
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