home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TIFF / TACS40.ZIP / TIFF421.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-27  |  6.4 KB  |  224 lines

  1. /***************************************************************************\
  2. *
  3. * PVCS Software Configuration Management Control Information
  4. *
  5. * TIFF421.C
  6. *
  7. * $Revision:   1.0  $
  8. *
  9. * $Date:   20 Mar 1988 18:14:28  $
  10. *
  11. * $Author:   tomh  $
  12. *
  13. * $Logfile:   F:/public/gads/product/src/tiff421.c_v  $
  14. *
  15. * $Log:   F:/public/gads/product/src/tiff421.c_v  $
  16. *    
  17. *       Rev 1.0   20 Mar 1988 18:14:28   tomh
  18. *    Initial revision.
  19. *
  20. \***************************************************************************/
  21.  
  22. /*
  23.     tiff421.c the tiff file open and read routines for the 421
  24.     prototype.
  25.  
  26.     written by B. G. Madsen
  27.  
  28.     June 15, 1987
  29.     Modified July 13, 1987
  30.  
  31.     includes -
  32. */
  33.  
  34. /* #include "windows.h" */
  35. /* #include "gawb.h" */
  36. #include "wintypes.h"
  37. #include "tiffint.h"
  38.  
  39. #define FULL_RES    1
  40. #define PLANE_1     1
  41. #define BITSPERBYTE    8
  42.  
  43. /* externals from the tiff library */
  44. extern short read_tag();
  45. extern int read_image();
  46. extern void close_image();
  47. extern void close_read();
  48. extern void close();
  49.  
  50. /* library exports */
  51. short TLGetTiff();
  52. long  TLReadLine();
  53. void  TLCloseImg();
  54.  
  55. /* global variables */
  56. /* note, if defined elsewhere, these definetions should be proceeded with */
  57. /* a extern */
  58.  
  59. static int RowsStrip;   /* how many rows/strip in image file */
  60. static int Bytes_Per_Line;    /*the number of bytes needed to read in one scan line */
  61. static unsigned int Width;        /*the width of the image in pixels */
  62. static unsigned int Length;        /* the length of the image in pixels */
  63. static int Bits_per_Pixel;    /* the number of bits per pixel */
  64. static int Black_Level;     /* a variable describing if 0 or 1 is black */
  65. static int scan_direction;    /* a variable describing how the image was scanned */
  66.                 /* see the tiff specification for more information */
  67.                 /* for our application, this value will always be 1*/
  68. static RATIO    Xresolution;    /* horizontal resolution */
  69. static RATIO    Yresolution;    /* vertical resolution */
  70.  
  71.  
  72. /************************************************************************
  73.  *                                    *
  74.  * open_tiff - open tiff will open a tiff file and read the following    *
  75.  *    parameters from the file:                    *
  76.  *        width,height,samples per pixel, bits per sample,    *
  77.  *        black level, scan_direction                *
  78.  *        These paramters are passed back through global values    *
  79.  *                                    *
  80.  *    parameters needed for the call:                 *
  81.  *        HWND hWnd;    a handle to the current window        *
  82.  *        LPSTR *fname;  a character pointer to the name of the    *
  83.  *                the file                *
  84.  *                                    *
  85.  *                                    *
  86.  *    the function will return -1 for failure, the file handle if    *
  87.  *    the function was successful                    *
  88.  *                                    *
  89.  ***********************************************************************/
  90.  
  91. short TLGetTiff(hDataFile, Tiffdata)
  92. HANDLE        hDataFile;    /* handle to the tiff file */
  93. TIFF_DATA    *Tiffdata;    /* tiff data structure */
  94. {
  95.     int samples_per_pixel;
  96.     int bits_per_sample;
  97.  
  98.     /* now read the tiff file's tag list */
  99.  
  100.     if(!read_tag(hDataFile,FULL_RES,TAG_SAMPIX,(LPSTR)&samples_per_pixel,
  101.         (short)sizeof(samples_per_pixel))){
  102.               samples_per_pixel = 1;
  103.     }
  104.  
  105.     if(!read_tag(hDataFile,FULL_RES,TAG_BITSPIX,(LPSTR)&bits_per_sample,
  106.         (short)sizeof(bits_per_sample))){
  107.               bits_per_sample = 1;
  108.     }
  109.  
  110.     if(!read_tag(hDataFile,FULL_RES,TAG_IMWIDTH,(LPSTR)&Width,
  111.         (short)sizeof(Width))){
  112.               return(-1);
  113.     }
  114.  
  115.     if(!read_tag(hDataFile,FULL_RES,TAG_IMLENGTH,(LPSTR)&Length,
  116.         (short)sizeof(Length))){
  117.               return(-1);
  118.     }
  119.  
  120.     if(!read_tag(hDataFile,FULL_RES,TAG_PHOTOINTERP,(LPSTR)&Black_Level,
  121.         (short)sizeof(Black_Level))){
  122.               return(-1);
  123.     }
  124.  
  125. /*    if(!read_tag(hDataFile,FULL_RES,TAG_ORIENT,(LPSTR)&scan_direction,
  126.         (short)sizeof(scan_direction))){
  127.               return(-1);
  128.     } */
  129.  
  130.     if(!read_tag(hDataFile,FULL_RES,TAG_XRES,(LPSTR)&Xresolution,
  131.         (short)sizeof(RATIO))){
  132.               return(-1);
  133.     }
  134.  
  135.     if(!read_tag(hDataFile,FULL_RES,TAG_YRES,(LPSTR)&Yresolution,
  136.         (short)sizeof(RATIO))){
  137.               return(-1);
  138.     }
  139.  
  140.     if(!read_tag(hDataFile,FULL_RES,TAG_ROW_STRIP,(LPSTR)&RowsStrip,
  141.         (short)sizeof(RATIO))){
  142.               return(-1);
  143.     }
  144.  
  145.     Bytes_Per_Line= ((Width * bits_per_sample * samples_per_pixel) + 7) / 8;
  146.  
  147.     Bits_per_Pixel = bits_per_sample * samples_per_pixel;
  148.  
  149.     /* move data to the tiff_open structure */
  150.     Tiffdata->BytesPerLine = Bytes_Per_Line;
  151.     Tiffdata->TiffWidth = Width;
  152.     Tiffdata->TiffLength = Length;
  153.     Tiffdata->BitsPerPixel = Bits_per_Pixel;
  154.     Tiffdata->BlackLevel = Black_Level;
  155.     Tiffdata->ScanDirection = scan_direction;
  156.     Tiffdata->RowsPerStrip = RowsStrip;
  157.     Tiffdata->Tiffxresolution = (short)Xresolution.upper;
  158.     Tiffdata->Tiffyresolution = (short)Yresolution.upper;
  159.  
  160.     return(0);
  161. }
  162.  
  163.  
  164. /************************************************************************
  165.  *                                    *
  166.  * function ReadLine(Window_handle, Filehandle,buffer,lineno,        *
  167.  *                        number_of_lines)    *
  168.  *    ReadLine reads number of lines of image data into a buffer    *
  169.  *    starting at the line number specified.                *
  170.  *        paramters are:                        *
  171.  *            Window_handle - a handle to the current     *
  172.  *            window.                     *
  173.  *            Filehandle - a handle to a file opened for    *
  174.  *            reading.                    *
  175.  *            buffer - a long pointer to a character buffer    *
  176.  *            to hold the returned data.            *
  177.  *            lineno - a long indictating where to start    *
  178.  *            reading.                    *
  179.  *            number_of_lines - a long specifying how many    *
  180.  *            lines to read.                    *
  181.  *    NOTE: the space available to the buffer must be greater than    *
  182.  *        or equal to the number_of_lines * bytes_per_line.    *
  183.  *        The function will fail if this requirment is not met.    *
  184.  *                                    *
  185.  *    The function returns the linenumber where scanning would begin    *
  186.  *    if a sequental read was to be done.                *
  187.  *                                    *
  188.  ************************************************************************/
  189.  
  190. LONG TLReadLine(hDataFile,buffer,lineno,number_of_lines)
  191. /* HWND hWnd; */
  192. HANDLE    hDataFile;    /* ms-dos file descriptor */
  193. LPSTR    buffer;
  194. unsigned long    lineno;
  195. unsigned long    number_of_lines;
  196. {
  197.  
  198.     int retval;
  199.     char buf[200];
  200.  
  201.     if((retval = read_image (hDataFile,FULL_RES,
  202.                 PLANE_1,lineno,number_of_lines,
  203.                 buffer,
  204.                 Bytes_Per_Line*number_of_lines)) == NULL){
  205.  
  206.     /*    MessageBox(hWnd,"Cannot read image from TIFF file",
  207.             "",MB_OK); */
  208.         return(-1);
  209.     }
  210.     return(lineno+=number_of_lines);
  211. }
  212.  
  213.  
  214. /* close_img(hDatafile) - close a tiff file read */
  215. /* needs to be passed the handle to the open file. */
  216.  
  217. void TLCloseImg(hDataFile)
  218. HANDLE hDataFile;
  219. {
  220.  
  221.     close_read(hDataFile);
  222. /*    close(hDataFile); */
  223. }
  224.