-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdipluspixelformats.go
178 lines (133 loc) · 5.78 KB
/
gdipluspixelformats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package gdiplus
import (
"unsafe"
. "github.com/tryor/winapi"
)
/*
* 32-bit and 64-bit ARGB pixel value
*/
type ARGB uint32
const ARGB_SIZE = 4
type ARGB64 uint64
const ALPHA_SHIFT = 24
const RED_SHIFT = 16
const GREEN_SHIFT = 8
const BLUE_SHIFT = 0
const ALPHA_MASK = (ARGB(0xff) << ALPHA_SHIFT)
// In-memory pixel data formats:
// bits 0-7 = format index
// bits 8-15 = pixel size (in bits)
// bits 16-23 = flags
// bits 24-31 = reserved
type PixelFormat INT
const (
PixelFormatIndexed PixelFormat = 0x00010000 // Indexes into a palette
PixelFormatGDI PixelFormat = 0x00020000 // Is a GDI-supported format
PixelFormatAlpha PixelFormat = 0x00040000 // Has an alpha component
PixelFormatPAlpha PixelFormat = 0x00080000 // Pre-multiplied alpha
PixelFormatExtended PixelFormat = 0x00100000 // Extended color 16 bits/channel
PixelFormatCanonical PixelFormat = 0x00200000
PixelFormatUndefined PixelFormat = 0
PixelFormatDontCare PixelFormat = 0
)
var (
PixelFormat1bppIndexed PixelFormat = (1 | (1 << 8) | PixelFormatIndexed | PixelFormatGDI)
PixelFormat4bppIndexed PixelFormat = (2 | (4 << 8) | PixelFormatIndexed | PixelFormatGDI)
PixelFormat8bppIndexed PixelFormat = (3 | (8 << 8) | PixelFormatIndexed | PixelFormatGDI)
PixelFormat16bppGrayScale PixelFormat = (4 | (16 << 8) | PixelFormatExtended)
PixelFormat16bppRGB555 PixelFormat = (5 | (16 << 8) | PixelFormatGDI)
PixelFormat16bppRGB565 PixelFormat = (6 | (16 << 8) | PixelFormatGDI)
PixelFormat16bppARGB1555 PixelFormat = (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
PixelFormat24bppRGB PixelFormat = (8 | (24 << 8) | PixelFormatGDI)
PixelFormat32bppRGB PixelFormat = (9 | (32 << 8) | PixelFormatGDI)
PixelFormat32bppARGB PixelFormat = (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
PixelFormat32bppPARGB PixelFormat = (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
PixelFormat48bppRGB PixelFormat = (12 | (48 << 8) | PixelFormatExtended)
PixelFormat64bppARGB PixelFormat = (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended)
PixelFormat64bppPARGB PixelFormat = (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended)
PixelFormat32bppCMYK PixelFormat = (15 | (32 << 8))
PixelFormatMax PixelFormat = 16
)
func GetPixelFormatSize(pixfmt PixelFormat) UINT {
return UINT((pixfmt >> 8) & 0xff)
}
func IsIndexedPixelFormat(pixfmt PixelFormat) BOOL {
return (pixfmt & PixelFormatIndexed) != 0
}
func IsAlphaPixelFormat(pixfmt PixelFormat) BOOL {
return (pixfmt & PixelFormatAlpha) != 0
}
func IsExtendedPixelFormat(pixfmt PixelFormat) BOOL {
return (pixfmt & PixelFormatExtended) != 0
}
//--------------------------------------------------------------------------
// Determine if the Pixel Format is Canonical format:
// PixelFormat32bppARGB
// PixelFormat32bppPARGB
// PixelFormat64bppARGB
// PixelFormat64bppPARGB
//--------------------------------------------------------------------------
func IsCanonicalPixelFormat(pixfmt PixelFormat) BOOL {
return (pixfmt & PixelFormatCanonical) != 0
}
type PaletteFlags INT
const (
PaletteFlagsHasAlpha PaletteFlags = 0x0001
PaletteFlagsGrayScale PaletteFlags = 0x0002
PaletteFlagsHalftone PaletteFlags = 0x0004
)
type ColorPalette struct {
Flags UINT // Palette flags
Count UINT // Number of color entries
Entries [1]ARGB // Palette color entries
}
var ColorPalette_SIZE = UINT(unsafe.Sizeof(ColorPalette{}))
//#if (GDIPVER >= 0x0110)
//----------------------------------------------------------------------------
// Color format conversion parameters
//----------------------------------------------------------------------------
type PaletteType INT
const (
// Arbitrary custom palette provided by caller.
PaletteTypeCustom PaletteType = 0
// Optimal palette generated using a median-cut algorithm.
PaletteTypeOptimal PaletteType = 1
// Black and white palette.
PaletteTypeFixedBW PaletteType = 2
// Symmetric halftone palettes.
// Each of these halftone palettes will be a superset of the system palette.
// E.g. Halftone8 will have it's 8-color on-off primaries and the 16 system
// colors added. With duplicates removed, that leaves 16 colors.
PaletteTypeFixedHalftone8 PaletteType = 3 // 8-color on-off primaries
PaletteTypeFixedHalftone27 PaletteType = 4 // 3 intensity levels of each color
PaletteTypeFixedHalftone64 PaletteType = 5 // 4 intensity levels of each color
PaletteTypeFixedHalftone125 PaletteType = 6 // 5 intensity levels of each color
PaletteTypeFixedHalftone216 PaletteType = 7 // 6 intensity levels of each color
// Assymetric halftone palettes.
// These are somewhat less useful than the symmetric ones, but are
// included for completeness. These do not include all of the system
// colors.
PaletteTypeFixedHalftone252 PaletteType = 8 // 6-red, 7-green, 6-blue intensities
PaletteTypeFixedHalftone256 PaletteType = 9 // 8-red, 8-green, 4-blue intensities
)
type DitherType INT
const (
DitherTypeNone DitherType = 0
// Solid color - picks the nearest matching color with no attempt to
// halftone or dither. May be used on an arbitrary palette.
DitherTypeSolid DitherType = 1
// Ordered dithers and spiral dithers must be used with a fixed palette.
// NOTE: DitherOrdered4x4 is unique in that it may apply to 16bpp
// conversions also.
DitherTypeOrdered4x4 DitherType = 2
DitherTypeOrdered8x8 DitherType = 3
DitherTypeOrdered16x16 DitherType = 4
DitherTypeSpiral4x4 DitherType = 5
DitherTypeSpiral8x8 DitherType = 6
DitherTypeDualSpiral4x4 DitherType = 7
DitherTypeDualSpiral8x8 DitherType = 8
// Error diffusion. May be used with any palette.
DitherTypeErrorDiffusion DitherType = 9
DitherTypeMax DitherType = 10
)
//#endif //(GDIPVER >= 0x0110)