2
0

ccitt_stream.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.CCITTFaxStream = undefined;
  20. var _primitives = require('./primitives');
  21. var _ccitt = require('./ccitt');
  22. var _stream = require('./stream');
  23. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  24. function CCITTFaxStream(str, maybeLength, params) {
  25. this.str = str;
  26. this.dict = str.dict;
  27. if (!(0, _primitives.isDict)(params)) {
  28. params = _primitives.Dict.empty;
  29. }
  30. var source = {
  31. next: function next() {
  32. return str.getByte();
  33. }
  34. };
  35. this.ccittFaxDecoder = new _ccitt.CCITTFaxDecoder(source, {
  36. K: params.get('K'),
  37. EndOfLine: params.get('EndOfLine'),
  38. EncodedByteAlign: params.get('EncodedByteAlign'),
  39. Columns: params.get('Columns'),
  40. Rows: params.get('Rows'),
  41. EndOfBlock: params.get('EndOfBlock'),
  42. BlackIs1: params.get('BlackIs1')
  43. });
  44. _stream.DecodeStream.call(this, maybeLength);
  45. }
  46. CCITTFaxStream.prototype = Object.create(_stream.DecodeStream.prototype);
  47. CCITTFaxStream.prototype.readBlock = function () {
  48. while (!this.eof) {
  49. var c = this.ccittFaxDecoder.readNextChar();
  50. if (c === -1) {
  51. this.eof = true;
  52. return;
  53. }
  54. this.ensureBuffer(this.bufferLength + 1);
  55. this.buffer[this.bufferLength++] = c;
  56. }
  57. };
  58. return CCITTFaxStream;
  59. }();
  60. exports.CCITTFaxStream = CCITTFaxStream;