gimex.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* Copyright (C) Electronic Arts Canada Inc. 1994-2002. All rights reserved. */
  19. /* ABSTRACT
  20. gimex.h - Primary header file for the GIMEX API.
  21. @ */
  22. /*------------------------------------------------------------------*/
  23. /* */
  24. /* Graphics IMport EXport API v3.46 */
  25. /* */
  26. /* by Frank Barchard, EAC */
  27. /* */
  28. /* Header Module - Dec 05, 2002 */
  29. /* */
  30. /*------------------------------------------------------------------*/
  31. /* */
  32. /* Version Date SE History */
  33. /* ------- ------ -- ------- */
  34. /* 3.01 ------ FB gref void * */
  35. /* 3.02 ------ FB const GIMEX_write */
  36. /* 3.10 ------ FB 16 bpp import */
  37. /* 3.11 ------ FB gbitmap->image void * */
  38. /* 3.12 ------ FB about importstream, exportstream, maxredbits et*/
  39. /* 3.13 ------ FB about->movie */
  40. /* 3.14 ------ FB GFUNCTIONS table declared */
  41. /* 3.15 ------ FB about->mipmap */
  42. /* 3.16 ------ FB about->font */
  43. /* 3.17 ------ FB linux use intel ordered ARGB */
  44. /* 3.20 ------ FB 64 bit file system (GPOS), removed ARGB16 */
  45. /* 3.21 ------ FB 64 bit backwards compatibility with 32 */
  46. /* 3.22 ------ FB 32 bit file implementation for efficiency */
  47. /* 3.23 ------ FB bitfield warning removed */
  48. /* 3.24 010426 FB GIMEX_read/write take void * prototyped here */
  49. /* 3.25 010427 FB about width/height max,align and obsolete */
  50. /* 3.26 010501 FB INT64 for gcc 2.95.3 on ps2 use long */
  51. /* 3.27 010504 FB removed _ARGB_T - use ARGB. add GC reference */
  52. /* 3.30 010614 LC update for 330 release */
  53. /* 3.31 010628 FB GIMEX_COMMENT_SIZE 1024 */
  54. /* 3.32 011009 FB about->file64 for 64 bit file sizes */
  55. /* 3.40 011022 FB bool returns, ggetm inline, 512 GIMEX_FRAME... */
  56. /* 3.41 020225 FB metalbin 240 on ps2 */
  57. /* 3.44 020307 FB bumped for next release. no api change */
  58. /* 3.45 020927 FB geti 3 bounds safe/purify */
  59. /* 3.46 021205 FB about firstextension */
  60. /* */
  61. /*------------------------------------------------------------------*/
  62. #ifndef __GIMEX_H
  63. #define __GIMEX_H 1
  64. #if defined(_MSC_VER)
  65. #pragma once
  66. #pragma warning(disable : 4100)
  67. /* warning C4100: unreferenced parameter */
  68. #endif
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. #define GIMEX_VERSION 346
  73. #define GIMEX_PATCH 0
  74. /****************************************************************************/
  75. /* Data Types */
  76. /****************************************************************************/
  77. /* ARGB structure used for palettes/pixels */
  78. // experimental float channel
  79. #ifdef GIMEXFLOAT
  80. typedef float GCHANNEL;
  81. #else
  82. typedef unsigned char GCHANNEL;
  83. #endif
  84. #ifndef ARGB
  85. #define ARGB ARGB
  86. #if defined(_MSC_VER) || defined(__i386__)
  87. typedef struct
  88. {
  89. GCHANNEL b,g,r,a;
  90. } ARGB;
  91. #elif defined(__R5900) || defined(SGI) /* PS2 */
  92. typedef struct
  93. {
  94. GCHANNEL r,g,b,a;
  95. } ARGB;
  96. #else /* GameCube/Mac */
  97. typedef struct
  98. {
  99. GCHANNEL a,r,g,b;
  100. } ARGB;
  101. #endif
  102. #endif
  103. #if !defined(GPOS)
  104. #if defined(_MSC_VER)
  105. typedef __int64 GPOS;
  106. #elif defined(__R5900)
  107. typedef long GPOS;
  108. #else
  109. typedef long long GPOS;
  110. #endif
  111. #endif
  112. /* Info structure describing bitmaps */
  113. #define GIMEX_FRAMENAME_SIZE 512
  114. #define GIMEX_COMMENT_SIZE 1024
  115. #define GIMEX_COLOURTBL_SIZE 256
  116. #define GIMEX_HOTSPOTTBL_SIZE 1024
  117. #define GIMEX_HOTSPOTTBL_VALUES 2
  118. typedef struct
  119. {
  120. int signature; /* signature of gimex ie 'tga ' (optional) */
  121. int size; /* size of GINFO structure */
  122. int version; /* version number of GINFO structure (300) */
  123. int framenum; /* current frame */
  124. int width; /* width of bitmap in pixels */
  125. int height; /* height of bitmap in pixels */
  126. int bpp; /* bits per pixel (8, 16 or 32) */
  127. int originalbpp; /* bits per pixel in original image (1 to 32) */
  128. int startcolour; /* first colour in palette */
  129. int numcolours; /* number of colours in original indexed palette */
  130. ARGB colourtbl[GIMEX_COLOURTBL_SIZE]; /* 8 bit palette */
  131. int subtype; /* internal format sub-type 0-default */
  132. int packed; /* type of packing on original image. 0 none, 1 run, n other */
  133. int quality; /* quality of lossy packing 0..100 */
  134. int framesize; /* size of frame in bytes */
  135. int alphabits; /* number of bits in alpha channel */
  136. int redbits; /* number of bits in red channel */
  137. int greenbits; /* number of bits in green channel */
  138. int bluebits; /* number of bits in blue channel */
  139. int centerx; /* center point relative to upper left corner */
  140. int centery;
  141. int defaultx; /* default coordinate point */
  142. int defaulty;
  143. int numhotspots; /* number of hot spots defined */
  144. char framename[GIMEX_FRAMENAME_SIZE]; /* null terminated name of frame/image */
  145. char comment[GIMEX_COMMENT_SIZE]; /* null terminated multiline user comment */
  146. int hotspottbl[GIMEX_HOTSPOTTBL_SIZE][GIMEX_HOTSPOTTBL_VALUES];/* up to 256 hot spots, XY pairs relative to upperleft */
  147. float dpi; /* dots per inch ie 72.0 */
  148. float fps; /* frame per second (one over duration). 15.0 is typical */
  149. int reserved[3]; /* reserved for future use - set to zero */
  150. } GINFO;
  151. typedef struct GSTREAM GSTREAM; /* handle used for file functions */
  152. typedef struct
  153. {
  154. int signature; /* signature of gimex ie '.tga' (optional) */
  155. int size; /* size of GINSTANCE structure */
  156. int frames; /* Number of frames in file */
  157. int framenum; /* current frame (optional) */
  158. GSTREAM *gstream; /* stream pointer for file */
  159. void *gref; /* gimex reference to additional memory used by module (optional) */
  160. } GINSTANCE;
  161. /* Info structure describing bitmaps */
  162. #define MAXMACTYPES 8
  163. #define MAXEXTENSIONS 8
  164. #define GIMEX_EXTENSION_SIZE 8
  165. #define GIMEX_AUTHORSTR_SIZE 32
  166. #define GIMEX_VERSIONSTR_SIZE 8
  167. #define GIMEX_SHORTTYPESTR_SIZE 8
  168. #define GIMEX_WORDTYPESTR_SIZE 16
  169. #define GIMEX_LONGTYPESTR_SIZE 32
  170. typedef struct
  171. {
  172. int signature; /* signature of gimex ie 'tga ' (optional) */
  173. int size; /* size of GABOUT structure */
  174. int version; /* version number of GABOUT structure (200) */
  175. unsigned int canimport :1; /* supports importing */
  176. unsigned int canexport :1; /* supports exporting */
  177. unsigned int importpacked :2; /* max import packed field 0..3 */
  178. unsigned int exportpacked :2; /* max export packed field 0..3 */
  179. unsigned int import8 :1; /* supports importing 8 bit indexed */
  180. unsigned int export8 :1; /* supports exporting 8 bit indexed */
  181. unsigned int import32 :1; /* supports importing 32 bit direct rgb */
  182. unsigned int export32 :1; /* supports exporting 32 bit direct rgb */
  183. unsigned int multiframe :1; /* supports multiple frames */
  184. unsigned int multifile :1; /* format requires additional files or resource fork */
  185. unsigned int multisize :1; /* supports different size per frame */
  186. unsigned int framebuffer :1; /* module requires memory to buffer entire frame */
  187. unsigned int external :1; /* uses external resources */
  188. unsigned int usesfile :1; /* module is file based vs ads/printer/generator */
  189. unsigned int globalpalette :1; /* limited to a single palette per file */
  190. unsigned int greyscale :1; /* use maxcolours for number of levels */
  191. unsigned int startcolour :1; /* supports start colour */
  192. unsigned int dotsubtype :1; /* subtype based on extension */
  193. unsigned int resizable :1; /* read will respect ginfo width & height */
  194. unsigned int reserved2 :1; /* reserved for future use */
  195. unsigned int reserved3 :1; /* reserved for future use */
  196. unsigned int importstream :1; /* supports open with GIMEX_NOFRAMECOUNT */
  197. unsigned int exportstream :1; /* will ignore frame count on export */
  198. unsigned int movie :1; /* this is a movie format (as opposed to mipmaps, fonts or multipage) */
  199. unsigned int mipmap :1; /* mipmaps are supported and will constrain sizes */
  200. unsigned int font :1; /* this is a font format */
  201. unsigned int obsolete :1; /* this format is obsolete */
  202. unsigned int file64 :1; /* this format supports 64 bit file sizes */
  203. unsigned int firstextension:1; /* use first extension when assigning default name */
  204. unsigned int pad :1; /* pad bitfield to 32 bit boundary for inter compiler compatibility */
  205. int maxcolours; /* only use in 8 bit, 0 if module does not care */
  206. int maxframename; /* maximum characters in ginfo framename */
  207. int defaultquality; /* default pack quality */
  208. int mactype[MAXMACTYPES]; /* mac file system types used */
  209. char extensions[MAXEXTENSIONS][GIMEX_EXTENSION_SIZE]; /* null terminated extensions with '.' */
  210. char authorstr[GIMEX_AUTHORSTR_SIZE]; /* name of gimex module author */
  211. char versionstr[GIMEX_VERSIONSTR_SIZE]; /* version number of gimex module ie 1.00 */
  212. char shorttypestr[GIMEX_SHORTTYPESTR_SIZE]; /* 3 or 4 character type string ie TGA */
  213. char wordtypestr[GIMEX_WORDTYPESTR_SIZE]; /* single word type string ie Targa */
  214. char longtypestr[GIMEX_LONGTYPESTR_SIZE]; /* full name of data format ie True Vision Targa */
  215. unsigned int maxalphabits:8; /* maximum supported number of bits in alpha channel */
  216. unsigned int maxredbits :8; /* maximum supported number of bits in red channel */
  217. unsigned int maxgreenbits:8; /* maximum supported number of bits in green channel */
  218. unsigned int maxbluebits :8; /* maximum supported number of bits in blue channel */
  219. unsigned int maxwidth; /* maximum width in pixels */
  220. unsigned int maxheight; /* maximum height in pixels */
  221. unsigned int alignwidth; /* width must be multiple of this in pixels */
  222. unsigned int alignheight; /* height must be multiple of this in pixels */
  223. unsigned int pad2[4];
  224. } GABOUT;
  225. /* Bitmap structure (optional) */
  226. typedef struct
  227. {
  228. GINFO *ginfo;
  229. void *image;
  230. int rowbytes;
  231. } GBITMAP;
  232. #ifndef GMAKEID
  233. #define GMAKEID(a,b,c,d) (((int)(a)<<24)|((int)(b)<<16)|((int)(c)<<8)|(int)(d))
  234. #endif
  235. #ifndef gmin
  236. #define gmin(a,b) ((a)<(b)?(a):(b))
  237. #endif
  238. #ifndef gmax
  239. #define gmax(a,b) ((a)>(b)?(a):(b))
  240. #endif
  241. #if !defined(GCALL)
  242. #if defined(_MSC_VER) && !defined(_XBOX)
  243. #define GCALL __stdcall
  244. #else
  245. #define GCALL
  246. #endif
  247. #endif
  248. #if !defined(__cplusplus) && !defined(bool)
  249. #define bool bool
  250. typedef enum{ False=0x0, True=0x1}bool;
  251. #endif
  252. typedef struct GFUNCTIONS
  253. {
  254. GABOUT * (GCALL * GIMEX_about)(void);
  255. int (GCALL * GIMEX_is)(GSTREAM *g);
  256. int (GCALL * GIMEX_open)(GINSTANCE **gx, GSTREAM *g, const char *pathname,bool framecountflag);
  257. GINFO * (GCALL * GIMEX_info)(GINSTANCE *gx, int framenum);
  258. int (GCALL * GIMEX_read)(GINSTANCE *gx, GINFO *ginfo, char *dest, int rowbytes);
  259. int (GCALL * GIMEX_close)(GINSTANCE *gx);
  260. int (GCALL * GIMEX_wopen)(GINSTANCE **gx, GSTREAM *g, const char *pathname, int numframes);
  261. int (GCALL * GIMEX_write)(GINSTANCE *gx, const GINFO *ginfo, char *source, int rowbytes);
  262. int (GCALL * GIMEX_wclose)(GINSTANCE *gx);
  263. } GFUNCTIONS;
  264. extern struct GFUNCTIONS gfunctions[];
  265. /****************************************************************************/
  266. /* Gimex Module Example Prototypes */
  267. /****************************************************************************/
  268. /* valid values to be passed to framecountflag parameter for the GIMEX_open function */
  269. #ifdef __cplusplus
  270. #define GIMEX_FRAMECOUNT true
  271. #define GIMEX_NOFRAMECOUNT false
  272. #else
  273. #define GIMEX_FRAMECOUNT 0x1
  274. #define GIMEX_NOFRAMECOUNT 0x0
  275. #endif
  276. /* Information Functions */
  277. GABOUT *GCALL GIMEX_about(void);
  278. int GCALL GIMEX_is(GSTREAM *g);
  279. /* Import Functions */
  280. #ifdef __cplusplus
  281. int GCALL GIMEX_open(GINSTANCE **gx, GSTREAM *g, const char *pathname, bool framecountflag=GIMEX_FRAMECOUNT);
  282. #else
  283. int GCALL GIMEX_open(GINSTANCE **gx, GSTREAM *g, const char *pathname, bool framecountflag);
  284. #endif
  285. GINFO * GCALL GIMEX_info(GINSTANCE *gx, int framenum);
  286. bool GCALL GIMEX_read(GINSTANCE *gx, const GINFO *ginfo, void *dest, int rowbytes);
  287. bool GCALL GIMEX_close(GINSTANCE *gx);
  288. /* Example Export Functions */
  289. bool GCALL GIMEX_wopen(GINSTANCE **gx, GSTREAM *g, const char *pathname, int numframes);
  290. bool GCALL GIMEX_write(GINSTANCE *gx, const GINFO *ginfo, const void *source, int rowbytes);
  291. bool GCALL GIMEX_wclose(GINSTANCE *gx);
  292. /****************************************************************************/
  293. /* Application Module Prototypes */
  294. /****************************************************************************/
  295. /* File Stream Functions */
  296. GSTREAM * GCALL gopen(const char *pathname);
  297. GSTREAM * GCALL gwopen(const char *pathname);
  298. bool GCALL gclose(GSTREAM *g);
  299. int GCALL gread(GSTREAM *g, void *buf, int size);
  300. int GCALL gwrite(GSTREAM *g, const void *buf, int size);
  301. bool GCALL gseek(GSTREAM *g, GPOS offset);
  302. GPOS GCALL glen(GSTREAM *g);
  303. GPOS GCALL gtell(GSTREAM *g);
  304. /* Memory Functions */
  305. #if !defined(galloc)
  306. #include <stdlib.h>
  307. #define galloc malloc
  308. //void * GCALL galloc(int size);
  309. #endif
  310. //bool GCALL gfree(void *memptr);
  311. #define gfree free
  312. #ifdef __cplusplus
  313. }
  314. #endif
  315. /****************************************************************************/
  316. /* Inline C++ (cross platform) */
  317. /****************************************************************************/
  318. #ifdef _MSC_VER
  319. #pragma warning(disable: 4514) // unreferenced inline function has been removed
  320. #endif
  321. /* get motorola memory */
  322. static __inline unsigned int ggetm(const void *src, int bytes)
  323. {
  324. if (bytes==1)
  325. return (unsigned int) *(const unsigned char *) src;
  326. #if defined(__APPLE__) || (defined(__MWERKS__) && defined(__PPCGEKKO__))
  327. else if (bytes==2)
  328. return (unsigned int) *(const unsigned short *) src;
  329. else if (bytes==4)
  330. return (unsigned int) *(const unsigned int *) src;
  331. #else
  332. else if (bytes==2)
  333. return (((unsigned int) *(const unsigned char *) src)<<8) | (((unsigned int) *((const unsigned char *) src+1)));
  334. else if (bytes==4)
  335. return (((unsigned int) *(const unsigned char *) src)<<24) | (((unsigned int) *((const unsigned char *) src+1))<<16) | (((unsigned int) *((const unsigned char *) src+2))<<8) | (((unsigned int) *((const unsigned char *) src+3)));
  336. #endif
  337. else if (bytes==3)
  338. return (((unsigned int) *(const unsigned char *) src)<<16) | (((unsigned int) *((const unsigned char *) src+1))<<8) | (((unsigned int) *((const unsigned char *) src+2)));
  339. return 0;
  340. }
  341. /* get intel memory */
  342. static __inline unsigned int ggeti(const void *src, int bytes)
  343. {
  344. if (bytes==1)
  345. return (unsigned int) *(const unsigned char *) src;
  346. #if defined(_MSC_VER) || defined(__i386__)
  347. else if (bytes==2)
  348. return (unsigned int) *(const unsigned short *) src;
  349. else if (bytes==4)
  350. return (unsigned int) *(const unsigned int *) src;
  351. #else
  352. else if (bytes==2)
  353. return (((unsigned int) *((const unsigned char *) src+1))<<8) | (((unsigned int) *(const unsigned char *) src+0));
  354. else if (bytes==4)
  355. return (((unsigned int) *((const unsigned char *) src+3))<<24) | (((unsigned int) *((const unsigned char *) src+2))<<16) | (((unsigned int) *((const unsigned char *) src+1))<<8) | (((unsigned int) *(const unsigned char *) src+0));
  356. #endif
  357. else if (bytes==3)
  358. return (((unsigned int) *((const unsigned char *) src+2))<<16) | (((unsigned int) *((const unsigned char *) src+1))<<8) | (((unsigned int) *(const unsigned char *) src+0));
  359. return 0;
  360. }
  361. /* put motorolla memory */
  362. static __inline void gputm(void *dst, unsigned int data, int bytes)
  363. {
  364. if (bytes==1)
  365. {
  366. ((unsigned char *) dst)[0] = (unsigned char) data;
  367. }
  368. #if defined(__APPLE__) || (defined(__MWERKS__) && defined(__PPCGEKKO__))
  369. else if (bytes==2)
  370. {
  371. ((unsigned short *) dst)[0] = (unsigned short) data;
  372. }
  373. else if (bytes==4)
  374. {
  375. ((unsigned int *) dst)[0] = (unsigned int) data;
  376. }
  377. #else
  378. else if (bytes==2)
  379. {
  380. ((unsigned char *) dst)[0] = (unsigned char) (data>>8);
  381. ((unsigned char *) dst)[1] = (unsigned char) data;
  382. }
  383. else if (bytes==4)
  384. {
  385. ((unsigned char *) dst)[0] = (unsigned char) (data>>24);
  386. ((unsigned char *) dst)[1] = (unsigned char) (data>>16);
  387. ((unsigned char *) dst)[2] = (unsigned char) (data>>8);
  388. ((unsigned char *) dst)[3] = (unsigned char) data;
  389. }
  390. #endif
  391. else if (bytes==3)
  392. {
  393. ((unsigned char *) dst)[0] = (unsigned char) (data>>16);
  394. ((unsigned char *) dst)[1] = (unsigned char) (data>>8);
  395. ((unsigned char *) dst)[2] = (unsigned char) data;
  396. }
  397. }
  398. /* put intel memory */
  399. static __inline void gputi(void *dst, unsigned int data, int bytes)
  400. {
  401. if (bytes==1)
  402. {
  403. ((unsigned char *) dst)[0] = (unsigned char) data;
  404. }
  405. #if defined(_MSC_VER) || defined(__i386__)
  406. else if (bytes==2)
  407. {
  408. ((unsigned short *) dst)[0] = (unsigned short) data;
  409. }
  410. else if (bytes==4)
  411. {
  412. ((unsigned int *) dst)[0] = (unsigned int) data;
  413. }
  414. #else
  415. else if (bytes==2)
  416. {
  417. ((unsigned char *) dst)[0] = (unsigned char) data;
  418. ((unsigned char *) dst)[1] = (unsigned char) (data>>8);
  419. }
  420. else if (bytes==4)
  421. {
  422. ((unsigned char *) dst)[0] = (unsigned char) data;
  423. ((unsigned char *) dst)[1] = (unsigned char) (data>>8);
  424. ((unsigned char *) dst)[2] = (unsigned char) (data>>16);
  425. ((unsigned char *) dst)[3] = (unsigned char) (data>>24);
  426. }
  427. #endif
  428. else if (bytes==3)
  429. {
  430. ((unsigned char *) dst)[0] = (unsigned char) data;
  431. ((unsigned char *) dst)[1] = (unsigned char) (data>>8);
  432. ((unsigned char *) dst)[2] = (unsigned char) (data>>16);
  433. }
  434. }
  435. #endif /* __GIMEX_H */
  436. /* END ABSTRACT */