home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
morpho.zip
/
morpho
/
src
/
vgdiskse
/
vgdiskse.prog
< prev
Wrap
Text File
|
1992-07-31
|
6KB
|
238 lines
-AUTHORS
Greg Donohoe
-AUTHORS_END
-SHORT_PROG_DESCRIPTION
Creates a image of a disk with the origin at the center
-SHORT_PROG_DESCRIPTION_END
-SHORT_LIB_DESCRIPTION
Creates a image of a disk with the origin at the center
-SHORT_LIB_DESCRIPTION_END
-MAN1_LONG_DESCRIPTION
.I vgdiskse
creates an image of a disk. The background intensity is set by the
-b argument. The foreground or circle intensity is set by the -f argument.
The circle can be placed anywhere, and is NOT required to lie
completely within the image boundaries. The origin of the structuring
elment is placed at the center of the disk.
.LP
The position of the center of the circle and its diameter can all be
specified as floating point numbers, allowing sub-pixel positioning of
the circle.
.LP
The trigger input can be used to cause
.I vgdiskse
to re-execute when used inside cantata. No image is read from this input.
-MAN1_LONG_DESCRIPTION_END
-MAN1_EXAMPLES
vgdiskse -r 32 -c 32 -b 3.5 -f 100 -x 32 -y 16 -d 32 -t int
.LP
Creates a 32x32 image of type INT, with the background level at 3.5 and
the foreground at 107.5. The circle lies in this case halfway off the image
to the right. The diameter of the circle is 32 pixels.
-MAN1_EXAMPLES_END
-MAN1_RESTRICTIONS
.I vgdiskse
will generate only BYTE or FLOAT images.
-MAN1_RESTRICTIONS_END
-MAN1_SEE_ALSO
-MAN1_SEE_ALSO_END
-MAN3_LONG_DESCRIPTION
.I lvgdiskse
creates an image of a disk. The background intensity is set by the
-b argument. The foreground or circle intensity is set by the -f argument.
The circle can be placed anywhere, and is NOT required to lie
completely within the image boundaries. The origin of the structuring
elment is placed at the center of the disk.
.LP
The position of the center of the circle and its diameter can all be
specified as floating point numbers, allowing sub-pixel positioning of
the circle.
-MAN3_LONG_DESCRIPTION_END
-MAN3_RESTRICTIONS
.I lvgdiskse
will generate only INT or BYTE images.
-MAN3_RESTRICTIONS_END
-MAN3_SEE_ALSO
-MAN3_SEE_ALSO_END
-USAGE_ADDITIONS
-USAGE_ADDITIONS_END
-INCLUDE_INCLUDES
-INCLUDE_INCLUDES_END
-INCLUDE_ADDITIONS
-INCLUDE_ADDITIONS_END
-INCLUDE_MACROS
-INCLUDE_MACROS_END
-MAIN_VARIABLE_LIST
struct xvimage *image;
int type;
-MAIN_VARIABLE_LIST_END
-MAIN_BEFORE_LIB_CALL
if(check_args())exit(1);
if(!vget_type(&type, vgdiskse->t_toggle)){
fprintf(stderr,"vgdiskse: Invalid data type specified\n");
exit(1);
}
if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
fprintf(stderr,"%s: Illegal image data type specified.\n",program);
exit(1);
}
-MAIN_BEFORE_LIB_CALL_END
-MAIN_LIBRARY_CALL
if(! lvgdiskse( &image,type, vgdiskse->b_float, vgdiskse->f_float,
vgdiskse->origin_logic, vgdiskse->x_float,vgdiskse->y_float, vgdiskse->d_float))
{
(void) fprintf(stderr, "lvgdiskse Failed\n");
exit(1);
}
-MAIN_LIBRARY_CALL_END
-MAIN_AFTER_LIB_CALL
writeimage(vgdiskse->o_file,image);
-MAIN_AFTER_LIB_CALL_END
-LIBRARY_INCLUDES
-LIBRARY_INCLUDES_END
-LIBRARY_INPUT
.IP "image" 15
input image structure
.IP "type" 15
the data storage type of the resulting image
.IP "bgnd" 15
the background intensity
.IP "fgnd" 15
the forground intensity
.IP "origin" 15
if set, take origin as center; otherwise, user specified origin
.IP "x" 15
the X coordinate of the origin
.IP "y" 15
the Y coordinate of the origin
.IP "d" 15
diameter of circle (in pixels)
-LIBRARY_INPUT_END
-LIBRARY_OUTPUT
.IP "image" 15
holds the resulting output image.
-LIBRARY_OUTPUT_END
-LIBRARY_DEF
int
lvgdiskse (image, type, bgnd, fgnd, origin, x, y, d)
struct xvimage **image;
int type;
float bgnd,fgnd,x,y,d;
int origin;
-LIBRARY_DEF_END
-LIBRARY_CODE
{
int i,j;
unsigned char *c;
float r;
int *ipixel;
struct xvimage *img, *createimage();
int rows;
int cols;
int xorg, yorg;
int x_ctr, y_ctr;
rows = d+2;
cols = d+2;
img = createimage((unsigned long) rows, /* number of rows */
(unsigned long) cols, /* number of columns */
(unsigned long) type, /* data storage type */
(unsigned long) 1, /* num_of_images */
(unsigned long) 1, /* num_data_bands */
"created by vgdiskse", /* comment */
(unsigned long) 0, /* map_row_size */
(unsigned long) 0, /* map_col_size */
(unsigned long)
VFF_MS_NONE, /* map_scheme */
(unsigned long)
VFF_MAPTYP_NONE, /* map_storage_type */
(unsigned long)
VFF_LOC_IMPLICIT, /* location_type */
(unsigned long) 0); /* location_dim */
if (img == NULL)
{
fprintf(stderr,"lvgdiskse: Unable to allocate new image!\n");
*image = NULL;
return(0);
}
*image = img;
r = d/2.0;
r = r*r;
x_ctr = (int)d/2.0+1;
y_ctr = (int)d/2.0+1;
/* Set the SE origin: either center it, or accept user */
/* values */
if (origin) {
xorg = x_ctr/2.0;
yorg = y_ctr/2.0;
}
else {
xorg = x;
yorg = y;
}
img->ispare1 = -xorg;
img->ispare2 = -yorg;
switch(type)
{
case VFF_TYP_1_BYTE:
c = (unsigned char *)(img->imagedata);
for (i=0; i<rows; i++)
for (j=0; j<cols; j++)
if ((i-y_ctr)*(i-y_ctr)+(j-x_ctr)*(j-x_ctr) <= r) *c++ = fgnd;
else *c++ = bgnd;
break;
case VFF_TYP_4_BYTE:
ipixel = (int *)(img->imagedata);
for (i=0; i<rows; i++)
for (j=0; j<cols; j++)
if ((i-y_ctr)*(i-y_ctr)+(j-x_ctr)*(j-x_ctr) <= r) *ipixel++ = fgnd;
else *ipixel++ = bgnd;
break;
default:
fprintf(stderr,"lvgdiskse: Unsupported data storage type requested\n");
fprintf(stderr," Supported types: INT and BYTE\n");
return(0);
}
return(1);
}
-LIBRARY_CODE_END
-LIBRARY_MODS
-LIBRARY_MODS_END