forked from MajorHard/vraylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.v
202 lines (161 loc) · 6.34 KB
/
images.v
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
module vraylib
// Image manipulation functions
// Create an image duplicate (useful for transformations)
[inline] pub fn image_copy(image Image) Image {
return C.ImageCopy(image)
}
// Convert image to POT (power-of-two)
[inline] pub fn image_to_pot(image &Image, fillColor Color) {
C.ImageToPOT(image, fillColor)
}
// Convert image data to desired format
[inline] pub fn image_format(image &Image, newFormat int) {
C.ImageFormat(image, newFormat)
}
// Apply alpha mask to image
[inline] pub fn image_alpha_mask(image &Image, alphaMask Image) {
C.ImageAlphaMask(image, alphaMask)
}
// Clear alpha channel to desired color
[inline] pub fn image_alpha_clear(image &Image, color Color, threshold f32) {
C.ImageAlphaClear(image, color, threshold)
}
// Crop image depending on alpha value
[inline] pub fn image_alpha_crop(image &Image, threshold f32) {
C.ImageAlphaCrop(image, threshold)
}
// Premultiply alpha channe
[inline] pub fn image_alpha_premultiply(image &Image) {
C.ImageAlphaPremultiply(image)
}
// Crop an image to a defined rectangle
[inline] pub fn image_crop(image &Image, crop Rectangle) {
C.ImageCrop(image, crop)
}
// Resize image (Bicubic scaling algorithm)
[inline] pub fn image_resize(image &Image, newWidth, newHeight int) {
C.ImageResize(image, newWidth, newHeight)
}
// Resize image (Nearest-Neighbor scaling algorithm)
[inline] pub fn image_resize_nn(image &Image, newWidth, newHeight int) {
C.ImageResizeNN(image, newWidth, newHeight)
}
// Resize canvas and fill with color
[inline] pub fn image_resize_canvas(image &Image, newWidth, newHeight, offsetX, offsetY int, color Color) {
C.ImageResizeCanvas(image, newWidth, newHeight, offsetX, offsetY, color)
}
// Generate all mipmap levels for a provided image
[inline] pub fn image_mipmaps(image &Image) {
C.ImageMipmaps(image)
}
// Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
[inline] pub fn image_dither(image &Image, rBpp, gBpp, bBpp, aBpp int) {
C.ImageDither(image, rBpp, gBpp, bBpp, aBpp)
}
// Extract color palette from image to maximum size (memory should be freed)
[inline] pub fn image_extract_palette(image Image, maxPaletteSize, extractCount &int) &Color {
return C.ImageExtractPalette(image, *maxPaletteSize, extractCount)
}
// Create an image from text (default font)
[inline] pub fn image_text(text string, fontSize int, color Color) Image {
return C.ImageText(text.str, fontSize, color)
}
// Create an image from text (custom sprite font)
[inline] pub fn image_text_ex(font Font, text string, fontSize, spacing f32, tint Color) Image {
return C.ImageTextEx(font, text.str, fontSize, spacing, tint)
}
// TODO: Potential TCC bug
// Draw a source image within a destination image
// [inline] pub fn image_draw(dst &Image, src Image, srcRec, dstRec Rectangle) {
// C.ImageDraw(dst, src, srcRec, dstRec)
// }
// Draw rectangle within an image
[inline] pub fn image_draw_rectangle(dst &Image, rec Rectangle, color Color) {
C.ImageDrawRectangle(dst, rec, color)
}
// Draw rectangle lines within an image
[inline] pub fn image_draw_rectangle_lines(dst &Image, rec Rectangle, thick int, color Color) {
C.ImageDrawRectangleLines(dst, rec, thick, color)
}
// Draw text (default font) within an image (destination)
[inline] pub fn image_draw_text(dst &Image, position Vector2, text string, fontSize int, color Color) {
C.ImageDrawText(dst, position, text.str, fontSize, color)
}
// Draw text (custom sprite font) within an image (destination)
[inline] pub fn image_draw_text_ex(dst &Image, position Vector2, font Font, text string, fontSize, spacing f32, color Color) {
C.ImageDrawTextEx(dst, position, font, text.str, fontSize, spacing, color)
}
// Flip image vertically
[inline] pub fn image_flip_vertical(image &Image) {
C.ImageFlipVertical(image)
}
// Flip image horizontally
[inline] pub fn image_flip_horizontal(image &Image) {
C.ImageFlipHorizontal(image)
}
// Rotate image clockwise 90deg
[inline] pub fn image_rotate_cw(image &Image) {
C.ImageRotateCW(image)
}
// Rotate image counter-clockwise 90deg
[inline] pub fn image_rotate_ccw(image &Image) {
C.ImageRotateCCW(image)
}
// Modify image color: tint
[inline] pub fn image_color_tint(image &Image, color Color) {
C.ImageColorTint(image, color)
}
// Modify image color: invert
[inline] pub fn image_color_invert(image &Image) {
C.ImageColorInvert(image)
}
// Modify image color: grayscale
[inline] pub fn image_color_grayscale(image &Image) {
C.ImageColorGrayscale(image)
}
// Modify image color: contrast (-100 to 100)
[inline] pub fn image_color_contrast(image &Image, contrast f32) {
C.ImageColorContrast(image, contrast)
}
// Modify image color: brightness (-255 to 255)
[inline] pub fn image_color_brightness(image &Image, brightness int) {
C.ImageColorBrightness(image, brightness)
}
// Modify image color: replace color
[inline] pub fn image_color_replace(image &Image, color, replace Color) {
C.ImageColorReplace(image, color, replace)
}
// // Image generation functions
//
// Generate image: plain color
[inline] pub fn gen_image_color(width, height int, color Color) Image {
return C.GenImageColor(width, height, color)
}
// Generate image: vertical gradient
[inline] pub fn gen_image_gradient_v(width, height int, top, bottom Color) Image {
return C.GenImageGradientV(width, height, top, bottom)
}
// Generate image: horizontal gradient
[inline] pub fn get_image_gradient_h(width, height int, left, right Color) Image {
return C.GenImageGradientH(width, height, left, right)
}
// Generate image: radial gradient
[inline] pub fn get_image_gradient_radial(width, height int, density f32, inner, outer Color) Image {
return C.GenImageGradientRadial(width, height, density, inner, outer)
}
// Generate image: checked
[inline] pub fn get_image_checked(width, height, checksX, checksY int, color1, color2 Color) Image {
return C.GenImageChecked(width, height, checksX, checksY, color1, color2)
}
// Generate image: white noise
[inline] pub fn gen_image_white_noise(width, height int, factor f32) Image {
return C.GenImageWhiteNoise(width, height, factor)
}
// Generate image: perlin noise
[inline] pub fn gen_image_perlin_noise(width, height, offsetX, offsetY, scale f32) Image {
return C.GenImagePerlinNoise(width, height, offsetX, offsetY, scale)
}
// Generate image: cellular algorithm. Bigger tileSize means bigger cells
[inline] pub fn gen_image_cellular(width, height, tileSize int) Image {
return C.GenImageCellular(width, height, tileSize)
}