stream_spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. import { Dict } from "../../src/core/primitives.js";
  16. import { PredictorStream } from "../../src/core/predictor_stream.js";
  17. import { Stream } from "../../src/core/stream.js";
  18. describe("stream", function () {
  19. describe("PredictorStream", function () {
  20. it("should decode simple predictor data", function () {
  21. const dict = new Dict();
  22. dict.set("Predictor", 12);
  23. dict.set("Colors", 1);
  24. dict.set("BitsPerComponent", 8);
  25. dict.set("Columns", 2);
  26. const input = new Stream(
  27. new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]),
  28. 0,
  29. 9,
  30. dict
  31. );
  32. const predictor = new PredictorStream(input, /* length = */ 9, dict);
  33. const result = predictor.getBytes(6);
  34. expect(result).toEqual(new Uint8Array([100, 3, 101, 2, 102, 1]));
  35. });
  36. });
  37. });