on using timer for screen updates: Is there any advantage (or disadvantage) of that vs. callLater ?
On 9/23/07, Gordon Smith <[EMAIL PROTECTED]> wrote: > > > the corelib version > This class is now an official part of Flex 3: > mx.graphics.codec.JPEGEncoder. > > - Gordon > > ------------------------------ > *From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On > Behalf Of *Jon Bradley > *Sent:* Saturday, September 22, 2007 11:03 AM > *To:* flexcoders@yahoogroups.com > *Subject:* Re: [flexcoders] JPGEncoder with progress support? > > > > Sure does Doug! Thanks for the tips. > > I'm actually re-writing the corelib version now to make it more efficient > for larger images. Right now encoding a 2k image takes much longer than I'm > happy with. :) > > > I was doing a bit more research and will be breaking it up into 'chunks' > with progress events, hopefully. > > > If I get a good result I'll post back the code to the corelib project. > > > peace, > > > jon > > > > On Sep 22, 2007, at 1:38 PM, Doug McCune wrote: > > This is doable, but requires a little more work than you probably think. > To do this you would modify JPEGEncoder, if you're using Moxie take a look > at the JPEGEncoder class around line 121. You'll see this double for loop: > > for (var ypos:int = 0; ypos < height; ypos += 8) > { > for (var xpos:int = 0; xpos < width; xpos += 8) > { > RGB2YUV(source, xpos, ypos, width, height); > DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT); > DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT); > DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT); > } > } > > As far as I can tell that's where the bulk of the processing happens. What > you're going to want to do is add progress events dispatching in there. But > simply dispatching progress events isn't going to be enough. That would > effectively give you notifications for progress of encoding, but since flash > player is single threaded, your display won't ever have time to update while > those for loops are running. > > So you'll need to split the processing up into smaller tasks and insert > idle times between them. You'll want to use the Timer class to make your > code wait for a given period (I've found that even just a few milliseconds > is enough for the display to update). > > I would split up the algorithm to process one row at a time (so basically > that inner for loop gets turned into its own function). Then have the > function that processes a row start a timer once it's completed, and once > that timer completes, then run the function for the next row and so on until > you finish. That was you can dispatch a progress event for each row and the > display will have time to update. > > Hope some of that makes sense. > > Doug > > > > > > -- Arpit Mathur Lead Software Engineer, Comcast Interactive Media --------------------------------------- post your flex tips on http://flextips.corank.com