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
On 9/22/07, Jon Bradley <[EMAIL PROTECTED]> wrote:
>
> Has anyone attempted to modify the corelib JPGEncoder to support
> progress. Rather than letting it bang away for a seemingly long time,
> I'd like to provide feedback for JPG (and PNG) compression if possible.
>
> many thanks for any pointers...
>
> - jon
>
>