palette.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,99 by the Free Pascal development team
  5. This include implements the different palette manipulation
  6. routines.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. CONST
  14. { This is the standard VGA palette for the first 256 colors }
  15. { at 6 bpp for each RG and B component. }
  16. DefaultColors: Array[0..255] of RGBRec = (
  17. (Red: 0;Green: 0;Blue: 0),
  18. (Red: 0;Green: 0;Blue: 168),
  19. (Red: 0;Green: 168;Blue: 0),
  20. (Red: 0;Green: 168;Blue: 168),
  21. (Red: 168;Green: 0;Blue: 0),
  22. (Red: 168;Green: 0;Blue: 168),
  23. (Red: 168;Green: 84;Blue: 0),
  24. (Red: 168;Green: 168;Blue: 168),
  25. (Red: 84;Green: 84;Blue: 84),
  26. (Red: 84;Green: 84;Blue: 252),
  27. (Red: 84;Green: 252;Blue: 84),
  28. (Red: 84;Green: 252;Blue: 252),
  29. (Red: 252;Green: 84;Blue: 84),
  30. (Red: 252;Green: 84;Blue: 252),
  31. (Red: 252;Green: 252;Blue: 84),
  32. (Red: 252;Green: 252;Blue: 252),
  33. (Red: 0;Green: 0;Blue: 0),
  34. (Red: 20;Green: 20;Blue: 20),
  35. (Red: 32;Green: 32;Blue: 32),
  36. (Red: 44;Green: 44;Blue: 44),
  37. (Red: 56;Green: 56;Blue: 56),
  38. (Red: 68;Green: 68;Blue: 68),
  39. (Red: 80;Green: 80;Blue: 80),
  40. (Red: 96;Green: 96;Blue: 96),
  41. (Red: 112;Green: 112;Blue: 112),
  42. (Red: 128;Green: 128;Blue: 128),
  43. (Red: 144;Green: 144;Blue: 144),
  44. (Red: 160;Green: 160;Blue: 160),
  45. (Red: 180;Green: 180;Blue: 180),
  46. (Red: 200;Green: 200;Blue: 200),
  47. (Red: 224;Green: 224;Blue: 224),
  48. (Red: 252;Green: 252;Blue: 252),
  49. (Red: 0;Green: 0;Blue: 252),
  50. (Red: 64;Green: 0;Blue: 252),
  51. (Red: 124;Green: 0;Blue: 252),
  52. (Red: 188;Green: 0;Blue: 252),
  53. (Red: 252;Green: 0;Blue: 252),
  54. (Red: 252;Green: 0;Blue: 188),
  55. (Red: 252;Green: 0;Blue: 124),
  56. (Red: 252;Green: 0;Blue: 64),
  57. (Red: 252;Green: 0;Blue: 0),
  58. (Red: 252;Green: 64;Blue: 0),
  59. (Red: 252;Green: 124;Blue: 0),
  60. (Red: 252;Green: 188;Blue: 0),
  61. (Red: 252;Green: 252;Blue: 0),
  62. (Red: 188;Green: 252;Blue: 0),
  63. (Red: 124;Green: 252;Blue: 0),
  64. (Red: 64;Green: 252;Blue: 0),
  65. (Red: 0;Green: 252;Blue: 0),
  66. (Red: 0;Green: 252;Blue: 64),
  67. (Red: 0;Green: 252;Blue: 124),
  68. (Red: 0;Green: 252;Blue: 188),
  69. (Red: 0;Green: 252;Blue: 252),
  70. (Red: 0;Green: 188;Blue: 252),
  71. (Red: 0;Green: 124;Blue: 252),
  72. (Red: 0;Green: 64;Blue: 252),
  73. (Red: 124;Green: 124;Blue: 252),
  74. (Red: 156;Green: 124;Blue: 252),
  75. (Red: 188;Green: 124;Blue: 252),
  76. (Red: 220;Green: 124;Blue: 252),
  77. (Red: 252;Green: 124;Blue: 252),
  78. (Red: 252;Green: 124;Blue: 220),
  79. (Red: 252;Green: 124;Blue: 188),
  80. (Red: 252;Green: 124;Blue: 156),
  81. (Red: 252;Green: 124;Blue: 124),
  82. (Red: 252;Green: 156;Blue: 124),
  83. (Red: 252;Green: 188;Blue: 124),
  84. (Red: 252;Green: 220;Blue: 124),
  85. (Red: 252;Green: 252;Blue: 124),
  86. (Red: 220;Green: 252;Blue: 124),
  87. (Red: 188;Green: 252;Blue: 124),
  88. (Red: 156;Green: 252;Blue: 124),
  89. (Red: 124;Green: 252;Blue: 124),
  90. (Red: 124;Green: 252;Blue: 156),
  91. (Red: 124;Green: 252;Blue: 188),
  92. (Red: 124;Green: 252;Blue: 220),
  93. (Red: 124;Green: 252;Blue: 252),
  94. (Red: 124;Green: 220;Blue: 252),
  95. (Red: 124;Green: 188;Blue: 252),
  96. (Red: 124;Green: 156;Blue: 252),
  97. (Red: 180;Green: 180;Blue: 252),
  98. (Red: 196;Green: 180;Blue: 252),
  99. (Red: 216;Green: 180;Blue: 252),
  100. (Red: 232;Green: 180;Blue: 252),
  101. (Red: 252;Green: 180;Blue: 252),
  102. (Red: 252;Green: 180;Blue: 232),
  103. (Red: 252;Green: 180;Blue: 216),
  104. (Red: 252;Green: 180;Blue: 196),
  105. (Red: 252;Green: 180;Blue: 180),
  106. (Red: 252;Green: 196;Blue: 180),
  107. (Red: 252;Green: 216;Blue: 180),
  108. (Red: 252;Green: 232;Blue: 180),
  109. (Red: 252;Green: 252;Blue: 180),
  110. (Red: 232;Green: 252;Blue: 180),
  111. (Red: 216;Green: 252;Blue: 180),
  112. (Red: 196;Green: 252;Blue: 180),
  113. (Red: 180;Green: 252;Blue: 180),
  114. (Red: 180;Green: 252;Blue: 196),
  115. (Red: 180;Green: 252;Blue: 216),
  116. (Red: 180;Green: 252;Blue: 232),
  117. (Red: 180;Green: 252;Blue: 252),
  118. (Red: 180;Green: 232;Blue: 252),
  119. (Red: 180;Green: 216;Blue: 252),
  120. (Red: 180;Green: 196;Blue: 252),
  121. (Red: 0;Green: 0;Blue: 112),
  122. (Red: 28;Green: 0;Blue: 112),
  123. (Red: 56;Green: 0;Blue: 112),
  124. (Red: 84;Green: 0;Blue: 112),
  125. (Red: 112;Green: 0;Blue: 112),
  126. (Red: 112;Green: 0;Blue: 84),
  127. (Red: 112;Green: 0;Blue: 56),
  128. (Red: 112;Green: 0;Blue: 28),
  129. (Red: 112;Green: 0;Blue: 0),
  130. (Red: 112;Green: 28;Blue: 0),
  131. (Red: 112;Green: 56;Blue: 0),
  132. (Red: 112;Green: 84;Blue: 0),
  133. (Red: 112;Green: 112;Blue: 0),
  134. (Red: 84;Green: 112;Blue: 0),
  135. (Red: 56;Green: 112;Blue: 0),
  136. (Red: 28;Green: 112;Blue: 0),
  137. (Red: 0;Green: 112;Blue: 0),
  138. (Red: 0;Green: 112;Blue: 28),
  139. (Red: 0;Green: 112;Blue: 56),
  140. (Red: 0;Green: 112;Blue: 84),
  141. (Red: 0;Green: 112;Blue: 112),
  142. (Red: 0;Green: 84;Blue: 112),
  143. (Red: 0;Green: 56;Blue: 112),
  144. (Red: 0;Green: 28;Blue: 112),
  145. (Red: 56;Green: 56;Blue: 112),
  146. (Red: 68;Green: 56;Blue: 112),
  147. (Red: 84;Green: 56;Blue: 112),
  148. (Red: 96;Green: 56;Blue: 112),
  149. (Red: 112;Green: 56;Blue: 112),
  150. (Red: 112;Green: 56;Blue: 96),
  151. (Red: 112;Green: 56;Blue: 84),
  152. (Red: 112;Green: 56;Blue: 68),
  153. (Red: 112;Green: 56;Blue: 56),
  154. (Red: 112;Green: 68;Blue: 56),
  155. (Red: 112;Green: 84;Blue: 56),
  156. (Red: 112;Green: 96;Blue: 56),
  157. (Red: 112;Green: 112;Blue: 56),
  158. (Red: 96;Green: 112;Blue: 56),
  159. (Red: 84;Green: 112;Blue: 56),
  160. (Red: 68;Green: 112;Blue: 56),
  161. (Red: 56;Green: 112;Blue: 56),
  162. (Red: 56;Green: 112;Blue: 68),
  163. (Red: 56;Green: 112;Blue: 84),
  164. (Red: 56;Green: 112;Blue: 96),
  165. (Red: 56;Green: 112;Blue: 112),
  166. (Red: 56;Green: 96;Blue: 112),
  167. (Red: 56;Green: 84;Blue: 112),
  168. (Red: 56;Green: 68;Blue: 112),
  169. (Red: 80;Green: 80;Blue: 112),
  170. (Red: 88;Green: 80;Blue: 112),
  171. (Red: 96;Green: 80;Blue: 112),
  172. (Red: 104;Green: 80;Blue: 112),
  173. (Red: 112;Green: 80;Blue: 112),
  174. (Red: 112;Green: 80;Blue: 104),
  175. (Red: 112;Green: 80;Blue: 96),
  176. (Red: 112;Green: 80;Blue: 88),
  177. (Red: 112;Green: 80;Blue: 80),
  178. (Red: 112;Green: 88;Blue: 80),
  179. (Red: 112;Green: 96;Blue: 80),
  180. (Red: 112;Green: 104;Blue: 80),
  181. (Red: 112;Green: 112;Blue: 80),
  182. (Red: 104;Green: 112;Blue: 80),
  183. (Red: 96;Green: 112;Blue: 80),
  184. (Red: 88;Green: 112;Blue: 80),
  185. (Red: 80;Green: 112;Blue: 80),
  186. (Red: 80;Green: 112;Blue: 88),
  187. (Red: 80;Green: 112;Blue: 96),
  188. (Red: 80;Green: 112;Blue: 104),
  189. (Red: 80;Green: 112;Blue: 112),
  190. (Red: 80;Green: 104;Blue: 112),
  191. (Red: 80;Green: 96;Blue: 112),
  192. (Red: 80;Green: 88;Blue: 112),
  193. (Red: 0;Green: 0;Blue: 64),
  194. (Red: 16;Green: 0;Blue: 64),
  195. (Red: 32;Green: 0;Blue: 64),
  196. (Red: 48;Green: 0;Blue: 64),
  197. (Red: 64;Green: 0;Blue: 64),
  198. (Red: 64;Green: 0;Blue: 48),
  199. (Red: 64;Green: 0;Blue: 32),
  200. (Red: 64;Green: 0;Blue: 16),
  201. (Red: 64;Green: 0;Blue: 0),
  202. (Red: 64;Green: 16;Blue: 0),
  203. (Red: 64;Green: 32;Blue: 0),
  204. (Red: 64;Green: 48;Blue: 0),
  205. (Red: 64;Green: 64;Blue: 0),
  206. (Red: 48;Green: 64;Blue: 0),
  207. (Red: 32;Green: 64;Blue: 0),
  208. (Red: 16;Green: 64;Blue: 0),
  209. (Red: 0;Green: 64;Blue: 0),
  210. (Red: 0;Green: 64;Blue: 16),
  211. (Red: 0;Green: 64;Blue: 32),
  212. (Red: 0;Green: 64;Blue: 48),
  213. (Red: 0;Green: 64;Blue: 64),
  214. (Red: 0;Green: 48;Blue: 64),
  215. (Red: 0;Green: 32;Blue: 64),
  216. (Red: 0;Green: 16;Blue: 64),
  217. (Red: 32;Green: 32;Blue: 64),
  218. (Red: 40;Green: 32;Blue: 64),
  219. (Red: 48;Green: 32;Blue: 64),
  220. (Red: 56;Green: 32;Blue: 64),
  221. (Red: 64;Green: 32;Blue: 64),
  222. (Red: 64;Green: 32;Blue: 56),
  223. (Red: 64;Green: 32;Blue: 48),
  224. (Red: 64;Green: 32;Blue: 40),
  225. (Red: 64;Green: 32;Blue: 32),
  226. (Red: 64;Green: 40;Blue: 32),
  227. (Red: 64;Green: 48;Blue: 32),
  228. (Red: 64;Green: 56;Blue: 32),
  229. (Red: 64;Green: 64;Blue: 32),
  230. (Red: 56;Green: 64;Blue: 32),
  231. (Red: 48;Green: 64;Blue: 32),
  232. (Red: 40;Green: 64;Blue: 32),
  233. (Red: 32;Green: 64;Blue: 32),
  234. (Red: 32;Green: 64;Blue: 40),
  235. (Red: 32;Green: 64;Blue: 48),
  236. (Red: 32;Green: 64;Blue: 56),
  237. (Red: 32;Green: 64;Blue: 64),
  238. (Red: 32;Green: 56;Blue: 64),
  239. (Red: 32;Green: 48;Blue: 64),
  240. (Red: 32;Green: 40;Blue: 64),
  241. (Red: 44;Green: 44;Blue: 64),
  242. (Red: 48;Green: 44;Blue: 64),
  243. (Red: 52;Green: 44;Blue: 64),
  244. (Red: 60;Green: 44;Blue: 64),
  245. (Red: 64;Green: 44;Blue: 64),
  246. (Red: 64;Green: 44;Blue: 60),
  247. (Red: 64;Green: 44;Blue: 52),
  248. (Red: 64;Green: 44;Blue: 48),
  249. (Red: 64;Green: 44;Blue: 44),
  250. (Red: 64;Green: 48;Blue: 44),
  251. (Red: 64;Green: 52;Blue: 44),
  252. (Red: 64;Green: 60;Blue: 44),
  253. (Red: 64;Green: 64;Blue: 44),
  254. (Red: 60;Green: 64;Blue: 44),
  255. (Red: 52;Green: 64;Blue: 44),
  256. (Red: 48;Green: 64;Blue: 44),
  257. (Red: 44;Green: 64;Blue: 44),
  258. (Red: 44;Green: 64;Blue: 48),
  259. (Red: 44;Green: 64;Blue: 52),
  260. (Red: 44;Green: 64;Blue: 60),
  261. (Red: 44;Green: 64;Blue: 64),
  262. (Red: 44;Green: 60;Blue: 64),
  263. (Red: 44;Green: 52;Blue: 64),
  264. (Red: 44;Green: 48;Blue: 64),
  265. (Red: 0;Green: 0;Blue: 0),
  266. (Red: 0;Green: 0;Blue: 0),
  267. (Red: 0;Green: 0;Blue: 0),
  268. (Red: 0;Green: 0;Blue: 0),
  269. (Red: 0;Green: 0;Blue: 0),
  270. (Red: 0;Green: 0;Blue: 0),
  271. (Red: 0;Green: 0;Blue: 0),
  272. (Red: 0;Green: 0;Blue: 0));
  273. procedure SetAllPalette(var Palette:PaletteType);
  274. var
  275. i: longint;
  276. Size: longint;
  277. begin
  278. { palette routines do not work in DirectColor mode }
  279. if DirectColor then
  280. begin
  281. _GraphResult := grError;
  282. exit;
  283. end;
  284. Size:=Palette.Size; { number of entries...}
  285. { first determine if we are not trying to }
  286. { change too much colors... }
  287. if Palette.Size > PaletteSize then
  288. begin
  289. _GraphResult := grError;
  290. exit;
  291. end;
  292. Dec(Size); { Color arrays are indexed according to zero }
  293. for i:=0 to Size do
  294. begin
  295. { skip if RGB values are -1 , as stated in the TP manual }
  296. if (Palette.Colors[i].Red <> -1) and (Palette.Colors[i].Green <> -1)
  297. and (Palette.Colors[i].Blue <> -1) then
  298. SetRGBPalette(i,
  299. Palette.Colors[i].Red,
  300. Palette.Colors[i].Green,
  301. Palette.Colors[i].Blue);
  302. end;
  303. end;
  304. {********************************************************}
  305. { Procedure SetPalette() }
  306. {--------------------------------------------------------}
  307. { This routine changes the colorNum to the default }
  308. { palette entry specified in the second parameter. }
  309. { For example, SetPalette(0, Lightcyan) makes the }
  310. { 0th palette entry to the default Light Cyan Color . }
  311. {********************************************************}
  312. Procedure SetPalette(ColorNum: word; Color: shortint);
  313. begin
  314. { palette routines do not work in DirectColor mode }
  315. if DirectColor then
  316. begin
  317. _GraphResult := grError;
  318. exit;
  319. end;
  320. { Check if we can actually change that palette color }
  321. if ColorNum > PaletteSize then
  322. Begin
  323. _GraphResult := grError;
  324. exit;
  325. end
  326. else
  327. { Check if the max. default color is reached...}
  328. if Color > EGAWhite then
  329. begin
  330. _GraphResult := grError;
  331. exit;
  332. end;
  333. SetRGBPalette(ColorNum,
  334. DefaultColors[Color].Red,
  335. DefaultColors[Color].Green,
  336. DefaultColors[Color].Blue);
  337. end;
  338. procedure GetPalette(var Palette: PaletteType);
  339. var
  340. i: longint;
  341. size : longint;
  342. begin
  343. { palette routines do not work in DirectColor mode }
  344. if DirectColor then
  345. begin
  346. _GraphResult := grError;
  347. exit;
  348. end;
  349. Palette.Size := PaletteSize;
  350. { index at zero }
  351. size := PaletteSize - 1;
  352. for i:=0 to size do
  353. GetRGBPalette(i,
  354. Palette.Colors[i].Red,
  355. Palette.Colors[i].Green,
  356. Palette.Colors[i].Blue);
  357. end;
  358. function GetPaletteSize: integer;
  359. begin
  360. GetPaletteSize := PaletteSize;
  361. end;
  362. procedure GetDefaultPalette(var Palette: PaletteType);
  363. begin
  364. move(DefaultColors, Palette.Colors, sizeof(DefaultColors));
  365. { The default palette always has 256 entries, but in reality }
  366. { it depends on the number of colors possible. }
  367. Palette.Size := PaletteSize;
  368. if PaletteSize > 256 then Palette.Size := 256;
  369. end;
  370. {
  371. $Log$
  372. Revision 1.4 1999-07-12 13:27:15 jonas
  373. + added Log and Id tags
  374. * added first FPC support, only VGA works to some extend for now
  375. * use -dasmgraph to use assembler routines, otherwise Pascal
  376. equivalents are used
  377. * use -dsupportVESA to support VESA (crashes under FPC for now)
  378. * only dispose vesainfo at closegrph if a vesa card was detected
  379. * changed int32 to longint (int32 is not declared under FPC)
  380. * changed the declaration of almost every procedure in graph.inc to
  381. "far;" becquse otherwise you can't assign them to procvars under TP
  382. real mode (but unexplainable "data segnment too large" errors prevent
  383. it from working under real mode anyway)
  384. }