2
0

stream_spec.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _stream = require("../../core/stream.js");
  24. var _primitives = require("../../core/primitives.js");
  25. describe("stream", function () {
  26. beforeEach(function () {
  27. jasmine.addMatchers({
  28. toMatchTypedArray(util, customEqualityTesters) {
  29. return {
  30. compare(actual, expected) {
  31. var result = {};
  32. if (actual.length !== expected.length) {
  33. result.pass = false;
  34. result.message = "Array length: " + actual.length + ", expected: " + expected.length;
  35. return result;
  36. }
  37. result.pass = true;
  38. for (var i = 0, ii = expected.length; i < ii; i++) {
  39. var a = actual[i],
  40. b = expected[i];
  41. if (a !== b) {
  42. result.pass = false;
  43. break;
  44. }
  45. }
  46. return result;
  47. }
  48. };
  49. }
  50. });
  51. });
  52. describe("PredictorStream", function () {
  53. it("should decode simple predictor data", function () {
  54. var dict = new _primitives.Dict();
  55. dict.set("Predictor", 12);
  56. dict.set("Colors", 1);
  57. dict.set("BitsPerComponent", 8);
  58. dict.set("Columns", 2);
  59. var input = new _stream.Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
  60. var predictor = new _stream.PredictorStream(input, 9, dict);
  61. var result = predictor.getBytes(6);
  62. expect(result).toMatchTypedArray(new Uint8Array([100, 3, 101, 2, 102, 1]));
  63. predictor.reset();
  64. const clampedResult = predictor.getBytes(6, true);
  65. expect(clampedResult).toEqual(new Uint8ClampedArray([100, 3, 101, 2, 102, 1]));
  66. });
  67. });
  68. });