mozilla/pdf.js — pull request #926 by brendandahl (2011-12-12 20:15:11+00:00)
Title: Soft Masks for Natively Supported(decoded by browser) JPEGs

Resolves #883, #704.

The main issue was we regressed from the worker code and didn't support soft masks for jpegs anymore. This became more prevalent when we added the CMYK jpeg code since that had a different code path than the natively supported jpegs. The above two issues were from a jpeg that we had to decode, but the jpeg also had a jpeg softmask which was a natively supported jpeg.

I've added back support for jpeg soft masks but the code is now much more complicated than when we previously supported them because of the workers. To try and make this easier I've added two new pieces.

-MessageHandler.send() now accepts a third parameter of a callback. This allows you to send something to main thread or worker and expect a response back e.g.
```m.send('do_some_work', data, function(work_result) { alert('look ma ' + worker_result });```
and then on the other side of things
```m.on('do_some_work', function(message) { message.reply('I did some work'); })```

-I added a new '"static" helper function to Promise named all(). This is a pretty common function in other Promise frameworks. You pass in multiple promises and it creates a wrapper promise that is resolved when all the promises are resolved. This makes it so if both the soft mask and the regular image are natively supported jpegs then we can send them both to the main thread and wait for them.

I expect this to fail on pdkids page 9. This image is displayed wrong currently and will still be displayed wrong after this PR. It is a natively supported JPEG with a flate soft mask. It is still displayed wrong because the soft mask uses an unsupported decode map. I plan to address this in a separate PR and will add the issue number when I create it.