1. /*
  2. * @(#)TexturePaintContext.java 1.23 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt;
  11. import java.awt.image.BufferedImage;
  12. import java.awt.image.Raster;
  13. import java.awt.image.WritableRaster;
  14. import java.awt.image.ColorModel;
  15. import java.awt.image.DirectColorModel;
  16. import java.awt.image.IndexColorModel;
  17. import java.awt.geom.AffineTransform;
  18. import java.awt.geom.NoninvertibleTransformException;
  19. import sun.awt.image.IntegerInterleavedRaster;
  20. import sun.awt.image.ByteInterleavedRaster;
  21. abstract class TexturePaintContext implements PaintContext {
  22. ColorModel colorModel;
  23. int bWidth;
  24. int bHeight;
  25. int maxWidth;
  26. WritableRaster outRas;
  27. double xOrg;
  28. double yOrg;
  29. double incXAcross;
  30. double incYAcross;
  31. double incXDown;
  32. double incYDown;
  33. int colincx;
  34. int colincy;
  35. int colincxerr;
  36. int colincyerr;
  37. int rowincx;
  38. int rowincy;
  39. int rowincxerr;
  40. int rowincyerr;
  41. public static PaintContext getContext(BufferedImage bufImg,
  42. AffineTransform xform,
  43. RenderingHints hints,
  44. Rectangle devBounds) {
  45. WritableRaster raster = bufImg.getRaster();
  46. ColorModel cm = bufImg.getColorModel();
  47. int maxw = devBounds.width;
  48. Object val = hints.get(hints.KEY_INTERPOLATION);
  49. boolean filter =
  50. (val == null
  51. ? (hints.get(hints.KEY_RENDERING) == hints.VALUE_RENDER_QUALITY)
  52. : (val != hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
  53. if (raster instanceof IntegerInterleavedRaster &&
  54. (!filter || isFilterableDCM(cm)))
  55. {
  56. IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
  57. if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
  58. return new Int(iir, cm, xform, maxw, filter);
  59. }
  60. } else if (raster instanceof ByteInterleavedRaster) {
  61. ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
  62. if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
  63. if (filter) {
  64. if (isFilterableICM(cm)) {
  65. return new ByteFilter(bir, cm, xform, maxw);
  66. }
  67. } else {
  68. return new Byte(bir, cm, xform, maxw);
  69. }
  70. }
  71. }
  72. return new Any(raster, cm, xform, maxw, filter);
  73. }
  74. public static boolean isFilterableICM(ColorModel cm) {
  75. if (cm instanceof IndexColorModel) {
  76. IndexColorModel icm = (IndexColorModel) cm;
  77. if (icm.getMapSize() <= 256) {
  78. return true;
  79. }
  80. }
  81. return false;
  82. }
  83. public static boolean isFilterableDCM(ColorModel cm) {
  84. if (cm instanceof DirectColorModel) {
  85. DirectColorModel dcm = (DirectColorModel) cm;
  86. return (isMaskOK(dcm.getAlphaMask(), true) &&
  87. isMaskOK(dcm.getRedMask(), false) &&
  88. isMaskOK(dcm.getGreenMask(), false) &&
  89. isMaskOK(dcm.getBlueMask(), false));
  90. }
  91. return false;
  92. }
  93. public static boolean isMaskOK(int mask, boolean canbezero) {
  94. if (canbezero && mask == 0) {
  95. return true;
  96. }
  97. return (mask == 0xff ||
  98. mask == 0xff00 ||
  99. mask == 0xff0000 ||
  100. mask == 0xff000000);
  101. }
  102. TexturePaintContext(ColorModel cm, AffineTransform xform,
  103. int bWidth, int bHeight, int maxw) {
  104. this.colorModel = cm;
  105. this.bWidth = bWidth;
  106. this.bHeight = bHeight;
  107. this.maxWidth = maxw;
  108. try {
  109. xform = xform.createInverse();
  110. } catch (NoninvertibleTransformException e) {
  111. xform.setToScale(0, 0);
  112. }
  113. this.incXAcross = mod(xform.getScaleX(), bWidth);
  114. this.incYAcross = mod(xform.getShearY(), bHeight);
  115. this.incXDown = mod(xform.getShearX(), bWidth);
  116. this.incYDown = mod(xform.getScaleY(), bHeight);
  117. this.xOrg = xform.getTranslateX();
  118. this.yOrg = xform.getTranslateY();
  119. this.colincx = (int) incXAcross;
  120. this.colincy = (int) incYAcross;
  121. this.colincxerr = fractAsInt(incXAcross);
  122. this.colincyerr = fractAsInt(incYAcross);
  123. this.rowincx = (int) incXDown;
  124. this.rowincy = (int) incYDown;
  125. this.rowincxerr = fractAsInt(incXDown);
  126. this.rowincyerr = fractAsInt(incYDown);
  127. }
  128. static int fractAsInt(double d) {
  129. return (int) ((d % 1.0) * Integer.MAX_VALUE);
  130. }
  131. static double mod(double num, double den) {
  132. num = num % den;
  133. if (num < 0) {
  134. num += den;
  135. if (num >= den) {
  136. // For very small negative numerators, the answer might
  137. // be such a tiny bit less than den that the difference
  138. // is smaller than the mantissa of a double allows and
  139. // the result would then be rounded to den. If that is
  140. // the case then we map that number to 0 as the nearest
  141. // modulus representation.
  142. num = 0;
  143. }
  144. }
  145. return num;
  146. }
  147. /**
  148. * Release the resources allocated for the operation.
  149. */
  150. public void dispose() {
  151. // Nothing to dispose
  152. }
  153. /**
  154. * Return the ColorModel of the output.
  155. */
  156. public ColorModel getColorModel() {
  157. return colorModel;
  158. }
  159. /**
  160. * Return a Raster containing the colors generated for the graphics
  161. * operation.
  162. * @param x,y,w,h The area in device space for which colors are
  163. * generated.
  164. */
  165. public Raster getRaster(int x, int y, int w, int h) {
  166. if (outRas == null ||
  167. outRas.getWidth() < w ||
  168. outRas.getHeight() < h)
  169. {
  170. // If h==1, we will probably get lots of "scanline" rects
  171. outRas = makeRaster((h == 1 ? Math.max(w, maxWidth) : w), h);
  172. }
  173. double X = mod(xOrg + x * incXAcross + y * incXDown, bWidth);
  174. double Y = mod(yOrg + x * incYAcross + y * incYDown, bHeight);
  175. setRaster((int) X, (int) Y, fractAsInt(X), fractAsInt(Y),
  176. w, h, bWidth, bHeight,
  177. colincx, colincxerr,
  178. colincy, colincyerr,
  179. rowincx, rowincxerr,
  180. rowincy, rowincyerr);
  181. return outRas;
  182. }
  183. public abstract WritableRaster makeRaster(int w, int h);
  184. public abstract void setRaster(int x, int y, int xerr, int yerr,
  185. int w, int h, int bWidth, int bHeight,
  186. int colincx, int colincxerr,
  187. int colincy, int colincyerr,
  188. int rowincx, int rowincxerr,
  189. int rowincy, int rowincyerr);
  190. /*
  191. * Blends the four ARGB values in the rgbs array using the factors
  192. * described by xmul and ymul in the following ratio:
  193. *
  194. * rgbs[0] * (1-xmul) * (1-ymul) +
  195. * rgbs[1] * ( xmul) * (1-ymul) +
  196. * rgbs[2] * (1-xmul) * ( ymul) +
  197. * rgbs[3] * ( xmul) * ( ymul)
  198. *
  199. * xmul and ymul are integer values in the half-open range [0, 2^31)
  200. * where 0 == 0.0 and 2^31 == 1.0.
  201. *
  202. * Note that since the range is half-open, the values are always
  203. * logically less than 1.0. This makes sense because while choosing
  204. * pixels to blend, when the error values reach 1.0 we move to the
  205. * next pixel and reset them to 0.0.
  206. */
  207. public static int blend(int rgbs[], int xmul, int ymul) {
  208. // xmul/ymul are 31 bits wide, (0 => 2^31-1)
  209. // shift them to 12 bits wide, (0 => 2^12-1)
  210. xmul = (xmul >>> 19);
  211. ymul = (ymul >>> 19);
  212. int accumA, accumR, accumG, accumB;
  213. accumA = accumR = accumG = accumB = 0;
  214. for (int i = 0; i < 4; i++) {
  215. int rgb = rgbs[i];
  216. // The complement of the [xy]mul values (1-[xy]mul) can result
  217. // in new values in the range (1 => 2^12). Thus for any given
  218. // loop iteration, the values could be anywhere in (0 => 2^12).
  219. xmul = (1<<12) - xmul;
  220. if ((i & 1) == 0) {
  221. ymul = (1<<12) - ymul;
  222. }
  223. // xmul and ymul are each 12 bits (0 => 2^12)
  224. // factor is thus 24 bits (0 => 2^24)
  225. int factor = xmul * ymul;
  226. if (factor != 0) {
  227. // accum variables will accumulate 32 bits
  228. // bytes extracted from rgb fit in 8 bits (0 => 255)
  229. // byte * factor thus fits in 32 bits (0 => 255 * 2^24)
  230. accumA += (((rgb >>> 24) ) * factor);
  231. accumR += (((rgb >>> 16) & 0xff) * factor);
  232. accumG += (((rgb >>> 8) & 0xff) * factor);
  233. accumB += (((rgb ) & 0xff) * factor);
  234. }
  235. }
  236. return ((((accumA + (1<<23)) >>> 24) << 24) |
  237. (((accumR + (1<<23)) >>> 24) << 16) |
  238. (((accumG + (1<<23)) >>> 24) << 8) |
  239. (((accumB + (1<<23)) >>> 24) ));
  240. }
  241. static class Int extends TexturePaintContext {
  242. IntegerInterleavedRaster srcRas;
  243. int inData[];
  244. int inOff;
  245. int inSpan;
  246. int outData[];
  247. int outOff;
  248. int outSpan;
  249. boolean filter;
  250. public Int(IntegerInterleavedRaster srcRas, ColorModel cm,
  251. AffineTransform xform, int maxw, boolean filter)
  252. {
  253. super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
  254. this.srcRas = srcRas;
  255. this.inData = srcRas.getDataStorage();
  256. this.inSpan = srcRas.getScanlineStride();
  257. this.inOff = srcRas.getDataOffset(0);
  258. this.filter = filter;
  259. }
  260. public WritableRaster makeRaster(int w, int h) {
  261. WritableRaster ras = srcRas.createCompatibleWritableRaster(w, h);
  262. IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster) ras;
  263. outData = iiRas.getDataStorage();
  264. outSpan = iiRas.getScanlineStride();
  265. outOff = iiRas.getDataOffset(0);
  266. return ras;
  267. }
  268. public void setRaster(int x, int y, int xerr, int yerr,
  269. int w, int h, int bWidth, int bHeight,
  270. int colincx, int colincxerr,
  271. int colincy, int colincyerr,
  272. int rowincx, int rowincxerr,
  273. int rowincy, int rowincyerr) {
  274. int[] inData = this.inData;
  275. int[] outData = this.outData;
  276. int out = outOff;
  277. int inSpan = this.inSpan;
  278. int inOff = this.inOff;
  279. int outSpan = this.outSpan;
  280. boolean filter = this.filter;
  281. boolean normalx = (colincx == 1 && colincxerr == 0 &&
  282. colincy == 0 && colincyerr == 0) && !filter;
  283. int rowx = x;
  284. int rowy = y;
  285. int rowxerr = xerr;
  286. int rowyerr = yerr;
  287. if (normalx) {
  288. outSpan -= w;
  289. }
  290. int rgbs[] = filter ? new int[4] : null;
  291. for (int j = 0; j < h; j++) {
  292. if (normalx) {
  293. int in = inOff + rowy * inSpan + bWidth;
  294. x = bWidth - rowx;
  295. out += w;
  296. if (bWidth >= 32) {
  297. int i = w;
  298. while (i > 0) {
  299. int copyw = (i < x) ? i : x;
  300. System.arraycopy(inData, in - x,
  301. outData, out - i,
  302. copyw);
  303. i -= copyw;
  304. if ((x -= copyw) == 0) {
  305. x = bWidth;
  306. }
  307. }
  308. } else {
  309. for (int i = w; i > 0; i--) {
  310. outData[out - i] = inData[in - x];
  311. if (--x == 0) {
  312. x = bWidth;
  313. }
  314. }
  315. }
  316. } else {
  317. x = rowx;
  318. y = rowy;
  319. xerr = rowxerr;
  320. yerr = rowyerr;
  321. for (int i = 0; i < w; i++) {
  322. if (filter) {
  323. int nextx, nexty;
  324. if ((nextx = x + 1) >= bWidth) {
  325. nextx = 0;
  326. }
  327. if ((nexty = y + 1) >= bHeight) {
  328. nexty = 0;
  329. }
  330. rgbs[0] = inData[inOff + y * inSpan + x];
  331. rgbs[1] = inData[inOff + y * inSpan + nextx];
  332. rgbs[2] = inData[inOff + nexty * inSpan + x];
  333. rgbs[3] = inData[inOff + nexty * inSpan + nextx];
  334. outData[out + i] =
  335. TexturePaintContext.blend(rgbs, xerr, yerr);
  336. } else {
  337. outData[out + i] = inData[inOff + y * inSpan + x];
  338. }
  339. if ((xerr += colincxerr) < 0) {
  340. xerr &= Integer.MAX_VALUE;
  341. x++;
  342. }
  343. if ((x += colincx) >= bWidth) {
  344. x -= bWidth;
  345. }
  346. if ((yerr += colincyerr) < 0) {
  347. yerr &= Integer.MAX_VALUE;
  348. y++;
  349. }
  350. if ((y += colincy) >= bHeight) {
  351. y -= bHeight;
  352. }
  353. }
  354. }
  355. if ((rowxerr += rowincxerr) < 0) {
  356. rowxerr &= Integer.MAX_VALUE;
  357. rowx++;
  358. }
  359. if ((rowx += rowincx) >= bWidth) {
  360. rowx -= bWidth;
  361. }
  362. if ((rowyerr += rowincyerr) < 0) {
  363. rowyerr &= Integer.MAX_VALUE;
  364. rowy++;
  365. }
  366. if ((rowy += rowincy) >= bHeight) {
  367. rowy -= bHeight;
  368. }
  369. out += outSpan;
  370. }
  371. }
  372. }
  373. static class Byte extends TexturePaintContext {
  374. ByteInterleavedRaster srcRas;
  375. byte inData[];
  376. int inOff;
  377. int inSpan;
  378. byte outData[];
  379. int outOff;
  380. int outSpan;
  381. public Byte(ByteInterleavedRaster srcRas, ColorModel cm,
  382. AffineTransform xform, int maxw)
  383. {
  384. super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
  385. this.srcRas = srcRas;
  386. this.inData = srcRas.getDataStorage();
  387. this.inSpan = srcRas.getScanlineStride();
  388. this.inOff = srcRas.getDataOffset(0);
  389. }
  390. public WritableRaster makeRaster(int w, int h) {
  391. WritableRaster ras = srcRas.createCompatibleWritableRaster(w, h);
  392. ByteInterleavedRaster biRas = (ByteInterleavedRaster) ras;
  393. outData = biRas.getDataStorage();
  394. outSpan = biRas.getScanlineStride();
  395. outOff = biRas.getDataOffset(0);
  396. return ras;
  397. }
  398. public void setRaster(int x, int y, int xerr, int yerr,
  399. int w, int h, int bWidth, int bHeight,
  400. int colincx, int colincxerr,
  401. int colincy, int colincyerr,
  402. int rowincx, int rowincxerr,
  403. int rowincy, int rowincyerr) {
  404. byte[] inData = this.inData;
  405. byte[] outData = this.outData;
  406. int out = outOff;
  407. int inSpan = this.inSpan;
  408. int inOff = this.inOff;
  409. int outSpan = this.outSpan;
  410. boolean normalx = (colincx == 1 && colincxerr == 0 &&
  411. colincy == 0 && colincyerr == 0);
  412. int rowx = x;
  413. int rowy = y;
  414. int rowxerr = xerr;
  415. int rowyerr = yerr;
  416. if (normalx) {
  417. outSpan -= w;
  418. }
  419. for (int j = 0; j < h; j++) {
  420. if (normalx) {
  421. int in = inOff + rowy * inSpan + bWidth;
  422. x = bWidth - rowx;
  423. out += w;
  424. if (bWidth >= 32) {
  425. int i = w;
  426. while (i > 0) {
  427. int copyw = (i < x) ? i : x;
  428. System.arraycopy(inData, in - x,
  429. outData, out - i,
  430. copyw);
  431. i -= copyw;
  432. if ((x -= copyw) == 0) {
  433. x = bWidth;
  434. }
  435. }
  436. } else {
  437. for (int i = w; i > 0; i--) {
  438. outData[out - i] = inData[in - x];
  439. if (--x == 0) {
  440. x = bWidth;
  441. }
  442. }
  443. }
  444. } else {
  445. x = rowx;
  446. y = rowy;
  447. xerr = rowxerr;
  448. yerr = rowyerr;
  449. for (int i = 0; i < w; i++) {
  450. outData[out + i] = inData[inOff + y * inSpan + x];
  451. if ((xerr += colincxerr) < 0) {
  452. xerr &= Integer.MAX_VALUE;
  453. x++;
  454. }
  455. if ((x += colincx) >= bWidth) {
  456. x -= bWidth;
  457. }
  458. if ((yerr += colincyerr) < 0) {
  459. yerr &= Integer.MAX_VALUE;
  460. y++;
  461. }
  462. if ((y += colincy) >= bHeight) {
  463. y -= bHeight;
  464. }
  465. }
  466. }
  467. if ((rowxerr += rowincxerr) < 0) {
  468. rowxerr &= Integer.MAX_VALUE;
  469. rowx++;
  470. }
  471. if ((rowx += rowincx) >= bWidth) {
  472. rowx -= bWidth;
  473. }
  474. if ((rowyerr += rowincyerr) < 0) {
  475. rowyerr &= Integer.MAX_VALUE;
  476. rowy++;
  477. }
  478. if ((rowy += rowincy) >= bHeight) {
  479. rowy -= bHeight;
  480. }
  481. out += outSpan;
  482. }
  483. }
  484. }
  485. static class ByteFilter extends TexturePaintContext {
  486. ByteInterleavedRaster srcRas;
  487. int inPalette[];
  488. byte inData[];
  489. int inOff;
  490. int inSpan;
  491. int outData[];
  492. int outOff;
  493. int outSpan;
  494. public static ColorModel xrgbmodel =
  495. new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
  496. public static ColorModel argbmodel = ColorModel.getRGBdefault();
  497. public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm,
  498. AffineTransform xform, int maxw)
  499. {
  500. super((cm.getTransparency() == Transparency.OPAQUE
  501. ? xrgbmodel : argbmodel),
  502. xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
  503. this.inPalette = new int[256];
  504. ((IndexColorModel) cm).getRGBs(this.inPalette);
  505. this.srcRas = srcRas;
  506. this.inData = srcRas.getDataStorage();
  507. this.inSpan = srcRas.getScanlineStride();
  508. this.inOff = srcRas.getDataOffset(0);
  509. }
  510. public WritableRaster makeRaster(int w, int h) {
  511. WritableRaster ras =
  512. colorModel.createCompatibleWritableRaster(w, h);
  513. IntegerInterleavedRaster iiRas = (IntegerInterleavedRaster) ras;
  514. outData = iiRas.getDataStorage();
  515. outSpan = iiRas.getScanlineStride();
  516. outOff = iiRas.getDataOffset(0);
  517. return ras;
  518. }
  519. public void setRaster(int x, int y, int xerr, int yerr,
  520. int w, int h, int bWidth, int bHeight,
  521. int colincx, int colincxerr,
  522. int colincy, int colincyerr,
  523. int rowincx, int rowincxerr,
  524. int rowincy, int rowincyerr) {
  525. byte[] inData = this.inData;
  526. int[] outData = this.outData;
  527. int out = outOff;
  528. int inSpan = this.inSpan;
  529. int inOff = this.inOff;
  530. int outSpan = this.outSpan;
  531. int rowx = x;
  532. int rowy = y;
  533. int rowxerr = xerr;
  534. int rowyerr = yerr;
  535. int rgbs[] = new int[4];
  536. for (int j = 0; j < h; j++) {
  537. x = rowx;
  538. y = rowy;
  539. xerr = rowxerr;
  540. yerr = rowyerr;
  541. for (int i = 0; i < w; i++) {
  542. int nextx, nexty;
  543. if ((nextx = x + 1) >= bWidth) {
  544. nextx = 0;
  545. }
  546. if ((nexty = y + 1) >= bHeight) {
  547. nexty = 0;
  548. }
  549. rgbs[0] = inPalette[0xff & inData[inOff + x +
  550. inSpan * y]];
  551. rgbs[1] = inPalette[0xff & inData[inOff + nextx +
  552. inSpan * y]];
  553. rgbs[2] = inPalette[0xff & inData[inOff + x +
  554. inSpan * nexty]];
  555. rgbs[3] = inPalette[0xff & inData[inOff + nextx +
  556. inSpan * nexty]];
  557. outData[out + i] =
  558. TexturePaintContext.blend(rgbs, xerr, yerr);
  559. if ((xerr += colincxerr) < 0) {
  560. xerr &= Integer.MAX_VALUE;
  561. x++;
  562. }
  563. if ((x += colincx) >= bWidth) {
  564. x -= bWidth;
  565. }
  566. if ((yerr += colincyerr) < 0) {
  567. yerr &= Integer.MAX_VALUE;
  568. y++;
  569. }
  570. if ((y += colincy) >= bHeight) {
  571. y -= bHeight;
  572. }
  573. }
  574. if ((rowxerr += rowincxerr) < 0) {
  575. rowxerr &= Integer.MAX_VALUE;
  576. rowx++;
  577. }
  578. if ((rowx += rowincx) >= bWidth) {
  579. rowx -= bWidth;
  580. }
  581. if ((rowyerr += rowincyerr) < 0) {
  582. rowyerr &= Integer.MAX_VALUE;
  583. rowy++;
  584. }
  585. if ((rowy += rowincy) >= bHeight) {
  586. rowy -= bHeight;
  587. }
  588. out += outSpan;
  589. }
  590. }
  591. }
  592. static class Any extends TexturePaintContext {
  593. WritableRaster srcRas;
  594. boolean filter;
  595. public Any(WritableRaster srcRas, ColorModel cm,
  596. AffineTransform xform, int maxw, boolean filter)
  597. {
  598. super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
  599. this.srcRas = srcRas;
  600. this.filter = filter;
  601. }
  602. public WritableRaster makeRaster(int w, int h) {
  603. return srcRas.createCompatibleWritableRaster(w, h);
  604. }
  605. public void setRaster(int x, int y, int xerr, int yerr,
  606. int w, int h, int bWidth, int bHeight,
  607. int colincx, int colincxerr,
  608. int colincy, int colincyerr,
  609. int rowincx, int rowincxerr,
  610. int rowincy, int rowincyerr) {
  611. Object data = null;
  612. int rowx = x;
  613. int rowy = y;
  614. int rowxerr = xerr;
  615. int rowyerr = yerr;
  616. WritableRaster srcRas = this.srcRas;
  617. WritableRaster outRas = this.outRas;
  618. int rgbs[] = filter ? new int[4] : null;
  619. for (int j = 0; j < h; j++) {
  620. x = rowx;
  621. y = rowy;
  622. xerr = rowxerr;
  623. yerr = rowyerr;
  624. for (int i = 0; i < w; i++) {
  625. data = srcRas.getDataElements(x, y, data);
  626. if (filter) {
  627. int nextx, nexty;
  628. if ((nextx = x + 1) >= bWidth) {
  629. nextx = 0;
  630. }
  631. if ((nexty = y + 1) >= bHeight) {
  632. nexty = 0;
  633. }
  634. rgbs[0] = colorModel.getRGB(data);
  635. data = srcRas.getDataElements(nextx, y, data);
  636. rgbs[1] = colorModel.getRGB(data);
  637. data = srcRas.getDataElements(x, nexty, data);
  638. rgbs[2] = colorModel.getRGB(data);
  639. data = srcRas.getDataElements(nextx, nexty, data);
  640. rgbs[3] = colorModel.getRGB(data);
  641. int rgb =
  642. TexturePaintContext.blend(rgbs, xerr, yerr);
  643. data = colorModel.getDataElements(rgb, data);
  644. }
  645. outRas.setDataElements(i, j, data);
  646. if ((xerr += colincxerr) < 0) {
  647. xerr &= Integer.MAX_VALUE;
  648. x++;
  649. }
  650. if ((x += colincx) >= bWidth) {
  651. x -= bWidth;
  652. }
  653. if ((yerr += colincyerr) < 0) {
  654. yerr &= Integer.MAX_VALUE;
  655. y++;
  656. }
  657. if ((y += colincy) >= bHeight) {
  658. y -= bHeight;
  659. }
  660. }
  661. if ((rowxerr += rowincxerr) < 0) {
  662. rowxerr &= Integer.MAX_VALUE;
  663. rowx++;
  664. }
  665. if ((rowx += rowincx) >= bWidth) {
  666. rowx -= bWidth;
  667. }
  668. if ((rowyerr += rowincyerr) < 0) {
  669. rowyerr &= Integer.MAX_VALUE;
  670. rowy++;
  671. }
  672. if ((rowy += rowincy) >= bHeight) {
  673. rowy -= bHeight;
  674. }
  675. }
  676. }
  677. }
  678. }