All images handled by this module are stored as 24-bit RGB images. This means that a 1024 pixel wide and 1024 pixel high image will use 1024*1024*3 bytes = 3 megabytes. It is quite easy to mess up and use up all the memory by giving the wrong argument to one of the scaling functions.
Most functions in this module work by creating a new Image and then returning that instead of changing the Image you are working with. This makes it possible to share the same image between many variables without having to worry that it will be changed by accident. This can reduce the amount of memory used.
Many functions in this module work with the 'current color', this can be thought of as the background color if you wish. To change the current color you use 'setcolor'.
Let's look at an example of how this can be used:
This very simple example can be used as a CGI script to produce a gif image which says what time it is in white text on a black background.#!/usr/local/bin/pike
int main()
{
write("Content-type: image/gif\n\n");
object font=Image.font();
font->load("testfont");
object image=font->write(ctime(time));
write(Image.GIF.encode(image));
}
Image.Image | Basic image manipulation |
Image.Font | Creating images from text |
Image.Colortable | Color reduction, quantisation and dither |
Image.Color | Color names, objects and conversion |
encoding/decoding image files | |
Image.GIF | GIF encoding/decoding capabilities |
Image.JPEG | JPEG encoding/decoding capabilities (needs libjpeg) |
Image.PNG | PNG encoding/decoding capabilities (needs libz) |
Image.PNM | PNM (PBM/PGM/PPM) encoding/decoding capabilities |
Image.XFace | XFace encoding/decoding capabilities (needs libgmp) |
Image.XWD | XWD (X-windows dump) decoding capabilities |
advanced | |
Image.X | module for supporting X-windows low-level formats, keeping a lot of bit-mending stuff. |
Image module documentation is based on these file versions:$Id: blit.c,v 1.37 1999/06/18 19:19:14 mirar Exp $ $Id: blit_layer_include.h,v 1.6 1999/04/13 12:32:11 mirar Exp $ $Id: colors.c,v 1.30 2000/02/03 19:02:22 grubba Exp $ $Id: colortable.c,v 1.77 1999/10/30 11:51:41 mirar Exp $ $Id: colortable.h,v 1.17 1999/04/11 12:55:43 mirar Exp $ $Id: colortable_lookup.h,v 1.9 1999/04/10 02:02:07 mirar Exp $ $Id: dct.c,v 1.14 1999/06/18 19:19:20 mirar Exp $ $Id: any.c,v 1.16 2000/03/22 18:12:19 peter Exp $ $Id: bmp.c,v 1.20 2000/02/03 12:25:18 grubba Exp $ $Id: gif.c,v 1.50 1999/11/14 22:16:08 mast Exp $ $Id: gif_lzw.c,v 1.6 1999/05/30 20:11:14 mirar Exp $ $Id: gif_lzw.h,v 1.7 1999/05/30 20:11:15 mirar Exp $ $Id: ilbm.c,v 1.13 2000/02/03 19:01:29 grubba Exp $ $Id: pnm.c,v 1.20 1999/06/19 11:08:00 mirar Exp $ $Id: x.c,v 1.26 2000/03/27 07:42:35 hubbe Exp $ $Id: xwd.c,v 1.13 2000/01/11 01:42:36 mast Exp $ $Id: font.c,v 1.58 2000/03/25 23:34:32 hubbe Exp $ $Id: image.c,v 1.160 2000/04/09 06:15:17 per Exp $ $Id: image.h,v 1.35 1999/09/25 19:58:48 grubba Exp $ $Id: layers.c,v 1.43 2000/02/22 03:41:27 per Exp $ $Id: matrix.c,v 1.22 2000/04/09 06:15:17 per Exp $ $Id: operator.c,v 1.25 1999/09/14 23:17:15 marcus Exp $ $Id: orient.c,v 1.13 1999/06/19 20:24:48 hubbe Exp $ $Id: pattern.c,v 1.18 1999/07/16 11:44:20 mirar Exp $ $Id: poly.c,v 1.3 1999/07/28 09:26:20 mirar Exp $ $Id: polyfill.c,v 1.30 1999/06/19 20:24:49 hubbe Exp $ Experimental functions.
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,
average, max, min, sum, sumf, find_min, find_max
special pattern drawing:
noise,
turbulence,
test,
tuned_box,
gradients,
random
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.
argument(s) | description |
array(array(int|array(int))) | the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation. |
int r int g int b | base level of result, default is zero |
int|float div | division factor, default is 1.0. |
This function is not very fast.
argument(s) | description |
array(array(int|array(int))) | the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation. |
int r int g int b | base level of result, default is zero |
int|float div | division factor, default is 1.0. |
"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.)
argument(s) | description |
int border int left int right int top int bottom | which borders to scan and cut the image;
a typical example is removing the top and bottom unneccesary
pixels:
img=img->autocrop(0, 0,0,1,1); |
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.
argument(s) | description |
float factor | factor to use for both x and y |
float xfactor float yfactor | separate factors for x and y |
argument(s) | description |
int newxsize int newysize | new image size in pixels |
original | ->box |
argument(s) | description |
int x1 int y1 int x2 int y2 | box corners |
int r int g int b | color of the box |
int alpha | alpha value |
argument(s) | description |
int tor int tog int tob | destination color and next current color |
int fromr int fromg int fromb | source color, default is current color |
original | ->circle |
argument(s) | description |
int x int y | circle center |
int rx int ry | circle radius in pixels |
int r int g int b | color |
int alpha | alpha value |
original | ->clear |
argument(s) | description |
int r int g int b | color of the new image |
int alpha | new default alpha channel value |
original | clone | clone(50,50) |
argument(s) | description |
int xsize int ysize | size of (new) image in pixels, called image is cropped to that size |
int r int g int b | current color of the new image, default is black. Will also be the background color if the cloned image is empty (no drawing area made). |
int alpha | new default alpha channel value |
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); |
argument(s) | description |
int r int g int b | red, green, blue factors |
int value | factor |
original | ->copy |
->copy |
argument(s) | description |
int x1 int y1 int x2 int y2 | The requested new area. Default is the old image size. |
int r int g int b | color of the new image |
int alpha | new default alpha channel value |
Image.Image |
Image.Image |
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)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)
argument(s) | description |
int xsize int ysize | size of (new) image in pixels |
Color color int r int g int b | background color (will also be current color), default color is black |
int alpha | default alpha channel value |
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...
argument(s) | description |
int newx int newy | new image size in pixels |
It write's dots on stderr, to indicate some sort of progress. It doesn't use any fct (compare: fft) algorithms.
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 |
argument(s) | description |
int r int g int b | red, green, blue coordinates |
argument(s) | description |
int r int g int b | weight of color, default is r=87,g=127,b=41, same as the grey() method. |
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);
argument(s) | description |
int g int gred int ggreen int gblue | gamma value |
argument(s) | description |
int x int y | position of the pixel |
original | 2 color gradient |
10 color gradient |
3 colors, grad=4.0 |
3 colors, grad=1.0 |
3 colors, grad=0.25 |
original | ->grey(); | ->grey(0,0,255); |
argument(s) | description |
int r int g int b | weight of color, default is r=87,g=127,b=41, which should be pretty accurate of what the eyes see... |
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();
original | ->invert(); | ->rgb_to_hsv()->invert()->hsv_to_rgb(); |
original | ->line |
argument(s) | description |
int x1 int y1 int x2 int y2 | line endpoints |
int r int g int b | color |
int alpha | alpha value |
//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);
| / - \ hue= 0 64 128 192 (=red in an hsv image)
Replacement examples:
Old code:
img=map_fs(img->select_colors(200));New code:
img=Image.Colortable(img,200)->floyd_steinberg()->map(img);
Old code:
img=map_closest(img->select_colors(17)+({({255,255,255}),({0,0,0})}));New code:
img=Image.Colortable(img,19,({({255,255,255}),({0,0,0})}))->map(img);
new pixel value = sum( my_abs(needle_pixel-haystack_pixel))
The new image only have the red rgb-part set.
argument(s) | description |
int|float scale | Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle. |
object needle | The image to use for the matching. |
object 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. |
object needle_cert | The same, but for the needle-image. |
int foo object 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. |
original | ->mirrorx(); |
original | ->mirrory(); |
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})); |
argument(s) | description |
int r int g int b | red, green, blue intensity factors |
int|array(int) v1 int|array(int) vn | destination color |
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 );
argument(s) | description |
array(float|int|array(int)) colorrange | colorrange table |
float scale | default value is 0.1 |
float xdiff float ydiff | default value is 0,0 |
float cscale | default value is 1 |
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 redRed, 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.
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 |
argument(s) | description |
array(array(int)) mask | mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}). |
int olr int olg int olb | outline color. Default is current. |
int bkgr int bkgg int bkgb | background color (what color to outline to); default is color of pixel 0,0. |
int|float div | division factor, default is 1.0. |
argument(s) | description |
object image | image to paste (may be empty, needs to be an image object) |
int x int y | where to paste the image; default is 0,0 |
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.
argument(s) | description |
object image | image to paste |
int alpha | alpha channel value |
int x int y | where to paste the image; default is 0,0 |
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.
argument(s) | description |
object mask | mask image |
int r int g int b | what color to paint with; default is current |
int x int y | where to paste the image; default is 0,0 |
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.
argument(s) | description |
object image | image to paste |
object mask | mask image |
int x int y | where to paste the image; default is 0,0 |
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() |
argument(s) | description |
array(int|float) curve | curve(s), ({x1,y1,x2,y2,...,xn,yn}),
automatically closed.
If any given curve is inside another, it will make a hole. |
original | ->random() | ->random(17) | greyed (same again) |
color(red) (same again) |
...red channel |
Use with ->grey() or ->color() for one-color-results.
The string is nullpadded or cut to fit.
argument(s) | description |
string what | the hidden message |
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.
argument(s) | description |
int|float angle | the number of degrees to rotate |
int r int g int b | color to fill with; default is current |
original | ->rotate_ccw(); |
original | ->rotate_cw(); |
argument(s) | description |
float factor | factor to use for both x and y |
float xfactor float yfactor | separate factors for x and y |
argument(s) | description |
int newxsize int newysize | new image size in pixels |
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.
argument(s) | description |
int x int y | originating pixel in the image |
argument(s) | description |
int r int g int b | new color |
int alpha | new alpha value |
original | ->setpixel |
argument(s) | description |
int x int y | position of the pixel |
int r int g int b | color |
int alpha | alpha value |
original | ->skewx(15,255,0,0); | ->skewx_expand(15); |
argument(s) | description |
int x | the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color. |
float yfactor | best described as: x=yfactor*this->ysize() |
int r int g int b | color to fill with; default is current |
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.
argument(s) | description |
int y | the number of pixels |
float xfactor | best described as: t=xfactor*this->xsize() |
int r int g int b | color to fill with; default is current |
original | ->test() | ...and again |
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); |
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) |
argument(s) | description |
int x1 int y1 int x2 int y2 | rectangle corners |
array(array(int)) corner_color | colors of the corners:
({x1y1,x2y1,x1y2,x2y2})each of these is an array of integeres: ({r,g,b}) or ({r,g,b,alpha})Default alpha channel value is 0 (opaque). |
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}) );
argument(s) | description |
array(float|int|array(int)) colorrange | colorrange table |
int octaves | default value is 3 |
float scale | default value is 0.1 |
float xdiff float ydiff | default value is 0,0 |
float cscale | default value is 1 |
argument(s) | description |
object operand | the other image to divide with; the images must have the same size. |
Color color int value | if specified as color or value, it will act as a whole image of that color (or value). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
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.)
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
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).
This can be useful to lower the values of an image, making it greyer, for instance:
image=image*128+64;
argument(s) | description |
object operand | the other image to multiply with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the image which to add. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
argument(s) | description |
object operand | the other image to compare with; the images must have the same size. |
array(int) color | an array in format ({r,g,b}), this is equal to using an uniform-colored image. |
int value | equal to ({value,value,value}). |
The object has color reduction, quantisation, mapping and dithering capabilities.
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 255ct=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
argument(s) | description |
array(array(int)) colors | list of colors |
object(Image.Image) image | source image |
int number | number of colors to get from the image
0 (zero) gives all colors in the image. Default value is 256. |
array(array(int)) needed | needed colors (to optimize selection of others to these given)
this will add to the total number of colors (see argument 'number') |
int r int g int 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. |
array(int) fromi array(int) toi int 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. |
example: (mapping)Image.Colortable(img)
argument(s) | description |
string to | must be "string", "array" or "mapping". |
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 |
argument(s) | description |
int r int g int 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. |
int 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. |
Not applicable to colorcube types of colortable.
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 |
argument(s) | description |
int bidir | Set algorithm direction of forward. -1 is backward, 1 is forward, 0 for toggle of direction each line (default). |
int|float forward int|float downforward int|float down int|float downback | Set error correction directions. Default is forward=7, downforward=1, down=5, downback=3. |
int|float 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. |
example: colors=Image.Colortable(img)->full();
algorithm time: O[n*m], where n is numbers of colors and m is number of pixels
each pixel in the image object is an entry in the colortable
no dither | ||||||
floyd_steinberg dither | ||||||
ordered dither | ||||||
randomcube dither | ||||||
original | 2 | 4 | 8 | 16 | 32 colors |
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) |
|
argument(s) | description |
int r int g int b | The maximum error. Default is 32, or colorcube steps (256/size). |
int xsize int 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,...). |
int x int y int rx int ry int gx int gy int bx int by | Offset for the error matrix. x and y is for both red, green and blue values, the other is individual. |
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() | |
argument(s) | description |
int r int g int b int err | The maximum error. Default is 32, or colorcube step. |
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.)
argument(s) | description |
int colors | target number of colors |
reduce_fs keeps the "corners" as "needed 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.
Default factors are 3, 4 and 1; blue is much darker than green. Compare with Image.Image->grey().
argument(s) | description |
object(Colortable) with | Colortable object with colors to add |
argument(s) | description |
object(Colortable) with | Colortable object with colors to subtract |
(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().
left...bottom arguments can be used to tell what sides cropping are ok on.
"normal", "add", "subtract", "multiply", "divide", "modulo", "invsubtract", "invdivide", "invmodulo", "difference", "max", "min", "bitwise_and", "bitwise_or", "bitwise_xor",
"replace", "red", "green", "blue",
"replace_hsv", "hue", "saturation", "value", "color",
"darken", "lighten",
"dissolve", "behind", "erase",
available_modes() simply gives an array containing the names of these modes.
"image":image, // default: blackThe 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."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
All values can be modified after object creation.
The fill values are used if the layer is enlarged.
As an example, the XCF and PSD image decoders set the 'name' attribute to the name the layer had in the source file.
For simple usage, see write and load.
other methods: baseline, height, set_xspacing_scale, set_yspacing_scale, text_extents
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) **!
argument(s) | description |
string text, ... | One or more lines of text. |
argument(s) | description |
string filename | Font file |
argument(s) | description |
float scale | what scale to use |
argument(s) | description |
string text, ... | One or more lines of text. |
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!
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.
The html() method only understands the HTML color names, or the #rrggbb form. It is case insensitive.
method | effect | h | s | v | as |
---|---|---|---|---|---|
light | raise light level | ±0 | ±0 | +50 | |
dark | lower light level | ±0 | ±0 | -50 | |
bright | brighter color | ±0 | +50 | +50 | |
dull | greyer color | ±0 | -50 | -50 | |
neon | set to extreme | ±0 | max | max |
light and dark lower/highers saturation when value is min-/maximised respective.
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.
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.
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") ...
argument(s) | description |
object image | the image object to encode |
int bpp | bits per pixel, how many bits each pixel should take |
int vbpp | value bits per pixel; how many bits per pixel that really contains information |
int alignbits | the number of even bits each line should be padded to |
object colortable | colortable to get indices for pseudocolor |
string translate | translate table for colors. Length of this string should be 1<<vbpp (or 2<<vbpp if vbpp are greater than 8). |
encode_truecolor(img, 12,32, 0, 3,5, 4,0, 3,8)
will give (aligned to even 32 bits for each row):
0bbbrrr0 gggg0bbb rrr0gggg 0bbb...
<--pixel 1--><--pixel 2--> <--3-->
10987654 32101098 76543210 1098... <- bit position
<-><-> <-->
| | +--- 4,0: 4 bits green shifted 0 bits
| +-------- 3,5: 3 bits red shifted 5 bits
+----------- 3,8: 3 bits blue shifted 8 bits
The above call is equal to
encode_truecolor_masks(img, 12,32, 0, 224, 15, 768)
and
encode_truecolor(img, 12,32, 0, 3,5,4,0,3,8, colortable(1<<3,1<<4,1<<3)).
The latter gives possibility to use dither algorithms,
but is slightly slower.
argument(s) | description |
object image | the image object to encode |
int bpp | bits per pixel, how many bits each pixel should take |
int alignbits | the number of even bits each line should be padded to |
int rbits int gbits int bbits | bits for each basecolor |
int rshift int gshift int bshift | leftshifts for each basecolor |
int rmask int gmask int bmask | masks for each basecolor (xbits and gbits are calculated from this), needs to be massive (no zeroes among the ones in the mask). |
object ct | colortable object (for dithering, or whatever) |
int swapbytes | swap bytes for bpp==16,24,32, swaps bits in the bytes if bpp==1, for change of byte/bitorder between client and server. |
Methods: decode, decode_alpha, _decode
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
An AVS file is a raw (uncompressed) 24 bit image file with alpha. The alpha channel is 8 bit, and there is no separate alpha for r, g and b.
BMP is common in the Windows environment.
Simple encoding:
encode
decode gives an image object, _decode gives a mapping in the format
"type":"image/bmp", "image":image object, "colortable":colortable object (if applicable)"xsize":int, "ysize":int, "compression":int, "bpp":int, "windows":int,
option is a mapping that may contain:
"colortable": Image.Colortable - palette "bpp": 1|4|8|24 - force this many bits per pixel "rle": 0|1 - run-length encode (default is 0)
argument(s) | description |
object image | Source image. |
object colortable | Colortable object, shortcut for "colortable" in options. |
GD is the internal format of libgd by Thomas Boutell, http://www.boutell.com/gd/ It is a rather simple, uncompressed, palette format.
The decode_header and _decode has these elements:
"image":object - image object \ "alpha":object - decoded alpha |- not decode_header "colortable":object - decoded palette /"type":"image/x-gd" - image type "xsize":int - horisontal size in pixels "ysize":int - vertical size in pixels "alpha_index":int - index to transparancy in palette -1 means no transparency "colors":int - numbers of colors
options is a mapping with optional values:
"colortable":object - palette to use (max 256 colors) "alpha":object - alpha channel (truncated to 1 bit) "alpha_index":int - index to transparancy in palette
GIF is a common image storage format, usable for a limited color palette - a GIF image can only contain as most 256 colors - and animations.
Simple encoding: encode, encode_trans
Advanced stuff: render_block, header_block, end_block, netscape_loop_block
Very advanced stuff: _render_block, _gce_block
"image":the image "alpha":the alpha channel"xsize":int "ysize":int size of image "type":"image/gif" file type information as MIME type
The latter (encode_trans) functions add transparency capabilities.
Example:
img=Image.Image([...]); [...] // make your very-nice image write(Image.GIF.encode(img)); // write it as GIF on stdout
argument(s) | description |
object img | The image which to encode. |
int colors object colortable | These arguments decides what colors the image should be encoded with. If a number is given, a colortable with be created with (at most) that amount of colors. Default is '256' (GIF maximum amount of colors). |
object alpha | Alpha channel image (defining what is transparent); black
color indicates transparency. GIF has only transparent
or nontransparent (no real alpha channel).
You can always dither a transparency channel:
Image.Colortable(my_alpha, ({({0,0,0}),({255,255,255})})) |
int tr_r int tr_g int tr_b | Use this (or the color closest to this) color as transparent pixels. |
int a_r int a_g int a_b | Encode transparent pixels (given by alpha channel image) to have this color. This option is for making GIFs for the decoders that doesn't support transparency. |
int transp_index | Use this color no in the colortable as transparent color. |
Image.GIF.encode_trans(img,colortable,alpha);is equivalent of using
Image.GIF.header_block(img->xsize(),img->ysize(),colortable)+ Image.GIF.render_block(img,colortable,0,0,0,alpha)+ Image.GIF.end_block();and is actually implemented that way.
The result of this function is always ";" or "\x3b", but I recommend using this function anyway for code clearity.
Giving a colortable to this function includes a global palette in the header block.
argument(s) | description |
int xsize int ysize | Size of drawing area. Usually same size as in the first (or only) render block(s). |
int background_color_index | This color in the palette is the background color. Background is visible if the following render block(s) doesn't fill the drawing area or are transparent. Most decoders doesn't use this value, though. |
int gif87a | If set, write 'GIF87a' instead of 'GIF89a' (default 0 == 89a). |
int aspectx int aspecty | Aspect ratio of pixels, ranging from 4:1 to 1:4 in increments of 1/16th. Ignored by most decoders. If any of aspectx or aspecty is zero, aspectratio information is skipped. |
int r int g int b | Add this color as the transparent color. This is the color used as transparency color in case of alpha-channel given as image object. This increases (!) the number of colors by one. |
This GIF encoder doesn't support different size of colors in global palette and color resolution.
argument(s) | description |
int number_of_loops | Number of loops. Max and default is 65535. |
Example:
img1=Image.Image([...]); img2=Image.Image([...]); [...] // make your very-nice images nct=Image.Colortable([...]); // make a nice colortable write(Image.GIF.header_block(xsize,ysize,nct)); // write a GIF header write(Image.GIF.render_block(img1,nct,0,0,0,10)); // write a render block write(Image.GIF.render_block(img2,nct,0,0,0,10)); // write a render block [...] write(Image.GIF.end_block()); // write end block // voila! A GIF animation on stdout.
The above animation is thus created:
object nct=colortable(lena,32,({({0,0,0})})); string s=GIF.header_block(lena->xsize(),lena->ysize(),nct); foreach ( ({lena->xsize(), (int)(lena->xsize()*0.75), (int)(lena->xsize()*0.5), (int)(lena->xsize()*0.25), (int)(1), (int)(lena->xsize()*0.25), (int)(lena->xsize()*0.5), (int)(lena->xsize()*0.75)}),int xsize) { object o=lena->scale(xsize,lena->ysize()); object p=lena->clear(0,0,0); p->paste(o,(lena->xsize()-o->xsize())/2,0); s+=GIF.render_block(p,nct,0,0,0,25); } s+=GIF.netscape_loop_block(200); s+=GIF.end_block(); write(s);
argument(s) | description |
object img | The image. |
object colortable | Colortable with colors to use and to write as palette. |
int x int y | Position of this image. |
int localpalette | If set, writes a local palette. |
object alpha | Alpha channel image; black is transparent. |
int r int g int b | Color of transparent pixels. Not all decoders understands transparency. This is ignored if localpalette isn't set. |
int delay | View this image for this many centiseconds. Default is zero. |
int transp_index | Index of the transparent color in the colortable. -1 indicates no transparency. |
int user_input | If set: wait the delay or until user input. If delay is zero, wait indefinitely for user input. May sound the bell upon decoding. Default is non-set. |
int disposal | Disposal method number;
|
The user_input and disposal method are unsupported in most decoders.
({int xsize,int ysize, // 0: size of image drawing area void|object colortable, // 2: opt. global colortable ({ int aspx, int aspy, // 3 0: aspect ratio or 0, 0 if not set int background }), // 2: index of background colorfollowed by any number these blocks in any order (gce chunks are decoded and incorporated in the render chunks):
({ GIF.RENDER, // 0: block identifier int x, int y, // 1: position of render object image, // 3: render image void|object alpha, // 4: 0 or render alpha channel object colortable, // 5: colortable (may be same as global)and possibly ended with one of these:int interlace, // 6: interlace flag int trans_index, // 7: 0 or transparent color index int delay, // 8: 0 or delay in centiseconds int user_input, // 9: user input flag int disposal}) // 10: disposal method number (0..7)
({ GIF.EXTENSION, // 0: block identifier int extension, // 1: extension number string data }) // 2: extension data
({ GIF.ERROR_PREMATURE_EOD }) // premature end-of-data({ GIF.ERROR_TOO_MUCH_DATA, // data following end marker string data }) // (rest of file)
({ GIF.ERROR_UNKNOWN_DATA, // unknown data string data }) // (rest of file)
The decode method uses this data in a way similar to this program:
import Image;object my_decode_gif(string data) { array a=GIF._decode(data); object img=image(a[0],a[1]); foreach (a[4..],array b) if (b[0]==GIF.RENDER) if (b[4]) img->paste_alpha(b[3],b[4],b[1],b[2]); else img->paste(b[3],b[1],b[2]); return img; }
argument(s) | description |
string gifdata | GIF data (with header and all) |
array __decoded | GIF data as from __decode |
This is in the very advanced sector of the GIF support; please read about how GIF files works.
argument(s) | description |
array data | data as returned from _encode |
argument(s) | description |
int transparency int transparency_index | The following image has transparency, marked with this index. |
int delay | View the following rendering for this many centiseconds (0..65535). |
int user_input | Wait the delay or until user input. If delay is zero, wait indefinitely for user input. May sound the bell upon decoding. |
int disposal | Disposal method number;
|
Most decoders just ignore some or all of these parameters.
argument(s) | description |
int x int y | Position of this image. |
int xsize int ysize | Size of the image. Length if the indices string must be xsize*ysize. |
int bpp | Bits per pixels in the indices. Valid range 1..8. |
string indices | The image indices as an 8bit indices. |
string colortable | Colortable with colors to write as palette. If this argument is zero, no local colortable is written. Colortable string len must be 1<<bpp. |
int interlace | Interlace index data and set interlace bit. The given string should _not_ be pre-interlaced. |
({int xsize,int ysize, // 0: size of image drawing area int numcol, // 2: suggested number of colors void|string colortable, // 3: opt. global colortable ({ int aspx, int aspy, // 4,0: aspect ratio or 0, 0 if not set int background }), // 1: index of background colorfollowed by any number these blocks in any order:
({ GIF.EXTENSION, // 0: block identifier int extension, // 1: extension number string data }) // 2: extension dataand possibly ended with one of these:({ GIF.RENDER, // 0: block identifier int x, int y, // 1: position of render int xsize, int ysize, // 3: size of render int interlace, // 5: interlace flag void|string colortbl, // 6: opt. local colortable int lzwsize, // 7: lzw code size string lzwdata }) // 8: packed lzw data
({ GIF.ERROR_PREMATURE_EOD }) // premature end-of-data({ GIF.ERROR_TOO_MUCH_DATA, // data following end marker string data }) // (rest of file)
({ GIF.ERROR_UNKNOWN_DATA, // unknown data string data }) // (rest of file)
This is in the very advanced sector of the GIF support; please read about how GIF files works.
The HRZ file is always 256x240 with RGB values from 0 to 63. No compression, no header, just the raw RGB data. HRZ is (was?) used for amatuer radio slow-scan TV.
The options argument may be a mapping containing zero or more encoding options:
normal options: "alpha":image object Use this image as mask (Note: ILBM mask is boolean. The values are calculated by (r+2g+b)/4>=128.)"palette":colortable object Use this as palette for pseudocolor encoding
Result is a mapping,
([ "image": object image,... more ... ])
image is the stored image.
({int xsize,int ysize, // 0: size of image drawing area string bitmapheader, // 2: BMHD chunk void|string colortable, // 3: opt. colortable chunk (CMAP) void|string colortable, // 4: opt. colormode chunk (CAMG) string body, // 5: BODY chunk mapping more_chunks}) // 6: mapping with other chunks
The options argument may be a mapping containing zero or more encoding options:
normal options: "raw":1 Do not RLE encode the image "dpy":int "xdpy":int "ydpy":int Image resolution (in pixels/inch, integer numbers) "xoffset":int "yoffset":int Image offset (not used by most programs, but gimp uses it)
The options argument may be a mapping containing zero or more encoding options:
The options argument may be a mapping containing zero or more encoding options:
normal options: "alpha":image object Use this image as alpha channel (Note: PNG alpha channel is grey. The values are calculated by (r+2g+b)/4.)"palette":colortable object Use this as palette for pseudocolor encoding (Note: encoding with alpha channel and pseudocolor at the same time are not supported)
Result is a mapping,
([ "image": object image,... options ... ])
image is the stored image.
Valid entries in options is a superset of the one given to encode:
basic options:"alpha": object alpha, - alpha channel
"palette": object colortable, - image palette (if non-truecolor)
advanced options:
"background": array(int) color, - suggested background color "background_index": int index, - what index in colortable
"chroma": ({ float white_point_x, float white_point_y, float red_x, float red_y, - CIE x,y chromaticities float green_x, float green_y, float blue_x, float blue_y })
"gamma": float gamma, - gamma
"spalette": object colortable, - suggested palette, for truecolor images "histogram": array(int) hist, - histogram for the image, corresponds to palette index
"physical": ({ int unit, - physical pixel dimension int x,y }) unit 0 means pixels/meter
"sbit": array(int) sbits - significant bits
"text": array(array(string)) text - text information, ({ ({ keyword, data }), ... })
Standard keywords:
Title Short (one line) title or caption for image Author Name of image's creator Description Description of image (possibly long) Copyright Copyright notice Creation Time Time of original image creation Software Software used to create the image Disclaimer Legal disclaimer Warning Warning of nature of content Source Device used to create the image Comment Miscellaneous comment
"time": ({ int year, month, day, - time of last modification hour, minute, second })
wizard options: "compression": int method - compression method (0)
This method can also take options, as a mapping:
advanced options: "palette": colortable object - replace the decoded palette with this when unpacking the image data, if applicable
Result is an array of arrays, ({ ({ string chunk_type, string data, int crc_ok }), ({ string chunk_type, string data, int crc_ok }) ... })
chunk_type is the type of the chunk, like "IHDR" or "IDAT".
data is the actual chunk data.
crcok is set to 1 if the checksum is ok and dontcheckcrc parameter isn't set.
Returns 0 if it isn't a PNG file.
PNM is a common image storage format on unix systems, and is a very simple format.
This format doesn't use any color palette.
The format is divided into seven subformats;
P1(PBM) - ascii bitmap (only two colors) P2(PGM) - ascii greymap (only grey levels) P3(PPM) - ascii truecolor P4(PBM) - binary bitmap P5(PGM) - binary greymap P6(PPM) - binary truecolor
Simple encoding:
encode,
encode_binary,
encode_ascii
Simple decoding:
decode
Advanced encoding:
encode_P1,
encode_P2,
encode_P3,
encode_P4,
encode_P5,
encode_P6
encode_binary() and encode_ascii() uses the most optimized encoding for this image (bitmap, grey or truecolor) - P4, P5 or P6 respective P1, P2 or P3.
encode_P1/encode_P4
assumes the image is black and white. Use
Image.Image->threshold() or something like
Image.Colortable( ({({0,0,0}),({255,255,255})}) )
encode_P2/encode_P5 assumes the image is greyscale. Use Image.Image->grey() to get a greyscale image.
The options argument may be a mapping containing zero or more encoding options:
normal options: "alpha":image object Use this image as alpha channel (Note: Targa alpha channel is grey. The values are calculated by (r+2g+b)/4.)"raw":1 Do not RLE encode the image
The options argument may be a mapping containing zero or more encoding options.
normal options: "name":"xbm_image_name" The name of the XBM. Defaults to 'image'
Supported options: ([ "fg":({fgcolor}), // Foreground color. Default black "bg":({bgcolor}), // Background color. Default white "invert":1, // Invert the mask ])
The layer object have the following extra variables (to be queried using get_misc_value):
image_xres, image_yres, image_colormap, image_guides, image_parasites, name, parasites, visible, active
Supported options ([ "background":({r,g,b})||Image.Color object "draw_all_layers":1, Draw invisible layers as well"draw_guides":1, Draw the guides
"draw_selection":1, Mark the selection using an overlay
"ignore_unknown_layer_modes":1 Do not asume 'Normal' for unknown layer modes.
"mark_layers":1, Draw an outline around all (drawn) layers
"mark_layer_names":Image.Font object, Write the name of all layers using the font object,
"mark_active_layer":1, Draw an outline around the active layer ])
Returned structure referenceclass GimpImage { int width; int height; int compression; int type; int tattoo_state; float xres = 72.0; float yres = 72.0; int res_unit; Image.Colortable colormap; Image.Colortable meta_colormap; array(Layer) layers = ({}); array(Channel) channels = ({}); array(Guide) guides = ({}); array(Parasite) parasites = ({}); array(Path) paths = ({});
Layer active_layer; Channel active_channel; Channel selection; }
class Layer { string name; int opacity; int type; int mode; int tattoo; mapping flags = ([]); int width, height; int xoffset, yoffset; array (Parasite) parasites; LayerMask mask; Hierarchy image; }
class Channel { string name; int width; int height; int opacity; int r, g, b; int tattoo; Hierarchy image_data; object parent; mapping flags = ([]); array (Parasite) parasites; }
class Hierarchy { Image.Image img; Image.Image alpha; int width; int height; int bpp; }
class Parasite { string name; int flags; string data; }
class Guide { int pos; int vertical; }
class Path { string name; int ptype; int tattoo; int closed; int state; int locked; array (PathPoint) points = ({}); }
class PathPoint { int type; float x; float y; }
Structure reference([ "width":int, "height":int, "type":int, "properties":({ ([ "type":int, "data":string, ]), ... }), "layers":({ ([ "name":string, "width":int, "height":int, "type":type, "properties":({ ([ "type":int, "data":string, ]), ... }), "mask":0 || ([ "name":string, "width":int, "height":int, "properties":({ ([ "type":int, "data":string, ]), ... }), "image_data":([ "bpp":int, "width":int, "height":int, "tiles":({ string, ... }), ]), ]), "image_data":([ "bpp":int, "width":int, "height":int, "tiles":({ string, ... }), ]), ]), ... }), "channels":({ "name":string, "width":int, "height":int, "properties":({ ([ "type":int, "data":string, ]), ... }), "image_data":([ "bpp":int, "width":int, "height":int, "tiles":({ string, ... }), ]), }), ])
XWD is the output format for the xwd program.
Simple decoding:
decode
Advanced decoding:
_decode
Supported XWD visual classes and encoding formats are TrueColor / ZPixmap DirectColor / ZPixmap PseudoColor / ZPixmap
If someone sends me files of other formats, these formats may be implemented. :) /mirar@idonex.se
The options argument may be a mapping containing zero or more encoding options:
advanced options: "block_smoothing":0|1 Do interblock smoothing. Default is on (1). "fancy_upsampling":0|1 Do fancy upsampling of chroma components. Default is on (1). "method":JPEG.IFAST|JPEG.ISLOW|JPEG.FLOAT|JPEG.DEFAULT|JPEG.FASTEST DCT method to use. DEFAULT and FASTEST is from the jpeg library, probably ISLOW and IFAST respective.wizard options: "scale_num":1.. "scale_denom":1.. Rescale the image when read from JPEG data. My (Mirar) version (6a) of jpeglib can only handle 1/1, 1/2, 1/4 and 1/8.
_decode and decode_header gives a mapping as result, with this content:
"xsize":int "ysize":int size of image "xdpi":float "ydpi":float image dpi, if known "type":"image/jpeg" file type information as MIME typeJPEG specific: "num_compontents":int number of channels in JPEG image "color_space":"GRAYSCALE"|"RGB"|"YUV"|"CMYK"|"YCCK"|"UNKNOWN" color space of JPEG image "density_unit":int "x_density":int "y_density":int density of image; unit is 1:dpi 2:dpcm 0:no units "adobe_marker":0|1 if the file has an adobe marker
The options argument may be a mapping containing zero or more encoding options:
normal options: "quality":0..100 Set quality of result. Default is 75. "optimize":0|1 Optimize Huffman table. Default is on (1) for images smaller than 50kpixels. "progressive":0|1 Make a progressive JPEG. Default is off.advanced options: "smooth":1..100 Smooth input. Value is strength. "method":JPEG.IFAST|JPEG.ISLOW|JPEG.FLOAT|JPEG.DEFAULT|JPEG.FASTEST DCT method to use. DEFAULT and FASTEST is from the jpeg library, probably ISLOW and IFAST respective.
"density_unit":int "x_density":int "y_density":int density of image; unit is 1:dpi 2:dpcm 0:no units
wizard options: "baseline":0|1 Force baseline output. Useful for quality<25. Default is on for quality<25. "quant_tables":mapping(int,array(array(int))) Tune quantisation tables manually.
The options argument may be a mapping containing zero or more encoding options:
normal options: "compression":Image.TIFF.COMPRESSION_*, "name":"an image name", "comment":"an image comment", "alpha":An alpha channel, "dpy":Dots per inch (as a float), "xdpy":Horizontal dots per inch (as a float), "ydpy":Vertical dots per inch (as a float),
argument(s) | description |
string filename | The filename of the TTF font or the TTC font collection. |
mapping options | advanced options: "face":int If opening a font collection, '.TTC', this is used to get other fonts than the first. |
The result from names() is a mapping, which has any or all of these indices:
"copyright": ("Copyright the Foo Corporation...bla bla") "family": ("My Little Font") "style": ("Bold") "full": ("Foo: My Little Font: 1998") "expose": ("My Little Font Bold") "version": ("June 1, 1998; 1.00, ...") "postscript": ("MyLittleFont-Bold") "trademark": ("MyLittleFont is a registered...bla bla")
This is extracted from the information from _names(), and fit into pike-strings using unicode or iso-8859-1, if possible.
The result from _names() is a matrix, on this form:
({ ({ int platform, encoding, language, id, string name }), ({ int platform, encoding, language, id, string name }), ... })
The most interesting item to look at may be ->num_Faces, which describes the number of faces in a .TTC font collection.
The options argument may be a mapping containing zero options.
"xsize":int "ysize":int size of image "type":"image/x-xface" file type information
The options argument may be a mapping containing zero options.
The img argument must be an image of the dimensions 48 by 48 pixels. All non-black pixels will be considered white.
The options argument may be a mapping containing zero options.