|
27 | 27 | #ifndef _DRM_MODE_H |
28 | 28 | #define _DRM_MODE_H |
29 | 29 |
|
| 30 | +#include <linux/const.h> |
| 31 | + |
30 | 32 | #include "drm.h" |
31 | 33 |
|
32 | 34 | #if defined(__cplusplus) |
@@ -1363,6 +1365,71 @@ struct drm_mode_closefb { |
1363 | 1365 | __u32 pad; |
1364 | 1366 | }; |
1365 | 1367 |
|
| 1368 | +/* |
| 1369 | + * Put 16-bit ARGB values into a standard 64-bit representation that can be |
| 1370 | + * used for ioctl parameters, inter-driver communication, etc. |
| 1371 | + * |
| 1372 | + * If the component values being provided contain less than 16 bits of |
| 1373 | + * precision, use a conversion ratio to get a better color approximation. |
| 1374 | + * The ratio is computed as (2^16 - 1) / (2^bpc - 1), where bpc and 16 are |
| 1375 | + * the input and output precision, respectively. |
| 1376 | + */ |
| 1377 | +#define __DRM_ARGB64_PREP(c, shift) \ |
| 1378 | + (((__u64)(c) & 0xffffU) << (shift)) |
| 1379 | + |
| 1380 | +#define __DRM_ARGB64_PREP_BPC(c, shift, bpc)( \ |
| 1381 | +{ \ |
| 1382 | + __u16 mask = (1U << (bpc)) - 1; \ |
| 1383 | + __u16 conv = __KERNEL_DIV_ROUND_CLOSEST((mask & (c)) * \ |
| 1384 | + 0xffffU, mask); \ |
| 1385 | + __DRM_ARGB64_PREP(conv, shift); \ |
| 1386 | +} \ |
| 1387 | +) |
| 1388 | + |
| 1389 | +#define DRM_ARGB64_PREP_BPC(alpha, red, green, blue, bpc)( \ |
| 1390 | +{ \ |
| 1391 | + __typeof__(bpc) __bpc = bpc; \ |
| 1392 | + __DRM_ARGB64_PREP_BPC(alpha, 48, __bpc) | \ |
| 1393 | + __DRM_ARGB64_PREP_BPC(red, 32, __bpc) | \ |
| 1394 | + __DRM_ARGB64_PREP_BPC(green, 16, __bpc) | \ |
| 1395 | + __DRM_ARGB64_PREP_BPC(blue, 0, __bpc); \ |
| 1396 | +} \ |
| 1397 | +) |
| 1398 | + |
| 1399 | +#define DRM_ARGB64_PREP(alpha, red, green, blue) \ |
| 1400 | + (__DRM_ARGB64_PREP(alpha, 48) | \ |
| 1401 | + __DRM_ARGB64_PREP(red, 32) | \ |
| 1402 | + __DRM_ARGB64_PREP(green, 16) | \ |
| 1403 | + __DRM_ARGB64_PREP(blue, 0)) |
| 1404 | + |
| 1405 | +/* |
| 1406 | + * Extract the specified color component from a standard 64-bit ARGB value. |
| 1407 | + * |
| 1408 | + * If the requested precision is less than 16 bits, make use of a conversion |
| 1409 | + * ratio calculated as (2^bpc - 1) / (2^16 - 1), where bpc and 16 are the |
| 1410 | + * output and input precision, respectively. |
| 1411 | + */ |
| 1412 | +#define __DRM_ARGB64_GET(c, shift) \ |
| 1413 | + ((__u16)(((__u64)(c) >> (shift)) & 0xffffU)) |
| 1414 | + |
| 1415 | +#define __DRM_ARGB64_GET_BPC(c, shift, bpc)( \ |
| 1416 | +{ \ |
| 1417 | + __u16 comp = __DRM_ARGB64_GET(c, shift); \ |
| 1418 | + __KERNEL_DIV_ROUND_CLOSEST(comp * ((1U << (bpc)) - 1), \ |
| 1419 | + 0xffffU); \ |
| 1420 | +} \ |
| 1421 | +) |
| 1422 | + |
| 1423 | +#define DRM_ARGB64_GETA_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 48, bpc) |
| 1424 | +#define DRM_ARGB64_GETR_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 32, bpc) |
| 1425 | +#define DRM_ARGB64_GETG_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 16, bpc) |
| 1426 | +#define DRM_ARGB64_GETB_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 0, bpc) |
| 1427 | + |
| 1428 | +#define DRM_ARGB64_GETA(c) __DRM_ARGB64_GET(c, 48) |
| 1429 | +#define DRM_ARGB64_GETR(c) __DRM_ARGB64_GET(c, 32) |
| 1430 | +#define DRM_ARGB64_GETG(c) __DRM_ARGB64_GET(c, 16) |
| 1431 | +#define DRM_ARGB64_GETB(c) __DRM_ARGB64_GET(c, 0) |
| 1432 | + |
1366 | 1433 | #if defined(__cplusplus) |
1367 | 1434 | } |
1368 | 1435 | #endif |
|
0 commit comments