Top Documents Download Gallery Repository
Are you looking for a Software Engineer? Check Here

29jpeg Module

The jpeg module provides measures to read/write image data in JPEG format. To utilize it, import the jpeg module using import function.

Below is an example to read a JPEG file:

import(jpeg)
img = image('foo.jpeg')

29.1Exntension to Function's Capability

This module extends the capability of function image() and instance method image#write() so that they can read/write JPEG files.

When function image() is provided with a stream that satisfies the following conditions, it would recognize the stream as a JPEG file.

When instance method image#write() is provided with a stream that satisfies the following condition, it would write image data in JPEG format.

29.2jpeg.exif Class

The jpeg.exif class provides EXIF information in a JPEG stream.

A jpeg.exif instance contains jpeg.ifd instances as properties named jpeg.exif#ifd0 and jpeg.exif#ifd1 that include a list of jpeg.tag instances.

+-----------+             +----------+        +----------+
| jpeg.exif |ifd0, ifd1   | jpeg.ifd |1..     | jpeg.tag |
|-----------*-------------+----------*--------+----------|
|           |             |          |        |          |
+-----------+             +----------+        +----------+

29.2.1Property

A jpeg.exif instance has the following properties:

Property Type R/W Explanation
endian symbol R The endian type: `big for big-endian and `little for little-endian.
ifd0 jpeg.ifd R IFD0 instance.
ifd1 jpeg.ifd R IFD1 instance.
thumbnail image R Thumbnail image as image value.
thumbnail@jpeg binary R Thumbnail image as JPEG binary data.

29.2.2Constructor

jpeg.exif
jpeg.exif(stream?:stream:r):map:[raise] {block?}
Reads EXIF data from stream and creates a jpeg.exif instance.

If no EXIF information exists in the stream, this function returns nil. If the attribute :raise is specified, an error occurs for that case.

If block is specified, it would be evaluated with a block parameter |exif:jpeg.exif|, where exif is the created instance. In this case, the block's result would become the function's returned value.

29.2.3Method

jpeg.exif#each
jpeg.exif#each() {block?}
Creates an iterator that returns jpeg.tag values as elements that are stored in the property jpeg.exif#ifd0.

In default, this returns an iterator as its result value. Specifying the following attributes would customize the returned value:

See the chapter of Mapping Process in Gura Language Manual for the detail.

If a block is specified, it would be evaluated repeatingly with block parameters |value, idx:number| where value is the iterated value and idx the loop index starting from zero. In this case, the last evaluated value of the block would be the result value. If one of the attributes listed above is specified, an iterator or a list of the evaluated value would be returned.

29.3jpeg.ifd Class

29.3.1Property

A jpeg.ifd instance has the following properties:

Property Type R/W Explanation
name string R
symbol symbol R

29.3.2Method

jpeg.ifd#each
jpeg.ifd#each() {block?}
Creates an iterator that returns jpeg.tag values as elements that are stored in the target jpeg.ifd instance.

In default, this returns an iterator as its result value. Specifying the following attributes would customize the returned value:

See the chapter of Mapping Process in Gura Language Manual for the detail.

If a block is specified, it would be evaluated repeatingly with block parameters |value, idx:number| where value is the iterated value and idx the loop index starting from zero. In this case, the last evaluated value of the block would be the result value. If one of the attributes listed above is specified, an iterator or a list of the evaluated value would be returned.

29.4jpeg.tag Class

29.4.1Property

A jpeg.tag instance has the following properties:

Property Type R/W Explanation
id number R Tag ID.
name string R Tag name.
symbol symbol R Tag name as symbol.
type number R Tag type.
typename string R Tag type name.
value any R Tag value. When the attribute :cooked is specified, numbers in some tags are translated to human-readable symbols.
ifd jpeg.ifd R IFD instance. Valid only for tags Exif, GPSInfo and Interoperability.

29.5Extension to image Class

This module extends the image class with methods described here.

image#read@jpeg
image#read@jpeg(stream:stream:r, size?:number):reduce:[fast,rough]
Reads a JPEG image data from the specified stream.

When the argument size is specified, the image would be shrinked so that it is boxed within the size.

The attribute :fast indicates a fast but less-qualified decompression process.

The attriubte :rough is only valid when size is specified and makes the shrinked image with nearest neighbor method. Othereise, shrinking shall be done with bilinear method.

image#write@jpeg
image#write@jpeg(stream:stream:w, quality:number => 75):reduce
Writes a JPEG image data to the specified stream.

The argument quality takes a number between 0 and 100 with which a a higher number results in a higher quality of result but a less compression performance. The default value for it is 75.

29.6Thanks

This module uses JPEG library which is distributed in the following site:

http://www.ijg.org/


Copyright (C) 2011-2017 ypsitau