forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_traits.h
208 lines (164 loc) · 5.11 KB
/
image_traits.h
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Aseprite Document Library
// Copyright (c) 2018-2024 Igara Studio S.A.
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_IMAGE_TRAITS_H_INCLUDED
#define DOC_IMAGE_TRAITS_H_INCLUDED
#pragma once
#include "base/memory.h"
#include "doc/aligned_memory.h"
#include "doc/blend_funcs.h"
#include "doc/color.h"
#include "doc/color_mode.h"
#include "doc/pixel_format.h"
namespace doc {
struct RgbTraits {
static const ColorMode color_mode = ColorMode::RGB;
static const PixelFormat pixel_format = IMAGE_RGB;
enum {
bits_per_pixel = 32,
bytes_per_pixel = 4,
pixels_per_byte = 0,
channels = 4,
has_alpha = true,
};
typedef uint32_t pixel_t;
typedef pixel_t* address_t;
typedef const pixel_t* const_address_t;
static const pixel_t min_value = 0x00000000l;
static const pixel_t max_value = 0xffffffffl;
static inline int width_bytes(int pixels_per_row) { return bytes_per_pixel * pixels_per_row; }
static inline int rowstride_bytes(int pixels_per_row)
{
return doc_align_size(width_bytes(pixels_per_row));
}
static inline BlendFunc get_blender(BlendMode blend_mode, bool newBlend)
{
return get_rgba_blender(blend_mode, newBlend);
}
static inline bool same_color(const pixel_t a, const pixel_t b)
{
if (rgba_geta(a) == 0) {
if (rgba_geta(b) == 0)
return true;
return false;
}
if (rgba_geta(b) == 0)
return false;
return a == b;
}
};
struct GrayscaleTraits {
static const ColorMode color_mode = ColorMode::GRAYSCALE;
static const PixelFormat pixel_format = IMAGE_GRAYSCALE;
enum {
bits_per_pixel = 16,
bytes_per_pixel = 2,
pixels_per_byte = 0,
channels = 2,
has_alpha = true,
};
typedef uint16_t pixel_t;
typedef pixel_t* address_t;
typedef const pixel_t* const_address_t;
static const pixel_t min_value = 0x0000;
static const pixel_t max_value = 0xffff;
static inline int width_bytes(int pixels_per_row) { return bytes_per_pixel * pixels_per_row; }
static inline int rowstride_bytes(int pixels_per_row)
{
return doc_align_size(width_bytes(pixels_per_row));
}
static inline BlendFunc get_blender(BlendMode blend_mode, bool newBlend)
{
return get_graya_blender(blend_mode, newBlend);
}
static inline bool same_color(const pixel_t a, const pixel_t b)
{
if (graya_geta(a) == 0) {
if (graya_geta(b) == 0)
return true;
return false;
}
if (graya_geta(b) == 0)
return false;
return a == b;
}
};
struct IndexedTraits {
static const ColorMode color_mode = ColorMode::INDEXED;
static const PixelFormat pixel_format = IMAGE_INDEXED;
enum {
bits_per_pixel = 8,
bytes_per_pixel = 1,
pixels_per_byte = 1,
channels = 1,
has_alpha = false,
};
typedef uint8_t pixel_t;
typedef pixel_t* address_t;
typedef const pixel_t* const_address_t;
static const pixel_t min_value = 0x00;
static const pixel_t max_value = 0xff;
static inline int width_bytes(int pixels_per_row) { return bytes_per_pixel * pixels_per_row; }
static inline int rowstride_bytes(int pixels_per_row)
{
return doc_align_size(width_bytes(pixels_per_row));
}
static inline BlendFunc get_blender(BlendMode blend_mode, bool newBlend)
{
return get_indexed_blender(blend_mode, newBlend);
}
static inline bool same_color(const pixel_t a, const pixel_t b) { return a == b; }
};
struct BitmapTraits {
static const ColorMode color_mode = ColorMode::BITMAP;
static const PixelFormat pixel_format = IMAGE_BITMAP;
enum {
bits_per_pixel = 1,
bytes_per_pixel = 1,
pixels_per_byte = 8,
channels = 1,
has_alpha = false,
};
typedef uint8_t pixel_t;
typedef pixel_t* address_t;
typedef const pixel_t* const_address_t;
static const pixel_t min_value = 0;
static const pixel_t max_value = 1;
static inline int width_bytes(int pixels_per_row) { return (pixels_per_row + 7) / 8; }
static inline int rowstride_bytes(int pixels_per_row)
{
return doc_align_size(width_bytes(pixels_per_row));
}
static inline bool same_color(const pixel_t a, const pixel_t b) { return a == b; }
};
struct TilemapTraits {
static const ColorMode color_mode = ColorMode::TILEMAP;
static const PixelFormat pixel_format = IMAGE_TILEMAP;
enum {
bits_per_pixel = 32,
bytes_per_pixel = 4,
pixels_per_byte = 0,
channels = 3, // Tile Index + Tile Set + Flags
has_alpha = false,
};
typedef uint32_t pixel_t;
typedef pixel_t* address_t;
typedef const pixel_t* const_address_t;
static const pixel_t min_value = 0x00000000l;
static const pixel_t max_value = 0xffffffffl;
static inline int width_bytes(int pixels_per_row) { return bytes_per_pixel * pixels_per_row; }
static inline int rowstride_bytes(int pixels_per_row)
{
return doc_align_size(width_bytes(pixels_per_row));
}
static inline BlendFunc get_blender(BlendMode blend_mode, bool newBlend)
{
return get_indexed_blender(blend_mode, newBlend);
}
static inline bool same_color(const pixel_t a, const pixel_t b) { return a == b; }
};
} // namespace doc
#endif