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
00013 GRAYSCAL (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   )
00021 {
00022   register short j, k;
00023   char msg[SLEN];
00024   double inc =
00025     (nlev <= 1 ? 0.0 : (double) (gmax - gmin) / (double) (nlev - 1));
00026 
00027   if (TIMES)
00028     TIMING (T_GRAYSCAL);
00029   if (NAMES)
00030     {
00031       MESSAGE ('I', "");
00032       MESSAGE ('I', "GRAYSCAL");
00033       MESSAGE ('I', "");
00034       sprintf (msg, " Image size: lines:     %d", nlin);
00035       MESSAGE ('I', msg);
00036       sprintf (msg, "             pixels:    %d", npix);
00037       MESSAGE ('I', msg);
00038       sprintf (msg, " Minimum graylevel:   %12.4e", gmin);
00039       MESSAGE ('I', msg);
00040       sprintf (msg, " Maximum graylevel:   %12.4e", gmax);
00041       MESSAGE ('I', msg);
00042       sprintf (msg, " Number of graylevels:  %d", nlev);
00043       MESSAGE ('I', msg);
00044       MESSAGE ('I', " ...............");
00045     }
00046 
00047   /* check input */
00048   if (nlin <= 0)
00049     {
00050       MESSAGE ('E', " Number of lines must be greater than zero.");
00051       goto the_end;
00052     }
00053   else if (npix <= 0)
00054     {
00055       MESSAGE ('E', " Number of pixels/line must be greater than zero.");
00056       goto the_end;
00057     }
00058   else if (nlev <= 0)
00059     {
00060       MESSAGE ('E', " Number of graylevels must be greater than zero.");
00061       goto the_end;
00062     }
00063   else if (nlev > npix)
00064     {
00065       MESSAGE ('E',
00066                " Number of graylevels must be less than or equal to number of pixels/line.");
00067       goto the_end;
00068     }
00069   else if (gmin > gmax)
00070     {
00071       MESSAGE ('E',
00072                " Minimum graylevel value must be less than or equal to maximum graylevel value.");
00073       goto the_end;
00074     }
00075 
00076   /* create image of appropriate size */
00077   if (!CHECKIMG (*out))
00078     GETMEM (1, nlin, npix, out);
00079   if (!*out)
00080     goto the_end;
00081 
00082   /* create grayscale */
00083   for (k = 0; k < npix; k++)
00084     {
00085       (*out)->data[0][0][k] =
00086         (PIXEL) ((double) gmin +
00087                  (double) ((long) k * (long) nlev / (long) npix) * inc);
00088     }
00089   for (j = 1; j < nlin; j++)
00090     {
00091       for (k = 0; k < npix; k++)
00092         {
00093           (*out)->data[0][j][k] = (*out)->data[0][0][k];
00094         }
00095     }
00096   (*out)->gmin = gmin;
00097   (*out)->gmax = gmax;
00098 
00099 the_end:
00100   if (TIMES)
00101     TIMING (T_EXIT);
00102 }

Generated on Sun May 18 15:36:10 2003 for tclSadie by doxygen1.3