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   
Text File  |  1992-07-31  |  6KB  |  238 lines

  1. -AUTHORS
  2. Greg Donohoe
  3. -AUTHORS_END
  4.  
  5. -SHORT_PROG_DESCRIPTION
  6. Creates a image of a disk with the origin at the center
  7. -SHORT_PROG_DESCRIPTION_END
  8.  
  9. -SHORT_LIB_DESCRIPTION
  10. Creates a image of a disk with the origin at the center
  11. -SHORT_LIB_DESCRIPTION_END
  12.  
  13. -MAN1_LONG_DESCRIPTION
  14. .I vgdiskse
  15. creates an image of a disk.  The background intensity is set by the
  16. -b argument. The foreground or circle intensity is set by the -f argument.
  17. The circle can be placed anywhere, and is NOT required to lie
  18. completely within the image boundaries.  The origin of the structuring
  19. elment is placed at the center of the disk.
  20. .LP
  21. The position of the center of the circle and its diameter can all be
  22. specified as floating point numbers, allowing sub-pixel positioning of
  23. the circle.
  24. .LP
  25. The trigger input can be used to cause
  26. .I vgdiskse
  27. to re-execute when used inside cantata. No image is read from this input.
  28. -MAN1_LONG_DESCRIPTION_END
  29.  
  30. -MAN1_EXAMPLES
  31. vgdiskse -r 32 -c 32 -b 3.5 -f 100 -x 32 -y 16 -d 32 -t int
  32. .LP
  33. Creates a 32x32 image of type INT, with the background level at 3.5 and
  34. the foreground at 107.5. The circle lies in this case halfway off the image
  35. to the right.  The diameter of the circle is 32 pixels.
  36. -MAN1_EXAMPLES_END
  37.  
  38. -MAN1_RESTRICTIONS
  39. .I vgdiskse
  40. will generate only BYTE or FLOAT images.
  41. -MAN1_RESTRICTIONS_END
  42.  
  43. -MAN1_SEE_ALSO
  44. -MAN1_SEE_ALSO_END
  45.  
  46. -MAN3_LONG_DESCRIPTION
  47. .I lvgdiskse
  48. creates an image of a disk.  The background intensity is set by the
  49. -b argument. The foreground or circle intensity is set by the -f argument.
  50. The circle can be placed anywhere, and is NOT required to lie
  51. completely within the image boundaries.  The origin of the structuring
  52. elment is placed at the center of the disk.
  53. .LP
  54. The position of the center of the circle and its diameter can all be
  55. specified as floating point numbers, allowing sub-pixel positioning of
  56. the circle.
  57. -MAN3_LONG_DESCRIPTION_END
  58.  
  59. -MAN3_RESTRICTIONS
  60. .I lvgdiskse
  61. will generate only INT or BYTE images.
  62. -MAN3_RESTRICTIONS_END
  63.  
  64. -MAN3_SEE_ALSO
  65. -MAN3_SEE_ALSO_END
  66.  
  67. -USAGE_ADDITIONS
  68. -USAGE_ADDITIONS_END
  69.  
  70. -INCLUDE_INCLUDES
  71. -INCLUDE_INCLUDES_END
  72.  
  73. -INCLUDE_ADDITIONS
  74. -INCLUDE_ADDITIONS_END
  75.  
  76. -INCLUDE_MACROS
  77. -INCLUDE_MACROS_END
  78.  
  79. -MAIN_VARIABLE_LIST
  80. struct xvimage *image;
  81. int type;
  82. -MAIN_VARIABLE_LIST_END
  83.  
  84. -MAIN_BEFORE_LIB_CALL
  85. if(check_args())exit(1);
  86.  
  87. if(!vget_type(&type, vgdiskse->t_toggle)){
  88.    fprintf(stderr,"vgdiskse:  Invalid data type specified\n");
  89.    exit(1);
  90. }
  91.  
  92. if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
  93.    fprintf(stderr,"%s:  Illegal image data type specified.\n",program);
  94.    exit(1);
  95. }
  96.  
  97. -MAIN_BEFORE_LIB_CALL_END
  98.  
  99. -MAIN_LIBRARY_CALL
  100. if(! lvgdiskse( &image,type, vgdiskse->b_float, vgdiskse->f_float,
  101. vgdiskse->origin_logic, vgdiskse->x_float,vgdiskse->y_float, vgdiskse->d_float))
  102.   {
  103.       (void) fprintf(stderr, "lvgdiskse Failed\n");
  104.       exit(1);
  105.   }
  106. -MAIN_LIBRARY_CALL_END
  107.  
  108. -MAIN_AFTER_LIB_CALL
  109. writeimage(vgdiskse->o_file,image);
  110. -MAIN_AFTER_LIB_CALL_END
  111.  
  112. -LIBRARY_INCLUDES
  113. -LIBRARY_INCLUDES_END
  114.  
  115. -LIBRARY_INPUT
  116. .IP "image" 15
  117. input image structure
  118. .IP "type" 15
  119. the data storage type of the resulting image
  120. .IP "bgnd" 15
  121. the background intensity
  122. .IP "fgnd" 15
  123. the forground intensity
  124. .IP "origin" 15
  125. if set,  take origin as center;  otherwise, user specified origin
  126. .IP "x" 15
  127. the X coordinate of the origin 
  128. .IP "y" 15
  129. the Y coordinate of the origin 
  130. .IP "d" 15
  131. diameter of circle (in pixels) 
  132. -LIBRARY_INPUT_END
  133.  
  134. -LIBRARY_OUTPUT
  135. .IP "image" 15
  136. holds the resulting output image.
  137. -LIBRARY_OUTPUT_END
  138.  
  139. -LIBRARY_DEF
  140. int
  141. lvgdiskse (image, type, bgnd, fgnd, origin, x, y, d)
  142. struct xvimage **image;
  143. int type;
  144. float bgnd,fgnd,x,y,d;
  145. int origin;
  146. -LIBRARY_DEF_END
  147.  
  148. -LIBRARY_CODE
  149. {
  150.   int i,j;
  151.   unsigned char *c;
  152.   float r;
  153.   int *ipixel;
  154.   struct xvimage *img, *createimage();
  155.   int rows;
  156.   int cols;
  157.   int xorg, yorg;
  158.   int x_ctr, y_ctr;
  159.  
  160.   rows = d+2;
  161.   cols = d+2;
  162.  
  163.   img   = createimage((unsigned long) rows,  /* number of rows */
  164.                      (unsigned long) cols,   /* number of columns */
  165.                      (unsigned long) type,   /* data storage type */
  166.                      (unsigned long) 1,      /* num_of_images */
  167.                      (unsigned long) 1,      /* num_data_bands */
  168.                      "created by vgdiskse",    /* comment */
  169.                      (unsigned long) 0,      /* map_row_size */
  170.                      (unsigned long) 0,      /* map_col_size */
  171.                      (unsigned long)
  172.                      VFF_MS_NONE,            /* map_scheme */
  173.                      (unsigned long)
  174.                      VFF_MAPTYP_NONE,        /* map_storage_type */
  175.                      (unsigned long)
  176.                      VFF_LOC_IMPLICIT,       /* location_type */
  177.                      (unsigned long) 0);     /* location_dim */
  178.  
  179.  
  180.   if (img == NULL)
  181.     {
  182.       fprintf(stderr,"lvgdiskse: Unable to allocate new image!\n");
  183.       *image = NULL;
  184.       return(0);
  185.     }
  186.  
  187.   *image = img;
  188.   r = d/2.0;
  189.   r = r*r;
  190.  
  191.   x_ctr = (int)d/2.0+1; 
  192.   y_ctr = (int)d/2.0+1;
  193.  
  194.   /* Set the SE origin:  either center it,  or accept user */
  195.   /*  values */
  196.   if (origin) {
  197.      xorg = x_ctr/2.0;
  198.      yorg = y_ctr/2.0;
  199.   }
  200.   else {
  201.      xorg = x;
  202.      yorg = y;
  203.   }
  204.  
  205.  img->ispare1 = -xorg;
  206.  img->ispare2 = -yorg;
  207.  
  208.   switch(type)
  209.     {
  210.       case VFF_TYP_1_BYTE:
  211.         c = (unsigned char *)(img->imagedata);
  212.         for (i=0; i<rows; i++)
  213.           for (j=0; j<cols; j++)
  214.             if ((i-y_ctr)*(i-y_ctr)+(j-x_ctr)*(j-x_ctr) <= r) *c++ = fgnd;
  215.             else *c++ = bgnd;
  216.         break;
  217.       case VFF_TYP_4_BYTE:
  218.         ipixel = (int *)(img->imagedata);
  219.         for (i=0; i<rows; i++)
  220.           for (j=0; j<cols; j++)
  221.             if ((i-y_ctr)*(i-y_ctr)+(j-x_ctr)*(j-x_ctr) <= r) *ipixel++ = fgnd;
  222.             else *ipixel++ = bgnd;
  223.         break;
  224.       default:
  225.         fprintf(stderr,"lvgdiskse: Unsupported data storage type requested\n");
  226.         fprintf(stderr,"         Supported types: INT and BYTE\n");
  227.         return(0);
  228.     }
  229.  
  230.   return(1);
  231. }
  232. -LIBRARY_CODE_END
  233.  
  234. -LIBRARY_MODS
  235.  
  236. -LIBRARY_MODS_END
  237.  
  238.