/**C*
 *
 * Vaisala software source code file
 *
 * Copyright (c) Vaisala Oyj 1998, 2002, 2011, 2012.
 * All rights reserved.
 *
 **C*/

/** @file
 *
 * Fileformats_Library Prototypes and Structures
 *
 * $URL: https://subversion.vaisala.com/svn/repos/sigmet/wr_iris_rda/branches/release8.13.5/base/fileformats_lib/fileformats_lib.h $
 *
 * $Id: fileformats_lib.h 29330 2013-04-23 19:25:20Z dp $
 *
 */

/* 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_UNKNOWN  0
#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
#define FILE_FORMAT_TYPE_PNG      7
#define FILE_FORMAT_TYPE_ERROR    8 

/*************************************
** 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 UINT1 PIC24_T;

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;

/** Creates localized filename (if file is present) returns char count */
int LocalizedFileName(char ** str_out, const char * str_in); /* */
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);
int ReadPNGFilename(char *filename, PICINFO *pinfo);
int ReadPNG(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 outputToPrinter24(
 PIC24_T *image_ptr_a,
 SINT4 iwidth_a, SINT4 iheight_a,
 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);

#ifdef SIGMET_PROJECTION_H
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,
 time_t time_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,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

#ifdef SIGMET_PROJECTION_H
MESSAGE outputToFile24
(
 PIC24_T *image_ptr_a,
 int32_t iwidth_a, int32_t iheight_a,
 const char *sfile_dest_path_a,
 const char *stiff_description_a,
 time_t time_a,
 uint8_t if_compress_a,          /* compression scheme */
 uint32_t ijpeg_quality_percent_a, uint16_t ifile_format_type_a,
 uint16_t ipostscript_paper_orientation_a,
 uint16_t ipostscript_paper_size_idx_a,
 uint16_t ipostscript_image_color_a,
 uint16_t ipostscript_image_position_a,
 uint16_t ipostscript_image_size_a,
 int32_t ix_offset_a, int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

MESSAGE WriteBMP24(
   FILE  *fp,
   uint8_t *image_rgb,
   int32_t iwidth_a,
   int32_t iheight_a);

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

MESSAGE WriteJPEG24(
   FILE  *fp,
   uint8_t *image_rgb,
   int32_t iwidth_a,
   int32_t iheight_a,
   time_t time_a,
   uint32_t iquality_percent_a);

MESSAGE WriteGIF24
( FILE  *fp,
  UINT1 *image_ptr_a,
  SINT4 iwidth_a,
  SINT4 iheight_a,
  int   colorstyle,
  const char  *comment);

/* File: write_png.c */
MESSAGE WritePNG
( FILE  *fp,
  UINT1 *image_ptr_a,
  SINT4 iwidth_a,
  SINT4 iheight_a,
  const struct color_def Colormap_a[256],
  int   numcols);

MESSAGE WritePNG24
( FILE  *fp,
  UINT1 *image_rgb_ptr_a,
  SINT4 iwidth_a,
  SINT4 iheight_a);

MESSAGE WritePNG32
( FILE  *fp,
  UINT1 *image_rgb_ptr_a,
  SINT4 iwidth_a,
  SINT4 iheight_a);

void WritePS24(
 FILE *fp_RGB,
 const UINT1 *image_rgb,
 int image_width_pix,
 int image_height_pix,
 const char *filename,
 int paper_orientation,
 int paper_size_idx, 
 int image_color,
 int image_pos, 
 int image_size);


#ifdef SIGMET_PROJECTION_H
MESSAGE WriteTIFF24
(uint8_t *image_rgb,
 int32_t iwidth_a,
 int32_t iheight_a,
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */


#ifdef SIGMET_PROJECTION_H
MESSAGE WriteTIFF8BitGray
(const uint8_t *image_ptr_a,
 int32_t width_a,
 int32_t height_a,
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

#ifdef SIGMET_PROJECTION_H
MESSAGE WriteTIFF8BitPalette
(const uint8_t *image_ptr_a,
 int32_t width_a,
 int32_t height_a,
 const struct color_def colormap_a[256],
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

#ifdef SIGMET_PROJECTION_H
MESSAGE WriteTIFF24BitRGB
(const uint8_t *image_ptr_a,
 int32_t width_a,
 int32_t height_a,
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

#ifdef SIGMET_PROJECTION_H
MESSAGE WriteTIFFFloat
(const float *image_ptr_a,
 int32_t iwidth_a,
 int32_t iheight_a,
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */

#ifdef SIGMET_PROJECTION_H
/* file write_tiff.c */
MESSAGE WriteTIFF
(UINT1 *image_ptr_a,
 SINT4 iwidth_a,
 SINT4 iheight_a,
 const struct color_def Colormap_a[256],
 const char *fname,
 const char *sdescription,
 time_t time_a,
 int comp_a,
 int32_t ix_offset_a,
 int32_t iy_top_offset_a,
 const struct mpj_projection8 *mpjd,
 const struct mpj_region8 *mpjr);
#endif   /* #ifdef SIGMET_PROJECTION_H */


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 */
