2
0

stream_spec.js 2.1 KB

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