12. Image Module

  CLASS Image.Image

Description

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

basic:
clear , clone , create , xsize , ysize

plain drawing:
box , circle , getpixel , line , setcolor , setpixel , threshold , polyfill

operators:
`& , `* , `+ , `- , `== , `> , `< , `|

pasting images:
paste , paste_alpha , paste_alpha_color , paste_mask

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

calculation by pixels:
apply_matrix , change_color , color , distancesq , grey , invert , modify_by_intensity , outline select_from , rgb_to_hsv , hsv_to_rgb , rgb_to_yuv , yuv_to_rgb ,

average , max , min , sum , sumf , find_min , find_max

special pattern drawing:
noise , turbulence , test , tuned_box , gradients , random

See also

Image , Image.Font , Image.Colortable , Image.X


Method mirrorx

object mirrorx()

Description

mirrors an image:
original ->mirrorx();

Returns

the new image object


Method mirrory

object mirrory()

Description

mirrors an image:
original ->mirrory();


Method rotate
Method rotate_expand

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:

original ->rotate(15,255,0,0); ->rotate_expand(15);

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.

Parameter angle

the number of degrees to rotate

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method rotate_ccw

object rotate_ccw()

Description

rotates an image counter-clockwise, 90 degrees.

original ->rotate_ccw();

Returns

the new image object


Method rotate_cw

object rotate_cw()

Description

rotates an image clockwise, 90 degrees.

original ->rotate_cw();

Returns

the new image object


Method scale

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.

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method scale

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.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method skewx
Method skewx_expand

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

Description

Skews an image an amount of pixels or a factor; a skew-x is a transformation:

original ->skewx(15,255,0,0); ->skewx_expand(15);

Parameter x

the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

Parameter yfactor

best described as: x=yfactor*this->ysize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method skewy
Method skewy_expand

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

Description

Skews an image an amount of pixels or a factor; a skew-y is a transformation:

original ->skewy(15,255,0,0); ->skewy_expand(15);

The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

Parameter y

the number of pixels

Parameter xfactor

best described as: t=xfactor*this->xsize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method noise

void noise(array(float|int|array(int)) colorrange)
void noise(array(float|int|array(int)) colorrange, float scale, float xdiff, float ydiff, float cscale)

Description

Gives a new image with the old image's size, filled width a 'noise' pattern.

The random seed may be different with each instance of pike.

Example: ->noise( ({0,({255,0,0}), 0.3,({0,255,0}), 0.6,({0,0,255}), 0.8,({255,255,0})}), 0.2,0.0,0.0,1.0 );

Parameter colorrange

colorrange table

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

turbulence


Method random
Method randomgrey

object random()
object random(int seed)
object randomgrey()
object random(greyint seed)

Description

Gives a randomized image;
original ->random() ->random(17) greyed
(same again)
color(red)
(same again)
...red channel

Use with ->grey () or ->color () for one-color-results.

Returns

a new image

See also

test , noise


Method turbulence

void turbulence(array(float|int|array(int)) colorrange)
void turbulence(array(float|int|array(int)) colorrange, int octaves, float scale, float xdiff, float ydiff, float cscale)

Description

gives a new image with the old image's size, filled width a 'turbulence' pattern

The random seed may be different with each instance of pike.

Example:
->turbulence( ({0,({229,204,204}), 0.9,({229,20,20}), 0.9,Color.black}) );

Parameter colorrange

colorrange table

Parameter octaves

default value is 3

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

noise , Image.Color


Method apply_curve

object apply_curve(object array(int(0..255)
object apply_curve(object array(int(0..255)
object apply_curve(object stringchannel, object array(int(0..255)

Description

Apply a lookup-table on all pixels in an image. If only one curve is passed, use the same curve for red, green and blue. If 'channel' is specified, the curve is only applied to the specified channel.

Parameter curve_r
Parameter curve_g
Parameter curve_b
Parameter curve

An array with 256 elements, each between 0 and 255. It is used as a look-up table, if the pixel value is 2 and curve[2] is 10, the new pixel value will be 10.

Parameter channel

one of "red", "green", "blue", "value", "saturation" and "hue".

Returns

a new image object

See also

gamma , `* , modify_by_intensity


Method apply_matrix

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})})
original
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,-2,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, 3
greyed

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object


Method autocrop
Method find_autocrop

object autocrop()
object autocrop(int border)
object autocrop(int border, Color color)
object autocrop(int border, int left, int right, int top, int bottom)
object autocrop(int border, int left, int right, int top, int bottom, Color color)
array(int) find_autocrop()
array(int) find_autocrop(int border)
array(int) find_autocrop(int border, int left, int right, int top, int bottom)

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.

The find_autocrop() function simply returns x1,y1,x2,y2 for the kept area. (This can be used with copy later.)

Parameter border
Parameter left
Parameter right
Parameter top
Parameter 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


Method bitscale

object bitscale(float factor)
object bitscale(float xfactor, float yfactor)

Description

scales the image with a factor, without smoothing. This routine is faster than scale, but gives less correct results

original bitscale(0.75) scale(0.75)

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method bitscale

object bitscale(int newxsize, int newysize)
object bitscale(0, int newysize)
object bitscale(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.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method blur

string blur(int no_pass)

Description

A special case of apply_matrix that creates a blur effect. About four times faster than the generic apply_matrix. @[no_pass] is the number of times the blur matrix is applied.

original blur(1) blur(5)

See also

apply_matrix , grey_blur


Method box

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.

original ->box
(40,10,
10,80,
0,255,0)
->box
(40,10,
10,80,
255,0,0,75)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

box corners

Parameter r
Parameter g
Parameter b

color of the box

Parameter alpha

alpha value

Returns

the object called


Method cast

string cast(string type)

Description

Cast the image to another datatype. Currently supported are string ("rgbrgbrgb...") and array (double array of Image.Color objects).

See also

Image.Color , Image.X


Method change_color

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 (exact match) to another. If non-exact-match is preferred, check distancesq and paste_alpha_color .

Parameter tor
Parameter tog
Parameter tob

destination color and next current color

Parameter fromr
Parameter fromg
Parameter fromb

source color, default is current color

Returns

a new (the destination) image object


Method circle

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 circle on the image. The circle is not antialiased.

original ->circle
(50,50,
30,50,
0,255,255)

Parameter x
Parameter y

circle center

Parameter rx
Parameter ry

circle radius in pixels

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method clear

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

original ->clear
(0,128,255)

Parameter r
Parameter g
Parameter b

color of the new image

Parameter alpha

new default alpha channel value

See also

copy , clone


Method clone

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.

original clone clone(50,50)

Parameter xsize
Parameter ysize

size of (new) image in pixels, called image is cropped to that size

Parameter r
Parameter g
Parameter 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).

Parameter alpha

new default alpha channel value

Returns

the new object

See also

copy , create


Method color

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.

original ->color(128,128,255);

Parameter r
Parameter g
Parameter b

red, green, blue factors

Parameter value

factor

Returns

the new image object

See also

grey , `* , modify_by_intensity


Method copy

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.

original ->copy
(5,5,
XSIZE-6,YSIZE-6)
->copy
(-5,-5,
XSIZE+4,YSIZE+4,
10,75,10)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

The requested new area. Default is the old image size.

Parameter r
Parameter g
Parameter b

color of the new image

Parameter 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


Method create

void Image.Image()
void Image.Image(int xsize, int ysize)
void Image.Image(int xsize, int ysize, Color color)
void Image.Image(int xsize, int ysize, int r, int g, int b)
void Image.Image(int xsize, int ysize, int r, int g, int b, int alpha)
void Image.Image(int xsize, int ysize, string method, method ...)

Description

Initializes a new image object.

Image.Image
(XSIZE,YSIZE)
Image.Image
(XSIZE,YSIZE,255,128,0)

The image can also be calculated from some special methods, for convinience:

channel modes; followed by a number of 1-char-per-pixel strings
or image objects (where red channel will be used),
or an integer value:
  "grey" : make a grey image (needs 1 source: grey)
  "rgb"  : make an rgb image (needs 3 sources: red, green and blue)
  "cmyk" : make a rgb image from cmyk (cyan, magenta, yellow, black)
  "adjusted_cmyk" : make a rgb image from cmyk
           (cyan, magenta, yellow, black) where the colors aren't
           100% pure (C: 009ee0, M: e2007a, Y: ffec00, K: 1a171b).
 
generate modes; all extra arguments is given to the
generation function. These has the same name as the method:
  "test ,"
  "gradients "
  "noise "
  "turbulence "
  "random "
  "randomgrey "
specials cases:
  "tuned_box " (coordinates is automatic)

Parameter xsize
Parameter ysize

size of (new) image in pixels

Parameter color
Parameter r
Parameter g
Parameter b

background color (will also be current color), default color is black

Parameter alpha

default alpha channel value

Bugs

SIGSEGVS can be caused if the size is too big, due to unchecked overflow - (xsize*ysize)&MAXINT is small enough to allocate.

See also

copy , clone , Image.Image


Method distancesq

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

original distance² to cyan ...to purple ...to yellow

Parameter r
Parameter g
Parameter b

red, green, blue coordinates

Returns

the new image object

See also

select_from


Method gamma

object gamma(float g)
object gamma(float gred, object floatggreen, object floatgblue)

Description

Calculate pixels in image by gamma curve.

Intensity of new pixels are calculated by:
i' = i^g

For example, you are viewing your image on a screen with gamma 2.2. To correct your image to the correct gamma value, do something like:

my_display_image(my_image()->gamma(1/2.2);

Parameter g
Parameter gred
Parameter ggreen
Parameter gblue

gamma value

Returns

a new image object

See also

grey , `* , color


Method getpixel

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

Description

Parameter x
Parameter y

position of the pixel

Returns

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


Method gradients

int gradients(array(int) point, object ...)
int gradients(array(int) point, object ..., object floatgrad)

Description

original 2 color
gradient
10 color
gradient
3 colors,
grad=4.0
3 colors,
grad=1.0
3 colors,
grad=0.25

Returns

the new image


Method grey

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

Description

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

original ->grey(); ->grey(0,0,255);

Parameter r
Parameter g
Parameter 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


Method grey_blur

object grey_blur(int no_pass)

Description

Works like blur, but only operates on the r color channel. A faster alternative to blur for grey scale images. @[no_pass] is the number of times the blur matrix is applied.

original grey_blur(1) grey_blur(5)

See also

blur


Method rgb_to_hsv
Method hsv_to_rgb

object rgb_to_hsv()
object hsv_to_rgb()

Description

Converts RGB data to HSV data, or the other way around. When converting to HSV, the resulting data is stored like this: pixel.r = h; pixel.g = s; pixel.b = v;

When converting to RGB, the input data is asumed to be placed in the pixels as above.

original ->hsv_to_rgb(); ->rgb_to_hsv();
tuned box (below) the rainbow (below) same, but rgb_to_hsv()

HSV to RGB calculation:

in = input pixel
out = destination pixel
h=-pos*c_angle*3.1415/(float)NUM_SQUARES;
out.r=(in.b+in.g*cos(in.r));
out.g=(in.b+in.g*cos(in.r + pi*2/3));
out.b=(in.b+in.g*cos(in.r + pi*4/3));

RGB to HSV calculation: Hmm.

Example: Nice rainbow.

 object i = Image.Image(200,200);
 i = i->tuned_box(0,0, 200,200,
                  ({ ({ 255,255,128 }), ({ 0,255,128 }),
                     ({ 255,255,255 }), ({ 0,255,255 })}))
      ->hsv_to_rgb();
 

Returns

the new image object


Method invert

object invert()

Description

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

original ->invert(); ->rgb_to_hsv()->invert()->hsv_to_rgb();

Returns

the new image object


Method line

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.

original ->line
(50,10,
10,50,
255,0,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

line endpoints

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method modify_by_intensity

object modify_by_intensity(int r, int g, int b, 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.

original ->grey()->modify_by_intensity(1,0,0, 0,({255,0,0}),({0,255,0}));

Parameter r
Parameter g
Parameter b

red, green, blue intensity factors

Parameter v1
Parameter vn

destination color

Returns

the new image object

See also

grey , `* , color


Method outline
Method outline_mask

object outline()
object outline(int olr, int olg, int olb)
object outline(int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline(array(array(int)) mask)
object outline(array(array(int)) mask, int olr, int olg, int olb)
object outline(array(array(int)) mask, int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline_mask()
object outline_mask(int bkgr, int bkgg, int bkgb)
object outline_mask(array(array(int)) mask)
object outline_mask(array(array(int)) mask, int bkgr, int bkgg, int bkgb)

Description

Makes an outline of this image, ie paints with the given color around the non-background pixels.

Default is to paint above, below, to the left and the right of these pixels.

You can also run your own outline mask.

The outline_mask function gives the calculated outline as an alpha channel image of white and black instead.

original masked
through
threshold
...and
outlined
with red

Parameter mask

mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}).

Parameter olr
Parameter olg
Parameter olb

outline color. Default is current.

Parameter bkgr
Parameter bkgg
Parameter bkgb

background color (what color to outline to); default is color of pixel 0,0.

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

no antialias!


Method write_lsb_rgb
Method write_lsb_grey
Method read_lsb_rgb
Method read_lsb_grey

object write_lsb_rgb(string what)
object write_lsb_grey(string what)
string read_lsb_rgb()
string read_lsb_grey()

Description

These functions read/write in the least significant bit of the image pixel values. The _rgb() functions read/write on each of the red, green and blue values, and the grey keeps the same lsb on all three.

The string is nullpadded or cut to fit.

Parameter what

the hidden message

Returns

the current object or the read string


Method rgb_to_yuv
Method yuv_to_rgb

object rgb_to_yuv()
object yuv_to_rgb()

Description

Converts RGB data to YUV (YCrCb) data, or the other way around. When converting to YUV, the resulting data is stored like this: pixel.r = v (cr); pixel.g = y; pixel.b = u (cb);

When converting to RGB, the input data is asumed to be placed in the pixels as above.

original ->yuv_to_rgb(); ->rgb_to_yuv();
tuned box (below) the rainbow (below) same, but rgb_to_yuv()

RGB to YUB calculation (this follows CCIR.601):

in = input pixel
out = destination pixel
Ey = 0.299*in.r+0.587*in.g+0.114*in.b
Ecr = 0.713*(in.r - Ey) = 0.500*in.r-0.419*in.g-0.081*in.b
Ecb = 0.564*(in.b - Ey) = -0.169*in.r-0.331*in.g+0.500*in.b
out.r=0.875*Ecr+128
out.g=0.86*Ey+16
out.b=0.875*Ecb+128

Example: Nice rainbow.

 object i = Image.Image(200,200);
 i = i->tuned_box(0,0, 200,200,
                  ({ ({ 255,255,128 }), ({ 0,255,128 }),
                     ({ 255,255,255 }), ({ 0,255,255 })}))
      ->yuv_to_rgb();
 

Returns

the new image object


Method select_from

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.

35, 35, 16 35, 35, 32 35, 35, 64 35, 35, 96 35, 35, 128 35, 35, 192 35, 35, 256

original original * select_from(35,35,200)

Parameter x
Parameter y

originating pixel in the image

Returns

the new image object

See also

distancesq


Method setcolor

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

Description

set the current color

Parameter r
Parameter g
Parameter b

new color

Parameter alpha

new alpha value

Returns

the object called


Method setpixel

object setpixel(int x, int y)
object setpixel(int x, int y, Image.Color c)
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)

Description

original ->setpixel
(10,10,
255,0,0)

Parameter x
Parameter y

position of the pixel

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method test

object test()
object test(int seed)

Description

Generates a test image, currently random gradients.

original ->test() ...and again

Returns

the new image

Note

May be subject to change or cease without prior warning.

See also

gradients , tuned_box


Method threshold

object threshold()
object threshold(int level)
object threshold(int r, int g, int b)
object threshold(Color color)

Description

Makes a black-white image.

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

This method works fine with the grey method.

If no arguments are given, it will paint all non-black pixels white. (Ie, default is 0,0,0.)

original ->threshold(100); ->threshold(0,100,0);

Returns

the new image object

Note

The above statement "any ..." was changed from "all ..." in Pike 0.7 (9906). It also uses 0,0,0 as default input, instead of current color. This is more useful.

See also

grey


Method tuned_box

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.

original tuned box solid tuning
(blue,red,green,yellow)
tuning transparency
(as left + 255,128,128,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

rectangle corners

Parameter 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


Method xsize

int xsize()

Returns

the width of the image


Method ysize

int ysize()

Returns

the height of the image


Method paste

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

Description

Pastes a given image over the current image.

Parameter image

image to paste (may be empty, needs to be an image object)

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste_alpha , paste_alpha_color


Method paste_alpha

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.

Parameter image

image to paste

Parameter alpha

alpha channel value

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste , paste_alpha_color


Method paste_alpha_color

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)
object paste_alpha_color(object mask, Color color)
object paste_alpha_color(object mask, Color color, 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.

Parameter mask

mask image

Parameter r
Parameter g
Parameter b

what color to paint with; default is current

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste_alpha , paste_alpha_color


Method paste_mask

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.

Parameter image

image to paste

Parameter mask

mask image

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste , paste_alpha , paste_alpha_color


Method apply_max

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

Description

This is the same as apply_matrix, but it uses the maximum instead.

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions


Method make_ascii

string make_ascii(object orient1, object orient2, object orient3, object orient4, int|void tlevel, int|void xsize, int|void ysize)

Description

This method creates a string that looks like the image. Example:

   //Stina is an image with a cat.
   array(object) Stina4=Stina->orient4();
   Stina4[1]*=215;
   Stina4[3]*=215;
   string foo=Stina->make_ascii(@Stina4,40,4,8);

Returns

some nice acsii-art.

Note

experimental status; may not be exact the same output in later versions

      |      /    -    \
     hue=  0     64   128  192  (=red in an hsv image)

See also

orient , orient4


Method match

object match(int|float scale, object objectneedle)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert)
object match(int|float scale, object objectneedle, object objecthaystack_avoid, object intfoo)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert, object objecthaystack_avoid, object intfoo)

Description

This method creates an image that describes the match in every pixel in the image and the needle-Image.

   new pixel value =
     sum( my_abs(needle_pixel-haystack_pixel))

The new image only have the red rgb-part set.

Parameter scale

Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle.

Parameter needle

The image to use for the matching.

Parameter haystack_cert

This image should be the same size as the image itselves. A non-white-part of the haystack_cert-image modifies the output by lowering it.

Parameter needle_cert

The same, but for the needle-image.

Parameter foo
Parameter haystack_avoid

This image should be the same size as the image itselves. If foo is less than the red value in haystack_avoid the corresponding matching-calculating is not calculated. The avoided parts are drawn in the color 0,100,0.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

See also

phasev , phaseh


Method phaseh
Method phasev
Method phasevh
Method phasehv

object phaseh()
object phasev()
object phasevh()
object phasehv()

Description

Draws images describing the phase of the current image. phaseh gives the horizontal phase and phasev the vertical phase.

phaseh gives an image where

       max  falling   min  rising
value=  0     64      128   192

0 is set if there is no way to determine if it is rising or falling. This is done for the every red, green and blue part of the image.

Phase images can be used to create ugly effects or to find meta-information in the orginal image.

original phaseh() phasev() phasevh() phasehv()

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

Bugs

0 should not be set as explained above.


Method dct

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...

Parameter newx
Parameter 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...

It doesn't use any fct (compare: fft) algorithms.


Method orient
Method orient4

object orient(void|array(object) something)
array(object) orient4()

Description

Draws images describing the orientation of the current image.

orient gives an HSV image (run a hsv_to_rgb pass on it to get a viewable image). corresponding to the angle of the orientation:

      |      /    -    \
     hue=  0     64   128  192  (=red in an hsv image)
         purple cyan green red
Red, green and blue channels are added and not compared separately.

If you first use orient4 you can give its output as input to this function.

The orient4 function gives back 4 image objects, corresponding to the amount of different directions, see above.

Returns

an image or an array of the four new image objects

Note

experimental status; may not be exact the same output in later versions


Method polyfill

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

Description

fills an area with the current color

Parameter curve

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

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

Image.Image(100,100)->setcolor(255,0,0,128)->
  polyfill( ({ 20,20, 80,20, 80,80 }) );

Returns

the current object

Note

Lines in the polygon may not be crossed without the crossing coordinate specified in both lines.

Bugs

Inverted lines reported on Intel and Alpha processors.

See also

setcolor


Method average
Method min
Method max
Method sum
Method sumf

array(float) average()
array(int) min()
array(int) max()
array(int) sum()
array(float) sumf()

Description

Gives back the average, minimum, maximum color value, and the sum of all pixel's color value.

Note

sum() values can wrap! Most systems only have 31 bits available for positive integers. (Meaning, be careful with images that have more than 8425104 pixels.)

average() and sumf() may also wrap, but on a line basis. (Meaning, be careful with images that are wider than 8425104 pixels.) These functions may have a precision problem instead, during to limits in the 'double' C type and/or 'float' Pike type.


Method find_min
Method find_max

array(int) find_min()
array(int) find_max()
array(int) find_min(int r, int g, int b)
array(int) find_max(int r, int g, int b)

Description

Gives back the position of the minimum or maximum pixel value, weighted to grey.

Parameter r
Parameter g
Parameter b

weight of color, default is r=87,g=127,b=41, same as the grey () method.


Method `/
Method `%

object `/(object operand)
object `/(Color color)
object `/(int value)
object `%(object operand)
object `%(Color color)
object `%(int value)

Description

Divides pixel values and creates a new image from the result or the rest.

Parameter operand

the other image to divide with; the images must have the same size.

Parameter color
Parameter value

if specified as color or value, it will act as a whole image of that color (or value).

Returns

the new image object

Note

It isn't possible to do a modulo 256 either. (why?)

See also

`- , `+ , `| , `&amp; , `* , Image.Layer


Method `&

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

Description

makes a new image out of the minimum pixels values

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+ , `| , `* , Image.Layer


Method `==
Method `<
Method `>

int `==(object operand)
int `==(array(int) color)
int `==(int value)
int `<(object operand)
int `<(array(int) color)
int `<(int value)
int `>(object operand)
int `>(array(int) color)
int `>(int value)

Description

Compares an image with another image or a color.

Comparision is strict and on pixel-by-pixel basis. (Means if not all pixel r,g,b values are correct compared with the corresponding pixel values, 0 is returned.)

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

true (1) or false (0).

Note

`< or `> on empty ("no image") image objects or images with different size will result in an error. `== is always true on two empty image objects and always false if one and only one of the image objects is empty or the images differs in size.

a>=b and a<=b between objects is equal to !(a<b) and !(a>b), which may not be what you want (since both < and > can return false, comparing the same images).

See also

`- , `+ , `| , `* , `&amp;


Method `*

object `*(object operand)
object `*(array(int) color)
object `*(int value)
object `*(float 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;

Parameter operand

the other image to multiply with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+ , `| , `&amp; , Image.Layer


Method `+

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

Description

adds two images; values are truncated at 255.

Parameter operand

the image which to add.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `| , `&amp; , `* , Image.Layer


Method `-

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

Description

makes a new image out of the difference

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`+ , `| , `&amp; , `* , Image.Layer , min , max , `==


Method `|

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

Description

makes a new image out of the maximum pixels values

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+ , `&amp; , `* , Image.Layer

  CLASS Image.Layer

See also

layers


Method set_image
Method image
Method alpha

object set_image(Image.Image image)
object set_image(Image.Image image, Image.Image alpha_channel)
object|int(0..) image()
object|int(0..) alpha()

Description

Set/change/get image and alpha channel for the layer. You could also cancel the channels giving 0 instead of an image object.

Note

image and alpha channel must be of the same size, or canceled.


Method set_alpha_value
Method alpha_value

object set_alpha_value(float value)
float alpha_value()

Description

Set/get the general alpha value of this layer. This is a float value between 0 and 1, and is multiplied with the alpha channel.


Method autocrop
Method find_autocrop

object autocrop()
object autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)
array(int) find_autocrop()
array(int) find_autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)

Description

This crops (of finds) a suitable crop, non-destructive crop. The layer alpha channel is checked, and edges that is transparent is removed.

(What really happens is that the image and alpha channel is checked, and edges equal the fill setup is cropped away.)

find_autocrop () returns an array of xoff,yoff,xsize,ysize, which can be fed to crop ().

Note

A tiled image will not be cropped at all.

left...bottom arguments can be used to tell what sides cropping are ok on.

See also

crop , Image.Image->autocrop


Method set_mode
Method mode
Method available_modes

object set_mode(string mode)
string mode()
array(string) available_modes()

Description

Set/get layer mode. Mode is one of these:

All channels are calculated separately, if nothing else is specified.
top layer
bottom layer
normal
D=L applied with alpha: D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=(aL+(1-aL)*aS)
add
D=L+S applied with alpha, aD=aS
subtract
D=S-L applied with alpha, aD=aS
multiply
D=S*L applied with alpha, aD=aS
divide
D=S/L applied with alpha, aD=aS
negdivide
D=1.0-S/L applied with alpha, aD=aS
modulo
D=S%L applied with alpha, aD=aS
invsubtract
D=L-S applied with alpha, aD=aS
invdivide
D=L/S applied with alpha, aD=aS
invmodulo
D=L%S applied with alpha, aD=aS
imultiply
D=(1-L)*S applied with alpha, aD=aS
idivide
D=S/(1-L) applied with alpha, aD=aS
invidivide
D=L/(1-S) applied with alpha, aD=aS
difference
D=abs(L-S) applied with alpha, aD=aS
max
D=max(L,S) applied with alpha, aD=aS
min
D=min(L,S) applied with alpha, aD=aS
bitwise_and
D=L&amp;S applied with alpha, aD=aS
bitwise_or
D=L|S applied with alpha, aD=aS
bitwise_xor
D=L^S applied with alpha, aD=aS
replace
D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=aS
red
Dr=(Lr*aLr+Sr*(1-aLr)*aSr) / (aLr+(1-aLr)*aSr), Dgb=Sgb, aD=aS
green
Dg=(Lg*aLg+Sg*(1-aLg)*aSg) / (aLg+(1-aLg)*aSg), Drb=Srb, aD=aS
blue
Db=(Lb*aLb+Sb*(1-aLb)*aSb) / (aLb+(1-aLb)*aSb), Drg=Srg, aD=aS
hardlight
Like photoshop hardlight layer mode, aD=aS
replace_hsv
Dhsv=Lhsv apply with alpha, aD=aS
hue
Dh=Lh apply with alpha, Dsv=Lsv, aD=aS
saturation
Ds=Ls apply with alpha, Dhv=Lhv, aD=aS
value
Dv=Lv apply with alpha, Dhs=Lhs, aD=aS
color
Dhs=Lhs apply with alpha, Dv=Lv, aD=aS
value_mul
Dv=Lv*Sv apply with alpha, Dhs=Lhs, aD=aS
darken
Dv=min(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS
lighten
Dv=max(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS
saturate
Ds=max(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS
desaturate
Ds=min(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS
hls_replace
Dhls=Lhls apply with alpha, aD=aS
hls_hue
Dh=Lh apply with alpha, Dsv=Lsv, aD=aS
hls_saturation
Ds=Ls apply with alpha, Dhv=Lhv, aD=aS
hls_lightness
Dl=Ll apply with alpha, Dhs=Lhs, aD=aS
hls_color
Dhs=Lhs apply with alpha, Dl=Ll, aD=aS
hls_lightness_mul
Dl=Ll*Sl apply with alpha, Dhs=Lhs, aD=aS
hls_darken
Dl=min(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS
hls_lighten
Dl=max(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS
hls_saturate
Ds=max(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS
hls_desaturate
Ds=min(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS
dissolve
i=random 0 or 1, D=i?L:S, aD=i+aS
behind
D=(S*aS+L*(1-aS)*aL) / (aS+(1-aS)*aL), aD=(aS+(1-aS)*aL); simply swap S and L
erase
D=S, aD=aS*(1-aL)
screen
1-(1-S)*(1-L) applied with alpha, aD=aS
overlay
(1-(1-a)*(1-b)-a*b)*a+a*b applied with alpha, aD=aS
burn_alpha
aD=aL+aS applied with alpha, D=L+S; experimental, may change or be removed
equal
each channel D=max if L==S, 0 otherwise, apply with alpha
not_equal
each channel D=max if L!=S, 0 otherwise, apply with alpha
less
each channel D=max if L<S, 0 otherwise, apply with alpha
more
each channel D=max if L>S, 0 otherwise, apply with alpha
less_or_equal
each channel D=max if L<=S, 0 otherwise, apply with alpha
more_or_equal
each channel D=max if L>=S, 0 otherwise, apply with alpha
logic_equal
logic: D=white and opaque if L==S, black and transparent otherwise
logic_not_equal
logic: D=white and opaque if any L!=S, black and transparent otherwise
logic_strict_less
logic: D=white and opaque if all L<S, black and transparent otherwise
logic_strict_more
logic: D=white and opaque if all L>S, black and transparent otherwise
logic_strict_less_equal
logic: D=white and opaque if all L<=L, black and transparent otherwise
logic_strict_more_equal
logic: D=white and opaque if all L>=L, black and transparent otherwise

available_modes () simply gives an array containing the names of these modes.

Note

image and alpha channel must be of the same size, or canceled.


Method cast

mapping(string:mixed)|string cast()

Description

([ "xsize":int, "ysize":int, "image":image, "alpha":image, "xoffset":int, "yoffset":int, "fill":image, "fill_alpha":image "tiled":int, "mode":string ])


Method clone

object clone()

Description

Creates a copy of the called object.

Returns

the copy


Method create

void Image.Layer(object image, object alpha, string mode)
void Image.Layer(mapping info)
void Image.Layer()
void Image.Layer(int xsize, int ysize, object color)
void Image.Layer(object color)

Description

The Layer construct either three arguments, the image object, alpha channel and mode, or a mapping with optional elements:

"image":image,
        // default: black
 
"alpha":alpha,
        // alpha channel object
        // default: full opaque
 
"mode":string mode,
        // layer mode, see mode .
        // default: "normal"
 
"alpha_value":float(0.0-1.0),
        // layer general alpha value
        // default is 1.0; this is multiplied
        // with the alpha channel.
 
"xoffset":int,
"yoffset":int,
        // offset of this layer
 
"fill":Color,
"fill_alpha":Color,
        // fill color, ie what color is used
        // "outside" the image. default: black
        // and black (full transparency).
 
"tiled":int(0|1),
        // select tiling; if 1, the image
        // will be tiled. deafult: 0, off
The layer can also be created "empty", either giving a size and color - this will give a filled opaque square, or a color, which will set the "fill" values and fill the whole layer with an opaque color.

All values can be modified after object creation.

Note

image and alpha channel must be of the same size.


Method crop

object crop(int xoff, int yoff, int xsize, int ysize)

Description

Crops this layer at this offset and size. Offset is not relative the layer offset, so this can be used to crop a number of layers simuntaneously.

The fill values are used if the layer is enlarged.

Returns

a new layer object

Note

The new layer object may have the same image object, if there was no cropping to be done.


Method description

array(string) description()

Description

Layer descriptions


Method set_fill
Method fill
Method fill_alpha

object set_fill(Color color)
object set_fill(Color color, Color alpha)
object fill()
object fill_alpha()

Description

Set/query fill color and alpha, ie the color used "outside" the image. This is mostly useful if you want to "frame" a layer.


Method set_misc_value
Method get_misc_value

mixed set_misc_value(object mixedwhat, object mixedto)
mixed get_misc_value(object mixedwhat)

Description

Set or query misc. attributes for the layer.

As an example, the XCF and PSD image decoders set the 'name' attribute to the name the layer had in the source file.


Method set_offset
Method xoffset
Method yoffset

object set_offset(int x, int y)
int xoffset()
int yoffset()

Description

Set/query layer offset.


Method set_tiled
Method tiled

object set_tiled(int yes)
int tiled()

Description

Set/query tiled flag. If set, the image and alpha channel will be tiled rather then framed by the fill values.


Method xsize
Method ysize

int xsize()
int ysize()

Description

Query layer offset. This is the same as layer image/alpha image size.

  CLASS Image.Font

Description

Short technical documentation on a font file: This object adds the text-drawing and -creation capabilities of the Image module.

For simple usage, see write and load .

Note

	       struct file_head
	       {
		  unsigned INT32 cookie;   - 0x464f4e54
		  unsigned INT32 version;  - 1
		  unsigned INT32 chars;    - number of chars
		  unsigned INT32 height;   - height of font
		  unsigned INT32 baseline; - font baseline
		  unsigned INT32 o[1];     - position of char_head's
	       } *fh;
	       struct char_head
	       {
		  unsigned INT32 width;    - width of this character
		  unsigned INT32 spacing;  - spacing to next character
		  unsigned char data[1];   - pixmap data (1byte/pixel)
	       } *ch;

            version 2:


            	  On-disk syntax (everything in N.B.O), int is 4 bytes, a byte is 8 bits:

            pos
            	0   int cookie = 'FONT';     or 0x464f4e54
            	4   int version = 2;         1 was the old version without the last four chars
            	8   int numchars;            Always 256 in this version of the dump program
            12   int height;              in (whole) pixels
            16   int baseline;            in (whole) pixels
            20   char direction;          1==right to left, 0 is left to right
            21   char format;             Font format
            22   char colortablep;        Colortable format
            23   char kerningtablep;      Kerning table format

            24   int offsets[numchars];   pointers into the data, realative to &cookie.
            	    [colortable]
            	    [kerningtable]

            	  At each offset:


            0   int width;               in pixels
            4   int spacing;             in 1/1000:th of a pixels
            8   char data[];             Enough data to plot width * font->height pixels
            				    Please note that if width is 0, there is no data.

            Font formats:
            	id type
            	 0 Raw 8bit data
            	 1 RLE encoded data,  char length, char data,   70% more compact than raw data
            	 2 ZLib compressed data                         60% more compact than RLE

            Colortable types:
            	 0 No colortable		 (the data is an alpha channel)
            	 1 24bit RGB with alpha         (index->color, 256*4 bytes, rgba)
            	 2 8bit Greyscale with alpha    (index->color, 256*2 bytes)

            Kerningtable types:
            	 0 No kerning table
            	 1 numchars*numchars entries, each a signed char with the kerning value
            	 2 numchar entries, each with a list of kerning pairs, like this:
            	    int len
            	    len * (short char, short value)
 

See also

Image , Image.Image


Method load

Image.Font|int load(string filename)

Description

Loads a font file to this font object.

Returns

Returns zero upon failure and a font object upon success.

Parameter filename

The path to the font file.

See also

write


Method create

void Image.Font(string filename)

Description

Loads a font file to this font object. Similar to load() .


Method write

Image.Image write(string text, string ... more_text_lines)

Description

Writes some text; thus creating an image object that can be used as mask or as a complete picture. One or more text lines may be provided.

See also

text_extents , load , Image.Image->paste_mask , Image.Image->paste_alpha_color


Method height

int height()

Description

Returns the font height.

See also

baseline , text_extents


Method text_extents

array(int) text_extents(string text, string ... more_text_lines)

Description

Calculate extents of a text-image, that would be created by calling write with the same arguments. One or more lines of text may be provided.

Returns
Array
int width
int height

See also

write , height , baseline


Method set_xspacing_scale
Method set_yspacing_scale

void set_xspacing_scale(float scale)
void set_yspacing_scale(float scale)

Description

Set spacing scale to write characters closer or more far away. This does not change scale of character, only the space between them.


Method baseline

int baseline()

Description

Returns font baseline (pixels from top)

See also

height , text_extents


Method center

void center()

FIXME

Document this function.


Method right

void right()

FIXME

Document this function.


Method left

void left()

FIXME

Document this function.

  CLASS Image.Colortable

Description

This object keeps colortable information, mostly for image re-coloring (quantization).

The object has color reduction, quantisation, mapping and dithering capabilities.

See also

Image , Image.Image , Image.Font , Image.GIF


Method create
Method add

void Image.Colortable()
void Image.Colortable(array(array(int)) colors)
void Image.Colortable(Image.Image image, int number)
void Image.Colortable(Image.Image image, int number, array(array(int)) needed)
void Image.Colortable(int r, int g, int b)
void Image.Colortable(int r, int g, int b, object array(int)
object add(array(array(int)) colors)
object add(Image.Image image, int number)
object add(Image.Image image, int number, array(array(int)) needed)
object add(int r, int g, int b)
object add(int r, int g, int b, object array(int)

Description

create initiates a colortable object. Default is that no colors are in the colortable.

add takes the same argument(s) as create , thus adding colors to the colortable.

The colortable is mostly a list of colors, or more advanced, colors and weight.

The colortable could also be a colorcube, with or without additional scales. A colorcube is the by-far fastest way to find colors.

Example:

ct=colortable(my_image,256); // the best 256 colors
ct=colortable(my_image,256,({0,0,0})); // black and the best other 255
 
ct=colortable(({({0,0,0}),({255,255,255})})); // black and white
 
ct=colortable(6,7,6); // a colortable of 252 colors
ct=colortable(7,7,5, ({0,0,0}),({255,255,255}),11);
        // a colorcube of 245 colors, and a greyscale of the rest -> 256

Parameter colors

list of colors

Parameter image

source image

Parameter number

number of colors to get from the image

0 (zero) gives all colors in the image.

Default value is 256.

Parameter needed

needed colors (to optimize selection of others to these given)

this will add to the total number of colors (see argument 'number')

Parameter r
Parameter g
Parameter b

size of sides in the colorcube, must (of course) be equal or larger than 2 - if smaller, the cube is ignored (no colors). This could be used to have only scales (like a greyscale) in the output.

Parameter fromi
Parameter toi
Parameter stepi

This is to add the possibility of adding a scale of colors to the colorcube; for instance a grayscale using the arguments ({0,0,0}),({255,255,255}),17, adding a scale from black to white in 17 or more steps.

Colors already in the cube is used again to add the number of steps, if possible.

The total number of colors in the table is therefore r*b*g+step1+...+stepn.

Note

max hash size is (probably, set by a #define) 32768 entries, giving maybe half that number of colors as maximum.


Method cast

object cast(string to)

Description

cast the colortable to an array or mapping, the array consists of Image.Color objects and are not in index order. The mapping consists of index:Image.Color pairs, where index is the index (int) of that color.

example: (mapping)Image.Colortable(img)

Parameter to

must be "string", "array" or "mapping".


Method corners

array(object) corners()

Description

Gives the eight corners in rgb colorspace as an array. The "black" and "white" corners are the first two.


Method cubicles

object cubicles()
object cubicles(int r, int g, int b)
object cubicles(int r, int g, int b, int accuracy)

Description

Set the colortable to use the cubicles algorithm to lookup the closest color. This is a mostly very fast and very accurate way to find the correct color, and the default algorithm.

The colorspace is divided in small cubes, each cube containing the colors in that cube. Each cube then gets a list of the colors in the cube, and the closest from the corners and midpoints between corners.

When a color is needed, the algorithm first finds the correct cube and then compares with all the colors in the list for that cube.

example: colors=Image.Colortable(img)->cubicles();

algorithm time: between O[m] and O[m * n], where n is numbers of colors and m is number of pixels

The arguments can be heavy trimmed for the usage of your colortable; a large number (10×10×10 or bigger) of cubicles is recommended when you use the colortable repeatedly, since the calculation takes much more time than usage.

recommended values:

image size  setup
100×100     cubicles(4,5,4) (default)
1000×1000   cubicles(12,12,12) (factor 2 faster than default)

In some cases, the full method is faster.

original default cubicles,
16 colors
accuracy=200

Parameter r
Parameter g
Parameter b

Size, ie how much the colorspace is divided. Note that the size of each cubicle is at least about 8b, and that it takes time to calculate them. The number of cubicles are r*g*b, and default is 4,5,4, ie 80 cubicles. This works good for 200±100 colors.

Parameter accuracy

Accuracy when checking sides of cubicles. Default is 16. A value of 1 gives complete accuracy, ie cubicle() method gives exactly the same result as full(), but takes (in worst case) 16× the time to calculate.

Returns

the object being called

Note

this method doesn't figure out the cubicles, this is done on the first use of the colortable.

Not applicable to colorcube types of colortable.


Method floyd_steinberg

object floyd_steinberg()
object floyd_steinberg(int bidir, int|float forward, int|float downforward, int|float down, int|float downback, int|float factor)

Description

Set dithering method to floyd_steinberg.

The arguments to this method is for fine-tuning of the algorithm (for computer graphics wizards).

original floyd_steinberg to a 4×4×4 colorcube floyd_steinberg to 16 chosen colors

Parameter bidir

Set algorithm direction of forward. -1 is backward, 1 is forward, 0 for toggle of direction each line (default).

Parameter forward
Parameter downforward
Parameter down
Parameter downback

Set error correction directions. Default is forward=7, downforward=1, down=5, downback=3.

Parameter factor

Error keeping factor. Error will increase if more than 1.0 and decrease if less than 1.0. A value of 0.0 will cancel any dither effects. Default is 0.95.

Returns

the object being called


Method full

object full()

Description

Set the colortable to use full scan to lookup the closest color.

example: colors=Image.Colortable(img)->full();

algorithm time: O[n*m], where n is numbers of colors and m is number of pixels

Returns

the object being called

Note

Not applicable to colorcube types of colortable.

See also

cubicles , map


Method greyp

int(0..1) greyp()

Description

Returns true if this colortable only contains greyscale.


Method image

object image()

Description

cast the colortable to an image object

each pixel in the image object is an entry in the colortable

Returns

the resulting image object


Method map
Method `*
Method ``*

object map(object image)
object `*(object image)
object ``*(object image)
object map(string data, int xsize, int ysize)
object `*(string data, int xsize, int ysize)
object ``*(string data, int xsize, int ysize)

Description

Map colors in an image object to the colors in the colortable, and creates a new image with the closest colors.

no dither
floyd_steinberg dither
ordered dither
randomcube dither
original 2 4 8 16 32 colors

Returns

a new image object

Note

Flat (not cube) colortable and not 'full ' method: this method does figure out the data needed for the lookup method, which may take time the first use of the colortable - the second use is quicker.

See also

cubicles , full


Method nodither

object nodither()

Description

Set no dithering (default).

Returns

the object being called


Method ordered

object ordered()
object ordered(int r, int g, int b)
object ordered(int r, int g, int b, int xsize, int ysize)
object ordered(int r, int g, int b, int xsize, int ysize, int x, int y)
object ordered(int r, int g, int b, int xsize, int ysize, int rx, int ry, int gx, int gy, int bx, int by)

Description

Set ordered dithering, which gives a position-dependent error added to the pixel values.

original mapped to
Image.Colortable(6,6,6)->
ordered
(42,42,42,2,2)
ordered() ordered
(42,42,42, 8,8,
0,0, 0,1, 1,0)

Parameter r
Parameter g
Parameter b

The maximum error. Default is 32, or colorcube steps (256/size).

Parameter xsize
Parameter ysize

Size of error matrix. Default is 8×8. Only values which factors to multiples of 2 and 3 are possible to choose (2,3,4,6,8,12,...).

Parameter x
Parameter y
Parameter rx
Parameter ry
Parameter gx
Parameter gy
Parameter bx
Parameter by

Offset for the error matrix. x and y is for both red, green and blue values, the other is individual.

Returns

the object being called

See also

randomcube , nodither , floyd_steinberg , create


Method randomcube
Method randomgrey

object randomcube()
object randomcube(int r, int g, int b)
object randomgrey()
object randomgrey(int err)

Description

Set random cube dithering. Color choosen is the closest one to color in picture plus (flat) random error; color±random(error).

The randomgrey method uses the same random error on red, green and blue and the randomcube method has three random errors.

original mapped to
Image.Colortable(4,4,4)->
randomcube() randomgrey()

Parameter r
Parameter g
Parameter b
Parameter err

The maximum error. Default is 32, or colorcube step.

Returns

the object being called

Note

randomgrey method needs colorcube size to be the same on red, green and blue sides to work properly. It uses the red colorcube value as default.

See also

ordered , nodither , floyd_steinberg , create


Method reduce
Method reduce_fs

object reduce(int colors)
object reduce_fs(int colors)

Description

reduces the number of colors

All needed (see create ) colors are kept.

reduce_fs creates and keeps the outmost corners of the color space, to improve floyd-steinberg dithering result. (It doesn't work very well, though.)

Parameter colors

target number of colors

Returns

the new Colortable object

Note

this algorithm assumes all colors are different to begin with (!)

reduce_fs keeps the "corners" as "needed colors".

See also

corners


Method rigid

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

Description

Set the colortable to use the "rigid" method of looking up colors.

This is a very simple way of finding the correct color. The algorithm initializes a cube with r x g x b colors, where every color is chosen by closest match to the corresponding coordinate.

This format is not recommended for exact match, but may be usable when it comes to quickly view pictures on-screen.

It has a high init-cost and low use-cost. The structure is initiated at first usage.

Returns

the object being called

Note

Not applicable to colorcube types of colortable.

See also

cubicles , map , full


Method spacefactors

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

Description

Colortable tuning option, this sets the color space distance factors. This is used when comparing distances in the colorspace and comparing grey levels.

Default factors are 3, 4 and 1; blue is much darker than green. Compare with Image.Image->grey ().

Returns

the object being called

Note

This has no sanity check. Some functions may bug if the factors are to high - color reduction functions sums grey levels in the image, this could exceed maxint in the case of high factors. Negative values may also cause strange effects. *grin*


Method `+

object `+(object with, object mixed...more)

Description

sums colortables

Parameter with

Colortable object with colors to add

Returns

the resulting new Colortable object


Method `-

object `-(object with, object mixed...more)

Description

subtracts colortables

Parameter with

Colortable object with colors to subtract

Returns

the resulting new Colortable object

  Module Image.Color

Description

This module keeps names and easy handling for easy color support. It gives you an easy way to get colors from names.

A color is here an object, containing color information and methods for conversion, see below.

Image.Color can be called to make a color object. Image.Color() takes the following arguments:

    Image.Color(string name)          // "red"
    Image.Color(string prefix_string) // "lightblue"
    Image.Color(string hex_name)      // "#ff00ff"
    Image.Color(string cmyk_string)   // "%17,42,0,19.4"
    Image.Color(string hsv_string)    // "%@327,90,32"
    Image.Color(int red, int green, int blue)
    

The color names available can be listed by using indices on Image.Color. The colors are available by name directly as Image.Color.name, too:

    ...Image.Color.red...
    ...Image.Color.green...
    or, maybe
    import Image.Color;
    ...red...
    ...green...
    ...lightgreen...
    

Giving red, green and blue values is equal to calling Image.Color.rgb ().

The prefix_string method is a form for getting modified colors, it understands all modifiers (light , dark , bright , dull and neon ). Simply use "method"+"color"; (as in lightgreen, dullmagenta, lightdullorange).

The hex_name form is a simple #rrggbb form, as in HTML or X-program argument. A shorter form (#rgb) is also accepted. This is the inverse to the Image.Color.Color->hex () method.

The cmyk_string is a string form of giving cmyk (cyan, magenta, yellow, black) color. These values are floats representing percent.

The hsv_string is another hue, saturation, value representation, but in floats; hue is in degree range (0..360), and saturation and value is given in percent. This is not the same as returned or given to the hsv () methods!

This table lists all the different named colors available in Image.Color. The first column shows the actual color while the five following columns demonstrates the modifiers neon, light, dark, bright and dull. The color begind the name of the color is produced by calling neon()->dark()->dark()->dark() from the color object itself, i.e. Image.Color.mintcream->neon()->dark()->dark()->dark().


























































Note

Image.Color["something"] will never(!) generate an error, but a zero_type 0, if the color is unknown. This is enough to give the error "not present in module", if used as Image.Color.something, though.

If you are using colors from for instance a webpage, you might want to create the color from Image.Color.guess (), since that method is more tolerant for mistakes and errors.

Image.Color() is case- and space-sensitive. Use Image.Color.guess () to catch all variants.

and subtract with a space (lower_case(x)-" ") to make sure you get all variants.

See also

Image.Color.Color , Image.Color.guess , Image , Image.Colortable


Method rgb
Method hsv
Method cmyk
Method greylevel
Method html

object rgb(int red, object intgreen, object intblue)
object hsv(int hue, object intsaturation, object intvalue)
object cmyk(float c, float m, float y, float k)
object greylevel(int level)
object html(string html_color)

Description

Creates a new color object from given red, green and blue, hue, saturation and value, or greylevel, in color value range. It could also be created from cmyk values in percent.

The html () method only understands the HTML color names, or the #rrggbb form. It is case insensitive.

Returns

the created object.


Method guess

object guess(string color)

Description

This is equivalent to Image.Color (lower_case(str)-" "), and tries the color with a prepending '#' if no corresponding color is found.

Returns

a color object or zero_type


Method _indices
Method _values

array(string) _indices()
array(object) _values()

Description

(ie as indices(Image.Color) or values(Image.Color)) indices gives a list of all the known color names, values gives there corresponding objects.

See also

Image.Color

  CLASS Image.Color.Color

Description

This is the color object. It has six readable variables, r, g, b, for the red, green and blue values, and h, s, v, for the hue, saturation anv value values.


Method bits

int bits(object intrbits, object intgbits, object intbbits, object intrshift, object intgshift, object intbshift)

Description

Returns the color as an integer. The first three parameters state how many bits to use for red, green and blue respectively. The last three state how many bits each colour should be shifted. For instance, Image.Color("#AABBCC")->bits(8, 8, 8, 16, 8, 0) returns the integer 11189196, that is, 0xAABBCC.


Method light
Method dark
Method neon
Method bright
Method dull

object light()
object dark()
object neon()
object bright()
object dull()

Description

Color modification methods. These returns a new color.
methodeffect hsvas
light raise light level±0 ±0+50
dark lower light level±0 ±0-50
brightbrighter color ±0+50+50
dull greyer color ±0-50-50
neon set to extreme ±0maxmax

light and dark lower/highers saturation when value is min-/maximised respective.

Returns

the new color object

Note

The opposites may not always take each other out. The color is maximised at white and black levels, so, for instance Image.Color .white->light ()->dark () doesn't give the white color back, but the equal to Image.Color .white->dark (), since white can't get any light er.


Method cast

array|string cast()

Description

cast the object to an array, representing red, green and blue (equal to ->rgb ()), or to a string, giving the name (equal to ->name ()).

Returns

the name as string or rgb as array

See also

rgb , name


Method rgb
Method rgbf
Method hsv
Method hsvf
Method cmyk
Method greylevel

array(int) rgb()
array(float) rgbf()
array(int) hsv()
array(float) hsvf()
array(float) cmyk()
int greylevel()
int greylevel(int r, object intg, object intb)

Description

This is methods of getting information from an Image.Color.Color object.

They give an array of red, green and blue (rgb) values (color value),
hue, saturation and value (hsv) values (range as color value),
cyan, magenta, yellow, black (cmyk) values (in percent)
or the greylevel value (range as color value).

The greylevel is calculated by weighting red, green and blue. Default weights are 87, 127 and 41, respective, and could be given by argument.

Returns

array(int) respective int

See also

Image.Color.Color , grey


Method create

void Image.Color.Color(int r, int g, int b)

Description

This is the main Image.Color.Color creation method, mostly for internal use.


Method grey

object grey()
object grey(int red, int green, int blue)

Description

Gives a new color, containing a grey color, which is calculated by the greylevel method.

Returns

a new Image.Color.Color object

See also

greylevel


Method hex
Method name
Method html

string hex()
string hex(int n)
string name()
string html()

Description

Information methods.

hex () simply gives a string on the #rrggbb format. If n is given, the number of significant digits is set to this number. (Ie, n=3 gives #rrrgggbbb.)

name () is a simplified method; if the color exists in the database, the name is returned, per default is the hex () method use.

html () gives the HTML name of the color, or the hex (2) if it isn't one of the 16 HTML colors.

Returns

a new Image.Color.Color object

See also

rgb , hsv , Image.Color


Method `==

int `==(object other_color)
int `==(array(int) rgb)
int `==(int greylevel)
int `==(string name)

Description

Compares this object to another color, or color name. Example:

object red=Image.Color.red;
object other=Image.Color. ...;
object black=Image.Color.black;
 
if (red==other) ...
if (red==({255,0,0})) ...
if (black==0) ...
if (red=="red") ...

Returns

1 or 0

Note

The other datatype (not color object) must be to the right!

See also

rgb , grey , name

  Module Image.ANY

Description

This method calls the other decoding methods and has some heuristics for what type of image this is.

Methods: decode , decode_alpha , _decode

See also

Image


Method _decode
Method decode
Method decode_alpha

mapping _decode(string data)
object decode(string data)
object decode_alpha(string data)

Description

Tries heuristics to find the correct method of decoding the data, then calls that method.

The result of _decode() is a mapping that contains

        "type":image data type (ie, "image/jpeg" or similar)
        "image":the image object,
        "alpha":the alpha channel or 0 if N/A

Note

Throws upon failure.

  Module Image


Method lay

Image.Layer lay(array(Image.Layer|mapping) layers)
Image.Layer lay(array(Image.Layer|mapping) layers, int xoffset, int yoffset, int xsize, int ysize)

Description

Combine layers.

Returns

a new layer object.

See also

Image.Layer


Method _decode

mapping _decode(string data)

Description

Attempts to decode data as image data. The heuristics has some limited ability to decode macbinary files as well.


Method decode_layers

array(Image.Layer) decode_layers(string data, mapping|void opt)

Description

Attempts to decode data as image layer data. Additional arguments to the various formats decode_layers method can be passed through opt .


Method read_file

string read_file(string file)

Description

Reads the file file and, if the file is compressed with gzip or bzip, attempts to decompress it by calling gzip and bzip2 in a Process.create_process call.


Method load_file

string load_file(void|object|string file)

Description

Loads in a file, which need not be an image file. If no argument is given the data will be taken from stdin. If a file object is given, it will be read to the end of the file. If a string is given the function will first attempt to load a file with that name, then try to download data with the string as URL. Zero will be returned upon failure.


Method _load

mapping _load(void|object|string file)

Description

Loads a file with load_file and decodes it with _decode .


Method load_layer

Image.Layer load_layer(void|object|string file)

Description

Helper function to load an image layer from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with _decode.


Method load_layers

array(Image.Layer) load_layers(void|object|string file, mixed|void opts)

Description

Helper function to load all image layers from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with decode_layers. Extra arguments to the image types layer decoder, e.g. for XCF files, can be given in the opts mapping.


Method load

Image.Image load(void|object|string file)

Description

Helper function to load an image from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with _decode.


Method filled_circle
Method filled_circle_layer

Image.Image filled_circle(int d)
Image.Image filled_circle(int xd, int yd)
Image.Layer filled_circle_layer(int d)
Image.Layer filled_circle_layer(int xd, int yd)
Image.Layer filled_circle_layer(int d, Image.Color.Color color)
Image.Layer filled_circle_layer(int xd, int yd, Image.Color.Color color)
Image.Layer filled_circle_layer(int d, int r, int g, int b)
Image.Layer filled_circle_layer(int xd, int yd, int r, int g, int b)

Description

Generates a filled circle of the dimensions xd x yd (or d x d). The Image is a white circle on black background; the layer function defaults to a white circle (the background is transparent).

  CLASS Image.Font

Description

Short technical documentation on a font file: This object adds the text-drawing and -creation capabilities of the Image module.

For simple usage, see write and load .

Note

	       struct file_head
	       {
		  unsigned INT32 cookie;   - 0x464f4e54
		  unsigned INT32 version;  - 1
		  unsigned INT32 chars;    - number of chars
		  unsigned INT32 height;   - height of font
		  unsigned INT32 baseline; - font baseline
		  unsigned INT32 o[1];     - position of char_head's
	       } *fh;
	       struct char_head
	       {
		  unsigned INT32 width;    - width of this character
		  unsigned INT32 spacing;  - spacing to next character
		  unsigned char data[1];   - pixmap data (1byte/pixel)
	       } *ch;

            version 2:


            	  On-disk syntax (everything in N.B.O), int is 4 bytes, a byte is 8 bits:

            pos
            	0   int cookie = 'FONT';     or 0x464f4e54
            	4   int version = 2;         1 was the old version without the last four chars
            	8   int numchars;            Always 256 in this version of the dump program
            12   int height;              in (whole) pixels
            16   int baseline;            in (whole) pixels
            20   char direction;          1==right to left, 0 is left to right
            21   char format;             Font format
            22   char colortablep;        Colortable format
            23   char kerningtablep;      Kerning table format

            24   int offsets[numchars];   pointers into the data, realative to &cookie.
            	    [colortable]
            	    [kerningtable]

            	  At each offset:


            0   int width;               in pixels
            4   int spacing;             in 1/1000:th of a pixels
            8   char data[];             Enough data to plot width * font->height pixels
            				    Please note that if width is 0, there is no data.

            Font formats:
            	id type
            	 0 Raw 8bit data
            	 1 RLE encoded data,  char length, char data,   70% more compact than raw data
            	 2 ZLib compressed data                         60% more compact than RLE

            Colortable types:
            	 0 No colortable		 (the data is an alpha channel)
            	 1 24bit RGB with alpha         (index->color, 256*4 bytes, rgba)
            	 2 8bit Greyscale with alpha    (index->color, 256*2 bytes)

            Kerningtable types:
            	 0 No kerning table
            	 1 numchars*numchars entries, each a signed char with the kerning value
            	 2 numchar entries, each with a list of kerning pairs, like this:
            	    int len
            	    len * (short char, short value)
 

See also

Image , Image.Image


Method load

Image.Font|int load(string filename)

Description

Loads a font file to this font object.

Returns

Returns zero upon failure and a font object upon success.

Parameter filename

The path to the font file.

See also

write


Method create

void Image.Font(string filename)

Description

Loads a font file to this font object. Similar to load() .


Method write

Image.Image write(string text, string ... more_text_lines)

Description

Writes some text; thus creating an image object that can be used as mask or as a complete picture. One or more text lines may be provided.

See also

text_extents , load , Image.Image->paste_mask , Image.Image->paste_alpha_color


Method height

int height()

Description

Returns the font height.

See also

baseline , text_extents


Method text_extents

array(int) text_extents(string text, string ... more_text_lines)

Description

Calculate extents of a text-image, that would be created by calling write with the same arguments. One or more lines of text may be provided.

Returns
Array
int width
int height

See also

write , height , baseline


Method set_xspacing_scale
Method set_yspacing_scale

void set_xspacing_scale(float scale)
void set_yspacing_scale(float scale)

Description

Set spacing scale to write characters closer or more far away. This does not change scale of character, only the space between them.


Method baseline

int baseline()

Description

Returns font baseline (pixels from top)

See also

height , text_extents


Method center

void center()

FIXME

Document this function.


Method right

void right()

FIXME

Document this function.


Method left

void left()

FIXME

Document this function.

  CLASS Image.Colortable

Description

This object keeps colortable information, mostly for image re-coloring (quantization).

The object has color reduction, quantisation, mapping and dithering capabilities.

See also

Image , Image.Image , Image.Font , Image.GIF


Method create
Method add

void Image.Colortable()
void Image.Colortable(array(array(int)) colors)
void Image.Colortable(Image.Image image, int number)
void Image.Colortable(Image.Image image, int number, array(array(int)) needed)
void Image.Colortable(int r, int g, int b)
void Image.Colortable(int r, int g, int b, object array(int)
object add(array(array(int)) colors)
object add(Image.Image image, int number)
object add(Image.Image image, int number, array(array(int)) needed)
object add(int r, int g, int b)
object add(int r, int g, int b, object array(int)

Description

create initiates a colortable object. Default is that no colors are in the colortable.

add takes the same argument(s) as create , thus adding colors to the colortable.

The colortable is mostly a list of colors, or more advanced, colors and weight.

The colortable could also be a colorcube, with or without additional scales. A colorcube is the by-far fastest way to find colors.

Example:

ct=colortable(my_image,256); // the best 256 colors
ct=colortable(my_image,256,({0,0,0})); // black and the best other 255
 
ct=colortable(({({0,0,0}),({255,255,255})})); // black and white
 
ct=colortable(6,7,6); // a colortable of 252 colors
ct=colortable(7,7,5, ({0,0,0}),({255,255,255}),11);
        // a colorcube of 245 colors, and a greyscale of the rest -> 256

Parameter colors

list of colors

Parameter image

source image

Parameter number

number of colors to get from the image

0 (zero) gives all colors in the image.

Default value is 256.

Parameter needed

needed colors (to optimize selection of others to these given)

this will add to the total number of colors (see argument 'number')

Parameter r
Parameter g
Parameter b

size of sides in the colorcube, must (of course) be equal or larger than 2 - if smaller, the cube is ignored (no colors). This could be used to have only scales (like a greyscale) in the output.

Parameter fromi
Parameter toi
Parameter stepi

This is to add the possibility of adding a scale of colors to the colorcube; for instance a grayscale using the arguments ({0,0,0}),({255,255,255}),17, adding a scale from black to white in 17 or more steps.

Colors already in the cube is used again to add the number of steps, if possible.

The total number of colors in the table is therefore r*b*g+step1+...+stepn.

Note

max hash size is (probably, set by a #define) 32768 entries, giving maybe half that number of colors as maximum.


Method cast

object cast(string to)

Description

cast the colortable to an array or mapping, the array consists of Image.Color objects and are not in index order. The mapping consists of index:Image.Color pairs, where index is the index (int) of that color.

example: (mapping)Image.Colortable(img)

Parameter to

must be "string", "array" or "mapping".


Method corners

array(object) corners()

Description

Gives the eight corners in rgb colorspace as an array. The "black" and "white" corners are the first two.


Method cubicles

object cubicles()
object cubicles(int r, int g, int b)
object cubicles(int r, int g, int b, int accuracy)

Description

Set the colortable to use the cubicles algorithm to lookup the closest color. This is a mostly very fast and very accurate way to find the correct color, and the default algorithm.

The colorspace is divided in small cubes, each cube containing the colors in that cube. Each cube then gets a list of the colors in the cube, and the closest from the corners and midpoints between corners.

When a color is needed, the algorithm first finds the correct cube and then compares with all the colors in the list for that cube.

example: colors=Image.Colortable(img)->cubicles();

algorithm time: between O[m] and O[m * n], where n is numbers of colors and m is number of pixels

The arguments can be heavy trimmed for the usage of your colortable; a large number (10×10×10 or bigger) of cubicles is recommended when you use the colortable repeatedly, since the calculation takes much more time than usage.

recommended values:

image size  setup
100×100     cubicles(4,5,4) (default)
1000×1000   cubicles(12,12,12) (factor 2 faster than default)

In some cases, the full method is faster.

original default cubicles,
16 colors
accuracy=200

Parameter r
Parameter g
Parameter b

Size, ie how much the colorspace is divided. Note that the size of each cubicle is at least about 8b, and that it takes time to calculate them. The number of cubicles are r*g*b, and default is 4,5,4, ie 80 cubicles. This works good for 200±100 colors.

Parameter accuracy

Accuracy when checking sides of cubicles. Default is 16. A value of 1 gives complete accuracy, ie cubicle() method gives exactly the same result as full(), but takes (in worst case) 16× the time to calculate.

Returns

the object being called

Note

this method doesn't figure out the cubicles, this is done on the first use of the colortable.

Not applicable to colorcube types of colortable.


Method floyd_steinberg

object floyd_steinberg()
object floyd_steinberg(int bidir, int|float forward, int|float downforward, int|float down, int|float downback, int|float factor)

Description

Set dithering method to floyd_steinberg.

The arguments to this method is for fine-tuning of the algorithm (for computer graphics wizards).

original floyd_steinberg to a 4×4×4 colorcube floyd_steinberg to 16 chosen colors

Parameter bidir

Set algorithm direction of forward. -1 is backward, 1 is forward, 0 for toggle of direction each line (default).

Parameter forward
Parameter downforward
Parameter down
Parameter downback

Set error correction directions. Default is forward=7, downforward=1, down=5, downback=3.

Parameter factor

Error keeping factor. Error will increase if more than 1.0 and decrease if less than 1.0. A value of 0.0 will cancel any dither effects. Default is 0.95.

Returns

the object being called


Method full

object full()

Description

Set the colortable to use full scan to lookup the closest color.

example: colors=Image.Colortable(img)->full();

algorithm time: O[n*m], where n is numbers of colors and m is number of pixels

Returns

the object being called

Note

Not applicable to colorcube types of colortable.

See also

cubicles , map


Method greyp

int(0..1) greyp()

Description

Returns true if this colortable only contains greyscale.


Method image

object image()

Description

cast the colortable to an image object

each pixel in the image object is an entry in the colortable

Returns

the resulting image object


Method map
Method `*
Method ``*

object map(object image)
object `*(object image)
object ``*(object image)
object map(string data, int xsize, int ysize)
object `*(string data, int xsize, int ysize)
object ``*(string data, int xsize, int ysize)

Description

Map colors in an image object to the colors in the colortable, and creates a new image with the closest colors.

no dither
floyd_steinberg dither
ordered dither
randomcube dither
original 2 4 8 16 32 colors

Returns

a new image object

Note

Flat (not cube) colortable and not 'full ' method: this method does figure out the data needed for the lookup method, which may take time the first use of the colortable - the second use is quicker.

See also

cubicles , full


Method nodither

object nodither()

Description

Set no dithering (default).

Returns

the object being called


Method ordered

object ordered()
object ordered(int r, int g, int b)
object ordered(int r, int g, int b, int xsize, int ysize)
object ordered(int r, int g, int b, int xsize, int ysize, int x, int y)
object ordered(int r, int g, int b, int xsize, int ysize, int rx, int ry, int gx, int gy, int bx, int by)

Description

Set ordered dithering, which gives a position-dependent error added to the pixel values.

original mapped to
Image.Colortable(6,6,6)->
ordered
(42,42,42,2,2)
ordered() ordered
(42,42,42, 8,8,
0,0, 0,1, 1,0)

Parameter r
Parameter g
Parameter b

The maximum error. Default is 32, or colorcube steps (256/size).

Parameter xsize
Parameter ysize

Size of error matrix. Default is 8×8. Only values which factors to multiples of 2 and 3 are possible to choose (2,3,4,6,8,12,...).

Parameter x
Parameter y
Parameter rx
Parameter ry
Parameter gx
Parameter gy
Parameter bx
Parameter by

Offset for the error matrix. x and y is for both red, green and blue values, the other is individual.

Returns

the object being called

See also

randomcube , nodither , floyd_steinberg , create


Method randomcube
Method randomgrey

object randomcube()
object randomcube(int r, int g, int b)
object randomgrey()
object randomgrey(int err)

Description

Set random cube dithering. Color choosen is the closest one to color in picture plus (flat) random error; color±random(error).

The randomgrey method uses the same random error on red, green and blue and the randomcube method has three random errors.

original mapped to
Image.Colortable(4,4,4)->
randomcube() randomgrey()

Parameter r
Parameter g
Parameter b
Parameter err

The maximum error. Default is 32, or colorcube step.

Returns

the object being called

Note

randomgrey method needs colorcube size to be the same on red, green and blue sides to work properly. It uses the red colorcube value as default.

See also

ordered , nodither , floyd_steinberg , create


Method reduce
Method reduce_fs

object reduce(int colors)
object reduce_fs(int colors)

Description

reduces the number of colors

All needed (see create ) colors are kept.

reduce_fs creates and keeps the outmost corners of the color space, to improve floyd-steinberg dithering result. (It doesn't work very well, though.)

Parameter colors

target number of colors

Returns

the new Colortable object

Note

this algorithm assumes all colors are different to begin with (!)

reduce_fs keeps the "corners" as "needed colors".

See also

corners


Method rigid

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

Description

Set the colortable to use the "rigid" method of looking up colors.

This is a very simple way of finding the correct color. The algorithm initializes a cube with r x g x b colors, where every color is chosen by closest match to the corresponding coordinate.

This format is not recommended for exact match, but may be usable when it comes to quickly view pictures on-screen.

It has a high init-cost and low use-cost. The structure is initiated at first usage.

Returns

the object being called

Note

Not applicable to colorcube types of colortable.

See also

cubicles , map , full


Method spacefactors

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

Description

Colortable tuning option, this sets the color space distance factors. This is used when comparing distances in the colorspace and comparing grey levels.

Default factors are 3, 4 and 1; blue is much darker than green. Compare with Image.Image->grey ().

Returns

the object being called

Note

This has no sanity check. Some functions may bug if the factors are to high - color reduction functions sums grey levels in the image, this could exceed maxint in the case of high factors. Negative values may also cause strange effects. *grin*


Method `+

object `+(object with, object mixed...more)

Description

sums colortables

Parameter with

Colortable object with colors to add

Returns

the resulting new Colortable object


Method `-

object `-(object with, object mixed...more)

Description

subtracts colortables

Parameter with

Colortable object with colors to subtract

Returns

the resulting new Colortable object

  CLASS Image.Layer

See also

layers


Method set_image
Method image
Method alpha

object set_image(Image.Image image)
object set_image(Image.Image image, Image.Image alpha_channel)
object|int(0..) image()
object|int(0..) alpha()

Description

Set/change/get image and alpha channel for the layer. You could also cancel the channels giving 0 instead of an image object.

Note

image and alpha channel must be of the same size, or canceled.


Method set_alpha_value
Method alpha_value

object set_alpha_value(float value)
float alpha_value()

Description

Set/get the general alpha value of this layer. This is a float value between 0 and 1, and is multiplied with the alpha channel.


Method autocrop
Method find_autocrop

object autocrop()
object autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)
array(int) find_autocrop()
array(int) find_autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)

Description

This crops (of finds) a suitable crop, non-destructive crop. The layer alpha channel is checked, and edges that is transparent is removed.

(What really happens is that the image and alpha channel is checked, and edges equal the fill setup is cropped away.)

find_autocrop () returns an array of xoff,yoff,xsize,ysize, which can be fed to crop ().

Note

A tiled image will not be cropped at all.

left...bottom arguments can be used to tell what sides cropping are ok on.

See also

crop , Image.Image->autocrop


Method set_mode
Method mode
Method available_modes

object set_mode(string mode)
string mode()
array(string) available_modes()

Description

Set/get layer mode. Mode is one of these:

All channels are calculated separately, if nothing else is specified.
top layer
bottom layer
normal
D=L applied with alpha: D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=(aL+(1-aL)*aS)
add
D=L+S applied with alpha, aD=aS
subtract
D=S-L applied with alpha, aD=aS
multiply
D=S*L applied with alpha, aD=aS
divide
D=S/L applied with alpha, aD=aS
negdivide
D=1.0-S/L applied with alpha, aD=aS
modulo
D=S%L applied with alpha, aD=aS
invsubtract
D=L-S applied with alpha, aD=aS
invdivide
D=L/S applied with alpha, aD=aS
invmodulo
D=L%S applied with alpha, aD=aS
imultiply
D=(1-L)*S applied with alpha, aD=aS
idivide
D=S/(1-L) applied with alpha, aD=aS
invidivide
D=L/(1-S) applied with alpha, aD=aS
difference
D=abs(L-S) applied with alpha, aD=aS
max
D=max(L,S) applied with alpha, aD=aS
min
D=min(L,S) applied with alpha, aD=aS
bitwise_and
D=L&amp;S applied with alpha, aD=aS
bitwise_or
D=L|S applied with alpha, aD=aS
bitwise_xor
D=L^S applied with alpha, aD=aS
replace
D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=aS
red
Dr=(Lr*aLr+Sr*(1-aLr)*aSr) / (aLr+(1-aLr)*aSr), Dgb=Sgb, aD=aS
green
Dg=(Lg*aLg+Sg*(1-aLg)*aSg) / (aLg+(1-aLg)*aSg), Drb=Srb, aD=aS
blue
Db=(Lb*aLb+Sb*(1-aLb)*aSb) / (aLb+(1-aLb)*aSb), Drg=Srg, aD=aS
hardlight
Like photoshop hardlight layer mode, aD=aS
replace_hsv
Dhsv=Lhsv apply with alpha, aD=aS
hue
Dh=Lh apply with alpha, Dsv=Lsv, aD=aS
saturation
Ds=Ls apply with alpha, Dhv=Lhv, aD=aS
value
Dv=Lv apply with alpha, Dhs=Lhs, aD=aS
color
Dhs=Lhs apply with alpha, Dv=Lv, aD=aS
value_mul
Dv=Lv*Sv apply with alpha, Dhs=Lhs, aD=aS
darken
Dv=min(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS
lighten
Dv=max(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS
saturate
Ds=max(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS
desaturate
Ds=min(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS
hls_replace
Dhls=Lhls apply with alpha, aD=aS
hls_hue
Dh=Lh apply with alpha, Dsv=Lsv, aD=aS
hls_saturation
Ds=Ls apply with alpha, Dhv=Lhv, aD=aS
hls_lightness
Dl=Ll apply with alpha, Dhs=Lhs, aD=aS
hls_color
Dhs=Lhs apply with alpha, Dl=Ll, aD=aS
hls_lightness_mul
Dl=Ll*Sl apply with alpha, Dhs=Lhs, aD=aS
hls_darken
Dl=min(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS
hls_lighten
Dl=max(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS
hls_saturate
Ds=max(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS
hls_desaturate
Ds=min(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS
dissolve
i=random 0 or 1, D=i?L:S, aD=i+aS
behind
D=(S*aS+L*(1-aS)*aL) / (aS+(1-aS)*aL), aD=(aS+(1-aS)*aL); simply swap S and L
erase
D=S, aD=aS*(1-aL)
screen
1-(1-S)*(1-L) applied with alpha, aD=aS
overlay
(1-(1-a)*(1-b)-a*b)*a+a*b applied with alpha, aD=aS
burn_alpha
aD=aL+aS applied with alpha, D=L+S; experimental, may change or be removed
equal
each channel D=max if L==S, 0 otherwise, apply with alpha
not_equal
each channel D=max if L!=S, 0 otherwise, apply with alpha
less
each channel D=max if L<S, 0 otherwise, apply with alpha
more
each channel D=max if L>S, 0 otherwise, apply with alpha
less_or_equal
each channel D=max if L<=S, 0 otherwise, apply with alpha
more_or_equal
each channel D=max if L>=S, 0 otherwise, apply with alpha
logic_equal
logic: D=white and opaque if L==S, black and transparent otherwise
logic_not_equal
logic: D=white and opaque if any L!=S, black and transparent otherwise
logic_strict_less
logic: D=white and opaque if all L<S, black and transparent otherwise
logic_strict_more
logic: D=white and opaque if all L>S, black and transparent otherwise
logic_strict_less_equal
logic: D=white and opaque if all L<=L, black and transparent otherwise
logic_strict_more_equal
logic: D=white and opaque if all L>=L, black and transparent otherwise

available_modes () simply gives an array containing the names of these modes.

Note

image and alpha channel must be of the same size, or canceled.


Method cast

mapping(string:mixed)|string cast()

Description

([ "xsize":int, "ysize":int, "image":image, "alpha":image, "xoffset":int, "yoffset":int, "fill":image, "fill_alpha":image "tiled":int, "mode":string ])


Method clone

object clone()

Description

Creates a copy of the called object.

Returns

the copy


Method create

void Image.Layer(object image, object alpha, string mode)
void Image.Layer(mapping info)
void Image.Layer()
void Image.Layer(int xsize, int ysize, object color)
void Image.Layer(object color)

Description

The Layer construct either three arguments, the image object, alpha channel and mode, or a mapping with optional elements:

"image":image,
        // default: black
 
"alpha":alpha,
        // alpha channel object
        // default: full opaque
 
"mode":string mode,
        // layer mode, see mode .
        // default: "normal"
 
"alpha_value":float(0.0-1.0),
        // layer general alpha value
        // default is 1.0; this is multiplied
        // with the alpha channel.
 
"xoffset":int,
"yoffset":int,
        // offset of this layer
 
"fill":Color,
"fill_alpha":Color,
        // fill color, ie what color is used
        // "outside" the image. default: black
        // and black (full transparency).
 
"tiled":int(0|1),
        // select tiling; if 1, the image
        // will be tiled. deafult: 0, off
The layer can also be created "empty", either giving a size and color - this will give a filled opaque square, or a color, which will set the "fill" values and fill the whole layer with an opaque color.

All values can be modified after object creation.

Note

image and alpha channel must be of the same size.


Method crop

object crop(int xoff, int yoff, int xsize, int ysize)

Description

Crops this layer at this offset and size. Offset is not relative the layer offset, so this can be used to crop a number of layers simuntaneously.

The fill values are used if the layer is enlarged.

Returns

a new layer object

Note

The new layer object may have the same image object, if there was no cropping to be done.


Method description

array(string) description()

Description

Layer descriptions


Method set_fill
Method fill
Method fill_alpha

object set_fill(Color color)
object set_fill(Color color, Color alpha)
object fill()
object fill_alpha()

Description

Set/query fill color and alpha, ie the color used "outside" the image. This is mostly useful if you want to "frame" a layer.


Method set_misc_value
Method get_misc_value

mixed set_misc_value(object mixedwhat, object mixedto)
mixed get_misc_value(object mixedwhat)

Description

Set or query misc. attributes for the layer.

As an example, the XCF and PSD image decoders set the 'name' attribute to the name the layer had in the source file.


Method set_offset
Method xoffset
Method yoffset

object set_offset(int x, int y)
int xoffset()
int yoffset()

Description

Set/query layer offset.


Method set_tiled
Method tiled

object set_tiled(int yes)
int tiled()

Description

Set/query tiled flag. If set, the image and alpha channel will be tiled rather then framed by the fill values.


Method xsize
Method ysize

int xsize()
int ysize()

Description

Query layer offset. This is the same as layer image/alpha image size.

  CLASS Image.Image

Description

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

basic:
clear , clone , create , xsize , ysize

plain drawing:
box , circle , getpixel , line , setcolor , setpixel , threshold , polyfill

operators:
`& , `* , `+ , `- , `== , `> , `< , `|

pasting images:
paste , paste_alpha , paste_alpha_color , paste_mask

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

calculation by pixels:
apply_matrix , change_color , color , distancesq , grey , invert , modify_by_intensity , outline select_from , rgb_to_hsv , hsv_to_rgb , rgb_to_yuv , yuv_to_rgb ,

average , max , min , sum , sumf , find_min , find_max

special pattern drawing:
noise , turbulence , test , tuned_box , gradients , random

See also

Image , Image.Font , Image.Colortable , Image.X


Method mirrorx

object mirrorx()

Description

mirrors an image:
original ->mirrorx();

Returns

the new image object


Method mirrory

object mirrory()

Description

mirrors an image:
original ->mirrory();


Method rotate
Method rotate_expand

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:

original ->rotate(15,255,0,0); ->rotate_expand(15);

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.

Parameter angle

the number of degrees to rotate

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method rotate_ccw

object rotate_ccw()

Description

rotates an image counter-clockwise, 90 degrees.

original ->rotate_ccw();

Returns

the new image object


Method rotate_cw

object rotate_cw()

Description

rotates an image clockwise, 90 degrees.

original ->rotate_cw();

Returns

the new image object


Method scale

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.

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method scale

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.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method skewx
Method skewx_expand

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

Description

Skews an image an amount of pixels or a factor; a skew-x is a transformation:

original ->skewx(15,255,0,0); ->skewx_expand(15);

Parameter x

the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

Parameter yfactor

best described as: x=yfactor*this->ysize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method skewy
Method skewy_expand

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

Description

Skews an image an amount of pixels or a factor; a skew-y is a transformation:

original ->skewy(15,255,0,0); ->skewy_expand(15);

The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.

Parameter y

the number of pixels

Parameter xfactor

best described as: t=xfactor*this->xsize()

Parameter r
Parameter g
Parameter b

color to fill with; default is current

Returns

the new image object


Method noise

void noise(array(float|int|array(int)) colorrange)
void noise(array(float|int|array(int)) colorrange, float scale, float xdiff, float ydiff, float cscale)

Description

Gives a new image with the old image's size, filled width a 'noise' pattern.

The random seed may be different with each instance of pike.

Example: ->noise( ({0,({255,0,0}), 0.3,({0,255,0}), 0.6,({0,0,255}), 0.8,({255,255,0})}), 0.2,0.0,0.0,1.0 );

Parameter colorrange

colorrange table

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

turbulence


Method random
Method randomgrey

object random()
object random(int seed)
object randomgrey()
object random(greyint seed)

Description

Gives a randomized image;
original ->random() ->random(17) greyed
(same again)
color(red)
(same again)
...red channel

Use with ->grey () or ->color () for one-color-results.

Returns

a new image

See also

test , noise


Method turbulence

void turbulence(array(float|int|array(int)) colorrange)
void turbulence(array(float|int|array(int)) colorrange, int octaves, float scale, float xdiff, float ydiff, float cscale)

Description

gives a new image with the old image's size, filled width a 'turbulence' pattern

The random seed may be different with each instance of pike.

Example:
->turbulence( ({0,({229,204,204}), 0.9,({229,20,20}), 0.9,Color.black}) );

Parameter colorrange

colorrange table

Parameter octaves

default value is 3

Parameter scale

default value is 0.1

Parameter xdiff
Parameter ydiff

default value is 0,0

Parameter cscale

default value is 1

See also

noise , Image.Color


Method apply_curve

object apply_curve(object array(int(0..255)
object apply_curve(object array(int(0..255)
object apply_curve(object stringchannel, object array(int(0..255)

Description

Apply a lookup-table on all pixels in an image. If only one curve is passed, use the same curve for red, green and blue. If 'channel' is specified, the curve is only applied to the specified channel.

Parameter curve_r
Parameter curve_g
Parameter curve_b
Parameter curve

An array with 256 elements, each between 0 and 255. It is used as a look-up table, if the pixel value is 2 and curve[2] is 10, the new pixel value will be 10.

Parameter channel

one of "red", "green", "blue", "value", "saturation" and "hue".

Returns

a new image object

See also

gamma , `* , modify_by_intensity


Method apply_matrix

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})})
original
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,-2,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, 3
greyed

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object


Method autocrop
Method find_autocrop

object autocrop()
object autocrop(int border)
object autocrop(int border, Color color)
object autocrop(int border, int left, int right, int top, int bottom)
object autocrop(int border, int left, int right, int top, int bottom, Color color)
array(int) find_autocrop()
array(int) find_autocrop(int border)
array(int) find_autocrop(int border, int left, int right, int top, int bottom)

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.

The find_autocrop() function simply returns x1,y1,x2,y2 for the kept area. (This can be used with copy later.)

Parameter border
Parameter left
Parameter right
Parameter top
Parameter 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


Method bitscale

object bitscale(float factor)
object bitscale(float xfactor, float yfactor)

Description

scales the image with a factor, without smoothing. This routine is faster than scale, but gives less correct results

original bitscale(0.75) scale(0.75)

Parameter factor

factor to use for both x and y

Parameter xfactor
Parameter yfactor

separate factors for x and y

Returns

the new image object


Method bitscale

object bitscale(int newxsize, int newysize)
object bitscale(0, int newysize)
object bitscale(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.

Parameter newxsize
Parameter newysize

new image size in pixels

Returns

the new image object

Note

resulting image will be 1x1 pixels, at least


Method blur

string blur(int no_pass)

Description

A special case of apply_matrix that creates a blur effect. About four times faster than the generic apply_matrix. @[no_pass] is the number of times the blur matrix is applied.

original blur(1) blur(5)

See also

apply_matrix , grey_blur


Method box

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.

original ->box
(40,10,
10,80,
0,255,0)
->box
(40,10,
10,80,
255,0,0,75)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

box corners

Parameter r
Parameter g
Parameter b

color of the box

Parameter alpha

alpha value

Returns

the object called


Method cast

string cast(string type)

Description

Cast the image to another datatype. Currently supported are string ("rgbrgbrgb...") and array (double array of Image.Color objects).

See also

Image.Color , Image.X


Method change_color

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 (exact match) to another. If non-exact-match is preferred, check distancesq and paste_alpha_color .

Parameter tor
Parameter tog
Parameter tob

destination color and next current color

Parameter fromr
Parameter fromg
Parameter fromb

source color, default is current color

Returns

a new (the destination) image object


Method circle

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 circle on the image. The circle is not antialiased.

original ->circle
(50,50,
30,50,
0,255,255)

Parameter x
Parameter y

circle center

Parameter rx
Parameter ry

circle radius in pixels

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method clear

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

original ->clear
(0,128,255)

Parameter r
Parameter g
Parameter b

color of the new image

Parameter alpha

new default alpha channel value

See also

copy , clone


Method clone

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.

original clone clone(50,50)

Parameter xsize
Parameter ysize

size of (new) image in pixels, called image is cropped to that size

Parameter r
Parameter g
Parameter 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).

Parameter alpha

new default alpha channel value

Returns

the new object

See also

copy , create


Method color

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.

original ->color(128,128,255);

Parameter r
Parameter g
Parameter b

red, green, blue factors

Parameter value

factor

Returns

the new image object

See also

grey , `* , modify_by_intensity


Method copy

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.

original ->copy
(5,5,
XSIZE-6,YSIZE-6)
->copy
(-5,-5,
XSIZE+4,YSIZE+4,
10,75,10)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

The requested new area. Default is the old image size.

Parameter r
Parameter g
Parameter b

color of the new image

Parameter 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


Method create

void Image.Image()
void Image.Image(int xsize, int ysize)
void Image.Image(int xsize, int ysize, Color color)
void Image.Image(int xsize, int ysize, int r, int g, int b)
void Image.Image(int xsize, int ysize, int r, int g, int b, int alpha)
void Image.Image(int xsize, int ysize, string method, method ...)

Description

Initializes a new image object.

Image.Image
(XSIZE,YSIZE)
Image.Image
(XSIZE,YSIZE,255,128,0)

The image can also be calculated from some special methods, for convinience:

channel modes; followed by a number of 1-char-per-pixel strings
or image objects (where red channel will be used),
or an integer value:
  "grey" : make a grey image (needs 1 source: grey)
  "rgb"  : make an rgb image (needs 3 sources: red, green and blue)
  "cmyk" : make a rgb image from cmyk (cyan, magenta, yellow, black)
  "adjusted_cmyk" : make a rgb image from cmyk
           (cyan, magenta, yellow, black) where the colors aren't
           100% pure (C: 009ee0, M: e2007a, Y: ffec00, K: 1a171b).
 
generate modes; all extra arguments is given to the
generation function. These has the same name as the method:
  "test ,"
  "gradients "
  "noise "
  "turbulence "
  "random "
  "randomgrey "
specials cases:
  "tuned_box " (coordinates is automatic)

Parameter xsize
Parameter ysize

size of (new) image in pixels

Parameter color
Parameter r
Parameter g
Parameter b

background color (will also be current color), default color is black

Parameter alpha

default alpha channel value

Bugs

SIGSEGVS can be caused if the size is too big, due to unchecked overflow - (xsize*ysize)&MAXINT is small enough to allocate.

See also

copy , clone , Image.Image


Method distancesq

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

original distance² to cyan ...to purple ...to yellow

Parameter r
Parameter g
Parameter b

red, green, blue coordinates

Returns

the new image object

See also

select_from


Method gamma

object gamma(float g)
object gamma(float gred, object floatggreen, object floatgblue)

Description

Calculate pixels in image by gamma curve.

Intensity of new pixels are calculated by:
i' = i^g

For example, you are viewing your image on a screen with gamma 2.2. To correct your image to the correct gamma value, do something like:

my_display_image(my_image()->gamma(1/2.2);

Parameter g
Parameter gred
Parameter ggreen
Parameter gblue

gamma value

Returns

a new image object

See also

grey , `* , color


Method getpixel

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

Description

Parameter x
Parameter y

position of the pixel

Returns

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


Method gradients

int gradients(array(int) point, object ...)
int gradients(array(int) point, object ..., object floatgrad)

Description

original 2 color
gradient
10 color
gradient
3 colors,
grad=4.0
3 colors,
grad=1.0
3 colors,
grad=0.25

Returns

the new image


Method grey

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

Description

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

original ->grey(); ->grey(0,0,255);

Parameter r
Parameter g
Parameter 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


Method grey_blur

object grey_blur(int no_pass)

Description

Works like blur, but only operates on the r color channel. A faster alternative to blur for grey scale images. @[no_pass] is the number of times the blur matrix is applied.

original grey_blur(1) grey_blur(5)

See also

blur


Method rgb_to_hsv
Method hsv_to_rgb

object rgb_to_hsv()
object hsv_to_rgb()

Description

Converts RGB data to HSV data, or the other way around. When converting to HSV, the resulting data is stored like this: pixel.r = h; pixel.g = s; pixel.b = v;

When converting to RGB, the input data is asumed to be placed in the pixels as above.

original ->hsv_to_rgb(); ->rgb_to_hsv();
tuned box (below) the rainbow (below) same, but rgb_to_hsv()

HSV to RGB calculation:

in = input pixel
out = destination pixel
h=-pos*c_angle*3.1415/(float)NUM_SQUARES;
out.r=(in.b+in.g*cos(in.r));
out.g=(in.b+in.g*cos(in.r + pi*2/3));
out.b=(in.b+in.g*cos(in.r + pi*4/3));

RGB to HSV calculation: Hmm.

Example: Nice rainbow.

 object i = Image.Image(200,200);
 i = i->tuned_box(0,0, 200,200,
                  ({ ({ 255,255,128 }), ({ 0,255,128 }),
                     ({ 255,255,255 }), ({ 0,255,255 })}))
      ->hsv_to_rgb();
 

Returns

the new image object


Method invert

object invert()

Description

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

original ->invert(); ->rgb_to_hsv()->invert()->hsv_to_rgb();

Returns

the new image object


Method line

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.

original ->line
(50,10,
10,50,
255,0,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

line endpoints

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method modify_by_intensity

object modify_by_intensity(int r, int g, int b, 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.

original ->grey()->modify_by_intensity(1,0,0, 0,({255,0,0}),({0,255,0}));

Parameter r
Parameter g
Parameter b

red, green, blue intensity factors

Parameter v1
Parameter vn

destination color

Returns

the new image object

See also

grey , `* , color


Method outline
Method outline_mask

object outline()
object outline(int olr, int olg, int olb)
object outline(int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline(array(array(int)) mask)
object outline(array(array(int)) mask, int olr, int olg, int olb)
object outline(array(array(int)) mask, int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline_mask()
object outline_mask(int bkgr, int bkgg, int bkgb)
object outline_mask(array(array(int)) mask)
object outline_mask(array(array(int)) mask, int bkgr, int bkgg, int bkgb)

Description

Makes an outline of this image, ie paints with the given color around the non-background pixels.

Default is to paint above, below, to the left and the right of these pixels.

You can also run your own outline mask.

The outline_mask function gives the calculated outline as an alpha channel image of white and black instead.

original masked
through
threshold
...and
outlined
with red

Parameter mask

mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}).

Parameter olr
Parameter olg
Parameter olb

outline color. Default is current.

Parameter bkgr
Parameter bkgg
Parameter bkgb

background color (what color to outline to); default is color of pixel 0,0.

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

no antialias!


Method write_lsb_rgb
Method write_lsb_grey
Method read_lsb_rgb
Method read_lsb_grey

object write_lsb_rgb(string what)
object write_lsb_grey(string what)
string read_lsb_rgb()
string read_lsb_grey()

Description

These functions read/write in the least significant bit of the image pixel values. The _rgb() functions read/write on each of the red, green and blue values, and the grey keeps the same lsb on all three.

The string is nullpadded or cut to fit.

Parameter what

the hidden message

Returns

the current object or the read string


Method rgb_to_yuv
Method yuv_to_rgb

object rgb_to_yuv()
object yuv_to_rgb()

Description

Converts RGB data to YUV (YCrCb) data, or the other way around. When converting to YUV, the resulting data is stored like this: pixel.r = v (cr); pixel.g = y; pixel.b = u (cb);

When converting to RGB, the input data is asumed to be placed in the pixels as above.

original ->yuv_to_rgb(); ->rgb_to_yuv();
tuned box (below) the rainbow (below) same, but rgb_to_yuv()

RGB to YUB calculation (this follows CCIR.601):

in = input pixel
out = destination pixel
Ey = 0.299*in.r+0.587*in.g+0.114*in.b
Ecr = 0.713*(in.r - Ey) = 0.500*in.r-0.419*in.g-0.081*in.b
Ecb = 0.564*(in.b - Ey) = -0.169*in.r-0.331*in.g+0.500*in.b
out.r=0.875*Ecr+128
out.g=0.86*Ey+16
out.b=0.875*Ecb+128

Example: Nice rainbow.

 object i = Image.Image(200,200);
 i = i->tuned_box(0,0, 200,200,
                  ({ ({ 255,255,128 }), ({ 0,255,128 }),
                     ({ 255,255,255 }), ({ 0,255,255 })}))
      ->yuv_to_rgb();
 

Returns

the new image object


Method select_from

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.

35, 35, 16 35, 35, 32 35, 35, 64 35, 35, 96 35, 35, 128 35, 35, 192 35, 35, 256

original original * select_from(35,35,200)

Parameter x
Parameter y

originating pixel in the image

Returns

the new image object

See also

distancesq


Method setcolor

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

Description

set the current color

Parameter r
Parameter g
Parameter b

new color

Parameter alpha

new alpha value

Returns

the object called


Method setpixel

object setpixel(int x, int y)
object setpixel(int x, int y, Image.Color c)
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)

Description

original ->setpixel
(10,10,
255,0,0)

Parameter x
Parameter y

position of the pixel

Parameter r
Parameter g
Parameter b

color

Parameter alpha

alpha value

Returns

the object called


Method test

object test()
object test(int seed)

Description

Generates a test image, currently random gradients.

original ->test() ...and again

Returns

the new image

Note

May be subject to change or cease without prior warning.

See also

gradients , tuned_box


Method threshold

object threshold()
object threshold(int level)
object threshold(int r, int g, int b)
object threshold(Color color)

Description

Makes a black-white image.

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

This method works fine with the grey method.

If no arguments are given, it will paint all non-black pixels white. (Ie, default is 0,0,0.)

original ->threshold(100); ->threshold(0,100,0);

Returns

the new image object

Note

The above statement "any ..." was changed from "all ..." in Pike 0.7 (9906). It also uses 0,0,0 as default input, instead of current color. This is more useful.

See also

grey


Method tuned_box

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.

original tuned box solid tuning
(blue,red,green,yellow)
tuning transparency
(as left + 255,128,128,0)

Parameter x1
Parameter y1
Parameter x2
Parameter y2

rectangle corners

Parameter 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


Method xsize

int xsize()

Returns

the width of the image


Method ysize

int ysize()

Returns

the height of the image


Method paste

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

Description

Pastes a given image over the current image.

Parameter image

image to paste (may be empty, needs to be an image object)

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste_alpha , paste_alpha_color


Method paste_alpha

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.

Parameter image

image to paste

Parameter alpha

alpha channel value

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste , paste_alpha_color


Method paste_alpha_color

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)
object paste_alpha_color(object mask, Color color)
object paste_alpha_color(object mask, Color color, 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.

Parameter mask

mask image

Parameter r
Parameter g
Parameter b

what color to paint with; default is current

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste_mask , paste_alpha , paste_alpha_color


Method paste_mask

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.

Parameter image

image to paste

Parameter mask

mask image

Parameter x
Parameter y

where to paste the image; default is 0,0

Returns

the object called

See also

paste , paste_alpha , paste_alpha_color


Method apply_max

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

Description

This is the same as apply_matrix, but it uses the maximum instead.

This function is not very fast.

Parameter array

the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.

Parameter r
Parameter g
Parameter b

base level of result, default is zero

Parameter div

division factor, default is 1.0.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions


Method make_ascii

string make_ascii(object orient1, object orient2, object orient3, object orient4, int|void tlevel, int|void xsize, int|void ysize)

Description

This method creates a string that looks like the image. Example:

   //Stina is an image with a cat.
   array(object) Stina4=Stina->orient4();
   Stina4[1]*=215;
   Stina4[3]*=215;
   string foo=Stina->make_ascii(@Stina4,40,4,8);

Returns

some nice acsii-art.

Note

experimental status; may not be exact the same output in later versions

      |      /    -    \
     hue=  0     64   128  192  (=red in an hsv image)

See also

orient , orient4


Method match

object match(int|float scale, object objectneedle)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert)
object match(int|float scale, object objectneedle, object objecthaystack_avoid, object intfoo)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert, object objecthaystack_avoid, object intfoo)

Description

This method creates an image that describes the match in every pixel in the image and the needle-Image.

   new pixel value =
     sum( my_abs(needle_pixel-haystack_pixel))

The new image only have the red rgb-part set.

Parameter scale

Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle.

Parameter needle

The image to use for the matching.

Parameter haystack_cert

This image should be the same size as the image itselves. A non-white-part of the haystack_cert-image modifies the output by lowering it.

Parameter needle_cert

The same, but for the needle-image.

Parameter foo
Parameter haystack_avoid

This image should be the same size as the image itselves. If foo is less than the red value in haystack_avoid the corresponding matching-calculating is not calculated. The avoided parts are drawn in the color 0,100,0.

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

See also

phasev , phaseh


Method phaseh
Method phasev
Method phasevh
Method phasehv

object phaseh()
object phasev()
object phasevh()
object phasehv()

Description

Draws images describing the phase of the current image. phaseh gives the horizontal phase and phasev the vertical phase.

phaseh gives an image where

       max  falling   min  rising
value=  0     64      128   192

0 is set if there is no way to determine if it is rising or falling. This is done for the every red, green and blue part of the image.

Phase images can be used to create ugly effects or to find meta-information in the orginal image.

original phaseh() phasev() phasevh() phasehv()

Returns

the new image object

Note

experimental status; may not be exact the same output in later versions

Bugs

0 should not be set as explained above.


Method dct

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...

Parameter newx
Parameter 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...

It doesn't use any fct (compare: fft) algorithms.


Method orient
Method orient4

object orient(void|array(object) something)
array(object) orient4()

Description

Draws images describing the orientation of the current image.

orient gives an HSV image (run a hsv_to_rgb pass on it to get a viewable image). corresponding to the angle of the orientation:

      |      /    -    \
     hue=  0     64   128  192  (=red in an hsv image)
         purple cyan green red
Red, green and blue channels are added and not compared separately.

If you first use orient4 you can give its output as input to this function.

The orient4 function gives back 4 image objects, corresponding to the amount of different directions, see above.

Returns

an image or an array of the four new image objects

Note

experimental status; may not be exact the same output in later versions


Method polyfill

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

Description

fills an area with the current color

Parameter curve

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

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

Image.Image(100,100)->setcolor(255,0,0,128)->
  polyfill( ({ 20,20, 80,20, 80,80 }) );

Returns

the current object

Note

Lines in the polygon may not be crossed without the crossing coordinate specified in both lines.

Bugs

Inverted lines reported on Intel and Alpha processors.

See also

setcolor


Method average
Method min
Method max
Method sum
Method sumf

array(float) average()
array(int) min()
array(int) max()
array(int) sum()
array(float) sumf()

Description

Gives back the average, minimum, maximum color value, and the sum of all pixel's color value.

Note

sum() values can wrap! Most systems only have 31 bits available for positive integers. (Meaning, be careful with images that have more than 8425104 pixels.)

average() and sumf() may also wrap, but on a line basis. (Meaning, be careful with images that are wider than 8425104 pixels.) These functions may have a precision problem instead, during to limits in the 'double' C type and/or 'float' Pike type.


Method find_min
Method find_max

array(int) find_min()
array(int) find_max()
array(int) find_min(int r, int g, int b)
array(int) find_max(int r, int g, int b)

Description

Gives back the position of the minimum or maximum pixel value, weighted to grey.

Parameter r
Parameter g
Parameter b

weight of color, default is r=87,g=127,b=41, same as the grey () method.


Method `/
Method `%

object `/(object operand)
object `/(Color color)
object `/(int value)
object `%(object operand)
object `%(Color color)
object `%(int value)

Description

Divides pixel values and creates a new image from the result or the rest.

Parameter operand

the other image to divide with; the images must have the same size.

Parameter color
Parameter value

if specified as color or value, it will act as a whole image of that color (or value).

Returns

the new image object

Note

It isn't possible to do a modulo 256 either. (why?)

See also

`- , `+ , `| , `&amp; , `* , Image.Layer


Method `&

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

Description

makes a new image out of the minimum pixels values

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+ , `| , `* , Image.Layer


Method `==
Method `<
Method `>

int `==(object operand)
int `==(array(int) color)
int `==(int value)
int `<(object operand)
int `<(array(int) color)
int `<(int value)
int `>(object operand)
int `>(array(int) color)
int `>(int value)

Description

Compares an image with another image or a color.

Comparision is strict and on pixel-by-pixel basis. (Means if not all pixel r,g,b values are correct compared with the corresponding pixel values, 0 is returned.)

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

true (1) or false (0).

Note

`< or `> on empty ("no image") image objects or images with different size will result in an error. `== is always true on two empty image objects and always false if one and only one of the image objects is empty or the images differs in size.

a>=b and a<=b between objects is equal to !(a<b) and !(a>b), which may not be what you want (since both < and > can return false, comparing the same images).

See also

`- , `+ , `| , `* , `&amp;


Method `*

object `*(object operand)
object `*(array(int) color)
object `*(int value)
object `*(float 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;

Parameter operand

the other image to multiply with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+ , `| , `&amp; , Image.Layer


Method `+

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

Description

adds two images; values are truncated at 255.

Parameter operand

the image which to add.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `| , `&amp; , `* , Image.Layer


Method `-

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

Description

makes a new image out of the difference

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`+ , `| , `&amp; , `* , Image.Layer , min , max , `==


Method `|

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

Description

makes a new image out of the maximum pixels values

Parameter operand

the other image to compare with; the images must have the same size.

Parameter color

an array in format ({r,g,b}), this is equal to using an uniform-colored image.

Parameter value

equal to ({value,value,value}).

Returns

the new image object

See also

`- , `+