MCPcopy Create free account
hub / github.com/apache/cloudstack / decodeRect

Method decodeRect

systemvm/agent/noVNC/core/decoders/jpeg.js:20–87  ·  view source on GitHub ↗
(x, y, width, height, sock, display, depth)

Source from the content-addressed store, hash-verified

18 }
19
20 decodeRect(x, y, width, height, sock, display, depth) {
21 // A rect of JPEG encodings is simply a JPEG file
22 while (true) {
23 let segment = this._readSegment(sock);
24 if (segment === null) {
25 return false;
26 }
27 this._segments.push(segment);
28 // End of image?
29 if (segment[1] === 0xD9) {
30 break;
31 }
32 }
33
34 let huffmanTables = [];
35 let quantTables = [];
36 for (let segment of this._segments) {
37 let type = segment[1];
38 if (type === 0xC4) {
39 // Huffman tables
40 huffmanTables.push(segment);
41 } else if (type === 0xDB) {
42 // Quantization tables
43 quantTables.push(segment);
44 }
45 }
46
47 const sofIndex = this._segments.findIndex(
48 x => x[1] == 0xC0 || x[1] == 0xC2
49 );
50 if (sofIndex == -1) {
51 throw new Error("Illegal JPEG image without SOF");
52 }
53
54 if (quantTables.length === 0) {
55 this._segments.splice(sofIndex+1, 0,
56 ...this._cachedQuantTables);
57 }
58 if (huffmanTables.length === 0) {
59 this._segments.splice(sofIndex+1, 0,
60 ...this._cachedHuffmanTables);
61 }
62
63 let length = 0;
64 for (let segment of this._segments) {
65 length += segment.length;
66 }
67
68 let data = new Uint8Array(length);
69 length = 0;
70 for (let segment of this._segments) {
71 data.set(segment, length);
72 length += segment.length;
73 }
74
75 display.imageRect(x, y, width, height, "image/jpeg", data);
76
77 if (huffmanTables.length !== 0) {

Callers

nothing calls this directly

Calls 3

_readSegmentMethod · 0.95
imageRectMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected