Class: Axon::PNGReader

Inherits:
Object
  • Object
show all
Includes:
Image, Enumerable
Defined in:
ext/axon/png_reader.c

Instance Method Summary collapse

Methods included from Image

#crop, #fit, #scale_bilinear, #scale_nearest_neighbor, #to_jpeg, #to_png, #write_jpeg, #write_png

Constructor Details

#new(string_or_io[, markers]) ⇒ Object

Create a new JPEG Reader. string_or_io may be a String or any object that responds to read and close.

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 all header markers by supplying an empty array, [].

When markers are not specified, we read all known JPEG markers.



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'ext/axon/png_reader.c', line 142

static VALUE
initialize(VALUE self, VALUE io)
{
    struct png_data *reader;

    Data_Get_Struct(self, struct png_data, reader);
    raise_if_locked(reader);
    png_set_read_fn(reader->png_ptr, (void *)io, read_data_fn);
    reader->io = io;
    read_info(reader);

    return self;
}

Instance Method Details

#color_modelObject

Returns a symbol representing the color space into which the JPEG will be transformed as it is read.

By default this color space is based on Reader#color_space.

Possible color spaces are: GRAYSCALE, RGB, YCbCr, CMYK, and YCCK. This method will return nil if the color space is not recognized.



220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'ext/axon/png_reader.c', line 220

static VALUE
color_model(VALUE self)
{
    struct png_data *reader;
    png_structp png_ptr;
    png_infop info_ptr;

    Data_Get_Struct(self, struct png_data, reader);
    png_ptr = reader->png_ptr;
    info_ptr = reader->info_ptr;

    return ID2SYM(png_color_type_to_id(png_get_color_type(png_ptr, info_ptr)));
}

#num_componentsNumeric

Retrieve the number of components as stored in the JPEG image.

Returns:

  • (Numeric)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/axon/png_reader.c', line 175

static VALUE
components(VALUE self)
{
    struct png_data *reader;
    png_structp png_ptr;
    png_infop info_ptr;
    int c;

    Data_Get_Struct(self, struct png_data, reader);
    png_ptr = reader->png_ptr;
    info_ptr = reader->info_ptr;

    c = get_components(png_ptr, info_ptr);

    if (c == 0)
	return Qnil;

    return INT2FIX(c);
}

#each(&block) ⇒ Object

Iterate over each decoded scanline in the JPEG image.



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'ext/axon/png_reader.c', line 294

static VALUE
each(VALUE self)
{
    struct png_data *reader;

    Data_Get_Struct(self, struct png_data, reader);

    if (reader->needs_reset)
	reset_reader(reader);

    raise_if_locked(reader);
    reader->locked = 1;
    rb_ensure(each2, (VALUE)reader, each2_ensure, (VALUE)reader);

    return Qnil;
}

#heightNumeric

Retrieve the height of the image as it will be written out. This is primarily affected by scale_num and scale_denom if they are set.

Note that this value is not automatically calculated unless you call Reader#calc_output_dimensions or after Reader#each has been called.

Returns:

  • (Numeric)


345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/axon/png_reader.c', line 345

static VALUE
height(VALUE self)
{
    struct png_data *reader;
    png_structp png_ptr;
    png_infop info_ptr;

    Data_Get_Struct(self, struct png_data, reader);
    png_ptr = reader->png_ptr;
    info_ptr = reader->info_ptr;

    return INT2FIX(png_get_image_height(png_ptr, info_ptr));
}

#widthNumeric

Retrieve the width of the image as it will be written out. This is primarily affected by scale_num and scale_denom if they are set.

Note that this value is not automatically calculated unless you call Reader#calc_output_dimensions or after Reader#each_scanline has been called.

Returns:

  • (Numeric)


321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'ext/axon/png_reader.c', line 321

static VALUE
width(VALUE self)
{
    struct png_data *reader;
    png_structp png_ptr;
    png_infop info_ptr;

    Data_Get_Struct(self, struct png_data, reader);
    png_ptr = reader->png_ptr;
    info_ptr = reader->info_ptr;

    return INT2FIX(png_get_image_width(png_ptr, info_ptr));
}