Class: PNG::Decoder

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
# File 'ext/png/png.c', line 1345

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

  /*
   * initialize
   */
  exc = Qnil;

  /*
   * strip object
   */
  TypedData_Get_Struct(self, png_decoder_t, &png_decoder_data_type, ptr);

  /*
   * parse argument
   */
  rb_scan_args(argc, argv, "0:", &opts);

  /*
   * set context
   */
  exc = set_decoder_context(ptr, opts);

  /*
   * post process
   */
  if (RTEST(exc)) rb_exc_raise(exc);

  return Qtrue;
}

Instance Method Details

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



2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
# File 'ext/png/png.c', line 2064

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);

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

  /*
   * strip object
   */
  TypedData_Get_Struct(self, png_decoder_t, &png_decoder_data_type, 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



1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
# File 'ext/png/png.c', line 1830

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
   */
  TypedData_Get_Struct(self, png_decoder_t, &png_decoder_data_type, 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;
}