UNPKG

2.35 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 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
24var _stream = require('../../core/stream');
25
26var _primitives = require('../../core/primitives');
27
28describe('stream', function () {
29 beforeEach(function () {
30 jasmine.addMatchers({
31 toMatchTypedArray: function toMatchTypedArray(util, customEqualityTesters) {
32 return {
33 compare: function compare(actual, expected) {
34 var result = {};
35 if (actual.length !== expected.length) {
36 result.pass = false;
37 result.message = 'Array length: ' + actual.length + ', expected: ' + expected.length;
38 return result;
39 }
40 result.pass = true;
41 for (var i = 0, ii = expected.length; i < ii; i++) {
42 var a = actual[i],
43 b = expected[i];
44 if (a !== b) {
45 result.pass = false;
46 break;
47 }
48 }
49 return result;
50 }
51 };
52 }
53 });
54 });
55 describe('PredictorStream', function () {
56 it('should decode simple predictor data', function () {
57 var dict = new _primitives.Dict();
58 dict.set('Predictor', 12);
59 dict.set('Colors', 1);
60 dict.set('BitsPerComponent', 8);
61 dict.set('Columns', 2);
62 var input = new _stream.Stream(new Uint8Array([2, 100, 3, 2, 1, 255, 2, 1, 255]), 0, 9, dict);
63 var predictor = new _stream.PredictorStream(input, 9, dict);
64 var result = predictor.getBytes(6);
65 expect(result).toMatchTypedArray(new Uint8Array([100, 3, 101, 2, 102, 1]));
66 });
67 });
68});
\No newline at end of file