Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

423 lines
12 KiB

  1. /*
  2. ** Copyright 1991,1992 Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. **
  17. ** $Revision: 1.7 $
  18. ** $Date: 1993/06/18 00:29:39 $
  19. */
  20. #include "precomp.h"
  21. #pragma hdrstop
  22. GLubyte __glMsbToLsbTable[256] = {
  23. 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  24. 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  25. 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  26. 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  27. 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  28. 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  29. 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  30. 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  31. 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  32. 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  33. 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  34. 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  35. 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  36. 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  37. 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  38. 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  39. 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  40. 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  41. 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  42. 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  43. 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  44. 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  45. 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  46. 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  47. 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  48. 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  49. 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  50. 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  51. 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  52. 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  53. 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  54. 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
  55. };
  56. static GLubyte LowBitsMask[9] = {
  57. 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff,
  58. };
  59. static GLubyte HighBitsMask[9] = {
  60. 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff,
  61. };
  62. /************************************************************************/
  63. void FASTCALL __glConvertStipple(__GLcontext *gc)
  64. {
  65. GLubyte b0, b1, b2, b3, *stipple;
  66. GLuint *dst;
  67. GLint i;
  68. stipple = &gc->state.polygonStipple.stipple[0];
  69. dst = &gc->polygon.stipple[0];
  70. #ifdef __GL_STIPPLE_MSB
  71. /*
  72. ** Convert input stipple bytes which are in little endian MSB format
  73. ** into a single long word, whose high bit represents the left most
  74. ** X coordinate of a 32 bit span.
  75. */
  76. for (i = 0; i < 32; i++) {
  77. b0 = *stipple++;
  78. b1 = *stipple++;
  79. b2 = *stipple++;
  80. b3 = *stipple++;
  81. *dst++ = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
  82. }
  83. #else
  84. /*
  85. ** Make 32bit form of the stipple for easier rendering.
  86. */
  87. for (i = 0; i < 32; i++) {
  88. b0 = __glMsbToLsbTable[*stipple++];
  89. b1 = __glMsbToLsbTable[*stipple++];
  90. b2 = __glMsbToLsbTable[*stipple++];
  91. b3 = __glMsbToLsbTable[*stipple++];
  92. *dst++ = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
  93. }
  94. #endif
  95. }
  96. /************************************************************************/
  97. /*
  98. ** Compute memory required for internal packed array of data of given type
  99. ** and format.
  100. */
  101. GLint APIPRIVATE __glImageSize(GLsizei width, GLsizei height, GLenum format, GLenum type)
  102. {
  103. GLint bytes_per_row;
  104. GLint components;
  105. components = __glElementsPerGroup(format);
  106. if (type == GL_BITMAP) {
  107. bytes_per_row = (width + 7) >> 3;
  108. } else {
  109. bytes_per_row =(GLint)__glBytesPerElement(type) * width;
  110. }
  111. return bytes_per_row * height * components;
  112. }
  113. /*
  114. ** Extract array from user's data applying all pixel store modes.
  115. ** The internal packed array format used has LSB_FIRST = FALSE and
  116. ** ALIGNMENT = 1.
  117. */
  118. void APIPRIVATE __glFillImage(__GLcontext *gc, GLsizei width, GLsizei height,
  119. GLenum format, GLenum type,
  120. const GLvoid *userdata, GLubyte *newimage)
  121. {
  122. GLint components;
  123. GLint element_size;
  124. GLint rowsize;
  125. GLint padding;
  126. GLint line_length = gc->state.pixel.unpackModes.lineLength;
  127. GLint alignment = gc->state.pixel.unpackModes.alignment;
  128. GLint skip_pixels = gc->state.pixel.unpackModes.skipPixels;
  129. GLint skip_lines = gc->state.pixel.unpackModes.skipLines;
  130. GLint groups_per_line;
  131. GLint group_size;
  132. GLint lsb_first = gc->state.pixel.unpackModes.lsbFirst;
  133. GLint swap_bytes = gc->state.pixel.unpackModes.swapEndian;
  134. GLint elements_per_line;
  135. const GLubyte *start;
  136. const GLubyte *iter;
  137. GLubyte *iter2;
  138. GLint i, j, k;
  139. components = __glElementsPerGroup(format);
  140. if (line_length > 0) {
  141. groups_per_line = line_length;
  142. } else {
  143. groups_per_line = width;
  144. }
  145. /* All formats except GL_BITMAP fall out trivially */
  146. if (type == GL_BITMAP) {
  147. GLint elements_left;
  148. GLint bit_offset;
  149. GLint current_byte;
  150. GLint next_byte;
  151. GLint high_bit_mask;
  152. GLint low_bit_mask;
  153. rowsize = (groups_per_line * components + 7) / 8;
  154. padding = (rowsize % alignment);
  155. if (padding) {
  156. rowsize += alignment - padding;
  157. }
  158. start = ((const GLubyte*) userdata) + skip_lines * rowsize +
  159. (skip_pixels * components / 8);
  160. bit_offset = (skip_pixels * components) % 8;
  161. high_bit_mask = LowBitsMask[8-bit_offset];
  162. low_bit_mask = HighBitsMask[bit_offset];
  163. elements_per_line = width * components;
  164. iter2 = newimage;
  165. for (i = 0; i < height; i++) {
  166. elements_left = elements_per_line;
  167. iter = start;
  168. while (elements_left) {
  169. /* First retrieve low bits from current byte */
  170. if (lsb_first) {
  171. current_byte = __glMsbToLsbTable[iter[0]];
  172. } else {
  173. current_byte = iter[0];
  174. }
  175. if (bit_offset) {
  176. /* Need to read next byte to finish current byte */
  177. if (elements_left > (8 - bit_offset)) {
  178. if (lsb_first) {
  179. next_byte = __glMsbToLsbTable[iter[1]];
  180. } else {
  181. next_byte = iter[1];
  182. }
  183. current_byte =
  184. ((current_byte & high_bit_mask) << bit_offset) |
  185. ((next_byte & low_bit_mask) >> (8 - bit_offset));
  186. } else {
  187. current_byte =
  188. ((current_byte & high_bit_mask) << bit_offset);
  189. }
  190. }
  191. if (elements_left >= 8) {
  192. *iter2 = (GLubyte) current_byte;
  193. elements_left -= 8;
  194. } else {
  195. *iter2 = (GLubyte)
  196. (current_byte & HighBitsMask[elements_left]);
  197. elements_left = 0;
  198. }
  199. iter2++;
  200. iter++;
  201. }
  202. start += rowsize;
  203. }
  204. } else {
  205. element_size = (GLint)__glBytesPerElement(type);
  206. group_size = element_size * components;
  207. if (element_size == 1) swap_bytes = 0;
  208. rowsize = groups_per_line * group_size;
  209. padding = (rowsize % alignment);
  210. if (padding) {
  211. rowsize += alignment - padding;
  212. }
  213. start = ((const GLubyte*) userdata) + skip_lines * rowsize
  214. + skip_pixels * group_size;
  215. iter2 = newimage;
  216. elements_per_line = width * components;
  217. if (swap_bytes) {
  218. for (i = 0; i < height; i++) {
  219. iter = start;
  220. for (j = 0; j < elements_per_line; j++) {
  221. for (k = 1; k <= element_size; k++) {
  222. iter2[k-1] = iter[element_size - k];
  223. }
  224. iter2 += element_size;
  225. iter += element_size;
  226. }
  227. start += rowsize;
  228. }
  229. } else {
  230. if (rowsize == elements_per_line * element_size) {
  231. /* Ha! This is mondo easy! */
  232. __GL_MEMCOPY(iter2, start,
  233. elements_per_line * element_size * height);
  234. } else {
  235. iter = start;
  236. for (i = 0; i < height; i++) {
  237. __GL_MEMCOPY(iter2, iter, elements_per_line * element_size);
  238. iter2 += elements_per_line * element_size;
  239. iter += rowsize;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. /*
  246. ** Insert array into user's data applying all pixel store modes.
  247. ** The internal packed array format used has LSB_FIRST = FALSE and
  248. ** ALIGNMENT = 1. __glEmptyImage() because it is the opposite of
  249. ** __glFillImage().
  250. */
  251. void __glEmptyImage(__GLcontext *gc, GLsizei width, GLsizei height,
  252. GLenum format, GLenum type,
  253. const GLubyte *oldimage, GLvoid *userdata)
  254. {
  255. GLint components;
  256. GLint element_size;
  257. GLint rowsize;
  258. GLint padding;
  259. GLint line_length = gc->state.pixel.packModes.lineLength;
  260. GLint alignment = gc->state.pixel.packModes.alignment;
  261. GLint skip_pixels = gc->state.pixel.packModes.skipPixels;
  262. GLint skip_lines = gc->state.pixel.packModes.skipLines;
  263. GLint groups_per_line;
  264. GLint group_size;
  265. GLint lsb_first = gc->state.pixel.packModes.lsbFirst;
  266. GLint swap_bytes = gc->state.pixel.packModes.swapEndian;
  267. GLint elements_per_line;
  268. GLubyte *start;
  269. GLubyte *iter;
  270. const GLubyte *iter2;
  271. GLint i, j, k;
  272. components = __glElementsPerGroup(format);
  273. if (line_length > 0) {
  274. groups_per_line = line_length;
  275. } else {
  276. groups_per_line = width;
  277. }
  278. /* All formats except GL_BITMAP fall out trivially */
  279. if (type == GL_BITMAP) {
  280. GLint elements_left;
  281. GLint bit_offset;
  282. GLint current_byte;
  283. GLint high_bit_mask;
  284. GLint low_bit_mask;
  285. GLint write_mask;
  286. GLubyte write_byte;
  287. rowsize = (groups_per_line * components + 7) / 8;
  288. padding = (rowsize % alignment);
  289. if (padding) {
  290. rowsize += alignment - padding;
  291. }
  292. start = ((GLubyte*) userdata) + skip_lines * rowsize +
  293. (skip_pixels * components / 8);
  294. bit_offset = (skip_pixels * components) % 8;
  295. high_bit_mask = LowBitsMask[8-bit_offset];
  296. low_bit_mask = HighBitsMask[bit_offset];
  297. elements_per_line = width * components;
  298. iter2 = oldimage;
  299. for (i = 0; i < height; i++) {
  300. elements_left = elements_per_line;
  301. iter = start;
  302. write_mask = high_bit_mask;
  303. write_byte = 0;
  304. while (elements_left) {
  305. /* Set up write_mask (to write to current byte) */
  306. if (elements_left + bit_offset < 8) {
  307. /* Need to trim write_mask */
  308. write_mask &= HighBitsMask[bit_offset+elements_left];
  309. }
  310. if (lsb_first) {
  311. current_byte = __glMsbToLsbTable[iter[0]];
  312. } else {
  313. current_byte = iter[0];
  314. }
  315. if (bit_offset) {
  316. write_byte |= (GLubyte) (iter2[0] >> bit_offset);
  317. current_byte = (current_byte & ~write_mask) |
  318. (write_byte & write_mask);
  319. write_byte = (GLubyte) (iter2[0] << (8 - bit_offset));
  320. } else {
  321. current_byte = (current_byte & ~write_mask) |
  322. (iter2[0] & write_mask);
  323. }
  324. if (lsb_first) {
  325. iter[0] = __glMsbToLsbTable[current_byte];
  326. } else {
  327. iter[0] = (GLubyte) current_byte;
  328. }
  329. if (elements_left >= 8) {
  330. elements_left -= 8;
  331. } else {
  332. elements_left = 0;
  333. }
  334. iter2++;
  335. iter++;
  336. write_mask = 0xff;
  337. }
  338. if (write_byte) {
  339. /* Some data left over that still needs writing */
  340. write_mask &= low_bit_mask;
  341. if (lsb_first) {
  342. current_byte = __glMsbToLsbTable[iter[0]];
  343. } else {
  344. current_byte = iter[0];
  345. }
  346. current_byte = (current_byte & ~write_mask) |
  347. (write_byte & write_mask);
  348. if (lsb_first) {
  349. iter[0] = __glMsbToLsbTable[current_byte];
  350. } else {
  351. iter[0] = (GLubyte) current_byte;
  352. }
  353. }
  354. start += rowsize;
  355. }
  356. } else {
  357. element_size = (GLint)__glBytesPerElement(type);
  358. group_size = element_size * components;
  359. if (element_size == 1) swap_bytes = 0;
  360. rowsize = groups_per_line * group_size;
  361. padding = (rowsize % alignment);
  362. if (padding) {
  363. rowsize += alignment - padding;
  364. }
  365. start = ((GLubyte*) userdata) + skip_lines * rowsize
  366. + skip_pixels * group_size;
  367. iter2 = oldimage;
  368. elements_per_line = width * components;
  369. if (swap_bytes) {
  370. for (i = 0; i < height; i++) {
  371. iter = start;
  372. for (j = 0; j < elements_per_line; j++) {
  373. for (k = 1; k <= element_size; k++) {
  374. iter[k-1] = iter2[element_size - k];
  375. }
  376. iter2 += element_size;
  377. iter += element_size;
  378. }
  379. start += rowsize;
  380. }
  381. } else {
  382. if (rowsize == elements_per_line * element_size) {
  383. /* Ha! This is mondo easy! */
  384. __GL_MEMCOPY(start, iter2,
  385. elements_per_line * element_size * height);
  386. } else {
  387. iter = start;
  388. for (i = 0; i < height; i++) {
  389. __GL_MEMCOPY(iter, iter2, elements_per_line * element_size);
  390. iter2 += elements_per_line * element_size;
  391. iter += rowsize;
  392. }
  393. }
  394. }
  395. }
  396. }