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])
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'ext/axon/jpeg.c', line 621
static VALUE
initialize(int argc, VALUE *argv, VALUE self)
{
struct readerdata *reader;
j_decompress_ptr cinfo;
VALUE io, markers;
int i;
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.
714 715 716 717 718 719 720 721 722 723 724 |
# File 'ext/axon/jpeg.c', line 714
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.
650 651 652 653 654 655 656 |
# File 'ext/axon/jpeg.c', line 650
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.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'ext/axon/png.c', line 417
static VALUE
p_gets(VALUE self)
{
struct png_data *reader;
png_structp png_ptr;
png_infop info_ptr;
int width, components, 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;
width = png_get_image_width(png_ptr, info_ptr);
components = get_components(png_ptr, info_ptr);
sl_width = width * components;
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.
961 962 963 964 965 966 967 |
# File 'ext/axon/jpeg.c', line 961
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.
1104 1105 1106 1107 1108 1109 1110 |
# File 'ext/axon/jpeg.c', line 1104
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.
945 946 947 948 949 950 951 |
# File 'ext/axon/jpeg.c', line 945
static VALUE
width(VALUE self)
{
struct jpeg_decompress_struct * cinfo;
Data_Get_Struct(self, struct jpeg_decompress_struct, cinfo);
return INT2FIX(cinfo->output_width);
}
|