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.

755 lines
19 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. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "imports.h"
  20. /*
  21. ** This file contains span packers. A span packer takes a span of source
  22. ** data, and packs its contents into the user's data space.
  23. **
  24. ** The packer is expected to aquire information about store modes from
  25. ** the __GLpixelSpanInfo structure.
  26. */
  27. void FASTCALL __glInitPacker(__GLcontext *gc, __GLpixelSpanInfo *spanInfo)
  28. {
  29. GLint alignment;
  30. GLint lsb_first;
  31. GLint components;
  32. GLint element_size;
  33. GLint rowsize;
  34. GLint padding;
  35. GLint group_size;
  36. GLint groups_per_line;
  37. GLint skip_pixels, skip_lines;
  38. GLint swap_bytes;
  39. GLenum format, type;
  40. const GLvoid *pixels;
  41. format = spanInfo->dstFormat;
  42. type = spanInfo->dstType;
  43. pixels = spanInfo->dstImage;
  44. skip_pixels = spanInfo->dstSkipPixels;
  45. skip_lines = spanInfo->dstSkipLines;
  46. alignment = spanInfo->dstAlignment;
  47. lsb_first = spanInfo->dstLsbFirst;
  48. swap_bytes = spanInfo->dstSwapBytes;
  49. components = __glElementsPerGroup(format);
  50. groups_per_line = spanInfo->dstLineLength;
  51. element_size = __glBytesPerElement(type);
  52. if (element_size == 1) swap_bytes = 0;
  53. group_size = element_size * components;
  54. rowsize = groups_per_line * group_size;
  55. if (type == GL_BITMAP) {
  56. rowsize = (groups_per_line + 7)/8;
  57. }
  58. padding = (rowsize % alignment);
  59. if (padding) {
  60. rowsize += alignment - padding;
  61. }
  62. if (((skip_pixels & 0x7) && type == GL_BITMAP) ||
  63. (swap_bytes && element_size > 1)) {
  64. spanInfo->dstPackedData = GL_FALSE;
  65. } else {
  66. spanInfo->dstPackedData = GL_TRUE;
  67. }
  68. if (type == GL_BITMAP) {
  69. spanInfo->dstCurrent = (GLvoid *) (((const GLubyte*) pixels) +
  70. skip_lines * rowsize + skip_pixels / 8);
  71. spanInfo->dstStartBit = skip_pixels % 8;
  72. } else {
  73. spanInfo->dstCurrent = (GLvoid *) (((const GLubyte*) pixels) +
  74. skip_lines * rowsize + skip_pixels * group_size);
  75. }
  76. spanInfo->dstRowIncrement = rowsize;
  77. spanInfo->dstGroupIncrement = group_size;
  78. spanInfo->dstComponents = components;
  79. spanInfo->dstElementSize = element_size;
  80. }
  81. /*
  82. ** Reduces and unscales a RGBA, FLOAT span into a RED, FLOAT span, unscaling
  83. ** as it goes.
  84. */
  85. void __glSpanReduceRed(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  86. GLvoid *inspan, GLvoid *outspan)
  87. {
  88. GLint i;
  89. GLint width = spanInfo->realWidth;
  90. GLfloat *outData = (GLfloat *) outspan;
  91. GLfloat *inData = (GLfloat *) inspan;
  92. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  93. for (i=0; i<width; i++) {
  94. *outData++ = *inData * rs;
  95. inData += 4;
  96. }
  97. }
  98. /*
  99. ** Reduces and unscales a RGBA, FLOAT span into a GREEN, FLOAT span, unscaling
  100. ** as it goes.
  101. */
  102. void __glSpanReduceGreen(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  103. GLvoid *inspan, GLvoid *outspan)
  104. {
  105. GLint i;
  106. GLint width = spanInfo->realWidth;
  107. GLfloat *outData = (GLfloat *) outspan;
  108. GLfloat *inData = (GLfloat *) inspan;
  109. GLfloat gs = gc->frontBuffer.oneOverGreenScale;
  110. inData++; /* Skip first red */
  111. for (i=0; i<width; i++) {
  112. *outData++ = *inData * gs;
  113. inData += 4;
  114. }
  115. }
  116. /*
  117. ** Reduces and unscales a RGBA, FLOAT span into a BLUE, FLOAT span, unscaling
  118. ** as it goes.
  119. */
  120. void __glSpanReduceBlue(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  121. GLvoid *inspan, GLvoid *outspan)
  122. {
  123. GLint i;
  124. GLint width = spanInfo->realWidth;
  125. GLfloat *outData = (GLfloat *) outspan;
  126. GLfloat *inData = (GLfloat *) inspan;
  127. GLfloat bs = gc->frontBuffer.oneOverBlueScale;
  128. inData += 2; /* Skip first red, green */
  129. for (i=0; i<width; i++) {
  130. *outData++ = *inData * bs;
  131. inData += 4;
  132. }
  133. }
  134. /*
  135. ** Reduces and unscales a RGBA, FLOAT span into a ALPHA, FLOAT span, unscaling
  136. ** as it goes.
  137. */
  138. void __glSpanReduceAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  139. GLvoid *inspan, GLvoid *outspan)
  140. {
  141. GLint i;
  142. GLint width = spanInfo->realWidth;
  143. GLfloat *outData = (GLfloat *) outspan;
  144. GLfloat *inData = (GLfloat *) inspan;
  145. GLfloat as = gc->frontBuffer.oneOverAlphaScale;
  146. inData += 3; /* Skip first red, green, blue */
  147. for (i=0; i<width; i++) {
  148. *outData++ = *inData * as;
  149. inData += 4;
  150. }
  151. }
  152. /*
  153. ** Reduces and unscales a RGBA, FLOAT span into a RGB, FLOAT span, unscaling
  154. ** as it goes.
  155. */
  156. void __glSpanReduceRGB(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  157. GLvoid *inspan, GLvoid *outspan)
  158. {
  159. GLint i;
  160. GLint width = spanInfo->realWidth;
  161. GLfloat *outData = (GLfloat *) outspan;
  162. GLfloat *inData = (GLfloat *) inspan;
  163. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  164. GLfloat bs = gc->frontBuffer.oneOverBlueScale;
  165. GLfloat gs = gc->frontBuffer.oneOverGreenScale;
  166. GLfloat red, green, blue;
  167. for (i=0; i<width; i++) {
  168. red = *inData++ * rs;
  169. green = *inData++ * gs;
  170. blue = *inData++ * bs;
  171. *outData++ = red;
  172. *outData++ = green;
  173. *outData++ = blue;
  174. inData++;
  175. }
  176. }
  177. #ifdef GL_EXT_bgra
  178. /*
  179. ** Reduces and unscales a RGBA, FLOAT span into a BGR, FLOAT span, unscaling
  180. ** as it goes.
  181. */
  182. void __glSpanReduceBGR(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  183. GLvoid *inspan, GLvoid *outspan)
  184. {
  185. GLint i;
  186. GLint width = spanInfo->realWidth;
  187. GLfloat *outData = (GLfloat *) outspan;
  188. GLfloat *inData = (GLfloat *) inspan;
  189. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  190. GLfloat bs = gc->frontBuffer.oneOverBlueScale;
  191. GLfloat gs = gc->frontBuffer.oneOverGreenScale;
  192. GLfloat red, green, blue;
  193. for (i=0; i<width; i++) {
  194. red = *inData++ * rs;
  195. green = *inData++ * gs;
  196. blue = *inData++ * bs;
  197. *outData++ = blue;
  198. *outData++ = green;
  199. *outData++ = red;
  200. inData++;
  201. }
  202. }
  203. #endif
  204. /*
  205. ** Reduces and unscales a RGBA, FLOAT span into a LUMINANCE, FLOAT span,
  206. ** unscaling as it goes.
  207. */
  208. void __glSpanReduceLuminance(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  209. GLvoid *inspan, GLvoid *outspan)
  210. {
  211. GLint i;
  212. GLint width = spanInfo->realWidth;
  213. GLfloat *outData = (GLfloat *) outspan;
  214. GLfloat *inData = (GLfloat *) inspan;
  215. GLfloat l, one;
  216. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  217. GLfloat bs = gc->frontBuffer.oneOverBlueScale;
  218. GLfloat gs = gc->frontBuffer.oneOverGreenScale;
  219. one = __glOne;
  220. for (i=0; i<width; i++) {
  221. l = inData[0] * rs + inData[1] * gs + inData[2] * bs;
  222. if (l > one) l = one;
  223. *outData++ = l;
  224. inData += 4;
  225. }
  226. }
  227. /*
  228. ** Reduces and unscales a RGBA, FLOAT span into a LUMINANCE_ALPHA, FLOAT span,
  229. ** unscaling as it goes.
  230. */
  231. void __glSpanReduceLuminanceAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  232. GLvoid *inspan, GLvoid *outspan)
  233. {
  234. GLint i;
  235. GLint width = spanInfo->realWidth;
  236. GLfloat *outData = (GLfloat *) outspan;
  237. GLfloat *inData = (GLfloat *) inspan;
  238. GLfloat l, one;
  239. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  240. GLfloat bs = gc->frontBuffer.oneOverBlueScale;
  241. GLfloat gs = gc->frontBuffer.oneOverGreenScale;
  242. GLfloat as = gc->frontBuffer.oneOverAlphaScale;
  243. one = __glOne;
  244. for (i=0; i<width; i++) {
  245. l = inData[0] * rs + inData[1] * gs + inData[2] * bs;
  246. if (l > one) l = one;
  247. *outData++ = l;
  248. inData += 3;
  249. *outData++ = *inData++ * as;
  250. }
  251. }
  252. /*
  253. ** Reduces and unscales a RGBA, FLOAT span into a __GL_RED_ALPHA, FLOAT span,
  254. ** unscaling as it goes.
  255. */
  256. void __glSpanReduceRedAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  257. GLvoid *inspan, GLvoid *outspan)
  258. {
  259. GLint i;
  260. GLint width = spanInfo->realWidth;
  261. GLfloat *outData = (GLfloat *) outspan;
  262. GLfloat *inData = (GLfloat *) inspan;
  263. GLfloat r, one;
  264. GLfloat rs = gc->frontBuffer.oneOverRedScale;
  265. GLfloat as = gc->frontBuffer.oneOverAlphaScale;
  266. one = __glOne;
  267. for (i=0; i<width; i++) {
  268. *outData++ = *inData++ * rs;
  269. inData += 2;
  270. *outData++ = *inData++ * as;
  271. }
  272. }
  273. /*
  274. ** Packs to any component of type UNSIGNED_BYTE from a span of the same
  275. ** format of type FLOAT.
  276. */
  277. void __glSpanPackUbyte(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  278. GLvoid *inspan, GLvoid *outspan)
  279. {
  280. GLint i;
  281. GLint width = spanInfo->realWidth;
  282. GLfloat *inData = (GLfloat *) inspan;
  283. GLubyte *outData = (GLubyte *) outspan;
  284. GLint components = spanInfo->dstComponents;
  285. GLint totalSize = width * components;
  286. FPU_SAVE_MODE();
  287. FPU_CHOP_ON_PREC_LOW();
  288. #ifdef __GL_LINT
  289. gc = gc;
  290. #endif
  291. for (i=0; i<totalSize; i++) {
  292. *outData++ = (GLubyte) UNSAFE_FTOL((*inData++) * __glVal255 + __glHalf);
  293. }
  294. FPU_RESTORE_MODE();
  295. }
  296. /*
  297. ** Packs to any component of type BYTE from a span of the same
  298. ** format of type FLOAT.
  299. */
  300. void __glSpanPackByte(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  301. GLvoid *inspan, GLvoid *outspan)
  302. {
  303. GLint i;
  304. GLint width = spanInfo->realWidth;
  305. GLfloat *inData = (GLfloat *) inspan;
  306. GLbyte *outData = (GLbyte *) outspan;
  307. GLint components = spanInfo->dstComponents;
  308. GLint totalSize = width * components;
  309. #ifdef __GL_LINT
  310. gc = gc;
  311. #endif
  312. for (i=0; i<totalSize; i++) {
  313. *outData++ = __GL_FLOAT_TO_B(*inData++);
  314. }
  315. }
  316. /*
  317. ** Packs to any component of type UNSIGNED_SHORT from a span of the same
  318. ** format of type FLOAT.
  319. */
  320. void __glSpanPackUshort(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  321. GLvoid *inspan, GLvoid *outspan)
  322. {
  323. GLint i;
  324. GLint width = spanInfo->realWidth;
  325. GLfloat *inData = (GLfloat *) inspan;
  326. GLushort *outData = (GLushort *) outspan;
  327. GLint components = spanInfo->dstComponents;
  328. GLint totalSize = width * components;
  329. FPU_SAVE_MODE();
  330. FPU_CHOP_ON_PREC_LOW();
  331. #ifdef __GL_LINT
  332. gc = gc;
  333. #endif
  334. for (i=0; i<totalSize; i++) {
  335. *outData++ = (GLushort) UNSAFE_FTOL((*inData++) * __glVal65535 + __glHalf);
  336. }
  337. FPU_RESTORE_MODE();
  338. }
  339. /*
  340. ** Packs to any component of type SHORT from a span of the same
  341. ** format of type FLOAT.
  342. */
  343. void __glSpanPackShort(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  344. GLvoid *inspan, GLvoid *outspan)
  345. {
  346. GLint i;
  347. GLint width = spanInfo->realWidth;
  348. GLfloat *inData = (GLfloat *) inspan;
  349. GLshort *outData = (GLshort *) outspan;
  350. GLint components = spanInfo->dstComponents;
  351. GLint totalSize = width * components;
  352. #ifdef __GL_LINT
  353. gc = gc;
  354. #endif
  355. for (i=0; i<totalSize; i++) {
  356. *outData++ = __GL_FLOAT_TO_S(*inData++);
  357. }
  358. }
  359. /*
  360. ** Packs to any component of type UNSIGNED_INT from a span of the same
  361. ** format of type FLOAT.
  362. */
  363. void __glSpanPackUint(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  364. GLvoid *inspan, GLvoid *outspan)
  365. {
  366. GLint i;
  367. GLint width = spanInfo->realWidth;
  368. GLfloat *inData = (GLfloat *) inspan;
  369. GLuint *outData = (GLuint *) outspan;
  370. GLint components = spanInfo->dstComponents;
  371. GLint totalSize = width * components;
  372. #ifdef __GL_LINT
  373. gc = gc;
  374. #endif
  375. for (i=0; i<totalSize; i++) {
  376. *outData++ = __GL_FLOAT_TO_UI(*inData++);
  377. }
  378. }
  379. /*
  380. ** Packs to any component of type INT from a span of the same
  381. ** format of type FLOAT.
  382. */
  383. void __glSpanPackInt(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  384. GLvoid *inspan, GLvoid *outspan)
  385. {
  386. GLint i;
  387. GLint width = spanInfo->realWidth;
  388. GLfloat *inData = (GLfloat *) inspan;
  389. GLint *outData = (GLint *) outspan;
  390. GLint components = spanInfo->dstComponents;
  391. GLint totalSize = width * components;
  392. #ifdef __GL_LINT
  393. gc = gc;
  394. #endif
  395. for (i=0; i<totalSize; i++) {
  396. *outData++ = __GL_FLOAT_TO_I(*inData++);
  397. }
  398. }
  399. /*
  400. ** Packs to any index of type UNSIGNED_BYTE from a span of the same
  401. ** format of type FLOAT.
  402. */
  403. void __glSpanPackUbyteI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  404. GLvoid *inspan, GLvoid *outspan)
  405. {
  406. GLint i;
  407. GLint totalSize = spanInfo->realWidth;
  408. GLfloat *inData = (GLfloat *) inspan;
  409. GLubyte *outData = (GLubyte *) outspan;
  410. FPU_SAVE_MODE();
  411. FPU_CHOP_ON_PREC_LOW();
  412. #ifdef __GL_LINT
  413. gc = gc;
  414. #endif
  415. for (i=0; i<totalSize; i++) {
  416. *outData++ = (GLubyte) UNSAFE_FTOL(*inData++);
  417. }
  418. FPU_RESTORE_MODE();
  419. }
  420. /*
  421. ** Packs to any index of type BYTE from a span of the same
  422. ** format of type FLOAT.
  423. */
  424. void __glSpanPackByteI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  425. GLvoid *inspan, GLvoid *outspan)
  426. {
  427. GLint i;
  428. GLint totalSize = spanInfo->realWidth;
  429. GLfloat *inData = (GLfloat *) inspan;
  430. GLbyte *outData = (GLbyte *) outspan;
  431. FPU_SAVE_MODE();
  432. FPU_CHOP_ON_PREC_LOW();
  433. #ifdef __GL_LINT
  434. gc = gc;
  435. #endif
  436. for (i=0; i<totalSize; i++) {
  437. *outData++ = UNSAFE_FTOL(*inData++) & 0x7f;
  438. }
  439. FPU_RESTORE_MODE();
  440. }
  441. /*
  442. ** Packs to any index of type UNSIGNED_SHORT from a span of the same
  443. ** format of type FLOAT.
  444. */
  445. void __glSpanPackUshortI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  446. GLvoid *inspan, GLvoid *outspan)
  447. {
  448. GLint i;
  449. GLint totalSize = spanInfo->realWidth;
  450. GLfloat *inData = (GLfloat *) inspan;
  451. GLushort *outData = (GLushort *) outspan;
  452. FPU_SAVE_MODE();
  453. FPU_CHOP_ON_PREC_LOW();
  454. #ifdef __GL_LINT
  455. gc = gc;
  456. #endif
  457. for (i=0; i<totalSize; i++) {
  458. *outData++ = (GLushort) UNSAFE_FTOL(*inData++);
  459. }
  460. FPU_RESTORE_MODE();
  461. }
  462. /*
  463. ** Packs to any index of type SHORT from a span of the same
  464. ** format of type FLOAT.
  465. */
  466. void __glSpanPackShortI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  467. GLvoid *inspan, GLvoid *outspan)
  468. {
  469. GLint i;
  470. GLint totalSize = spanInfo->realWidth;
  471. GLfloat *inData = (GLfloat *) inspan;
  472. GLshort *outData = (GLshort *) outspan;
  473. FPU_SAVE_MODE();
  474. FPU_CHOP_ON_PREC_LOW();
  475. #ifdef __GL_LINT
  476. gc = gc;
  477. #endif
  478. for (i=0; i<totalSize; i++) {
  479. *outData++ = UNSAFE_FTOL(*inData++) & 0x7fff;
  480. }
  481. FPU_RESTORE_MODE();
  482. }
  483. /*
  484. ** Packs to any index of type UNSIGNED_INT from a span of the same
  485. ** format of type FLOAT.
  486. */
  487. void __glSpanPackUintI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  488. GLvoid *inspan, GLvoid *outspan)
  489. {
  490. GLint i;
  491. GLint totalSize = spanInfo->realWidth;
  492. GLfloat *inData = (GLfloat *) inspan;
  493. GLuint *outData = (GLuint *) outspan;
  494. FPU_SAVE_MODE();
  495. FPU_CHOP_ON_PREC_LOW();
  496. #ifdef __GL_LINT
  497. gc = gc;
  498. #endif
  499. for (i=0; i<totalSize; i++) {
  500. *outData++ = FTOL(*inData++);
  501. }
  502. FPU_RESTORE_MODE();
  503. }
  504. /*
  505. ** Packs to any index of type INT from a span of the same
  506. ** format of type FLOAT.
  507. */
  508. void __glSpanPackIntI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  509. GLvoid *inspan, GLvoid *outspan)
  510. {
  511. GLint i;
  512. GLint totalSize = spanInfo->realWidth;
  513. GLfloat *inData = (GLfloat *) inspan;
  514. GLint *outData = (GLint *) outspan;
  515. FPU_SAVE_MODE();
  516. FPU_CHOP_ON_PREC_LOW();
  517. #ifdef __GL_LINT
  518. gc = gc;
  519. #endif
  520. for (i=0; i<totalSize; i++) {
  521. *outData++ = FTOL(*inData++) & 0x7fffffff;
  522. }
  523. FPU_RESTORE_MODE();
  524. }
  525. void __glSpanCopy(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  526. GLvoid *inspan, GLvoid *outspan)
  527. {
  528. GLint totalSize = spanInfo->realWidth * spanInfo->srcComponents *
  529. spanInfo->srcElementSize;
  530. __GL_MEMCOPY(outspan, inspan, totalSize);
  531. }
  532. /*
  533. ** Packs to any index of type BITMAP from a span of the same
  534. ** format of type FLOAT.
  535. */
  536. void __glSpanPackBitmap(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  537. GLvoid *inspan, GLvoid *outspan)
  538. {
  539. GLint i,j;
  540. GLint width;
  541. GLvoid *userData;
  542. GLfloat *spanData;
  543. GLint lsbFirst;
  544. GLint startBit;
  545. GLint bit;
  546. GLubyte ubyte, mask;
  547. #ifdef __GL_LINT
  548. gc = gc;
  549. #endif
  550. width = spanInfo->width;
  551. userData = outspan;
  552. spanData = (GLfloat *) inspan;
  553. lsbFirst = spanInfo->dstLsbFirst;
  554. startBit = spanInfo->dstStartBit;
  555. i = width;
  556. bit = startBit;
  557. ubyte = *(GLubyte *) userData;
  558. if (lsbFirst) {
  559. if (bit) {
  560. switch(bit) {
  561. case 1:
  562. if (((GLint) *spanData++) & 1) ubyte |= 0x02;
  563. else ubyte &= ~0x02;
  564. if (--i == 0) break;
  565. case 2:
  566. if (((GLint) *spanData++) & 1) ubyte |= 0x04;
  567. else ubyte &= ~0x04;
  568. if (--i == 0) break;
  569. case 3:
  570. if (((GLint) *spanData++) & 1) ubyte |= 0x08;
  571. else ubyte &= ~0x08;
  572. if (--i == 0) break;
  573. case 4:
  574. if (((GLint) *spanData++) & 1) ubyte |= 0x10;
  575. else ubyte &= ~0x10;
  576. if (--i == 0) break;
  577. case 5:
  578. if (((GLint) *spanData++) & 1) ubyte |= 0x20;
  579. else ubyte &= ~0x20;
  580. if (--i == 0) break;
  581. case 6:
  582. if (((GLint) *spanData++) & 1) ubyte |= 0x40;
  583. else ubyte &= ~0x40;
  584. if (--i == 0) break;
  585. case 7:
  586. if (((GLint) *spanData++) & 1) ubyte |= 0x80;
  587. else ubyte &= ~0x80;
  588. i--;
  589. }
  590. *(GLubyte *) userData = ubyte;
  591. userData = (GLvoid *) ((GLubyte *) userData + 1);
  592. }
  593. while (i >= 8) {
  594. ubyte = 0;
  595. i -= 8;
  596. if (((GLint) *spanData++) & 1) ubyte |= 0x01;
  597. if (((GLint) *spanData++) & 1) ubyte |= 0x02;
  598. if (((GLint) *spanData++) & 1) ubyte |= 0x04;
  599. if (((GLint) *spanData++) & 1) ubyte |= 0x08;
  600. if (((GLint) *spanData++) & 1) ubyte |= 0x10;
  601. if (((GLint) *spanData++) & 1) ubyte |= 0x20;
  602. if (((GLint) *spanData++) & 1) ubyte |= 0x40;
  603. if (((GLint) *spanData++) & 1) ubyte |= 0x80;
  604. *(GLubyte *) userData = ubyte;
  605. userData = (GLvoid *) ((GLubyte *) userData + 1);
  606. }
  607. if (i) {
  608. ubyte = *(GLubyte *) userData;
  609. mask = 0x01;
  610. while (i-- > 0) {
  611. if (((GLint) *spanData++) & 1) ubyte |= mask;
  612. else ubyte &= ~mask;
  613. mask <<= 1;
  614. }
  615. *(GLubyte *) userData = ubyte;
  616. }
  617. } else {
  618. if (bit) {
  619. switch(bit) {
  620. case 1:
  621. if (((GLint) *spanData++) & 1) ubyte |= 0x40;
  622. else ubyte &= ~0x40;
  623. if (--i == 0) break;
  624. case 2:
  625. if (((GLint) *spanData++) & 1) ubyte |= 0x20;
  626. else ubyte &= ~0x20;
  627. if (--i == 0) break;
  628. case 3:
  629. if (((GLint) *spanData++) & 1) ubyte |= 0x10;
  630. else ubyte &= ~0x10;
  631. if (--i == 0) break;
  632. case 4:
  633. if (((GLint) *spanData++) & 1) ubyte |= 0x08;
  634. else ubyte &= ~0x08;
  635. if (--i == 0) break;
  636. case 5:
  637. if (((GLint) *spanData++) & 1) ubyte |= 0x04;
  638. else ubyte &= ~0x04;
  639. if (--i == 0) break;
  640. case 6:
  641. if (((GLint) *spanData++) & 1) ubyte |= 0x02;
  642. else ubyte &= ~0x02;
  643. if (--i == 0) break;
  644. case 7:
  645. if (((GLint) *spanData++) & 1) ubyte |= 0x01;
  646. else ubyte &= ~0x01;
  647. i--;
  648. }
  649. *(GLubyte *) userData = ubyte;
  650. userData = (GLvoid *) ((GLubyte *) userData + 1);
  651. }
  652. while (i >= 8) {
  653. ubyte = 0;
  654. i -= 8;
  655. if (((GLint) *spanData++) & 1) ubyte |= 0x80;
  656. if (((GLint) *spanData++) & 1) ubyte |= 0x40;
  657. if (((GLint) *spanData++) & 1) ubyte |= 0x20;
  658. if (((GLint) *spanData++) & 1) ubyte |= 0x10;
  659. if (((GLint) *spanData++) & 1) ubyte |= 0x08;
  660. if (((GLint) *spanData++) & 1) ubyte |= 0x04;
  661. if (((GLint) *spanData++) & 1) ubyte |= 0x02;
  662. if (((GLint) *spanData++) & 1) ubyte |= 0x01;
  663. *(GLubyte *) userData = ubyte;
  664. userData = (GLvoid *) ((GLubyte *) userData + 1);
  665. }
  666. if (i) {
  667. ubyte = *(GLubyte *) userData;
  668. mask = 0x80;
  669. while (i-- > 0) {
  670. if (((GLint) *spanData++) & 1) ubyte |= mask;
  671. else ubyte &= ~mask;
  672. mask >>= 1;
  673. }
  674. *(GLubyte *) userData = ubyte;
  675. }
  676. }
  677. }