all files / core/compression/ jpeg-stream.js

48.94% Statements 23/47
47.83% Branches 11/23
66.67% Functions 8/12
45.45% Lines 20/44
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                                               
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../decode-stream", "../graphics/images/jpeg-image"], function (require, exports, decode_stream_1, jpeg_image_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfJpegStream = (function (_super) {
        __extends(_PdfJpegStream, _super);
        function _PdfJpegStream(stream, maybeLength, params) {
            var _this = _super.call(this, maybeLength) || this;
            _this._jpegStreamStart = 0;
            _this._needsReprocessing = false;
            _this.stream = stream;
            _this.params = params;
            _this.maybeLength = maybeLength;
            return _this;
        }
        _PdfJpegStream.prototype.readBlock = function () {
            this.decodeImage();
        };
        _PdfJpegStream.prototype.decodeImage = function (bytes) {
            if (this.eof) {
                return this.buffer;
            }
            bytes = this.skipUselessBytes(bytes || this.stream.getBytes(this.maybeLength));
            var jpegImage = new jpeg_image_1._PdfJpegImage();
            jpegImage.parse(bytes);
            var data = jpegImage._getData(this.drawWidth, this.drawHeight, this.forceRgba, this.forceRgb, true);
            this.buffer = data;
            this.bufferLength = data.length;
            this.eof = true;
            return this.buffer;
        };
        _PdfJpegStream.prototype.skipUselessBytes = function (data) {
            for (var i = 0, ii = data.length - 1; i < ii; i++) {
                if (data[i] === 0xff && data[i + 1] === 0xd8) {
                    if (i > 0) {
                        data = data.subarray(i);
                    }
                    break;
                }
            }
            return data;
        };
        return _PdfJpegStream;
    }(decode_stream_1._PdfDecodeStream));
    exports._PdfJpegStream = _PdfJpegStream;
});