home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / libcnv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  210 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. //"libcnv.h"
  20. #ifndef _LIBCNV_H
  21. #define _LIBCNV_H
  22. #ifndef _IMAGE_CONVERT
  23. #error _IMAGE_CONVERT SYMBOL NEEDED BEFORE INCLUSION
  24. #endif /*_IMAGE_CONVERT*/
  25.  
  26. #ifndef __cplusplus
  27. typedef unsigned char BYTE;
  28. typedef uint32 DWORD;
  29. #endif
  30.  
  31. #include "xp_core.h"/*defines of int32 ect*/
  32. #include "xp_file.h"
  33. #include "xp_mem.h"/*XP_HUGE*/
  34.  
  35. #define MAXIMAGEPATHLEN 255
  36.  
  37.  
  38.  
  39. typedef enum
  40. {
  41.     CONV_CANCEL,
  42.     CONV_OK,
  43.     CONVERR_INVALIDSOURCE,
  44.     CONVERR_INVALIDDEST,
  45.     CONVERR_INVALIDFILEHEADER,
  46.     CONVERR_INVALIDIMAGEHEADER,
  47.     CONVERR_INVALIDBITDEPTH,
  48.     CONVERR_INVALIDCOLORMAP,
  49.     CONVERR_BADREAD,
  50.     CONVERR_OUTOFMEMORY,
  51.     CONVERR_JPEGERROR,
  52.     CONVERR_COMPRESSED,
  53.     CONVERR_BADPLANES,
  54.     CONVERR_BADWRITE,
  55.     CONVERR_INVALIDPARAMS,
  56.     CONVERR_UNKNOWN,
  57.     NUM_CONVERR
  58. }CONVERT_IMAGERESULT;
  59.  
  60.  
  61.  
  62. typedef BYTE * CONVERT_IMG_ROW;
  63. typedef CONVERT_IMG_ROW * CONVERT_IMG_ARRAY;
  64.  
  65.  
  66.  
  67. typedef enum
  68. {
  69.     conv_unknown,
  70.     conv_png,
  71.     conv_jpeg,
  72.     conv_bmp,
  73.     conv_pict,
  74.     conv_xpm,
  75.     conv_rgb,
  76.     conv_plugin
  77. }convimgenum;
  78.  
  79.  
  80. typedef struct tagCONVERT_IMG_STREAM
  81. {
  82.     XP_HUGE_CHAR_PTR m_mem;
  83.     FILE *m_file;/*used only with type 0 -must allready be opened for read or write does not use current index ect.*/
  84.     int16 m_type;/*0=CONVERT_FILE 1=CONVERT_MEMORY*/
  85.     DWORD m_streamsize;/* 0== unlimited */
  86.     DWORD m_currentindex;
  87. }CONVERT_IMG_STREAM;
  88.  
  89.  
  90.  
  91. /*Sent in a BITMAP structure*/
  92. #define CONVERT_MEMORY 1
  93. #define CONVERT_FILE 0
  94.  
  95.  
  96. typedef struct tagCONVERT_IMGCONTEXT CONVERT_IMGCONTEXT;
  97. typedef struct tagCONVERT_IMG_INFO CONVERT_IMG_INFO;
  98.  
  99. typedef CONVERT_IMAGERESULT (*CONVERT_DIALOGIMAGECALLBACK)(CONVERT_IMGCONTEXT *input,
  100.                                              CONVERT_IMGCONTEXT *outputarray,
  101.                                              CONVERT_IMG_INFO *imginfo,
  102.                                              int16 numoutput,
  103.                                              CONVERT_IMG_ARRAY imagearray);
  104. typedef CONVERT_IMAGERESULT (*CONVERT_COMPLETECALLBACK)(CONVERT_IMGCONTEXT *outputarray,int16 p_numoutputs,void *hook);
  105.  
  106. typedef void (*CONVERT_BUFFERCALLBACK)(void *);/*j_common_ptr);*/
  107.  
  108.  
  109.  
  110. typedef struct tagCONVERT_CALLBACKS
  111. {
  112.     CONVERT_DIALOGIMAGECALLBACK m_dialogimagecallback;
  113.     CONVERT_BUFFERCALLBACK m_displaybuffercallback;
  114.     CONVERT_COMPLETECALLBACK m_completecallback;
  115. }CONVERT_CALLBACKS;
  116.  
  117.  
  118.  
  119. typedef struct tagCONVERT_IMGCONTEXT
  120. {
  121.     convimgenum m_imagetype;
  122.     CONVERT_IMG_STREAM m_stream;/*used with m_streamtype 1,2*/
  123.     int16 m_quality;
  124.     char m_filename[MAXIMAGEPATHLEN];/*will not be used to open FILE *. used for output. maybe in future will open file?*/
  125.     CONVERT_CALLBACKS m_callbacks;
  126. #ifdef XP_OS2
  127.     XP_OS2_ARG(void *m_parentwindow);/*used for callbacks to bring up dialog boxes. void * = CWnd *for Windows*/
  128. #else
  129.     XP_WIN_ARG(void *m_parentwindow);/*used for callbacks to bring up dialog boxes. void * = CWnd *for Windows*/
  130. #endif
  131.     void *m_pMWContext;//used for callbacks to insert the image. and for plugins
  132. }CONVERT_IMGCONTEXT;
  133.  
  134.  
  135.  
  136. typedef struct tagCONVERT_IMG_INFO
  137. {
  138.     BYTE *m_colormap;
  139.     int16 m_numcolorentries;
  140.     uint16 m_X_density;
  141.     uint16 m_Y_density;
  142.     int16 m_density_unit;
  143.     int16 m_in_color_space;
  144.     int16 m_input_components;
  145.     int16 m_data_precision;
  146.     int16 m_image_width;/*pixel width*/
  147.     int16 m_image_height;/*pixel_height*/
  148.     int16 m_bitsperpixel;
  149.     int16 m_row_width;/*width in bytes*/
  150.     int16 m_stride; /*row_width-(pixel_width*bpp)/8 */
  151.     DWORD m_image_size; /*informational purposes*/
  152. }CONVERT_IMG_INFO;
  153.  
  154.  
  155.  
  156. #ifdef __cplusplus
  157. extern "C" 
  158. {
  159. #endif
  160.  
  161.  
  162.     
  163. /****************************/    
  164. /*API CALLS AND DECLARATIONS*/
  165. /****************************/    
  166.  
  167. /*converts input to p_numoutput many outputs*/
  168. /*p_outpuffilenames must be a PREALLOCATED array of char *s at least p_numoutputs char *s  these pointers will
  169. point to output filenames that YOU will be responsible to destroy!
  170.     you may pass in null for p_outputfilenames and it wil*/
  171. CONVERT_IMAGERESULT convert_stream2image(CONVERT_IMGCONTEXT p_input,CONVERT_IMG_INFO *p_imageinfo,int16 p_numoutputs,char **p_outputfilenames);
  172.  
  173. /*quantize_pixels will change the imagearray to have only maxcolors distinct values*/
  174. CONVERT_IMAGERESULT convert_quantize_pixels(CONVERT_IMG_ARRAY imagearray,int16 imagewidth,int16 imageheight,int16 maxcolorvalue);
  175.  
  176. /*given a imagecontext, it will tell you if it is a png,bmp,gif ect*/
  177. convimgenum select_file_type (CONVERT_IMGCONTEXT * p_input);
  178.  
  179. /****************************/    
  180. /*END API CALLS AND DECLARATIONS*/
  181. /****************************/    
  182.  
  183.  
  184. /****************************/    
  185. /*STREAM DECLARATIONS*/
  186. /****************************/    
  187.  
  188. /*CONV_IMG_FREAD taken from JPEG libraries for independence from common header file*/
  189. #define CONV_IMG_FREAD(file,buf,sizeofbuf)  \
  190.   ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  191.  
  192. #define    ReadOK(file,buffer,len)    (CONV_IMG_FREAD(file,buffer,len) == ((size_t) (len)))
  193.  
  194. int16 read_mem_stream(CONVERT_IMG_STREAM *p_stream,void *p_dest,uint16 p_bytecount);
  195. BYTE read_mem_stream_byte(CONVERT_IMG_STREAM *p_stream);
  196. int16 read_param(CONVERT_IMG_STREAM *p_input,void *p_dest,uint16 p_bytecount);
  197. BYTE read_param_byte(CONVERT_IMG_STREAM *p_input);
  198. /****************************/    
  199. /*END STREAM DECLARATIONS*/
  200. /****************************/    
  201.  
  202.  
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206.  
  207. #endif
  208.  
  209.  
  210.