AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YDAT | YWAIT | Byzgraf | FAQs
convert (Color target, Object value [, Array grid]) typedict.Image
convert (Image value, Array grid)  
 
Converts the pixels in this image that match target and are selected by the optional grid argument to a color determined by value, which must be a Color, an Image, or NULL, and returns this image to the caller. If value is a color all selected pixels are changed to that color. If value is an image each selected pixel is mapped into value and the pixel at that location in value is used to replace the selected pixel. Finally, if value is NULL and this image support alpha, then selected pixels are assigned an alpha value of 0.0, which effectively erases them.

The grid argument should be an array of four numbers. The first two specify the width and height (in pixels) of the grid used to partition this image. The second two numbers specify the column and row of the only pixel in each grid that can be selected and converted.

If convert is called with an image as the first argument then grid must be supplied and every pixel selected by grid in this image is converted to the corresponding pixel in value.
 
 Example:   The program,
import yoix.*.*;

Image img = {
    String source = "http://www.yoix.org/imgs/ATTlogo.gif";
    double metrics = 1.1;
};

Image img_merged = {
    Color background = Color.black;
    Array metrics = {0, -1, 0, 0};

    Dimension size = {
        double width = img.size.width;
        double height = img.size.height;
    };
};

JFrame f = {
    Color  background = Color.lightGray;

    paint(Rectangle r) {
        int n;

        graphics {           // "named block"
            gsave();
            rectclip(r);
            recterase(r);
            moveto(72, 144);
            img_merged.source = NULL;
            showimage(img);
            showimage(img_merged);
            for (n = 0; n < 15; n++) {
                img_merged.convert(img, new Array{5, 3, n%5, n%3});
                showimage(img_merged);
            }
            setrgbcolor(1, 0, 0);
            moveto(36, 144);
            lineto(300, 144);
            stroke();
            grestore();
        }
    }
};

f.visible = TRUE;
is a fairly complicated example that uses convert to merge one image into another in fifteen steps. Both images have metrics entries. In the first image metrics is a double, which means showimage, which is defined in Graphics, uses it as the horizontal width. In the second image we set a vertical side bearing, which controls the positioning of the image's upper left corner, but the horizontal and vertical widths are both 0, because we want to draw it in the same place 16 times.
 
 Return:   Image
 
 See Also:   convolve, getpixel, replace, rescale, setpixel, transform

 

Yoix is a registered trademark of AT&T Intellectual Property.