Module: Oil

Defined in:
lib/oil.rb

Defined Under Namespace

Classes: JPEGReader, PNGReader

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.fix_ratio(src_w, src_h, out_w, out_h) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'ext/oil/oil.c', line 4

static VALUE rb_fix_ratio(VALUE self, VALUE src_w, VALUE src_h, VALUE out_w, VALUE out_h)
{
	uint32_t out_width, out_height;
	VALUE ret;
	out_width = NUM2INT(out_w);
	out_height = NUM2INT(out_h);
	fix_ratio(NUM2INT(src_w), NUM2INT(src_h), &out_width, &out_height);
	ret = rb_ary_new2(2);
	rb_ary_push(ret, INT2FIX(out_width));
	rb_ary_push(ret, INT2FIX(out_height));
	return ret;
}

.new(io, box_width, box_height) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/oil.rb', line 17

def self.new(io, box_width, box_height)
  case sniff_signature(io)
  when :JPEG
    return new_jpeg_reader(io, box_width, box_height)
  when :PNG
    return new_png_reader(io, box_width, box_height)
  else
    raise "Unknown image file format."
  end
end

.sniff_signature(io) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/oil.rb', line 4

def self.sniff_signature(io)
  a = io.getc
  b = io.getc
  io.ungetc(b)
  io.ungetc(a)

  if (a == "\xFF".b && b == "\xD8".b)
    return :JPEG
  elsif (a == "\x89".b && b == "P".b)
    return :PNG
  end
end