class RbSDL2::Surface::PixelFormat::PixelFormatPointer

Public Class Methods

==(other) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 34
def ==(other)
  other.respond_to?(:to_ptr) && to_ptr == other.to_ptr
end
alpha_mask?(= @st[:Amask] > 0) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 38
  def alpha_mask? = @st[:Amask] > 0

  def bits_per_pixel = @st[:BitsPerPixel]
  alias bpp bits_per_pixel

  def bytes_per_pixel = @st[:BytesPerPixel]

  def format = @st[:format]

  require_relative '../pixel_format_enum'
  include PixelFormatEnum

  # indexed format のときはパレット番号を戻す。
  def pack_color(color)
    r, g, b, a = color
    if alpha_mask?
      ::SDL2.SDL_MapRGBA(self, r, g, b, a || ::SDL2::SDL_ALPHA_OPAQUE)
    else
      ::SDL2.SDL_MapRGB(self, r, g, b)
    end
  end

  require_relative '../palette'

  def palette
    # パレットは参照カウンターで生存の保証がある。
    # Ruby 側がパレットを保持している限り同一アドレスに違うパレットが作成されることはない。
    # SDL では PixelFormat の palette メンバーは(行儀よく SDL_SetPixelFormatPalette を使う場合は)
    # 後から NULL に書き換わることはない。
    (ptr = @st[:palette]) == @palette&.to_ptr ? @palette : @palette = Palette.to_ptr(ptr)
  end

  def palette=(pal)
    err = ::SDL2.SDL_SetPixelFormatPalette(self, pal)
    raise RbSDL2Error if err < 0
    @palette = nil
  end

  def to_ptr = @st.to_ptr

  # indexed format のときはパレット番号を引数へ与える。
  def unpack_color(pixel)
    if alpha_mask?
      ::SDL2.SDL_GetRGBA(pixel, self, *Array.new(4) { ::FFI::MemoryPointer.new(:uint8) })
    else
      ::SDL2.SDL_GetRGB(pixel, self, *Array.new(3) { ::FFI::MemoryPointer.new(:uint8) })
    end
    color.map(&:read_uint8)
  end
end
bits_per_pixel(= @st[:BitsPerPixel]) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 40
    def bits_per_pixel = @st[:BitsPerPixel]
    alias bpp bits_per_pixel

    def bytes_per_pixel = @st[:BytesPerPixel]

    def format = @st[:format]

    require_relative '../pixel_format_enum'
    include PixelFormatEnum

    # indexed format のときはパレット番号を戻す。
    def pack_color(color)
      r, g, b, a = color
      if alpha_mask?
        ::SDL2.SDL_MapRGBA(self, r, g, b, a || ::SDL2::SDL_ALPHA_OPAQUE)
      else
        ::SDL2.SDL_MapRGB(self, r, g, b)
      end
    end

    require_relative '../palette'

    def palette
      # パレットは参照カウンターで生存の保証がある。
      # Ruby 側がパレットを保持している限り同一アドレスに違うパレットが作成されることはない。
      # SDL では PixelFormat の palette メンバーは(行儀よく SDL_SetPixelFormatPalette を使う場合は)
      # 後から NULL に書き換わることはない。
      (ptr = @st[:palette]) == @palette&.to_ptr ? @palette : @palette = Palette.to_ptr(ptr)
    end

    def palette=(pal)
      err = ::SDL2.SDL_SetPixelFormatPalette(self, pal)
      raise RbSDL2Error if err < 0
      @palette = nil
    end

    def to_ptr = @st.to_ptr

    # indexed format のときはパレット番号を引数へ与える。
    def unpack_color(pixel)
      if alpha_mask?
        ::SDL2.SDL_GetRGBA(pixel, self, *Array.new(4) { ::FFI::MemoryPointer.new(:uint8) })
      else
        ::SDL2.SDL_GetRGB(pixel, self, *Array.new(3) { ::FFI::MemoryPointer.new(:uint8) })
      end
      color.map(&:read_uint8)
    end
  end
end
bytes_per_pixel(= @st[:BytesPerPixel]) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 43
      def bytes_per_pixel = @st[:BytesPerPixel]

      def format = @st[:format]

      require_relative '../pixel_format_enum'
      include PixelFormatEnum

      # indexed format のときはパレット番号を戻す。
      def pack_color(color)
        r, g, b, a = color
        if alpha_mask?
          ::SDL2.SDL_MapRGBA(self, r, g, b, a || ::SDL2::SDL_ALPHA_OPAQUE)
        else
          ::SDL2.SDL_MapRGB(self, r, g, b)
        end
      end

      require_relative '../palette'

      def palette
        # パレットは参照カウンターで生存の保証がある。
        # Ruby 側がパレットを保持している限り同一アドレスに違うパレットが作成されることはない。
        # SDL では PixelFormat の palette メンバーは(行儀よく SDL_SetPixelFormatPalette を使う場合は)
        # 後から NULL に書き換わることはない。
        (ptr = @st[:palette]) == @palette&.to_ptr ? @palette : @palette = Palette.to_ptr(ptr)
      end

      def palette=(pal)
        err = ::SDL2.SDL_SetPixelFormatPalette(self, pal)
        raise RbSDL2Error if err < 0
        @palette = nil
      end

      def to_ptr = @st.to_ptr

      # indexed format のときはパレット番号を引数へ与える。
      def unpack_color(pixel)
        if alpha_mask?
          ::SDL2.SDL_GetRGBA(pixel, self, *Array.new(4) { ::FFI::MemoryPointer.new(:uint8) })
        else
          ::SDL2.SDL_GetRGB(pixel, self, *Array.new(3) { ::FFI::MemoryPointer.new(:uint8) })
        end
        color.map(&:read_uint8)
      end
    end
  end
end
entity_class(= ::SDL2::SDL_PixelFormat) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 10
  def entity_class = ::SDL2::SDL_PixelFormat
end
format(= @st[:format]) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 45
    def format = @st[:format]

    require_relative '../pixel_format_enum'
    include PixelFormatEnum

    # indexed format のときはパレット番号を戻す。
    def pack_color(color)
      r, g, b, a = color
      if alpha_mask?
        ::SDL2.SDL_MapRGBA(self, r, g, b, a || ::SDL2::SDL_ALPHA_OPAQUE)
      else
        ::SDL2.SDL_MapRGB(self, r, g, b)
      end
    end

    require_relative '../palette'

    def palette
      # パレットは参照カウンターで生存の保証がある。
      # Ruby 側がパレットを保持している限り同一アドレスに違うパレットが作成されることはない。
      # SDL では PixelFormat の palette メンバーは(行儀よく SDL_SetPixelFormatPalette を使う場合は)
      # 後から NULL に書き換わることはない。
      (ptr = @st[:palette]) == @palette&.to_ptr ? @palette : @palette = Palette.to_ptr(ptr)
    end

    def palette=(pal)
      err = ::SDL2.SDL_SetPixelFormatPalette(self, pal)
      raise RbSDL2Error if err < 0
      @palette = nil
    end

    def to_ptr = @st.to_ptr

    # indexed format のときはパレット番号を引数へ与える。
    def unpack_color(pixel)
      if alpha_mask?
        ::SDL2.SDL_GetRGBA(pixel, self, *Array.new(4) { ::FFI::MemoryPointer.new(:uint8) })
      else
        ::SDL2.SDL_GetRGB(pixel, self, *Array.new(3) { ::FFI::MemoryPointer.new(:uint8) })
      end
      color.map(&:read_uint8)
    end
  end
end
initialize(ptr) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 30
def initialize(ptr)
  @st = ::SDL2::SDL_PixelFormat.new(ptr)
end
new(format) click to toggle source
Calls superclass method
# File lib/rb_sdl2/surface/pixel_format.rb, line 17
def new(format)
  ptr = PixelFormatPointer.new(::SDL2::SDL_AllocFormat(PixelFormatEnum.to_num(format)))
  raise RbSDL2Error if ptr.null?
  super(ptr)
end
pack_color(color) click to toggle source

indexed format のときはパレット番号を戻す。

# File lib/rb_sdl2/surface/pixel_format.rb, line 51
def pack_color(color)
  r, g, b, a = color
  if alpha_mask?
    ::SDL2.SDL_MapRGBA(self, r, g, b, a || ::SDL2::SDL_ALPHA_OPAQUE)
  else
    ::SDL2.SDL_MapRGB(self, r, g, b)
  end
end
palette() click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 62
def palette
  # パレットは参照カウンターで生存の保証がある。
  # Ruby 側がパレットを保持している限り同一アドレスに違うパレットが作成されることはない。
  # SDL では PixelFormat の palette メンバーは(行儀よく SDL_SetPixelFormatPalette を使う場合は)
  # 後から NULL に書き換わることはない。
  (ptr = @st[:palette]) == @palette&.to_ptr ? @palette : @palette = Palette.to_ptr(ptr)
end
palette=(pal) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 70
def palette=(pal)
  err = ::SDL2.SDL_SetPixelFormatPalette(self, pal)
  raise RbSDL2Error if err < 0
  @palette = nil
end
release(ptr) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 8
    def release(ptr) = ::SDL2.SDL_FreeFormat(ptr)

    def entity_class = ::SDL2::SDL_PixelFormat
  end
end
to_ptr(ptr) click to toggle source
# File lib/rb_sdl2/surface/pixel_format.rb, line 23
def to_ptr(ptr)
  obj = allocate
  obj.__send__(:initialize, PixelFormatPointer.to_ptr(ptr))
  obj
end
unpack_color(pixel) click to toggle source

indexed format のときはパレット番号を引数へ与える。

# File lib/rb_sdl2/surface/pixel_format.rb, line 79
def unpack_color(pixel)
  if alpha_mask?
    ::SDL2.SDL_GetRGBA(pixel, self, *Array.new(4) { ::FFI::MemoryPointer.new(:uint8) })
  else
    ::SDL2.SDL_GetRGB(pixel, self, *Array.new(3) { ::FFI::MemoryPointer.new(:uint8) })
  end
  color.map(&:read_uint8)
end