Class: RbSDL2::Surface::PixelFormat
- Inherits:
-
Object
- Object
- RbSDL2::Surface::PixelFormat
show all
- Includes:
- PixelFormatEnum
- Defined in:
- lib/rb_sdl2/surface/pixel_format.rb
Defined Under Namespace
Classes: PixelFormatPointer
Constant Summary
PixelFormatEnum::FORMAT_MAP, PixelFormatEnum::INDEXED_TYPES, PixelFormatEnum::WITH_ALPHA
Instance Method Summary
collapse
#format_name, #fourcc, #fourcc?, #indexed_color?, #rgb?, #rgba?, to_name, to_num
Constructor Details
Returns a new instance of PixelFormat.
19
20
21
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 19
def initialize(ptr)
@st = ::SDL::PixelFormat.new(PixelFormatPointer.to_ptr(ptr))
end
|
Instance Method Details
#==(other) ⇒ Object
23
24
25
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 23
def ==(other)
other.respond_to?(:to_ptr) && other.to_ptr == to_ptr
end
|
#a_mask ⇒ Object
27
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 27
def a_mask = @st[:Amask]
|
#a_mask? ⇒ Boolean
35
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 35
def a_mask? = @st[:Amask] > 0
|
#b_mask ⇒ Object
29
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 29
def b_mask = @st[:Bmask]
|
#bits_per_pixel ⇒ Object
Also known as:
bpp
37
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 37
def bits_per_pixel = @st[:BitsPerPixel]
|
#bytes_per_pixel ⇒ Object
40
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 40
def bytes_per_pixel = @st[:BytesPerPixel]
|
42
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 42
def format = @st[:format]
|
#g_mask ⇒ Object
31
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 31
def g_mask = @st[:Gmask]
|
#pack_color(color) ⇒ Object
indexed format のときはパレット番号を戻す。
48
49
50
51
52
53
54
55
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 48
def pack_color(color)
r, g, b, a = color
if a_mask?
::SDL.MapRGBA(self, r, g, b, a || ::SDL::ALPHA_OPAQUE)
else
::SDL.MapRGB(self, r, g, b)
end
end
|
#palette ⇒ Object
パレットがある場合は Palette インスタンスを戻します。ない場合は nil を戻します。
60
61
62
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 60
def palette
Palette.to_ptr(@st[:palette]) unless @st[:palette].null?
end
|
#palette=(pal) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 64
def palette=(pal)
if Palette === pal && !pal.to_ptr.null?
err = ::SDL.SetPixelFormatPalette(self, pal)
raise RbSDL2Error if err < 0
else
raise ArgumentError, "pointer is NULL"
end
end
|
#palette? ⇒ Boolean
74
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 74
def palette? = !@st[:palette].null?
|
#r_mask ⇒ Object
33
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 33
def r_mask = @st[:Rmask]
|
#to_ptr ⇒ Object
76
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 76
def to_ptr = @st.to_ptr
|
#unpack_pixel(num) ⇒ Object
indexed format のときはパレット番号を引数へ与える。
79
80
81
82
83
84
85
86
87
|
# File 'lib/rb_sdl2/surface/pixel_format.rb', line 79
def unpack_pixel(num)
color = Array.new(a_mask? ? 4 : 3) { ::FFI::MemoryPointer.new(:uint8) }
if a_mask?
::SDL.GetRGBA(num, self, *color)
else
::SDL.GetRGB(num, self, *color)
end
color.map(&:read_uint8)
end
|