/* ***************************************************
 * *                                                 *
 * *  Fileformats Library Prototypes and Structures  *
 * *                                                 *
 * ***************************************************
 * File: include/fileformats_lib.h
 *
 *                    COPYRIGHT (c) 1998, 2002  BY 
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.  
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED. 
 */ 

/* Include requirements:
 *  <stdio.h>
 */
#ifndef SIGMET_FILEFORMATS_LIB_H
#define SIGMET_FILEFORMATS_LIB_H 1

#ifdef __cplusplus
extern "C" {
#endif

/***********************************
**
**  File format stuff *
**
*******************************/
#define FILE_FORMAT_TYPE_BMP   1
#define FILE_FORMAT_TYPE_GIF   2
#define FILE_FORMAT_TYPE_JPEG  3
#define FILE_FORMAT_TYPE_TIFF  4
#define FILE_FORMAT_TYPE_PS    5
#define FILE_FORMAT_TYPE_PBM   6

/*************************************
** Printer Func stuff
*************************************/
/*Postscript options */
#define PAPER_SIZE_8x11        0
#define PAPER_SIZE_8x14        1
#define PAPER_SIZE_11x17       2
#define PAPER_SIZE_A4          3
#define PAPER_SIZE_A3          4
#define PAPER_SIZE_MAX         4  /* Set to maximum allowed paper size */

#define PAPER_ORIENT_PORT      0
#define PAPER_ORIENT_LAND      1

#define IMAGE_COLOR_FULLCOLOR  0
#define IMAGE_COLOR_GRAYSCALE  1

#define IMAGE_POS_CENTER       0
#define IMAGE_POS_ORIGIN       1

#define IMAGE_SIZE_ORIGINAL    0
#define IMAGE_SIZE_MAX         1

#define OUTPUT_TO_PRINTER      0
#define OUTPUT_TO_FILE         1

/**********************************
** values 'picType' can take 
***********************************/
/* indicies into conv24MB */
#define CONV24_8BIT  0
#define CONV24_24BIT 1
#define CONV24_SEP1  2
#define CONV24_LOCK  3
#define CONV24_SEP2  4
#define CONV24_FAST  5
#define CONV24_SLOW  6
#define CONV24_BEST  7
#define CONV24_MAX   8

#define PIC8  CONV24_8BIT
#define PIC24 CONV24_24BIT

#define F_FULLCOLOR 1
#define F_GREYSCALE 2
#define F_REDUCED   3
#define F_BWDITHER  4

typedef struct 
{ UINT1 *pic;                 /* image data */
  int   w, h;                 /* pic size */
  int   type;                 /* PIC8 or PIC24 */

  int   iColorMapSize;
  /*  UINT1 r[256],g[256],b[256]; */
  struct color_def Colormap[256];
  int   normw, normh;         /* 'normal size' of image file */
                                                
  int   colType;              /* def. Color type to save in */
  char  fullInfo[128];        /* Format: field in info box */
  char  shrtInfo[128];        /* short format info */
  char  *comment;             /* comment text */
} PICINFO;

int GetPictureType(char *filename); /* Return file format type */
int ReadPictureFile(char *fname, PICINFO *pinfo);
int ReadPBM(char *fname, PICINFO *pinfo);
int ReadJPEG( char *fname, PICINFO *pinfo);
int ReadTIFF(char *fname, PICINFO *pinfo);
int ReadGIFFilename(char *filename, PICINFO *pinfo);
int ReadGIF(const UINT1 *pData_a, SINT4 iFileSize_a, PICINFO *pinfo);
  void RgbFromColormap              /* File: ColormapFromRgb.c */
  (UINT1 iRed_a[256],
   UINT1 iGreen_a[256],
   UINT1 iBlue_a[256],
   volatile const struct color_def Colormap_a[256] );

MESSAGE outputToPrinter(
 UINT1 *image_ptr_a,
 SINT4 iwidth_a, SINT4 iheight_a,
  const struct color_def Colormap_a[256],
 const char *sprinter_que_a,
 UINT2 ifile_format_type_a,
 UINT2 ipostscript_paper_orientation_a,
 UINT2 ipostscript_paper_size_idx_a,
 UINT2 ipostscript_image_color_a,
 UINT2 ipostscript_image_position_a,
 UINT2 ipostscript_image_size_a);


MESSAGE outputToFile 
(
 UINT1 *image_ptr_a,
 SINT4 iwidth_a, SINT4 iheight_a,
 const struct color_def Colormap_a[256],
 const char *sfile_dest_path_a,
 const char *stiff_description_a,
 const char *sdatetime_a,
 UINT1 if_compress_a,          /* compression scheme */
 UINT4 ijpeg_quality_percent_a, UINT2 ifile_format_type_a,
 UINT2 ipostscript_paper_orientation_a,
 UINT2 ipostscript_paper_size_idx_a,
 UINT2 ipostscript_image_color_a,
 UINT2 ipostscript_image_position_a,
 UINT2 ipostscript_image_size_a);

MESSAGE WriteGIF
( FILE  *fp,                        /* File: write_gif.c */
  UINT1 *image_ptr_a,
  SINT4 iwidth_a,
  SINT4 iheight_a,
  const struct color_def Colormap_a[256],
  int   numcols,
  int   colorstyle,
  const char  *comment);

UINT1 *Conv24to8(
   const UINT1 *pic24, int w, int h, int nc,
   struct color_def Colormap_a[256] ); 

void pr_get_paper_size(SINT4 paper_size_idx, 
  FLT4 *paper_width, FLT4 *paper_height);

#ifdef __cplusplus
}
#endif
#endif /* #ifndef SIGMET_FILEFORMATS_LIB_H */
