Class: SDL2::PixelFormat

Inherits:
Object
  • Object
show all
Defined in:
ext/sdl2_ext/video.c,
ext/sdl2_ext/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 =

Array of all available formats

-
UNKNOWN =

PixelFormat: Unused - reserved by SDL

-
INDEX1LSB =
format
INDEX1MSB =
format
INDEX4LSB =
format
INDEX4MSB =
format
INDEX8 =
format
RGB332 =
format
RGB444 =
format
RGB555 =
format
BGR555 =
format
ARGB4444 =
format
RGBA4444 =
format
ABGR4444 =
format
BGRA4444 =
format
ARGB1555 =
format
RGBA5551 =
format
ABGR1555 =
format
BGRA5551 =
format
RGB565 =
format
BGR565 =
format
RGB24 =
format
BGR24 =
format
RGB888 =
format
RGBX8888 =
format
BGR888 =
format
BGRX8888 =
format
ARGB8888 =
format
RGBA8888 =
format
ABGR8888 =
format
BGRA8888 =
format
ARGB2101010 =
format
YV12 =
format
IYUV =
format
YUY2 =
format
UYVY =
format
YVYU =
format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format) ⇒ Object

Initialize pixel format from the given integer representing a fomrmat.

Parameters:

  • format (Integer)

    an unsigned integer as a pixel formats



3193
3194
3195
3196
3197
# File 'ext/sdl2_ext/video.c', line 3193

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.

Returns:

  • (Boolean)


3294
3295
3296
3297
3298
3299
3300
# File 'ext/sdl2_ext/video.c', line 3294

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)


3274
3275
3276
3277
# File 'ext/sdl2_ext/video.c', line 3274

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)


3248
3249
3250
3251
# File 'ext/sdl2_ext/video.c', line 3248

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)


3258
3259
3260
3261
# File 'ext/sdl2_ext/video.c', line 3258

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)


3283
3284
3285
3286
# File 'ext/sdl2_ext/video.c', line 3283

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)


3266
3267
3268
3269
# File 'ext/sdl2_ext/video.c', line 3266

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



3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
# File 'ext/sdl2_ext/video.c', line 3303

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.



3238
3239
3240
3241
# File 'ext/sdl2_ext/video.c', line 3238

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)


3218
3219
3220
3221
# File 'ext/sdl2_ext/video.c', line 3218

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:



3228
3229
3230
3231
# File 'ext/sdl2_ext/video.c', line 3228

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.



3204
3205
3206
3207
# File 'ext/sdl2_ext/video.c', line 3204

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