module RbSDL2::PixelFormatEnum

Constants

ARRAY_ORDERS
ARRAY_TYPES
FORMAT_MAP
INDEXED_TYPES
PACKED_ORDERS
PACKED_TYPES

Public Class Methods

array_type?(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 24
  def array_type?(num) = !fourcc?(num) && ARRAY_TYPES.include?(to_type(num))

  def fourcc?(num) = (num >> 28) & 0x0F != 1

  def indexed_type?(num) = !fourcc?(num) && INDEXED_TYPES.include?(to_type(num))

  def packed_type?(num) = !fourcc?(num) && PACKED_TYPES.include?(to_type(num))

  def to_fourcc(num)
    4.times.inject([]) { |n, i| n << (num >> i * 8) % 0x100 }.pack("c4") if fourcc?
  end

  def to_name(num) = ::SDL2.SDL_GetPixelFormatName(num).read_string

  # obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。
  # 定数名は RGBA32 のような短縮した名前でもよい。"UNKNOWN" も受け取れる(値は 0)。
  # 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。
  # SDL はオリジナルのフォーマットを処理しないことに注意。
  def to_num(obj)
    name = if Symbol === obj || String === obj
             obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
           else
             to_name(obj)
           end
    FORMAT_MAP[name.to_sym].to_i
  end

  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)
format_name(= PixelFormatEnum.to_name(format)) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 65
def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def rgba? = PixelFormatEnum.with_alpha?(format)
fourcc(= PixelFormatEnum.to_fourcc(format)) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 61
def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def rgba? = PixelFormatEnum.with_alpha?
fourcc?(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 26
  def fourcc?(num) = (num >> 28) & 0x0F != 1

  def indexed_type?(num) = !fourcc?(num) && INDEXED_TYPES.include?(to_type(num))

  def packed_type?(num) = !fourcc?(num) && PACKED_TYPES.include?(to_type(num))

  def to_fourcc(num)
    4.times.inject([]) { |n, i| n << (num >> i * 8) % 0x100 }.pack("c4") if fourcc?
  end

  def to_name(num) = ::SDL2.SDL_GetPixelFormatName(num).read_string

  # obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。
  # 定数名は RGBA32 のような短縮した名前でもよい。"UNKNOWN" も受け取れる(値は 0)。
  # 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。
  # SDL はオリジナルのフォーマットを処理しないことに注意。
  def to_num(obj)
    name = if Symbol === obj || String === obj
             obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
           else
             to_name(obj)
           end
    FORMAT_MAP[name.to_sym].to_i
  end

  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

indexed_color?(= PixelFormatEnum.indexed_type?(format)) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 67
  def indexed_color? = PixelFormatEnum.indexed_type?(format)

  def rgb? = !(fourcc? || indexed_color? || rgba?)

  def rgba? = PixelFormatEnum.with_alpha?(format)
end
indexed_type?(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 28
  def indexed_type?(num) = !fourcc?(num) && INDEXED_TYPES.include?(to_type(num))

  def packed_type?(num) = !fourcc?(num) && PACKED_TYPES.include?(to_type(num))

  def to_fourcc(num)
    4.times.inject([]) { |n, i| n << (num >> i * 8) % 0x100 }.pack("c4") if fourcc?
  end

  def to_name(num) = ::SDL2.SDL_GetPixelFormatName(num).read_string

  # obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。
  # 定数名は RGBA32 のような短縮した名前でもよい。"UNKNOWN" も受け取れる(値は 0)。
  # 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。
  # SDL はオリジナルのフォーマットを処理しないことに注意。
  def to_num(obj)
    name = if Symbol === obj || String === obj
             obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
           else
             to_name(obj)
           end
    FORMAT_MAP[name.to_sym].to_i
  end

  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def
packed_type?(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 30
  def packed_type?(num) = !fourcc?(num) && PACKED_TYPES.include?(to_type(num))

  def to_fourcc(num)
    4.times.inject([]) { |n, i| n << (num >> i * 8) % 0x100 }.pack("c4") if fourcc?
  end

  def to_name(num) = ::SDL2.SDL_GetPixelFormatName(num).read_string

  # obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。
  # 定数名は RGBA32 のような短縮した名前でもよい。"UNKNOWN" も受け取れる(値は 0)。
  # 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。
  # SDL はオリジナルのフォーマットを処理しないことに注意。
  def to_num(obj)
    name = if Symbol === obj || String === obj
             obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
           else
             to_name(obj)
           end
    FORMAT_MAP[name.to_sym].to_i
  end

  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def rgba?
rgb?(= !(fourcc? || indexed_color? || rgba?)) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 69
    def rgb? = !(fourcc? || indexed_color? || rgba?)

    def rgba? = PixelFormatEnum.with_alpha?(format)
  end
end
rgba?(= PixelFormatEnum.with_alpha?(format)) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 71
  def rgba? = PixelFormatEnum.with_alpha?(format)
end
to_fourcc(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 32
def to_fourcc(num)
  4.times.inject([]) { |n, i| n << (num >> i * 8) % 0x100 }.pack("c4") if fourcc?
end
to_name(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 36
  def to_name(num) = ::SDL2.SDL_GetPixelFormatName(num).read_string

  # obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。
  # 定数名は RGBA32 のような短縮した名前でもよい。"UNKNOWN" も受け取れる(値は 0)。
  # 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。
  # SDL はオリジナルのフォーマットを処理しないことに注意。
  def to_num(obj)
    name = if Symbol === obj || String === obj
             obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
           else
             to_name(obj)
           end
    FORMAT_MAP[name.to_sym].to_i
  end

  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def rgba? =
to_num(obj) click to toggle source

obj は SDL の SDL_PIXELFORMAT_* 定数のどれか、または定数名でもよい。 定数名は RGBA32 のような短縮した名前でもよい。“UNKNOWN” も受け取れる(値は 0)。 該当するフォーマットがない場合は 0 (SDL_PIXELFORMAT_UNKNOWN) を戻す。 SDL はオリジナルのフォーマットを処理しないことに注意。

# File lib/rb_sdl2/pixel_format_enum.rb, line 42
def to_num(obj)
  name = if Symbol === obj || String === obj
           obj.match?(/\ASDL_PIXELFORMAT_/) ? obj : "SDL_PIXELFORMAT_#{obj.upcase}"
         else
           to_name(obj)
         end
  FORMAT_MAP[name.to_sym].to_i
end
to_order(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 51
  def to_order(num) = fourcc?(num) ? 0 : (num >> 20) & 0x0F

  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end

def fourcc = PixelFormatEnum.to_fourcc(format)

def fourcc? = PixelFormatEnum.fourcc?(format)

def format_name = PixelFormatEnum.to_name(format)

def indexed_color? = PixelFormatEnum.indexed_type?(format)

def rgb? = !(fourcc? || indexed_color? || rgba?)

def rgba? = PixelFormatEnum
to_type(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 53
  def to_type(num) = fourcc?(num) ? 0 : (num >> 24) & 0x0F

  def with_alpha?(num)
    packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
      array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
  end
end
with_alpha?(num) click to toggle source
# File lib/rb_sdl2/pixel_format_enum.rb, line 55
def with_alpha?(num)
  packed_type?(num) && PACKED_ORDERS.include?(to_order(num)) ||
    array_type?(num) && ARRAY_ORDERS.include?(to_order(num))
end