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.

1348 lines
39 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. /*
  20. ** This file contains a bunch of routines that perform span modification.
  21. ** As a span of pixel data is being processed (for DrawPixels, ReadPixels
  22. ** or CopyPixels), it usually has to pass through one of these routines.
  23. ** Span modification consists of mapping colors through pixel maps provided
  24. ** with glPixelMap*(), or scaling/biasing/shifting/offsetting colors with the
  25. ** values provided through glPixelTransfer*().
  26. */
  27. /*
  28. ** Build lookup tables to perform automatic modification of RGBA when the
  29. ** type is UNSIGNED_BYTE.
  30. */
  31. void FASTCALL __glBuildRGBAModifyTables(__GLcontext *gc, __GLpixelMachine *pm)
  32. {
  33. GLfloat *redMap, *greenMap, *blueMap, *alphaMap;
  34. GLint rrsize, ggsize, bbsize, aasize;
  35. __GLpixelMapHead *rrmap, *ggmap, *bbmap, *aamap;
  36. GLboolean mapColor;
  37. __GLfloat rbias, gbias, bbias, abias;
  38. GLint entry;
  39. __GLfloat rscale, gscale, bscale, ascale;
  40. GLint i;
  41. __GLfloat red, green, blue, alpha;
  42. mapColor = gc->state.pixel.transferMode.mapColor;
  43. pm->rgbaCurrent = GL_TRUE;
  44. redMap = pm->redModMap;
  45. if (redMap == NULL) {
  46. /* First time allocation of these maps */
  47. redMap = pm->redModMap = (GLfloat*)
  48. GCALLOC(gc, 4 * 256 * sizeof(GLfloat));
  49. if (!pm->redModMap)
  50. return;
  51. pm->greenModMap = pm->redModMap + 1 * 256;
  52. pm->blueModMap = pm->redModMap + 2 * 256;
  53. pm->alphaModMap = pm->redModMap + 3 * 256;
  54. }
  55. greenMap = pm->greenModMap;
  56. blueMap = pm->blueModMap;
  57. alphaMap = pm->alphaModMap;
  58. rbias = gc->state.pixel.transferMode.r_bias;
  59. gbias = gc->state.pixel.transferMode.g_bias;
  60. bbias = gc->state.pixel.transferMode.b_bias;
  61. abias = gc->state.pixel.transferMode.a_bias;
  62. rscale = gc->state.pixel.transferMode.r_scale;
  63. gscale = gc->state.pixel.transferMode.g_scale;
  64. bscale = gc->state.pixel.transferMode.b_scale;
  65. ascale = gc->state.pixel.transferMode.a_scale;
  66. if (mapColor) {
  67. rrmap =
  68. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  69. rrsize = rrmap->size;
  70. ggmap =
  71. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  72. ggsize = ggmap->size;
  73. bbmap =
  74. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  75. bbsize = bbmap->size;
  76. aamap =
  77. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  78. aasize = aamap->size;
  79. }
  80. for (i=0; i<256; i++) {
  81. alpha = red = green = blue = i / (__GLfloat) 255.0;
  82. red = red * rscale + rbias;
  83. green = green * gscale + gbias;
  84. blue = blue * bscale + bbias;
  85. alpha = alpha * ascale + abias;
  86. if (mapColor) {
  87. entry = red * rrsize;
  88. if (entry < 0) entry = 0;
  89. else if (entry > rrsize-1) entry = rrsize-1;
  90. red = rrmap->base.mapF[entry];
  91. entry = green * ggsize;
  92. if (entry < 0) entry = 0;
  93. else if (entry > ggsize-1) entry = ggsize-1;
  94. green = ggmap->base.mapF[entry];
  95. entry = blue * bbsize;
  96. if (entry < 0) entry = 0;
  97. else if (entry > bbsize-1) entry = bbsize-1;
  98. blue = bbmap->base.mapF[entry];
  99. entry = alpha * aasize;
  100. if (entry < 0) entry = 0;
  101. else if (entry > aasize-1) entry = aasize-1;
  102. alpha = aamap->base.mapF[entry];
  103. } else {
  104. if (red > __glOne) red = __glOne;
  105. else if (red < 0) red = 0;
  106. if (green > __glOne) green = __glOne;
  107. else if (green < 0) green = 0;
  108. if (blue > __glOne) blue = __glOne;
  109. else if (blue < 0) blue = 0;
  110. if (alpha > __glOne) alpha = __glOne;
  111. else if (alpha < 0) alpha = 0;
  112. }
  113. redMap[i] = red * gc->frontBuffer.redScale;
  114. greenMap[i] = green * gc->frontBuffer.greenScale;
  115. blueMap[i] = blue * gc->frontBuffer.blueScale;
  116. alphaMap[i] = alpha * gc->frontBuffer.alphaScale;
  117. }
  118. }
  119. /*
  120. ** Build lookup tables to perform automatic modification of color index to
  121. ** color index when the type is UNSIGNED_BYTE.
  122. */
  123. void FASTCALL __glBuildItoIModifyTables(__GLcontext *gc, __GLpixelMachine *pm)
  124. {
  125. GLint indexOffset, indexShift;
  126. __GLfloat indexScale;
  127. __GLpixelMapHead *iimap;
  128. GLint iimask;
  129. GLboolean mapColor;
  130. GLfloat *indexMap;
  131. GLint i;
  132. GLint entry;
  133. __GLfloat index;
  134. GLint mask;
  135. mapColor = gc->state.pixel.transferMode.mapColor;
  136. mask = gc->frontBuffer.redMax;
  137. pm->iToICurrent = GL_TRUE;
  138. indexMap = pm->iToIMap;
  139. if (indexMap == NULL) {
  140. indexMap = pm->iToIMap = (GLfloat*)
  141. GCALLOC(gc, 256 * sizeof(GLfloat));
  142. #ifdef NT
  143. if (!indexMap)
  144. return;
  145. #endif
  146. }
  147. indexOffset = gc->state.pixel.transferMode.indexOffset;
  148. indexShift = gc->state.pixel.transferMode.indexShift;
  149. if (indexShift >= 0) {
  150. indexScale = (GLuint) (1 << indexShift);
  151. } else {
  152. indexScale = __glOne/(GLuint) (1 << (-indexShift));
  153. }
  154. if (mapColor) {
  155. iimap = &gc->state.pixel.
  156. pixelMap[__GL_PIXEL_MAP_I_TO_I];
  157. iimask = iimap->size - 1;
  158. }
  159. for (i=0; i<256; i++) {
  160. index = i * indexScale + indexOffset;
  161. if (mapColor) {
  162. entry = (GLint) index;
  163. index = iimap->base.mapI[entry & iimask];
  164. }
  165. indexMap[i] = ((GLint) index) & mask;
  166. }
  167. }
  168. /*
  169. ** Build lookup tables to perform automatic modification of color index to
  170. ** RGBA when the type is UNSIGNED_BYTE.
  171. */
  172. void FASTCALL __glBuildItoRGBAModifyTables(__GLcontext *gc, __GLpixelMachine *pm)
  173. {
  174. GLint indexOffset, indexShift;
  175. __GLfloat indexScale;
  176. __GLpixelMapHead *irmap, *igmap, *ibmap, *iamap;
  177. GLint irmask, igmask, ibmask, iamask;
  178. GLfloat *redMap, *greenMap, *blueMap, *alphaMap;
  179. __GLfloat index;
  180. GLint entry;
  181. GLint i;
  182. pm->iToRGBACurrent = GL_TRUE;
  183. redMap = pm->iToRMap;
  184. if (redMap == NULL) {
  185. /* First time allocation of these maps */
  186. redMap = pm->iToRMap =
  187. (GLfloat*) GCALLOC(gc, 4 * 256 * sizeof(GLfloat));
  188. if (!pm->iToRMap)
  189. return;
  190. pm->iToGMap = pm->iToRMap + 1 * 256;
  191. pm->iToBMap = pm->iToRMap + 2 * 256;
  192. pm->iToAMap = pm->iToRMap + 3 * 256;
  193. }
  194. greenMap = pm->iToGMap;
  195. blueMap = pm->iToBMap;
  196. alphaMap = pm->iToAMap;
  197. indexOffset = gc->state.pixel.transferMode.indexOffset;
  198. indexShift = gc->state.pixel.transferMode.indexShift;
  199. if (indexShift >= 0) {
  200. indexScale = (GLuint) (1 << indexShift);
  201. } else {
  202. indexScale = __glOne/(GLuint) (1 << (-indexShift));
  203. }
  204. irmap =
  205. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_R];
  206. irmask = irmap->size - 1;
  207. igmap =
  208. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_G];
  209. igmask = igmap->size - 1;
  210. ibmap =
  211. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_B];
  212. ibmask = ibmap->size - 1;
  213. iamap =
  214. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_A];
  215. iamask = iamap->size - 1;
  216. for (i=0; i<256; i++) {
  217. index = i * indexScale + indexOffset;
  218. entry = (GLint) index;
  219. redMap[i] = irmap->base.mapF[entry & irmask] *
  220. gc->frontBuffer.redScale;
  221. greenMap[i] = igmap->base.mapF[entry & igmask] *
  222. gc->frontBuffer.greenScale;
  223. blueMap[i] = ibmap->base.mapF[entry & ibmask] *
  224. gc->frontBuffer.blueScale;
  225. alphaMap[i] = iamap->base.mapF[entry & iamask] *
  226. gc->frontBuffer.alphaScale;
  227. }
  228. }
  229. /*
  230. ** Modify a RGBA, FLOAT span. On the way out, the RGBA span will have
  231. ** been modified as needed, and also scaled by the color scaling factors.
  232. */
  233. void __glSpanModifyRGBA(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  234. GLvoid *inspan, GLvoid *outspan)
  235. {
  236. __GLfloat rbias, gbias, bbias, abias;
  237. __GLfloat rscale, gscale, bscale, ascale;
  238. __GLpixelMapHead *rrmap, *ggmap, *bbmap, *aamap;
  239. GLint rrsize, ggsize, bbsize, aasize;
  240. GLboolean mapColor;
  241. GLfloat *oldData;
  242. GLfloat *newData;
  243. GLint i;
  244. GLint width;
  245. GLint entry;
  246. GLfloat red, green, blue, alpha;
  247. mapColor = gc->state.pixel.transferMode.mapColor;
  248. if (mapColor) {
  249. rbias = gc->state.pixel.transferMode.r_bias;
  250. gbias = gc->state.pixel.transferMode.g_bias;
  251. bbias = gc->state.pixel.transferMode.b_bias;
  252. abias = gc->state.pixel.transferMode.a_bias;
  253. rscale = gc->state.pixel.transferMode.r_scale;
  254. gscale = gc->state.pixel.transferMode.g_scale;
  255. bscale = gc->state.pixel.transferMode.b_scale;
  256. ascale = gc->state.pixel.transferMode.a_scale;
  257. rrmap =
  258. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  259. rrsize = rrmap->size;
  260. ggmap =
  261. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  262. ggsize = ggmap->size;
  263. bbmap =
  264. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  265. bbsize = bbmap->size;
  266. aamap =
  267. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  268. aasize = aamap->size;
  269. } else {
  270. rbias = gc->state.pixel.transferMode.r_bias *
  271. gc->frontBuffer.redScale;
  272. gbias = gc->state.pixel.transferMode.g_bias *
  273. gc->frontBuffer.greenScale;
  274. bbias = gc->state.pixel.transferMode.b_bias *
  275. gc->frontBuffer.blueScale;
  276. abias = gc->state.pixel.transferMode.a_bias *
  277. gc->frontBuffer.alphaScale;
  278. rscale = gc->state.pixel.transferMode.r_scale *
  279. gc->frontBuffer.redScale;
  280. gscale = gc->state.pixel.transferMode.g_scale *
  281. gc->frontBuffer.greenScale;
  282. bscale = gc->state.pixel.transferMode.b_scale *
  283. gc->frontBuffer.blueScale;
  284. ascale = gc->state.pixel.transferMode.a_scale *
  285. gc->frontBuffer.alphaScale;
  286. }
  287. oldData = (GLfloat*) inspan;
  288. newData = (GLfloat*) outspan;
  289. width = spanInfo->realWidth;
  290. for (i=0; i<width; i++) {
  291. #ifdef GL_EXT_bgra
  292. if (spanInfo->srcFormat == GL_RGBA)
  293. {
  294. red = *oldData++ * rscale + rbias;
  295. green = *oldData++ * gscale + gbias;
  296. blue = *oldData++ * bscale + bbias;
  297. alpha = *oldData++ * ascale + abias;
  298. }
  299. else
  300. {
  301. blue = *oldData++ * bscale + bbias;
  302. green = *oldData++ * gscale + gbias;
  303. red = *oldData++ * rscale + rbias;
  304. alpha = *oldData++ * ascale + abias;
  305. }
  306. #else
  307. red = *oldData++ * rscale + rbias;
  308. green = *oldData++ * gscale + gbias;
  309. blue = *oldData++ * bscale + bbias;
  310. alpha = *oldData++ * ascale + abias;
  311. #endif
  312. if (mapColor) {
  313. entry = red * rrsize;
  314. if (entry < 0) entry = 0;
  315. else if (entry > rrsize-1) entry = rrsize-1;
  316. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  317. entry = green * ggsize;
  318. if (entry < 0) entry = 0;
  319. else if (entry > ggsize-1) entry = ggsize-1;
  320. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  321. entry = blue * bbsize;
  322. if (entry < 0) entry = 0;
  323. else if (entry > bbsize-1) entry = bbsize-1;
  324. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  325. entry = alpha * aasize;
  326. if (entry < 0) entry = 0;
  327. else if (entry > aasize-1) entry = aasize-1;
  328. *newData++ = aamap->base.mapF[entry] * gc->frontBuffer.alphaScale;
  329. } else {
  330. if (red > gc->frontBuffer.redScale) {
  331. red = gc->frontBuffer.redScale;
  332. } else if (red < 0) red = 0;
  333. if (green > gc->frontBuffer.greenScale) {
  334. green = gc->frontBuffer.greenScale;
  335. } else if (green < 0) green = 0;
  336. if (blue > gc->frontBuffer.blueScale) {
  337. blue = gc->frontBuffer.blueScale;
  338. } else if (blue < 0) blue = 0;
  339. if (alpha > gc->frontBuffer.alphaScale) {
  340. alpha = gc->frontBuffer.alphaScale;
  341. } else if (alpha < 0) alpha = 0;
  342. *newData++ = red;
  343. *newData++ = green;
  344. *newData++ = blue;
  345. *newData++ = alpha;
  346. }
  347. }
  348. }
  349. /*
  350. ** Modify a palette index, FLOAT span. On the way out, the RGBA span will have
  351. ** been modified as needed, and also scaled by the color scaling factors.
  352. **
  353. ** Because the palette in the span info is a pointer to the internal palette,
  354. ** it's guaranteed to always be 32-bit BGRA
  355. */
  356. #ifdef GL_EXT_paletted_texture
  357. void __glSpanModifyPI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  358. GLvoid *inspan, GLvoid *outspan)
  359. {
  360. __GLfloat rbias, gbias, bbias, abias;
  361. __GLfloat rscale, gscale, bscale, ascale;
  362. __GLpixelMapHead *rrmap, *ggmap, *bbmap, *aamap;
  363. GLint rrsize, ggsize, bbsize, aasize;
  364. GLboolean mapColor;
  365. GLfloat *oldData;
  366. GLfloat *newData;
  367. GLint i;
  368. GLint width;
  369. GLint entry;
  370. GLfloat red, green, blue, alpha;
  371. RGBQUAD *rgb;
  372. mapColor = gc->state.pixel.transferMode.mapColor;
  373. if (mapColor) {
  374. rbias = gc->state.pixel.transferMode.r_bias;
  375. gbias = gc->state.pixel.transferMode.g_bias;
  376. bbias = gc->state.pixel.transferMode.b_bias;
  377. abias = gc->state.pixel.transferMode.a_bias;
  378. rscale = gc->state.pixel.transferMode.r_scale;
  379. gscale = gc->state.pixel.transferMode.g_scale;
  380. bscale = gc->state.pixel.transferMode.b_scale;
  381. ascale = gc->state.pixel.transferMode.a_scale;
  382. rrmap =
  383. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  384. rrsize = rrmap->size;
  385. ggmap =
  386. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  387. ggsize = ggmap->size;
  388. bbmap =
  389. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  390. bbsize = bbmap->size;
  391. aamap =
  392. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  393. aasize = aamap->size;
  394. } else {
  395. rbias = gc->state.pixel.transferMode.r_bias *
  396. gc->frontBuffer.redScale;
  397. gbias = gc->state.pixel.transferMode.g_bias *
  398. gc->frontBuffer.greenScale;
  399. bbias = gc->state.pixel.transferMode.b_bias *
  400. gc->frontBuffer.blueScale;
  401. abias = gc->state.pixel.transferMode.a_bias *
  402. gc->frontBuffer.alphaScale;
  403. rscale = gc->state.pixel.transferMode.r_scale *
  404. gc->frontBuffer.redScale;
  405. gscale = gc->state.pixel.transferMode.g_scale *
  406. gc->frontBuffer.greenScale;
  407. bscale = gc->state.pixel.transferMode.b_scale *
  408. gc->frontBuffer.blueScale;
  409. ascale = gc->state.pixel.transferMode.a_scale *
  410. gc->frontBuffer.alphaScale;
  411. }
  412. // Throw in an extra scaling of 1/255 because the palette
  413. // data is in ubyte format
  414. rscale *= __glOneOver255;
  415. gscale *= __glOneOver255;
  416. bscale *= __glOneOver255;
  417. ascale *= __glOneOver255;
  418. oldData = (GLfloat*) inspan;
  419. newData = (GLfloat*) outspan;
  420. width = spanInfo->realWidth;
  421. for (i=0; i<width; i++) {
  422. rgb = &spanInfo->srcPalette[(int)((*oldData++)*
  423. spanInfo->srcPaletteSize)];
  424. red = rgb->rgbRed * rscale + rbias;
  425. green = rgb->rgbGreen * gscale + gbias;
  426. blue = rgb->rgbBlue * bscale + bbias;
  427. alpha = rgb->rgbReserved * ascale + abias;
  428. if (mapColor) {
  429. entry = red * rrsize;
  430. if (entry < 0) entry = 0;
  431. else if (entry > rrsize-1) entry = rrsize-1;
  432. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  433. entry = green * ggsize;
  434. if (entry < 0) entry = 0;
  435. else if (entry > ggsize-1) entry = ggsize-1;
  436. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  437. entry = blue * bbsize;
  438. if (entry < 0) entry = 0;
  439. else if (entry > bbsize-1) entry = bbsize-1;
  440. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  441. entry = alpha * aasize;
  442. if (entry < 0) entry = 0;
  443. else if (entry > aasize-1) entry = aasize-1;
  444. *newData++ = aamap->base.mapF[entry] * gc->frontBuffer.alphaScale;
  445. } else {
  446. if (red > gc->frontBuffer.redScale) {
  447. red = gc->frontBuffer.redScale;
  448. } else if (red < 0) red = 0;
  449. if (green > gc->frontBuffer.greenScale) {
  450. green = gc->frontBuffer.greenScale;
  451. } else if (green < 0) green = 0;
  452. if (blue > gc->frontBuffer.blueScale) {
  453. blue = gc->frontBuffer.blueScale;
  454. } else if (blue < 0) blue = 0;
  455. if (alpha > gc->frontBuffer.alphaScale) {
  456. alpha = gc->frontBuffer.alphaScale;
  457. } else if (alpha < 0) alpha = 0;
  458. *newData++ = red;
  459. *newData++ = green;
  460. *newData++ = blue;
  461. *newData++ = alpha;
  462. }
  463. }
  464. }
  465. #endif
  466. /*
  467. ** Modify a RED, FLOAT span. On the way out, the RED span will have been
  468. ** converted into a RGBA span, modified as needed, and also scaled by the
  469. ** color scaling factors.
  470. */
  471. void __glSpanModifyRed(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  472. GLvoid *inspan, GLvoid *outspan)
  473. {
  474. __GLpixelMachine *pm;
  475. __GLfloat rbias;
  476. __GLfloat rscale;
  477. __GLpixelMapHead *rrmap;
  478. GLint rrsize;
  479. GLboolean mapColor;
  480. GLfloat *oldData;
  481. GLfloat *newData;
  482. GLint i;
  483. GLint width;
  484. GLint entry;
  485. GLfloat red, green, blue, alpha;
  486. mapColor = gc->state.pixel.transferMode.mapColor;
  487. pm = &(gc->pixel);
  488. green = pm->green0Mod;
  489. blue = pm->blue0Mod;
  490. alpha = pm->alpha1Mod;
  491. if (mapColor) {
  492. rbias = gc->state.pixel.transferMode.r_bias;
  493. rscale = gc->state.pixel.transferMode.r_scale;
  494. rrmap =
  495. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  496. rrsize = rrmap->size;
  497. } else {
  498. rbias = gc->state.pixel.transferMode.r_bias *
  499. gc->frontBuffer.redScale;
  500. rscale = gc->state.pixel.transferMode.r_scale *
  501. gc->frontBuffer.redScale;
  502. }
  503. oldData = (GLfloat*) inspan;
  504. newData = (GLfloat*) outspan;
  505. width = spanInfo->realWidth;
  506. for (i=0; i<width; i++) {
  507. red = *oldData++ * rscale + rbias;
  508. if (mapColor) {
  509. entry = red * rrsize;
  510. if (entry < 0) entry = 0;
  511. else if (entry > rrsize-1) entry = rrsize-1;
  512. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  513. } else {
  514. if (red > gc->frontBuffer.redScale) {
  515. red = gc->frontBuffer.redScale;
  516. } else if (red < 0) red = 0;
  517. *newData++ = red;
  518. }
  519. *newData++ = green;
  520. *newData++ = blue;
  521. *newData++ = alpha;
  522. }
  523. }
  524. /*
  525. ** Modify a GREEN, FLOAT span. On the way out, the GREEN span will have been
  526. ** converted into a RGBA span, modified as needed, and also scaled by the
  527. ** color scaling factors.
  528. */
  529. void __glSpanModifyGreen(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  530. GLvoid *inspan, GLvoid *outspan)
  531. {
  532. __GLpixelMachine *pm;
  533. __GLfloat gbias;
  534. __GLfloat gscale;
  535. __GLpixelMapHead *ggmap;
  536. GLint ggsize;
  537. GLboolean mapColor;
  538. GLfloat *oldData;
  539. GLfloat *newData;
  540. GLint i;
  541. GLint width;
  542. GLint entry;
  543. GLfloat red, green, blue, alpha;
  544. mapColor = gc->state.pixel.transferMode.mapColor;
  545. pm = &(gc->pixel);
  546. red = pm->red0Mod;
  547. blue = pm->blue0Mod;
  548. alpha = pm->alpha1Mod;
  549. if (mapColor) {
  550. gbias = gc->state.pixel.transferMode.g_bias;
  551. gscale = gc->state.pixel.transferMode.g_scale;
  552. ggmap =
  553. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  554. ggsize = ggmap->size;
  555. } else {
  556. gbias = gc->state.pixel.transferMode.g_bias *
  557. gc->frontBuffer.greenScale;
  558. gscale = gc->state.pixel.transferMode.g_scale *
  559. gc->frontBuffer.greenScale;
  560. }
  561. oldData = (GLfloat*) inspan;
  562. newData = (GLfloat*) outspan;
  563. width = spanInfo->realWidth;
  564. for (i=0; i<width; i++) {
  565. green = *oldData++ * gscale + gbias;
  566. *newData++ = red;
  567. if (mapColor) {
  568. entry = green * ggsize;
  569. if (entry < 0) entry = 0;
  570. else if (entry > ggsize-1) entry = ggsize-1;
  571. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  572. } else {
  573. if (green > gc->frontBuffer.greenScale) {
  574. green = gc->frontBuffer.greenScale;
  575. } else if (green < 0) green = 0;
  576. *newData++ = green;
  577. }
  578. *newData++ = blue;
  579. *newData++ = alpha;
  580. }
  581. }
  582. /*
  583. ** Modify a BLUE, FLOAT span. On the way out, the BLUE span will have been
  584. ** converted into a RGBA span, modified as needed, and also scaled by the
  585. ** color scaling factors.
  586. */
  587. void __glSpanModifyBlue(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  588. GLvoid *inspan, GLvoid *outspan)
  589. {
  590. __GLpixelMachine *pm;
  591. __GLfloat bbias;
  592. __GLfloat bscale;
  593. __GLpixelMapHead *bbmap;
  594. GLint bbsize;
  595. GLboolean mapColor;
  596. GLfloat *oldData;
  597. GLfloat *newData;
  598. GLint i;
  599. GLint width;
  600. GLint entry;
  601. GLfloat red, green, blue, alpha;
  602. mapColor = gc->state.pixel.transferMode.mapColor;
  603. pm = &(gc->pixel);
  604. red = pm->red0Mod;
  605. green = pm->green0Mod;
  606. alpha = pm->alpha1Mod;
  607. if (mapColor) {
  608. bbias = gc->state.pixel.transferMode.b_bias;
  609. bscale = gc->state.pixel.transferMode.b_scale;
  610. bbmap =
  611. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  612. bbsize = bbmap->size;
  613. } else {
  614. bbias = gc->state.pixel.transferMode.b_bias *
  615. gc->frontBuffer.blueScale;
  616. bscale = gc->state.pixel.transferMode.b_scale *
  617. gc->frontBuffer.blueScale;
  618. }
  619. oldData = (GLfloat*) inspan;
  620. newData = (GLfloat*) outspan;
  621. width = spanInfo->realWidth;
  622. for (i=0; i<width; i++) {
  623. blue = *oldData++ * bscale + bbias;
  624. *newData++ = red;
  625. *newData++ = green;
  626. if (mapColor) {
  627. entry = blue * bbsize;
  628. if (entry < 0) entry = 0;
  629. else if (entry > bbsize-1) entry = bbsize-1;
  630. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  631. } else {
  632. if (blue > gc->frontBuffer.blueScale) {
  633. blue = gc->frontBuffer.blueScale;
  634. } else if (blue < 0) blue = 0;
  635. *newData++ = blue;
  636. }
  637. *newData++ = alpha;
  638. }
  639. }
  640. /*
  641. ** Modify an ALPHA, FLOAT span. On the way out, the ALPHA span will have been
  642. ** converted into a RGBA span, modified as needed, and also scaled by the
  643. ** color scaling factors.
  644. */
  645. void __glSpanModifyAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  646. GLvoid *inspan, GLvoid *outspan)
  647. {
  648. __GLpixelMachine *pm;
  649. __GLfloat abias;
  650. __GLfloat ascale;
  651. __GLpixelMapHead *aamap;
  652. GLint aasize;
  653. GLboolean mapColor;
  654. GLfloat *oldData;
  655. GLfloat *newData;
  656. GLint i;
  657. GLint width;
  658. GLint entry;
  659. GLfloat red, green, blue, alpha;
  660. mapColor = gc->state.pixel.transferMode.mapColor;
  661. pm = &(gc->pixel);
  662. red = pm->red0Mod;
  663. green = pm->green0Mod;
  664. blue = pm->blue0Mod;
  665. if (mapColor) {
  666. abias = gc->state.pixel.transferMode.a_bias;
  667. ascale = gc->state.pixel.transferMode.a_scale;
  668. aamap =
  669. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  670. aasize = aamap->size;
  671. } else {
  672. abias = gc->state.pixel.transferMode.a_bias *
  673. gc->frontBuffer.alphaScale;
  674. ascale = gc->state.pixel.transferMode.a_scale *
  675. gc->frontBuffer.alphaScale;
  676. }
  677. oldData = (GLfloat*) inspan;
  678. newData = (GLfloat*) outspan;
  679. width = spanInfo->realWidth;
  680. for (i=0; i<width; i++) {
  681. alpha = *oldData++ * ascale + abias;
  682. *newData++ = red;
  683. *newData++ = green;
  684. *newData++ = blue;
  685. if (mapColor) {
  686. entry = alpha * aasize;
  687. if (entry < 0) entry = 0;
  688. else if (entry > aasize-1) entry = aasize-1;
  689. *newData++ = aamap->base.mapF[entry] * gc->frontBuffer.alphaScale;
  690. } else {
  691. if (alpha > gc->frontBuffer.alphaScale) {
  692. alpha = gc->frontBuffer.alphaScale;
  693. } else if (alpha < 0) alpha = 0;
  694. *newData++ = alpha;
  695. }
  696. }
  697. }
  698. /*
  699. ** Modify a RGB, FLOAT span. On the way out, the RGB span will have been
  700. ** converted into a RGBA span, modified as needed, and also scaled by the
  701. ** color scaling factors.
  702. */
  703. void __glSpanModifyRGB(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  704. GLvoid *inspan, GLvoid *outspan)
  705. {
  706. __GLpixelMachine *pm;
  707. __GLfloat rbias, gbias, bbias;
  708. __GLfloat rscale, gscale, bscale;
  709. __GLpixelMapHead *rrmap, *ggmap, *bbmap;
  710. GLint rrsize, ggsize, bbsize;
  711. GLboolean mapColor;
  712. GLfloat *oldData;
  713. GLfloat *newData;
  714. GLint i;
  715. GLint width;
  716. GLint entry;
  717. GLfloat red, green, blue, alpha;
  718. pm = &(gc->pixel);
  719. mapColor = gc->state.pixel.transferMode.mapColor;
  720. alpha = pm->alpha1Mod;
  721. if (mapColor) {
  722. rbias = gc->state.pixel.transferMode.r_bias;
  723. gbias = gc->state.pixel.transferMode.g_bias;
  724. bbias = gc->state.pixel.transferMode.b_bias;
  725. rscale = gc->state.pixel.transferMode.r_scale;
  726. gscale = gc->state.pixel.transferMode.g_scale;
  727. bscale = gc->state.pixel.transferMode.b_scale;
  728. rrmap =
  729. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  730. rrsize = rrmap->size;
  731. ggmap =
  732. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  733. ggsize = ggmap->size;
  734. bbmap =
  735. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  736. bbsize = bbmap->size;
  737. } else {
  738. rbias = gc->state.pixel.transferMode.r_bias *
  739. gc->frontBuffer.redScale;
  740. gbias = gc->state.pixel.transferMode.g_bias *
  741. gc->frontBuffer.greenScale;
  742. bbias = gc->state.pixel.transferMode.b_bias *
  743. gc->frontBuffer.blueScale;
  744. rscale = gc->state.pixel.transferMode.r_scale *
  745. gc->frontBuffer.redScale;
  746. gscale = gc->state.pixel.transferMode.g_scale *
  747. gc->frontBuffer.greenScale;
  748. bscale = gc->state.pixel.transferMode.b_scale *
  749. gc->frontBuffer.blueScale;
  750. }
  751. oldData = (GLfloat*) inspan;
  752. newData = (GLfloat*) outspan;
  753. width = spanInfo->realWidth;
  754. for (i=0; i<width; i++) {
  755. #ifdef GL_EXT_bgra
  756. if (spanInfo->srcFormat == GL_RGB)
  757. {
  758. red = *oldData++ * rscale + rbias;
  759. green = *oldData++ * gscale + gbias;
  760. blue = *oldData++ * bscale + bbias;
  761. }
  762. else
  763. {
  764. blue = *oldData++ * bscale + bbias;
  765. green = *oldData++ * gscale + gbias;
  766. red = *oldData++ * rscale + rbias;
  767. }
  768. #else
  769. red = *oldData++ * rscale + rbias;
  770. green = *oldData++ * gscale + gbias;
  771. blue = *oldData++ * bscale + bbias;
  772. #endif
  773. if (mapColor) {
  774. entry = red * rrsize;
  775. if (entry < 0) entry = 0;
  776. else if (entry > rrsize-1) entry = rrsize-1;
  777. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  778. entry = green * ggsize;
  779. if (entry < 0) entry = 0;
  780. else if (entry > ggsize-1) entry = ggsize-1;
  781. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  782. entry = blue * bbsize;
  783. if (entry < 0) entry = 0;
  784. else if (entry > bbsize-1) entry = bbsize-1;
  785. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  786. } else {
  787. if (red > gc->frontBuffer.redScale) {
  788. red = gc->frontBuffer.redScale;
  789. } else if (red < 0) red = 0;
  790. if (green > gc->frontBuffer.greenScale) {
  791. green = gc->frontBuffer.greenScale;
  792. } else if (green < 0) green = 0;
  793. if (blue > gc->frontBuffer.blueScale) {
  794. blue = gc->frontBuffer.blueScale;
  795. } else if (blue < 0) blue = 0;
  796. *newData++ = red;
  797. *newData++ = green;
  798. *newData++ = blue;
  799. }
  800. *newData++ = alpha;
  801. }
  802. }
  803. /*
  804. ** Modify a LUMINANCE, FLOAT span. On the way out, the LUMINANCE span will
  805. ** have been converted into a RGBA span, modified as needed, and also scaled
  806. ** by the color scaling factors.
  807. */
  808. void __glSpanModifyLuminance(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  809. GLvoid *inspan, GLvoid *outspan)
  810. {
  811. __GLpixelMachine *pm;
  812. __GLfloat rbias, gbias, bbias;
  813. __GLfloat rscale, gscale, bscale;
  814. __GLpixelMapHead *rrmap, *ggmap, *bbmap;
  815. GLint rrsize, ggsize, bbsize;
  816. GLboolean mapColor;
  817. GLfloat *oldData;
  818. GLfloat *newData;
  819. GLint i;
  820. GLint width;
  821. GLint entry;
  822. GLfloat red, green, blue, alpha;
  823. pm = &(gc->pixel);
  824. mapColor = gc->state.pixel.transferMode.mapColor;
  825. alpha = pm->alpha1Mod;
  826. if (mapColor) {
  827. rbias = gc->state.pixel.transferMode.r_bias;
  828. gbias = gc->state.pixel.transferMode.g_bias;
  829. bbias = gc->state.pixel.transferMode.b_bias;
  830. rscale = gc->state.pixel.transferMode.r_scale;
  831. gscale = gc->state.pixel.transferMode.g_scale;
  832. bscale = gc->state.pixel.transferMode.b_scale;
  833. rrmap =
  834. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  835. rrsize = rrmap->size;
  836. ggmap =
  837. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  838. ggsize = ggmap->size;
  839. bbmap =
  840. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  841. bbsize = bbmap->size;
  842. } else {
  843. rbias = gc->state.pixel.transferMode.r_bias *
  844. gc->frontBuffer.redScale;
  845. gbias = gc->state.pixel.transferMode.g_bias *
  846. gc->frontBuffer.greenScale;
  847. bbias = gc->state.pixel.transferMode.b_bias *
  848. gc->frontBuffer.blueScale;
  849. rscale = gc->state.pixel.transferMode.r_scale *
  850. gc->frontBuffer.redScale;
  851. gscale = gc->state.pixel.transferMode.g_scale *
  852. gc->frontBuffer.greenScale;
  853. bscale = gc->state.pixel.transferMode.b_scale *
  854. gc->frontBuffer.blueScale;
  855. }
  856. oldData = (GLfloat*) inspan;
  857. newData = (GLfloat*) outspan;
  858. width = spanInfo->realWidth;
  859. for (i=0; i<width; i++) {
  860. red = *oldData * rscale + rbias;
  861. green = *oldData * gscale + gbias;
  862. blue = *oldData++ * bscale + bbias;
  863. if (mapColor) {
  864. entry = red * rrsize;
  865. if (entry < 0) entry = 0;
  866. else if (entry > rrsize-1) entry = rrsize-1;
  867. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  868. entry = green * ggsize;
  869. if (entry < 0) entry = 0;
  870. else if (entry > ggsize-1) entry = ggsize-1;
  871. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  872. entry = blue * bbsize;
  873. if (entry < 0) entry = 0;
  874. else if (entry > bbsize-1) entry = bbsize-1;
  875. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  876. } else {
  877. if (red > gc->frontBuffer.redScale) {
  878. red = gc->frontBuffer.redScale;
  879. } else if (red < 0) red = 0;
  880. if (green > gc->frontBuffer.greenScale) {
  881. green = gc->frontBuffer.greenScale;
  882. } else if (green < 0) green = 0;
  883. if (blue > gc->frontBuffer.blueScale) {
  884. blue = gc->frontBuffer.blueScale;
  885. } else if (blue < 0) blue = 0;
  886. *newData++ = red;
  887. *newData++ = green;
  888. *newData++ = blue;
  889. }
  890. *newData++ = alpha;
  891. }
  892. }
  893. /*
  894. ** Modify a LUMINANCE_ALPHA, FLOAT span. On the way out, the LUMINANCE_ALPHA
  895. ** span will have been converted into a RGBA span, modified as needed, and
  896. ** also scaled by the color scaling factors.
  897. */
  898. void __glSpanModifyLuminanceAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  899. GLvoid *inspan, GLvoid *outspan)
  900. {
  901. __GLfloat rbias, gbias, bbias, abias;
  902. __GLfloat rscale, gscale, bscale, ascale;
  903. __GLpixelMapHead *rrmap, *ggmap, *bbmap, *aamap;
  904. GLint rrsize, ggsize, bbsize, aasize;
  905. GLboolean mapColor;
  906. GLfloat *oldData;
  907. GLfloat *newData;
  908. GLint i;
  909. GLint width;
  910. GLint entry;
  911. GLfloat red, green, blue, alpha;
  912. mapColor = gc->state.pixel.transferMode.mapColor;
  913. if (mapColor) {
  914. rbias = gc->state.pixel.transferMode.r_bias;
  915. gbias = gc->state.pixel.transferMode.g_bias;
  916. bbias = gc->state.pixel.transferMode.b_bias;
  917. abias = gc->state.pixel.transferMode.a_bias;
  918. rscale = gc->state.pixel.transferMode.r_scale;
  919. gscale = gc->state.pixel.transferMode.g_scale;
  920. bscale = gc->state.pixel.transferMode.b_scale;
  921. ascale = gc->state.pixel.transferMode.a_scale;
  922. rrmap =
  923. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  924. rrsize = rrmap->size;
  925. ggmap =
  926. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_G_TO_G];
  927. ggsize = ggmap->size;
  928. bbmap =
  929. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_B_TO_B];
  930. bbsize = bbmap->size;
  931. aamap =
  932. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  933. aasize = aamap->size;
  934. } else {
  935. rbias = gc->state.pixel.transferMode.r_bias *
  936. gc->frontBuffer.redScale;
  937. gbias = gc->state.pixel.transferMode.g_bias *
  938. gc->frontBuffer.greenScale;
  939. bbias = gc->state.pixel.transferMode.b_bias *
  940. gc->frontBuffer.blueScale;
  941. abias = gc->state.pixel.transferMode.a_bias *
  942. gc->frontBuffer.alphaScale;
  943. rscale = gc->state.pixel.transferMode.r_scale *
  944. gc->frontBuffer.redScale;
  945. gscale = gc->state.pixel.transferMode.g_scale *
  946. gc->frontBuffer.greenScale;
  947. bscale = gc->state.pixel.transferMode.b_scale *
  948. gc->frontBuffer.blueScale;
  949. ascale = gc->state.pixel.transferMode.a_scale *
  950. gc->frontBuffer.alphaScale;
  951. }
  952. oldData = (GLfloat*) inspan;
  953. newData = (GLfloat*) outspan;
  954. width = spanInfo->realWidth;
  955. for (i=0; i<width; i++) {
  956. red = *oldData * rscale + rbias;
  957. green = *oldData * gscale + gbias;
  958. blue = *oldData++ * bscale + bbias;
  959. alpha = *oldData++ * ascale + abias;
  960. if (mapColor) {
  961. entry = red * rrsize;
  962. if (entry < 0) entry = 0;
  963. else if (entry > rrsize-1) entry = rrsize-1;
  964. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  965. entry = green * ggsize;
  966. if (entry < 0) entry = 0;
  967. else if (entry > ggsize-1) entry = ggsize-1;
  968. *newData++ = ggmap->base.mapF[entry] * gc->frontBuffer.greenScale;
  969. entry = blue * bbsize;
  970. if (entry < 0) entry = 0;
  971. else if (entry > bbsize-1) entry = bbsize-1;
  972. *newData++ = bbmap->base.mapF[entry] * gc->frontBuffer.blueScale;
  973. entry = alpha * aasize;
  974. if (entry < 0) entry = 0;
  975. else if (entry > aasize-1) entry = aasize-1;
  976. *newData++ = aamap->base.mapF[entry] * gc->frontBuffer.alphaScale;
  977. } else {
  978. if (red > gc->frontBuffer.redScale) {
  979. red = gc->frontBuffer.redScale;
  980. } else if (red < 0) red = 0;
  981. if (green > gc->frontBuffer.greenScale) {
  982. green = gc->frontBuffer.greenScale;
  983. } else if (green < 0) green = 0;
  984. if (blue > gc->frontBuffer.blueScale) {
  985. blue = gc->frontBuffer.blueScale;
  986. } else if (blue < 0) blue = 0;
  987. if (alpha > gc->frontBuffer.alphaScale) {
  988. alpha = gc->frontBuffer.alphaScale;
  989. } else if (alpha < 0) alpha = 0;
  990. *newData++ = red;
  991. *newData++ = green;
  992. *newData++ = blue;
  993. *newData++ = alpha;
  994. }
  995. }
  996. }
  997. /*
  998. ** Modify a RED_ALPHA, FLOAT span. On the way out, the RED_ALPHA span will
  999. ** have been converted into a RGBA span, modified as needed, and also scaled
  1000. ** by the color scaling factors.
  1001. **
  1002. ** A RED_ALPHA span comes from a two component texture (where the spec
  1003. ** takes the first component from RED for some reason rather than the more
  1004. ** typical recombination of r, g and b, as is done in ReadPixels).
  1005. */
  1006. void __glSpanModifyRedAlpha(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  1007. GLvoid *inspan, GLvoid *outspan)
  1008. {
  1009. __GLpixelMachine *pm;
  1010. __GLfloat rbias, abias;
  1011. __GLfloat rscale, ascale;
  1012. __GLpixelMapHead *rrmap, *aamap;
  1013. GLint rrsize, aasize;
  1014. GLboolean mapColor;
  1015. GLfloat *oldData;
  1016. GLfloat *newData;
  1017. GLint i;
  1018. GLint width;
  1019. GLint entry;
  1020. GLfloat red, green, blue, alpha;
  1021. mapColor = gc->state.pixel.transferMode.mapColor;
  1022. pm = &(gc->pixel);
  1023. green = pm->green0Mod;
  1024. blue = pm->blue0Mod;
  1025. if (mapColor) {
  1026. rbias = gc->state.pixel.transferMode.r_bias;
  1027. abias = gc->state.pixel.transferMode.a_bias;
  1028. rscale = gc->state.pixel.transferMode.r_scale;
  1029. ascale = gc->state.pixel.transferMode.a_scale;
  1030. rrmap =
  1031. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_R_TO_R];
  1032. rrsize = rrmap->size;
  1033. aamap =
  1034. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_A_TO_A];
  1035. aasize = aamap->size;
  1036. } else {
  1037. rbias = gc->state.pixel.transferMode.r_bias *
  1038. gc->frontBuffer.redScale;
  1039. abias = gc->state.pixel.transferMode.a_bias *
  1040. gc->frontBuffer.alphaScale;
  1041. rscale = gc->state.pixel.transferMode.r_scale *
  1042. gc->frontBuffer.redScale;
  1043. ascale = gc->state.pixel.transferMode.a_scale *
  1044. gc->frontBuffer.alphaScale;
  1045. }
  1046. oldData = (GLfloat*) inspan;
  1047. newData = (GLfloat*) outspan;
  1048. width = spanInfo->realWidth;
  1049. for (i=0; i<width; i++) {
  1050. red = *oldData * rscale + rbias;
  1051. alpha = *oldData++ * ascale + abias;
  1052. if (mapColor) {
  1053. entry = red * rrsize;
  1054. if (entry < 0) entry = 0;
  1055. else if (entry > rrsize-1) entry = rrsize-1;
  1056. *newData++ = rrmap->base.mapF[entry] * gc->frontBuffer.redScale;
  1057. *newData++ = green;
  1058. *newData++ = blue;
  1059. entry = alpha * aasize;
  1060. if (entry < 0) entry = 0;
  1061. else if (entry > aasize-1) entry = aasize-1;
  1062. *newData++ = aamap->base.mapF[entry] * gc->frontBuffer.alphaScale;
  1063. } else {
  1064. if (red > gc->frontBuffer.redScale) {
  1065. red = gc->frontBuffer.redScale;
  1066. } else if (red < 0) red = 0;
  1067. if (alpha > gc->frontBuffer.alphaScale) {
  1068. alpha = gc->frontBuffer.alphaScale;
  1069. } else if (alpha < 0) alpha = 0;
  1070. *newData++ = red;
  1071. *newData++ = green;
  1072. *newData++ = blue;
  1073. *newData++ = alpha;
  1074. }
  1075. }
  1076. }
  1077. /*
  1078. ** Modify a DEPTH, FLOAT span. On the way out, the DEPTH span will have been
  1079. ** modified as needed.
  1080. */
  1081. void __glSpanModifyDepth(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  1082. GLvoid *inspan, GLvoid *outspan)
  1083. {
  1084. __GLfloat dbias;
  1085. __GLfloat dscale;
  1086. GLfloat *oldData;
  1087. GLfloat *newData;
  1088. GLfloat d;
  1089. GLfloat one, zero;
  1090. GLint i;
  1091. GLint width;
  1092. dbias = gc->state.pixel.transferMode.d_bias;
  1093. dscale = gc->state.pixel.transferMode.d_scale;
  1094. one = __glOne;
  1095. zero = __glZero;
  1096. oldData = (GLfloat*) inspan;
  1097. newData = (GLfloat*) outspan;
  1098. width = spanInfo->realWidth;
  1099. for (i=0; i<width; i++) {
  1100. d = *oldData++ * dscale + dbias;
  1101. if (d < zero) d = zero;
  1102. else if (d > one) d = one;
  1103. *newData++ = d;
  1104. }
  1105. }
  1106. /*
  1107. ** Modify a STENCIL_INDEX, FLOAT span. On the way out, the STENCIL_INDEX span
  1108. ** will have been modified as needed.
  1109. */
  1110. void __glSpanModifyStencil(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  1111. GLvoid *inspan, GLvoid *outspan)
  1112. {
  1113. __GLpixelMapHead *ssmap;
  1114. GLint ssmask;
  1115. GLfloat *oldData;
  1116. GLfloat *newData;
  1117. GLint i;
  1118. GLint width;
  1119. GLint entry;
  1120. GLboolean mapStencil;
  1121. __GLfloat indexScale;
  1122. GLint indexOffset, indexShift;
  1123. GLfloat index;
  1124. indexOffset = gc->state.pixel.transferMode.indexOffset;
  1125. indexShift = gc->state.pixel.transferMode.indexShift;
  1126. if (indexShift >= 0) {
  1127. indexScale = (GLuint) (1 << indexShift);
  1128. } else {
  1129. indexScale = __glOne/(GLuint) (1 << (-indexShift));
  1130. }
  1131. mapStencil = gc->state.pixel.transferMode.mapStencil;
  1132. if (mapStencil) {
  1133. ssmap =
  1134. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_S_TO_S];
  1135. ssmask = ssmap->size - 1;
  1136. }
  1137. oldData = (GLfloat*) inspan;
  1138. newData = (GLfloat*) outspan;
  1139. width = spanInfo->realWidth;
  1140. for (i=0; i<width; i++) {
  1141. index = *oldData++ * indexScale + indexOffset;
  1142. if (mapStencil) {
  1143. entry = (int) index;
  1144. *newData++ = ssmap->base.mapI[entry & ssmask];
  1145. } else {
  1146. *newData++ = index;
  1147. }
  1148. }
  1149. }
  1150. /*
  1151. ** Modify a COLOR_INDEX, FLOAT span. On the way out, the COLOR_INDEX span
  1152. ** will have been modified as needed.
  1153. */
  1154. void __glSpanModifyCI(__GLcontext *gc, __GLpixelSpanInfo *spanInfo,
  1155. GLvoid *inspan, GLvoid *outspan)
  1156. {
  1157. __GLfloat indexScale;
  1158. GLint indexOffset, indexShift;
  1159. __GLpixelMapHead *iimap, *irmap, *igmap, *ibmap, *iamap;
  1160. GLint iimask, irmask, igmask, ibmask, iamask;
  1161. GLboolean mapColor;
  1162. GLfloat *oldData;
  1163. GLfloat *newData;
  1164. GLint i;
  1165. GLint width;
  1166. GLint entry;
  1167. GLfloat index;
  1168. mapColor = gc->state.pixel.transferMode.mapColor;
  1169. indexOffset = gc->state.pixel.transferMode.indexOffset;
  1170. indexShift = gc->state.pixel.transferMode.indexShift;
  1171. if (indexShift >= 0) {
  1172. indexScale = (GLuint) (1 << indexShift);
  1173. } else {
  1174. indexScale = __glOne/(GLuint) (1 << (-indexShift));
  1175. }
  1176. if (spanInfo->dstFormat != GL_COLOR_INDEX) {
  1177. irmap =
  1178. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_R];
  1179. irmask = irmap->size - 1;
  1180. igmap =
  1181. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_G];
  1182. igmask = igmap->size - 1;
  1183. ibmap =
  1184. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_B];
  1185. ibmask = ibmap->size - 1;
  1186. iamap =
  1187. &gc->state.pixel.pixelMap[__GL_PIXEL_MAP_I_TO_A];
  1188. iamask = iamap->size - 1;
  1189. } else {
  1190. if (mapColor) {
  1191. iimap = &gc->state.pixel.
  1192. pixelMap[__GL_PIXEL_MAP_I_TO_I];
  1193. iimask = iimap->size - 1;
  1194. }
  1195. }
  1196. oldData = (GLfloat*) inspan;
  1197. newData = (GLfloat*) outspan;
  1198. width = spanInfo->realWidth;
  1199. for (i=0; i<width; i++) {
  1200. index = *oldData++ * indexScale + indexOffset;
  1201. entry = (int) index;
  1202. if (spanInfo->dstFormat != GL_COLOR_INDEX) {
  1203. *newData++ = irmap->base.mapF[entry & irmask] *
  1204. gc->frontBuffer.redScale;
  1205. *newData++ = igmap->base.mapF[entry & igmask] *
  1206. gc->frontBuffer.greenScale;
  1207. *newData++ = ibmap->base.mapF[entry & ibmask] *
  1208. gc->frontBuffer.blueScale;
  1209. *newData++ = iamap->base.mapF[entry & iamask] *
  1210. gc->frontBuffer.alphaScale;
  1211. } else if (mapColor) {
  1212. *newData++ = iimap->base.mapI[entry & iimask];
  1213. } else {
  1214. *newData++ = index;
  1215. }
  1216. }
  1217. }