source: branches/v2.9/JPGPROC/source/gbm.h@ 20

Last change on this file since 20 was 2, checked in by stevenhl, 8 years ago

Import sources from cwmm-full.zip dated 2005-03-21

File size: 7.0 KB
Line 
1/*
2
3gbm.h - Generalised Bitmap Module
4
5Data is stored as an array of lines.
6Lines are stored with bottom line first, moving upwards.
7Each line is an array of pixels, leftmost first.
8Lines are padded to be a multiple of a dword long.
9Palettised pixels are either a 1 bit, 4 bit, or 8 bit indexes.
10Alternately a B, G, R triple in that order is stored.
11This format exactly matches the format used by OS/2 and Windows bitmaps.
12
13One notable point: a 1 in a 1bpp image denotes colour 1, as found by
14looking at palette entry 1. Data is not inversed when passed to and from GBM.
15
16This interface file provides access to routines for reading and writing
17bitmaps in a variety of image file formats.
18
19Normally file I/O is done using lseek,read and write. Occasionally GBM
20needs to access additional files, and it uses open and close to do this.
21Sometimes it needs to create a new file, and GBM uses create and close
22for this. The 'create' function is an invokation of open with
23O_CREAT|O_TRUNC combined with the mode flags it is passed, and
24S_IREAD|S_IWRITE passed as the additional optional parameter.
25
26You can trick GBM into using your own versions of open, create, close,
27lseek, read and write routines, by calling gbm_io_setup.
28
29One example use of this is that the file descriptor could then be an index
30into a array of pointers to C++ iostreams, thus allowing GBM to read and
31write file data to and from memory.
32
33On some platforms, the GBM file I/O library may be provided in DLL form.
34Therefore it can have its own C run time library, and on some platforms
35file descriptors obtained by an executable do not make sense to the
36C run time which is a part of the DLL. Hence GBM will be unable to use
37the file descriptor. One solution is to use gbm_io_setup to get the GBM
38library to call back into the calling application and use its C run time.
39Another solution is to have the application use the GBM libraries C run
40time to open the file - this is made possible via the gbm_io_ routines.
41This is the easier solution, and is used by the sample GBM programs.
42The particular offending platform is Visual C++ on Windows NT, everything
43works fine for VisualAge C++ on OS/2.
44
45gbm_read_header shall seek to the start of the stream indentified by the
46file descriptor argument and then shall invoke the bitmap header reader
47routine identified by the format type variable.
48
49gbm_read_palette may only be legally invoked after an immediately
50preceeding gbm_read_header.
51
52gbm_read_data may only be legally invoked after an immediately preceeding
53gbm_read_palette. In the case of a 24bpp file (which therefore has no
54palette), 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
63typedef int BOOLEAN;
64#define TRUE 1
65#define FALSE 0
66#endif
67
68#ifndef BASICTYPES_DEFINED
69#define BASICTYPES_DEFINED
70typedef unsigned char byte;
71typedef unsigned short word;
72typedef unsigned long dword;
73#endif
74
75typedef 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
96typedef 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
104typedef struct { byte r, g, b; } GBMRGB;
105
106#define PRIV_SIZE 2000
107
108typedef 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
130GBMEXPORT GBM_ERR GBMENTRY gbm_init(void);
131GBMEXPORT GBM_ERR GBMENTRY gbm_deinit(void);
132
133GBMEXPORT 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
142GBMEXPORT int GBMENTRY gbm_io_open (const char *fn, int mode);
143GBMEXPORT int GBMENTRY gbm_io_create(const char *fn, int mode);
144GBMEXPORT void GBMENTRY gbm_io_close (int fd);
145GBMEXPORT long GBMENTRY gbm_io_lseek (int fd, long pos, int whence);
146GBMEXPORT int GBMENTRY gbm_io_read (int fd, void *buf, int len);
147GBMEXPORT int GBMENTRY gbm_io_write (int fd, const void *buf, int len);
148
149GBMEXPORT GBM_ERR GBMENTRY gbm_query_n_filetypes(int *n_ft);
150GBMEXPORT GBM_ERR GBMENTRY gbm_query_filetype(int ft, GBMFT *gbmft);
151GBMEXPORT GBM_ERR GBMENTRY gbm_guess_filetype(const char *fn, int *ft);
152
153GBMEXPORT GBM_ERR GBMENTRY gbm_read_header(const char *fn, int fd, int ft, GBM *gbm, const char *opt);
154GBMEXPORT GBM_ERR GBMENTRY gbm_read_palette(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
155GBMEXPORT GBM_ERR GBMENTRY gbm_read_data(int fd, int ft, GBM *gbm, byte *data);
156GBMEXPORT 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
158GBMEXPORT const char * GBMENTRY gbm_err(GBM_ERR rc);
159
160GBMEXPORT 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
169GBM_ERR _System Gbm_init(void);
170GBM_ERR _System Gbm_deinit(void);
171int _System Gbm_io_open(const char *fn, int mode);
172int _System Gbm_io_create(const char *fn, int mode);
173void _System Gbm_io_close(int fd);
174long _System Gbm_io_lseek(int fd, long pos, int whence);
175int _System Gbm_io_read (int fd, void *buf, int len);
176int _System Gbm_io_write(int fd, const void *buf, int len);
177GBM_ERR _System Gbm_query_n_filetypes(int *n_ft);
178GBM_ERR _System Gbm_guess_filetype(const char *fn, int *ft);
179GBM_ERR _System Gbm_query_filetype(int ft, GBMFT *gbmft);
180GBM_ERR _System Gbm_read_header(const char *fn, int fd, int ft, GBM *gbm, const char *opt);
181GBM_ERR _System Gbm_read_palette(int fd, int ft, GBM *gbm, GBMRGB *gbmrgb);
182GBM_ERR _System Gbm_read_data(int fd, int ft, GBM *gbm, byte *data);
183GBM_ERR _System Gbm_write(const char *fn, int fd, int ft, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt);
184const char * _System Gbm_err(GBM_ERR rc);
185int _System Gbm_version(void);
186/*...e*/
187#endif
188
189#endif
190
191#endif
Note: See TracBrowser for help on using the repository browser.