Class: SDL2::PixelFormat

Inherits:
Object
  • Object
show all
Defined in:
video.c,
video.c

Overview

This class represents pixel format of textures, windows, and displays.

In C level, SDL use unsigned integers as pixel formats. This class wraps these integers. You can get the integers from #format.

Defined Under Namespace

Modules: ArrayOrder, BitmapOrder, PackedLayout, PackedOrder, Type

Constant Summary collapse

FORMATS =

Returns array of all available formats.

Returns:

-
UNKNOWN =

Returns Unused - reserved by SDL.

Returns:

-
INDEX1LSB =

Returns:

-
INDEX1MSB =

Returns:

-
INDEX4LSB =

Returns:

-
INDEX4MSB =

Returns:

-
INDEX8 =

Returns:

-
RGB332 =

Returns:

-
RGB444 =

Returns:

-
RGB555 =

Returns:

-
BGR555 =

Returns:

-
ARGB4444 =

Returns:

-
RGBA4444 =

Returns:

-
ABGR4444 =

Returns:

-
BGRA4444 =

Returns:

-
ARGB1555 =

Returns:

-
RGBA5551 =

Returns:

-
ABGR1555 =

Returns:

-
BGRA5551 =

Returns:

-
RGB565 =

Returns:

-
BGR565 =

Returns:

-
RGB24 =

Returns:

-
BGR24 =

Returns:

-
RGB888 =

Returns:

-
RGBX8888 =

Returns:

-
BGR888 =

Returns:

-
BGRX8888 =

Returns:

-
ARGB8888 =

Returns:

-
RGBA8888 =

Returns:

-
ABGR8888 =

Returns:

-
BGRA8888 =

Returns:

-
ARGB2101010 =

Returns:

-
YV12 =

Returns:

-
IYUV =

Returns:

-
YUY2 =

Returns:

-
UYVY =

Returns:

-
YVYU =

Returns:

-

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialze(format) ⇒ Object

Initialize pixel format from the given integer representing a fomrmat.

Parameters:

  • format (Integer)

    an unsigned integer as a pixel formats



2728
2729
2730
2731
2732
# File 'video.c', line 2728

static VALUE PixelForamt_initialize(VALUE self, VALUE format)
{
    rb_iv_set(self, "@format", format);
    return Qnil;
}

Instance Attribute Details

#formatInteger (readonly)

An integer representing the pixel format.

Returns:

  • (Integer)

Instance Method Details

#==(other) ⇒ Boolean

Return true if two pixel format is the same format.

Parameters:

Returns:

  • (Boolean)


2831
2832
2833
2834
2835
2836
2837
# File 'video.c', line 2831

static VALUE PixelFormat_eq(VALUE self, VALUE other)
{
    if (!rb_obj_is_kind_of(other, cPixelFormat))
        return Qfalse;

    return INT2BOOL(rb_iv_get(self, "@format") == rb_iv_get(other, "@format"));
}

#alpha?Boolean

Return true if the pixel format have an alpha channel.

Returns:

  • (Boolean)


2809
2810
2811
2812
# File 'video.c', line 2809

static VALUE PixelFormat_alpha_p(VALUE self)
{
    return INT2BOOL(SDL_ISPIXELFORMAT_ALPHA(NUM2UINT(rb_iv_get(self, "@format"))));
};

#bits_per_pixelInteger Also known as: bpp

Get the number of bits per pixel.

Returns:

  • (Integer)


2783
2784
2785
2786
# File 'video.c', line 2783

static VALUE PixelFormat_bits_per_pixel(VALUE self)
{
    return INT2NUM(SDL_BITSPERPIXEL(NUM2UINT(rb_iv_get(self, "@format"))));
};

#bytes_per_pixelInteger

Get the number of bytes per pixel.

Returns:

  • (Integer)


2793
2794
2795
2796
# File 'video.c', line 2793

static VALUE PixelFormat_bytes_per_pixel(VALUE self)
{
    return INT2NUM(SDL_BYTESPERPIXEL(NUM2UINT(rb_iv_get(self, "@format"))));
};

#fourcc?Boolean

Return true if the pixel format is not indexed, and not RGB(A), for example, the pixel format is YUV.

Returns:

  • (Boolean)


2818
2819
2820
2821
# File 'video.c', line 2818

static VALUE PixelFormat_fourcc_p(VALUE self)
{
    return INT2BOOL(SDL_ISPIXELFORMAT_FOURCC(NUM2UINT(rb_iv_get(self, "@format"))));
};

#indexed?Boolean

Return true if the pixel format have a palette.

Returns:

  • (Boolean)


2801
2802
2803
2804
# File 'video.c', line 2801

static VALUE PixelFormat_indexed_p(VALUE self)
{
    return INT2BOOL(SDL_ISPIXELFORMAT_INDEXED(NUM2UINT(rb_iv_get(self, "@format"))));
};

#inspectString

Returns inspection string.

Returns:

  • (String)

    inspection string



2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
# File 'video.c', line 2840

static VALUE PixelFormat_inspect(VALUE self)
{
    Uint32 format = NUM2UINT(rb_iv_get(self, "@format"));
    return rb_sprintf("<%s: %s type=%d order=%d layout=%d"
                      " bits=%d bytes=%d indexed=%s alpha=%s fourcc=%s>",
                      rb_obj_classname(self),
                      SDL_GetPixelFormatName(format),
                      SDL_PIXELTYPE(format), SDL_PIXELORDER(format), SDL_PIXELLAYOUT(format),
                      SDL_BITSPERPIXEL(format), SDL_BYTESPERPIXEL(format),
                      INT2BOOLCSTR(SDL_ISPIXELFORMAT_INDEXED(format)),
                      INT2BOOLCSTR(SDL_ISPIXELFORMAT_ALPHA(format)),
                      INT2BOOLCSTR(SDL_ISPIXELFORMAT_FOURCC(format)));
}

#layoutInteger

Get the channel bit pattern of the pixel format.

Returns:

  • (Integer)

    One of the constants of PackedLayout module.



2773
2774
2775
2776
# File 'video.c', line 2773

static VALUE PixelFormat_layout(VALUE self)
{
    return UINT2NUM(SDL_PIXELLAYOUT(NUM2UINT(rb_iv_get(self, "@format"))));
};

#nameString

Get the human readable name of the pixel format

Returns:

  • (String)


2753
2754
2755
2756
# File 'video.c', line 2753

static VALUE PixelFormat_name(VALUE self)
{
    return utf8str_new_cstr(SDL_GetPixelFormatName(NUM2UINT(rb_iv_get(self, "@format"))));
};

#orderInteger

Get the ordering of channels or bits in the pixel format.

Returns:



2763
2764
2765
2766
# File 'video.c', line 2763

static VALUE PixelFormat_order(VALUE self)
{
    return UINT2NUM(SDL_PIXELORDER(NUM2UINT(rb_iv_get(self, "@format"))));
};

#typeInteger

Get the type of the format.

Returns:

  • (Integer)

    One of the constants of Type module.



2739
2740
2741
2742
# File 'video.c', line 2739

static VALUE PixelFormat_type(VALUE self)
{
    return UINT2NUM(SDL_PIXELTYPE(NUM2UINT(rb_iv_get(self, "@format"))));
}