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

create(pixel_format) click to toggle source

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_name(pixel_format) click to toggle source

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
release(pointer) click to toggle source

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
to_masks(format) click to toggle source

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_name() click to toggle source

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_rgb(pixel) click to toggle source

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_rgba(pixel) click to toggle source

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
map(color) click to toggle source

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
map_rgb(rgb) click to toggle source

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
map_rgba(rgba) click to toggle source

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
palette=(palette)
Alias for: set_palette
set_palette(palette) click to toggle source

Set the palette

# File lib/sdl2/pixel_format.rb, line 76
def set_palette(palette)
  SDL2.set_pixel_format_palette(self, palette)
end
Also aliased as: palette=
to_masks() click to toggle source

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