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

46.94% Statements 23/49
52.38% Branches 11/21
66.67% Functions 8/12
43.48% Lines 20/46
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 61 62 63 64 65 66                                                                                           
/* 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", "../base-stream", "../decode-stream", "../graphics/images/jbig2-image", "../pdf-primitives"], function (require, exports, base_stream_1, decode_stream_1, jbig2_image_1, pdf_primitives_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _PdfJbig2Stream = (function (_super) {
        __extends(_PdfJbig2Stream, _super);
        function _PdfJbig2Stream(stream, maybeLength, params) {
            var _this = _super.call(this, maybeLength) || this;
            _this.stream = stream;
            _this.maybeLength = maybeLength;
            _this.params = params;
            return _this;
        }
        Object.defineProperty(_PdfJbig2Stream.prototype, "bytes", {
            get: function () {
                return this.stream.getBytes(this.maybeLength);
            },
            enumerable: true,
            configurable: true
        });
        _PdfJbig2Stream.prototype.readBlock = function () {
            this.decodeImage();
        };
        _PdfJbig2Stream.prototype.decodeImage = function (bytes) {
            if (this.eof) {
                return this.buffer;
            }
            bytes = bytes || this.bytes;
            var jbig2Image = new jbig2_image_1._PdfJbig2Image();
            var chunks = [];
            if (this.params instanceof pdf_primitives_1._PdfDictionary) {
                var globalsStream = this.params.get('JBIG2Globals');
                if (globalsStream instanceof base_stream_1._PdfBaseStream) {
                    var globals = globalsStream.getBytes();
                    chunks.push({ data: globals, start: 0, end: globals.length });
                }
            }
            chunks.push({ data: bytes, start: 0, end: bytes.length });
            var data = jbig2Image._parseChunks(chunks);
            var dataLength = data.length;
            for (var i = 0; i < dataLength; i++) {
                data[i] ^= 0xff;
            }
            this.buffer = data;
            this.bufferLength = dataLength;
            this.eof = true;
            return this.buffer;
        };
        return _PdfJbig2Stream;
    }(decode_stream_1._PdfDecodeStream));
    exports._PdfJbig2Stream = _PdfJbig2Stream;
});