class SDL2::PixelFormat
SDL_pixels.h:272~293:typdef struct SDL_PixelFormat note Everything in the pixel format structure is read-only.
Public Class Methods
SDL_AllocFormat, renamed ‘create’ to follow ruby paradigms. Create an PixelFormat
from the Enumerated format value.
# File lib/sdl2/pixel_format.rb, line 66 def self.create(pixel_format) SDL2.alloc_format!(pixel_format) end
Get the human readable name of a pixel format
# File lib/sdl2/pixel_format.rb, line 38 def self.get_name(pixel_format) SDL2.get_pixel_format_name(pixel_format) end
SDL_FreeFormat, renamed ‘release’ to follow FFI
paradigms.
# File lib/sdl2/pixel_format.rb, line 71 def self.release(pointer) SDL2.free_format(pointer) end
Convert enumerated pixel value format to bpp & RGBA mask values TODO: Review why this is needed? Why not just read the Struct
fields?
# 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
Public Instance Methods
Get the human readable name of this pixel format
# File lib/sdl2/pixel_format.rb, line 43 def get_name self.class.get_name self.format end
Get the RGB components (array) from a pixel value
# 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 the RGBA components (array) from a pixel value
# 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
Maps a color struct to a pixel value.
# File lib/sdl2/pixel_format.rb, line 83 def map(color) #binding.pry c = Color.cast(color) map_rgba(c.to_a) end
Maps an RGB triple (array) to an opaque pixel value
# File lib/sdl2/pixel_format.rb, line 90 def map_rgb(rgb) r, g, b = *rgb SDL2.map_rgb(self, r, g, b) end
Maps an RGBA quadruple (array) to a pixel value
# 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 the palette
# File lib/sdl2/pixel_format.rb, line 76 def set_palette(palette) SDL2.set_pixel_format_palette(self, palette) end
TODO Review Redundancy: Basically return the masks you could read directly anyway?
# File lib/sdl2/pixel_format.rb, line 60 def to_masks() self.class.to_masks(self.format) end