This is a simple JPEG extension library for Ruby. This library only supports reading and writing JPEG files. You can access raw RGB data if you need.
IJG's jpeg library (libjpeg)
$ ruby extconf.rb $ make
If you use VC++, run nmake instead of make.
If extconf.rb cannot find libjpeg headers and/or library, you should specify their paths by --with-jpeg-include and --with-jpeg-lib options.
JPEG base module.
Version string of this library.
Read JPEG file from io and returns JPEG::Image
object.
io
must be an IO
object. It will be binmode'ed.
Write img
as JPEG file to io
.
img
must be a JPEG::Image
object.
io
must be an IO
object. It will be binmode'ed.
gray
must be a true value or a false value. If gray
is a true value,
the written JPEG file will be grayscale image.
Class for image data.
Object
Create a JPEG::Image
object.
Returns the width of the image.
Set the width of the image.
num
must be an Integer
object. It must be more than 0.
Returns the height of the image.
Set the height of the image.
num
must be an Integer
object. It must be more than 0.
Returns the quality of the image.
Set the quality of the image.
num
must be an Integer
object. It must be more than 0 and less than or
equal to 100.
Returns the raw RGB data of the image.
The returned value is a String
object.
If the image is colored, 1 pixel is 3 bytes -- 1st byte means red, 2nd byte
means green, and 3rd byte means blue.
If the image is grayscaled, 1 pixel is 1 byte.
The raw data starts the pixel of left-top corner. And next 3 bytes (color) or 1 byte (grayscale) is the right pixel of it, and so on. After first line ended, the most left pixel of next line starts.
Set the raw RGB data of the image.
str
must be a String
object. It must be larger than or equal to the
required size.
You can calculate that the size is width * C * height.
C is 3 if the image is colored, or 1 if the image is grayscaled.
Returns the image is grayscaled or not.
The returned value is a true value or a false value.
Creates and returns a new JPEG::Image
object by converting the size of the
image.
It converts the image by using bilinear operation.
width
and height
must be Integer
objects. They must be more than 0.
Creates and returns a new JPEG::Image
object by converting the size of the
image.
It converts the image by using bicubic operation.
width
and height
must be Integer
objects. They must be more than 0.
Creates and returns a new JPEG::Image
object which is adfusted the level of
the image contrast automatically.
Creates and returns a new JPEG::Image
object which is cut the level of the
image contrast.
low
and high
must be Integer
objects. They must be more than 0 and less
than or equal to 100. high
must be more than low
.
adjust
must be a true value or a false value. If true, the level of contrast
will be adjusted automatically after cutting.
Creates and returns a new JPEG::Image
object which is clipped from the image.
If there is no argument, returns an image clipped automatically.
Otherwise, requires all 4 arguments and clips (x1
, y1
) - (x2
, y2
).
x1
, y1
, x2
, and y2
must be Integer
objects or nil.
Creates and returns a new JPEG::Image
object which is grayscaled from the
image.
Class for reading JPEG file.
Object
Create and returns a JPEG::Reader
object.
The object will read a JPEG file from io
.
io
must be an IO
object. It will be binmode'ed.
Create a JPEG::Reader
object and will pass it to the given block.
After executing the block, it returns nil
.
Close the object. You can never use this object to read data.
Reads the JPEG file and passes the raw RGB data of each lines to the block.
The passed line
will be a String
object.
If the image is colored, 1 pixel is 3 bytes -- 1st byte means red, 2nd byte
means green, and 3rd byte means blue.
If the image is grayscaled, 1 pixel is 1 byte.
Returns the width of the image.
Returns the height of the image.
Class for writing JPEG file.
Object
Create and returns a JPEG::Writer
object.
The object will write a JPEG file to io
.
io
must be an IO
object. It will be binmode'ed.
width
and hight
must be Integer
objects. They must be more than 0.
quality
must be an Integer
object. It must be more than 0 and less than or
equal to 100.
gray
must be a true value or a false value. If gray
is a true value,
the written JPEG file will be grayscale image.
Create a JPEG::Writer
object and will pass it to the given block.
The object will write a JPEG file to io.
io
must be an IO
object. It will be binmode'ed.
width
and height
must be Integer
objects. They must be more than 0.
quality
must be an Integer
object. It must be more than 0 and less than or
equal to 100.
gray
must be a true value or a false value. If gray
is a true value,
the written JPEG file will be grayscale image.
After executing the block, it returns nil
.
Close the object. You can never use this object to write data.
Write the return value of the block as the raw RGB data of each lines to
the JPEG file.
The return value of the block must be a String
object.
If the image is created for grayscale image, 1 pixel is 1 byte.
Otherwise, 1 pixel is 3 bytes -- 1st byte means red, 2nd byte means green,
and 3rd byte means blue.
Returns the width of the image.
Returns the height of the image.
Returns the quality of the image.
errors in this library.
StandardError
libjpeg errors.
JPEG::InternalError
libjpeg error code.
libjpeg unknown error.
JPEG::InternalError
Copyright (c) 2007,2011 NAKAMURA Usaku usa@garbagecollect.jp All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
(1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The binary form of this library may contain the libjpeg's code. In such case, you might have to consider to the license of libjpeg.