Module: Mikunyan::DecodeHelper

Defined in:
lib/mikunyan/decoders.rb,
ext/decoders/native/main.c

Overview

Module for helper classes for decoding object

Class Method Summary collapse

Class Method Details

.decode_a8(rb_data, rb_size) ⇒ String

Decode image from A8 binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

Returns:

  • (String)

    decoded rgb binary



52
53
54
55
56
57
58
59
60
# File 'ext/decoders/native/main.c', line 52

static VALUE rb_decode_a8(VALUE self, VALUE rb_data, VALUE rb_size) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 1))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_a8((uint8_t *)RSTRING_PTR(rb_data), size, (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_astc(rb_data, rb_w, rb_h, rb_bw, rb_bh) ⇒ String

Decode image from ASTC compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

  • rb_bw (Integer)

    block width

  • rb_bh (Integer)

    block height

Returns:

  • (String)

    decoded rgba binary



329
330
331
332
333
334
335
336
337
338
339
# File 'ext/decoders/native/main.c', line 329

static VALUE rb_decode_astc(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h, VALUE rb_bw, VALUE rb_bh) {
    long w = FIX2LONG(rb_w);
    long h = FIX2LONG(rb_h);
    int bw = FIX2INT(rb_bw);
    int bh = FIX2INT(rb_bh);
    if (!check_str_len_block(rb_data, w, h, bw, bh, 16))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    DECODE_CHECK(decode_astc((uint8_t *)RSTRING_PTR(rb_data), w, h, bw, bh, (uint32_t *)RSTRING_PTR(ret)));
    return ret;
}

.decode_dxt1(rb_data, rb_w, rb_h) ⇒ String

Decode image from DXT1 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



349
350
351
352
353
354
355
356
357
# File 'ext/decoders/native/main.c', line 349

static VALUE rb_decode_dxt1(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w);
    long h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    DECODE_CHECK(decode_dxt1((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)));
    return ret;
}

.decode_dxt5(rb_data, rb_w, rb_h) ⇒ String

Decode image from DXT5 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



367
368
369
370
371
372
373
374
375
# File 'ext/decoders/native/main.c', line 367

static VALUE rb_decode_dxt5(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w);
    long h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 16))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    DECODE_CHECK(decode_dxt5((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)));
    return ret;
}

.decode_eacr(rb_data, rb_w, rb_h) ⇒ String

Decode image from EAC R11 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



255
256
257
258
259
260
261
262
263
# File 'ext/decoders/native/main.c', line 255

static VALUE rb_decode_eacr(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_eacr((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_eacrg(rb_data, rb_w, rb_h) ⇒ String

Decode image from EAC RG11 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



291
292
293
294
295
296
297
298
299
# File 'ext/decoders/native/main.c', line 291

static VALUE rb_decode_eacrg(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 16))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_eacrg((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_eacsr(rb_data, rb_w, rb_h) ⇒ String

Decode image from EAC Signed R11 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



273
274
275
276
277
278
279
280
281
# File 'ext/decoders/native/main.c', line 273

static VALUE rb_decode_eacsr(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_eacr_signed((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_eacsrg(rb_data, rb_w, rb_h) ⇒ String

Decode image from EAC RG11 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



309
310
311
312
313
314
315
316
317
# File 'ext/decoders/native/main.c', line 309

static VALUE rb_decode_eacsrg(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 16))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_eacrg_signed((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_etc1(rb_data, rb_w, rb_h) ⇒ String

Decode image from ETC1 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



183
184
185
186
187
188
189
190
191
# File 'ext/decoders/native/main.c', line 183

static VALUE rb_decode_etc1(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_etc1((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_etc2(rb_data, rb_w, rb_h) ⇒ String

Decode image from ETC2 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



201
202
203
204
205
206
207
208
209
# File 'ext/decoders/native/main.c', line 201

static VALUE rb_decode_etc2(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_etc2((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_etc2a1(rb_data, rb_w, rb_h) ⇒ String

Decode image from ETC2 Alpha1 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



219
220
221
222
223
224
225
226
227
# File 'ext/decoders/native/main.c', line 219

static VALUE rb_decode_etc2a1(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_etc2a1((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_etc2a8(rb_data, rb_w, rb_h) ⇒ String

Decode image from ETC2 Alpha8 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

Returns:

  • (String)

    decoded rgba binary



237
238
239
240
241
242
243
244
245
# File 'ext/decoders/native/main.c', line 237

static VALUE rb_decode_etc2a8(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h) {
    long w = FIX2LONG(rb_w), h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, 4, 4, 16))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    if (!decode_etc2a8((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_pvrtc1(rb_data, rb_w, rb_h, rb_is2bpp) ⇒ String

Decode image from PVRTC1 compressed binary

Parameters:

  • rb_data (String)

    binary to decode

  • rb_w (Integer)

    image width

  • rb_h (Integer)

    image height

  • rb_is2bpp (Boolean)

    whether 2bpp or not (4bpp)

Returns:

  • (String)

    decoded rgba binary



386
387
388
389
390
391
392
393
394
395
# File 'ext/decoders/native/main.c', line 386

static VALUE rb_decode_pvrtc1(VALUE self, VALUE rb_data, VALUE rb_w, VALUE rb_h, VALUE rb_is2bpp) {
    int is2bpp = RTEST(rb_is2bpp);
    long w = FIX2LONG(rb_w);
    long h = FIX2LONG(rb_h);
    if (!check_str_len_block(rb_data, w, h, is2bpp ? 8 : 4, 4, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(w * h);
    DECODE_CHECK(decode_pvrtc((uint8_t *)RSTRING_PTR(rb_data), w, h, (uint32_t *)RSTRING_PTR(ret), is2bpp));
    return ret;
}

.decode_r16(rb_data, rb_size, rb_big) ⇒ String

Decode image from R16 binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

  • rb_big (Boolean)

    whether input data are big endian

Returns:

  • (String)

    decoded rgb binary



89
90
91
92
93
94
95
96
97
# File 'ext/decoders/native/main.c', line 89

static VALUE rb_decode_r16(VALUE self, VALUE rb_data, VALUE rb_size, VALUE rb_big) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 2))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_r16((uint8_t *)RSTRING_PTR(rb_data), size, RTEST(rb_big), (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_r8(rb_data, rb_size) ⇒ String

Decode image from R8 binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

Returns:

  • (String)

    decoded rgb binary



70
71
72
73
74
75
76
77
78
# File 'ext/decoders/native/main.c', line 70

static VALUE rb_decode_r8(VALUE self, VALUE rb_data, VALUE rb_size) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 1))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_r8((uint8_t *)RSTRING_PTR(rb_data), size, (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_rgb565(rb_data, rb_size, rb_big) ⇒ String

Decode image from RGB565 binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

  • rb_big (Boolean)

    whether input data are big endian

Returns:

  • (String)

    decoded rgb binary



108
109
110
111
112
113
114
115
116
# File 'ext/decoders/native/main.c', line 108

static VALUE rb_decode_rgb565(VALUE self, VALUE rb_data, VALUE rb_size, VALUE rb_big) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 2))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_rgb565((uint16_t *)RSTRING_PTR(rb_data), size, RTEST(rb_big), (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_rgbahalf(rb_data, rb_size, rb_big) ⇒ String

Decode image from RGBAHalf binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

  • rb_big (Boolean)

    whether input data are big endian

Returns:

  • (String)

    decoded rgba binary



165
166
167
168
169
170
171
172
173
# File 'ext/decoders/native/main.c', line 165

static VALUE rb_decode_rgbahalf(VALUE self, VALUE rb_data, VALUE rb_size, VALUE rb_big) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 8))
        return Qnil;
    VALUE ret = rb_alloc_rgba(size);
    if (!decode_rgbahalf((uint16_t *)RSTRING_PTR(rb_data), size, RTEST(rb_big), (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_rghalf(rb_data, rb_size, rb_big) ⇒ String

Decode image from RGHalf binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

  • rb_big (Boolean)

    whether input data are big endian

Returns:

  • (String)

    decoded rgb binary



146
147
148
149
150
151
152
153
154
# File 'ext/decoders/native/main.c', line 146

static VALUE rb_decode_rghalf(VALUE self, VALUE rb_data, VALUE rb_size, VALUE rb_big) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 4))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_rghalf((uint16_t *)RSTRING_PTR(rb_data), size, RTEST(rb_big), (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}

.decode_rhalf(rb_data, rb_size, rb_big) ⇒ String

Decode image from RHalf binary Returned image is not flipped

Parameters:

  • rb_data (String)

    binary to decode

  • rb_size (Integer)

    width * height

  • rb_big (Boolean)

    whether input data are big endian

Returns:

  • (String)

    decoded rgb binary



127
128
129
130
131
132
133
134
135
# File 'ext/decoders/native/main.c', line 127

static VALUE rb_decode_rhalf(VALUE self, VALUE rb_data, VALUE rb_size, VALUE rb_big) {
    long size = FIX2LONG(rb_size);
    if (!check_str_len(rb_data, size, 2))
        return Qnil;
    VALUE ret = rb_alloc_rgb(size);
    if (!decode_rhalf((uint16_t *)RSTRING_PTR(rb_data), size, RTEST(rb_big), (uint8_t *)RSTRING_PTR(ret)))
        return Qnil;
    return ret;
}