sdl3_sys/generated/surface.rs
1//! SDL surfaces are buffers of pixels in system RAM. These are useful for
2//! passing around and manipulating images that are not stored in GPU memory.
3//!
4//! [`SDL_Surface`] makes serious efforts to manage images in various formats, and
5//! provides a reasonable toolbox for transforming the data, including copying
6//! between surfaces, filling rectangles in the image data, etc.
7//!
8//! There is also a simple .bmp loader, [`SDL_LoadBMP()`], and a simple .png
9//! loader, [`SDL_LoadPNG()`]. SDL itself does not provide loaders for other file
10//! formats, but there are several excellent external libraries that do,
11//! including its own satellite library,
12//! [SDL_image](https://wiki.libsdl.org/SDL3_image)
13//! .
14//!
15//! In general these functions are thread-safe in that they can be called on
16//! different threads with different surfaces. You should not try to modify any
17//! surface from two threads simultaneously.
18
19use super::stdinc::*;
20
21use super::error::*;
22
23use super::blendmode::*;
24
25use super::pixels::*;
26
27use super::properties::*;
28
29use super::rect::*;
30
31use super::iostream::*;
32
33/// The flags on an [`SDL_Surface`].
34///
35/// These are generally considered read-only.
36///
37/// ## Availability
38/// This datatype is available since SDL 3.2.0.
39///
40/// ## Known values (`sdl3-sys`)
41/// | Associated constant | Global constant | Description |
42/// | ------------------- | --------------- | ----------- |
43/// | [`PREALLOCATED`](SDL_SurfaceFlags::PREALLOCATED) | [`SDL_SURFACE_PREALLOCATED`] | Surface uses preallocated pixel memory |
44/// | [`LOCK_NEEDED`](SDL_SurfaceFlags::LOCK_NEEDED) | [`SDL_SURFACE_LOCK_NEEDED`] | Surface needs to be locked to access pixels |
45/// | [`LOCKED`](SDL_SurfaceFlags::LOCKED) | [`SDL_SURFACE_LOCKED`] | Surface is currently locked |
46/// | [`SIMD_ALIGNED`](SDL_SurfaceFlags::SIMD_ALIGNED) | [`SDL_SURFACE_SIMD_ALIGNED`] | Surface uses pixel memory allocated with [`SDL_aligned_alloc()`] |
47#[repr(transparent)]
48#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
49pub struct SDL_SurfaceFlags(pub Uint32);
50
51impl ::core::cmp::PartialEq<Uint32> for SDL_SurfaceFlags {
52 #[inline(always)]
53 fn eq(&self, other: &Uint32) -> bool {
54 &self.0 == other
55 }
56}
57
58impl ::core::cmp::PartialEq<SDL_SurfaceFlags> for Uint32 {
59 #[inline(always)]
60 fn eq(&self, other: &SDL_SurfaceFlags) -> bool {
61 self == &other.0
62 }
63}
64
65impl From<SDL_SurfaceFlags> for Uint32 {
66 #[inline(always)]
67 fn from(value: SDL_SurfaceFlags) -> Self {
68 value.0
69 }
70}
71
72#[cfg(feature = "debug-impls")]
73impl ::core::fmt::Debug for SDL_SurfaceFlags {
74 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
75 let mut first = true;
76 let all_bits = 0;
77 write!(f, "SDL_SurfaceFlags(")?;
78 let all_bits = all_bits | Self::PREALLOCATED.0;
79 if (Self::PREALLOCATED != 0 || self.0 == 0)
80 && *self & Self::PREALLOCATED == Self::PREALLOCATED
81 {
82 if !first {
83 write!(f, " | ")?;
84 }
85 first = false;
86 write!(f, "PREALLOCATED")?;
87 }
88 let all_bits = all_bits | Self::LOCK_NEEDED.0;
89 if (Self::LOCK_NEEDED != 0 || self.0 == 0) && *self & Self::LOCK_NEEDED == Self::LOCK_NEEDED
90 {
91 if !first {
92 write!(f, " | ")?;
93 }
94 first = false;
95 write!(f, "LOCK_NEEDED")?;
96 }
97 let all_bits = all_bits | Self::LOCKED.0;
98 if (Self::LOCKED != 0 || self.0 == 0) && *self & Self::LOCKED == Self::LOCKED {
99 if !first {
100 write!(f, " | ")?;
101 }
102 first = false;
103 write!(f, "LOCKED")?;
104 }
105 let all_bits = all_bits | Self::SIMD_ALIGNED.0;
106 if (Self::SIMD_ALIGNED != 0 || self.0 == 0)
107 && *self & Self::SIMD_ALIGNED == Self::SIMD_ALIGNED
108 {
109 if !first {
110 write!(f, " | ")?;
111 }
112 first = false;
113 write!(f, "SIMD_ALIGNED")?;
114 }
115
116 if self.0 & !all_bits != 0 {
117 if !first {
118 write!(f, " | ")?;
119 }
120 write!(f, "{:#x}", self.0)?;
121 } else if first {
122 write!(f, "0")?;
123 }
124 write!(f, ")")
125 }
126}
127
128impl ::core::ops::BitAnd for SDL_SurfaceFlags {
129 type Output = Self;
130
131 #[inline(always)]
132 fn bitand(self, rhs: Self) -> Self::Output {
133 Self(self.0 & rhs.0)
134 }
135}
136
137impl ::core::ops::BitAndAssign for SDL_SurfaceFlags {
138 #[inline(always)]
139 fn bitand_assign(&mut self, rhs: Self) {
140 self.0 &= rhs.0;
141 }
142}
143
144impl ::core::ops::BitOr for SDL_SurfaceFlags {
145 type Output = Self;
146
147 #[inline(always)]
148 fn bitor(self, rhs: Self) -> Self::Output {
149 Self(self.0 | rhs.0)
150 }
151}
152
153impl ::core::ops::BitOrAssign for SDL_SurfaceFlags {
154 #[inline(always)]
155 fn bitor_assign(&mut self, rhs: Self) {
156 self.0 |= rhs.0;
157 }
158}
159
160impl ::core::ops::BitXor for SDL_SurfaceFlags {
161 type Output = Self;
162
163 #[inline(always)]
164 fn bitxor(self, rhs: Self) -> Self::Output {
165 Self(self.0 ^ rhs.0)
166 }
167}
168
169impl ::core::ops::BitXorAssign for SDL_SurfaceFlags {
170 #[inline(always)]
171 fn bitxor_assign(&mut self, rhs: Self) {
172 self.0 ^= rhs.0;
173 }
174}
175
176impl ::core::ops::Not for SDL_SurfaceFlags {
177 type Output = Self;
178
179 #[inline(always)]
180 fn not(self) -> Self::Output {
181 Self(!self.0)
182 }
183}
184
185impl SDL_SurfaceFlags {
186 /// Surface uses preallocated pixel memory
187 pub const PREALLOCATED: Self = Self((0x00000001 as Uint32));
188 /// Surface needs to be locked to access pixels
189 pub const LOCK_NEEDED: Self = Self((0x00000002 as Uint32));
190 /// Surface is currently locked
191 pub const LOCKED: Self = Self((0x00000004 as Uint32));
192 /// Surface uses pixel memory allocated with [`SDL_aligned_alloc()`]
193 pub const SIMD_ALIGNED: Self = Self((0x00000008 as Uint32));
194}
195
196/// Surface uses preallocated pixel memory
197pub const SDL_SURFACE_PREALLOCATED: SDL_SurfaceFlags = SDL_SurfaceFlags::PREALLOCATED;
198/// Surface needs to be locked to access pixels
199pub const SDL_SURFACE_LOCK_NEEDED: SDL_SurfaceFlags = SDL_SurfaceFlags::LOCK_NEEDED;
200/// Surface is currently locked
201pub const SDL_SURFACE_LOCKED: SDL_SurfaceFlags = SDL_SurfaceFlags::LOCKED;
202/// Surface uses pixel memory allocated with [`SDL_aligned_alloc()`]
203pub const SDL_SURFACE_SIMD_ALIGNED: SDL_SurfaceFlags = SDL_SurfaceFlags::SIMD_ALIGNED;
204
205#[cfg(feature = "metadata")]
206impl sdl3_sys::metadata::GroupMetadata for SDL_SurfaceFlags {
207 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
208 &crate::metadata::surface::METADATA_SDL_SurfaceFlags;
209}
210
211/// The scaling mode.
212///
213/// ## Availability
214/// This enum is available since SDL 3.2.0.
215///
216/// ## Known values (`sdl3-sys`)
217/// | Associated constant | Global constant | Description |
218/// | ------------------- | --------------- | ----------- |
219/// | [`INVALID`](SDL_ScaleMode::INVALID) | [`SDL_SCALEMODE_INVALID`] | |
220/// | [`NEAREST`](SDL_ScaleMode::NEAREST) | [`SDL_SCALEMODE_NEAREST`] | nearest pixel sampling |
221/// | [`LINEAR`](SDL_ScaleMode::LINEAR) | [`SDL_SCALEMODE_LINEAR`] | linear filtering |
222/// | [`PIXELART`](SDL_ScaleMode::PIXELART) | [`SDL_SCALEMODE_PIXELART`] | nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0 |
223#[repr(transparent)]
224#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
225pub struct SDL_ScaleMode(pub ::core::ffi::c_int);
226
227impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_ScaleMode {
228 #[inline(always)]
229 fn eq(&self, other: &::core::ffi::c_int) -> bool {
230 &self.0 == other
231 }
232}
233
234impl ::core::cmp::PartialEq<SDL_ScaleMode> for ::core::ffi::c_int {
235 #[inline(always)]
236 fn eq(&self, other: &SDL_ScaleMode) -> bool {
237 self == &other.0
238 }
239}
240
241impl From<SDL_ScaleMode> for ::core::ffi::c_int {
242 #[inline(always)]
243 fn from(value: SDL_ScaleMode) -> Self {
244 value.0
245 }
246}
247
248#[cfg(feature = "debug-impls")]
249impl ::core::fmt::Debug for SDL_ScaleMode {
250 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
251 #[allow(unreachable_patterns)]
252 f.write_str(match *self {
253 Self::INVALID => "SDL_SCALEMODE_INVALID",
254 Self::NEAREST => "SDL_SCALEMODE_NEAREST",
255 Self::LINEAR => "SDL_SCALEMODE_LINEAR",
256 Self::PIXELART => "SDL_SCALEMODE_PIXELART",
257
258 _ => return write!(f, "SDL_ScaleMode({})", self.0),
259 })
260 }
261}
262
263impl SDL_ScaleMode {
264 pub const INVALID: Self = Self((-1_i32 as ::core::ffi::c_int));
265 /// nearest pixel sampling
266 pub const NEAREST: Self = Self((0_i32 as ::core::ffi::c_int));
267 /// linear filtering
268 pub const LINEAR: Self = Self((1_i32 as ::core::ffi::c_int));
269 /// nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0
270 pub const PIXELART: Self = Self((2_i32 as ::core::ffi::c_int));
271}
272
273pub const SDL_SCALEMODE_INVALID: SDL_ScaleMode = SDL_ScaleMode::INVALID;
274/// nearest pixel sampling
275pub const SDL_SCALEMODE_NEAREST: SDL_ScaleMode = SDL_ScaleMode::NEAREST;
276/// linear filtering
277pub const SDL_SCALEMODE_LINEAR: SDL_ScaleMode = SDL_ScaleMode::LINEAR;
278/// nearest pixel sampling with improved scaling for pixel art, available since SDL 3.4.0
279pub const SDL_SCALEMODE_PIXELART: SDL_ScaleMode = SDL_ScaleMode::PIXELART;
280
281#[cfg(feature = "metadata")]
282impl sdl3_sys::metadata::GroupMetadata for SDL_ScaleMode {
283 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
284 &crate::metadata::surface::METADATA_SDL_ScaleMode;
285}
286
287/// The flip mode.
288///
289/// ## Availability
290/// This enum is available since SDL 3.2.0.
291///
292/// ## Known values (`sdl3-sys`)
293/// | Associated constant | Global constant | Description |
294/// | ------------------- | --------------- | ----------- |
295/// | [`NONE`](SDL_FlipMode::NONE) | [`SDL_FLIP_NONE`] | Do not flip |
296/// | [`HORIZONTAL`](SDL_FlipMode::HORIZONTAL) | [`SDL_FLIP_HORIZONTAL`] | flip horizontally |
297/// | [`VERTICAL`](SDL_FlipMode::VERTICAL) | [`SDL_FLIP_VERTICAL`] | flip vertically |
298/// | [`HORIZONTAL_AND_VERTICAL`](SDL_FlipMode::HORIZONTAL_AND_VERTICAL) | [`SDL_FLIP_HORIZONTAL_AND_VERTICAL`] | flip horizontally and vertically (not a diagonal flip) |
299#[repr(transparent)]
300#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
301pub struct SDL_FlipMode(pub ::core::ffi::c_int);
302
303impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_FlipMode {
304 #[inline(always)]
305 fn eq(&self, other: &::core::ffi::c_int) -> bool {
306 &self.0 == other
307 }
308}
309
310impl ::core::cmp::PartialEq<SDL_FlipMode> for ::core::ffi::c_int {
311 #[inline(always)]
312 fn eq(&self, other: &SDL_FlipMode) -> bool {
313 self == &other.0
314 }
315}
316
317impl From<SDL_FlipMode> for ::core::ffi::c_int {
318 #[inline(always)]
319 fn from(value: SDL_FlipMode) -> Self {
320 value.0
321 }
322}
323
324#[cfg(feature = "debug-impls")]
325impl ::core::fmt::Debug for SDL_FlipMode {
326 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
327 let mut first = true;
328 let all_bits = 0;
329 write!(f, "SDL_FlipMode(")?;
330 let all_bits = all_bits | Self::NONE.0;
331 if (Self::NONE != 0 || self.0 == 0) && *self & Self::NONE == Self::NONE {
332 if !first {
333 write!(f, " | ")?;
334 }
335 first = false;
336 write!(f, "NONE")?;
337 }
338 let all_bits = all_bits | Self::HORIZONTAL.0;
339 if (Self::HORIZONTAL != 0 || self.0 == 0) && *self & Self::HORIZONTAL == Self::HORIZONTAL {
340 if !first {
341 write!(f, " | ")?;
342 }
343 first = false;
344 write!(f, "HORIZONTAL")?;
345 }
346 let all_bits = all_bits | Self::VERTICAL.0;
347 if (Self::VERTICAL != 0 || self.0 == 0) && *self & Self::VERTICAL == Self::VERTICAL {
348 if !first {
349 write!(f, " | ")?;
350 }
351 first = false;
352 write!(f, "VERTICAL")?;
353 }
354 let all_bits = all_bits | Self::HORIZONTAL_AND_VERTICAL.0;
355 if (Self::HORIZONTAL_AND_VERTICAL != 0 || self.0 == 0)
356 && *self & Self::HORIZONTAL_AND_VERTICAL == Self::HORIZONTAL_AND_VERTICAL
357 {
358 if !first {
359 write!(f, " | ")?;
360 }
361 first = false;
362 write!(f, "HORIZONTAL_AND_VERTICAL")?;
363 }
364
365 if self.0 & !all_bits != 0 {
366 if !first {
367 write!(f, " | ")?;
368 }
369 write!(f, "{:#x}", self.0)?;
370 } else if first {
371 write!(f, "0")?;
372 }
373 write!(f, ")")
374 }
375}
376
377impl ::core::ops::BitAnd for SDL_FlipMode {
378 type Output = Self;
379
380 #[inline(always)]
381 fn bitand(self, rhs: Self) -> Self::Output {
382 Self(self.0 & rhs.0)
383 }
384}
385
386impl ::core::ops::BitAndAssign for SDL_FlipMode {
387 #[inline(always)]
388 fn bitand_assign(&mut self, rhs: Self) {
389 self.0 &= rhs.0;
390 }
391}
392
393impl ::core::ops::BitOr for SDL_FlipMode {
394 type Output = Self;
395
396 #[inline(always)]
397 fn bitor(self, rhs: Self) -> Self::Output {
398 Self(self.0 | rhs.0)
399 }
400}
401
402impl ::core::ops::BitOrAssign for SDL_FlipMode {
403 #[inline(always)]
404 fn bitor_assign(&mut self, rhs: Self) {
405 self.0 |= rhs.0;
406 }
407}
408
409impl ::core::ops::BitXor for SDL_FlipMode {
410 type Output = Self;
411
412 #[inline(always)]
413 fn bitxor(self, rhs: Self) -> Self::Output {
414 Self(self.0 ^ rhs.0)
415 }
416}
417
418impl ::core::ops::BitXorAssign for SDL_FlipMode {
419 #[inline(always)]
420 fn bitxor_assign(&mut self, rhs: Self) {
421 self.0 ^= rhs.0;
422 }
423}
424
425impl ::core::ops::Not for SDL_FlipMode {
426 type Output = Self;
427
428 #[inline(always)]
429 fn not(self) -> Self::Output {
430 Self(!self.0)
431 }
432}
433
434impl SDL_FlipMode {
435 /// Do not flip
436 pub const NONE: Self = Self((0 as ::core::ffi::c_int));
437 /// flip horizontally
438 pub const HORIZONTAL: Self = Self((1 as ::core::ffi::c_int));
439 /// flip vertically
440 pub const VERTICAL: Self = Self((2 as ::core::ffi::c_int));
441 /// flip horizontally and vertically (not a diagonal flip)
442 pub const HORIZONTAL_AND_VERTICAL: Self = Self((SDL_FLIP_HORIZONTAL.0 | SDL_FLIP_VERTICAL.0));
443}
444
445/// Do not flip
446pub const SDL_FLIP_NONE: SDL_FlipMode = SDL_FlipMode::NONE;
447/// flip horizontally
448pub const SDL_FLIP_HORIZONTAL: SDL_FlipMode = SDL_FlipMode::HORIZONTAL;
449/// flip vertically
450pub const SDL_FLIP_VERTICAL: SDL_FlipMode = SDL_FlipMode::VERTICAL;
451/// flip horizontally and vertically (not a diagonal flip)
452pub const SDL_FLIP_HORIZONTAL_AND_VERTICAL: SDL_FlipMode = SDL_FlipMode::HORIZONTAL_AND_VERTICAL;
453
454#[cfg(feature = "metadata")]
455impl sdl3_sys::metadata::GroupMetadata for SDL_FlipMode {
456 const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
457 &crate::metadata::surface::METADATA_SDL_FlipMode;
458}
459
460/// A collection of pixels used in software blitting.
461///
462/// Pixels are arranged in memory in rows, with the top row first. Each row
463/// occupies an amount of memory given by the pitch (sometimes known as the row
464/// stride in non-SDL APIs).
465///
466/// Within each row, pixels are arranged from left to right until the width is
467/// reached. Each pixel occupies a number of bits appropriate for its format,
468/// with most formats representing each pixel as one or more whole bytes (in
469/// some indexed formats, instead multiple pixels are packed into each byte),
470/// and a byte order given by the format. After encoding all pixels, any
471/// remaining bytes to reach the pitch are used as padding to reach a desired
472/// alignment, and have undefined contents.
473///
474/// When a surface holds YUV format data, the planes are assumed to be
475/// contiguous without padding between them, e.g. a 32x32 surface in NV12
476/// format with a pitch of 32 would consist of 32x32 bytes of Y plane followed
477/// by 32x16 bytes of UV plane.
478///
479/// When a surface holds MJPG format data, pixels points at the compressed JPEG
480/// image and pitch is the length of that data.
481///
482/// ## Availability
483/// This struct is available since SDL 3.2.0.
484///
485/// ## See also
486/// - [`SDL_CreateSurface`]
487/// - [`SDL_DestroySurface`]
488#[repr(C)]
489#[cfg_attr(feature = "debug-impls", derive(Debug))]
490pub struct SDL_Surface {
491 /// The flags of the surface, read-only
492 pub flags: SDL_SurfaceFlags,
493 /// The format of the surface, read-only
494 pub format: SDL_PixelFormat,
495 /// The width of the surface, read-only.
496 pub w: ::core::ffi::c_int,
497 /// The height of the surface, read-only.
498 pub h: ::core::ffi::c_int,
499 /// The distance in bytes between rows of pixels, read-only
500 pub pitch: ::core::ffi::c_int,
501 /// A pointer to the pixels of the surface, the pixels are writeable if non-NULL
502 pub pixels: *mut ::core::ffi::c_void,
503 /// Application reference count, used when freeing surface
504 pub refcount: ::core::ffi::c_int,
505 /// Reserved for internal use
506 pub reserved: *mut ::core::ffi::c_void,
507 #[doc(hidden)]
508 __non_exhaustive: ::sdl3_sys::NonExhaustive,
509}
510
511/// Evaluates to true if the surface needs to be locked before access.
512///
513/// ## Availability
514/// This macro is available since SDL 3.2.0.
515#[inline(always)]
516pub const unsafe fn SDL_MUSTLOCK(S: *const SDL_Surface) -> ::core::primitive::bool {
517 ((unsafe { (&raw const (*S).flags).read() }.0 & SDL_SURFACE_LOCK_NEEDED.0)
518 == SDL_SURFACE_LOCK_NEEDED.0)
519}
520
521unsafe extern "C" {
522 /// Allocate a new surface with a specific pixel format.
523 ///
524 /// The pixels of the new surface are initialized to zero.
525 ///
526 /// ## Parameters
527 /// - `width`: the width of the surface.
528 /// - `height`: the height of the surface.
529 /// - `format`: the [`SDL_PixelFormat`] for the new surface's pixel format.
530 ///
531 /// ## Return value
532 /// Returns the new [`SDL_Surface`] structure that is created or NULL on failure;
533 /// call [`SDL_GetError()`] for more information.
534 ///
535 /// ## Thread safety
536 /// It is safe to call this function from any thread.
537 ///
538 /// ## Availability
539 /// This function is available since SDL 3.2.0.
540 ///
541 /// ## See also
542 /// - [`SDL_CreateSurfaceFrom`]
543 /// - [`SDL_DestroySurface`]
544 pub fn SDL_CreateSurface(
545 width: ::core::ffi::c_int,
546 height: ::core::ffi::c_int,
547 format: SDL_PixelFormat,
548 ) -> *mut SDL_Surface;
549}
550
551unsafe extern "C" {
552 /// Allocate a new surface with a specific pixel format and existing pixel
553 /// data.
554 ///
555 /// No copy is made of the pixel data. Pixel data is not managed automatically;
556 /// you must free the surface before you free the pixel data.
557 ///
558 /// Pitch is the offset in bytes from one row of pixels to the next, e.g.
559 /// `width*4` for [`SDL_PIXELFORMAT_RGBA8888`].
560 ///
561 /// You may pass NULL for pixels and 0 for pitch to create a surface that you
562 /// will fill in with valid values later.
563 ///
564 /// ## Parameters
565 /// - `width`: the width of the surface.
566 /// - `height`: the height of the surface.
567 /// - `format`: the [`SDL_PixelFormat`] for the new surface's pixel format.
568 /// - `pixels`: a pointer to existing pixel data.
569 /// - `pitch`: the number of bytes between each row, including padding.
570 ///
571 /// ## Return value
572 /// Returns the new [`SDL_Surface`] structure that is created or NULL on failure;
573 /// call [`SDL_GetError()`] for more information.
574 ///
575 /// ## Thread safety
576 /// It is safe to call this function from any thread.
577 ///
578 /// ## Availability
579 /// This function is available since SDL 3.2.0.
580 ///
581 /// ## See also
582 /// - [`SDL_CreateSurface`]
583 /// - [`SDL_DestroySurface`]
584 pub fn SDL_CreateSurfaceFrom(
585 width: ::core::ffi::c_int,
586 height: ::core::ffi::c_int,
587 format: SDL_PixelFormat,
588 pixels: *mut ::core::ffi::c_void,
589 pitch: ::core::ffi::c_int,
590 ) -> *mut SDL_Surface;
591}
592
593unsafe extern "C" {
594 /// Free a surface.
595 ///
596 /// It is safe to pass NULL to this function.
597 ///
598 /// ## Parameters
599 /// - `surface`: the [`SDL_Surface`] to free.
600 ///
601 /// ## Thread safety
602 /// No other thread should be using the surface when it is freed.
603 ///
604 /// ## Availability
605 /// This function is available since SDL 3.2.0.
606 ///
607 /// ## See also
608 /// - [`SDL_CreateSurface`]
609 /// - [`SDL_CreateSurfaceFrom`]
610 pub fn SDL_DestroySurface(surface: *mut SDL_Surface);
611}
612
613unsafe extern "C" {
614 /// Get the properties associated with a surface.
615 ///
616 /// The following properties are understood by SDL:
617 ///
618 /// - [`SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`]\: for HDR10 and floating point
619 /// surfaces, this defines the value of 100% diffuse white, with higher
620 /// values being displayed in the High Dynamic Range headroom. This defaults
621 /// to 203 for HDR10 surfaces and 1.0 for floating point surfaces.
622 /// - [`SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT`]\: for HDR10 and floating point
623 /// surfaces, this defines the maximum dynamic range used by the content, in
624 /// terms of the SDR white point. This defaults to 0.0, which disables tone
625 /// mapping.
626 /// - [`SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING`]\: the tone mapping operator
627 /// used when compressing from a surface with high dynamic range to another
628 /// with lower dynamic range. Currently this supports "chrome", which uses
629 /// the same tone mapping that Chrome uses for HDR content, the form "*=N",
630 /// where N is a floating point scale factor applied in linear space, and
631 /// "none", which disables tone mapping. This defaults to "chrome".
632 /// - [`SDL_PROP_SURFACE_HOTSPOT_X_NUMBER`]\: the hotspot pixel offset from the
633 /// left edge of the image, if this surface is being used as a cursor.
634 /// - [`SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER`]\: the hotspot pixel offset from the
635 /// top edge of the image, if this surface is being used as a cursor.
636 /// - [`SDL_PROP_SURFACE_ROTATION_FLOAT`]\: the number of degrees a surface's data
637 /// is meant to be rotated clockwise to make the image right-side up. Default
638 /// 0. This is used by the camera API, if a mobile device is oriented
639 /// differently than what its camera provides (i.e. - the camera always
640 /// provides portrait images but the phone is being held in landscape
641 /// orientation). Since SDL 3.4.0.
642 ///
643 /// ## Parameters
644 /// - `surface`: the [`SDL_Surface`] structure to query.
645 ///
646 /// ## Return value
647 /// Returns a valid property ID on success or 0 on failure; call
648 /// [`SDL_GetError()`] for more information.
649 ///
650 /// ## Thread safety
651 /// It is safe to call this function from any thread.
652 ///
653 /// ## Availability
654 /// This function is available since SDL 3.2.0.
655 pub fn SDL_GetSurfaceProperties(surface: *mut SDL_Surface) -> SDL_PropertiesID;
656}
657
658pub const SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT: *const ::core::ffi::c_char =
659 c"SDL.surface.SDR_white_point".as_ptr();
660
661pub const SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT: *const ::core::ffi::c_char =
662 c"SDL.surface.HDR_headroom".as_ptr();
663
664pub const SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING: *const ::core::ffi::c_char =
665 c"SDL.surface.tonemap".as_ptr();
666
667pub const SDL_PROP_SURFACE_HOTSPOT_X_NUMBER: *const ::core::ffi::c_char =
668 c"SDL.surface.hotspot.x".as_ptr();
669
670pub const SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER: *const ::core::ffi::c_char =
671 c"SDL.surface.hotspot.y".as_ptr();
672
673pub const SDL_PROP_SURFACE_ROTATION_FLOAT: *const ::core::ffi::c_char =
674 c"SDL.surface.rotation".as_ptr();
675
676unsafe extern "C" {
677 /// Set the colorspace used by a surface.
678 ///
679 /// Setting the colorspace doesn't change the pixels, only how they are
680 /// interpreted in color operations.
681 ///
682 /// ## Parameters
683 /// - `surface`: the [`SDL_Surface`] structure to update.
684 /// - `colorspace`: an [`SDL_Colorspace`] value describing the surface
685 /// colorspace.
686 ///
687 /// ## Return value
688 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
689 /// information.
690 ///
691 /// ## Thread safety
692 /// This function can be called on different threads with
693 /// different surfaces.
694 ///
695 /// ## Availability
696 /// This function is available since SDL 3.2.0.
697 ///
698 /// ## See also
699 /// - [`SDL_GetSurfaceColorspace`]
700 pub fn SDL_SetSurfaceColorspace(
701 surface: *mut SDL_Surface,
702 colorspace: SDL_Colorspace,
703 ) -> ::core::primitive::bool;
704}
705
706unsafe extern "C" {
707 /// Get the colorspace used by a surface.
708 ///
709 /// The colorspace defaults to [`SDL_COLORSPACE_SRGB_LINEAR`] for floating point
710 /// formats, [`SDL_COLORSPACE_HDR10`] for 10-bit formats, [`SDL_COLORSPACE_SRGB`] for
711 /// other RGB surfaces and [`SDL_COLORSPACE_BT709_FULL`] for YUV textures.
712 ///
713 /// ## Parameters
714 /// - `surface`: the [`SDL_Surface`] structure to query.
715 ///
716 /// ## Return value
717 /// Returns the colorspace used by the surface, or [`SDL_COLORSPACE_UNKNOWN`] if
718 /// the surface is NULL.
719 ///
720 /// ## Thread safety
721 /// This function can be called on different threads with
722 /// different surfaces.
723 ///
724 /// ## Availability
725 /// This function is available since SDL 3.2.0.
726 ///
727 /// ## See also
728 /// - [`SDL_SetSurfaceColorspace`]
729 pub fn SDL_GetSurfaceColorspace(surface: *mut SDL_Surface) -> SDL_Colorspace;
730}
731
732unsafe extern "C" {
733 /// Create a palette and associate it with a surface.
734 ///
735 /// This function creates a palette compatible with the provided surface. The
736 /// palette is then returned for you to modify, and the surface will
737 /// automatically use the new palette in future operations. You do not need to
738 /// destroy the returned palette, it will be freed when the reference count
739 /// reaches 0, usually when the surface is destroyed.
740 ///
741 /// Bitmap surfaces (with format [`SDL_PIXELFORMAT_INDEX1LSB`] or
742 /// [`SDL_PIXELFORMAT_INDEX1MSB`]) will have the palette initialized with 0 as
743 /// white and 1 as black. Other surfaces will get a palette initialized with
744 /// white in every entry.
745 ///
746 /// If this function is called for a surface that already has a palette, a new
747 /// palette will be created to replace it.
748 ///
749 /// ## Parameters
750 /// - `surface`: the [`SDL_Surface`] structure to update.
751 ///
752 /// ## Return value
753 /// Returns a new [`SDL_Palette`] structure on success or NULL on failure (e.g. if
754 /// the surface didn't have an index format); call [`SDL_GetError()`] for
755 /// more information.
756 ///
757 /// ## Thread safety
758 /// This function can be called on different threads with
759 /// different surfaces.
760 ///
761 /// ## Availability
762 /// This function is available since SDL 3.2.0.
763 ///
764 /// ## See also
765 /// - [`SDL_SetPaletteColors`]
766 pub fn SDL_CreateSurfacePalette(surface: *mut SDL_Surface) -> *mut SDL_Palette;
767}
768
769unsafe extern "C" {
770 /// Set the palette used by a surface.
771 ///
772 /// Setting the palette keeps an internal reference to the palette, which can
773 /// be safely destroyed afterwards.
774 ///
775 /// A single palette can be shared with many surfaces.
776 ///
777 /// ## Parameters
778 /// - `surface`: the [`SDL_Surface`] structure to update.
779 /// - `palette`: the [`SDL_Palette`] structure to use.
780 ///
781 /// ## Return value
782 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
783 /// information.
784 ///
785 /// ## Thread safety
786 /// This function can be called on different threads with
787 /// different surfaces.
788 ///
789 /// ## Availability
790 /// This function is available since SDL 3.2.0.
791 ///
792 /// ## See also
793 /// - [`SDL_CreatePalette`]
794 /// - [`SDL_GetSurfacePalette`]
795 pub fn SDL_SetSurfacePalette(
796 surface: *mut SDL_Surface,
797 palette: *mut SDL_Palette,
798 ) -> ::core::primitive::bool;
799}
800
801unsafe extern "C" {
802 /// Get the palette used by a surface.
803 ///
804 /// ## Parameters
805 /// - `surface`: the [`SDL_Surface`] structure to query.
806 ///
807 /// ## Return value
808 /// Returns a pointer to the palette used by the surface, or NULL if there is
809 /// no palette used.
810 ///
811 /// ## Thread safety
812 /// It is safe to call this function from any thread.
813 ///
814 /// ## Availability
815 /// This function is available since SDL 3.2.0.
816 ///
817 /// ## See also
818 /// - [`SDL_SetSurfacePalette`]
819 pub fn SDL_GetSurfacePalette(surface: *mut SDL_Surface) -> *mut SDL_Palette;
820}
821
822unsafe extern "C" {
823 /// Add an alternate version of a surface.
824 ///
825 /// This function adds an alternate version of this surface, usually used for
826 /// content with high DPI representations like cursors or icons. The size,
827 /// format, and content do not need to match the original surface, and these
828 /// alternate versions will not be updated when the original surface changes.
829 ///
830 /// This function adds a reference to the alternate version, so you should call
831 /// [`SDL_DestroySurface()`] on the image after this call.
832 ///
833 /// ## Parameters
834 /// - `surface`: the [`SDL_Surface`] structure to update.
835 /// - `image`: a pointer to an alternate [`SDL_Surface`] to associate with this
836 /// surface.
837 ///
838 /// ## Return value
839 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
840 /// information.
841 ///
842 /// ## Thread safety
843 /// This function can be called on different threads with
844 /// different surfaces.
845 ///
846 /// ## Availability
847 /// This function is available since SDL 3.2.0.
848 ///
849 /// ## See also
850 /// - [`SDL_RemoveSurfaceAlternateImages`]
851 /// - [`SDL_GetSurfaceImages`]
852 /// - [`SDL_SurfaceHasAlternateImages`]
853 pub fn SDL_AddSurfaceAlternateImage(
854 surface: *mut SDL_Surface,
855 image: *mut SDL_Surface,
856 ) -> ::core::primitive::bool;
857}
858
859unsafe extern "C" {
860 /// Return whether a surface has alternate versions available.
861 ///
862 /// ## Parameters
863 /// - `surface`: the [`SDL_Surface`] structure to query.
864 ///
865 /// ## Return value
866 /// Returns true if alternate versions are available or false otherwise.
867 ///
868 /// ## Thread safety
869 /// It is safe to call this function from any thread.
870 ///
871 /// ## Availability
872 /// This function is available since SDL 3.2.0.
873 ///
874 /// ## See also
875 /// - [`SDL_AddSurfaceAlternateImage`]
876 /// - [`SDL_RemoveSurfaceAlternateImages`]
877 /// - [`SDL_GetSurfaceImages`]
878 pub fn SDL_SurfaceHasAlternateImages(surface: *mut SDL_Surface) -> ::core::primitive::bool;
879}
880
881unsafe extern "C" {
882 /// Get an array including all versions of a surface.
883 ///
884 /// This returns all versions of a surface, with the surface being queried as
885 /// the first element in the returned array.
886 ///
887 /// Freeing the array of surfaces does not affect the surfaces in the array.
888 /// They are still referenced by the surface being queried and will be cleaned
889 /// up normally.
890 ///
891 /// ## Parameters
892 /// - `surface`: the [`SDL_Surface`] structure to query.
893 /// - `count`: a pointer filled in with the number of surface pointers
894 /// returned, may be NULL.
895 ///
896 /// ## Return value
897 /// Returns a NULL terminated array of [`SDL_Surface`] pointers or NULL on
898 /// failure; call [`SDL_GetError()`] for more information. This should be
899 /// freed with [`SDL_free()`] when it is no longer needed.
900 ///
901 /// ## Thread safety
902 /// This function can be called on different threads with
903 /// different surfaces.
904 ///
905 /// ## Availability
906 /// This function is available since SDL 3.2.0.
907 ///
908 /// ## See also
909 /// - [`SDL_AddSurfaceAlternateImage`]
910 /// - [`SDL_RemoveSurfaceAlternateImages`]
911 /// - [`SDL_SurfaceHasAlternateImages`]
912 pub fn SDL_GetSurfaceImages(
913 surface: *mut SDL_Surface,
914 count: *mut ::core::ffi::c_int,
915 ) -> *mut *mut SDL_Surface;
916}
917
918unsafe extern "C" {
919 /// Remove all alternate versions of a surface.
920 ///
921 /// This function removes a reference from all the alternative versions,
922 /// destroying them if this is the last reference to them.
923 ///
924 /// ## Parameters
925 /// - `surface`: the [`SDL_Surface`] structure to update.
926 ///
927 /// ## Thread safety
928 /// This function can be called on different threads with
929 /// different surfaces.
930 ///
931 /// ## Availability
932 /// This function is available since SDL 3.2.0.
933 ///
934 /// ## See also
935 /// - [`SDL_AddSurfaceAlternateImage`]
936 /// - [`SDL_GetSurfaceImages`]
937 /// - [`SDL_SurfaceHasAlternateImages`]
938 pub fn SDL_RemoveSurfaceAlternateImages(surface: *mut SDL_Surface);
939}
940
941unsafe extern "C" {
942 /// Set up a surface for directly accessing the pixels.
943 ///
944 /// Between calls to [`SDL_LockSurface()`] / [`SDL_UnlockSurface()`], you can write to
945 /// and read from `surface->pixels`, using the pixel format stored in
946 /// `surface->format`. Once you are done accessing the surface, you should use
947 /// [`SDL_UnlockSurface()`] to release it.
948 ///
949 /// Not all surfaces require locking. If `SDL_MUSTLOCK(surface)` evaluates to
950 /// 0, then you can read and write to the surface at any time, and the pixel
951 /// format of the surface will not change.
952 ///
953 /// ## Parameters
954 /// - `surface`: the [`SDL_Surface`] structure to be locked.
955 ///
956 /// ## Return value
957 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
958 /// information.
959 ///
960 /// ## Thread safety
961 /// This function can be called on different threads with
962 /// different surfaces. The locking referred to by this function
963 /// is making the pixels available for direct access, not
964 /// thread-safe locking.
965 ///
966 /// ## Availability
967 /// This function is available since SDL 3.2.0.
968 ///
969 /// ## See also
970 /// - [`SDL_MUSTLOCK`]
971 /// - [`SDL_UnlockSurface`]
972 pub fn SDL_LockSurface(surface: *mut SDL_Surface) -> ::core::primitive::bool;
973}
974
975unsafe extern "C" {
976 /// Release a surface after directly accessing the pixels.
977 ///
978 /// ## Parameters
979 /// - `surface`: the [`SDL_Surface`] structure to be unlocked.
980 ///
981 /// ## Thread safety
982 /// This function is not thread safe. The locking referred to by
983 /// this function is making the pixels available for direct
984 /// access, not thread-safe locking.
985 ///
986 /// ## Availability
987 /// This function is available since SDL 3.2.0.
988 ///
989 /// ## See also
990 /// - [`SDL_LockSurface`]
991 pub fn SDL_UnlockSurface(surface: *mut SDL_Surface);
992}
993
994unsafe extern "C" {
995 /// Load a BMP or PNG image from a seekable SDL data stream.
996 ///
997 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
998 /// will result in a memory leak.
999 ///
1000 /// ## Parameters
1001 /// - `src`: the data stream for the surface.
1002 /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `src` before returning, even
1003 /// in the case of an error.
1004 ///
1005 /// ## Return value
1006 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1007 /// [`SDL_GetError()`] for more information.
1008 ///
1009 /// ## Thread safety
1010 /// It is safe to call this function from any thread.
1011 ///
1012 /// ## Availability
1013 /// This function is available since SDL 3.4.0.
1014 ///
1015 /// ## See also
1016 /// - [`SDL_DestroySurface`]
1017 /// - [`SDL_LoadSurface`]
1018 pub fn SDL_LoadSurface_IO(
1019 src: *mut SDL_IOStream,
1020 closeio: ::core::primitive::bool,
1021 ) -> *mut SDL_Surface;
1022}
1023
1024unsafe extern "C" {
1025 /// Load a BMP or PNG image from a file.
1026 ///
1027 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
1028 /// will result in a memory leak.
1029 ///
1030 /// ## Parameters
1031 /// - `file`: the file to load.
1032 ///
1033 /// ## Return value
1034 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1035 /// [`SDL_GetError()`] for more information.
1036 ///
1037 /// ## Thread safety
1038 /// It is safe to call this function from any thread.
1039 ///
1040 /// ## Availability
1041 /// This function is available since SDL 3.4.0.
1042 ///
1043 /// ## See also
1044 /// - [`SDL_DestroySurface`]
1045 /// - [`SDL_LoadSurface_IO`]
1046 pub fn SDL_LoadSurface(file: *const ::core::ffi::c_char) -> *mut SDL_Surface;
1047}
1048
1049unsafe extern "C" {
1050 /// Load a BMP image from a seekable SDL data stream.
1051 ///
1052 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
1053 /// will result in a memory leak.
1054 ///
1055 /// ## Parameters
1056 /// - `src`: the data stream for the surface.
1057 /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `src` before returning, even
1058 /// in the case of an error.
1059 ///
1060 /// ## Return value
1061 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1062 /// [`SDL_GetError()`] for more information.
1063 ///
1064 /// ## Thread safety
1065 /// It is safe to call this function from any thread.
1066 ///
1067 /// ## Availability
1068 /// This function is available since SDL 3.2.0.
1069 ///
1070 /// ## See also
1071 /// - [`SDL_DestroySurface`]
1072 /// - [`SDL_LoadBMP`]
1073 /// - [`SDL_SaveBMP_IO`]
1074 pub fn SDL_LoadBMP_IO(
1075 src: *mut SDL_IOStream,
1076 closeio: ::core::primitive::bool,
1077 ) -> *mut SDL_Surface;
1078}
1079
1080unsafe extern "C" {
1081 /// Load a BMP image from a file.
1082 ///
1083 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
1084 /// will result in a memory leak.
1085 ///
1086 /// ## Parameters
1087 /// - `file`: the BMP file to load.
1088 ///
1089 /// ## Return value
1090 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1091 /// [`SDL_GetError()`] for more information.
1092 ///
1093 /// ## Thread safety
1094 /// It is safe to call this function from any thread.
1095 ///
1096 /// ## Availability
1097 /// This function is available since SDL 3.2.0.
1098 ///
1099 /// ## See also
1100 /// - [`SDL_DestroySurface`]
1101 /// - [`SDL_LoadBMP_IO`]
1102 /// - [`SDL_SaveBMP`]
1103 pub fn SDL_LoadBMP(file: *const ::core::ffi::c_char) -> *mut SDL_Surface;
1104}
1105
1106unsafe extern "C" {
1107 /// Save a surface to a seekable SDL data stream in BMP format.
1108 ///
1109 /// Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
1110 /// BMP directly. Other RGB formats with 8-bit or higher get converted to a
1111 /// 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
1112 /// surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
1113 /// not supported.
1114 ///
1115 /// ## Parameters
1116 /// - `surface`: the [`SDL_Surface`] structure containing the image to be saved.
1117 /// - `dst`: a data stream to save to.
1118 /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `dst` before returning, even
1119 /// in the case of an error.
1120 ///
1121 /// ## Return value
1122 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1123 /// information.
1124 ///
1125 /// ## Thread safety
1126 /// This function can be called on different threads with
1127 /// different surfaces.
1128 ///
1129 /// ## Availability
1130 /// This function is available since SDL 3.2.0.
1131 ///
1132 /// ## See also
1133 /// - [`SDL_LoadBMP_IO`]
1134 /// - [`SDL_SaveBMP`]
1135 pub fn SDL_SaveBMP_IO(
1136 surface: *mut SDL_Surface,
1137 dst: *mut SDL_IOStream,
1138 closeio: ::core::primitive::bool,
1139 ) -> ::core::primitive::bool;
1140}
1141
1142unsafe extern "C" {
1143 /// Save a surface to a file in BMP format.
1144 ///
1145 /// Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
1146 /// BMP directly. Other RGB formats with 8-bit or higher get converted to a
1147 /// 24-bit surface or, if they have an alpha mask or a colorkey, to a 32-bit
1148 /// surface before they are saved. YUV and paletted 1-bit and 4-bit formats are
1149 /// not supported.
1150 ///
1151 /// ## Parameters
1152 /// - `surface`: the [`SDL_Surface`] structure containing the image to be saved.
1153 /// - `file`: a file to save to.
1154 ///
1155 /// ## Return value
1156 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1157 /// information.
1158 ///
1159 /// ## Thread safety
1160 /// This function can be called on different threads with
1161 /// different surfaces.
1162 ///
1163 /// ## Availability
1164 /// This function is available since SDL 3.2.0.
1165 ///
1166 /// ## See also
1167 /// - [`SDL_LoadBMP`]
1168 /// - [`SDL_SaveBMP_IO`]
1169 pub fn SDL_SaveBMP(
1170 surface: *mut SDL_Surface,
1171 file: *const ::core::ffi::c_char,
1172 ) -> ::core::primitive::bool;
1173}
1174
1175unsafe extern "C" {
1176 /// Load a PNG image from a seekable SDL data stream.
1177 ///
1178 /// This is intended as a convenience function for loading images from trusted
1179 /// sources. If you want to load arbitrary images you should use libpng or
1180 /// another image loading library designed with security in mind.
1181 ///
1182 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
1183 /// will result in a memory leak.
1184 ///
1185 /// ## Parameters
1186 /// - `src`: the data stream for the surface.
1187 /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `src` before returning, even
1188 /// in the case of an error.
1189 ///
1190 /// ## Return value
1191 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1192 /// [`SDL_GetError()`] for more information.
1193 ///
1194 /// ## Thread safety
1195 /// It is safe to call this function from any thread.
1196 ///
1197 /// ## Availability
1198 /// This function is available since SDL 3.4.0.
1199 ///
1200 /// ## See also
1201 /// - [`SDL_DestroySurface`]
1202 /// - [`SDL_LoadPNG`]
1203 /// - [`SDL_SavePNG_IO`]
1204 pub fn SDL_LoadPNG_IO(
1205 src: *mut SDL_IOStream,
1206 closeio: ::core::primitive::bool,
1207 ) -> *mut SDL_Surface;
1208}
1209
1210unsafe extern "C" {
1211 /// Load a PNG image from a file.
1212 ///
1213 /// This is intended as a convenience function for loading images from trusted
1214 /// sources. If you want to load arbitrary images you should use libpng or
1215 /// another image loading library designed with security in mind.
1216 ///
1217 /// The new surface should be freed with [`SDL_DestroySurface()`]. Not doing so
1218 /// will result in a memory leak.
1219 ///
1220 /// ## Parameters
1221 /// - `file`: the PNG file to load.
1222 ///
1223 /// ## Return value
1224 /// Returns a pointer to a new [`SDL_Surface`] structure or NULL on failure; call
1225 /// [`SDL_GetError()`] for more information.
1226 ///
1227 /// ## Thread safety
1228 /// It is safe to call this function from any thread.
1229 ///
1230 /// ## Availability
1231 /// This function is available since SDL 3.4.0.
1232 ///
1233 /// ## See also
1234 /// - [`SDL_DestroySurface`]
1235 /// - [`SDL_LoadPNG_IO`]
1236 /// - [`SDL_SavePNG`]
1237 pub fn SDL_LoadPNG(file: *const ::core::ffi::c_char) -> *mut SDL_Surface;
1238}
1239
1240unsafe extern "C" {
1241 /// Save a surface to a seekable SDL data stream in PNG format.
1242 ///
1243 /// ## Parameters
1244 /// - `surface`: the [`SDL_Surface`] structure containing the image to be saved.
1245 /// - `dst`: a data stream to save to.
1246 /// - `closeio`: if true, calls [`SDL_CloseIO()`] on `dst` before returning, even
1247 /// in the case of an error.
1248 ///
1249 /// ## Return value
1250 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1251 /// information.
1252 ///
1253 /// ## Thread safety
1254 /// This function can be called on different threads with
1255 /// different surfaces.
1256 ///
1257 /// ## Availability
1258 /// This function is available since SDL 3.4.0.
1259 ///
1260 /// ## See also
1261 /// - [`SDL_LoadPNG_IO`]
1262 /// - [`SDL_SavePNG`]
1263 pub fn SDL_SavePNG_IO(
1264 surface: *mut SDL_Surface,
1265 dst: *mut SDL_IOStream,
1266 closeio: ::core::primitive::bool,
1267 ) -> ::core::primitive::bool;
1268}
1269
1270unsafe extern "C" {
1271 /// Save a surface to a file in PNG format.
1272 ///
1273 /// ## Parameters
1274 /// - `surface`: the [`SDL_Surface`] structure containing the image to be saved.
1275 /// - `file`: a file to save to.
1276 ///
1277 /// ## Return value
1278 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1279 /// information.
1280 ///
1281 /// ## Thread safety
1282 /// This function can be called on different threads with
1283 /// different surfaces.
1284 ///
1285 /// ## Availability
1286 /// This function is available since SDL 3.4.0.
1287 ///
1288 /// ## See also
1289 /// - [`SDL_LoadPNG`]
1290 /// - [`SDL_SavePNG_IO`]
1291 pub fn SDL_SavePNG(
1292 surface: *mut SDL_Surface,
1293 file: *const ::core::ffi::c_char,
1294 ) -> ::core::primitive::bool;
1295}
1296
1297unsafe extern "C" {
1298 /// Set the RLE acceleration hint for a surface.
1299 ///
1300 /// If RLE is enabled, color key and alpha blending blits are much faster, but
1301 /// the surface must be locked before directly accessing the pixels.
1302 ///
1303 /// ## Parameters
1304 /// - `surface`: the [`SDL_Surface`] structure to optimize.
1305 /// - `enabled`: true to enable RLE acceleration, false to disable it.
1306 ///
1307 /// ## Return value
1308 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1309 /// information.
1310 ///
1311 /// ## Thread safety
1312 /// This function can be called on different threads with
1313 /// different surfaces.
1314 ///
1315 /// ## Availability
1316 /// This function is available since SDL 3.2.0.
1317 ///
1318 /// ## See also
1319 /// - [`SDL_BlitSurface`]
1320 /// - [`SDL_LockSurface`]
1321 /// - [`SDL_UnlockSurface`]
1322 pub fn SDL_SetSurfaceRLE(
1323 surface: *mut SDL_Surface,
1324 enabled: ::core::primitive::bool,
1325 ) -> ::core::primitive::bool;
1326}
1327
1328unsafe extern "C" {
1329 /// Returns whether the surface is RLE enabled.
1330 ///
1331 /// It is safe to pass a NULL `surface` here; it will return false.
1332 ///
1333 /// ## Parameters
1334 /// - `surface`: the [`SDL_Surface`] structure to query.
1335 ///
1336 /// ## Return value
1337 /// Returns true if the surface is RLE enabled, false otherwise.
1338 ///
1339 /// ## Thread safety
1340 /// It is safe to call this function from any thread.
1341 ///
1342 /// ## Availability
1343 /// This function is available since SDL 3.2.0.
1344 ///
1345 /// ## See also
1346 /// - [`SDL_SetSurfaceRLE`]
1347 pub fn SDL_SurfaceHasRLE(surface: *mut SDL_Surface) -> ::core::primitive::bool;
1348}
1349
1350unsafe extern "C" {
1351 /// Set the color key (transparent pixel) in a surface.
1352 ///
1353 /// The color key defines a pixel value that will be treated as transparent in
1354 /// a blit. For example, one can use this to specify that cyan pixels should be
1355 /// considered transparent, and therefore not rendered.
1356 ///
1357 /// It is a pixel of the format used by the surface, as generated by
1358 /// [`SDL_MapRGB()`].
1359 ///
1360 /// ## Parameters
1361 /// - `surface`: the [`SDL_Surface`] structure to update.
1362 /// - `enabled`: true to enable color key, false to disable color key.
1363 /// - `key`: the transparent pixel.
1364 ///
1365 /// ## Return value
1366 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1367 /// information.
1368 ///
1369 /// ## Thread safety
1370 /// This function can be called on different threads with
1371 /// different surfaces.
1372 ///
1373 /// ## Availability
1374 /// This function is available since SDL 3.2.0.
1375 ///
1376 /// ## See also
1377 /// - [`SDL_GetSurfaceColorKey`]
1378 /// - [`SDL_SetSurfaceRLE`]
1379 /// - [`SDL_SurfaceHasColorKey`]
1380 pub fn SDL_SetSurfaceColorKey(
1381 surface: *mut SDL_Surface,
1382 enabled: ::core::primitive::bool,
1383 key: Uint32,
1384 ) -> ::core::primitive::bool;
1385}
1386
1387unsafe extern "C" {
1388 /// Returns whether the surface has a color key.
1389 ///
1390 /// It is safe to pass a NULL `surface` here; it will return false.
1391 ///
1392 /// ## Parameters
1393 /// - `surface`: the [`SDL_Surface`] structure to query.
1394 ///
1395 /// ## Return value
1396 /// Returns true if the surface has a color key, false otherwise.
1397 ///
1398 /// ## Thread safety
1399 /// It is safe to call this function from any thread.
1400 ///
1401 /// ## Availability
1402 /// This function is available since SDL 3.2.0.
1403 ///
1404 /// ## See also
1405 /// - [`SDL_SetSurfaceColorKey`]
1406 /// - [`SDL_GetSurfaceColorKey`]
1407 pub fn SDL_SurfaceHasColorKey(surface: *mut SDL_Surface) -> ::core::primitive::bool;
1408}
1409
1410unsafe extern "C" {
1411 /// Get the color key (transparent pixel) for a surface.
1412 ///
1413 /// The color key is a pixel of the format used by the surface, as generated by
1414 /// [`SDL_MapRGB()`].
1415 ///
1416 /// If the surface doesn't have color key enabled this function returns false.
1417 ///
1418 /// ## Parameters
1419 /// - `surface`: the [`SDL_Surface`] structure to query.
1420 /// - `key`: a pointer filled in with the transparent pixel.
1421 ///
1422 /// ## Return value
1423 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1424 /// information.
1425 ///
1426 /// ## Thread safety
1427 /// It is safe to call this function from any thread.
1428 ///
1429 /// ## Availability
1430 /// This function is available since SDL 3.2.0.
1431 ///
1432 /// ## See also
1433 /// - [`SDL_SetSurfaceColorKey`]
1434 /// - [`SDL_SurfaceHasColorKey`]
1435 pub fn SDL_GetSurfaceColorKey(
1436 surface: *mut SDL_Surface,
1437 key: *mut Uint32,
1438 ) -> ::core::primitive::bool;
1439}
1440
1441unsafe extern "C" {
1442 /// Set an additional color value multiplied into blit operations.
1443 ///
1444 /// When this surface is blitted, during the blit operation each source color
1445 /// channel is modulated by the appropriate color value according to the
1446 /// following formula:
1447 ///
1448 /// `srcC = srcC * (color / 255)`
1449 ///
1450 /// ## Parameters
1451 /// - `surface`: the [`SDL_Surface`] structure to update.
1452 /// - `r`: the red color value multiplied into blit operations.
1453 /// - `g`: the green color value multiplied into blit operations.
1454 /// - `b`: the blue color value multiplied into blit operations.
1455 ///
1456 /// ## Return value
1457 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1458 /// information.
1459 ///
1460 /// ## Thread safety
1461 /// This function can be called on different threads with
1462 /// different surfaces.
1463 ///
1464 /// ## Availability
1465 /// This function is available since SDL 3.2.0.
1466 ///
1467 /// ## See also
1468 /// - [`SDL_GetSurfaceColorMod`]
1469 /// - [`SDL_SetSurfaceAlphaMod`]
1470 pub fn SDL_SetSurfaceColorMod(
1471 surface: *mut SDL_Surface,
1472 r: Uint8,
1473 g: Uint8,
1474 b: Uint8,
1475 ) -> ::core::primitive::bool;
1476}
1477
1478unsafe extern "C" {
1479 /// Get the additional color value multiplied into blit operations.
1480 ///
1481 /// ## Parameters
1482 /// - `surface`: the [`SDL_Surface`] structure to query.
1483 /// - `r`: a pointer filled in with the current red color value.
1484 /// - `g`: a pointer filled in with the current green color value.
1485 /// - `b`: a pointer filled in with the current blue color value.
1486 ///
1487 /// ## Return value
1488 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1489 /// information.
1490 ///
1491 /// ## Thread safety
1492 /// This function can be called on different threads with
1493 /// different surfaces.
1494 ///
1495 /// ## Availability
1496 /// This function is available since SDL 3.2.0.
1497 ///
1498 /// ## See also
1499 /// - [`SDL_GetSurfaceAlphaMod`]
1500 /// - [`SDL_SetSurfaceColorMod`]
1501 pub fn SDL_GetSurfaceColorMod(
1502 surface: *mut SDL_Surface,
1503 r: *mut Uint8,
1504 g: *mut Uint8,
1505 b: *mut Uint8,
1506 ) -> ::core::primitive::bool;
1507}
1508
1509unsafe extern "C" {
1510 /// Set an additional alpha value used in blit operations.
1511 ///
1512 /// When this surface is blitted, during the blit operation the source alpha
1513 /// value is modulated by this alpha value according to the following formula:
1514 ///
1515 /// `srcA = srcA * (alpha / 255)`
1516 ///
1517 /// ## Parameters
1518 /// - `surface`: the [`SDL_Surface`] structure to update.
1519 /// - `alpha`: the alpha value multiplied into blit operations.
1520 ///
1521 /// ## Return value
1522 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1523 /// information.
1524 ///
1525 /// ## Thread safety
1526 /// This function can be called on different threads with
1527 /// different surfaces.
1528 ///
1529 /// ## Availability
1530 /// This function is available since SDL 3.2.0.
1531 ///
1532 /// ## See also
1533 /// - [`SDL_GetSurfaceAlphaMod`]
1534 /// - [`SDL_SetSurfaceColorMod`]
1535 pub fn SDL_SetSurfaceAlphaMod(
1536 surface: *mut SDL_Surface,
1537 alpha: Uint8,
1538 ) -> ::core::primitive::bool;
1539}
1540
1541unsafe extern "C" {
1542 /// Get the additional alpha value used in blit operations.
1543 ///
1544 /// ## Parameters
1545 /// - `surface`: the [`SDL_Surface`] structure to query.
1546 /// - `alpha`: a pointer filled in with the current alpha value.
1547 ///
1548 /// ## Return value
1549 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1550 /// information.
1551 ///
1552 /// ## Thread safety
1553 /// It is safe to call this function from any thread.
1554 ///
1555 /// ## Availability
1556 /// This function is available since SDL 3.2.0.
1557 ///
1558 /// ## See also
1559 /// - [`SDL_GetSurfaceColorMod`]
1560 /// - [`SDL_SetSurfaceAlphaMod`]
1561 pub fn SDL_GetSurfaceAlphaMod(
1562 surface: *mut SDL_Surface,
1563 alpha: *mut Uint8,
1564 ) -> ::core::primitive::bool;
1565}
1566
1567unsafe extern "C" {
1568 /// Set the blend mode used for blit operations.
1569 ///
1570 /// To copy a surface to another surface (or texture) without blending with the
1571 /// existing data, the blendmode of the SOURCE surface should be set to
1572 /// [`SDL_BLENDMODE_NONE`].
1573 ///
1574 /// ## Parameters
1575 /// - `surface`: the [`SDL_Surface`] structure to update.
1576 /// - `blendMode`: the [`SDL_BlendMode`] to use for blit blending.
1577 ///
1578 /// ## Return value
1579 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1580 /// information.
1581 ///
1582 /// ## Thread safety
1583 /// This function can be called on different threads with
1584 /// different surfaces.
1585 ///
1586 /// ## Availability
1587 /// This function is available since SDL 3.2.0.
1588 ///
1589 /// ## See also
1590 /// - [`SDL_GetSurfaceBlendMode`]
1591 pub fn SDL_SetSurfaceBlendMode(
1592 surface: *mut SDL_Surface,
1593 blendMode: SDL_BlendMode,
1594 ) -> ::core::primitive::bool;
1595}
1596
1597unsafe extern "C" {
1598 /// Get the blend mode used for blit operations.
1599 ///
1600 /// ## Parameters
1601 /// - `surface`: the [`SDL_Surface`] structure to query.
1602 /// - `blendMode`: a pointer filled in with the current [`SDL_BlendMode`].
1603 ///
1604 /// ## Return value
1605 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1606 /// information.
1607 ///
1608 /// ## Thread safety
1609 /// It is safe to call this function from any thread.
1610 ///
1611 /// ## Availability
1612 /// This function is available since SDL 3.2.0.
1613 ///
1614 /// ## See also
1615 /// - [`SDL_SetSurfaceBlendMode`]
1616 pub fn SDL_GetSurfaceBlendMode(
1617 surface: *mut SDL_Surface,
1618 blendMode: *mut SDL_BlendMode,
1619 ) -> ::core::primitive::bool;
1620}
1621
1622unsafe extern "C" {
1623 /// Set the clipping rectangle for a surface.
1624 ///
1625 /// When `surface` is the destination of a blit, only the area within the clip
1626 /// rectangle is drawn into.
1627 ///
1628 /// Note that blits are automatically clipped to the edges of the source and
1629 /// destination surfaces.
1630 ///
1631 /// ## Parameters
1632 /// - `surface`: the [`SDL_Surface`] structure to be clipped.
1633 /// - `rect`: the [`SDL_Rect`] structure representing the clipping rectangle, or
1634 /// NULL to disable clipping.
1635 ///
1636 /// ## Return value
1637 /// Returns true if the rectangle intersects the surface, otherwise false and
1638 /// blits will be completely clipped.
1639 ///
1640 /// ## Thread safety
1641 /// This function can be called on different threads with
1642 /// different surfaces.
1643 ///
1644 /// ## Availability
1645 /// This function is available since SDL 3.2.0.
1646 ///
1647 /// ## See also
1648 /// - [`SDL_GetSurfaceClipRect`]
1649 pub fn SDL_SetSurfaceClipRect(
1650 surface: *mut SDL_Surface,
1651 rect: *const SDL_Rect,
1652 ) -> ::core::primitive::bool;
1653}
1654
1655unsafe extern "C" {
1656 /// Get the clipping rectangle for a surface.
1657 ///
1658 /// When `surface` is the destination of a blit, only the area within the clip
1659 /// rectangle is drawn into.
1660 ///
1661 /// ## Parameters
1662 /// - `surface`: the [`SDL_Surface`] structure representing the surface to be
1663 /// clipped.
1664 /// - `rect`: an [`SDL_Rect`] structure filled in with the clipping rectangle for
1665 /// the surface.
1666 ///
1667 /// ## Return value
1668 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1669 /// information.
1670 ///
1671 /// ## Thread safety
1672 /// This function can be called on different threads with
1673 /// different surfaces.
1674 ///
1675 /// ## Availability
1676 /// This function is available since SDL 3.2.0.
1677 ///
1678 /// ## See also
1679 /// - [`SDL_SetSurfaceClipRect`]
1680 pub fn SDL_GetSurfaceClipRect(
1681 surface: *mut SDL_Surface,
1682 rect: *mut SDL_Rect,
1683 ) -> ::core::primitive::bool;
1684}
1685
1686unsafe extern "C" {
1687 /// Flip a surface vertically or horizontally.
1688 ///
1689 /// ## Parameters
1690 /// - `surface`: the surface to flip.
1691 /// - `flip`: the direction to flip.
1692 ///
1693 /// ## Return value
1694 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1695 /// information.
1696 ///
1697 /// ## Thread safety
1698 /// This function can be called on different threads with
1699 /// different surfaces.
1700 ///
1701 /// ## Availability
1702 /// This function is available since SDL 3.2.0.
1703 pub fn SDL_FlipSurface(
1704 surface: *mut SDL_Surface,
1705 flip: SDL_FlipMode,
1706 ) -> ::core::primitive::bool;
1707}
1708
1709unsafe extern "C" {
1710 /// Return a copy of a surface rotated clockwise a number of degrees.
1711 ///
1712 /// The angle of rotation can be negative for counter-clockwise rotation.
1713 ///
1714 /// When the rotation isn't a multiple of 90 degrees, the resulting surface is
1715 /// larger than the original, with the background filled in with the colorkey,
1716 /// if available, or RGBA 255/255/255/0 if not.
1717 ///
1718 /// If `surface` has the [`SDL_PROP_SURFACE_ROTATION_FLOAT`] property set on it,
1719 /// the new copy will have the adjusted value set: if the rotation property is
1720 /// 90 and `angle` was 30, the new surface will have a property value of 60
1721 /// (that is: to be upright vs gravity, this surface needs to rotate 60 more
1722 /// degrees). However, note that further rotations on the new surface in this
1723 /// example will produce unexpected results, since the image will have resized
1724 /// and padded to accommodate the not-90 degree angle.
1725 ///
1726 /// ## Parameters
1727 /// - `surface`: the surface to rotate.
1728 /// - `angle`: the rotation angle, in degrees.
1729 ///
1730 /// ## Return value
1731 /// Returns a rotated copy of the surface or NULL on failure; call
1732 /// [`SDL_GetError()`] for more information.
1733 ///
1734 /// ## Thread safety
1735 /// This function can be called on different threads with
1736 /// different surfaces.
1737 ///
1738 /// ## Availability
1739 /// This function is available since SDL 3.4.0.
1740 pub fn SDL_RotateSurface(
1741 surface: *mut SDL_Surface,
1742 angle: ::core::ffi::c_float,
1743 ) -> *mut SDL_Surface;
1744}
1745
1746unsafe extern "C" {
1747 /// Creates a new surface identical to the existing surface.
1748 ///
1749 /// If the original surface has alternate images, the new surface will have a
1750 /// reference to them as well.
1751 ///
1752 /// The returned surface should be freed with [`SDL_DestroySurface()`].
1753 ///
1754 /// ## Parameters
1755 /// - `surface`: the surface to duplicate.
1756 ///
1757 /// ## Return value
1758 /// Returns a copy of the surface or NULL on failure; call [`SDL_GetError()`] for
1759 /// more information.
1760 ///
1761 /// ## Thread safety
1762 /// This function can be called on different threads with
1763 /// different surfaces.
1764 ///
1765 /// ## Availability
1766 /// This function is available since SDL 3.2.0.
1767 ///
1768 /// ## See also
1769 /// - [`SDL_DestroySurface`]
1770 pub fn SDL_DuplicateSurface(surface: *mut SDL_Surface) -> *mut SDL_Surface;
1771}
1772
1773unsafe extern "C" {
1774 /// Creates a new surface identical to the existing surface, scaled to the
1775 /// desired size.
1776 ///
1777 /// The returned surface should be freed with [`SDL_DestroySurface()`].
1778 ///
1779 /// ## Parameters
1780 /// - `surface`: the surface to duplicate and scale.
1781 /// - `width`: the width of the new surface.
1782 /// - `height`: the height of the new surface.
1783 /// - `scaleMode`: the [`SDL_ScaleMode`] to be used.
1784 ///
1785 /// ## Return value
1786 /// Returns a copy of the surface or NULL on failure; call [`SDL_GetError()`] for
1787 /// more information.
1788 ///
1789 /// ## Thread safety
1790 /// This function can be called on different threads with
1791 /// different surfaces.
1792 ///
1793 /// ## Availability
1794 /// This function is available since SDL 3.2.0.
1795 ///
1796 /// ## See also
1797 /// - [`SDL_DestroySurface`]
1798 pub fn SDL_ScaleSurface(
1799 surface: *mut SDL_Surface,
1800 width: ::core::ffi::c_int,
1801 height: ::core::ffi::c_int,
1802 scaleMode: SDL_ScaleMode,
1803 ) -> *mut SDL_Surface;
1804}
1805
1806unsafe extern "C" {
1807 /// Copy an existing surface to a new surface of the specified format.
1808 ///
1809 /// This function is used to optimize images for faster *repeat* blitting. This
1810 /// is accomplished by converting the original and storing the result as a new
1811 /// surface. The new, optimized surface can then be used as the source for
1812 /// future blits, making them faster.
1813 ///
1814 /// If you are converting to an indexed surface and want to map colors to a
1815 /// palette, you can use [`SDL_ConvertSurfaceAndColorspace()`] instead.
1816 ///
1817 /// If the original surface has alternate images, the new surface will have a
1818 /// reference to them as well.
1819 ///
1820 /// ## Parameters
1821 /// - `surface`: the existing [`SDL_Surface`] structure to convert.
1822 /// - `format`: the new pixel format.
1823 ///
1824 /// ## Return value
1825 /// Returns the new [`SDL_Surface`] structure that is created or NULL on failure;
1826 /// call [`SDL_GetError()`] for more information.
1827 ///
1828 /// ## Thread safety
1829 /// This function can be called on different threads with
1830 /// different surfaces.
1831 ///
1832 /// ## Availability
1833 /// This function is available since SDL 3.2.0.
1834 ///
1835 /// ## See also
1836 /// - [`SDL_ConvertSurfaceAndColorspace`]
1837 /// - [`SDL_DestroySurface`]
1838 pub fn SDL_ConvertSurface(
1839 surface: *mut SDL_Surface,
1840 format: SDL_PixelFormat,
1841 ) -> *mut SDL_Surface;
1842}
1843
1844unsafe extern "C" {
1845 /// Copy an existing surface to a new surface of the specified format and
1846 /// colorspace.
1847 ///
1848 /// This function converts an existing surface to a new format and colorspace
1849 /// and returns the new surface. This will perform any pixel format and
1850 /// colorspace conversion needed.
1851 ///
1852 /// If the original surface has alternate images, the new surface will have a
1853 /// reference to them as well.
1854 ///
1855 /// ## Parameters
1856 /// - `surface`: the existing [`SDL_Surface`] structure to convert.
1857 /// - `format`: the new pixel format.
1858 /// - `palette`: an optional palette to use for indexed formats, may be NULL.
1859 /// - `colorspace`: the new colorspace.
1860 /// - `props`: an [`SDL_PropertiesID`] with additional color properties, or 0.
1861 ///
1862 /// ## Return value
1863 /// Returns the new [`SDL_Surface`] structure that is created or NULL on failure;
1864 /// call [`SDL_GetError()`] for more information.
1865 ///
1866 /// ## Thread safety
1867 /// This function can be called on different threads with
1868 /// different surfaces.
1869 ///
1870 /// ## Availability
1871 /// This function is available since SDL 3.2.0.
1872 ///
1873 /// ## See also
1874 /// - [`SDL_ConvertSurface`]
1875 /// - [`SDL_DestroySurface`]
1876 pub fn SDL_ConvertSurfaceAndColorspace(
1877 surface: *mut SDL_Surface,
1878 format: SDL_PixelFormat,
1879 palette: *mut SDL_Palette,
1880 colorspace: SDL_Colorspace,
1881 props: SDL_PropertiesID,
1882 ) -> *mut SDL_Surface;
1883}
1884
1885unsafe extern "C" {
1886 /// Copy a block of pixels of one format to another format.
1887 ///
1888 /// ## Parameters
1889 /// - `width`: the width of the block to copy, in pixels.
1890 /// - `height`: the height of the block to copy, in pixels.
1891 /// - `src_format`: an [`SDL_PixelFormat`] value of the `src` pixels format.
1892 /// - `src`: a pointer to the source pixels.
1893 /// - `src_pitch`: the pitch of the source pixels, in bytes.
1894 /// - `dst_format`: an [`SDL_PixelFormat`] value of the `dst` pixels format.
1895 /// - `dst`: a pointer to be filled in with new pixel data.
1896 /// - `dst_pitch`: the pitch of the destination pixels, in bytes.
1897 ///
1898 /// ## Return value
1899 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1900 /// information.
1901 ///
1902 /// ## Thread safety
1903 /// The same destination pixels should not be used from two
1904 /// threads at once. It is safe to use the same source pixels
1905 /// from multiple threads.
1906 ///
1907 /// ## Availability
1908 /// This function is available since SDL 3.2.0.
1909 ///
1910 /// ## See also
1911 /// - [`SDL_ConvertPixelsAndColorspace`]
1912 pub fn SDL_ConvertPixels(
1913 width: ::core::ffi::c_int,
1914 height: ::core::ffi::c_int,
1915 src_format: SDL_PixelFormat,
1916 src: *const ::core::ffi::c_void,
1917 src_pitch: ::core::ffi::c_int,
1918 dst_format: SDL_PixelFormat,
1919 dst: *mut ::core::ffi::c_void,
1920 dst_pitch: ::core::ffi::c_int,
1921 ) -> ::core::primitive::bool;
1922}
1923
1924unsafe extern "C" {
1925 /// Copy a block of pixels of one format and colorspace to another format and
1926 /// colorspace.
1927 ///
1928 /// ## Parameters
1929 /// - `width`: the width of the block to copy, in pixels.
1930 /// - `height`: the height of the block to copy, in pixels.
1931 /// - `src_format`: an [`SDL_PixelFormat`] value of the `src` pixels format.
1932 /// - `src_colorspace`: an [`SDL_Colorspace`] value describing the colorspace of
1933 /// the `src` pixels.
1934 /// - `src_properties`: an [`SDL_PropertiesID`] with additional source color
1935 /// properties, or 0.
1936 /// - `src`: a pointer to the source pixels.
1937 /// - `src_pitch`: the pitch of the source pixels, in bytes.
1938 /// - `dst_format`: an [`SDL_PixelFormat`] value of the `dst` pixels format.
1939 /// - `dst_colorspace`: an [`SDL_Colorspace`] value describing the colorspace of
1940 /// the `dst` pixels.
1941 /// - `dst_properties`: an [`SDL_PropertiesID`] with additional destination color
1942 /// properties, or 0.
1943 /// - `dst`: a pointer to be filled in with new pixel data.
1944 /// - `dst_pitch`: the pitch of the destination pixels, in bytes.
1945 ///
1946 /// ## Return value
1947 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1948 /// information.
1949 ///
1950 /// ## Thread safety
1951 /// The same destination pixels should not be used from two
1952 /// threads at once. It is safe to use the same source pixels
1953 /// from multiple threads.
1954 ///
1955 /// ## Availability
1956 /// This function is available since SDL 3.2.0.
1957 ///
1958 /// ## See also
1959 /// - [`SDL_ConvertPixels`]
1960 pub fn SDL_ConvertPixelsAndColorspace(
1961 width: ::core::ffi::c_int,
1962 height: ::core::ffi::c_int,
1963 src_format: SDL_PixelFormat,
1964 src_colorspace: SDL_Colorspace,
1965 src_properties: SDL_PropertiesID,
1966 src: *const ::core::ffi::c_void,
1967 src_pitch: ::core::ffi::c_int,
1968 dst_format: SDL_PixelFormat,
1969 dst_colorspace: SDL_Colorspace,
1970 dst_properties: SDL_PropertiesID,
1971 dst: *mut ::core::ffi::c_void,
1972 dst_pitch: ::core::ffi::c_int,
1973 ) -> ::core::primitive::bool;
1974}
1975
1976unsafe extern "C" {
1977 /// Premultiply the alpha on a block of pixels.
1978 ///
1979 /// This is safe to use with src == dst, but not for other overlapping areas.
1980 ///
1981 /// ## Parameters
1982 /// - `width`: the width of the block to convert, in pixels.
1983 /// - `height`: the height of the block to convert, in pixels.
1984 /// - `src_format`: an [`SDL_PixelFormat`] value of the `src` pixels format.
1985 /// - `src`: a pointer to the source pixels.
1986 /// - `src_pitch`: the pitch of the source pixels, in bytes.
1987 /// - `dst_format`: an [`SDL_PixelFormat`] value of the `dst` pixels format.
1988 /// - `dst`: a pointer to be filled in with premultiplied pixel data.
1989 /// - `dst_pitch`: the pitch of the destination pixels, in bytes.
1990 /// - `linear`: true to convert from sRGB to linear space for the alpha
1991 /// multiplication, false to do multiplication in sRGB space.
1992 ///
1993 /// ## Return value
1994 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
1995 /// information.
1996 ///
1997 /// ## Thread safety
1998 /// The same destination pixels should not be used from two
1999 /// threads at once. It is safe to use the same source pixels
2000 /// from multiple threads.
2001 ///
2002 /// ## Availability
2003 /// This function is available since SDL 3.2.0.
2004 pub fn SDL_PremultiplyAlpha(
2005 width: ::core::ffi::c_int,
2006 height: ::core::ffi::c_int,
2007 src_format: SDL_PixelFormat,
2008 src: *const ::core::ffi::c_void,
2009 src_pitch: ::core::ffi::c_int,
2010 dst_format: SDL_PixelFormat,
2011 dst: *mut ::core::ffi::c_void,
2012 dst_pitch: ::core::ffi::c_int,
2013 linear: ::core::primitive::bool,
2014 ) -> ::core::primitive::bool;
2015}
2016
2017unsafe extern "C" {
2018 /// Premultiply the alpha in a surface.
2019 ///
2020 /// This is safe to use with src == dst, but not for other overlapping areas.
2021 ///
2022 /// ## Parameters
2023 /// - `surface`: the surface to modify.
2024 /// - `linear`: true to convert from sRGB to linear space for the alpha
2025 /// multiplication, false to do multiplication in sRGB space.
2026 ///
2027 /// ## Return value
2028 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2029 /// information.
2030 ///
2031 /// ## Thread safety
2032 /// This function can be called on different threads with
2033 /// different surfaces.
2034 ///
2035 /// ## Availability
2036 /// This function is available since SDL 3.2.0.
2037 pub fn SDL_PremultiplySurfaceAlpha(
2038 surface: *mut SDL_Surface,
2039 linear: ::core::primitive::bool,
2040 ) -> ::core::primitive::bool;
2041}
2042
2043unsafe extern "C" {
2044 /// Clear a surface with a specific color, with floating point precision.
2045 ///
2046 /// This function handles all surface formats, and ignores any clip rectangle.
2047 ///
2048 /// If the surface is YUV, the color is assumed to be in the sRGB colorspace,
2049 /// otherwise the color is assumed to be in the colorspace of the surface.
2050 ///
2051 /// ## Parameters
2052 /// - `surface`: the [`SDL_Surface`] to clear.
2053 /// - `r`: the red component of the pixel, normally in the range 0-1.
2054 /// - `g`: the green component of the pixel, normally in the range 0-1.
2055 /// - `b`: the blue component of the pixel, normally in the range 0-1.
2056 /// - `a`: the alpha component of the pixel, normally in the range 0-1.
2057 ///
2058 /// ## Return value
2059 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2060 /// information.
2061 ///
2062 /// ## Thread safety
2063 /// This function can be called on different threads with
2064 /// different surfaces.
2065 ///
2066 /// ## Availability
2067 /// This function is available since SDL 3.2.0.
2068 pub fn SDL_ClearSurface(
2069 surface: *mut SDL_Surface,
2070 r: ::core::ffi::c_float,
2071 g: ::core::ffi::c_float,
2072 b: ::core::ffi::c_float,
2073 a: ::core::ffi::c_float,
2074 ) -> ::core::primitive::bool;
2075}
2076
2077unsafe extern "C" {
2078 /// Perform a fast fill of a rectangle with a specific color.
2079 ///
2080 /// `color` should be a pixel of the format used by the surface, and can be
2081 /// generated by [`SDL_MapRGB()`] or [`SDL_MapRGBA()`]. If the color value contains an
2082 /// alpha component then the destination is simply filled with that alpha
2083 /// information, no blending takes place.
2084 ///
2085 /// If there is a clip rectangle set on the destination (set via
2086 /// [`SDL_SetSurfaceClipRect()`]), then this function will fill based on the
2087 /// intersection of the clip rectangle and `rect`.
2088 ///
2089 /// ## Parameters
2090 /// - `dst`: the [`SDL_Surface`] structure that is the drawing target.
2091 /// - `rect`: the [`SDL_Rect`] structure representing the rectangle to fill, or
2092 /// NULL to fill the entire surface.
2093 /// - `color`: the color to fill with.
2094 ///
2095 /// ## Return value
2096 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2097 /// information.
2098 ///
2099 /// ## Thread safety
2100 /// This function can be called on different threads with
2101 /// different surfaces.
2102 ///
2103 /// ## Availability
2104 /// This function is available since SDL 3.2.0.
2105 ///
2106 /// ## See also
2107 /// - [`SDL_FillSurfaceRects`]
2108 pub fn SDL_FillSurfaceRect(
2109 dst: *mut SDL_Surface,
2110 rect: *const SDL_Rect,
2111 color: Uint32,
2112 ) -> ::core::primitive::bool;
2113}
2114
2115unsafe extern "C" {
2116 /// Perform a fast fill of a set of rectangles with a specific color.
2117 ///
2118 /// `color` should be a pixel of the format used by the surface, and can be
2119 /// generated by [`SDL_MapRGB()`] or [`SDL_MapRGBA()`]. If the color value contains an
2120 /// alpha component then the destination is simply filled with that alpha
2121 /// information, no blending takes place.
2122 ///
2123 /// If there is a clip rectangle set on the destination (set via
2124 /// [`SDL_SetSurfaceClipRect()`]), then this function will fill based on the
2125 /// intersection of the clip rectangle and `rect`.
2126 ///
2127 /// ## Parameters
2128 /// - `dst`: the [`SDL_Surface`] structure that is the drawing target.
2129 /// - `rects`: an array of [`SDL_Rect`]s representing the rectangles to fill.
2130 /// - `count`: the number of rectangles in the array.
2131 /// - `color`: the color to fill with.
2132 ///
2133 /// ## Return value
2134 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2135 /// information.
2136 ///
2137 /// ## Thread safety
2138 /// This function can be called on different threads with
2139 /// different surfaces.
2140 ///
2141 /// ## Availability
2142 /// This function is available since SDL 3.2.0.
2143 ///
2144 /// ## See also
2145 /// - [`SDL_FillSurfaceRect`]
2146 pub fn SDL_FillSurfaceRects(
2147 dst: *mut SDL_Surface,
2148 rects: *const SDL_Rect,
2149 count: ::core::ffi::c_int,
2150 color: Uint32,
2151 ) -> ::core::primitive::bool;
2152}
2153
2154unsafe extern "C" {
2155 /// Performs a fast blit from the source surface to the destination surface
2156 /// with clipping.
2157 ///
2158 /// If either `srcrect` or `dstrect` are NULL, the entire surface (`src` or
2159 /// `dst`) is copied while ensuring clipping to `dst->clip_rect`.
2160 ///
2161 /// The blit function should not be called on a locked surface.
2162 ///
2163 /// The blit semantics for surfaces with and without blending and colorkey are
2164 /// defined as follows:
2165 ///
2166 /// ```text
2167 /// RGBA->RGB:
2168 /// Source surface blend mode set to SDL_BLENDMODE_BLEND:
2169 /// alpha-blend (using the source alpha-channel and per-surface alpha)
2170 /// SDL_SRCCOLORKEY ignored.
2171 /// Source surface blend mode set to SDL_BLENDMODE_NONE:
2172 /// copy RGB.
2173 /// if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
2174 /// RGB values of the source color key, ignoring alpha in the
2175 /// comparison.
2176 ///
2177 /// RGB->RGBA:
2178 /// Source surface blend mode set to SDL_BLENDMODE_BLEND:
2179 /// alpha-blend (using the source per-surface alpha)
2180 /// Source surface blend mode set to SDL_BLENDMODE_NONE:
2181 /// copy RGB, set destination alpha to source per-surface alpha value.
2182 /// both:
2183 /// if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
2184 /// source color key.
2185 ///
2186 /// RGBA->RGBA:
2187 /// Source surface blend mode set to SDL_BLENDMODE_BLEND:
2188 /// alpha-blend (using the source alpha-channel and per-surface alpha)
2189 /// SDL_SRCCOLORKEY ignored.
2190 /// Source surface blend mode set to SDL_BLENDMODE_NONE:
2191 /// copy all of RGBA to the destination.
2192 /// if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
2193 /// RGB values of the source color key, ignoring alpha in the
2194 /// comparison.
2195 ///
2196 /// RGB->RGB:
2197 /// Source surface blend mode set to SDL_BLENDMODE_BLEND:
2198 /// alpha-blend (using the source per-surface alpha)
2199 /// Source surface blend mode set to SDL_BLENDMODE_NONE:
2200 /// copy RGB.
2201 /// both:
2202 /// if SDL_SRCCOLORKEY set, only copy the pixels that do not match the
2203 /// source color key.
2204 /// ```
2205 ///
2206 /// ## Parameters
2207 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2208 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2209 /// copied, or NULL to copy the entire surface.
2210 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2211 /// - `dstrect`: the [`SDL_Rect`] structure representing the x and y position in
2212 /// the destination surface, or NULL for (0,0). The width and
2213 /// height are ignored, and are copied from `srcrect`. If you
2214 /// want a specific width and height, you should use
2215 /// [`SDL_BlitSurfaceScaled()`].
2216 ///
2217 /// ## Return value
2218 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2219 /// information.
2220 ///
2221 /// ## Thread safety
2222 /// Only one thread should be using the `src` and `dst` surfaces
2223 /// at any given time.
2224 ///
2225 /// ## Availability
2226 /// This function is available since SDL 3.2.0.
2227 ///
2228 /// ## See also
2229 /// - [`SDL_BlitSurfaceScaled`]
2230 pub fn SDL_BlitSurface(
2231 src: *mut SDL_Surface,
2232 srcrect: *const SDL_Rect,
2233 dst: *mut SDL_Surface,
2234 dstrect: *const SDL_Rect,
2235 ) -> ::core::primitive::bool;
2236}
2237
2238unsafe extern "C" {
2239 /// Perform low-level surface blitting only.
2240 ///
2241 /// This is a semi-private blit function and it performs low-level surface
2242 /// blitting, assuming the input rectangles have already been clipped.
2243 ///
2244 /// ## Parameters
2245 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2246 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2247 /// copied, may not be NULL.
2248 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2249 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2250 /// the destination surface, may not be NULL.
2251 ///
2252 /// ## Return value
2253 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2254 /// information.
2255 ///
2256 /// ## Thread safety
2257 /// Only one thread should be using the `src` and `dst` surfaces
2258 /// at any given time.
2259 ///
2260 /// ## Availability
2261 /// This function is available since SDL 3.2.0.
2262 ///
2263 /// ## See also
2264 /// - [`SDL_BlitSurface`]
2265 pub fn SDL_BlitSurfaceUnchecked(
2266 src: *mut SDL_Surface,
2267 srcrect: *const SDL_Rect,
2268 dst: *mut SDL_Surface,
2269 dstrect: *const SDL_Rect,
2270 ) -> ::core::primitive::bool;
2271}
2272
2273unsafe extern "C" {
2274 /// Perform a scaled blit to a destination surface, which may be of a different
2275 /// format.
2276 ///
2277 /// ## Parameters
2278 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2279 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2280 /// copied, or NULL to copy the entire surface.
2281 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2282 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2283 /// the destination surface, or NULL to fill the entire
2284 /// destination surface.
2285 /// - `scaleMode`: the [`SDL_ScaleMode`] to be used.
2286 ///
2287 /// ## Return value
2288 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2289 /// information.
2290 ///
2291 /// ## Thread safety
2292 /// Only one thread should be using the `src` and `dst` surfaces
2293 /// at any given time.
2294 ///
2295 /// ## Availability
2296 /// This function is available since SDL 3.2.0.
2297 ///
2298 /// ## See also
2299 /// - [`SDL_BlitSurface`]
2300 pub fn SDL_BlitSurfaceScaled(
2301 src: *mut SDL_Surface,
2302 srcrect: *const SDL_Rect,
2303 dst: *mut SDL_Surface,
2304 dstrect: *const SDL_Rect,
2305 scaleMode: SDL_ScaleMode,
2306 ) -> ::core::primitive::bool;
2307}
2308
2309unsafe extern "C" {
2310 /// Perform low-level surface scaled blitting only.
2311 ///
2312 /// This is a semi-private function and it performs low-level surface blitting,
2313 /// assuming the input rectangles have already been clipped.
2314 ///
2315 /// ## Parameters
2316 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2317 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2318 /// copied, may not be NULL.
2319 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2320 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2321 /// the destination surface, may not be NULL.
2322 /// - `scaleMode`: the [`SDL_ScaleMode`] to be used.
2323 ///
2324 /// ## Return value
2325 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2326 /// information.
2327 ///
2328 /// ## Thread safety
2329 /// Only one thread should be using the `src` and `dst` surfaces
2330 /// at any given time.
2331 ///
2332 /// ## Availability
2333 /// This function is available since SDL 3.2.0.
2334 ///
2335 /// ## See also
2336 /// - [`SDL_BlitSurfaceScaled`]
2337 pub fn SDL_BlitSurfaceUncheckedScaled(
2338 src: *mut SDL_Surface,
2339 srcrect: *const SDL_Rect,
2340 dst: *mut SDL_Surface,
2341 dstrect: *const SDL_Rect,
2342 scaleMode: SDL_ScaleMode,
2343 ) -> ::core::primitive::bool;
2344}
2345
2346unsafe extern "C" {
2347 /// Perform a stretched pixel copy from one surface to another.
2348 ///
2349 /// ## Parameters
2350 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2351 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2352 /// copied, or NULL to copy the entire surface.
2353 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2354 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2355 /// the destination surface, or NULL to fill the entire
2356 /// destination surface.
2357 /// - `scaleMode`: the [`SDL_ScaleMode`] to be used.
2358 ///
2359 /// ## Return value
2360 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2361 /// information.
2362 ///
2363 /// ## Thread safety
2364 /// Only one thread should be using the `src` and `dst` surfaces
2365 /// at any given time.
2366 ///
2367 /// ## Availability
2368 /// This function is available since SDL 3.4.0.
2369 ///
2370 /// ## See also
2371 /// - [`SDL_BlitSurfaceScaled`]
2372 pub fn SDL_StretchSurface(
2373 src: *mut SDL_Surface,
2374 srcrect: *const SDL_Rect,
2375 dst: *mut SDL_Surface,
2376 dstrect: *const SDL_Rect,
2377 scaleMode: SDL_ScaleMode,
2378 ) -> ::core::primitive::bool;
2379}
2380
2381unsafe extern "C" {
2382 /// Perform a tiled blit to a destination surface, which may be of a different
2383 /// format.
2384 ///
2385 /// The pixels in `srcrect` will be repeated as many times as needed to
2386 /// completely fill `dstrect`.
2387 ///
2388 /// ## Parameters
2389 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2390 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2391 /// copied, or NULL to copy the entire surface.
2392 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2393 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2394 /// the destination surface, or NULL to fill the entire surface.
2395 ///
2396 /// ## Return value
2397 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2398 /// information.
2399 ///
2400 /// ## Thread safety
2401 /// Only one thread should be using the `src` and `dst` surfaces
2402 /// at any given time.
2403 ///
2404 /// ## Availability
2405 /// This function is available since SDL 3.2.0.
2406 ///
2407 /// ## See also
2408 /// - [`SDL_BlitSurface`]
2409 pub fn SDL_BlitSurfaceTiled(
2410 src: *mut SDL_Surface,
2411 srcrect: *const SDL_Rect,
2412 dst: *mut SDL_Surface,
2413 dstrect: *const SDL_Rect,
2414 ) -> ::core::primitive::bool;
2415}
2416
2417unsafe extern "C" {
2418 /// Perform a scaled and tiled blit to a destination surface, which may be of a
2419 /// different format.
2420 ///
2421 /// The pixels in `srcrect` will be scaled and repeated as many times as needed
2422 /// to completely fill `dstrect`.
2423 ///
2424 /// ## Parameters
2425 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2426 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be
2427 /// copied, or NULL to copy the entire surface.
2428 /// - `scale`: the scale used to transform srcrect into the destination
2429 /// rectangle, e.g. a 32x32 texture with a scale of 2 would fill
2430 /// 64x64 tiles.
2431 /// - `scaleMode`: scale algorithm to be used.
2432 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2433 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2434 /// the destination surface, or NULL to fill the entire surface.
2435 ///
2436 /// ## Return value
2437 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2438 /// information.
2439 ///
2440 /// ## Thread safety
2441 /// Only one thread should be using the `src` and `dst` surfaces
2442 /// at any given time.
2443 ///
2444 /// ## Availability
2445 /// This function is available since SDL 3.2.0.
2446 ///
2447 /// ## See also
2448 /// - [`SDL_BlitSurface`]
2449 pub fn SDL_BlitSurfaceTiledWithScale(
2450 src: *mut SDL_Surface,
2451 srcrect: *const SDL_Rect,
2452 scale: ::core::ffi::c_float,
2453 scaleMode: SDL_ScaleMode,
2454 dst: *mut SDL_Surface,
2455 dstrect: *const SDL_Rect,
2456 ) -> ::core::primitive::bool;
2457}
2458
2459unsafe extern "C" {
2460 /// Perform a scaled blit using the 9-grid algorithm to a destination surface,
2461 /// which may be of a different format.
2462 ///
2463 /// The pixels in the source surface are split into a 3x3 grid, using the
2464 /// different corner sizes for each corner, and the sides and center making up
2465 /// the remaining pixels. The corners are then scaled using `scale` and fit
2466 /// into the corners of the destination rectangle. The sides and center are
2467 /// then stretched into place to cover the remaining destination rectangle.
2468 ///
2469 /// ## Parameters
2470 /// - `src`: the [`SDL_Surface`] structure to be copied from.
2471 /// - `srcrect`: the [`SDL_Rect`] structure representing the rectangle to be used
2472 /// for the 9-grid, or NULL to use the entire surface.
2473 /// - `left_width`: the width, in pixels, of the left corners in `srcrect`.
2474 /// - `right_width`: the width, in pixels, of the right corners in `srcrect`.
2475 /// - `top_height`: the height, in pixels, of the top corners in `srcrect`.
2476 /// - `bottom_height`: the height, in pixels, of the bottom corners in
2477 /// `srcrect`.
2478 /// - `scale`: the scale used to transform the corner of `srcrect` into the
2479 /// corner of `dstrect`, or 0.0f for an unscaled blit.
2480 /// - `scaleMode`: scale algorithm to be used.
2481 /// - `dst`: the [`SDL_Surface`] structure that is the blit target.
2482 /// - `dstrect`: the [`SDL_Rect`] structure representing the target rectangle in
2483 /// the destination surface, or NULL to fill the entire surface.
2484 ///
2485 /// ## Return value
2486 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2487 /// information.
2488 ///
2489 /// ## Thread safety
2490 /// Only one thread should be using the `src` and `dst` surfaces
2491 /// at any given time.
2492 ///
2493 /// ## Availability
2494 /// This function is available since SDL 3.2.0.
2495 ///
2496 /// ## See also
2497 /// - [`SDL_BlitSurface`]
2498 pub fn SDL_BlitSurface9Grid(
2499 src: *mut SDL_Surface,
2500 srcrect: *const SDL_Rect,
2501 left_width: ::core::ffi::c_int,
2502 right_width: ::core::ffi::c_int,
2503 top_height: ::core::ffi::c_int,
2504 bottom_height: ::core::ffi::c_int,
2505 scale: ::core::ffi::c_float,
2506 scaleMode: SDL_ScaleMode,
2507 dst: *mut SDL_Surface,
2508 dstrect: *const SDL_Rect,
2509 ) -> ::core::primitive::bool;
2510}
2511
2512unsafe extern "C" {
2513 /// Map an RGB triple to an opaque pixel value for a surface.
2514 ///
2515 /// This function maps the RGB color value to the specified pixel format and
2516 /// returns the pixel value best approximating the given RGB color value for
2517 /// the given pixel format.
2518 ///
2519 /// If the surface has a palette, the index of the closest matching color in
2520 /// the palette will be returned.
2521 ///
2522 /// If the surface pixel format has an alpha component it will be returned as
2523 /// all 1 bits (fully opaque).
2524 ///
2525 /// If the pixel format bpp (color depth) is less than 32-bpp then the unused
2526 /// upper bits of the return value can safely be ignored (e.g., with a 16-bpp
2527 /// format the return value can be assigned to a Uint16, and similarly a Uint8
2528 /// for an 8-bpp format).
2529 ///
2530 /// ## Parameters
2531 /// - `surface`: the surface to use for the pixel format and palette.
2532 /// - `r`: the red component of the pixel in the range 0-255.
2533 /// - `g`: the green component of the pixel in the range 0-255.
2534 /// - `b`: the blue component of the pixel in the range 0-255.
2535 ///
2536 /// ## Return value
2537 /// Returns a pixel value.
2538 ///
2539 /// ## Thread safety
2540 /// This function can be called on different threads with
2541 /// different surfaces.
2542 ///
2543 /// ## Availability
2544 /// This function is available since SDL 3.2.0.
2545 ///
2546 /// ## See also
2547 /// - [`SDL_MapSurfaceRGBA`]
2548 pub fn SDL_MapSurfaceRGB(surface: *mut SDL_Surface, r: Uint8, g: Uint8, b: Uint8) -> Uint32;
2549}
2550
2551unsafe extern "C" {
2552 /// Map an RGBA quadruple to a pixel value for a surface.
2553 ///
2554 /// This function maps the RGBA color value to the specified pixel format and
2555 /// returns the pixel value best approximating the given RGBA color value for
2556 /// the given pixel format.
2557 ///
2558 /// If the surface pixel format has no alpha component the alpha value will be
2559 /// ignored (as it will be in formats with a palette).
2560 ///
2561 /// If the surface has a palette, the index of the closest matching color in
2562 /// the palette will be returned.
2563 ///
2564 /// If the pixel format bpp (color depth) is less than 32-bpp then the unused
2565 /// upper bits of the return value can safely be ignored (e.g., with a 16-bpp
2566 /// format the return value can be assigned to a Uint16, and similarly a Uint8
2567 /// for an 8-bpp format).
2568 ///
2569 /// ## Parameters
2570 /// - `surface`: the surface to use for the pixel format and palette.
2571 /// - `r`: the red component of the pixel in the range 0-255.
2572 /// - `g`: the green component of the pixel in the range 0-255.
2573 /// - `b`: the blue component of the pixel in the range 0-255.
2574 /// - `a`: the alpha component of the pixel in the range 0-255.
2575 ///
2576 /// ## Return value
2577 /// Returns a pixel value.
2578 ///
2579 /// ## Thread safety
2580 /// This function can be called on different threads with
2581 /// different surfaces.
2582 ///
2583 /// ## Availability
2584 /// This function is available since SDL 3.2.0.
2585 ///
2586 /// ## See also
2587 /// - [`SDL_MapSurfaceRGB`]
2588 pub fn SDL_MapSurfaceRGBA(
2589 surface: *mut SDL_Surface,
2590 r: Uint8,
2591 g: Uint8,
2592 b: Uint8,
2593 a: Uint8,
2594 ) -> Uint32;
2595}
2596
2597unsafe extern "C" {
2598 /// Retrieves a single pixel from a surface.
2599 ///
2600 /// This function prioritizes correctness over speed: it is suitable for unit
2601 /// tests, but is not intended for use in a game engine.
2602 ///
2603 /// Like [`SDL_GetRGBA`], this uses the entire 0..255 range when converting color
2604 /// components from pixel formats with less than 8 bits per RGB component.
2605 ///
2606 /// ## Parameters
2607 /// - `surface`: the surface to read.
2608 /// - `x`: the horizontal coordinate, 0 <= x < width.
2609 /// - `y`: the vertical coordinate, 0 <= y < height.
2610 /// - `r`: a pointer filled in with the red channel, 0-255, or NULL to ignore
2611 /// this channel.
2612 /// - `g`: a pointer filled in with the green channel, 0-255, or NULL to
2613 /// ignore this channel.
2614 /// - `b`: a pointer filled in with the blue channel, 0-255, or NULL to
2615 /// ignore this channel.
2616 /// - `a`: a pointer filled in with the alpha channel, 0-255, or NULL to
2617 /// ignore this channel.
2618 ///
2619 /// ## Return value
2620 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2621 /// information.
2622 ///
2623 /// ## Thread safety
2624 /// This function can be called on different threads with
2625 /// different surfaces.
2626 ///
2627 /// ## Availability
2628 /// This function is available since SDL 3.2.0.
2629 pub fn SDL_ReadSurfacePixel(
2630 surface: *mut SDL_Surface,
2631 x: ::core::ffi::c_int,
2632 y: ::core::ffi::c_int,
2633 r: *mut Uint8,
2634 g: *mut Uint8,
2635 b: *mut Uint8,
2636 a: *mut Uint8,
2637 ) -> ::core::primitive::bool;
2638}
2639
2640unsafe extern "C" {
2641 /// Retrieves a single pixel from a surface.
2642 ///
2643 /// This function prioritizes correctness over speed: it is suitable for unit
2644 /// tests, but is not intended for use in a game engine.
2645 ///
2646 /// ## Parameters
2647 /// - `surface`: the surface to read.
2648 /// - `x`: the horizontal coordinate, 0 <= x < width.
2649 /// - `y`: the vertical coordinate, 0 <= y < height.
2650 /// - `r`: a pointer filled in with the red channel, normally in the range
2651 /// 0-1, or NULL to ignore this channel.
2652 /// - `g`: a pointer filled in with the green channel, normally in the range
2653 /// 0-1, or NULL to ignore this channel.
2654 /// - `b`: a pointer filled in with the blue channel, normally in the range
2655 /// 0-1, or NULL to ignore this channel.
2656 /// - `a`: a pointer filled in with the alpha channel, normally in the range
2657 /// 0-1, or NULL to ignore this channel.
2658 ///
2659 /// ## Return value
2660 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2661 /// information.
2662 ///
2663 /// ## Thread safety
2664 /// This function can be called on different threads with
2665 /// different surfaces.
2666 ///
2667 /// ## Availability
2668 /// This function is available since SDL 3.2.0.
2669 pub fn SDL_ReadSurfacePixelFloat(
2670 surface: *mut SDL_Surface,
2671 x: ::core::ffi::c_int,
2672 y: ::core::ffi::c_int,
2673 r: *mut ::core::ffi::c_float,
2674 g: *mut ::core::ffi::c_float,
2675 b: *mut ::core::ffi::c_float,
2676 a: *mut ::core::ffi::c_float,
2677 ) -> ::core::primitive::bool;
2678}
2679
2680unsafe extern "C" {
2681 /// Writes a single pixel to a surface.
2682 ///
2683 /// This function prioritizes correctness over speed: it is suitable for unit
2684 /// tests, but is not intended for use in a game engine.
2685 ///
2686 /// Like [`SDL_MapRGBA`], this uses the entire 0..255 range when converting color
2687 /// components from pixel formats with less than 8 bits per RGB component.
2688 ///
2689 /// ## Parameters
2690 /// - `surface`: the surface to write.
2691 /// - `x`: the horizontal coordinate, 0 <= x < width.
2692 /// - `y`: the vertical coordinate, 0 <= y < height.
2693 /// - `r`: the red channel value, 0-255.
2694 /// - `g`: the green channel value, 0-255.
2695 /// - `b`: the blue channel value, 0-255.
2696 /// - `a`: the alpha channel value, 0-255.
2697 ///
2698 /// ## Return value
2699 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2700 /// information.
2701 ///
2702 /// ## Thread safety
2703 /// This function can be called on different threads with
2704 /// different surfaces.
2705 ///
2706 /// ## Availability
2707 /// This function is available since SDL 3.2.0.
2708 pub fn SDL_WriteSurfacePixel(
2709 surface: *mut SDL_Surface,
2710 x: ::core::ffi::c_int,
2711 y: ::core::ffi::c_int,
2712 r: Uint8,
2713 g: Uint8,
2714 b: Uint8,
2715 a: Uint8,
2716 ) -> ::core::primitive::bool;
2717}
2718
2719unsafe extern "C" {
2720 /// Writes a single pixel to a surface.
2721 ///
2722 /// This function prioritizes correctness over speed: it is suitable for unit
2723 /// tests, but is not intended for use in a game engine.
2724 ///
2725 /// ## Parameters
2726 /// - `surface`: the surface to write.
2727 /// - `x`: the horizontal coordinate, 0 <= x < width.
2728 /// - `y`: the vertical coordinate, 0 <= y < height.
2729 /// - `r`: the red channel value, normally in the range 0-1.
2730 /// - `g`: the green channel value, normally in the range 0-1.
2731 /// - `b`: the blue channel value, normally in the range 0-1.
2732 /// - `a`: the alpha channel value, normally in the range 0-1.
2733 ///
2734 /// ## Return value
2735 /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
2736 /// information.
2737 ///
2738 /// ## Thread safety
2739 /// This function can be called on different threads with
2740 /// different surfaces.
2741 ///
2742 /// ## Availability
2743 /// This function is available since SDL 3.2.0.
2744 pub fn SDL_WriteSurfacePixelFloat(
2745 surface: *mut SDL_Surface,
2746 x: ::core::ffi::c_int,
2747 y: ::core::ffi::c_int,
2748 r: ::core::ffi::c_float,
2749 g: ::core::ffi::c_float,
2750 b: ::core::ffi::c_float,
2751 a: ::core::ffi::c_float,
2752 ) -> ::core::primitive::bool;
2753}
2754
2755#[cfg(doc)]
2756use crate::everything::*;