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.



3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
# File 'ext/jpeg/jpeg.c', line 3669

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:



3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
# File 'ext/jpeg/jpeg.c', line 3020

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