Main Page   Data Structures   File List   Data Fields   Globals  

grayscal.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function generates a horizontal grayscale pattern.                  */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void GRAYSCAL (
00013 short nlin,     /*  I   Number of lines in the output image.                  */
00014 short npix,     /*  I   Number of pixels/line in the output image.            */
00015 short nlev,     /*  I   Number of graylevels in the output image.             */
00016 PIXEL gmin,     /*  I   Minimum graylevel.                                    */
00017 PIXEL gmax,     /*  I   Maximum graylevel.                                    */
00018 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00019 /*----------------------------------------------------------------------------*/
00020 ) { register short j, k;
00021     char   msg[SLEN];
00022     double inc=(nlev<=1 ? 0.0:(double)(gmax-gmin)/(double)(nlev-1));
00023 
00024     if (TIMES) TIMING(T_GRAYSCAL);
00025     if (NAMES) {
00026         MESSAGE('I',"");
00027         MESSAGE('I',"GRAYSCAL");
00028         MESSAGE('I',"");
00029         sprintf(msg," Image size: lines:     %d",nlin);
00030         MESSAGE('I',msg);
00031         sprintf(msg,"             pixels:    %d",npix);
00032         MESSAGE('I',msg);
00033         sprintf(msg," Minimum graylevel:   %12.4e",gmin);
00034         MESSAGE('I',msg);
00035         sprintf(msg," Maximum graylevel:   %12.4e",gmax);
00036         MESSAGE('I',msg);
00037         sprintf(msg," Number of graylevels:  %d",nlev);
00038         MESSAGE('I',msg);
00039         MESSAGE('I'," ...............");
00040     }
00041 
00042     /* check input */
00043     if (nlin <= 0) {
00044         MESSAGE('E'," Number of lines must be greater than zero.");
00045         goto the_end;
00046     } else if (npix <= 0) {
00047         MESSAGE('E'," Number of pixels/line must be greater than zero.");
00048         goto the_end;
00049     } else if (nlev <= 0) {
00050         MESSAGE('E'," Number of graylevels must be greater than zero.");
00051         goto the_end;
00052     } else if (nlev > npix) {
00053         MESSAGE('E'," Number of graylevels must be less than or equal to number of pixels/line.");
00054         goto the_end;
00055     } else if (gmin > gmax) {
00056         MESSAGE('E', " Minimum graylevel value must be less than or equal to maximum graylevel value.");
00057         goto the_end;
00058     }
00059 
00060     /* create image of appropriate size */
00061     if (!CHECKIMG(*out)) GETMEM(1,nlin,npix,out);
00062     if (!*out) goto the_end;
00063 
00064     /* create grayscale */
00065     for (k=0; k<npix; k++) {
00066         (*out)->data[0][0][k] = (PIXEL)((double)gmin+(double)((long)k*(long)nlev/(long)npix)*inc);
00067     }
00068     for (j=1; j<nlin; j++) {
00069         for (k=0; k<npix; k++) {
00070             (*out)->data[0][j][k] = (*out)->data[0][0][k];
00071         }
00072     }
00073     (*out)->gmin = gmin;
00074     (*out)->gmax = gmax;
00075 
00076     the_end:
00077     if (TIMES) TIMING(T_EXIT);
00078 }

Generated on Wed Apr 9 08:56:06 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002