Image.image

The main object of the Image module, this object is used as drawing area, mask or result of operations.

init: clear, clone, create, xsize, ysize

plain drawing: box, circle, getpixel, line, setcolor, setpixel, treshold, tuned_box, polyfill

operators: `&, `*, `+, `-, `|

pasting images, layers: add_layers, paste, paste_alpha, paste_alpha_color, paste_mask

getting subimages, scaling, rotating: autocrop, ccw, cw, clone, copy, dct, mirrorx, rotate, rotate_expand, scale, skewx, skewx_expand, skewy, skewy_expand

calculation by pixels: apply_matrix, change_color, color, distancesq, grey, invert, map_closest, map_fast, modify_by_intensity, select_from

converting to other datatypes: cast, fromgif, frompnm/fromppm, gif_add, gif_add_fs, gif_add_fs_nomap, gif_add_nomap, gif_begin, gif_end, gif_netscape_loop, to8bit, to8bit_closest, to8bit_fs, to8bit_rgbcube, to8bit_rgbcube_rdither, tobitmap, togif, togif_fs, toppm, tozbgr

SEE ALSO

Image, Image.font

SYNOPSIS

object `&(object operand)
object `&(array(int) color)
object `&(int value)

DESCRIPTION

makes a new image out of the minimum pixels values

ARGUMENTS

object operand
the other image to compare with; the images must have the same size.
array(int) color
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
int value
equal to ({value,value,value}).

RETURNS

the new image object

SEE ALSO

`-, `+, `|, `*, add_layers

SYNOPSIS

object `*(object operand)
object `*(array(int) color)
object `*(int value)

DESCRIPTION

Multiplies pixel values and creates a new image.

This can be useful to lower the values of an image, making it greyer, for instance:

image=image*128+64;

ARGUMENTS

object operand
the other image to multiply with; the images must have the same size.
array(int) color
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
int value
equal to ({value,value,value}).

RETURNS

the new image object

SEE ALSO

`-, `+, `|, `&, add_layers

SYNOPSIS

object `+(object operand)
object `+(array(int) color)
object `+(int value)

DESCRIPTION

adds two images; values are truncated at 255.

ARGUMENTS

object operand
the image which to add.
array(int) color
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
int value
equal to ({value,value,value}).

RETURNS

the new image object

SEE ALSO

`-, `|, `&, `*, add_layers

SYNOPSIS

object `-(object operand)
object `-(array(int) color)
object `-(int value)

DESCRIPTION

makes a new image out of the difference

ARGUMENTS

object operand
the other image to compare with; the images must have the same size.
array(int) color
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
int value
equal to ({value,value,value}).

RETURNS

the new image object

SEE ALSO

`+, `|, `&, `*, add_layers

SYNOPSIS

object `|(object operand)
object `|(array(int) color)
object `|(int value)

DESCRIPTION

makes a new image out of the maximum pixels values

ARGUMENTS

object operand
the other image to compare with; the images must have the same size.
array(int) color
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
int value
equal to ({value,value,value}).

RETURNS

the new image object

SEE ALSO

`-, `+, `&, `*, add_layers

SYNOPSIS

object add_layers(array(int|object)) layer0, ...)
object add_layers(int x1, int y1, int x2, int y2, array(int|object)) layer0, ...)

DESCRIPTION

Using the called object as base, adds layers using masks, opaque channel values and special methods.

The destination image can also be cropped, thus speeding up the process.

Each array in the layers array is one of:

     ({object image,object|int mask})
     ({object image,object|int mask,int opaque_value})
     ({object image,object|int mask,int opaque_value,int method})
     
Given 0 as mask means the image is totally opaque.

Default opaque value is 255, only using the mask.

Methods for now are:

     0  no operation (just paste with mask, default)
     1  maximum  (`|)
     2  minimum  (`&)
     3  multiply (`*)
     4  add      (`+)
     5  diff     (`-)
     
The layer image and the current source are calculated through the given method and then pasted using the mask and the opaque channel value.

All given images must be the same size.

ARGUMENTS

array(int|object) layer0
image to paste
int x1
int y1
int x2
int y2
rectangle for cropping

RETURNS

a new image object

SEE ALSO

paste_mask, paste_alpha, paste_alpha_color, `|, `&, `*, `+, `-

SYNOPSIS

object apply_matrix(array(array(int|array(int))) matrix)
object apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b)
object apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b, int|float div)

DESCRIPTION

Applies a pixel-transform matrix, or filter, to the image.
                            2   2
     pixel(x,y)= base+ k ( sum sum pixel(x+k-1,y+l-1)*matrix(k,l) ) 
                           k=0 l=0 
     
1/k is sum of matrix, or sum of matrix multiplied with div. base is given by r,g,b and is normally black.

blur (ie a 2d gauss function):

     ({({1,2,1}),
       ({2,5,2}),
       ({1,2,1})})
     
sharpen (k>8, preferably 12 or 16):
     ({({-1,-1,-1}),
       ({-1, k,-1}),
       ({-1,-1,-1})})
     

edge detect:

     ({({1, 1,1}),
       ({1,-8,1}),
       ({1, 1,1})})
     

horisontal edge detect (get the idea):

     ({({0, 0,0})
       ({1,-8,1}),
       ({0, 0,0})})
     

emboss (might prefer to begin with a grey image):

     ({({2, 1, 0})
       ({1, 0,-1}),
       ({0,-1, 2})}), 128,128,128, 5
     

This function is not very fast, and it's hard to optimize it more, not using assembler.

ARGUMENTS

array(array(int|array(int)))
the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.
int r
int g
int b
base level of result, default is zero
int|float div
division factor, default is 1.0.

RETURNS

the new image object

SYNOPSIS

object autocrop()
object autocrop(int border)
object autocrop(int border, int r, int g, int b)
object autocrop(int border, int left, int right, int top, int bottom)
object autocrop(int border, int left, int right, int top, int bottom, int r, int g, int b)

DESCRIPTION

Removes "unneccesary" borders around the image, adds one of its own if wanted to, in selected directions.

"Unneccesary" is all pixels that are equal -- ie if all the same pixels to the left are the same color, that column of pixels are removed.

ARGUMENTS

int border
added border size in pixels
int r
int g
int b
color of the new border
int left
int right
int top
int bottom
which borders to scan and cut the image; a typical example is removing the top and bottom unneccesary pixels:
img=img->autocrop(0, 0,0,1,1);

RETURNS

the new image object

SEE ALSO

copy

SYNOPSIS

object box(int x1, int y1, int x2, int y2)
object box(int x1, int y1, int x2, int y2, int r, int g, int b)
object box(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

DESCRIPTION

Draws a filled rectangle on the image.

ARGUMENTS

int x1
int y1
int x2
int y2
box corners
int r
int g
int b
color of the box
int alpha
alpha value

RETURNS

the object called

SYNOPSIS

string cast(string type)
string to8bit(array(array(int)) colors)
string to8bit_fs(array(array(int)) colors)
string to8bit_closest(array(array(int)) colors)

DESCRIPTION

Maps the image to the given colors and returns the 8 bit data.

to8bit_fs uses floyd-steinberg dithering

RETURNS

the calculated string

KNOWN BUGS

always casts to string...

SEE ALSO

to8bit_rgbcube, tozbgr, map_fast, map_closest, select_colors, tobitmap

SYNOPSIS

object ccw()

DESCRIPTION

rotates an image counter-clockwise, 90 degrees.

RETURNS

the new image object

SYNOPSIS

object change_color(int tor, int tog, int tob)
object change_color(int fromr, int fromg, int fromb,  int tor, int tog, int tob)

DESCRIPTION

Changes one color (exakt match) to another. If non-exakt-match is preferred, check distancesq and paste_alpha_color.

ARGUMENTS

int tor
int tog
int tob
destination color and next current color
int fromr
int fromg
int fromb
source color, default is current color

RETURNS

a new (the destination) image object

SYNOPSIS

object circle(int x, int y, int rx, int ry)
object circle(int x, int y, int rx, int ry, int r, int g, int b)
object circle(int x, int y, int rx, int ry, int r, int g, int b, int alpha)

DESCRIPTION

Draws a line on the image. The line is not antialiased.

ARGUMENTS

int x
int y
circle center
int rx
int ry
circle radius in pixels
int r
int g
int b
color
int alpha
alpha value

RETURNS

the object called

SYNOPSIS

void clear()
void clear(int r, int g, int b)
void clear(int r, int g, int b, int alpha)

DESCRIPTION

gives a new, cleared image with the same size of drawing area

ARGUMENTS

int r
int g
int b
color of the new image
int alpha
new default alpha channel value

SEE ALSO

copy, clone

SYNOPSIS

object clone()
object clone(int xsize, int ysize)
object clone(int xsize, int ysize, int r, int g, int b)
object clone(int xsize, int ysize, int r, int g, int b, int alpha)

DESCRIPTION

Copies to or initialize a new image object.

ARGUMENTS

int xsize
int ysize
size of (new) image in pixels, called image is cropped to that size
int r
int g
int b
current color of the new image, default is black. Will also be the background color if the cloned image is empty (no drawing area made).
int alpha
new default alpha channel value

RETURNS

the new object

SEE ALSO

copy, create

SYNOPSIS

object color()
object color(int value)
object color(int r, int g, int b)

DESCRIPTION

Colorize an image.

The red, green and blue values of the pixels are multiplied with the given value(s). This works best on a grey image...

The result is divided by 255, giving correct pixel values.

If no arguments are given, the current color is used as factors.

ARGUMENTS

int r
int g
int b
red, green, blue factors
int value
factor

RETURNS

the new image object

SEE ALSO

grey, `*, modify_by_intensity

SYNOPSIS

object copy()
object copy(int x1, int y1, int x2, int y2)
object copy(int x1, int y1, int x2, int y2, int r, int g, int b)
object copy(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

DESCRIPTION

Copies this part of the image. The requested area can be smaller, giving a cropped image, or bigger - the new area will be filled with the given or current color.

ARGUMENTS

int x1
int y1
int x2
int y2
The requested new area. Default is the old image size.
int r
int g
int b
color of the new image
int alpha
new default alpha channel value

RETURNS

a new image object

NOTE

clone(void) and copy(void) does the same operation

SEE ALSO

clone, autocrop

SYNOPSIS

void create()
void create(int xsize, int ysize)
void create(int xsize, int ysize, int r, int g, int b)
void create(int xsize, int ysize, int r, int g, int b, int alpha)

DESCRIPTION

Initializes a new image object.

ARGUMENTS

int xsize
int ysize
size of (new) image in pixels
int r
int g
int b
background color (will also be current color), default color is black
int alpha
default alpha channel value

SEE ALSO

copy, clone, Image.image

SYNOPSIS

object cw()

DESCRIPTION

rotates an image clockwise, 90 degrees.

RETURNS

the new image object

SYNOPSIS

object dct(int newx, int newy)

DESCRIPTION

Scales the image to a new size. Method for scaling is rather complex; the image is transformed via a cosine transform, and then resampled back.

This gives a quality-conserving upscale, but the algorithm used is n*n+n*m, where n and m is pixels in the original and new image.

Recommended wrapping algorithm is to scale overlapping parts of the image-to-be-scaled.

This functionality is actually added as an true experiment, but works...

ARGUMENTS

int newx
int newy
new image size in pixels

RETURNS

the new image object

NOTE

Do NOT use this function if you don't know what you're dealing with! Read some signal theory first...

SYNOPSIS

object distancesq()
object distancesq(int r, int g, int b)

DESCRIPTION

Makes an grey-scale image, for alpha-channel use. The given value (or current color) are used for coordinates in the color cube. Each resulting pixel is the distance from this point to the source pixel color, in the color cube, squared, rightshifted 8 steps:

    p = pixel color
    o = given color
    d = destination pixel
    d.red=d.blue=d.green=
        ((o.red-p.red)²+(o.green-p.green)²+(o.blue-p.blue)²)>>8
    

ARGUMENTS

int r
int g
int b
red, green, blue coordinates

RETURNS

the new image object

SEE ALSO

select_from

SYNOPSIS

object fromgif(string gif)

DESCRIPTION

Reads GIF data to the called image object.

GIF animation delay or loops are ignored, and the resulting image is the written result.

ARGUMENTS

string pnm
pnm data, as a string

RETURNS

the called object

KNOWN BUGS

yes, it does -- it may even do segment overrides...

SEE ALSO

togif, frompnm

SYNOPSIS

object|string frompnm(string pnm)
object|string fromppm(string pnm)

DESCRIPTION

Reads a PNM (PBM, PGM or PPM in ascii or binary) to the called image object.

The method accepts P1 through P6 type of PNM data.

"fromppm" is an alias for "frompnm".

ARGUMENTS

string pnm
pnm data, as a string

RETURNS

the called object or a hint of what wronged.

SEE ALSO

toppm, fromgif

SYNOPSIS

array(int) getpixel(int x, int y)

ARGUMENTS

int x
int y
position of the pixel

RETURNS

color of the requested pixel -- ({int red,int green,int blue})

SYNOPSIS

string gif_add()
string gif_add(int x, int y)
string gif_add(int x, int y, int delay_cs)
string gif_add(int x, int y, float delay_s)
string gif_add(int x, int y, int num_colors, int delay_cs)
string gif_add(int x, int y, int num_colors, float delay_s)
string gif_add(int x, int y, array(array(int)) colors, int delay_cs)
string gif_add(int x, int y, array(array(int)) colors, float delay_s)
string gif_add_fs()
string gif_add_fs(int x, int y)
string gif_add_fs(int x, int y, int delay_cs)
string gif_add_fs(int x, int y, float delay_s)
string gif_add_fs(int x, int y, int num_colors, int delay_cs)
string gif_add_fs(int x, int y, int num_colors, float delay_s)
string gif_add_fs(int x, int y, array(array(int)) colors, int delay_cs)
string gif_add_fs(int x, int y, array(array(int)) colors, float delay_s)
string gif_add_nomap()
string gif_add_nomap(int x, int y)
string gif_add_nomap(int x, int y, int delay_cs)
string gif_add_nomap(int x, int y, float delay_s)
string gif_add_nomap(int x, int y, int num_colors, int delay_cs)
string gif_add_nomap(int x, int y, int num_colors, float delay_s)
string gif_add_nomap(int x, int y, array(array(int)) colors, int delay_cs)
string gif_add_nomap(int x, int y, array(array(int)) colors, float delay_s)
string gif_add_fs_nomap()
string gif_add_fs_nomap(int x, int y)
string gif_add_fs_nomap(int x, int y, int delay_cs)
string gif_add_fs_nomap(int x, int y, float delay_s)
string gif_add_fs_nomap(int x, int y, int num_colors, int delay_cs)
string gif_add_fs_nomap(int x, int y, int num_colors, float delay_s)
string gif_add_fs_nomap(int x, int y, array(array(int)) colors, int delay_cs)
string gif_add_fs_nomap(int x, int y, array(array(int)) colors, float delay_s)

DESCRIPTION

Makes a GIF (sub)image data chunk, to be placed at the given position.

The "fs" versions uses floyd-steinberg dithering, and the "nomap" versions have no local colormap.

Example:

     object img1 = Image(200,200); 
     object img2 = Image(200,200); 
     // load img1 and img2 with stuff
     write(img1->gif_begin()+
           img1->gif_netscape_loop()+
           img1->gif_add(0,0,100)+
           img2->gif_add(0,0,100)+
           img1->gif_end());
     // voila, a gif animation...
     

ARGUMENTS

int x
int y
the location of this subimage
int delay_cs
frame delay in centiseconds
float delay_s
frame delay in seconds
int num_colors
number of colors to quantize to (default is 256)
array array(array(int)) colors
colors to map to, format is ({({r,g,b}),({r,g,b}),...}).

RETURNS

the GIF data chunk as a string

NOTE

I (Mirar) recommend reading about the GIF file format before experementing with these.

SEE ALSO

gif_add, gif_end, gif_netscape_loop, togif */

SYNOPSIS

string gif_begin()
string gif_begin(int num_colors)
string gif_begin(array(array(int)) colors)

DESCRIPTION

Makes GIF header. With no argument, there is no global colortable (palette).

ARGUMENTS

int num_colors
number of colors to quantize to (default is 256) array array(array(int)) colors colors to map to, format is ({({r,g,b}),({r,g,b}),...}).

RETURNS

the GIF data

SEE ALSO

gif_add, gif_end, togif, gif_netscape_loop

SYNOPSIS

string gif_end()

DESCRIPTION

Ends GIF data.

RETURNS

the GIF data.

SEE ALSO

gif_begin

SYNOPSIS

string gif_netscape_loop()
string gif_netscape_loop(int loops)

ARGUMENTS

int loops
number of loops, default is 65535.

RETURNS

a gif chunk that defines that the GIF animation should loop

SEE ALSO

gif_add, gif_begin, gif_end

SYNOPSIS

object grey()
object grey(int r, int g, int b)

DESCRIPTION

Makes a grey-scale image (with weighted values).

ARGUMENTS

int r
int g
int b
weight of color, default is r=87,g=127,b=41, which should be pretty accurate of what the eyes see...

RETURNS

the new image object

SEE ALSO

color, `*, modify_by_intensity

SYNOPSIS

object invert()

DESCRIPTION

Invert an image. Each pixel value gets to be 255-x, where x is the old value.

RETURNS

the new image object

SYNOPSIS

object line(int x1, int y1, int x2, int y2)
object line(int x1, int y1, int x2, int y2, int r, int g, int b)
object line(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)

DESCRIPTION

Draws a line on the image. The line is not antialiased.

ARGUMENTS

int x1
int y1
int x2
int y2
line endpoints
int r
int g
int b
color
int alpha
alpha value

RETURNS

the object called

SYNOPSIS

object map_closest(array(array(int)) colors)

DESCRIPTION

Maps all pixel colors to the colors given.

Method to find the correct color is linear search over the colors given, selecting the nearest in the color cube. Slow...

ARGUMENTS

array(array(int)) color
list of destination (available) colors

RETURNS

the new image object

SEE ALSO

map_fast, select_colors, map_fs

SYNOPSIS

array(array(int)) map_closest(int num_colors)

DESCRIPTION

Selects the best colors to represent the image.

ARGUMENTS

int num_colors
number of colors to return

RETURNS

an array of colors

SEE ALSO

map_fast, select_colors

SYNOPSIS

object map_fast(array(array(int)) colors)

DESCRIPTION

Maps all pixel colors to the colors given.

Method to find the correct color is to branch in a binary space partitioning tree in the colorcube. This is fast, but in some cases it gives the wrong color (mostly when few colors are available).

ARGUMENTS

array(array(int)) color
list of destination (available) colors

RETURNS

the new image object

SEE ALSO

map_fast, select_colors

SYNOPSIS

object map_fs(array(array(int)) colors)

DESCRIPTION

Maps all pixel colors to the colors given.

Method to find the correct color is linear search over the colors given, selecting the nearest in the color cube. Slow...

Floyd-steinberg error correction is added to create a better-looking image, in many cases, anyway.

ARGUMENTS

array(array(int)) color
list of destination (available) colors

RETURNS

the new image object

SEE ALSO

map_fast, select_colors, map_closest

SYNOPSIS

object mirrorx()

DESCRIPTION

mirrors an image:
     +--+     +--+
     |x | <-> | x|
     | .|     |. |
     +--+     +--+
     

RETURNS

the new image object

SYNOPSIS

object mirrorx()

DESCRIPTION

mirrors an image:
     +--+     +--+
     |x | <-> | .|
     | .|     |x |
     +--+     +--+
     

SYNOPSIS

object modify_by_intensity(int r, int g, int b, int|array(int) v1, ..., int|array(int) vn)

DESCRIPTION

Recolor an image from intensity values.

For each color an intensity is calculated, from r, g and b factors (see grey), this gives a value between 0 and max.

The color is then calculated from the values given, v1 representing the intensity value of 0, vn representing max, and colors between representing intensity values between, linear.

ARGUMENTS

int r
int g
int b
red, green, blue intensity factors
int|array(int) v1
int|array(int) vn
destination color

RETURNS

the new image object

SEE ALSO

grey, `*, color

SYNOPSIS

object paste(object image)
object paste(object image, int x, int y)

DESCRIPTION

Pastes a given image over the current image.

ARGUMENTS

object image
image to paste
int x
int y
where to paste the image; default is 0,0

RETURNS

the object called

SEE ALSO

paste_mask, paste_alpha, paste_alpha_color

SYNOPSIS

object paste_alpha(object image, int alpha)
object paste_alpha(object image, int alpha, int x, int y)

DESCRIPTION

Pastes a given image over the current image, with the specified alpha channel value. An alpha channel value of 0 leaves nothing of the original image in the paste area, 255 is meaningless and makes the given image invisible.

ARGUMENTS

object image
image to paste
int alpha
alpha channel value
int x
int y
where to paste the image; default is 0,0

RETURNS

the object called

SEE ALSO

paste_mask, paste, paste_alpha_color

SYNOPSIS

object paste_alpha_color(object mask)
object paste_alpha_color(object mask, int x, int y)
object paste_alpha_color(object mask, int r, int g, int b)
object paste_alpha_color(object mask, int r, int g, int b, int x, int y)

DESCRIPTION

Pastes a given color over the current image, using the given mask as opaque channel. A pixel value of 255 makes the result become the color given, 0 doesn't change anything. The masks red, green and blue values are used separately. If no color are given, the current is used.

ARGUMENTS

object mask
mask image
int r
int g
int b
what color to paint with; default is current
int x
int y
where to paste the image; default is 0,0

RETURNS

the object called

SEE ALSO

paste_mask, paste_alpha, paste_alpha_color

SYNOPSIS

object paste_mask(object image, object mask)
object paste_mask(object image, object mask, int x, int y)

DESCRIPTION

Pastes a given image over the current image, using the given mask as opaque channel. A pixel value of 255 makes the result become a pixel from the given image, 0 doesn't change anything.

The masks red, green and blue values are used separately.

ARGUMENTS

object image
image to paste
object mask
mask image
int x
int y
where to paste the image; default is 0,0

RETURNS

the object called

SEE ALSO

paste, paste_alpha, paste_alpha_color

SYNOPSIS

object polygone(array(int|float) ... curve)

DESCRIPTION

fills an area with the current color

ARGUMENTS

array(int|float) curve
curve(s), ({x1,y1,x2,y2,...,xn,yn}), automatically closed.

If any given curve is inside another, it will make a hole.

NOTE This function is new (april-97) and rather untested.

RETURNS

the current object

SEE ALSO

box, setcolor

SYNOPSIS

object rotate(int|float angle)
object rotate(int|float angle, int r, int g, int b)
object rotate_expand(int|float angle)
object rotate_expand(int|float angle, int r, int g, int b)

DESCRIPTION

Rotates an image a certain amount of degrees (360° is a complete rotation) counter-clockwise:
                 x
     +--+       / \
     |  |  <-> x   x
     |  |       \ /
     +--+        x
     
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

This rotate uses the skewx() and skewy() functions.

ARGUMENTS

int|float angle
the number of degrees to rotate
int r
int g
int b
color to fill with; default is current

RETURNS

the new image object

SYNOPSIS

object scale(float factor)
object scale(0.5)
object scale(float xfactor, float yfactor)

DESCRIPTION

scales the image with a factor, 0.5 is an optimized case.

ARGUMENTS

float factor
factor to use for both x and y
float xfactor
float yfactor
separate factors for x and y

RETURNS

the new image object

SYNOPSIS

object scale(int newxsize, int newysize)
object scale(0, int newysize)
object scale(int newxsize, 0)

DESCRIPTION

scales the image to a specified new size, if one of newxsize or newysize is 0, the image aspect ratio is preserved.

ARGUMENTS

int newxsize
int newysize
new image size in pixels

RETURNS

the new image object

SYNOPSIS

object select_from(int x, int y)
object select_from(int x, int y, int edge_value)

DESCRIPTION

Makes an grey-scale image, for alpha-channel use. This is very close to a floodfill. The image is scanned from the given pixel, filled with 255 if the color is the same, or 255 minus distance in the colorcube, squared, rightshifted 8 steps (see distancesq).

When the edge distance is reached, the scan is stopped. Default edge value is 30. This value is squared and compared with the square of the distance above.

ARGUMENTS

int x
int y
originating pixel in the image

RETURNS

the new image object

SEE ALSO

distancesq

SYNOPSIS

object setcolor(int r, int g, int b)
object setcolor(int r, int g, int b, int alpha)

DESCRIPTION

set the current color

ARGUMENTS

int r
int g
int b
new color
int alpha
new alpha value

RETURNS

the object called

SYNOPSIS

object setpixel(int x, int y)
object setpixel(int x, int y, int r, int g, int b)
object setpixel(int x, int y, int r, int g, int b, int alpha)

ARGUMENTS

int x
int y
position of the pixel
int r
int g
int b
color
int alpha
alpha value

RETURNS

the object called

SYNOPSIS

object skewx(int x)
object skewx(int yfactor)
object skewx(int x, int r, int g, int b)
object skewx(int yfactor, int r, int g, int b)
object skewx_expand(int x)
object skewx_expand(int yfactor)
object skewx_expand(int x, int r, int g, int b)
object skewx_expand(int yfactor, int r, int g, int b)

DESCRIPTION

Skews an image an amount of pixels or a factor; a skew-x is a transformation:
     +--+         +--+
     |  |  <->   /  /
     |  |       /  /
     +--+      +--+
     

ARGUMENTS

int x
the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
float yfactor
best described as: x=yfactor*this->ysize()
int r
int g
int b
color to fill with; default is current

RETURNS

the new image object

SYNOPSIS

object skewy(int y)
object skewy(int xfactor)
object skewy(int y, int r, int g, int b)
object skewy(int xfactor, int r, int g, int b)
object skewy_expand(int y)
object skewy_expand(int xfactor)
object skewy_expand(int y, int r, int g, int b)
object skewy_expand(int xfactor, int r, int g, int b)

DESCRIPTION

Skews an image an amount of pixels or a factor; a skew-y is a transformation:
                  +
                 /|
     +--+       / |
     |  |  <-> +  +
     |  |      | /
     +--+      |/
               +
     
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

ARGUMENTS

int y
the number of pixels
float xfactor
best described as: t=xfactor*this->xsize()
int r
int g
int b
color to fill with; default is current

RETURNS

the new image object

SYNOPSIS

string tozbgr(array(array(int)) colors)
string to8bit_rgbcube(int red, int green, int blue)
string to8bit_rgbcube(int red, int green, int blue, string map)
string to8bit_rgbcube_rdither(int red, int green, int blue)
string to8bit_rgbcube_rdither(int red, int green, int blue, string map)

DESCRIPTION

Maps the image into a colorcube with the given dimensions. Red is least significant, blue is most.

The "rdither" type of method uses a random dither algoritm.

ARGUMENTS

int red
int green
int blue
The sides of the colorcube. Not the number of bits!
string map
Map this position in the colorcube to another value, ie: say we have position red=1,green=2,blue=3 in a colorcube of 6×6×6, we have the index 1+2*6+3*6*6=121. If the map-string contains 'å' in position 121, the resulting byte is 'å' or 229.

RETURNS

the calculated string

SEE ALSO

tozbgr, to8bit, tobitmap

SYNOPSIS

string tobitmap();

DESCRIPTION

Maps the image to a bitmap.

Bit 0 is the leftmost pixel, and the rows are aligned to bytes.

Any pixel value other then black results in a set bit.

RETURNS

the calculated string

SEE ALSO

tozbgr, to8bit, to8bit_rgbcube, cast

SYNOPSIS

string togif()
string togif(int num_colors)
string togif(array(array(int)) colors)
string togif(int trans_r, int trans_g, int trans_b)
string togif(int num_colors, int trans_r, int trans_g, int trans_b)
string togif(array(array(int)) colors, int trans_r, int trans_g, int trans_b)
string togif_fs()
string togif_fs(int num_colors)
string togif_fs(array(array(int)) colors)
string togif_fs(int trans_r, int trans_g, int trans_b)
string togif_fs(int num_colors, int trans_r, int trans_g, int trans_b)
string togif_fs(array(array(int)) colors, int trans_r, int trans_g, int trans_b)

DESCRIPTION

Makes GIF data. The togif_fs variant uses floyd-steinberg dithereing.

ARGUMENTS

int num_colors
number of colors to quantize to (default is 256) array array(array(int)) colors colors to map to (default is to quantize to 256), format is ({({r,g,b}),({r,g,b}),...}).
int trans_r
int trans_g
int trans_b
one color, that is to be transparent.

RETURNS

the GIF data

SEE ALSO

togif_begin, togif_add, togif_end, toppm, fromgif

SYNOPSIS

string toppm()

DESCRIPTION

Returns PPM (P6, binary pixmap) data from the current image object.

RETURNS

PPM data

SEE ALSO

frompnm, fromgif

SYNOPSIS

object treshold()
object treshold(int r, int g, int b)

DESCRIPTION

Makes a black-white image.

If all red, green, blue parts of a pixel is larger or equal then the given value, the pixel will become white, else black.

This method works fine with the grey method.

If no arguments are given, the current color is used for treshold values.

ARGUMENTS

int r
int g
int b
red, green, blue threshold values

RETURNS

the new image object

SEE ALSO

grey

SYNOPSIS

object tuned_box(int x1, int y1, int x2, int y2, array(array(int)) corner_color)

DESCRIPTION

Draws a filled rectangle with colors (and alpha values) tuned between the corners.

Tuning function is (1.0-x/xw)*(1.0-y/yw) where x and y is the distance to the corner and xw and yw are the sides of the rectangle.

ARGUMENTS

int x1
int y1
int x2
int y2
rectangle corners
array(array(int)) corner_color
colors of the corners:
     ({x1y1,x2y1,x1y2,x2y2})
     
each of these is an array of integeres:
     ({r,g,b}) or ({r,g,b,alpha})
     
Default alpha channel value is 0 (opaque).

RETURNS

the object called

SYNOPSIS

int xsize()

RETURNS

the width of the image

SYNOPSIS

int ysize()

RETURNS

the height of the image