1 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 Copyright (C) 2009-2015 Red Hat, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef SPICE_BITMAP_UTILS_H_
20 #define SPICE_BITMAP_UTILS_H_
21
22 #include "red-common.h"
23
24 SPICE_BEGIN_DECLS
25
26 typedef enum {
27 BITMAP_GRADUAL_INVALID,
28 BITMAP_GRADUAL_NOT_AVAIL,
29 BITMAP_GRADUAL_LOW,
30 BITMAP_GRADUAL_MEDIUM,
31 BITMAP_GRADUAL_HIGH,
32 } BitmapGradualType;
33
34 typedef struct {
35 uint8_t b;
36 uint8_t g;
37 uint8_t r;
38 uint8_t pad;
39 } rgb32_pixel_t;
40
41 verify(sizeof(rgb32_pixel_t) == 4);
42
43 typedef struct {
44 uint8_t b;
45 uint8_t g;
46 uint8_t r;
47 } rgb24_pixel_t;
48
49 verify(sizeof(rgb24_pixel_t) == 3);
50
51 typedef uint16_t rgb16_pixel_t;
52
53
bitmap_fmt_get_bytes_per_pixel(uint8_t fmt)54 static inline int bitmap_fmt_get_bytes_per_pixel(uint8_t fmt)
55 {
56 static const int bytes_per_pixel[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 4, 1};
57
58 spice_return_val_if_fail(fmt < SPICE_N_ELEMENTS(bytes_per_pixel), 0);
59
60 return bytes_per_pixel[fmt];
61 }
62
63
bitmap_fmt_is_plt(uint8_t fmt)64 static inline int bitmap_fmt_is_plt(uint8_t fmt)
65 {
66 static const int fmt_is_plt[] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
67
68 spice_return_val_if_fail(fmt < SPICE_N_ELEMENTS(fmt_is_plt), 0);
69
70 return fmt_is_plt[fmt];
71 }
72
bitmap_fmt_is_rgb(uint8_t fmt)73 static inline int bitmap_fmt_is_rgb(uint8_t fmt)
74 {
75 static const int fmt_is_rgb[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1};
76
77 spice_return_val_if_fail(fmt < SPICE_N_ELEMENTS(fmt_is_rgb), 0);
78
79 return fmt_is_rgb[fmt];
80 }
81
bitmap_fmt_has_graduality(uint8_t fmt)82 static inline int bitmap_fmt_has_graduality(uint8_t fmt)
83 {
84 return bitmap_fmt_is_rgb(fmt) && fmt != SPICE_BITMAP_FMT_8BIT_A;
85 }
86
87
88 BitmapGradualType bitmap_get_graduality_level (SpiceBitmap *bitmap);
89 int bitmap_has_extra_stride (SpiceBitmap *bitmap);
90
91 void dump_bitmap(SpiceBitmap *bitmap);
92
93 int spice_bitmap_from_surface_type(uint32_t surface_format);
94
95 SPICE_END_DECLS
96
97 #endif /* SPICE_BITMAP_UTILS_H_ */
98