stream_spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. var corePrimitives = require('../../core/primitives.js');
  17. var coreStream = require('../../core/stream.js');
  18. var Dict = corePrimitives.Dict;
  19. var Stream = coreStream.Stream;
  20. var PredictorStream = coreStream.PredictorStream;
  21. describe('stream', function () {
  22. beforeEach(function () {
  23. jasmine.addMatchers({
  24. toMatchTypedArray: function (util, customEqualityTesters) {
  25. return {
  26. compare: function (actual, expected) {
  27. var result = {};
  28. if (actual.length !== expected.length) {
  29. result.pass = false;
  30. result.message = 'Array length: ' + actual.length + ', expected: ' + expected.length;
  31. return result;
  32. }
  33. result.pass = true;
  34. for (var i = 0, ii = expected.length; i < ii; i++) {
  35. var a = actual[i], b = expected[i];
  36. if (a !== b) {
  37. result.pass = false;
  38. break;
  39. }
  40. }
  41. return result;
  42. }
  43. };
  44. }
  45. });
  46. });
  47. describe('PredictorStream', function () {
  48. it('should decode simple predictor data', function () {
  49. var dict = new Dict();
  50. dict.set('Predictor', 12);
  51. dict.set('Colors', 1);
  52. dict.set('BitsPerComponent', 8);
  53. dict.set('Columns', 2);
  54. var input = new Stream(new Uint8Array([
  55. 2,
  56. 100,
  57. 3,
  58. 2,
  59. 1,
  60. 255,
  61. 2,
  62. 1,
  63. 255
  64. ]), 0, 9, dict);
  65. var predictor = new PredictorStream(input, 9, dict);
  66. var result = predictor.getBytes(6);
  67. expect(result).toMatchTypedArray(new Uint8Array([
  68. 100,
  69. 3,
  70. 101,
  71. 2,
  72. 102,
  73. 1
  74. ]));
  75. });
  76. });
  77. });