Coder Social home page Coder Social logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024

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

  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024

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

  • Changed state: Accepted
  • Added labels: Priority-High
  • Removed labels: Priority-Low

from as3corelib.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 30, 2024
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 [email protected] on 3 Mar 2010 at 4:48

from as3corelib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.