Class: PNG::Decoder

Inherits:
Object
  • Object
show all
Defined in:
ext/png/png.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'ext/png/png.c', line 752

static VALUE
rb_decoder_initialize(int argc, VALUE* argv, VALUE self)
{
  png_decoder_t* ptr;
  VALUE opt;

  /*
   * strip object
   */
  Data_Get_Struct(self, png_decoder_t, ptr);

  /*
   * parse argument
   */
  rb_scan_args(argc, argv, "01", &opt);
  if (opt != Qnil) Check_Type(opt, T_HASH);

  /*
   * set context
   */
  set_decoder_context(ptr, opt);

  return Qtrue;
}

Instance Method Details

#decode(data) ⇒ Object Also known as: decompress, <<



1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'ext/png/png.c', line 1410

static VALUE
rb_decoder_decode(VALUE self, VALUE data)
{
  VALUE ret;
  png_decoder_t* ptr;
  decode_arg_t arg;

  /*
   * argument check
   */
  Check_Type(data, T_STRING);

  /*
   * strip object
   */
  Data_Get_Struct(self, png_decoder_t, ptr);

  /*
   * call decode funcs
   */
  arg.ptr  = ptr;
  arg.data = data;

  if (ptr->common.api_type == API_SIMPLIFIED) {
    ret = rb_ensure(decode_simplified_api_body, (VALUE)&arg,
                    decode_simplified_api_ensure, (VALUE)ptr);

  } else {
    ret = rb_ensure(decode_classic_api_body, (VALUE)&arg,
                    decode_classic_api_ensure, (VALUE)ptr);
  }

  return ret;
}

#read_header(data) ⇒ Object



1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
# File 'ext/png/png.c', line 1181

static VALUE
rb_decoder_read_header(VALUE self, VALUE data)
{
  VALUE ret;
  png_decoder_t* ptr;
  read_header_arg_t arg;

  /*
   * argument check
   */
  Check_Type(data, T_STRING);

  if (RSTRING_LEN(data) < 8) {
    RUNTIME_ERROR("data too short.");
  }

  if (png_sig_cmp((png_const_bytep)RSTRING_PTR(data), 0, 8)) {
    RUNTIME_ERROR("Invalid PNG signature.");
  }

  /*
   * strip object
   */
  Data_Get_Struct(self, png_decoder_t, ptr);

  /*
   * call read header funciton
   */
  arg.ptr  = ptr;
  arg.data = data;

  ret = rb_ensure(read_header_body, (VALUE)&arg,
                  read_header_ensure, (VALUE)ptr);

  return ret;
}