Class: SDL2::PixelFormat
- Defined in:
- lib/sdl2/pixel_format.rb
Overview
SDL_pixels.h:272~293:typdef struct SDL_PixelFormat note Everything in the pixel format structure is read-only.
Class Method Summary collapse
-
.create(pixel_format) ⇒ Object
SDL_AllocFormat, renamed ‘create’ to follow ruby paradigms.
-
.get_name(pixel_format) ⇒ Object
Get the human readable name of a pixel format.
-
.release(pointer) ⇒ Object
SDL_FreeFormat, renamed ‘release’ to follow FFI paradigms.
-
.to_masks(format) ⇒ Object
Convert enumerated pixel value format to bpp & RGBA mask values TODO: Review why this is needed? Why not just read the Struct fields?.
Instance Method Summary collapse
-
#get_name ⇒ Object
Get the human readable name of this pixel format.
-
#get_rgb(pixel) ⇒ Object
Get the RGB components (array) from a pixel value.
-
#get_rgba(pixel) ⇒ Object
Get the RGBA components (array) from a pixel value.
-
#map(color) ⇒ Object
Maps a color struct to a pixel value.
-
#map_rgb(rgb) ⇒ Object
Maps an RGB triple (array) to an opaque pixel value.
-
#map_rgba(rgba) ⇒ Object
Maps an RGBA quadruple (array) to a pixel value.
-
#set_palette(palette) ⇒ Object
(also: #palette=)
Set the palette.
-
#to_masks ⇒ Object
TODO Review Redundancy: Basically return the masks you could read directly anyway?.
Methods inherited from Struct
#==, cast, #free, #initialize, #to_s, #update_members
Methods included from StructHelper
#member_readers, #member_writers
Constructor Details
This class inherits a constructor from SDL2::Struct
Class Method Details
.create(pixel_format) ⇒ Object
SDL_AllocFormat, renamed ‘create’ to follow ruby paradigms. Create an PixelFormat from the Enumerated format value.
66 67 68 |
# File 'lib/sdl2/pixel_format.rb', line 66 def self.create(pixel_format) SDL2.alloc_format!(pixel_format) end |
.get_name(pixel_format) ⇒ Object
Get the human readable name of a pixel format
38 39 40 |
# File 'lib/sdl2/pixel_format.rb', line 38 def self.get_name(pixel_format) SDL2.get_pixel_format_name(pixel_format) end |
.release(pointer) ⇒ Object
SDL_FreeFormat, renamed ‘release’ to follow FFI paradigms.
71 72 73 |
# File 'lib/sdl2/pixel_format.rb', line 71 def self.release(pointer) SDL2.free_format(pointer) end |
.to_masks(format) ⇒ Object
Convert enumerated pixel value format to bpp & RGBA mask values TODO: Review why this is needed? Why not just read the Struct fields?
49 50 51 52 53 54 55 56 57 |
# File 'lib/sdl2/pixel_format.rb', line 49 def self.to_masks(format) p = Hash.new(){TypedPointer::UInt32.new} p[:bpp] = TypedPointer::Int.new SDL2.pixel_format_enum_to_masks(format, p[:bpp], p[:Rmask], p[:Bmask],p[:Amask]) result = [] p.each_value{|s|result << s[:value]} p.each(&:free) return result end |
Instance Method Details
#get_name ⇒ Object
Get the human readable name of this pixel format
43 44 45 |
# File 'lib/sdl2/pixel_format.rb', line 43 def get_name self.class.get_name self.format end |
#get_rgb(pixel) ⇒ Object
Get the RGB components (array) from a pixel value
103 104 105 106 107 108 109 110 |
# File 'lib/sdl2/pixel_format.rb', line 103 def get_rgb(pixel) ptr = Hash.new(){TypedPointer::UInt8.new} SDL2.get_rgb(pixel, self, ptr[:r], ptr[:g], ptr[:b]) result = [] ptr.each_value{|s|result << s[:value]} ptr.each(&:free) return result end |
#get_rgba(pixel) ⇒ Object
Get the RGBA components (array) from a pixel value
113 114 115 116 117 118 119 120 |
# File 'lib/sdl2/pixel_format.rb', line 113 def get_rgba(pixel) ptr = Hash.new(){TypedPointer::UInt8.new} SDL2.get_rgba(pixel, self, ptr[:r], ptr[:g], ptr[:b], ptr[:a]) result = [] ptr.each_value{|s|result << s[:value]} ptr.each(&:free) return result end |
#map(color) ⇒ Object
Maps a color struct to a pixel value.
83 84 85 86 87 |
# File 'lib/sdl2/pixel_format.rb', line 83 def map(color) #binding.pry c = Color.cast(color) map_rgba(c.to_a) end |
#map_rgb(rgb) ⇒ Object
Maps an RGB triple (array) to an opaque pixel value
90 91 92 93 |
# File 'lib/sdl2/pixel_format.rb', line 90 def map_rgb(rgb) r, g, b = *rgb SDL2.map_rgb(self, r, g, b) end |
#map_rgba(rgba) ⇒ Object
Maps an RGBA quadruple (array) to a pixel value
96 97 98 99 100 |
# File 'lib/sdl2/pixel_format.rb', line 96 def map_rgba(rgba) r, g, b, a = rgba a = 0 if a.nil? SDL2.map_rgba(self, r, g, b, a) end |
#set_palette(palette) ⇒ Object Also known as: palette=
Set the palette
76 77 78 |
# File 'lib/sdl2/pixel_format.rb', line 76 def set_palette(palette) SDL2.set_pixel_format_palette(self, palette) end |
#to_masks ⇒ Object
TODO Review Redundancy: Basically return the masks you could read directly anyway?
60 61 62 |
# File 'lib/sdl2/pixel_format.rb', line 60 def to_masks() self.class.to_masks(self.format) end |