├── .gitignore ├── .travis.yml ├── GLOSSORY.md ├── LICENSE ├── README.md ├── SUMMARY.md ├── book.json ├── handshake ├── README.md ├── initial.md ├── protocol-version.md └── security-type.md ├── package-lock.json ├── package.json └── transfer ├── README.md ├── display.md ├── encoding ├── README.md ├── copy-rect.md ├── raw.md ├── rise-and-run-length.md ├── set-encoding.md ├── tiled-run-length.md └── zlib-run-length.md ├── input ├── README.md ├── clipboard.md ├── keyboard.md └── mouse.md ├── pixel-format.md └── set-color-map.md /.gitignore: -------------------------------------------------------------------------------- 1 | _book/ 2 | node_modules/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | cache: npm 5 | 6 | notifications: 7 | pushover: 8 | api_key: "$PUSHOVER_KEY" 9 | users: 10 | - "$PUSHOVER_USER" 11 | on_success: change 12 | on_failure: always 13 | 14 | install: 15 | - sudo apt-get install jq 16 | - npm install -g gitbook-cli 17 | - npm install gitbook-plugin-sitemap 18 | - npm install 19 | - gitbook install 20 | 21 | script: 22 | - cat <<< $(jq --arg secret "$GITTALK_SECRET" '.pluginsConfig.gittalk.clientSecret = $secret' book.json) > book.json 23 | - gitbook build 24 | 25 | branches: 26 | only: 27 | - main 28 | 29 | deploy: 30 | provider: pages 31 | local_dir: _book 32 | skip_cleanup: true 33 | github_token: $GITHUB_TOKEN 34 | keep_history: true 35 | fqdn: rfb.vincentcui.cn 36 | on: 37 | branch: main -------------------------------------------------------------------------------- /GLOSSORY.md: -------------------------------------------------------------------------------- 1 | # 帧缓冲 2 | 3 | 帧缓冲器也称为帧缓冲或者显存,是用来存储渲染数据的地方。帧缓冲的每一个存储单位对应一个像素,它是屏幕显示画面的直接映象,又称为位映射图(Bit Map)。 4 | 5 | ![帧缓冲器](http://babeler-1251731700.cos.ap-shanghai.myqcloud.com/2021-08-15-022750.jpg) 6 | 7 | # 调色板 8 | 9 | 传统的帧缓冲器支持的色彩模式很广泛。受限于昂贵的内存,大多数早期的帧缓冲器使用的是1位、2位、4位或 8位的色深。小的色深导致不能产生完整的色彩范围。其解决方法是为帧缓冲器增加一个查找表(lookup table,LUT),把帧缓冲器中存储的每个“颜色”作为一个索引。这就是所谓的索引色(indexed color)模式。 10 | 11 | ![调色板](http://babeler-1251731700.cos.ap-shanghai.myqcloud.com/2021-08-15-021319.jpg) 12 | 13 | # 游程编码 14 | 15 | 游程编码(run-length encoding,RLE)是一种比较简单的压缩算法,其基本思想是将重复且连续出现多次的字符使用(连续出现次数,某个字符)来描述。 16 | 17 | 举例来说,字符串"AAAABBBCCDEEEE",由4个A、3个B、2个C、1个D、4个E组成,游程编码将其压缩为4A3B2C1D4E,由14个字符转成10个字符,压缩比 71.4%。 18 | 19 | 游程编码的优点是将重复性高的数据压缩成小单位;若数据出现频率不高,压缩结果可能比原始数据大。例如:"ABCDE",压缩结果为"1A1B1C1D1E",由5个字符转成10个字符,压缩比 200%。 20 | 21 | ![游程编码](http://babeler-1251731700.cos.ap-shanghai.myqcloud.com/2021-08-15-022914.jpg) 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public licenses. 411 | Notwithstanding, Creative Commons may elect to apply one of its public 412 | licenses to material it publishes and in those instances will be 413 | considered the “Licensor.” The text of the Creative Commons public 414 | licenses is dedicated to the public domain under the CC0 Public Domain 415 | Dedication. Except for the limited purpose of indicating that material 416 | is shared under a Creative Commons public license or as otherwise 417 | permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the public 425 | licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 远程帧缓冲协议 2 | 3 | ## RFB 协议 4 | 5 | RFB (Remote Framebuffer Protocol) 远程帧缓冲协议,是一种允许用户通过网络连接控制远端计算机的七层网络协议。 6 | 在 RFB 协议中,用户通过本地鼠标、键盘输入,经由远端计算机计算后,将图形用户界面(GUI)回传本地进行输出。 7 | 8 | ![RFB 协议通信](http://babeler-1251731700.cos.ap-shanghai.myqcloud.com/2021-08-07-085929.png) 9 | 10 | ### 协议特点 11 | 12 | 协议设计有以下几个特点: 13 | 14 | - 瘦客户端。客户端职责简单清晰,无状态 15 | - 运行在弱网络环境下 16 | - 跨操作系统兼容性 17 | 18 | ## 协议版本 19 | 20 | RFB 协议有三个公开版本,分别是 3.3、3.7和3.8,3.8 是稳定版本。 21 | 22 | 版本 | 发布时间 | 协议差异 23 | :---: | :---: | :---: 24 | Version 3.3 | 1998-01 | 服务器单向认证 25 | Version 3.7 | 2003-8-12 | 关闭连接时返回原因 26 | Version 3.8 (Final) | 2010-11-26 | - 27 | 28 | 三个版本只在协议的握手阶段和初始化阶段存在差异,在数据流交换阶段保持一致。 29 | 30 | ### 协议的拓展 31 | 32 | 第三方 VNC 服务端和客户端拓展了 3.8 版本协议,提供更多的认证方式,优化传输效率。 33 | 34 | - Tight 35 | - RealVNC 36 | - Ultra 37 | - VMWare 38 | 39 | ## RFB 的发展历史 40 | 41 | - 2002 年,AT&T 关闭其位于英国剑桥的 Olivetti 研究实验室。 42 | - 2002 年,VNC 技术发明者 Tristan Richardson 合伙成立 RealVNC 公司,向商业公司提供企业级远程访问软件。 43 | - 2003年8月12日,Richardson 公开 RFB 协议的 3.7 版本。 44 | - 2010年11月26日,发布稳定协议版本 v3.8。 45 | 46 | > RFB 是 IETF 公开的开源通信协议 47 | > 48 | > RFB® 和 VNC® 是 RealVNC 公司的注册商标。 49 | 50 | ## 公开协议版本及资料 51 | 52 | - [RFC 6143: The Remote Framebuffer Protocol (describes Version 3.8)](https://tools.ietf.org/html/rfc6143) 53 | - [The RFB Protocol - Community Version](https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst) 54 | - [The RFB Protocol - Version 3.8 (2010-11-26)](https://web.archive.org/web/20160410055332/http://www.realvnc.com/docs/rfbproto.pdf) 55 | - [The RFB Protocol - Version 3.7 (2003-08-12)](https://web.archive.org/web/20040325204925/http://www.realvnc.com/docs/rfbproto.pdf) 56 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # 目录 2 | 3 | - [远程帧缓冲协议](README.md) 4 | - [术语表](GLOSSORY.md) 5 | - [握手](handshake/README.md) 6 | - [协议版本握手](handshake/protocol-version.md) 7 | - [安全握手](handshake/security-type.md) 8 | - [初始化](handshake/initial.md) 9 | - [数据交互](transfer/README.md) 10 | - [显示协议](transfer/display.md) 11 | - [像素格式](transfer/pixel-format.md) 12 | - [输入协议](transfer/input/README.md) 13 | - [鼠标事件](transfer/input/mouse.md) 14 | - [键盘事件](transfer/input/keyboard.md) 15 | - [剪贴板](transfer/input/clipboard.md) 16 | - [编码](transfer/encoding/README.md) 17 | - [设置编码](transfer/encoding/set-encoding.md) 18 | - [Raw 原始编码](transfer/encoding/raw.md) 19 | - [CopyRect 镜像编码](transfer/encoding/copy-rect.md) 20 | - [RRE 上升游程编码](transfer/encoding/rise-and-run-length.md) 21 | - [TRLE 图块游程编码](transfer/encoding/tiled-run-length.md) 22 | - [ZRLE Zlib游程编码](transfer/encoding/zlib-run-length.md) 23 | -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "RFB 远程帧缓冲协议", 3 | "plugins": [ 4 | "-sharing", 5 | "-lunr", 6 | "-search", 7 | "search-pro", 8 | "expandable-chapters", 9 | "mermaid-v8", 10 | "back-to-top-button", 11 | "github", 12 | "prism", 13 | "-highlight", 14 | "icp", 15 | "hide-element", 16 | "gittalk", 17 | "sitemap", 18 | "ga", 19 | "tbfed-pagefooter", 20 | "pageview-busuanzi" 21 | ], 22 | "pluginsConfig": { 23 | "github": { 24 | "url": "https://github.com/vincenthcui/rfc6143" 25 | }, 26 | "icp": { 27 | "number": "粤ICP备20027265号-1", 28 | "link": "http://beian.miit.gov.cn/" 29 | }, 30 | "hide-element": { 31 | "elements": ["a[href=\"https://www.gitbook.com\"]"] 32 | }, 33 | "gittalk": { 34 | "clientID": "0d25ffc9a6f2a3194eec", 35 | "clientSecret": "", 36 | "repo": "rfc6143", 37 | "owner": "vincenthcui", 38 | "admin": ["vincenthcui"], 39 | "distractionFreeMode": false 40 | }, 41 | "sitemap": { 42 | "hostname": "https://rfb.vincentcui.cn/" 43 | }, 44 | "ga": { 45 | "token": "UA-204324591-1" 46 | }, 47 | 48 | "tbfed-pagefooter": { 49 | "copyright": "Copyright © Vincent.H.Cui 2021", 50 | "modify_label": "最后更新:", 51 | "modify_format": "YYYY-MM-DD HH:mm" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /handshake/README.md: -------------------------------------------------------------------------------- 1 | # 握手 2 | 3 | RFB 协议有四个阶段: 4 | 5 | ```mermaid 6 | graph LR 7 | protocol["协议握手"] 8 | auth["认证"] 9 | initial["初始化"] 10 | transfer("数据交互") 11 | subgraph 握手 12 | protocol --> auth 13 | auth --> initial 14 | end 15 | initial --> transfer 16 | transfer --> transfer 17 | ``` 18 | 19 | - [协议握手](/handshake/protocol-version.md):对协议版本达成共识 20 | - [认证](/handshake/security-type.md):认证客户端身份 21 | - [初始化](/handshake/initial.md):交换像素格式等背景数据 22 | - [数据交互](/transfer/README.md):传输交互事件,更新图像帧 23 | -------------------------------------------------------------------------------- /handshake/initial.md: -------------------------------------------------------------------------------- 1 | # 初始化 2 | 3 | 收 SecurityResult 后,客户端应当发送 [ClientInit](#客户端初始化) 数据包,收到后,服务端发送 [ServerInit](#服务端初始化) 包。 4 | 5 | ```mermaid 6 | sequenceDiagram 7 | participant Client 8 | participant Server 9 | Server->>Client: SecurityResult(success) 10 | Client->>Server: ClientInit 11 | Server->>Client: ServerInit 12 | ``` 13 | 14 | ## 客户端初始化 15 | 16 | 客户端初始化需要声明是否的共享屏幕。 17 | 18 | ``` 19 | +--------------+--------------+-------------+ 20 | | No. of bytes | Type [Value] | Description | 21 | +--------------+--------------+-------------+ 22 | | 1 | U8 | shared-flag | 23 | +--------------+--------------+-------------+ 24 | ``` 25 | 26 | - shared-flag: 是否与其他客户端共享连接。如果是 1,允许服务端保持/加入其他客户端的连接。如果是0,服务端应该主动断开与其他客户端的连接。 27 | 28 | ## 服务端初始化 29 | 30 | 收到 ClientInit 消息后,服务端发送 ServerInit 消息,声明帧缓冲区大小、像素格式以及桌面的名称。 31 | 32 | ``` 33 | +--------------+--------------+------------------------------+ 34 | | No. of bytes | Type [Value] | Description | 35 | +--------------+--------------+------------------------------+ 36 | | 2 | U16 | framebuffer-width in pixels | 37 | | 2 | U16 | framebuffer-height in pixels | 38 | | 16 | PIXEL_FORMAT | server-pixel-format | 39 | | 4 | U32 | name-length | 40 | | name-length | U8 array | name-string | 41 | +--------------+--------------+------------------------------+ 42 | ``` 43 | 44 | - framebuffer-width in pixels: 屏幕宽度 45 | - framebuffer-height in pixels: 屏幕高度 46 | - server-pixel-format: 服务器默认像素格式 47 | - name-length/name-string: 桌面的名字 48 | 49 | 如果客户端无法响应服务端指定的 pixel-format,可以主动发起 [SetPixelFormat](/display/pixel-format.md#SetPixelFormat) 重新设置。 50 | -------------------------------------------------------------------------------- /handshake/protocol-version.md: -------------------------------------------------------------------------------- 1 | 2 | # 协议握手 3 | 4 | 协议握手对客户端和服务端通信过程使用的协议版本达成共识,有可能的情况下,对不同协议版本实现向前兼容。 5 | 6 | ## 握手过程 7 | 8 | 建立 TCP 连接后,服务器首先向客户端发送版本 X,收到 X 后,客户端向服务器发送不高于 X 的版本 Y。 9 | 10 | RFB 有三个公开可选版本 3.3/3.7/3.8。 11 | 12 | 部分客户端或浏览器变种可能会发送其他的协议版本,统一将非标协议认定为 3.3(协议认为未公开协议版本没有实现3.7/3.8 中引入的特殊握手流程)。 13 | 14 | ```mermaid 15 | sequenceDiagram 16 | participant Client 17 | participant Server 18 | Server->>Client: ProtocolVersion 19 | Client->>Server: ProtocolVersion 20 | ``` 21 | 22 | ## 协议报文 23 | 24 | 协议消息由标识符、主次版本组成,其结构体如下: 25 | 26 | ``` 27 | +--------------+--------------+--------------+ 28 | | No. of bytes | Type [Value] | Description | 29 | +--------------+--------------+--------------+ 30 | | 3 | U8 array | protocol | 31 | | 1 | U8 [32] | blank | 32 | | 3 | U8 array | major version| 33 | | 1 | U8 [42] | pot | 34 | | 3 | U8 array | minor version| 35 | +--------------+--------------+--------------+ 36 | ``` 37 | 38 | 对于 3.8 版本协议,其发送协议头部如下: 39 | 40 | ``` 41 | RFB 003.008\n (hex 52 46 42 20 30 30 33 2e 30 30 38 0a) 42 | ``` 43 | -------------------------------------------------------------------------------- /handshake/security-type.md: -------------------------------------------------------------------------------- 1 | # 安全握手 2 | 3 | 协商好协议版本后,客户端和服务端进行安全握手,就认证方式达成共识,并完成认证过程。 4 | 5 | ## 握手过程 6 | 7 | 认证的流程图如下: 8 | 9 | ```mermaid 10 | sequenceDiagram 11 | participant Client 12 | participant Server 13 | 14 | alt incompatible 15 | Server->>Client: SecurityTypes(Empty) 16 | Server->>Client: FailReason 17 | Server-XClient: Close 18 | end 19 | 20 | Server->>Client: SecurityTypes 21 | Client->>Server: SecurityType 22 | 23 | alt None 24 | else VNC Auth 25 | Server->>Client: Challenge 26 | Client->>Server: ChallengeResponse 27 | end 28 | 29 | Server->>Client: SecurityResult 30 | alt failed 31 | Server->>Client: FailReason 32 | Server-XClient: Close 33 | end 34 | ``` 35 | 36 | - 服务器向客户端列举支持的加密方式,客户端挑选支持的认证方式,告知服务端。 37 | - 根据认证方式,完成认证 38 | - 服务端返回认证结果,完成安全握手 39 | 40 | ## 协议报文 41 | 42 | ### security-types 43 | 44 | ``` 45 | +--------------------------+-------------+--------------------------+ 46 | | No. of bytes | Type | Description | 47 | | | [Value] | | 48 | +--------------------------+-------------+--------------------------+ 49 | | 1 | U8 | number-of-security-types | 50 | | number-of-security-types | U8 array | security-types | 51 | +--------------------------+-------------+--------------------------+ 52 | ``` 53 | 54 | - number-of-security-types: 认证方式数量 55 | - security-types: 认证方式标识符 56 | 57 | 协议定义的标识符有三种,剩下的由协议厂家进行拓展: 58 | 59 | ``` 60 | +--------+--------------------+ 61 | | Number | Name | 62 | +--------+--------------------+ 63 | | 0 | Invalid | 64 | | 1 | None | 65 | | 2 | VNC Authentication | 66 | +--------+--------------------+ 67 | ``` 68 | 69 | ### security-type 70 | 71 | 客户端以单字节报文告知选择的认证方式 72 | 73 | ``` 74 | +--------------+--------------+---------------+ 75 | | No. of bytes | Type [Value] | Description | 76 | +--------------+--------------+---------------+ 77 | | 1 | U8 | security-type | 78 | +--------------+--------------+---------------+ 79 | ``` 80 | 81 | - security-type: 达成共识的协议标识符 82 | 83 | ### fail-reason 84 | 85 | 当错误发送时,例如,服务端不兼容客户端版本,服务端会发送空的 SecurityTypes,发送消息说明错误原因后,关闭连接。 86 | 87 | FailReason 报文如下: 88 | 89 | ``` 90 | +---------------+--------------+---------------+ 91 | | No. of bytes | Type [Value] | Description | 92 | +---------------+--------------+---------------+ 93 | | 4 | U32 | reason-length | 94 | | reason-length | U8 array | reason-string | 95 | +---------------+--------------+---------------+ 96 | ``` 97 | 98 | - reason-length: 原因长度 99 | - reason-string: 错误原因 100 | 101 | ### VNC Auth 102 | 103 | VNC Auth 过程,服务器首先发送 16 字节的随机字符串,作为 `challenge`。客户端用密码通过 `DES` 算法对 `challenge` 进行加密,将加密后的 16 字节结果告知服务端。 104 | 105 | > TODO: 加密算法详解 106 | 107 | 有几点需要注意: 108 | 109 | - 为格式化密钥,密码会被删节/补齐为 8 字符 110 | - VNC Auth 是弱加密,不能用于不可信网络 111 | - 为了更安全访问,可以通过 IPsec/SSH 加密链路 112 | 113 | #### Challenge 114 | 115 | ``` 116 | +--------------+--------------+-------------+ 117 | | No. of bytes | Type [Value] | Description | 118 | +--------------+--------------+-------------+ 119 | | 16 | U8 | challenge | 120 | +--------------+--------------+-------------+ 121 | ``` 122 | 123 | #### ChallengeResponse 124 | 125 | ``` 126 | +--------------+--------------+-------------+ 127 | | No. of bytes | Type [Value] | Description | 128 | +--------------+--------------+-------------+ 129 | | 16 | U8 | response | 130 | +--------------+--------------+-------------+ 131 | ``` 132 | 133 | ### SecurityResult 134 | 135 | 客户端选择认证方式后,服务端返回 SecurityResult 告知认证结果,哪怕使用 `None` 认证。 136 | 137 | 如果认证失败,服务器发送 `failed` 和 fail-reason 报文,主动关闭连接。 138 | 139 | ``` 140 | +--------------+--------------+-------------+ 141 | | No. of bytes | Type [Value] | Description | 142 | +--------------+--------------+-------------+ 143 | | 4 | U32 | status: | 144 | | | 0 | OK | 145 | | | 1 | failed | 146 | +--------------+--------------+-------------+ 147 | ``` 148 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "gitbook-plugin-mermaid-v8": "^0.3.0", 4 | "gitbook-plugin-sitemap": "^1.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /transfer/README.md: -------------------------------------------------------------------------------- 1 | # 数据交互 2 | 3 | 数据交互阶段,客户端向服务端发送鼠标、键盘事件,或请求更新图像。 4 | 5 | ```mermaid 6 | graph LR 7 | A("鼠标事件") 8 | B("键盘事件") 9 | C("更新图像") 10 | ``` 11 | -------------------------------------------------------------------------------- /transfer/display.md: -------------------------------------------------------------------------------- 1 | # 显示协议 2 | 3 | 客户端可能处于弱网络环境,或只有较低性能的渲染设备。如果服务端不加限制的向客户端发送像素画面,很容易造成客户端卡死或网络堵塞。 4 | 5 | 在 RFB 协议中,当且仅当客户端主动请求显示数据时,服务端才会将 [FramebufferUpdate](#FramebufferUpdate) 发往客户端。响应 [FramebufferUpdateRequest](#FramebufferUpdateRequest) 往往需要返回多条 FramebufferUpdate。 6 | 7 | 8 | ```mermaid 9 | sequenceDiagram 10 | participant Client 11 | participant Server 12 | Client->>Server: FramebufferUpdateRequest 13 | loop no change 14 | Client->>Server: FramebufferUpdateRequest 15 | 16 | end 17 | Server->>Client: FramebufferUpdate 18 | Server->>Client: FramebufferUpdate 19 | Server->>Client: FramebufferUpdate 20 | ``` 21 | 22 | ## FramebufferUpdateRequest 23 | 24 | FramebufferUpdateRequest 告知服务端,客户端希望得到指定区域的内容。 25 | 26 | ``` 27 | +--------------+--------------+--------------+ 28 | | No. of bytes | Type [Value] | Description | 29 | +--------------+--------------+--------------+ 30 | | 1 | U8 [3] | message-type | 31 | | 1 | U8 | incremental | 32 | | 2 | U16 | x-position | 33 | | 2 | U16 | y-position | 34 | | 2 | U16 | width | 35 | | 2 | U16 | height | 36 | +--------------+--------------+--------------+ 37 | ``` 38 | 39 | - message-type: 消息类型,固定 `3` 40 | - incremental: 是否是增量请求。 41 | - x-position/y-position: 区域的起始坐标 42 | - width/height: 区域的长度和宽度 43 | 44 | incremental 通常为非 0 值,服务器只需要发有变化的图像信息。当客户端丢失了缓存的帧缓冲信息,或者刚建立连接,需要完整的图像信息时,将 incremental 置为 0,获取全量信息。 45 | 46 | ## FramebufferUpdate 47 | 48 | FramebufferUpdate 由一组矩形图像(rectangles of pixel)组成,客户端收到 FramebufferUpdate 消息后,将消息内的矩形填充到帧缓冲对应区域,完成图像展示。 49 | 50 | ``` 51 | +--------------+--------------+----------------------+ 52 | | No. of bytes | Type [Value] | Description | 53 | +--------------+--------------+----------------------+ 54 | | 1 | U8 [0] | message-type | 55 | | 1 | | padding | 56 | | 2 | U16 | number-of-rectangles | 57 | +--------------+--------------+----------------------+ 58 | ``` 59 | 60 | - message-type: 消息类型,固定 0 61 | - number-of-rectangles: 矩形的数量 62 | 63 | ### FramebufferUpdateRectangle 64 | 65 | FramebufferUpdate 携带 `number-of-rectangles` 数量的矩形信息,每个矩形都有头部信息 66 | 67 | ``` 68 | +--------------+--------------+---------------+ 69 | | No. of bytes | Type [Value] | Description | 70 | +--------------+--------------+---------------+ 71 | | 2 | U16 | x-position | 72 | | 2 | U16 | y-position | 73 | | 2 | U16 | width | 74 | | 2 | U16 | height | 75 | | 4 | S32 | encoding-type | 76 | +--------------+--------------+---------------+ 77 | ``` 78 | 79 | - x-position/y-position: 矩形起始坐标 80 | - width/height: 矩形宽度和高度 81 | - encoding-type: 编码类型 82 | -------------------------------------------------------------------------------- /transfer/encoding/README.md: -------------------------------------------------------------------------------- 1 | # 编码 2 | 3 | ”编码“ 是像素数据的表达方式。在发往客户端前,服务器经常将发送的图形数据进行编码、压缩,提高图像传输效率。 4 | 5 | ``` 6 | +--------+-----------------------------+ 7 | | Number | Name | 8 | +--------+-----------------------------+ 9 | | 0 | Raw | 10 | | 1 | CopyRect | 11 | | 2 | RRE | 12 | | 5 | Hextile | 13 | | 15 | TRLE | 14 | | 16 | ZRLE | 15 | | -239 | Cursor pseudo-encoding | 16 | | -223 | DesktopSize pseudo-encoding | 17 | +--------+-----------------------------+ 18 | ``` 19 | 20 | - [Raw](/transfer/encoding/raw.md): 原始位图编码,即不编码 21 | - [CopyRect](/transfer/encoding/copy-rect.md): 从帧缓冲复制 22 | - [RRE](/transfer/encoding/rise-and-run-length.md): rise-and-run-length 二维游程编码 23 | - Hextile: RRE 的变种,图块游程编码 24 | - [TRLE](/transfer/encoding/tiled-run-length.md): 图块游程编码 25 | - [ZRLE](/transfer/encoding/zlib-run-length.md): Zlib Run-Length Encoding,zlib 压缩的游程编码 26 | - Cursor pseudo-encoding: 鼠标指针伪编码 27 | - DesktopSize pseudo-encoding: 桌面分辨率伪编码 28 | -------------------------------------------------------------------------------- /transfer/encoding/copy-rect.md: -------------------------------------------------------------------------------- 1 | # 镜像编码 Copy Rect 2 | 3 | CopyRect 指示客户端,从已有帧缓冲区域复制到新区域。这种编码常用于窗口拖动、页面滚动等场景。 4 | 5 | 报文只说明起始坐标,区域的长度和宽度由 [FramebufferUpdateRectangle](/display/display.md#FramebufferUpdateRectangle) 指定。 6 | 7 | ``` 8 | +--------------+--------------+----------------+ 9 | | No. of bytes | Type [Value] | Description | 10 | +--------------+--------------+----------------+ 11 | | 2 | U16 | src-x-position | 12 | | 2 | U16 | src-y-position | 13 | +--------------+--------------+----------------+ 14 | ``` 15 | 16 | - src-x-position/src-y-position: 源图像的起点坐标 17 | -------------------------------------------------------------------------------- /transfer/encoding/raw.md: -------------------------------------------------------------------------------- 1 | # Raw 原始编码 2 | 3 | Raw 是最简单也是最原始的编码,直接向客户端传递位图信息,不进行编码优化。 4 | 在 Raw 格式中,像素按从左到右,从上到下的顺序排列成一维数组。 5 | 6 | > 协议要求客户端必须支持 Raw 类型编码。 7 | > 8 | > 协议要求服务器必须传输 Raw 类型编码,除非客户端另有要求。 9 | 10 | ``` 11 | +----------------------------+--------------+-------------+ 12 | | No. of bytes | Type [Value] | Description | 13 | +----------------------------+--------------+-------------+ 14 | | width*height*bytesPerPixel | PIXEL array | pixels | 15 | +----------------------------+--------------+-------------+ 16 | ``` 17 | 18 | - pixels: 像素数组 19 | -------------------------------------------------------------------------------- /transfer/encoding/rise-and-run-length.md: -------------------------------------------------------------------------------- 1 | # 上升和游程编码 Rise-and-run-length 2 | 3 | RRE 是游程编码的二维变种。基本思想是将大的矩形拆分为子矩形,每个子矩形有单值的像素组成,所有小矩形的并集构成原始矩形区域。 4 | 5 | 编码由背景像素值 Vb 、计数 N ,以及 N 个子矩形列表组成。子矩形由元组 表示,其中 v 是像素值(v != Vb),x/y/w/h 表示子矩形相对主矩形的坐标,和大小。 6 | 7 | 绘制时,客户端先以背景像素值填充矩形,再绘制每个子矩形,叠加出原始图像。 8 | 9 | ``` 10 | +---------------+--------------+-------------------------+ 11 | | No. of bytes | Type [Value] | Description | 12 | +---------------+--------------+-------------------------+ 13 | | 4 | U32 | number-of-subrectangles | 14 | | bytesPerPixel | PIXEL | background-pixel-value | 15 | +---------------+--------------+-------------------------+ 16 | ``` 17 | 18 | - number-of-subrectangles: 子矩形数量 19 | - background-pixel-value: 矩形背景色 20 | 21 | 对于子矩形 22 | 23 | ``` 24 | +---------------+--------------+---------------------+ 25 | | No. of bytes | Type [Value] | Description | 26 | +---------------+--------------+---------------------+ 27 | | bytesPerPixel | PIXEL | subrect-pixel-value | 28 | | 2 | U16 | x-position | 29 | | 2 | U16 | y-position | 30 | | 2 | U16 | width | 31 | | 2 | U16 | height | 32 | +---------------+--------------+---------------------+ 33 | ``` 34 | 35 | - subrect-pixel-value: 子矩形色值 36 | - x-position/y-position: 与背景矩行的**相对位置** 37 | - width/height: 子矩形宽度和高度 38 | -------------------------------------------------------------------------------- /transfer/encoding/set-encoding.md: -------------------------------------------------------------------------------- 1 | # 设置编码 2 | 3 | 客户端用 SetEncoding 消息告知服务端,接受哪些像素[编码](/transfer/encoding/README.md)。 4 | 5 | 除了用于解析像素的编码外,客户端可以发送伪编码,向服务端请求拓展功能。如果服务端不识别此编码,可以直接忽略。客户端在未收到服务端明确的”支持“回复前,应当默认服务端不支持伪编码。 6 | 7 | 数据结构如下: 8 | 9 | ``` 10 | +-----------------------+--------------+---------------------+ 11 | | No. of bytes | Type [Value] | Description | 12 | +-----------------------+--------------+---------------------+ 13 | | 1 | U8 [2] | message-type | 14 | | 1 | | padding | 15 | | 2 | U16 | number-of-encodings | 16 | | 4*number-of-encodings | S32 array | encoding-types | 17 | +-----------------------+--------------+---------------------+ 18 | ``` 19 | 20 | - message-type: 消息类型,固定为 `2` 21 | - number-of-encodings: 编码数量 22 | - encoding-types: [编码标识符](/transfer/encoding/README.md) 23 | -------------------------------------------------------------------------------- /transfer/encoding/tiled-run-length.md: -------------------------------------------------------------------------------- 1 | # 图块游程编码 TRLE 2 | 3 | TRLE(Tiled Run-Length Encoding),使用图块压缩技术、调色板技术以及游程编码,对传输的桌面图像进行压缩。 4 | 5 | 在图块压缩技术中,传输图像被分为 N 个 16x16 的小图块,图块按从左到右,从上到下的顺序排列成一位数组。如果传输图像的尺寸不是 16 的整数倍,最后一列/最后一行图块的宽度/高度应为实际宽度/实际高度(小于16)。 6 | 7 | TRLE 使用 CPIXEL(compressed pixel) 表示像素。CPIXEL 同样由 [PIXEL_FORMAT](/display/pixel-format.md) 定义。 8 | 在特殊情况下,CPIXEL 使用更紧凑的结构表示像素。 9 | 假如 PIXEL_FORMAT 中 true-color-flag 是非零值,bits-per-pixel 是 32,depth 是 24 或更小,只会用低 3 bit 或者高 3 bit 来表达红、绿、蓝。 10 | 11 | ## 子编码 12 | 13 | 图块使用头部单字节表示图块的子编码类型。 14 | 子编码类型的最高比特表示当前图块是否使用游程编码。 15 | 低 7-bit 指示调色板的大小。 16 | 17 | ``` 18 | +---------------+--------------+------------------+ 19 | | No. of bits | Type [Value] | Description | 20 | +------------------------------+------------------+ 21 | | 1 | bit | run-length-flag | 22 | | 2-8 | bit | palette-length | 23 | +------------------------------+------------------+ 24 | ``` 25 | 26 | TRLE 对自编码的值有单独定义 27 | 28 | 十六进制 | 十进制 | 含义 | 29 | --- | --- | --- | 30 | 0x00 | 0 | [Raw 模式](#raw-模式),不使用游程和调色板 | 31 | 0x01 | 1 | [纯色模式](#纯色模式),图块使用同一种颜色 | 32 | 0x02 - 0x10 | 2 - 16 | [打包像素调色板模式](#打包像素调色板模式) | 33 | 0x11 - 0x7E | 17 - 126 | 保留 | 34 | 0x7F | 127 | [打包像素调色板模式](#打包像素调色板模式),复用调色板 | 35 | 0x80 | 128 | [RLE 模式](#rle-模式) | 36 | 0x81 | 129 | [调色板游程编码](#调色板游程编码),复用调色板 | 37 | 0x82 - 0xFF | 130 - 255 | [调色板游程编码](#调色板游程编码) | 38 | 39 | 40 | 41 | ### Raw 模式 42 | 43 | Raw 模式直接传输像素值,像素在图块中按从左到右、从上到下排列。不使用游程编码,不使用调色板。 44 | 45 | ``` 46 | +-----------------------------+----------------+--------------+ 47 | | No. of bytes | Type [Value] | Description | 48 | +-----------------------------+----------------+--------------+ 49 | | 1 | SubEncoding[0] | sub-encoding | 50 | | width*height*BytesPerCPixel | CPIXEL array | pixels | 51 | +-----------------------------+----------------+--------------+ 52 | ``` 53 | 54 | ### 纯色模式 55 | 56 | 图块使用同一种颜色。 57 | 58 | ``` 59 | +----------------+----------------+--------------+ 60 | | No. of bytes | Type [Value] | Description | 61 | +----------------+----------------+--------------+ 62 | | 1 | SubEncoding[1] | sub-encoding | 63 | | bytesPerCPixel | CPIXEL | pixelValue | 64 | +----------------+----------------+--------------+ 65 | ``` 66 | 67 | ### 打包像素调色板模式 68 | 69 | 打包像素调色板模式。使用调色板定义颜色,使用颜色在调色板中的偏移量表达颜色。由于调色板较小,可以将多个像素的色值打包到一个字节中存储,进一步压缩体积。 70 | 71 | 每个像素使用的 bit 数由调色板大小确定,N=log2 M。 72 | 如果像素的数量不是 2/4/8 的倍数,需要添加填充位,对齐字节。 73 | 74 | |调色板大小|像素比特数|打包后字节数| 75 | |:---:|:---:|---| 76 | |=2|1|m = (width+7) // 8 *height| 77 | |<=4|2|m = (width+3) // 4 * height| 78 | |<=16|4|m = (width+1) // 2 * height| 79 | 80 | ``` 81 | +----------------------------+--------------+--------------+ 82 | | No. of bytes | Type [Value] | Description | 83 | +----------------------------+--------------+--------------+ 84 | | 1 | SubEncoding | sub-encoding | 85 | | paletteSize*bytesPerCPixel | CPIXEL array | palette | 86 | | m | U8 array | packedPixels | 87 | +----------------------------+--------------+--------------+ 88 | ``` 89 | 90 | ### RLE 模式 91 | 92 | RLE 模式,不使用调色板,使用游程编码。在计算游程时,允许跨行计算。 93 | 长度由一个或多个字节表示,到第一个不是 255(0xFF)停止。 94 | 95 | ``` 96 | +-------------------------+------------------+-----------------------+ 97 | | No. of bytes | Type [Value] | Description | 98 | +-------------------------+------------------+-----------------------+ 99 | | 1 | SubEncoding[128] | sub-encoding | 100 | | bytesPerCPixel | CPIXEL | pixelValue | 101 | | div(runLength - 1, 255) | U8 array | 255 | 102 | | 1 | U8 | (runLength-1) mod 255 | 103 | +-------------------------+------------------+-----------------------+ 104 | ``` 105 | 106 | 例如: 107 | 108 | |游程长度|字节表示| 109 | |:---:|:---:| 110 | |1|0x00| 111 | |255|0xFE| 112 | |256| 0xFF00| 113 | |257|0xFF01| 114 | |510|0xFFFE| 115 | |511|0xFFFF00| 116 | 117 | 118 | ### 调色板游程编码 119 | 120 | 调色板游程编码。使用调色板,游程部分类似[RLE 模式](#rle-模式),将像素放入数组后,使用像素加游程的方式表示整个色块,像素用调色板偏移量表示。 121 | 122 | ``` 123 | +----------------------------+--------------+--------------+ 124 | | No. of bytes | Type [Value] | Description | 125 | +----------------------------+--------------+--------------+ 126 | | 1 | SubEncoding | sub-encoding | 127 | | paletteSize*bytesPerCPixel | CPIXEL array | palette | 128 | +----------------------------+--------------+--------------+ 129 | ``` 130 | 131 | 132 | - 长度为1的游程,仅由调色板索引表示 133 | 134 | ``` 135 | +--------------+--------------+--------------+ 136 | | No. of bytes | Type [Value] | Description | 137 | +--------------+--------------+--------------+ 138 | | 1 | U8 | paletteIndex | 139 | +--------------+--------------+--------------+ 140 | ``` 141 | 142 | - 长度大于1的游程,由调色板索引+128和游程长度表示 143 | 144 | ``` 145 | +-------------------------+--------------+-----------------------+ 146 | | No. of bytes | Type [Value] | Description | 147 | +-------------------------+--------------+-----------------------+ 148 | | 1 | U8 | paletteIndex + 128 | 149 | | div(runLength - 1, 255) | U8 array | 255 | 150 | | 1 | U8 | (runLength-1) mod 255 | 151 | +-------------------------+--------------+-----------------------+ 152 | ``` 153 | -------------------------------------------------------------------------------- /transfer/encoding/zlib-run-length.md: -------------------------------------------------------------------------------- 1 | # zlib 压缩游程编码 2 | 3 | ZRLE 融合游程编码、Zlib 压缩算法、图块压缩算法对传输图像进行压缩。 4 | 5 | ZRLE 使用 Zlib 进行编码和解码,要求流数据严格有序。 6 | 7 | ``` 8 | +--------------+--------------+-------------+ 9 | | No. of bytes | Type [Value] | Description | 10 | +--------------+--------------+-------------+ 11 | | 4 | U32 | length | 12 | | length | U8 array | zlibData | 13 | +--------------+--------------+-------------+ 14 | ``` 15 | 16 | - length: 流(stream)长度 17 | - zlibData: 流数据 18 | 19 | ZlibData 解压后,是从左到右,从上到下排列的图块数据。图块大小是 64x64,其他跟 TRLE 一致。对于长度和宽度不足的图形,其最后一排和最后一列的宽/高是实际尺寸,不做补齐。 20 | -------------------------------------------------------------------------------- /transfer/input/README.md: -------------------------------------------------------------------------------- 1 | # 输入协议 2 | 3 | RFB 协议支持鼠标和键盘两种输入设备,同时支持剪贴板进行远程复制粘贴。 4 | -------------------------------------------------------------------------------- /transfer/input/clipboard.md: -------------------------------------------------------------------------------- 1 | # 剪贴板 2 | 3 | 复制粘贴是双向事件,可以由客户端向服务端复制,也可以由服务端向客户端复制。 4 | 5 | ## 协议报文 6 | 7 | 复制剪贴板的报文如下: 8 | 9 | ``` 10 | +--------------+--------------+--------------+ 11 | | No. of bytes | Type [Value] | Description | 12 | +--------------+--------------+--------------+ 13 | | 1 | U8 [3/6] | message-type | 14 | | 3 | | padding | 15 | | 4 | U32 | length | 16 | | length | U8 array | text | 17 | +--------------+--------------+--------------+ 18 | ``` 19 | 20 | - message-type: 消息类型,客户端是 `0x6`,服务端是 `0x3` 21 | - length: 文本长度 22 | - text: 复制粘贴的文本,长度由 length 限制 23 | 24 | 协议有几点限制 25 | 26 | - 只支持 ISO 8859-1 (Latin-1) 字符集 27 | - 使用单独换行符 `0x0a`,不应该使用回车符 `0x0d` 28 | 29 | ## 拓展剪贴板伪协议 30 | 31 | > RFB 3.8 协议限制,剪贴板只能传输 Latin-1 字符集。 32 | > 2016年,Cendio Ossman 将 [Extended Clipboard Pseudo-Encoding](https://github.com/rfbproto/rfbproto/commit/08018f655acd52970680b34021159924357efb5d) 合入协议主分支,支持在剪贴板消息中传输 unicode 字符集。 33 | > UltraVNC/TigerVNC/RealVNC 服务端都支持此拓展协议,x11vnc 尚未提供支持(2021/8/11)。 34 | 35 | 拓展剪贴板伪协议需要客户端和服务端软件同时支持。报文拓展了 `ServerCutText` 和 `ClientCutText`, 如下: 36 | 37 | ``` 38 | +--------------+--------------+--------------+ 39 | | No. of bytes | Type [Value] | Description | 40 | +--------------+--------------+--------------+ 41 | | 1 | U8 [3/6] | message-type | 42 | | 3 | | padding | 43 | | 4 | S32 | length | 44 | | 4 | U32 | text-type | 45 | | length-4 | U8 array | text | 46 | +--------------+--------------+--------------+ 47 | ``` 48 | 49 | - length: 数据由 U32 改为 S32。首bit是标志位,0 表示传递原始 Latin-1 消息,1 表示传递拓展信息。abs(length) 是实际的消息长度。 50 | - text-type: 消息头部,指示消息类型 51 | - text: 消息内容 52 | 53 | ### 消息类型 54 | 55 | 消息用 4 字节的 text-type 作为头部。 56 | 57 | ``` 58 | +--------------+--------------+--------------+ 59 | | No. of bytes | Type [Value] | Description | 60 | +--------------+--------------+--------------+ 61 | | 1 | U32 | message-type | 62 | +--------------+--------------+--------------+ 63 | ``` 64 | 65 | text-type 分为指令(`action`)和格式(`formats`)两类。指令传输操作命令,格式传输剪贴板内容。 66 | 67 | text-type 标记的含义如下: 68 | 69 | | Bit | Name | Description | 70 | |-|-|---| 71 | | 0 | [text](#文本内容) | 文本内容 | 72 | | 1| rtf | 微软富文本格式 | 73 | | 2 | html | 微软 HTML 格式 | 74 | | 3 | dib | Microsoft Device Independent Bitmap | 75 | | 4 | files | 文件,暂未实现 | 76 | | 5-15| fotmats 保留位 | 77 | | 16-23 | 保留 | 78 | | 24 | [caps](#能力声明) | 指示支持的 text-type 和最大长度 | 79 | | 25 | request | 强制对端传递剪贴板内容 | 80 | | 26 | peek | 强制对端提供支持的 text-type | 81 | | 27 | notify | peek 回包,返回支持的 text-type | 82 | | 28 | [provide](#粘贴板内容) | request 回包,返回粘贴板内容 | 83 | | 29-31 | actions 保留位 | | 84 | 85 | ### 文本内容 text 86 | 87 | 纯文本,unicode 编码的无格式文本。以 `\r\n` 作为行的结尾,原始协议的换行符是 `\n`。 88 | 89 | 文本应该以 `\0` 结尾,即使在 ClientCutText/ServerCutText 中都声明了文本长度。 90 | 91 | ### 能力声明 caps 92 | 93 | Caps 指示期望收到的文本类型,发送的结构是长度数组。数组大小跟格式数量相等(0-15),数组的每个条目,指示格式支持的最大长度。 94 | 95 | #### 数据结构 96 | 97 | ``` 98 | +--------------+--------------+--------------+ 99 | | No. of bytes | Type [Value] | Description | 100 | +--------------+--------------+--------------+ 101 | | formats*4 | U32 array | sizes | 102 | +--------------+--------------+--------------+ 103 | ``` 104 | 105 | 例如: 106 | 107 | ``` 108 | [1024,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] 109 | ``` 110 | 111 | 表示只接受 1024 byte 以内的纯文本信息。 112 | 113 | #### 行为约束 114 | 115 | 服务端收到支持拓展剪贴板协议的 SetEncodings 报文时,必须主动发送类型为 caps 的 ServerCutText 消息。 116 | 117 | 客户端收到 caps 消息时,应该发送类型为 caps 的 ClientCutText 消息作为回应。 118 | 否则,客户端默认会接受 text/rtf/html/request/notify/provide 消息,其中 text 默认长度为 20 Mib,其他为 0 字节。 119 | 120 | 当最大长度限制为 0 时,认为长度没有限制,如果内容长度大于声明的长度限制,则剪贴板变动的消息不会被发送。建议将所有的 caps 设置为 0,以便接受所有的剪贴板消息变动。 121 | 122 | > 某些实现的默认行为与协议描述不一致,例如: 123 | > - dib 也是默认支持的格式 124 | > - text 的默认限制是 10Mid 125 | > - rft/html 默认限制为 2Mib 126 | > - dib 默认限制为 0 字节 127 | > - 客户端忽略 caps 消息建议的格式和长度限制 128 | 129 | 在发送 caps 之前,只能发送指令,不能发送格式和内容。 130 | 131 | ### 粘贴板内容 132 | 133 | 粘贴板内容的 text-type 是 provide。在剪贴板变化,或对端发送 request 后发送。 134 | 在 text-type 后面,是 Zlib 压缩的字节流。对于每种支持的 text-type,会发送 size + data 数据对。 135 | 136 | ``` 137 | +--------------+--------------+--------------+ 138 | | No. of bytes | Type [Value] | Description | 139 | +--------------+--------------+--------------+ 140 | | 4 | U32 | size | 141 | | size | U8 array | data | 142 | +--------------+--------------+--------------+ 143 | ``` 144 | -------------------------------------------------------------------------------- /transfer/input/keyboard.md: -------------------------------------------------------------------------------- 1 | # 键盘事件 2 | 3 | 在正常理解中,键盘事件的处理应该是简单明了的。参考以下协议报文 4 | 5 | ``` 6 | +--------------+--------------+--------------+ 7 | | No. of bytes | Type [Value] | Description | 8 | +--------------+--------------+--------------+ 9 | | 1 | U8 [4] | message-type | 10 | | 1 | U8 | down-flag | 11 | | 2 | | padding | 12 | | 4 | U32 | key | 13 | +--------------+--------------+--------------+ 14 | ``` 15 | 16 | - message-type: 固定为 `0x4` 17 | - down-flag: `1` 表示键位按下,`0` 表示弹起 18 | - pending: 对齐字节,方便解析 19 | - key: 表示具体的键位 20 | 21 | 其中 key 的值在 X 系统中有[明确定义](https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html#keysym_encoding) 22 | 23 | ``` 24 | +-----------------+--------------------+ 25 | | Key name | Keysym value (hex) | 26 | +-----------------+--------------------+ 27 | | BackSpace | 0xff08 | 28 | | Tab | 0xff09 | 29 | | Return or Enter | 0xff0d | 30 | | Escape | 0xff1b | 31 | | Insert | 0xff63 | 32 | | Delete | 0xffff | 33 | | Home | 0xff50 | 34 | | End | 0xff57 | 35 | | Page Up | 0xff55 | 36 | | Page Down | 0xff56 | 37 | | Left | 0xff51 | 38 | | Up | 0xff52 | 39 | | Right | 0xff53 | 40 | | Down | 0xff54 | 41 | | F1 | 0xffbe | 42 | | F2 | 0xffbf | 43 | | F3 | 0xffc0 | 44 | | F4 | 0xffc1 | 45 | | ... | ... | 46 | | F12 | 0xffc9 | 47 | | Shift (left) | 0xffe1 | 48 | | Shift (right) | 0xffe2 | 49 | | Control (left) | 0xffe3 | 50 | | Control (right) | 0xffe4 | 51 | | Meta (left) | 0xffe7 | 52 | | Meta (right) | 0xffe8 | 53 | | Alt (left) | 0xffe9 | 54 | | Alt (right) | 0xffea | 55 | +-----------------+--------------------+ 56 | ``` 57 | 58 | ## 组合键 59 | 60 | 组合键指 `Ctrl + Alt + Del` 或 `Shift + 3` 等组合按键。受不同的操作系统、键盘布局影响,组合键是按键事件中容易发生歧义的一环。 61 | 62 | RFB 基本遵循以下规则: 63 | 64 | - 如果客户端 key 在 `keysym` 中存在,服务端应该遵循 `keysym` 的指示,尽可能的忽略客户端传递 `Shift`、`CpasLock` 等键位,在需要时,应该主动补充/忽略 `Shift` 等键位。例如,在 US 键盘布局中,`#` 需要按下 `Shift + 3`,但是在 UK 布局中不需要。这就意味着用户在输入 `#` 的时候不会输入 `Shift`。这种情况下,服务端应该主动模拟一个 `Shift` 状态,防止输入的键位是 `3`。同理,如果 key 输入的键位是 `A`,服务端统一要模拟一个 `Shift`,保证输入的是 `A` 而不是 `a`。 65 | - 如果客户端 key 在 `keysym` 中不存在(例如 `Ctrl + A`),服务端应该遵循客户端指示,客户端应该主动在 `A` 前发送 `Ctrl` 的按键。 66 | - 如果客户端通过 `Ctrl + Alt + Q` 来输入 `@`,客户端应该在发送 `Ctrl`/`Alt`/`@`后,主动发送`Ctrl`/`Alt`的弹起事件。 67 | - 对于 `BackTab`,常见的有三种实现,`ISO_Left_Tab` `BackTab` 和 `Shift + Tab`。RFB 协议优先使用 `Shift + Tab`,但对于其他的键位,服务端和客户端应当尽量提供兼容。 68 | - 优先使用 `ASCII` 而不是 `unicode` 69 | - 对于 `Ctrl + Alt + Del` 等无法被客户端操作系统拦截的按键(系统拦截有更高优先级),客户端应该提供操作按钮 70 | -------------------------------------------------------------------------------- /transfer/input/mouse.md: -------------------------------------------------------------------------------- 1 | # 鼠标事件 2 | 3 | 鼠标指针即鼠标操作事件,分移动事件和点击事件两种。在 RFB 协议中,使用 PointerEvent 表示客户端触发一次鼠标事件。 4 | 5 | ## 协议报文 6 | 7 | 鼠标事件的报文如下 8 | 9 | ``` 10 | +--------------+--------------+--------------+ 11 | | No. of bytes | Type [Value] | Description | 12 | +--------------+--------------+--------------+ 13 | | 1 | U8 [5] | message-type | 14 | | 1 | U8 | button-mask | 15 | | 2 | U16 | x-position | 16 | | 2 | U16 | y-position | 17 | +--------------+--------------+--------------+ 18 | ``` 19 | 20 | - message-type: 无符号整形,固定 `0x5` 21 | - button-mask: 8 位掩码,表示键位状态,`1`为按下,`0`为弹起 22 | - x-position: 当前 X 坐标 23 | - y-position: 当前 Y 坐标 24 | 25 | button-mask 的 Bit0/1/2 位置分别代表鼠标的左键、中建、右键。使用滚轮的鼠标,每向上滑动一次,会发送一个 Bit3 的按下和弹起事件;每向下滑动一次,会发送一个 Bit4 的按下和弹起事件。 26 | 27 | ## USB/PS/2 鼠标协议 28 | 29 | 在 PS/2 或 USB 鼠标协议中,有类似 RFB 协议的表达方式。 30 | 31 | ``` 32 | ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐ 33 | │ │ Bit7 │ Bit6 │ Bit5 │ Bit4 │ Bit3 │ Bit2 │ Bit1 │ Bit0 │ 34 | ├──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤ 35 | │Byte 1│Y Over│X Over│X Sign│Y Sign│ 0x1 │ Mid │Right │ Left │ 36 | ├──────┼──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┤ 37 | │Byte 2│ X Movement │ 38 | ├──────┼───────────────────────────────────────────────────────┤ 39 | │Byte 3│ Y Movement │ 40 | ├──────┼───────────────────────────────────────────────────────┤ 41 | │Byte 4│ Z Movement │ 42 | └──────┴───────────────────────────────────────────────────────┘ 43 | ``` 44 | 45 | 鼠标协议和 RFB 协议有两点不同: 46 | 47 | - 鼠标协议的 Bit0/1/2 和 RFB 协议的 Bit0/2/1 对应 48 | - 鼠标协议的中轮转动,需要转换为 RFB 协议的按下/弹起事件 49 | 50 | > 根据 [wiki](https://en.wikipedia.org/wiki/RFB_protocol#Limitations) 描述,RFB 协议只支持8个鼠标键位,左中右和滑轮占用5个,只有3个键位给特殊按键(例如:多功能游戏鼠标) 51 | -------------------------------------------------------------------------------- /transfer/pixel-format.md: -------------------------------------------------------------------------------- 1 | # 像素格式 2 | 3 | [帧缓冲](/GLOSSORY.md#帧缓冲)由像素构成。 4 | 5 | ![像素组成帧缓冲](http://babeler-1251731700.cos.ap-shanghai.myqcloud.com/2021-08-15-084847.jpg) 6 | 7 | ## PixelFormat 8 | 9 | RFB 协议中,使用 16 字节结构体 PIXEL_FORMAT 描述像素的格式。 10 | 11 | ``` 12 | +--------------+--------------+-----------------+ 13 | | No. of bytes | Type [Value] | Description | 14 | +--------------+--------------+-----------------+ 15 | | 1 | U8 | bits-per-pixel | 16 | | 1 | U8 | depth | 17 | | 1 | U8 | big-endian-flag | 18 | | 1 | U8 | true-color-flag | 19 | | 2 | U16 | red-max | 20 | | 2 | U16 | green-max | 21 | | 2 | U16 | blue-max | 22 | | 1 | U8 | red-shift | 23 | | 1 | U8 | green-shift | 24 | | 1 | U8 | blue-shift | 25 | | 3 | | padding | 26 | +--------------+--------------+-----------------+ 27 | ``` 28 | 29 | - bits-per-pixel: 像素的位数,位数越大,色彩越丰富。只支持[8|16|32] 30 | - depth: 色深,像素中表示色彩的位数 31 | - big-endian-flag: 多字节像素的字节序,非零即大端序 32 | - true-color-flag: 1 表示真彩色,pixel 的值表示 RGB 颜色;0 表示调色板,pexel 的值表示颜色在调色板的偏移量 33 | - -max/-shift: 获取红蓝绿三色的位移量和长度,max=2^N-1,N是颜色的位数 34 | 35 | ``` 36 | BigEndian: Blue Shift Green Shift Red Shift 37 | │ │ │ 38 | ▼ ▼ ▼ 39 | ┌──────────────────┬─────────────────┬─────────────────┐ 40 | │ BLUE MAX │ GREEN MAX │ RED MAX │ 41 | └──────────────────┴─────────────────┴─────────────────┘ 42 | ``` 43 | 44 | > bits-per-pixel 必须大于或等于 depth 45 | 46 | ## SetPixelFormat 47 | 48 | 客户端发送 SetPixelFormat,声明需要的的像素格式(画面质量)。此消息覆盖 [ServerInit](/handshake/initial.md#服务端初始化) 消息中服务端声明的初始化像素格式。 49 | 50 | 当 true-color-flag 为 0 时,服务端必须发送 SetColorMapEntries,声明使用的颜色表。客户端发送 SetPixelFormat 后,需清空本地缓存的颜色表,无论颜色表中是否有内容。 51 | 52 | ``` 53 | +--------------+--------------+--------------+ 54 | | No. of bytes | Type [Value] | Description | 55 | +--------------+--------------+--------------+ 56 | | 1 | U8 [0] | message-type | 57 | | 3 | | padding | 58 | | 16 | PIXEL_FORMAT | pixel-format | 59 | +--------------+--------------+--------------+ 60 | ``` 61 | 62 | - message-type: 消息类型,固定为 0 63 | - pixel-format: [PixelFormat](#pixelformat) 结构 64 | -------------------------------------------------------------------------------- /transfer/set-color-map.md: -------------------------------------------------------------------------------- 1 | # 设置颜色表 2 | 3 | 当 PIXEL_FORMAT 的 true-color-flag 字段被设置为 0 时,服务端使用颜色表表示像素的颜色。 4 | `SetColorMapEntries` 用于设置颜色表的内容。 5 | 6 | ``` 7 | +--------------+--------------+------------------+ 8 | | No. of bytes | Type [Value] | Description | 9 | +--------------+--------------+------------------+ 10 | | 1 | U8 [1] | message-type | 11 | | 1 | | padding | 12 | | 2 | U16 | first-color | 13 | | 2 | U16 | number-of-colors | 14 | +--------------+--------------+------------------+ 15 | ``` 16 | 17 | - message-type: 消息类型,固定是 `1` 18 | - first-color: [未知](https://github.com/rfbproto/rfbproto/issues/42) 19 | - number-of-colors: 颜色的数量 20 | 21 | ## 色值 22 | 23 | 颜色表的值总是 3 个 16 bits,代表红、绿、蓝三种颜色,每个颜色的范围是 0-65535。 24 | 例如,白色的色值是 65535,65535,65535。 25 | 26 | ``` 27 | +--------------+--------------+-------------+ 28 | | No. of bytes | Type [Value] | Description | 29 | +--------------+--------------+-------------+ 30 | | 2 | U16 | red | 31 | | 2 | U16 | green | 32 | | 2 | U16 | blue | 33 | +--------------+--------------+-------------+ 34 | ``` 35 | --------------------------------------------------------------------------------