Class: Oil::JPEG
- Inherits:
-
Object
- Object
- Oil::JPEG
- Defined in:
- ext/oil.c
Instance Method Summary collapse
-
#each(&block) ⇒ self
Yields a series of binary strings that make up the resized JPEG image.
-
#new(io, width, height) ⇒ Object
constructor
Creates a new resizer.
Constructor Details
#new(io, width, height) ⇒ Object
Creates a new resizer. io_in
must be an IO-like object that responds to #read(size, buffer) and #seek(size).
The resulting image will be scaled to fit in the box given by width
and height
while preserving the original aspect ratio.
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/oil.c', line 452
static VALUE
initialize(VALUE self, VALUE io, VALUE rb_width, VALUE rb_height)
{
int width=FIX2INT(rb_width), height=FIX2INT(rb_height);
struct thumbdata *data;
if (width<1 || height<1) rb_raise(rb_eArgError, "Dimensions must be > 0");
Data_Get_Struct(self, struct thumbdata, data);
data->io = io;
data->width = width;
data->height = height;
return self;
}
|
Instance Method Details
#each(&block) ⇒ self
Yields a series of binary strings that make up the resized JPEG image.
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'ext/oil.c', line 475
static VALUE
jpeg_each(VALUE self)
{
struct jpeg_src src;
struct jpeg_dest dest;
struct thumbdata *data;
Data_Get_Struct(self, struct thumbdata, data);
memset(&src, 0, sizeof(struct jpeg_src));
src.io = data->io;
src.buffer = rb_str_new(0, 0);
src.mgr.init_source = init_source;
src.mgr.fill_input_buffer = fill_input_buffer;
src.mgr.skip_input_data = skip_input_data;
src.mgr.resync_to_restart = jpeg_resync_to_restart;
src.mgr.term_source = term_source;
memset(&dest, 0, sizeof(struct jpeg_dest));
dest.buffer = rb_str_new(0, BUF_LEN);
dest.mgr.next_output_byte = RSTRING_PTR(dest.buffer);
dest.mgr.free_in_buffer = BUF_LEN;
dest.mgr.init_destination = init_destination;
dest.mgr.empty_output_buffer = empty_output_buffer;
dest.mgr.term_destination = term_destination;
jpeg_each2(data, &src, &dest);
return self;
}
|