Browse Source

Transfer GRAYSCALE_1BPP and RGB_24BPP arrays when possible.

Nicholas Nethercote 11 years ago
parent
commit
f30babde58
  1. 15
      src/core/image.js

15
src/core/image.js

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals ColorSpace, error, isArray, ImageKind, isStream, JpegStream, Name, /* globals ColorSpace, DecodeStream, error, isArray, ImageKind, isStream,
Promise, Stream, warn, LegacyPromise */ JpegStream, Name, Promise, Stream, warn, LegacyPromise */
'use strict'; 'use strict';
@ -452,11 +452,18 @@ var PDFImage = (function PDFImageClosure() {
drawWidth === originalWidth && drawHeight === originalHeight) { drawWidth === originalWidth && drawHeight === originalHeight) {
imgData.kind = kind; imgData.kind = kind;
// We must make a copy of imgArray, otherwise it'll be neutered upon // If imgArray came from a DecodeStream, we're safe to transfer it
// transfer which will break any code that subsequently reuses it. // (and thus neuter it) because it will constitute the entire
// DecodeStream's data. But if it came from a Stream, we need to
// copy it because it'll only be a portion of the Stream's data, and
// the rest will be read later on.
if (this.image instanceof DecodeStream) {
imgData.data = imgArray;
} else {
var newArray = new Uint8Array(imgArray.length); var newArray = new Uint8Array(imgArray.length);
newArray.set(imgArray); newArray.set(imgArray);
imgData.data = newArray; imgData.data = newArray;
}
return imgData; return imgData;
} }
} }

Loading…
Cancel
Save