stream_spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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],
  36. b = expected[i];
  37. if (a !== b) {
  38. result.pass = false;
  39. break;
  40. }
  41. }
  42. return result;
  43. }
  44. };
  45. }
  46. });
  47. });
  48. describe('PredictorStream', function () {
  49. it('should decode simple predictor data', function () {
  50. var dict = new Dict();
  51. dict.set('Predictor', 12);
  52. dict.set('Colors', 1);
  53. dict.set('BitsPerComponent', 8);
  54. dict.set('Columns', 2);
  55. var input = new Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
  56. var predictor = new PredictorStream(input, 9, dict);
  57. var result = predictor.getBytes(6);
  58. expect(result).toMatchTypedArray(new Uint8Array([100, 3, 101, 2, 102, 1]));
  59. });
  60. });
  61. });