Class: JPEG::Decoder

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Object

initialize decoder object

Parameters:

  • opts (Hash)

    options to initialize object

Options Hash (opts):

  • :pixel_format (Symbol)

    specifies the format of the output image. possible values are: YUV422 YUYV RGB565 RGB RGB24 BGR BGR24 YUV444 YCbCr RGBX RGB32 BGRX BGR32 GRAYSCALE

  • :output_gamma (Float)
  • :fancy_upsampling (Boolean)
  • :do_smoothing (Boolean)
  • :dither (Array)

    specifies dithering parameters. A 3-elements array. specify the dither type as a string for the 1st element, whether to use 2-pass quantize for the 2nd element as a boolean, and the number of colors used for the 3rd element as an integer from 16 to 256.

  • :without_meta (Boolean)

    specifies whether or not to include meta information in the output data. If true, no meta-information is output.

  • :expand_colormap (Boolean)

    specifies whether to expand the color map. If dither is specified, the output will be a color number of 1 byte per pixel, but if this option is set to true, the output will be expanded to color information.

  • :scale (Ratioanl)
  • :dct_method (Symbol)

    specifies how decoding is handled. possible values are: FASTEST ISLOW IFAST FLOAT

  • :with_exif_tags (Boolean)

    specifies whether to include Exif tag information in the output data. set this option to true to parse the Exif tag information and include it in the meta information output.

  • :with_exif (Boolean)

    alias to :with_exif_tags option.



2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
# File 'ext/jpeg/jpeg.c', line 2001

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

  /*
   * initialize
   */
  TypedData_Get_Struct(self, jpeg_decode_t, &jpeg_decoder_data_type, ptr);

  /*
   * parse arguments
   */
  rb_scan_args( argc, argv, "0:", &opt);

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

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

  return Qtrue;
}

Instance Method Details

#decode(jpeg) ⇒ String Also known as: decompress, <<

decode JPEG data

Returns decoded raw image data.

Parameters:

  • jpeg (String)

    JPEG data to decode.

Returns:

  • (String)

    decoded raw image data.



3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
# File 'ext/jpeg/jpeg.c', line 3635

static VALUE
rb_decoder_decode(VALUE self, VALUE data)
{
  VALUE ret;
  jpeg_decode_t* ptr;
  int state;

  /*
   * initialize
   */
  ret   = Qnil;
  state = 0;

  TypedData_Get_Struct(self, jpeg_decode_t, &jpeg_decoder_data_type, ptr);

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

  /*
   * prepare
   */
  SET_DATA(ptr, data);

  /*
   * do decode
   */
  ret = rb_protect(do_decode, (VALUE)ptr, &state);

  /*
   * post process
   */
  CLR_DATA(ptr);

  if (state != 0) rb_jump_tag(state);

  return ret;
}

#read_header(jpeg) ⇒ JPEG::Meta

read meta data

Returns metadata.

Parameters:

  • jpeg (String)

    input data.

Returns:



2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
# File 'ext/jpeg/jpeg.c', line 2986

static VALUE
rb_decoder_read_header(VALUE self, VALUE data)
{
  VALUE ret;
  jpeg_decode_t* ptr;
  int state;

  /*
   * initialize
   */
  ret   = Qnil;
  state = 0;

  TypedData_Get_Struct(self, jpeg_decode_t, &jpeg_decoder_data_type, ptr);

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

  /*
   * prepare
   */
  SET_DATA(ptr, data);

  /*
   * do encode
   */
  ret = rb_protect(do_read_header, (VALUE)ptr, &state);

  /*
   * post process
   */
  CLR_DATA(ptr);

  if (state != 0) rb_jump_tag(state);

  return ret;
}

#set(opt) ⇒ Object



2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
# File 'ext/jpeg/jpeg.c', line 2031

static VALUE
rb_decoder_set(VALUE self, VALUE opt)
{
  jpeg_decode_t* ptr;
  VALUE exc;

  /*
   * initialize
   */
  TypedData_Get_Struct(self, jpeg_decode_t, &jpeg_decoder_data_type, ptr);

  /*
   * check argument
   */
  Check_Type(opt, T_HASH);

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

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

  return Qtrue;
}