Class: Axon::PNG::Reader
- Inherits:
-
Object
- Object
- Axon::PNG::Reader
- Defined in:
- ext/axon/png.c,
ext/axon/png.c
Overview
Read compressed PNG images from an IO.
Instance Method Summary collapse
-
#color_model ⇒ Object
Returns a symbol representing the color model into which the JPEG will be transformed as it is read.
-
#components ⇒ Numeric
Retrieve the number of components as stored in the JPEG image.
-
#gets ⇒ String?
Reads the next scanline of data from the image.
-
#height ⇒ Numeric
Retrieve the height of the image as it will be written out.
-
#new(io_in[, markers]) ⇒ Object
constructor
Creates a new JPEG Reader.
-
#lineno ⇒ Numeric
Returns the number of the next line to be read from the image, starting at 0.
-
#width ⇒ Numeric
Retrieve the width of the image as it will be written out.
Constructor Details
#new(io_in[, markers]) ⇒ Object
Creates a new JPEG Reader. io_in must be an IO-like object that responds to read(size).
markers should be an array of valid JPEG header marker symbols. Valid symbols are :APP0 through :APP15 and :COM.
If performance is important, you can avoid reading any header markers by supplying an empty array, [].
When markers are not specified, we read all known JPEG markers.
io = File.open("image.jpg", "r")
reader = Axon::JPEG::Reader.new(io)
io = File.open("image.jpg", "r")
reader = Axon::JPEG::Reader.new(io, [:APP4, :APP5])
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
# File 'ext/axon/jpeg.c', line 601 static VALUE initialize(int argc, VALUE *argv, VALUE self) { struct readerdata *reader; j_decompress_ptr cinfo; VALUE io, markers; Data_Get_Struct(self, struct readerdata, reader); raise_if_locked(reader); cinfo = &reader->cinfo; rb_scan_args(argc, argv, "11", &io, &markers); reader->source_io = io; reader->mgr.bytes_in_buffer = 0; read_header(reader, markers); return self; } |
Instance Method Details
#color_model ⇒ Object
Returns a symbol representing the color model into which the JPEG will be transformed as it is read.
Possible color models are: :GRAYSCALE, :RGB, :YCbCr, :CMYK, and :YCCK. This method will return nil if the color model is not recognized.
693 694 695 696 697 698 699 700 701 702 703 |
# File 'ext/axon/jpeg.c', line 693 static VALUE color_model(VALUE self) { ID id; struct jpeg_decompress_struct * cinfo; Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo); id = j_color_space_to_id(cinfo->out_color_space); return ID2SYM(id); } |
#components ⇒ Numeric
Retrieve the number of components as stored in the JPEG image.
629 630 631 632 633 634 635 |
# File 'ext/axon/jpeg.c', line 629 static VALUE components(VALUE self) { struct jpeg_decompress_struct * cinfo; Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo); return INT2FIX(cinfo->num_components); } |
#gets ⇒ String?
Reads the next scanline of data from the image.
If the end of the image has been reached, this will return nil.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'ext/axon/png.c', line 392 static VALUE p_gets(VALUE self) { struct png_data *reader; png_structp png_ptr; png_infop info_ptr; png_uint_32 sl_width; size_t height; VALUE sl; Data_Get_Struct(self, struct png_data, reader); png_ptr = reader->png_ptr; info_ptr = reader->info_ptr; height = png_get_image_height(png_ptr, info_ptr); if (reader->lineno >= height) return Qnil; sl_width = png_get_rowbytes(png_ptr, info_ptr); sl = rb_str_new(0, sl_width); png_read_row(png_ptr, (png_bytep)RSTRING_PTR(sl), (png_bytep)NULL); reader->lineno += 1; if (reader->lineno >= height) png_read_end(png_ptr, info_ptr); return sl; } |
#height ⇒ Numeric
Retrieve the height of the image as it will be written out. This can be affected by scale_num and scale_denom if they are set.
927 928 929 930 931 932 933 |
# File 'ext/axon/jpeg.c', line 927 static VALUE height(VALUE self) { struct jpeg_decompress_struct * cinfo; Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo); return INT2FIX(cinfo->output_height); } |
#lineno ⇒ Numeric
Returns the number of the next line to be read from the image, starting at 0.
1070 1071 1072 1073 1074 1075 1076 |
# File 'ext/axon/jpeg.c', line 1070 static VALUE lineno(VALUE self) { struct jpeg_decompress_struct * cinfo; Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo); return INT2FIX(cinfo->output_scanline); } |
#width ⇒ Numeric
Retrieve the width of the image as it will be written out. This can be affected by scale_num and scale_denom if they are set.
911 912 913 914 915 916 917 |
# File 'ext/axon/jpeg.c', line 911 static VALUE width(VALUE self) { struct jpeg_decompress_struct * cinfo; Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo); return INT2FIX(cinfo->output_width); } |