mozilla/pdf.js — pull request #4139 by nnethercote (2014-01-17 05:58:38+00:00)
Title: Write color and opacity values directly to the final RGBA array when possible, so as to avoid allocating unnecessary memory.

These patches get rid of copy 1 as described in https://bugzilla.mozilla.org/show_bug.cgi?id=959925.

The third patch, which removes the RGB array when resizing isn't required, is the most invasive. It required modifying all the getRgbBuffer() and getOutputLength() methods so they can work with either an RGB or an RGBA array. I did this by adding an extra |alpha01| parameter, which is 0 if we're dealing with an RGB array and 1 for an RGBA array.

Also, the (possible) resizing and subsequent RGB-to-RGBA copying had to move into createRgbBuffer(), which has been renamed fillRgb().

This branch passes all tests, but I'm a bit concerned that our test coverage isn't great. Several of the modified getRgbBuffer() and getOutputLength() functions aren't triggered by any of the tests.