]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Test correct handling of alpha
authorPierre Ossman <ossman@cendio.se>
Mon, 8 Jun 2020 05:40:56 +0000 (07:40 +0200)
committerPierre Ossman <ossman@cendio.se>
Mon, 8 Jun 2020 05:53:16 +0000 (07:53 +0200)
The forth byte of a pixel is undefined in most encodings, so make sure
the decoders don't leak that through as an alpha channel.

tests/test.hextile.js
tests/test.rre.js

index 406b0628beb1edeceb7055610c979f297147d9fb..7c97527b5d47b8fd895b0c9a9c52c0153233591d 100644 (file)
@@ -45,11 +45,11 @@ describe('Hextile Decoder', function () {
     it('should handle a tile with fg, bg specified, normal subrects', function () {
         let data = [];
         data.push(0x02 | 0x04 | 0x08); // bg spec, fg spec, anysubrects
-        push32(data, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
-        data.push(0xff); // becomes ff0000ff --> #0000FF fg color
+        push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
+        data.push(0xff); // becomes ff000000 --> #0000FF fg color
+        data.push(0x00);
         data.push(0x00);
         data.push(0x00);
-        data.push(0xff);
         data.push(2); // 2 subrects
         data.push(0); // x: 0, y: 0
         data.push(1 | (1 << 4)); // width: 2, height: 2
@@ -82,7 +82,8 @@ describe('Hextile Decoder', function () {
             data.push(targetData[i + 2]);
             data.push(targetData[i + 1]);
             data.push(targetData[i]);
-            data.push(targetData[i + 3]);
+            // Last byte zero to test correct alpha handling
+            data.push(0);
         }
 
         testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
@@ -93,13 +94,13 @@ describe('Hextile Decoder', function () {
     it('should handle a tile with only bg specified (solid bg)', function () {
         let data = [];
         data.push(0x02);
-        push32(data, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
+        push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
 
         testDecodeRect(decoder, 0, 0, 4, 4, data, display, 24);
 
         let expected = [];
         for (let i = 0; i < 16; i++) {
-            push32(expected, 0xff00ff);
+            push32(expected, 0x00ff00ff);
         }
 
         expect(display).to.have.displayed(new Uint8Array(expected));
@@ -113,7 +114,7 @@ describe('Hextile Decoder', function () {
 
         // send a bg frame
         data.push(0x02);
-        push32(data, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
+        push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
 
         // send an empty frame
         data.push(0x00);
@@ -122,10 +123,10 @@ describe('Hextile Decoder', function () {
 
         let expected = [];
         for (let i = 0; i < 16; i++) {
-            push32(expected, 0xff00ff);     // rect 1: solid
+            push32(expected, 0x00ff00ff);     // rect 1: solid
         }
         for (let i = 0; i < 16; i++) {
-            push32(expected, 0xff00ff);    // rect 2: same bkground color
+            push32(expected, 0x00ff00ff);    // rect 2: same bkground color
         }
 
         expect(display).to.have.displayed(new Uint8Array(expected));
@@ -134,18 +135,18 @@ describe('Hextile Decoder', function () {
     it('should handle a tile with bg and coloured subrects', function () {
         let data = [];
         data.push(0x02 | 0x08 | 0x10); // bg spec, anysubrects, colouredsubrects
-        push32(data, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
+        push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
         data.push(2); // 2 subrects
-        data.push(0xff); // becomes ff0000ff --> #0000FF fg color
+        data.push(0xff); // becomes ff000000 --> #0000FF fg color
+        data.push(0x00);
         data.push(0x00);
         data.push(0x00);
-        data.push(0xff);
         data.push(0); // x: 0, y: 0
         data.push(1 | (1 << 4)); // width: 2, height: 2
-        data.push(0xff); // becomes ff0000ff --> #0000FF fg color
+        data.push(0xff); // becomes ff000000 --> #0000FF fg color
+        data.push(0x00);
         data.push(0x00);
         data.push(0x00);
-        data.push(0xff);
         data.push(2 | (2 << 4)); // x: 2, y: 2
         data.push(1 | (1 << 4)); // width: 2, height: 2
 
index a24bec43ab6931a36a3c446a5ead987e8a15102d..78b5eaae60c97b9f72f7e4fda316bfef4cdbe478 100644 (file)
@@ -52,19 +52,19 @@ describe('RRE Decoder', function () {
     it('should handle the RRE encoding', function () {
         let data = [];
         push32(data, 2); // 2 subrects
-        push32(data, 0xff00ff); // becomes 00ff00ff --> #00FF00 bg color
-        data.push(0xff); // becomes ff0000ff --> #0000FF color
+        push32(data, 0x00ff0000); // becomes 00ff0000 --> #00FF00 bg color
+        data.push(0xff); // becomes ff000000 --> #0000FF color
+        data.push(0x00);
         data.push(0x00);
         data.push(0x00);
-        data.push(0xff);
         push16(data, 0); // x: 0
         push16(data, 0); // y: 0
         push16(data, 2); // width: 2
         push16(data, 2); // height: 2
-        data.push(0xff); // becomes ff0000ff --> #0000FF color
+        data.push(0xff); // becomes ff000000 --> #0000FF color
+        data.push(0x00);
         data.push(0x00);
         data.push(0x00);
-        data.push(0xff);
         push16(data, 2); // x: 2
         push16(data, 2); // y: 2
         push16(data, 2); // width: 2