| 1 | package SDL2::surface 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | use FFI::C::ArrayDef; | ||
| 5 | # | ||
| 6 | use SDL2::stdinc; | ||
| 7 | use SDL2::pixels; | ||
| 8 | use SDL2::rect; | ||
| 9 | use SDL2::blendmode; | ||
| 10 | use SDL2::rwops; | ||
| 11 | # | ||
| 12 | package SDL2::Surface { | ||
| 13 | use SDL2::Utils; | ||
| 14 | our $TYPE = has | ||
| 15 | flags => 'uint32', | ||
| 16 | format => 'opaque', # SDL_PixelFormat* | ||
| 17 | w => 'int', | ||
| 18 | h => 'int', | ||
| 19 | pitch => 'int', | ||
| 20 | pixels => 'opaque', # void* | ||
| 21 | userdata => 'opaque', # void* | ||
| 22 | locked => 'int', | ||
| 23 | lock_data => 'opaque', # void* | ||
| 24 | clip_rect => 'SDL_Rect', | ||
| 25 | map => 'opaque', # SDL_BlitMap* | ||
| 26 | refcount => 'int'; | ||
| 27 | }; | ||
| 28 | # | ||
| 29 | enum SDL_YUV_CONVERSION_MODE => [ | ||
| 30 | qw[SDL_YUV_CONVERSION_JPEG | ||
| 31 | SDL_YUV_CONVERSION_BT601 | ||
| 32 | SDL_YUV_CONVERSION_BT709 | ||
| 33 | SDL_YUV_CONVERSION_AUTOMATIC] | ||
| 34 | ]; | ||
| 35 | attach surface => { | ||
| 36 | SDL_CreateRGBSurface => [ | ||
| 37 | [ 'uint32', 'int', 'int', 'int', 'uint32', 'uint32', 'uint32', 'uint32' ], | ||
| 38 | 'SDL_Surface' | ||
| 39 | ], | ||
| 40 | SDL_CreateRGBSurfaceWithFormat => | ||
| 41 | [ [ 'uint32', 'int', 'int', 'int', 'uint32' ], 'SDL_Surface' ], | ||
| 42 | SDL_CreateRGBSurfaceFrom => [ # FIX: uint16 might be large enough for raw data | ||
| 43 | [ 'uint16[]', 'int', 'int', 'int', 'int', 'uint32', 'uint32', 'uint32', 'uint32' ], | ||
| 44 | 'SDL_Surface' | ||
| 45 | ], | ||
| 46 | SDL_CreateRGBSurfaceWithFormatFrom => [ # FIX: uint16 might be large enough for raw data | ||
| 47 | [ 'uint16[]', 'int', 'int', 'int', 'int', 'uint32' ], 'SDL_Surface' | ||
| 48 | ], | ||
| 49 | SDL_FreeSurface => [ ['SDL_Surface'] ], | ||
| 50 | SDL_SetSurfacePalette => [ [ 'SDL_Surface', 'SDL_Palette' ], 'int' ], | ||
| 51 | SDL_LockSurface => [ ['SDL_Surface'], 'int' ], | ||
| 52 | SDL_UnlockSurface => [ ['SDL_Surface'] ], | ||
| 53 | SDL_LoadBMP_RW => [ [ 'SDL_RWops', 'int' ], 'SDL_Surface' ], | ||
| 54 | SDL_SaveBMP_RW => [ [ 'SDL_Surface', 'SDL_RWops', 'int' ], 'int' ], | ||
| 55 | SDL_SetSurfaceRLE => [ [ 'SDL_Surface', 'int' ], 'int' ], | ||
| 56 | SDL_HasSurfaceRLE => [ ['SDL_Surface'], 'SDL_bool' ], | ||
| 57 | SDL_SetColorKey => [ [ 'SDL_Surface', 'int', 'uint32' ], 'int' ], | ||
| 58 | SDL_HasColorKey => [ ['SDL_Surface'], 'SDL_bool' ], | ||
| 59 | SDL_GetColorKey => [ [ 'SDL_Surface', 'uint32' ], 'int' ], | ||
| 60 | SDL_SetSurfaceColorMod => [ [ 'SDL_Surface', 'uint8', 'uint8', 'uint8' ], 'int' ], | ||
| 61 | SDL_GetSurfaceColorMod => [ [ 'SDL_Surface', 'uint8*', 'uint8*', 'uint8*' ], 'int' ], | ||
| 62 | SDL_SetSurfaceAlphaMod => [ [ 'SDL_Surface', 'uint8' ], 'int' ], | ||
| 63 | SDL_GetSurfaceAlphaMod => [ [ 'SDL_Surface', 'uint8*' ], 'int' ], | ||
| 64 | SDL_SetSurfaceBlendMode => [ [ 'SDL_Surface', 'SDL_BlendMode' ], 'int' ], | ||
| 65 | SDL_GetSurfaceBlendMode => [ [ 'SDL_Surface', 'SDL_BlendMode' ], 'int' ], | ||
| 66 | SDL_SetClipRect => [ [ 'SDL_Surface', 'SDL_Rect' ], 'SDL_bool' ], | ||
| 67 | SDL_GetClipRect => [ [ 'SDL_Surface', 'SDL_Rect' ] ], | ||
| 68 | SDL_DuplicateSurface => [ ['SDL_Surface'], 'SDL_Surface' ], | ||
| 69 | SDL_ConvertSurface => [ [ 'SDL_Surface', 'SDL_PixelFormat', 'uint32' ], 'SDL_Surface' ], | ||
| 70 | SDL_ConvertSurfaceFormat => [ [ 'SDL_Surface', 'uint32', 'uint32' ], 'SDL_Surface' ], | ||
| 71 | SDL_ConvertPixels => [ # FIX: uint16 might be large enough for raw data | ||
| 72 | [ 'int', 'int', 'uint32', 'uint16[]', 'int', 'uint32', 'uint16[]', 'int' ], 'int' | ||
| 73 | ], | ||
| 74 | SDL_FillRect => [ [ 'SDL_Surface', 'SDL_Rect', 'uint32' ], 'int' ], | ||
| 75 | SDL_FillRects => [ | ||
| 76 | [ 'SDL_Surface', 'RectList_t', 'int', 'uint32' ], | ||
| 77 | 'int' => sub ( $inner, $dst, $_rects, $count, $color ) { | ||
| 78 | my $rects = $SDL2::Rect::LIST->create( | ||
| 79 | [ map { { x => $_->x, y => $_->y, w => $_->w, h => $_->h } } @$_rects ] ); | ||
| 80 | $inner->( $dst, $rects, $count, $color ); | ||
| 81 | } | ||
| 82 | ], | ||
| 83 | SDL_UpperBlit => [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 84 | SDL_LowerBlit => [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 85 | SDL_SoftStretch => [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 86 | SDL_SoftStretchLinear => | ||
| 87 | [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 88 | SDL_UpperBlitScaled => [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 89 | SDL_LowerBlitScaled => [ [ 'SDL_Surface', 'SDL_Rect', 'SDL_Surface', 'SDL_Rect' ], 'int' ], | ||
| 90 | SDL_SetYUVConversionMode => [ ['SDL_YUV_CONVERSION_MODE'] ], | ||
| 91 | SDL_GetYUVConversionMode => [ [], 'SDL_YUV_CONVERSION_MODE' ], | ||
| 92 | SDL_GetYUVConversionModeForResolution => [ [ 'int', 'int' ], 'SDL_YUV_CONVERSION_MODE' ] | ||
| 93 | }; | ||
| 94 | define surface => [ | ||
| 95 | [ SDL_LoadBMP => sub ($file) { | ||
| 96 | SDL2::FFI::SDL_LoadBMP_RW( SDL2::FFI::SDL_RWFromFile( $file, 'rb' ), 1 ); | ||
| 97 | } | ||
| 98 | ], | ||
| 99 | [ SDL_SaveBMP => sub ( $surface, $file ) { | ||
| 100 | SDL2::FFI::SDL_SaveBMP_RW( $surface, SDL2::FFI::SDL_RWFromFile( $file, 'wb' ), 1 ); | ||
| 101 | } | ||
| 102 | ], | ||
| 103 | [ SDL_BlitSurface => sub ( $src, $srcrect, $dst, $dstrect ) { | ||
| 104 | SDL2::FFI::SDL_UpperBlit( $src, $srcrect, $dst, $dstrect ); | ||
| 105 | } | ||
| 106 | ], | ||
| 107 | [ SDL_BlitScaled => sub ( $src, $srcrect, $dst, $dstrect ) { | ||
| 108 | SDL2::FFI::SDL_UpperBlitScaled( $src, $srcrect, $dst, $dstrect ); | ||
| 109 | } | ||
| 110 | ], | ||
| 111 | ]; | ||
| 112 | |||
| 113 | =encoding utf-8 | ||
| 114 | |||
| 115 | =head1 NAME | ||
| 116 | |||
| 117 | SDL2::surface - SDL2::Surface Management Functions | ||
| 118 | |||
| 119 | =head1 SYNOPSIS | ||
| 120 | |||
| 121 | use SDL2 qw[:surface]; | ||
| 122 | |||
| 123 | =head1 DESCRIPTION | ||
| 124 | |||
| 125 | SDL2::surface contains enumerations, functions, and other values used to manage | ||
| 126 | a SDL2::Surface structure. | ||
| 127 | |||
| 128 | =head1 Functions | ||
| 129 | |||
| 130 | These may be imported with the C<:surface> tag or individually by name. | ||
| 131 | |||
| 132 | =head2 C<SDL_CreateRGBSurface( ... )> | ||
| 133 | |||
| 134 | Allocate a new RGB surface. | ||
| 135 | |||
| 136 | my ( $height, $width ) = ( 100, 100 ); | ||
| 137 | # Create a 32-bit surface with the bytes of each pixel in R,G,B,A order, | ||
| 138 | # as expected by OpenGL for textures | ||
| 139 | my ( $rmask, $gmask, $bmask, $amask ); | ||
| 140 | # SDL interprets each pixel as a 32-bit number, so our masks must depend | ||
| 141 | # on the endianness (byte order) of the machine | ||
| 142 | if ( SDL2::FFI::bigendian() ) { | ||
| 143 | $rmask = 0xff000000; | ||
| 144 | $gmask = 0x00ff0000; | ||
| 145 | $bmask = 0x0000ff00; | ||
| 146 | $amask = 0x000000ff; | ||
| 147 | } | ||
| 148 | else { | ||
| 149 | $rmask = 0x000000ff; | ||
| 150 | $gmask = 0x0000ff00; | ||
| 151 | $bmask = 0x00ff0000; | ||
| 152 | $amask = 0xff000000; | ||
| 153 | } | ||
| 154 | my $surface = SDL_CreateRGBSurface( 0, $width, $height, 32, $rmask, $gmask, $bmask, $amask ); | ||
| 155 | if ( !defined $surface ) { | ||
| 156 | SDL_Log( 'SDL_CreateRGBSurface() failed: %s', SDL_GetError() ); | ||
| 157 | exit 1; | ||
| 158 | } | ||
| 159 | # or using the default masks for the depth: | ||
| 160 | $surface = SDL_CreateRGBSurface( 0, $width, $height, 32, 0, 0, 0, 0 ); | ||
| 161 | |||
| 162 | If C<depth> is 4 or 8 bits, an empty palette is allocated for the surface. If | ||
| 163 | C<depth> is greater than 8 bits, the pixel format is set using the [RGBA]mask | ||
| 164 | parameters. | ||
| 165 | |||
| 166 | The [RGBA]mask parameters are the bitmasks used to extract that color from a | ||
| 167 | pixel. For instance, `Rmask` being 0xFF000000 means the red data is stored in | ||
| 168 | the most significant byte. Using zeros for the RGB masks sets a default value, | ||
| 169 | based on the depth. For example: | ||
| 170 | |||
| 171 | SDL_CreateRGBSurface( 0, $w, $h, 32, 0, 0, 0, 0 ); | ||
| 172 | |||
| 173 | However, using zero for the Amask results in an Amask of 0. | ||
| 174 | |||
| 175 | By default surfaces with an alpha mask are set up for blending as with: | ||
| 176 | |||
| 177 | SDL_SetSurfaceBlendMode( $surface, SDL_BLENDMODE_BLEND ); | ||
| 178 | |||
| 179 | You can change this by calling L<< C<SDL_SetSurfaceBlendMode( ... | ||
| 180 | )>|/C<SDL_SetSurfaceBlendMode( ... )> >> and selecting a different | ||
| 181 | C<blendMode>. | ||
| 182 | |||
| 183 | Expected parameters include: | ||
| 184 | |||
| 185 | =over | ||
| 186 | |||
| 187 | =item C<flags> - the flags are unused and should be set to 0 | ||
| 188 | |||
| 189 | =item C<width> - the width of the surface | ||
| 190 | |||
| 191 | =item C<height> - the height of the surface | ||
| 192 | |||
| 193 | =item C<depth> - the depth of the surface in bits | ||
| 194 | |||
| 195 | =item C<Rmask> - the red mask for the pixels | ||
| 196 | |||
| 197 | =item C<Gmask> - the green mask for the pixels | ||
| 198 | |||
| 199 | =item C<Bmask> - the blue mask for the pixels | ||
| 200 | |||
| 201 | =item C<Amask> - the alpha mask for the pixels | ||
| 202 | |||
| 203 | =back | ||
| 204 | |||
| 205 | Returns the new L<SDL2::Surface> structure that is created or C<undef> if it | ||
| 206 | fails; call C<SDL_GetError( )> for more information. | ||
| 207 | |||
| 208 | =head2 C<SDL_CreateRGBSurfaceWithFormat( ... )> | ||
| 209 | |||
| 210 | Allocate a new RGB surface with a specific pixel format. | ||
| 211 | |||
| 212 | # Create a 32-bit surface with the bytes of each pixel in R,G,B,A order, | ||
| 213 | # as expected by OpenGL for textures | ||
| 214 | my $surf = SDL_CreateRGBSurfaceWithFormat( 0, 100, 100, 32, SDL_PIXELFORMAT_RGBA32 ); | ||
| 215 | if ( !defined $surf ) { | ||
| 216 | SDL_Log( "SDL_CreateRGBSurfaceWithFormat() failed: %s", SDL_GetError() ); | ||
| 217 | exit 1; | ||
| 218 | } | ||
| 219 | |||
| 220 | This function operates mostly like L<< C<SDL_CreateRGBSurface( ... | ||
| 221 | )>|/C<SDL_CreateRGBSurface( ... )> >>, except instead of providing pixel color | ||
| 222 | masks, you provide it with a predefined format from C<SDL_PixelFormatEnum>. | ||
| 223 | |||
| 224 | Expected parameters include: | ||
| 225 | |||
| 226 | =over | ||
| 227 | |||
| 228 | =item C<flags> - the flags are unused and should be set to C<0> | ||
| 229 | |||
| 230 | =item C<width> - the width of the surface | ||
| 231 | |||
| 232 | =item C<height> - the height of the surface | ||
| 233 | |||
| 234 | =item C<depth> - the depth of the surface in bits | ||
| 235 | |||
| 236 | =item C<format> - the C<SDL_PixelFormatEnum> for the new surface's pixel format. | ||
| 237 | |||
| 238 | =back | ||
| 239 | |||
| 240 | Returns the new L<SDL2::Surface> structure that is created or C<undef> if it | ||
| 241 | fails; call C<SDL_GetError( )> for more information. | ||
| 242 | |||
| 243 | =head2 C<SDL_CreateRGBSurfaceFrom( ... )> | ||
| 244 | |||
| 245 | Allocate a new RGB surface with existing pixel data. | ||
| 246 | |||
| 247 | # Declare an SDL2::Surface to be filled with raw pixel data | ||
| 248 | my $pixels = [ | ||
| 249 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 250 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 251 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 252 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 253 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0aab, | ||
| 254 | 0x0789, 0x0bcc, 0x0eee, 0x09aa, 0x099a, 0x0ddd, 0x0fff, 0x0eee, 0x0899, 0x0fff, | ||
| 255 | 0x0fff, 0x1fff, 0x0dde, 0x0dee, 0x0fff, 0xabbc, 0xf779, 0x8cdd, 0x3fff, 0x9bbc, | ||
| 256 | 0xaaab, 0x6fff, 0x0fff, 0x3fff, 0xbaab, 0x0fff, 0x0fff, 0x6689, 0x6fff, 0x0dee, | ||
| 257 | 0xe678, 0xf134, 0x8abb, 0xf235, 0xf678, 0xf013, 0xf568, 0xf001, 0xd889, 0x7abc, | ||
| 258 | 0xf001, 0x0fff, 0x0fff, 0x0bcc, 0x9124, 0x5fff, 0xf124, 0xf356, 0x3eee, 0x0fff, | ||
| 259 | 0x7bbc, 0xf124, 0x0789, 0x2fff, 0xf002, 0xd789, 0xf024, 0x0fff, 0x0fff, 0x0002, | ||
| 260 | 0x0134, 0xd79a, 0x1fff, 0xf023, 0xf000, 0xf124, 0xc99a, 0xf024, 0x0567, 0x0fff, | ||
| 261 | 0xf002, 0xe678, 0xf013, 0x0fff, 0x0ddd, 0x0fff, 0x0fff, 0xb689, 0x8abb, 0x0fff, | ||
| 262 | 0x0fff, 0xf001, 0xf235, 0xf013, 0x0fff, 0xd789, 0xf002, 0x9899, 0xf001, 0x0fff, | ||
| 263 | 0x0fff, 0x0fff, 0x0fff, 0xe789, 0xf023, 0xf000, 0xf001, 0xe456, 0x8bcc, 0xf013, | ||
| 264 | 0xf002, 0xf012, 0x1767, 0x5aaa, 0xf013, 0xf001, 0xf000, 0x0fff, 0x7fff, 0xf124, | ||
| 265 | 0x0fff, 0x089a, 0x0578, 0x0fff, 0x089a, 0x0013, 0x0245, 0x0eff, 0x0223, 0x0dde, | ||
| 266 | 0x0135, 0x0789, 0x0ddd, 0xbbbc, 0xf346, 0x0467, 0x0fff, 0x4eee, 0x3ddd, 0x0edd, | ||
| 267 | 0x0dee, 0x0fff, 0x0fff, 0x0dee, 0x0def, 0x08ab, 0x0fff, 0x7fff, 0xfabc, 0xf356, | ||
| 268 | 0x0457, 0x0467, 0x0fff, 0x0bcd, 0x4bde, 0x9bcc, 0x8dee, 0x8eff, 0x8fff, 0x9fff, | ||
| 269 | 0xadee, 0xeccd, 0xf689, 0xc357, 0x2356, 0x0356, 0x0467, 0x0467, 0x0fff, 0x0ccd, | ||
| 270 | 0x0bdd, 0x0cdd, 0x0aaa, 0x2234, 0x4135, 0x4346, 0x5356, 0x2246, 0x0346, 0x0356, | ||
| 271 | 0x0467, 0x0356, 0x0467, 0x0467, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 272 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 273 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, | ||
| 274 | 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff | ||
| 275 | ]; | ||
| 276 | my $surface | ||
| 277 | = SDL_CreateRGBSurfaceFrom( $pixels, 16, 16, 16, 16 * 2, 0x0f00, 0x00f0, 0x000f, 0xf000 ); | ||
| 278 | # Set the icon to the window | ||
| 279 | SDL_SetWindowIcon( $window, $surface ) if $surface; | ||
| 280 | # No longer required | ||
| 281 | SDL_FreeSurface( $surface ); | ||
| 282 | |||
| 283 | This function operates mostly like L<< C<SDL_CreateRGBSurface( ... | ||
| 284 | )>|/C<SDL_CreateRGBSurface( ... )> >>, except it does not allocate memory for | ||
| 285 | the pixel data, instead the caller provides an existing buffer of data for the | ||
| 286 | surface to use. | ||
| 287 | |||
| 288 | No copy is made of the pixel data. Pixel data is not managed automatically; you | ||
| 289 | must free the surface before you free the pixel data. | ||
| 290 | |||
| 291 | Expected parameters include: | ||
| 292 | |||
| 293 | =over | ||
| 294 | |||
| 295 | =item C<pixels> - a pointer to existing pixel data | ||
| 296 | |||
| 297 | =item C<width> - the width of the surface | ||
| 298 | |||
| 299 | =item C<height> - the height of the surface | ||
| 300 | |||
| 301 | =item C<depth> - the depth of the surface in bits | ||
| 302 | |||
| 303 | =item C<pitch> - the pitch of the surface in bytes | ||
| 304 | |||
| 305 | =item C<Rmask> - the red mask for the pixels | ||
| 306 | |||
| 307 | =item C<Gmask> - the green mask for the pixels | ||
| 308 | |||
| 309 | =item C<Bmask> - the blue mask for the pixels | ||
| 310 | |||
| 311 | =item C<Amask> - the alpha mask for the pixels | ||
| 312 | |||
| 313 | =back | ||
| 314 | |||
| 315 | Returns the new L<SDL2::Surface> structure that is created or NULL if it fails; | ||
| 316 | call C<SDL_GetError( )> for more information. | ||
| 317 | |||
| 318 | =head2 C<SDL_CreateRGBSurfaceWithFormatFrom( ... )> | ||
| 319 | |||
| 320 | Allocate a new RGB surface with with a specific pixel format and existing pixel | ||
| 321 | data. | ||
| 322 | |||
| 323 | This function operates mostly like L<< C<SDL_CreateRGBSurfaceFrom( ... | ||
| 324 | )>|/C<SDL_CreateRGBSurfaceFrom( ... )> >>, except instead of providing pixel | ||
| 325 | color masks, you provide it with a predefined format from | ||
| 326 | C<SDL_PixelFormatEnum>. | ||
| 327 | |||
| 328 | No copy is made of the pixel data. Pixel data is not managed automatically; you | ||
| 329 | must free the surface before you free the pixel data. | ||
| 330 | |||
| 331 | Expected parameters include: | ||
| 332 | |||
| 333 | =over | ||
| 334 | |||
| 335 | =item C<pixels> - a pointer to existing pixel data | ||
| 336 | |||
| 337 | =item C<width> - the width of the surface | ||
| 338 | |||
| 339 | =item C<height> - the height of the surface | ||
| 340 | |||
| 341 | =item C<depth> - the depth of the surface in bits | ||
| 342 | |||
| 343 | =item C<pitch> - the pitch of the surface in bytes | ||
| 344 | |||
| 345 | =item C<format> - the C<SDL_PixelFormatEnum> for the new surface's pixel format. | ||
| 346 | |||
| 347 | =back | ||
| 348 | |||
| 349 | Returns the new L<SDL2::Surface> structure that is created or C<undef> if it | ||
| 350 | fails; call C<SDL_GetError( )> for more information. | ||
| 351 | |||
| 352 | =head2 C<SDL_FreeSurface( ... )> | ||
| 353 | |||
| 354 | Free an RGB surface. | ||
| 355 | |||
| 356 | Expected parameters include: | ||
| 357 | |||
| 358 | =over | ||
| 359 | |||
| 360 | =item C<surface> - the C<SDL2::Surface> to free | ||
| 361 | |||
| 362 | =back | ||
| 363 | |||
| 364 | =head2 C<SDL_SetSurfacePalette( ... )> | ||
| 365 | |||
| 366 | Set the palette used by a surface. | ||
| 367 | |||
| 368 | A single palette can be shared with many surfaces. | ||
| 369 | |||
| 370 | Expected parameters include: | ||
| 371 | |||
| 372 | =over | ||
| 373 | |||
| 374 | =item C<surface> - the L<SDL2::Surface> structure to update | ||
| 375 | |||
| 376 | =item C<palette> - the L<SDL2::Palette> structure to use | ||
| 377 | |||
| 378 | =back | ||
| 379 | |||
| 380 | Returns C<0> on success or a negative error code on failure; call | ||
| 381 | C<SDL_GetError( )> for more information. | ||
| 382 | |||
| 383 | =head2 C<SDL_LockSurface( ... )> | ||
| 384 | |||
| 385 | Set up a surface for directly accessing the pixels. | ||
| 386 | |||
| 387 | Between calls to C<SDL_LockSurface( ... )> / L<< C<SDL_UnlockSurface( ... | ||
| 388 | )>|/C<SDL_UnlockSurface( ... )> >>, you can write to and read from C<< | ||
| 389 | surface->pixels >>, using the pixel format stored in C<< surface->format >>. | ||
| 390 | Once you are done accessing the surface, you should use L<< | ||
| 391 | C<SDL_UnlockSurface( ... )>|/C<SDL_UnlockSurface( ... )> >> to release it. | ||
| 392 | |||
| 393 | Not all surfaces require locking. If C<SDL_MUSTLOCK(surface)> evaluates to | ||
| 394 | C<0>, then you can read and write to the surface at any time, and the pixel | ||
| 395 | format of the surface will not change. | ||
| 396 | |||
| 397 | Expected parameters include: | ||
| 398 | |||
| 399 | =over | ||
| 400 | |||
| 401 | =item C<surface> - the L<SDL2::Surface> structure to be locked | ||
| 402 | |||
| 403 | =back | ||
| 404 | |||
| 405 | Returns C<0> on success or a negative error code on failure; call | ||
| 406 | C<SDL_GetError( )> for more information. | ||
| 407 | |||
| 408 | =head2 C<SDL_UnlockSurface( ... )> | ||
| 409 | |||
| 410 | Release a surface after directly accessing the pixels. | ||
| 411 | |||
| 412 | Expected parameters include: | ||
| 413 | |||
| 414 | =over | ||
| 415 | |||
| 416 | =item C<surface> - the L<SDL2::Surface> structure to be unlocked | ||
| 417 | |||
| 418 | =back | ||
| 419 | |||
| 420 | =head2 C<SDL_LoadBMP_RW( ... )> | ||
| 421 | |||
| 422 | Load a BMP image from a seekable SDL data stream. | ||
| 423 | |||
| 424 | The new surface should be freed with L<< C<SDL_FreeSurface( ... | ||
| 425 | )>|/C<SDL_FreeSurface( ... )> >>. | ||
| 426 | |||
| 427 | Expected parameters include: | ||
| 428 | |||
| 429 | =over | ||
| 430 | |||
| 431 | =item C<src> - the data stream for the surface | ||
| 432 | |||
| 433 | =item C<freesrc> - non-zero to close the stream after being read | ||
| 434 | |||
| 435 | =back | ||
| 436 | |||
| 437 | Returns a pointer to a new L<SDL2::Surface> structure or C<undef> if there was | ||
| 438 | an error; call C<SDL_GetError( )> for more information. | ||
| 439 | |||
| 440 | =head2 C<SDL_LoadBMP( ... )> | ||
| 441 | |||
| 442 | Load a surface from a file. | ||
| 443 | |||
| 444 | my $surface = SDL_LoadBMP( './icons/16x16.bmp' ); | ||
| 445 | |||
| 446 | Expected parameters include: | ||
| 447 | |||
| 448 | =over | ||
| 449 | |||
| 450 | =item C<file> - path to a filename to read | ||
| 451 | |||
| 452 | =back | ||
| 453 | |||
| 454 | Returns a pointer to a new L<SDL2::Surface> structure or C<undef> if there was | ||
| 455 | an error; call C<SDL_GetError( )> for more information. | ||
| 456 | |||
| 457 | =head2 C<SDL_SaveBMP_RW( ... )> | ||
| 458 | |||
| 459 | Save a surface to a seekable SDL data stream in BMP format. | ||
| 460 | |||
| 461 | Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the BMP | ||
| 462 | directly. Other RGB formats with 8-bit or higher get converted to a 24-bit | ||
| 463 | surface or, if they have an alpha mask or a colorkey, to a 32-bit surface | ||
| 464 | before they are saved. YUV and paletted 1-bit and 4-bit formats are not | ||
| 465 | supported. | ||
| 466 | |||
| 467 | Expected parameters include: | ||
| 468 | |||
| 469 | =over | ||
| 470 | |||
| 471 | =item C<surface> - the L<SDL2::Surface> structure containing the image to be saved | ||
| 472 | |||
| 473 | =item C<dst> - a data stream to save to | ||
| 474 | |||
| 475 | =item C<freedst> - non-zero to close the stream after being written | ||
| 476 | |||
| 477 | =back | ||
| 478 | |||
| 479 | Returns C<0> on success or a negative error code on failure; call | ||
| 480 | C<SDL_GetError( )> for more information. | ||
| 481 | |||
| 482 | =head2 C<SDL_SaveBMP( ... )> | ||
| 483 | |||
| 484 | Save a surface to a file. | ||
| 485 | |||
| 486 | SDL_SaveBMP( $surface, './icons/output.bmp' ); | ||
| 487 | |||
| 488 | Expected parameters include: | ||
| 489 | |||
| 490 | =over | ||
| 491 | |||
| 492 | =item C<surface> - the L<SDL2::Surface> structure containing the image to be saved | ||
| 493 | |||
| 494 | =item C<file> - file to save to | ||
| 495 | |||
| 496 | =back | ||
| 497 | |||
| 498 | Returns C<0> on success or a negative error code on failure; call | ||
| 499 | C<SDL_GetError( )> for more information. | ||
| 500 | |||
| 501 | =head2 C<SDL_SetSurfaceRLE( ... )> | ||
| 502 | |||
| 503 | Set the RLE acceleration hint for a surface. | ||
| 504 | |||
| 505 | If RLE is enabled, color key and alpha blending blits are much faster, but the | ||
| 506 | surface must be locked before directly accessing the pixels. | ||
| 507 | |||
| 508 | Expected parameters include: | ||
| 509 | |||
| 510 | =over | ||
| 511 | |||
| 512 | =item C<surface> - the L<SDL2::Surface> structure to optimize | ||
| 513 | |||
| 514 | =item C<flag> - C<0> to disable, non-zero to enable RLE acceleration | ||
| 515 | |||
| 516 | =back | ||
| 517 | |||
| 518 | Returns C<0> on success or a negative error code on failure; call | ||
| 519 | C<SDL_GetError( )> for more information. | ||
| 520 | |||
| 521 | =head2 C<SDL_HasSurfaceRLE( ... )> | ||
| 522 | |||
| 523 | Returns whether the surface is RLE enabled | ||
| 524 | |||
| 525 | Expected parameters include: | ||
| 526 | |||
| 527 | =over | ||
| 528 | |||
| 529 | =item C<surface> the L<SDL2::Surface> structure to query | ||
| 530 | |||
| 531 | =back | ||
| 532 | |||
| 533 | Returns C<SDL_TRUE> if the surface is RLE enabled, C<SDL_FALSE> otherwise. | ||
| 534 | |||
| 535 | =head2 C<SDL_SetColorKey( ... )> | ||
| 536 | |||
| 537 | Set the color key (transparent pixel) in a surface. | ||
| 538 | |||
| 539 | The color key defines a pixel value that will be treated as transparent in a | ||
| 540 | blit. It is a pixel of the format used by the surface, as generated by | ||
| 541 | C<SDL_MapRGB( ... )>. | ||
| 542 | |||
| 543 | RLE acceleration can substantially speed up blitting of images with large | ||
| 544 | horizontal runs of transparent pixels. See L<< C<SDL_SetSurfaceRLE( ... | ||
| 545 | )>|/C<SDL_SetSurfaceRLE( ... )> >> for details. | ||
| 546 | |||
| 547 | Expected parameters include: | ||
| 548 | |||
| 549 | =over | ||
| 550 | |||
| 551 | =item C<surface> - the L<SDL2::Surface> structure to update | ||
| 552 | |||
| 553 | =item C<flag> - C<SDL_TRUE> to enable color key, C<SDL_FALSE> to disable color key | ||
| 554 | |||
| 555 | =item C<key> - the transparent pixel | ||
| 556 | |||
| 557 | =back | ||
| 558 | |||
| 559 | Returns C<0> on success or a negative error code on failure; call | ||
| 560 | C<SDL_GetError( )> for more information. | ||
| 561 | |||
| 562 | =head2 C<SDL_HasColorKey( ... )> | ||
| 563 | |||
| 564 | Returns whether the surface has a color key. | ||
| 565 | |||
| 566 | Expected parameters include: | ||
| 567 | |||
| 568 | =over | ||
| 569 | |||
| 570 | =item C<surface> - the L<SDL2::Surface> structure to query | ||
| 571 | |||
| 572 | =back | ||
| 573 | |||
| 574 | Returns C<SDL_TRUE> if the surface has a color key, C<SDL_FALSE> otherwise. | ||
| 575 | |||
| 576 | =head2 C<SDL_GetColorKey( ... )> | ||
| 577 | |||
| 578 | Get the color key (transparent pixel) for a surface. | ||
| 579 | |||
| 580 | The color key is a pixel of the format used by the surface, as generated by | ||
| 581 | C<SDL_MapRGB( )>. | ||
| 582 | |||
| 583 | If the surface doesn't have color key enabled this function returns C<-1>. | ||
| 584 | |||
| 585 | Expected parameters include: | ||
| 586 | |||
| 587 | =over | ||
| 588 | |||
| 589 | =item C<surface> - the L<SDL2::Surface> structure to query | ||
| 590 | |||
| 591 | =item C<key> a pointer filled in with the transparent pixel | ||
| 592 | |||
| 593 | =back | ||
| 594 | |||
| 595 | Returns C<0> on success or a negative error code on failure; call | ||
| 596 | C<SDL_GetError( )> for more information. | ||
| 597 | |||
| 598 | =head2 C<SDL_SetSurfaceColorMod( ... )> | ||
| 599 | |||
| 600 | Set an additional color value multiplied into blit operations. | ||
| 601 | |||
| 602 | When this surface is blitted, during the blit operation each source color | ||
| 603 | channel is modulated by the appropriate color value according to the following | ||
| 604 | formula: C<srcC = srcC * (color / 255)> | ||
| 605 | |||
| 606 | Expected parameters include: | ||
| 607 | |||
| 608 | =over | ||
| 609 | |||
| 610 | =item C<surface> - the L<SDL2::Surface> structure to update | ||
| 611 | |||
| 612 | =item C<r> - the red color value multiplied into blit operations | ||
| 613 | |||
| 614 | =item C<g> - the green color value multiplied into blit operations | ||
| 615 | |||
| 616 | =item C<b> - the blue color value multiplied into blit operations | ||
| 617 | |||
| 618 | =back | ||
| 619 | |||
| 620 | Returns C<0> on success or a negative error code on failure; call | ||
| 621 | C<SDL_GetError( )> for more information. | ||
| 622 | |||
| 623 | =head2 C<SDL_GetSurfaceColorMod( ... )> | ||
| 624 | |||
| 625 | Get the additional color value multiplied into blit operations. | ||
| 626 | |||
| 627 | Expected parameters include: | ||
| 628 | |||
| 629 | =over | ||
| 630 | |||
| 631 | =item C<surface> - the L<SDL2::Surface> structure to query | ||
| 632 | |||
| 633 | =item C<r> - a pointer filled in with the current red color value | ||
| 634 | |||
| 635 | =item C<g> - a pointer filled in with the current green color value | ||
| 636 | |||
| 637 | =item C<b> - a pointer filled in with the current blue color value | ||
| 638 | |||
| 639 | =back | ||
| 640 | |||
| 641 | Returns C<0> on success or a negative error code on failure; call | ||
| 642 | C<SDL_GetError( )> for more information. | ||
| 643 | |||
| 644 | =head2 C<SDL_SetSurfaceAlphaMod( ... )> | ||
| 645 | |||
| 646 | Set an additional alpha value used in blit operations. | ||
| 647 | |||
| 648 | When this surface is blitted, during the blit operation the source alpha value | ||
| 649 | is modulated by this alpha value according to the following formula: C<srcA = | ||
| 650 | srcA * (alpha / 255)>. | ||
| 651 | |||
| 652 | Expected parameters include: | ||
| 653 | |||
| 654 | =over | ||
| 655 | |||
| 656 | =item C<surface> - the L<SDL2::Surface> structure to update | ||
| 657 | |||
| 658 | =item C<alpha> - the alpha value multiplied into blit operations | ||
| 659 | |||
| 660 | =back | ||
| 661 | |||
| 662 | Returns C<0> on success or a negative error code on failure; call | ||
| 663 | C<SDL_GetError( )> for more information. | ||
| 664 | |||
| 665 | =head2 C<SDL_GetSurfaceAlphaMod( ... )> | ||
| 666 | |||
| 667 | Get the additional alpha value used in blit operations. | ||
| 668 | |||
| 669 | Expected parameters include: | ||
| 670 | |||
| 671 | =over | ||
| 672 | |||
| 673 | =item C<surface> - the L<SDL2::Surface> structure to query | ||
| 674 | |||
| 675 | =item C<alpha> - a pointer filled in with the current alpha value | ||
| 676 | |||
| 677 | =back | ||
| 678 | |||
| 679 | Returns C<0> on success or a negative error code on failure; call | ||
| 680 | C<SDL_GetError( )> for more information. | ||
| 681 | |||
| 682 | =head2 C<SDL_SetSurfaceBlendMode( ... )> | ||
| 683 | |||
| 684 | Set the blend mode used for blit operations. | ||
| 685 | |||
| 686 | To copy a surface to another surface (or texture) without blending with the | ||
| 687 | existing data, the blendmode of the SOURCE surface should be set to | ||
| 688 | C<SDL_BLENDMODE_NONE>. | ||
| 689 | |||
| 690 | Expected parameters include: | ||
| 691 | |||
| 692 | =over | ||
| 693 | |||
| 694 | =item C<surface> - the L<SDL2::Surface> structure to update | ||
| 695 | |||
| 696 | =item C<blendMode> - the SDL_BlendMode to use for blit blending | ||
| 697 | |||
| 698 | =back | ||
| 699 | |||
| 700 | Returns C<0> on success or a negative error code on failure; call | ||
| 701 | C<SDL_GetError( )> for more information. | ||
| 702 | |||
| 703 | =head2 C<SDL_GetSurfaceBlendMode( ... )> | ||
| 704 | |||
| 705 | Get the blend mode used for blit operations. | ||
| 706 | |||
| 707 | Expected parameters include: | ||
| 708 | |||
| 709 | =over | ||
| 710 | |||
| 711 | =item C<surface> - the L<SDL2::Surface> structure to query | ||
| 712 | |||
| 713 | =item C<blendMode> - a pointer filled in with the current SDL_BlendMode | ||
| 714 | |||
| 715 | =back | ||
| 716 | |||
| 717 | Returns C<0> on success or a negative error code on failure; call | ||
| 718 | C<SDL_GetError( )> for more information. | ||
| 719 | |||
| 720 | =head2 C<SDL_SetClipRect( ... )> | ||
| 721 | |||
| 722 | Set the clipping rectangle for a surface. | ||
| 723 | |||
| 724 | When C<surface> is the destination of a blit, only the area within the clip | ||
| 725 | rectangle is drawn into. | ||
| 726 | |||
| 727 | Note that blits are automatically clipped to the edges of the source and | ||
| 728 | destination surfaces. | ||
| 729 | |||
| 730 | Expected parameters include: | ||
| 731 | |||
| 732 | =over | ||
| 733 | |||
| 734 | =item C<surface> - the L<SDL2::Surface> structure to be clipped | ||
| 735 | |||
| 736 | =item C<rect> - the SDL_Rect structure representing the clipping rectangle, or C<undef> to disable clipping | ||
| 737 | |||
| 738 | =back | ||
| 739 | |||
| 740 | Returns C<SDL_TRUE> if the rectangle intersects the surface, otherwise | ||
| 741 | C<SDL_FALSE> and blits will be completely clipped. | ||
| 742 | |||
| 743 | =head2 C<SDL_GetClipRect( ... )> | ||
| 744 | |||
| 745 | Get the clipping rectangle for a surface. | ||
| 746 | |||
| 747 | When C<surface> is the destination of a blit, only the area within the clip | ||
| 748 | rectangle is drawn into. | ||
| 749 | |||
| 750 | Expected parameters include: | ||
| 751 | |||
| 752 | =over | ||
| 753 | |||
| 754 | =item C<surface> - the L<SDL2::Surface> structure representing the surface to be clipped | ||
| 755 | |||
| 756 | =item C<rect> - an SDL_Rect structure filled in with the clipping rectangle for the surface | ||
| 757 | |||
| 758 | =back | ||
| 759 | |||
| 760 | =head2 C<SDL_DuplicateSurface( ... )> | ||
| 761 | |||
| 762 | Creates a new surface identical to the existing surface. | ||
| 763 | |||
| 764 | The returned surface should be freed with L<< C<SDL_FreeSurface( ... | ||
| 765 | )>|/C<SDL_FreeSurface( ... )> >>. | ||
| 766 | |||
| 767 | Expected parameters include: | ||
| 768 | |||
| 769 | =over | ||
| 770 | |||
| 771 | =item C<surface> - the surface to duplicate. | ||
| 772 | |||
| 773 | =back | ||
| 774 | |||
| 775 | Returns a copy of the surface, or C<undef> on failure; call C<SDL_GetError( )> | ||
| 776 | for more information. | ||
| 777 | |||
| 778 | =head2 C<SDL_ConvertSurface( ... )> | ||
| 779 | |||
| 780 | Copy an existing surface to a new surface of the specified format. | ||
| 781 | |||
| 782 | This function is used to optimize images for faster *repeat* blitting. This is | ||
| 783 | accomplished by converting the original and storing the result as a new | ||
| 784 | surface. The new, optimized surface can then be used as the source for future | ||
| 785 | blits, making them faster. | ||
| 786 | |||
| 787 | Expected parameters include: | ||
| 788 | |||
| 789 | =over | ||
| 790 | |||
| 791 | =item C<src> - the existing SDL_Surface structure to convert | ||
| 792 | |||
| 793 | =item C<fmt> - the SDL_PixelFormat structure that the new surface is optimized for | ||
| 794 | |||
| 795 | =item C<flags> - the flags are unused and should be set to 0; this is a leftover from SDL 1.2's API | ||
| 796 | |||
| 797 | =back | ||
| 798 | |||
| 799 | Returns the new L<SDL2::Surface> structure that is created or C<undef> if it | ||
| 800 | fails; call C<SDL_GetError( )> for more information. | ||
| 801 | |||
| 802 | =head2 C<SDL_ConvertSurfaceFormat( ... )> | ||
| 803 | |||
| 804 | Copy an existing surface to a new surface of the specified format enum. | ||
| 805 | |||
| 806 | This function operates just like L<< C<SDL_ConvertSurface( ... | ||
| 807 | )>|/C<SDL_ConvertSurface( ... )> >>, but accepts an C<SDL_PixelFormatEnum> | ||
| 808 | value instead of an SDL_PixelFormat structure. As such, it might be easier to | ||
| 809 | call but it doesn't have access to palette information for the destination | ||
| 810 | surface, in case that would be important. | ||
| 811 | |||
| 812 | Expected parameters include: | ||
| 813 | |||
| 814 | =over | ||
| 815 | |||
| 816 | =item C<src> - the existing L<SDL2::Surface> structure to convert | ||
| 817 | |||
| 818 | =item C<pixel_format> - the C<SDL_PixelFormatEnum> that the new surface is optimized for | ||
| 819 | |||
| 820 | =item C<flags> - the flags are unused and should be set to 0; this is a leftover from SDL 1.2's API | ||
| 821 | |||
| 822 | =back | ||
| 823 | |||
| 824 | Returns the new L<SDL2::Surface> structure that is created or C<undef> if it | ||
| 825 | fails; call C<SDL_GetError( )> for more information. | ||
| 826 | |||
| 827 | =head2 C<SDL_ConvertPixels( ... )> | ||
| 828 | |||
| 829 | Copy a block of pixels of one format to another format. | ||
| 830 | |||
| 831 | Expected parameters include: | ||
| 832 | |||
| 833 | =over | ||
| 834 | |||
| 835 | =item C<width> - the width of the block to copy, in pixels | ||
| 836 | |||
| 837 | =item C<height> - the height of the block to copy, in pixels | ||
| 838 | |||
| 839 | =item C<src_format> - an C<SDL_PixelFormatEnum> value of the C<src> pixels format | ||
| 840 | |||
| 841 | =item C<src> - a pointer to the source pixels | ||
| 842 | |||
| 843 | =item C<src_pitch> - the pitch of the block to copy, in bytes | ||
| 844 | |||
| 845 | =item C<dst_format> - an C<SDL_PixelFormatEnum> value of the C<dst> pixels format | ||
| 846 | |||
| 847 | =item C<dst> - a pointer to be filled in with new pixel data | ||
| 848 | |||
| 849 | =item C<dst_pitch> - the pitch of the destination pixels, in bytes | ||
| 850 | |||
| 851 | =back | ||
| 852 | |||
| 853 | Returns C<0> on success or a negative error code on failure; call | ||
| 854 | C<SDL_GetError( )> for more information. | ||
| 855 | |||
| 856 | =head2 C<SDL_FillRect( ... )> | ||
| 857 | |||
| 858 | Perform a fast fill of a rectangle with a specific color. | ||
| 859 | |||
| 860 | C<color> should be a pixel of the format used by the surface, and can be | ||
| 861 | generated by C<SDL_MapRGB( ... )> or C<SDL_MapRGBA( ... )>. If the color value | ||
| 862 | contains an alpha component then the destination is simply filled with that | ||
| 863 | alpha information, no blending takes place. | ||
| 864 | |||
| 865 | If there is a clip rectangle set on the destination (set via C<SDL_SetClipRect( | ||
| 866 | ... )>), then this function will fill based on the intersection of the clip | ||
| 867 | rectangle and C<rect>. | ||
| 868 | |||
| 869 | Expected parameters include: | ||
| 870 | |||
| 871 | =over | ||
| 872 | |||
| 873 | =item C<dst> - the L<SDL2::Surface> structure that is the drawing target | ||
| 874 | |||
| 875 | =item C<rect> - the SDL_Rect structure representing the rectangle to fill, or C<undef> to fill the entire surface | ||
| 876 | |||
| 877 | =item C<color> - the color to fill with | ||
| 878 | |||
| 879 | =back | ||
| 880 | |||
| 881 | Returns C<0> on success or a negative error code on failure; call | ||
| 882 | C<SDL_GetError( )> for more information. | ||
| 883 | |||
| 884 | =head2 C<SDL_FillRects( ... )> | ||
| 885 | |||
| 886 | Perform a fast fill of a set of rectangles with a specific color. | ||
| 887 | |||
| 888 | my @rects = ( | ||
| 889 | SDL2::Rect->new( { w => 100, h => 100, x => 0, y => 0 } ), | ||
| 890 | SDL2::Rect->new( { w => 100, h => 100, x => 200, y => 20 } ) | ||
| 891 | ); | ||
| 892 | my $surface = SDL_LoadBMP('./imgs/640_426.bmp'); | ||
| 893 | SDL_FillRects( $surface, \@rects, scalar @rects, 255 ); # blue | ||
| 894 | SDL_SaveBMP( $surface, './imgs/new_640_426.bmp' ); | ||
| 895 | |||
| 896 | C<color> should be a pixel of the format used by the surface, and can be | ||
| 897 | generated by C<SDL_MapRGB( ... )> or C<SDL_MapRGBA( ... )>. If the color value | ||
| 898 | contains an alpha component then the destination is simply filled with that | ||
| 899 | alpha information, no blending takes place. | ||
| 900 | |||
| 901 | If there is a clip rectangle set on the destination (set via C<SDL_SetClipRect( | ||
| 902 | ... )>), then this function will fill based on the intersection of the clip | ||
| 903 | rectangle and C<rect>. | ||
| 904 | |||
| 905 | Expected parameters include: | ||
| 906 | |||
| 907 | =over | ||
| 908 | |||
| 909 | =item C<dst> - the L<SDL2::Surface> structure that is the drawing target | ||
| 910 | |||
| 911 | =item C<rects> - an array of C<SDL2::Rects> representing the rectangles to fill. | ||
| 912 | |||
| 913 | =item C<count> - the number of rectangles in the array | ||
| 914 | |||
| 915 | =item C<color> - the color to fill with | ||
| 916 | |||
| 917 | =back | ||
| 918 | |||
| 919 | Returns C<0> on success or a negative error code on failure; call | ||
| 920 | C<SDL_GetError( )> for more information. | ||
| 921 | |||
| 922 | =head2 C<SDL_BlitSurface( ... )> | ||
| 923 | |||
| 924 | Performs a fast blit from the source surface to the destination surface. | ||
| 925 | |||
| 926 | Expected parameters include: | ||
| 927 | |||
| 928 | =over | ||
| 929 | |||
| 930 | =item C<src> - the C<SDL2::Surface> structure to be copied from | ||
| 931 | |||
| 932 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 933 | |||
| 934 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 935 | |||
| 936 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 937 | |||
| 938 | =back | ||
| 939 | |||
| 940 | This assumes that the source and destination rectangles are the same size. If | ||
| 941 | either C<srcrect> or C<dstrect> are C<undef>, the entire surface (C<src> or | ||
| 942 | C<dst>) is copied. The final blit rectangles are saved in C<srcrect> and | ||
| 943 | C<dstrect> after all clipping is performed. | ||
| 944 | |||
| 945 | If the blit is successful, it returns C<0>, otherwise it returns C<-1>. | ||
| 946 | |||
| 947 | The blit function should not be called on a locked surface. | ||
| 948 | |||
| 949 | The blit semantics for surfaces with and without blending and colorkey are | ||
| 950 | defined as follows: | ||
| 951 | |||
| 952 | RGBA->RGB: | ||
| 953 | Source surface blend mode set to SDL_BLENDMODE_BLEND: | ||
| 954 | alpha-blend (using the source alpha-channel and per-surface alpha) | ||
| 955 | SDL_SRCCOLORKEY ignored. | ||
| 956 | Source surface blend mode set to SDL_BLENDMODE_NONE: | ||
| 957 | copy RGB. | ||
| 958 | if SDL_SRCCOLORKEY set, only copy the pixels matching the | ||
| 959 | RGB values of the source color key, ignoring alpha in the | ||
| 960 | comparison. | ||
| 961 | RGB->RGBA: | ||
| 962 | Source surface blend mode set to SDL_BLENDMODE_BLEND: | ||
| 963 | alpha-blend (using the source per-surface alpha) | ||
| 964 | Source surface blend mode set to SDL_BLENDMODE_NONE: | ||
| 965 | copy RGB, set destination alpha to source per-surface alpha value. | ||
| 966 | both: | ||
| 967 | if SDL_SRCCOLORKEY set, only copy the pixels matching the | ||
| 968 | source color key. | ||
| 969 | RGBA->RGBA: | ||
| 970 | Source surface blend mode set to SDL_BLENDMODE_BLEND: | ||
| 971 | alpha-blend (using the source alpha-channel and per-surface alpha) | ||
| 972 | SDL_SRCCOLORKEY ignored. | ||
| 973 | Source surface blend mode set to SDL_BLENDMODE_NONE: | ||
| 974 | copy all of RGBA to the destination. | ||
| 975 | if SDL_SRCCOLORKEY set, only copy the pixels matching the | ||
| 976 | RGB values of the source color key, ignoring alpha in the | ||
| 977 | comparison. | ||
| 978 | RGB->RGB: | ||
| 979 | Source surface blend mode set to SDL_BLENDMODE_BLEND: | ||
| 980 | alpha-blend (using the source per-surface alpha) | ||
| 981 | Source surface blend mode set to SDL_BLENDMODE_NONE: | ||
| 982 | copy RGB. | ||
| 983 | both: | ||
| 984 | if SDL_SRCCOLORKEY set, only copy the pixels matching the | ||
| 985 | source color key. | ||
| 986 | |||
| 987 | You should call C<SDL_BlitSurface( ... )> unless you know exactly how SDL | ||
| 988 | blitting works internally and how to use the other blit functions. | ||
| 989 | |||
| 990 | Returns C<0> if the blit is successful or a negative error code on failure; | ||
| 991 | call C<SDL_GetError( )> for more information. | ||
| 992 | |||
| 993 | =head2 C<SDL_UpperBlit( )> | ||
| 994 | |||
| 995 | Perform a fast blit from the source surface to the destination surface. | ||
| 996 | |||
| 997 | Expected parameters include: | ||
| 998 | |||
| 999 | =over | ||
| 1000 | |||
| 1001 | =item C<src> - the C<SDL2::Surface> structure to be copied from | ||
| 1002 | |||
| 1003 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1004 | |||
| 1005 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1006 | |||
| 1007 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1008 | |||
| 1009 | =back | ||
| 1010 | |||
| 1011 | C<SDL_UpperBlit( ... )> has been replaced by L<< C<SDL_BlitSurface( ... | ||
| 1012 | )>|/C<SDL_BlitSurface( ... )> >>, which is merely a wrapper for this function | ||
| 1013 | with a less confusing name. | ||
| 1014 | |||
| 1015 | Returns C<0> if the blit is successful or a negative error code on failure; | ||
| 1016 | call C<SDL_GetError( )> for more information. | ||
| 1017 | |||
| 1018 | =head2 C<SDL_LowerBlit( ... )> | ||
| 1019 | |||
| 1020 | Perform low-level surface blitting only. | ||
| 1021 | |||
| 1022 | This is a semi-private blit function and it performs low-level surface | ||
| 1023 | blitting, assuming the input rectangles have already been clipped. | ||
| 1024 | |||
| 1025 | Unless you know what you're doing, you should be using L<< C<SDL_BlitSurface( | ||
| 1026 | ... )>|/C<SDL_BlitSurface( ... )> >> instead. | ||
| 1027 | |||
| 1028 | Expected parameters include: | ||
| 1029 | |||
| 1030 | =over | ||
| 1031 | |||
| 1032 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1033 | |||
| 1034 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1035 | |||
| 1036 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1037 | |||
| 1038 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1039 | |||
| 1040 | =back | ||
| 1041 | |||
| 1042 | Returns C<0> on success or a negative error code on failure; call | ||
| 1043 | C<SDL_GetError( )> for more information. | ||
| 1044 | |||
| 1045 | =head2 C<SDL_SoftStretch( ... )> | ||
| 1046 | |||
| 1047 | Perform a fast, low quality, stretch blit between two surfaces of the same | ||
| 1048 | format. | ||
| 1049 | |||
| 1050 | Expected parameters include: | ||
| 1051 | |||
| 1052 | =over | ||
| 1053 | |||
| 1054 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1055 | |||
| 1056 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1057 | |||
| 1058 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1059 | |||
| 1060 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1061 | |||
| 1062 | =back | ||
| 1063 | |||
| 1064 | B<Warning>: This function uses a static buffer, and is not thread-safe. | ||
| 1065 | |||
| 1066 | Returns C<0> on success or a negative error code on failure; call | ||
| 1067 | C<SDL_GetError( )> for more information. | ||
| 1068 | |||
| 1069 | Please use L<< C<SDL_BlitScaled( ... )>|/C<SDL_BlitScaled( ... )> >> instead. | ||
| 1070 | |||
| 1071 | =head2 C<SDL_SoftStretchLinear( ... )> | ||
| 1072 | |||
| 1073 | Perform bilinear scaling between two surfaces of the same format, 32BPP. | ||
| 1074 | |||
| 1075 | Expected parameters include: | ||
| 1076 | |||
| 1077 | =over | ||
| 1078 | |||
| 1079 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1080 | |||
| 1081 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1082 | |||
| 1083 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1084 | |||
| 1085 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1086 | |||
| 1087 | =back | ||
| 1088 | |||
| 1089 | Returns C<0> on success or a negative error code on failure; call | ||
| 1090 | C<SDL_GetError( )> for more information. | ||
| 1091 | |||
| 1092 | Please use L<< C<SDL_BlitScaled( ... )>|/C<SDL_BlitScaled( ... )> >> instead. | ||
| 1093 | |||
| 1094 | =head2 C<SDL_BlitScaled( ... )> | ||
| 1095 | |||
| 1096 | Perform a scaled surface copy to a destination surface. | ||
| 1097 | |||
| 1098 | Expected parameters include: | ||
| 1099 | |||
| 1100 | =over | ||
| 1101 | |||
| 1102 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1103 | |||
| 1104 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1105 | |||
| 1106 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1107 | |||
| 1108 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1109 | |||
| 1110 | =back | ||
| 1111 | |||
| 1112 | Returns C<0> on success or a negative error code on failure; call | ||
| 1113 | C<SDL_GetError( )> for more information. | ||
| 1114 | |||
| 1115 | =head2 C<SDL_UpperBlitScaled( ... )> | ||
| 1116 | |||
| 1117 | Perform a scaled surface copy to a destination surface. | ||
| 1118 | |||
| 1119 | Expected parameters include: | ||
| 1120 | |||
| 1121 | =over | ||
| 1122 | |||
| 1123 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1124 | |||
| 1125 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1126 | |||
| 1127 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1128 | |||
| 1129 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1130 | |||
| 1131 | =back | ||
| 1132 | |||
| 1133 | Returns C<0> on success or a negative error code on failure; call | ||
| 1134 | C<SDL_GetError( )> for more information. | ||
| 1135 | |||
| 1136 | C<SDL_UpperBlitScaled( ... )> has been replaced by L<< C<SDL_BlitScaled( ... | ||
| 1137 | )>|/C<SDL_BlitScaled( ... )> >>, which is merely a wrapper for this function | ||
| 1138 | with a less confusing name. | ||
| 1139 | |||
| 1140 | =head2 C<SDL_LowerBlitScaled( ... )> | ||
| 1141 | |||
| 1142 | Perform low-level surface scaled blitting only. | ||
| 1143 | |||
| 1144 | Expected parameters include: | ||
| 1145 | |||
| 1146 | =over | ||
| 1147 | |||
| 1148 | =item C<src> - the L<SDL2::Surface> structure to be copied from | ||
| 1149 | |||
| 1150 | =item C<srcrect> - the L<SDL2::Rect> structure representing the rectangle to be copied, or C<undef> to copy the entire surface | ||
| 1151 | |||
| 1152 | =item C<dst> - the L<SDL2::Surface> structure that is the blit target | ||
| 1153 | |||
| 1154 | =item C<dstrect> - the L<SDL2::Rect> structure representing the rectangle that is copied into | ||
| 1155 | |||
| 1156 | =back | ||
| 1157 | |||
| 1158 | Returns C<0> on success or a negative error code on failure; call | ||
| 1159 | C<SDL_GetError( )> for more information. | ||
| 1160 | |||
| 1161 | This is a semi-private function and it performs low-level surface blitting, | ||
| 1162 | assuming the input rectangles have already been clipped. | ||
| 1163 | |||
| 1164 | =head2 C<SDL_SetYUVConversionMode( ... )> | ||
| 1165 | |||
| 1166 | Set the YUV conversion mode. | ||
| 1167 | |||
| 1168 | Expected parameters include; | ||
| 1169 | |||
| 1170 | =over | ||
| 1171 | |||
| 1172 | =item C<mode> - a C<SDL_YUV_CONVERSION_MODE> | ||
| 1173 | |||
| 1174 | =back | ||
| 1175 | |||
| 1176 | =head2 C<SDL_GetYUVConversionMode( )> | ||
| 1177 | |||
| 1178 | Get the YUV conversion mode. | ||
| 1179 | |||
| 1180 | Returns a C<SDL_GetYUVConversionMode> value. | ||
| 1181 | |||
| 1182 | =head2 C<SDL_GetYUVConversionModeForResolution( ... )> | ||
| 1183 | |||
| 1184 | Get the YUV conversion mode, returning the correct mode for the resolution when | ||
| 1185 | the current conversion mode is C<SDL_YUV_CONVERSION_AUTOMATIC>. | ||
| 1186 | |||
| 1187 | Expected parameters include: | ||
| 1188 | |||
| 1189 | =over | ||
| 1190 | |||
| 1191 | =item C<width> | ||
| 1192 | |||
| 1193 | =item C<height> | ||
| 1194 | |||
| 1195 | =back | ||
| 1196 | |||
| 1197 | Returns a C<SDL_YUV_CONVERSION_MODE> value. | ||
| 1198 | |||
| 1199 | =head1 Defined Values and Enumerations | ||
| 1200 | |||
| 1201 | These may be imported with the given tag or individually by name. | ||
| 1202 | |||
| 1203 | =head2 C<SDL_YUV_CONVERSION_MODE> | ||
| 1204 | |||
| 1205 | The formula used for converting between YUV and RGB. These values may be | ||
| 1206 | imported with the C<:YUV_CONVERSION_MODE> tag. | ||
| 1207 | |||
| 1208 | =over | ||
| 1209 | |||
| 1210 | =item C<SDL_YUV_CONVERSION_JPEG> - Full range JPEG | ||
| 1211 | |||
| 1212 | =item C<SDL_YUV_CONVERSION_BT601> - BT.601 (the default) | ||
| 1213 | |||
| 1214 | =item C<SDL_YUV_CONVERSION_BT709> - BT.709 | ||
| 1215 | |||
| 1216 | =item C<SDL_YUV_CONVERSION_AUTOMATIC> - BT.601 for SD content, BT.709 for HD content | ||
| 1217 | |||
| 1218 | =back | ||
| 1219 | |||
| 1220 | =head1 LICENSE | ||
| 1221 | |||
| 1222 | Copyright (C) Sanko Robinson. | ||
| 1223 | |||
| 1224 | This library is free software; you can redistribute it and/or modify it under | ||
| 1225 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 1226 | conditions may apply to data transmitted through this module. | ||
| 1227 | |||
| 1228 | =head1 AUTHOR | ||
| 1229 | |||
| 1230 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 1231 | |||
| 1232 | =begin stopwords | ||
| 1233 | |||
| 1234 | colorkey paletted bitmasks blit blits blitted blitting blendmode rect enum | ||
| 1235 | 0xFF000000 | ||
| 1236 | |||
| 1237 | =end stopwords | ||
| 1238 | |||
| 1239 | =cut | ||
| 1240 | |||
| 1241 | }; | ||
| 1242 | 1; |