diff options
author | Jiri Slaby <jslaby@suse.cz> | 2016-06-23 07:34:31 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-06-25 12:04:48 -0400 |
commit | e05ab238e30572abbac0cc4aba051553928de949 (patch) | |
tree | 1f687dcddffb73307a89b22835b73444c2c15d4a /drivers/tty/vt | |
parent | d711ea8f762eec3bc057bc92423c6ec804523a40 (diff) |
tty: vt, separate T.416 high colors handler
The code with T.416 high colors handling is flushed to the right and
hard to read. Move the code to a separate function and remove code
duplication for foreground & background colors.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r-- | drivers/tty/vt/vt.c | 85 |
1 files changed, 37 insertions, 48 deletions
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 6e12d9c0ea41..da49f5cfa654 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c | |||
@@ -1284,6 +1284,40 @@ static void rgb_background(struct vc_data *vc, struct rgb c) | |||
1284 | | (c.r&0x80) >> 1 | (c.g&0x80) >> 2 | (c.b&0x80) >> 3; | 1284 | | (c.r&0x80) >> 1 | (c.g&0x80) >> 2 | (c.b&0x80) >> 3; |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | /* | ||
1288 | * ITU T.416 Higher colour modes. They break the usual properties of SGR codes | ||
1289 | * and thus need to be detected and ignored by hand. Strictly speaking, that | ||
1290 | * standard also wants : rather than ; as separators, contrary to ECMA-48, but | ||
1291 | * no one produces such codes and almost no one accepts them. | ||
1292 | * | ||
1293 | * Subcommands 3 (CMY) and 4 (CMYK) are so insane there's no point in | ||
1294 | * supporting them. | ||
1295 | */ | ||
1296 | static int vc_t416_color(struct vc_data *vc, int i, | ||
1297 | void(*set_color)(struct vc_data *vc, struct rgb c)) | ||
1298 | { | ||
1299 | i++; | ||
1300 | if (i > vc->vc_npar) | ||
1301 | return i; | ||
1302 | |||
1303 | if (vc->vc_par[i] == 5 && i < vc->vc_npar) { | ||
1304 | /* 256 colours -- ubiquitous */ | ||
1305 | i++; | ||
1306 | set_color(vc, rgb_from_256(vc->vc_par[i])); | ||
1307 | } else if (vc->vc_par[i] == 2 && i <= vc->vc_npar + 3) { | ||
1308 | /* 24 bit -- extremely rare */ | ||
1309 | struct rgb c = { | ||
1310 | .r = vc->vc_par[i + 1], | ||
1311 | .g = vc->vc_par[i + 2], | ||
1312 | .b = vc->vc_par[i + 3], | ||
1313 | }; | ||
1314 | set_color(vc, c); | ||
1315 | i += 3; | ||
1316 | } | ||
1317 | |||
1318 | return i; | ||
1319 | } | ||
1320 | |||
1287 | /* console_lock is held */ | 1321 | /* console_lock is held */ |
1288 | static void csi_m(struct vc_data *vc) | 1322 | static void csi_m(struct vc_data *vc) |
1289 | { | 1323 | { |
@@ -1355,56 +1389,11 @@ static void csi_m(struct vc_data *vc) | |||
1355 | case 27: | 1389 | case 27: |
1356 | vc->vc_reverse = 0; | 1390 | vc->vc_reverse = 0; |
1357 | break; | 1391 | break; |
1358 | case 38: /* ITU T.416 | 1392 | case 38: |
1359 | * Higher colour modes. | 1393 | i = vc_t416_color(vc, i, rgb_foreground); |
1360 | * They break the usual properties of SGR codes | ||
1361 | * and thus need to be detected and ignored by | ||
1362 | * hand. Strictly speaking, that standard also | ||
1363 | * wants : rather than ; as separators, contrary | ||
1364 | * to ECMA-48, but no one produces such codes | ||
1365 | * and almost no one accepts them. | ||
1366 | */ | ||
1367 | i++; | ||
1368 | if (i > vc->vc_npar) | ||
1369 | break; | ||
1370 | if (vc->vc_par[i] == 5 && /* 256 colours */ | ||
1371 | i < vc->vc_npar) { /* ubiquitous */ | ||
1372 | i++; | ||
1373 | rgb_foreground(vc, | ||
1374 | rgb_from_256(vc->vc_par[i])); | ||
1375 | } else if (vc->vc_par[i] == 2 && /* 24 bit */ | ||
1376 | i <= vc->vc_npar + 3) {/* extremely rare */ | ||
1377 | struct rgb c = { | ||
1378 | .r = vc->vc_par[i + 1], | ||
1379 | .g = vc->vc_par[i + 2], | ||
1380 | .b = vc->vc_par[i + 3], | ||
1381 | }; | ||
1382 | rgb_foreground(vc, c); | ||
1383 | i += 3; | ||
1384 | } | ||
1385 | /* Subcommands 3 (CMY) and 4 (CMYK) are so insane | ||
1386 | * there's no point in supporting them. | ||
1387 | */ | ||
1388 | break; | 1394 | break; |
1389 | case 48: | 1395 | case 48: |
1390 | i++; | 1396 | i = vc_t416_color(vc, i, rgb_background); |
1391 | if (i > vc->vc_npar) | ||
1392 | break; | ||
1393 | if (vc->vc_par[i] == 5 && /* 256 colours */ | ||
1394 | i < vc->vc_npar) { | ||
1395 | i++; | ||
1396 | rgb_background(vc, | ||
1397 | rgb_from_256(vc->vc_par[i])); | ||
1398 | } else if (vc->vc_par[i] == 2 && /* 24 bit */ | ||
1399 | i <= vc->vc_npar + 3) { | ||
1400 | struct rgb c = { | ||
1401 | .r = vc->vc_par[i + 1], | ||
1402 | .g = vc->vc_par[i + 2], | ||
1403 | .b = vc->vc_par[i + 3], | ||
1404 | }; | ||
1405 | rgb_background(vc, c); | ||
1406 | i += 3; | ||
1407 | } | ||
1408 | break; | 1397 | break; |
1409 | case 39: | 1398 | case 39: |
1410 | vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0); | 1399 | vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0); |