home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gbmos2.zip / gbm.h < prev    next >
C/C++ Source or Header  |  1999-01-03  |  7KB  |  192 lines

  1. /*
  2.  
  3. gbm.h - Generalised Bitmap Module
  4.  
  5. Data is stored as an array of lines.
  6. Lines are stored with bottom line first, moving upwards.
  7. Each line is an array of pixels, leftmost first.
  8. Lines are padded to be a multiple of a dword long.
  9. Palettised pixels are either a 1 bit, 4 bit, or 8 bit indexes.
  10. Alternately a B, G, R triple in that order is stored.
  11. This format exactly matches the format used by OS/2 and Windows bitmaps.
  12.  
  13. One notable point: a 1 in a 1bpp image denotes colour 1, as found by
  14. looking at palette entry 1. Data is not inversed when passed to and from GBM.
  15.  
  16. This interface file provides access to routines for reading and writing
  17. bitmaps in a variety of image file formats.
  18.  
  19. Normally file I/O is done using lseek,read and write. Occasionally GBM
  20. needs to access additional files, and it uses open and close to do this.
  21. Sometimes it needs to create a new file, and GBM uses create and close
  22. for this. The 'create' function is an invokation of open with
  23. O_CREAT|O_TRUNC combined with the mode flags it is passed, and
  24. S_IREAD|S_IWRITE passed as the additional optional parameter.
  25.  
  26. You can trick GBM into using your own versions of open, create, close,
  27. lseek, read and write routines, by calling gbm_io_setup.
  28.  
  29. One example use of this is that the file descriptor could then be an index
  30. into a array of pointers to C++ iostreams, thus allowing GBM to read and
  31. write file data to and from memory.
  32.  
  33. On some platforms, the GBM file I/O library may be provided in DLL form.
  34. Therefore it can have its own C run time library, and on some platforms
  35. file descriptors obtained by an executable do not make sense to the
  36. C run time which is a part of the DLL. Hence GBM will be unable to use
  37. the file descriptor. One solution is to use gbm_io_setup to get the GBM
  38. library to call back into the calling application and use its C run time.
  39. Another solution is to have the application use the GBM libraries C run
  40. time to open the file - this is made possible via the gbm_io_ routines.
  41. This is the easier solution, and is used by the sample GBM programs.
  42. The particular offending platform is Visual C++ on Windows NT, everything
  43. works fine for VisualAge C++ on OS/2.
  44.  
  45. gbm_read_header shall seek to the start of the stream indentified by the
  46. file descriptor argument and then shall invoke the bitmap header reader
  47. routine identified by the format type variable.
  48.  
  49. gbm_read_palette may only be legally invoked after an immediately
  50. preceeding gbm_read_header.
  51.  
  52. gbm_read_data may only be legally invoked after an immediately preceeding
  53. gbm_read_palette. In the case of a 24bpp file (which therefore has no
  54. palette), gbm_read_data is additionally allowed to follow a gbm_read_header.
  55.  
  56. */
  57.  
  58. #ifndef GBM_H
  59. #define    GBM_H
  60.  
  61. #ifndef BOOLEAN_DEFINED
  62. #define    BOOLEAN_DEFINED
  63. typedef    int BOOLEAN;
  64. #define    TRUE  1
  65. #define    FALSE 0
  66. #endif
  67.  
  68. #ifndef BASICTYPES_DEFINED
  69. #define    BASICTYPES_DEFINED
  70. typedef unsigned  char  byte;
  71. typedef unsigned short  word;
  72. typedef unsigned  long dword;
  73. #endif
  74.  
  75. typedef int GBM_ERR;
  76. #define    GBM_ERR_OK        ((GBM_ERR) 0)
  77. #define    GBM_ERR_MEM        ((GBM_ERR) 1)
  78. #define    GBM_ERR_NOT_SUPP    ((GBM_ERR) 2)
  79. #define    GBM_ERR_BAD_OPTION    ((GBM_ERR) 3)
  80. #define    GBM_ERR_NOT_FOUND    ((GBM_ERR) 4)
  81. #define    GBM_ERR_BAD_MAGIC    ((GBM_ERR) 5)
  82. #define    GBM_ERR_BAD_SIZE    ((GBM_ERR) 6)
  83. #define    GBM_ERR_READ        ((GBM_ERR) 7)
  84. #define    GBM_ERR_WRITE        ((GBM_ERR) 8)
  85. #define    GBM_ERR_BAD_ARG        ((GBM_ERR) 9)
  86.  
  87. #define    GBM_FT_R1        0x0001
  88. #define    GBM_FT_R4        0x0002
  89. #define    GBM_FT_R8        0x0004
  90. #define    GBM_FT_R24        0x0008
  91. #define    GBM_FT_W1        0x0010
  92. #define    GBM_FT_W4        0x0020
  93. #define    GBM_FT_W8        0x0040
  94. #define    GBM_FT_W24        0x0080
  95.  
  96. typedef struct
  97.     {
  98.     char *short_name;        /* Eg: "Targa"                       */
  99.     char *long_name;        /* Eg: "Truevision Targa / Vista"    */
  100.     char *extensions;        /* Eg: "TGA VST"                     */
  101.     int flags;            /* What functionality exists         */
  102.     } GBMFT;
  103.  
  104. typedef struct { byte r, g, b; } GBMRGB;
  105.  
  106. #define    PRIV_SIZE 2000
  107.  
  108. typedef struct
  109.     {
  110.     int w, h, bpp;            /* Bitmap dimensions                 */
  111.     byte priv[PRIV_SIZE];        /* Private internal buffer           */
  112.     } GBM;
  113.  
  114. #ifndef _GBM_
  115.  
  116. #if defined(OS2)
  117. #define    GBMEXPORT
  118. #define    GBMENTRY _Optlink
  119. #elif defined(WIN32)
  120. #define    GBMEXPORT __declspec(dllexport)
  121. #define    GBMENTRY __stdcall
  122. #elif defined(DOS32)
  123. #define    GBMEXPORT
  124. #define    GBMENTRY __export _cdecl
  125. #else
  126. #define    GBMEXPORT
  127. #define    GBMENTRY
  128. #endif
  129.  
  130. GBMEXPORT GBM_ERR GBMENTRY gbm_init(void);
  131. GBMEXPORT GBM_ERR GBMENTRY gbm_deinit(void);
  132.  
  133. GBMEXPORT GBM_ERR GBMENTRY gbm_io_setup(
  134.     int  (*open  )(const char *fn, int mode),
  135.     int  (*create)(const char *fn, int mode),
  136.     void (*close )(int fd),
  137.     long (*lseek )(int fd, long pos, int whence),
  138.     int  (*read  )(int fd, void *buf, int len),
  139.     int  (*write )(int fd, const void *buf, int len)
  140.     );
  141.  
  142. GBMEXPORT int  GBMENTRY gbm_io_open  (const char *fn, int mode);
  143. GBMEXPORT int  GBMENTRY gbm_io_create(const char *fn, int mode);
  144. GBMEXPORT void GBMENTRY gbm_io_close (int fd);
  145. GBMEXPORT long GBMENTRY gbm_io_lseek (int fd, long pos, int whence);
  146. GBMEXPORT int  GBMENTRY gbm_io_read  (int fd, void *buf, int len);
  147. GBMEXPORT int  GBMENTRY gbm_io_write (int fd, const void *buf, int len);
  148.  
  149. GBMEXPORT GBM_ERR GBMENTRY gbm_query_n_filetypes(int *n_ft);
  150. GBMEXPORT GBM_ERR GBMENTRY gbm_query_filetype(int ft, GBMFT *gbmft);
  151. GBMEXPORT GBM_ERR GBMENTRY gbm_guess_filetype(const char *fn, int *ft);
  152.  
  153. GBMEXPORT GBM_ERR GBMENTRY gbm_read_header(const char *fn, int fd, int ft, GBM *gbm, const char *opt);
  154. GBMEXPORT GBM_ERR GBMENTRY gbm_read_palette(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
  155. GBMEXPORT GBM_ERR GBMENTRY gbm_read_data(int fd, int ft, GBM *gbm, byte *data);
  156. GBMEXPORT GBM_ERR GBMENTRY gbm_write(const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt);
  157.  
  158. GBMEXPORT const char * GBMENTRY gbm_err(GBM_ERR rc);
  159.  
  160. GBMEXPORT int     GBMENTRY gbm_version(void);
  161.  
  162. #ifdef OS2
  163. /*...s_System entrypoints:0:*/
  164. /* For GBM.DLL to be callable from IBM Smalltalk under OS/2, the entrypoints
  165.    must be of _System calling convention. These veneers help out here.
  166.    I can't just change the usual entrypoints because people depend on them.
  167.    For portability, avoid these entrypoints, use the gbm_ ones. */
  168.  
  169. GBM_ERR _System Gbm_init(void);
  170. GBM_ERR _System Gbm_deinit(void);
  171. int     _System Gbm_io_open(const char *fn, int mode);
  172. int     _System Gbm_io_create(const char *fn, int mode);
  173. void    _System Gbm_io_close(int fd);
  174. long    _System Gbm_io_lseek(int fd, long pos, int whence);
  175. int     _System Gbm_io_read (int fd, void *buf, int len);
  176. int     _System Gbm_io_write(int fd, const void *buf, int len);
  177. GBM_ERR _System Gbm_query_n_filetypes(int *n_ft);
  178. GBM_ERR    _System Gbm_guess_filetype(const char *fn, int *ft);
  179. GBM_ERR _System Gbm_query_filetype(int ft, GBMFT *gbmft);
  180. GBM_ERR _System Gbm_read_header(const char *fn, int fd, int ft, GBM *gbm, const char *opt);
  181. GBM_ERR _System Gbm_read_palette(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
  182. GBM_ERR _System Gbm_read_data(int fd, int ft, GBM *gbm, byte *data);
  183. GBM_ERR _System Gbm_write(const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt);
  184. const char * _System Gbm_err(GBM_ERR rc);
  185. int     _System Gbm_version(void);
  186. /*...e*/
  187. #endif
  188.  
  189. #endif
  190.  
  191. #endif
  192.