Class: SDL2::PixelFormat

Inherits:
FFI::Struct
  • Object
show all
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

Instance Method Summary collapse

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(){UInt32Struct.new}
  p[:bpp] = IntStruct.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_nameObject

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



95
96
97
98
99
100
101
102
# File 'lib/sdl2/pixel_format.rb', line 95

def get_rgb(pixel)
  ptr = Hash.new(){UInt8Struct.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



105
106
107
108
109
110
111
112
# File 'lib/sdl2/pixel_format.rb', line 105

def get_rgba(pixel)
  ptr = Hash.new(){UInt8Struct.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_rgb(rgb) ⇒ Object

Maps an RGB triple (array) to an opaque pixel value



83
84
85
86
# File 'lib/sdl2/pixel_format.rb', line 83

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



89
90
91
92
# File 'lib/sdl2/pixel_format.rb', line 89

def map_rgba(rgba)
  r, g, b, a = *rgba
  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_masksObject

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