Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPGEncoder Poor Performance #46

Open
darronschall opened this issue Jul 28, 2010 · 3 comments
Open

JPGEncoder Poor Performance #46

darronschall opened this issue Jul 28, 2010 · 3 comments

Comments

@darronschall
Copy link
Contributor

Originally filed by trent.niemeyer on 2008-03-07T23:20:24

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

@darronschall
Copy link
Contributor Author

Updated by mikechambers on 2008-07-02T16:52:21

Removed label Priority-Medium
Added label Priority-Low

@darronschall
Copy link
Contributor Author

Updated by mikechambers on 2009-09-22T08:17:26

Original ticket set owner to thibault.imbert
Removed label Priority-Low
Added label Priority-High
Original ticket set status to Accepted (we converted to open)

@darronschall
Copy link
Contributor Author

Updated by kopchickm on 2010-03-03T16:48:02

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= 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();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant