0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: /**
0018: * @author Igor V. Stolyarov
0019: * @version $Revision$
0020: */package org.apache.harmony.awt.gl.render;
0021:
0022: import java.awt.AlphaComposite;
0023: import java.awt.Color;
0024: import java.awt.Graphics2D;
0025: import java.awt.Point;
0026: import java.awt.Rectangle;
0027: import java.awt.Transparency;
0028: import java.awt.color.ColorSpace;
0029: import java.awt.geom.AffineTransform;
0030: import java.awt.image.BufferedImage;
0031: import java.awt.image.ColorModel;
0032: import java.awt.image.ComponentColorModel;
0033: import java.awt.image.ComponentSampleModel;
0034: import java.awt.image.DataBuffer;
0035: import java.awt.image.DataBufferFloat;
0036: import java.awt.image.WritableRaster;
0037:
0038: import org.apache.harmony.awt.gl.MultiRectArea;
0039: import org.apache.harmony.awt.gl.image.OrdinaryWritableRaster;
0040:
0041: import junit.framework.TestCase;
0042:
0043: public class JavaBlitterTest extends TestCase {
0044: int w, h;
0045: BufferedImage src, dst;
0046:
0047: public JavaBlitterTest(String name) {
0048: super (name);
0049: }
0050:
0051: @Override
0052: protected void setUp() throws Exception {
0053: super .setUp();
0054: w = 100;
0055: h = 100;
0056: }
0057:
0058: private BufferedImage createImage(int imageType) {
0059: BufferedImage bi = new BufferedImage(w, h, imageType);
0060: Graphics2D g2d = bi.createGraphics();
0061: g2d.setColor(Color.red);
0062: g2d.fillRect(0, 0, 50, 50);
0063: g2d.setColor(Color.green);
0064: g2d.fillRect(50, 0, 50, 50);
0065: g2d.setColor(Color.blue);
0066: g2d.fillRect(0, 50, 50, 50);
0067: g2d.setColor(Color.white);
0068: g2d.fillRect(50, 50, 50, 50);
0069: return bi;
0070: }
0071:
0072: // PART I. Different Color Models with sRGB Color Space
0073: // Blitting from Direct Color Model to Direct Color Model (INT RGB)
0074: public final void test_from_INT_RGB_to_INT_ARGB() {
0075: src = createImage(BufferedImage.TYPE_INT_RGB);
0076: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
0077: Graphics2D g2d = dst.createGraphics();
0078: g2d.drawImage(src, 0, 0, null);
0079:
0080: for (int y = 0; y < h; y++) {
0081: for (int x = 0; x < w; x++) {
0082: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0083: }
0084: }
0085: }
0086:
0087: public final void test_from_INT_RGB_to_INT_ARGB_PRE() {
0088: src = createImage(BufferedImage.TYPE_INT_RGB);
0089: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
0090: Graphics2D g2d = dst.createGraphics();
0091: g2d.drawImage(src, 0, 0, null);
0092:
0093: for (int y = 0; y < h; y++) {
0094: for (int x = 0; x < w; x++) {
0095: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0096: }
0097: }
0098: }
0099:
0100: public final void test_from_INT_RGB_to_INT_RGB() {
0101: src = createImage(BufferedImage.TYPE_INT_RGB);
0102: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
0103: Graphics2D g2d = dst.createGraphics();
0104: g2d.drawImage(src, 0, 0, null);
0105:
0106: for (int y = 0; y < h; y++) {
0107: for (int x = 0; x < w; x++) {
0108: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0109: }
0110: }
0111: }
0112:
0113: // Blitting from Direct Color Model to Direct Color Model (INT BGR)
0114: public final void test_from_INT_RGB_to_INT_BGR() {
0115: src = createImage(BufferedImage.TYPE_INT_RGB);
0116: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0117: Graphics2D g2d = dst.createGraphics();
0118: g2d.drawImage(src, 0, 0, null);
0119:
0120: for (int y = 0; y < h; y++) {
0121: for (int x = 0; x < w; x++) {
0122: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0123: }
0124: }
0125: }
0126:
0127: // Blitting from Direct Color Model to Component Color Model (BYTE RGB)
0128: public final void test_from_INT_RGB_to_3BYTE_BGR() {
0129: src = createImage(BufferedImage.TYPE_INT_RGB);
0130: dst = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
0131: Graphics2D g2d = dst.createGraphics();
0132: g2d.drawImage(src, 0, 0, null);
0133:
0134: for (int y = 0; y < h; y++) {
0135: for (int x = 0; x < w; x++) {
0136: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0137: }
0138: }
0139: }
0140:
0141: public final void test_from_INT_RGB_to_4BYTE_ABGR() {
0142: src = createImage(BufferedImage.TYPE_INT_RGB);
0143: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
0144: Graphics2D g2d = dst.createGraphics();
0145: g2d.drawImage(src, 0, 0, null);
0146:
0147: for (int y = 0; y < h; y++) {
0148: for (int x = 0; x < w; x++) {
0149: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0150: }
0151: }
0152: }
0153:
0154: public final void test_from_INT_RGB_to_4BYTE_ABGR_PRE() {
0155: src = createImage(BufferedImage.TYPE_INT_RGB);
0156: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR_PRE);
0157: Graphics2D g2d = dst.createGraphics();
0158: g2d.drawImage(src, 0, 0, null);
0159:
0160: for (int y = 0; y < h; y++) {
0161: for (int x = 0; x < w; x++) {
0162: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0163: }
0164: }
0165: }
0166:
0167: // Blitting from Direct Color Model to Direct ColorModel (USHORT RGB)
0168: public final void test_from_INT_RGB_to_USHORT_555_RGB() {
0169: src = createImage(BufferedImage.TYPE_INT_RGB);
0170: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_555_RGB);
0171: Graphics2D g2d = dst.createGraphics();
0172: g2d.drawImage(src, 0, 0, null);
0173:
0174: for (int y = 0; y < h; y++) {
0175: for (int x = 0; x < w; x++) {
0176: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0177: }
0178: }
0179: }
0180:
0181: public final void test_from_INT_RGB_to_USHORT_565_RGB() {
0182: src = createImage(BufferedImage.TYPE_INT_RGB);
0183: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_565_RGB);
0184: Graphics2D g2d = dst.createGraphics();
0185: g2d.drawImage(src, 0, 0, null);
0186:
0187: for (int y = 0; y < h; y++) {
0188: for (int x = 0; x < w; x++) {
0189: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0190: }
0191: }
0192: }
0193:
0194: // Blitting from Direct Color Model to Index Color Model (Map size - 256)
0195: public final void test_from_INT_RGB_to_BYTE_INDEXED() {
0196: src = createImage(BufferedImage.TYPE_INT_RGB);
0197: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED);
0198: Graphics2D g2d = dst.createGraphics();
0199: g2d.drawImage(src, 0, 0, null);
0200:
0201: for (int y = 0; y < h; y++) {
0202: for (int x = 0; x < w; x++) {
0203: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0204: }
0205: }
0206: }
0207:
0208: // Blitting from Direct Color Model to Index Color Model (Map size - 2)
0209: public final void test_from_INT_RGB_to_BYTE_BINARY() {
0210: src = createImage(BufferedImage.TYPE_INT_RGB);
0211: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
0212: Graphics2D g2d = dst.createGraphics();
0213: g2d.drawImage(src, 0, 0, null);
0214:
0215: for (int y = 0; y < h / 2; y++) {
0216: for (int x = 0; x < w / 2; x++) {
0217: assertEquals(0xff000000, dst.getRGB(x, y));
0218: }
0219: }
0220: for (int y = 0; y < h / 2; y++) {
0221: for (int x = w / 2; x < w; x++) {
0222: assertEquals(0xffffffff, dst.getRGB(x, y));
0223: }
0224: }
0225: for (int y = h / 2; y < h; y++) {
0226: for (int x = 0; x < w / 2; x++) {
0227: assertEquals(0xff000000, dst.getRGB(x, y));
0228: }
0229: }
0230: for (int y = h / 2; y < h; y++) {
0231: for (int x = w / 2; x < w; x++) {
0232: assertEquals(0xffffffff, dst.getRGB(x, y));
0233: }
0234: }
0235: }
0236:
0237: // Blitting from Component Color Model to Direct Color Model (INT RGB)
0238: public final void test_from_3BYTE_BGR_to_INT_ARGB() {
0239: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0240: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
0241: Graphics2D g2d = dst.createGraphics();
0242: g2d.drawImage(src, 0, 0, null);
0243:
0244: for (int y = 0; y < h; y++) {
0245: for (int x = 0; x < w; x++) {
0246: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0247: }
0248: }
0249: }
0250:
0251: public final void test_from_3BYTE_BGR_to_INT_ARGB_PRE() {
0252: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0253: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
0254: Graphics2D g2d = dst.createGraphics();
0255: g2d.drawImage(src, 0, 0, null);
0256:
0257: for (int y = 0; y < h; y++) {
0258: for (int x = 0; x < w; x++) {
0259: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0260: }
0261: }
0262: }
0263:
0264: public final void test_from_3BYTE_BGR_to_INT_RGB() {
0265: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0266: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
0267: Graphics2D g2d = dst.createGraphics();
0268: g2d.drawImage(src, 0, 0, null);
0269:
0270: for (int y = 0; y < h; y++) {
0271: for (int x = 0; x < w; x++) {
0272: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0273: }
0274: }
0275: }
0276:
0277: public final void test_from_3BYTE_BGR_to_INT_BGR() {
0278: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0279: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0280: Graphics2D g2d = dst.createGraphics();
0281: g2d.drawImage(src, 0, 0, null);
0282:
0283: for (int y = 0; y < h; y++) {
0284: for (int x = 0; x < w; x++) {
0285: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0286: }
0287: }
0288: }
0289:
0290: // Blitting from Component Color Model to Direct Color Model (INT BGR)
0291: public final void test_from_3BYTE_BGR_to_3BYTE_BGR() {
0292: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0293: dst = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
0294: Graphics2D g2d = dst.createGraphics();
0295: g2d.drawImage(src, 0, 0, null);
0296:
0297: for (int y = 0; y < h; y++) {
0298: for (int x = 0; x < w; x++) {
0299: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0300: }
0301: }
0302: }
0303:
0304: // Blitting from Component Color Model to Component Color Model (BYTE RGB)
0305: public final void test_from_3BYTE_BGR_to_4BYTE_ABGR() {
0306: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0307: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
0308: Graphics2D g2d = dst.createGraphics();
0309: g2d.drawImage(src, 0, 0, null);
0310:
0311: for (int y = 0; y < h; y++) {
0312: for (int x = 0; x < w; x++) {
0313: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0314: }
0315: }
0316: }
0317:
0318: public final void test_from_3BYTE_BGR_to_4BYTE_ABGR_PRE() {
0319: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0320: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR_PRE);
0321: Graphics2D g2d = dst.createGraphics();
0322: g2d.drawImage(src, 0, 0, null);
0323:
0324: for (int y = 0; y < h; y++) {
0325: for (int x = 0; x < w; x++) {
0326: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0327: }
0328: }
0329: }
0330:
0331: // Blitting from Component Color Model to Direct Color Model (USHORT RGB)
0332: public final void test_from_3BYTE_BGR_to_USHORT_555_RGB() {
0333: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0334: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_555_RGB);
0335: Graphics2D g2d = dst.createGraphics();
0336: g2d.drawImage(src, 0, 0, null);
0337:
0338: for (int y = 0; y < h; y++) {
0339: for (int x = 0; x < w; x++) {
0340: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0341: }
0342: }
0343: }
0344:
0345: public final void test_from_3BYTE_BGR_to_USHORT_565_RGB() {
0346: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0347: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_565_RGB);
0348: Graphics2D g2d = dst.createGraphics();
0349: g2d.drawImage(src, 0, 0, null);
0350:
0351: for (int y = 0; y < h; y++) {
0352: for (int x = 0; x < w; x++) {
0353: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0354: }
0355: }
0356: }
0357:
0358: // Blitting from Component Color Model to Index Color Model (Map size - 256)
0359: public final void test_from_3BYTE_BGR_to_BYTE_INDEXED() {
0360: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0361: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED);
0362: Graphics2D g2d = dst.createGraphics();
0363: g2d.drawImage(src, 0, 0, null);
0364:
0365: for (int y = 0; y < h; y++) {
0366: for (int x = 0; x < w; x++) {
0367: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0368: }
0369: }
0370: }
0371:
0372: // Blitting from Component Color Model to Index Color Model (Map size - 2)
0373: public final void test_from_3BYTE_BGR_to_BYTE_BINARY() {
0374: src = createImage(BufferedImage.TYPE_3BYTE_BGR);
0375: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
0376: Graphics2D g2d = dst.createGraphics();
0377: g2d.drawImage(src, 0, 0, null);
0378:
0379: for (int y = 0; y < h / 2; y++) {
0380: for (int x = 0; x < w / 2; x++) {
0381: assertEquals(0xff000000, dst.getRGB(x, y));
0382: }
0383: }
0384: for (int y = 0; y < h / 2; y++) {
0385: for (int x = w / 2; x < w; x++) {
0386: assertEquals(0xffffffff, dst.getRGB(x, y));
0387: }
0388: }
0389: for (int y = h / 2; y < h; y++) {
0390: for (int x = 0; x < w / 2; x++) {
0391: assertEquals(0xff000000, dst.getRGB(x, y));
0392: }
0393: }
0394: for (int y = h / 2; y < h; y++) {
0395: for (int x = w / 2; x < w; x++) {
0396: assertEquals(0xffffffff, dst.getRGB(x, y));
0397: }
0398: }
0399: }
0400:
0401: // Blitting from Index Color Model to Direct Color Model (INT RGB)
0402: public final void test_from_BYTE_INDEXED_to_INT_ARGB() {
0403: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0404: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
0405: Graphics2D g2d = dst.createGraphics();
0406: g2d.drawImage(src, 0, 0, null);
0407:
0408: for (int y = 0; y < h; y++) {
0409: for (int x = 0; x < w; x++) {
0410: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0411: }
0412: }
0413: }
0414:
0415: public final void test_from_BYTE_INDEXED_to_INT_ARGB_PRE() {
0416: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0417: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
0418: Graphics2D g2d = dst.createGraphics();
0419: g2d.drawImage(src, 0, 0, null);
0420:
0421: for (int y = 0; y < h; y++) {
0422: for (int x = 0; x < w; x++) {
0423: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0424: }
0425: }
0426: }
0427:
0428: public final void test_from_BYTE_INDEXEDR_to_INT_RGB() {
0429: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0430: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
0431: Graphics2D g2d = dst.createGraphics();
0432: g2d.drawImage(src, 0, 0, null);
0433:
0434: for (int y = 0; y < h; y++) {
0435: for (int x = 0; x < w; x++) {
0436: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0437: }
0438: }
0439: }
0440:
0441: // Blitting from Index Color Model to Direct Color Model (INT BGR)
0442: public final void test_from_BYTE_INDEXED_to_INT_BGR() {
0443: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0444: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0445: Graphics2D g2d = dst.createGraphics();
0446: g2d.drawImage(src, 0, 0, null);
0447:
0448: for (int y = 0; y < h; y++) {
0449: for (int x = 0; x < w; x++) {
0450: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0451: }
0452: }
0453: }
0454:
0455: // Blitting from Index Color Model to Component Color Model (BYTE RGB)
0456: public final void test_from_BYTE_INDEXED_to_3BYTE_BGR() {
0457: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0458: dst = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
0459: Graphics2D g2d = dst.createGraphics();
0460: g2d.drawImage(src, 0, 0, null);
0461:
0462: for (int y = 0; y < h; y++) {
0463: for (int x = 0; x < w; x++) {
0464: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0465: }
0466: }
0467: }
0468:
0469: public final void test_from_BYTE_INDEXED_to_4BYTE_ABGR() {
0470: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0471: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
0472: Graphics2D g2d = dst.createGraphics();
0473: g2d.drawImage(src, 0, 0, null);
0474:
0475: for (int y = 0; y < h; y++) {
0476: for (int x = 0; x < w; x++) {
0477: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0478: }
0479: }
0480: }
0481:
0482: public final void test_from_BYTE_INDEXED_to_4BYTE_ABGR_PRE() {
0483: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0484: dst = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR_PRE);
0485: Graphics2D g2d = dst.createGraphics();
0486: g2d.drawImage(src, 0, 0, null);
0487:
0488: for (int y = 0; y < h; y++) {
0489: for (int x = 0; x < w; x++) {
0490: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0491: }
0492: }
0493: }
0494:
0495: // Blitting from Index Color Model to Direct Color Model (USHORT RGB)
0496: public final void test_from_BYTE_INDEXED_to_USHORT_555_RGB() {
0497: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0498: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_555_RGB);
0499: Graphics2D g2d = dst.createGraphics();
0500: g2d.drawImage(src, 0, 0, null);
0501:
0502: for (int y = 0; y < h; y++) {
0503: for (int x = 0; x < w; x++) {
0504: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0505: }
0506: }
0507: }
0508:
0509: public final void test_from_BYTE_INDEXED_to_USHORT_565_RGB() {
0510: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0511: dst = new BufferedImage(w, h, BufferedImage.TYPE_USHORT_565_RGB);
0512: Graphics2D g2d = dst.createGraphics();
0513: g2d.drawImage(src, 0, 0, null);
0514:
0515: for (int y = 0; y < h; y++) {
0516: for (int x = 0; x < w; x++) {
0517: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0518: }
0519: }
0520: }
0521:
0522: // Blitting from Index Color Model to Index Color Model (Map size - 256)
0523: public final void test_from_BYTE_INDEXED_to_BYTE_INDEXED() {
0524: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0525: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED);
0526: Graphics2D g2d = dst.createGraphics();
0527: g2d.drawImage(src, 0, 0, null);
0528:
0529: for (int y = 0; y < h; y++) {
0530: for (int x = 0; x < w; x++) {
0531: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0532: }
0533: }
0534: }
0535:
0536: // Blitting from Index Color Model to Index Color Model (Map size - 2)
0537: public final void test_from_BYTE_INDEXED_to_BYTE_BINARY() {
0538: src = createImage(BufferedImage.TYPE_BYTE_INDEXED);
0539: dst = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);
0540: Graphics2D g2d = dst.createGraphics();
0541: g2d.drawImage(src, 0, 0, null);
0542:
0543: for (int y = 0; y < h / 2; y++) {
0544: for (int x = 0; x < w / 2; x++) {
0545: assertEquals(0xff000000, dst.getRGB(x, y));
0546: }
0547: }
0548: for (int y = 0; y < h / 2; y++) {
0549: for (int x = w / 2; x < w; x++) {
0550: assertEquals(0xffffffff, dst.getRGB(x, y));
0551: }
0552: }
0553: for (int y = h / 2; y < h; y++) {
0554: for (int x = 0; x < w / 2; x++) {
0555: assertEquals(0xff000000, dst.getRGB(x, y));
0556: }
0557: }
0558: for (int y = h / 2; y < h; y++) {
0559: for (int x = w / 2; x < w; x++) {
0560: assertEquals(0xffffffff, dst.getRGB(x, y));
0561: }
0562: }
0563: }
0564:
0565: // PART II. Blitting to Different Rasters and Data Buffers
0566:
0567: // Blitting from Buffered Image (INT RGB) to Custom Raster
0568: // (Float Data Buffer)
0569: public final void test_from_BuffImg_to_FloatDataBuffer() {
0570: src = createImage(BufferedImage.TYPE_INT_RGB);
0571:
0572: DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
0573: int offsets[] = new int[] { 0, 1, 2 };
0574: ComponentSampleModel csm = new ComponentSampleModel(
0575: DataBuffer.TYPE_FLOAT, w, h, 3, 3 * w, offsets);
0576: WritableRaster wr = new OrdinaryWritableRaster(csm, dbf,
0577: new Point(0, 0));
0578: ColorModel cm = new ComponentColorModel(ColorSpace
0579: .getInstance(ColorSpace.CS_sRGB), false, false,
0580: Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
0581: BufferedImage dst = new BufferedImage(cm, wr, cm
0582: .isAlphaPremultiplied(), null);
0583: Graphics2D g2d = dst.createGraphics();
0584: g2d.drawImage(src, 0, 0, null);
0585:
0586: for (int y = 0; y < h; y++) {
0587: for (int x = 0; x < w; x++) {
0588: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
0589: }
0590: }
0591: }
0592:
0593: // PART III. Affine Tranformation (Translate only) and various destination
0594: // coordinates.
0595: // Destination coordinates test (X coordinate changing)
0596: public final void test_Dest_Coordinates_X() {
0597: src = createImage(BufferedImage.TYPE_INT_BGR);
0598: for (int i = -w; i < w; i++) {
0599: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0600: Graphics2D g2d = dst.createGraphics();
0601: g2d.drawImage(src, i, 0, null);
0602:
0603: for (int y = 0; y < h / 2; y++) {
0604: for (int x = 0; x < w / 2; x++) {
0605: if (i + w <= 0) {
0606: assertEquals(0xff000000, dst.getRGB(x, y));
0607: } else if (i + w < w / 2) {
0608: if (x < w + i) {
0609: assertEquals(0xff00ff00, dst.getRGB(x, y));
0610: } else {
0611: assertEquals(0xff000000, dst.getRGB(x, y));
0612: }
0613: } else if (i + w < w) {
0614: if (x < i + w / 2) {
0615: assertEquals(0xffff0000, dst.getRGB(x, y));
0616: } else {
0617: assertEquals(0xff00ff00, dst.getRGB(x, y));
0618: }
0619: } else {
0620: if (x < i) {
0621: assertEquals(0xff000000, dst.getRGB(x, y));
0622: } else {
0623: assertEquals(0xffff0000, dst.getRGB(x, y));
0624: }
0625: }
0626: }
0627: }
0628: for (int y = 0; y < h / 2; y++) {
0629: for (int x = w / 2; x < w; x++) {
0630: if (i + w < w / 2) {
0631: assertEquals(0xff000000, dst.getRGB(x, y));
0632: } else if (i + w < w) {
0633: if (x < w + i) {
0634: assertEquals(0xff00ff00, dst.getRGB(x, y));
0635: } else {
0636: assertEquals(0xff000000, dst.getRGB(x, y));
0637: }
0638: } else if (i < w / 2) {
0639: if (x < i + w / 2) {
0640: assertEquals(0xffff0000, dst.getRGB(x, y));
0641: } else {
0642: assertEquals(0xff00ff00, dst.getRGB(x, y));
0643: }
0644: } else {
0645: if (x < i) {
0646: assertEquals(0xff000000, dst.getRGB(x, y));
0647: } else {
0648: assertEquals(0xffff0000, dst.getRGB(x, y));
0649: }
0650: }
0651: }
0652: }
0653: for (int y = h / 2; y < h; y++) {
0654: for (int x = 0; x < w / 2; x++) {
0655: if (i + w <= 0) {
0656: assertEquals(0xff000000, dst.getRGB(x, y));
0657: } else if (i + w < w / 2) {
0658: if (x < w + i) {
0659: assertEquals(0xffffffff, dst.getRGB(x, y));
0660: } else {
0661: assertEquals(0xff000000, dst.getRGB(x, y));
0662: }
0663: } else if (i + w < w) {
0664: if (x < i + w / 2) {
0665: assertEquals(0xff0000ff, dst.getRGB(x, y));
0666: } else {
0667: assertEquals(0xffffffff, dst.getRGB(x, y));
0668: }
0669: } else {
0670: if (x < i) {
0671: assertEquals(0xff000000, dst.getRGB(x, y));
0672: } else {
0673: assertEquals(0xff0000ff, dst.getRGB(x, y));
0674: }
0675: }
0676: }
0677: }
0678: for (int y = h / 2; y < h; y++) {
0679: for (int x = w / 2; x < w; x++) {
0680: if (i + w < w / 2) {
0681: assertEquals(0xff000000, dst.getRGB(x, y));
0682: } else if (i + w < w) {
0683: if (x < w + i) {
0684: assertEquals(0xffffffff, dst.getRGB(x, y));
0685: } else {
0686: assertEquals(0xff000000, dst.getRGB(x, y));
0687: }
0688: } else if (i < w / 2) {
0689: if (x < i + w / 2) {
0690: assertEquals(0xff0000ff, dst.getRGB(x, y));
0691: } else {
0692: assertEquals(0xffffffff, dst.getRGB(x, y));
0693: }
0694: } else {
0695: if (x < i) {
0696: assertEquals(0xff000000, dst.getRGB(x, y));
0697: } else {
0698: assertEquals(0xff0000ff, dst.getRGB(x, y));
0699: }
0700: }
0701: }
0702: }
0703:
0704: }
0705: }
0706:
0707: // Destination coordinates test (Y coordinate changing)
0708: public final void test_Dest_Coordinates_Y() {
0709: src = createImage(BufferedImage.TYPE_INT_BGR);
0710: for (int i = -h; i < h; i++) {
0711: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0712: Graphics2D g2d = dst.createGraphics();
0713: g2d.drawImage(src, 0, i, null);
0714:
0715: for (int y = 0; y < h / 2; y++) {
0716: for (int x = 0; x < w / 2; x++) {
0717: if (i + h <= 0) {
0718: assertEquals(0xff000000, dst.getRGB(x, y));
0719: } else if (i + h < h / 2) {
0720: if (y < h + i) {
0721: assertEquals(0xff0000ff, dst.getRGB(x, y));
0722: } else {
0723: assertEquals(0xff000000, dst.getRGB(x, y));
0724: }
0725: } else if (i + h < h) {
0726: if (y < i + h / 2) {
0727: assertEquals(0xffff0000, dst.getRGB(x, y));
0728: } else {
0729: assertEquals(0xff0000ff, dst.getRGB(x, y));
0730: }
0731: } else {
0732: if (y < i) {
0733: assertEquals(0xff000000, dst.getRGB(x, y));
0734: } else {
0735: assertEquals(0xffff0000, dst.getRGB(x, y));
0736: }
0737: }
0738: }
0739: }
0740: for (int y = 0; y < h / 2; y++) {
0741: for (int x = w / 2; x < w; x++) {
0742: if (i + h <= 0) {
0743: assertEquals(0xff000000, dst.getRGB(x, y));
0744: } else if (i + h < h / 2) {
0745: if (y < h + i) {
0746: assertEquals(0xffffffff, dst.getRGB(x, y));
0747: } else {
0748: assertEquals(0xff000000, dst.getRGB(x, y));
0749: }
0750: } else if (i + h < h) {
0751: if (y < i + h / 2) {
0752: assertEquals(0xff00ff00, dst.getRGB(x, y));
0753: } else {
0754: assertEquals(0xffffffff, dst.getRGB(x, y));
0755: }
0756: } else {
0757: if (y < i) {
0758: assertEquals(0xff000000, dst.getRGB(x, y));
0759: } else {
0760: assertEquals(0xff00ff00, dst.getRGB(x, y));
0761: }
0762: }
0763: }
0764: }
0765: for (int y = h / 2; y < h; y++) {
0766: for (int x = 0; x < w / 2; x++) {
0767: if (i + h < h / 2) {
0768: assertEquals(0xff000000, dst.getRGB(x, y));
0769: } else if (i + h < h) {
0770: if (y < i + h) {
0771: assertEquals(0xff0000ff, dst.getRGB(x, y));
0772: } else {
0773: assertEquals(0xff000000, dst.getRGB(x, y));
0774: }
0775: } else if (i < h / 2) {
0776: if (y < i + h / 2) {
0777: assertEquals(0xffff0000, dst.getRGB(x, y));
0778: } else {
0779: assertEquals(0xff0000ff, dst.getRGB(x, y));
0780: }
0781: } else if (i < h) {
0782: if (y < i) {
0783: assertEquals(0xff000000, dst.getRGB(x, y));
0784: } else {
0785: assertEquals(0xffff0000, dst.getRGB(x, y));
0786: }
0787: } else {
0788: assertEquals(0xff000000, dst.getRGB(x, y));
0789: }
0790: }
0791: }
0792: for (int y = h / 2; y < h; y++) {
0793: for (int x = w / 2; x < w; x++) {
0794: if (i + h < h / 2) {
0795: assertEquals(0xff000000, dst.getRGB(x, y));
0796: } else if (i + h < h) {
0797: if (y < i + h) {
0798: assertEquals(0xffffffff, dst.getRGB(x, y));
0799: } else {
0800: assertEquals(0xff000000, dst.getRGB(x, y));
0801: }
0802: } else if (i < h / 2) {
0803: if (y < i + h / 2) {
0804: assertEquals(0xff00ff00, dst.getRGB(x, y));
0805: } else {
0806: assertEquals(0xffffffff, dst.getRGB(x, y));
0807: }
0808: } else if (i < h) {
0809: if (y < i) {
0810: assertEquals(0xff000000, dst.getRGB(x, y));
0811: } else {
0812: assertEquals(0xff00ff00, dst.getRGB(x, y));
0813: }
0814: } else {
0815: assertEquals(0xff000000, dst.getRGB(x, y));
0816: }
0817: }
0818: }
0819:
0820: }
0821: }
0822:
0823: // Affine transform test (X translate)
0824: public final void test_AffineTransform_X() {
0825: src = createImage(BufferedImage.TYPE_INT_BGR);
0826: for (int i = -w; i < w; i++) {
0827: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0828: Graphics2D g2d = dst.createGraphics();
0829: AffineTransform t = new AffineTransform();
0830: t.setToTranslation(i, 0);
0831: g2d.setTransform(t);
0832: g2d.drawImage(src, 0, 0, null);
0833:
0834: for (int y = 0; y < h / 2; y++) {
0835: for (int x = 0; x < w / 2; x++) {
0836: if (i + w <= 0) {
0837: assertEquals(0xff000000, dst.getRGB(x, y));
0838: } else if (i + w < w / 2) {
0839: if (x < w + i) {
0840: assertEquals(0xff00ff00, dst.getRGB(x, y));
0841: } else {
0842: assertEquals(0xff000000, dst.getRGB(x, y));
0843: }
0844: } else if (i + w < w) {
0845: if (x < i + w / 2) {
0846: assertEquals(0xffff0000, dst.getRGB(x, y));
0847: } else {
0848: assertEquals(0xff00ff00, dst.getRGB(x, y));
0849: }
0850: } else {
0851: if (x < i) {
0852: assertEquals(0xff000000, dst.getRGB(x, y));
0853: } else {
0854: assertEquals(0xffff0000, dst.getRGB(x, y));
0855: }
0856: }
0857: }
0858: }
0859: for (int y = 0; y < h / 2; y++) {
0860: for (int x = w / 2; x < w; x++) {
0861: if (i + w < w / 2) {
0862: assertEquals(0xff000000, dst.getRGB(x, y));
0863: } else if (i + w < w) {
0864: if (x < w + i) {
0865: assertEquals(0xff00ff00, dst.getRGB(x, y));
0866: } else {
0867: assertEquals(0xff000000, dst.getRGB(x, y));
0868: }
0869: } else if (i < w / 2) {
0870: if (x < i + w / 2) {
0871: assertEquals(0xffff0000, dst.getRGB(x, y));
0872: } else {
0873: assertEquals(0xff00ff00, dst.getRGB(x, y));
0874: }
0875: } else {
0876: if (x < i) {
0877: assertEquals(0xff000000, dst.getRGB(x, y));
0878: } else {
0879: assertEquals(0xffff0000, dst.getRGB(x, y));
0880: }
0881: }
0882: }
0883: }
0884: for (int y = h / 2; y < h; y++) {
0885: for (int x = 0; x < w / 2; x++) {
0886: if (i + w <= 0) {
0887: assertEquals(0xff000000, dst.getRGB(x, y));
0888: } else if (i + w < w / 2) {
0889: if (x < w + i) {
0890: assertEquals(0xffffffff, dst.getRGB(x, y));
0891: } else {
0892: assertEquals(0xff000000, dst.getRGB(x, y));
0893: }
0894: } else if (i + w < w) {
0895: if (x < i + w / 2) {
0896: assertEquals(0xff0000ff, dst.getRGB(x, y));
0897: } else {
0898: assertEquals(0xffffffff, dst.getRGB(x, y));
0899: }
0900: } else {
0901: if (x < i) {
0902: assertEquals(0xff000000, dst.getRGB(x, y));
0903: } else {
0904: assertEquals(0xff0000ff, dst.getRGB(x, y));
0905: }
0906: }
0907: }
0908: }
0909: for (int y = h / 2; y < h; y++) {
0910: for (int x = w / 2; x < w; x++) {
0911: if (i + w < w / 2) {
0912: assertEquals(0xff000000, dst.getRGB(x, y));
0913: } else if (i + w < w) {
0914: if (x < w + i) {
0915: assertEquals(0xffffffff, dst.getRGB(x, y));
0916: } else {
0917: assertEquals(0xff000000, dst.getRGB(x, y));
0918: }
0919: } else if (i < w / 2) {
0920: if (x < i + w / 2) {
0921: assertEquals(0xff0000ff, dst.getRGB(x, y));
0922: } else {
0923: assertEquals(0xffffffff, dst.getRGB(x, y));
0924: }
0925: } else {
0926: if (x < i) {
0927: assertEquals(0xff000000, dst.getRGB(x, y));
0928: } else {
0929: assertEquals(0xff0000ff, dst.getRGB(x, y));
0930: }
0931: }
0932: }
0933: }
0934:
0935: }
0936: }
0937:
0938: // Affine transform test (Y translate)
0939: public final void test_AffineTransform_Y() {
0940: src = createImage(BufferedImage.TYPE_INT_BGR);
0941: for (int i = -h; i < h; i++) {
0942: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
0943: Graphics2D g2d = dst.createGraphics();
0944: AffineTransform t = new AffineTransform();
0945: t.setToTranslation(0, i);
0946: g2d.setTransform(t);
0947: g2d.drawImage(src, 0, 0, null);
0948:
0949: for (int y = 0; y < h / 2; y++) {
0950: for (int x = 0; x < w / 2; x++) {
0951: if (i + h <= 0) {
0952: assertEquals(0xff000000, dst.getRGB(x, y));
0953: } else if (i + h < h / 2) {
0954: if (y < h + i) {
0955: assertEquals(0xff0000ff, dst.getRGB(x, y));
0956: } else {
0957: assertEquals(0xff000000, dst.getRGB(x, y));
0958: }
0959: } else if (i + h < h) {
0960: if (y < i + h / 2) {
0961: assertEquals(0xffff0000, dst.getRGB(x, y));
0962: } else {
0963: assertEquals(0xff0000ff, dst.getRGB(x, y));
0964: }
0965: } else {
0966: if (y < i) {
0967: assertEquals(0xff000000, dst.getRGB(x, y));
0968: } else {
0969: assertEquals(0xffff0000, dst.getRGB(x, y));
0970: }
0971: }
0972: }
0973: }
0974: for (int y = 0; y < h / 2; y++) {
0975: for (int x = w / 2; x < w; x++) {
0976: if (i + h <= 0) {
0977: assertEquals(0xff000000, dst.getRGB(x, y));
0978: } else if (i + h < h / 2) {
0979: if (y < h + i) {
0980: assertEquals(0xffffffff, dst.getRGB(x, y));
0981: } else {
0982: assertEquals(0xff000000, dst.getRGB(x, y));
0983: }
0984: } else if (i + h < h) {
0985: if (y < i + h / 2) {
0986: assertEquals(0xff00ff00, dst.getRGB(x, y));
0987: } else {
0988: assertEquals(0xffffffff, dst.getRGB(x, y));
0989: }
0990: } else {
0991: if (y < i) {
0992: assertEquals(0xff000000, dst.getRGB(x, y));
0993: } else {
0994: assertEquals(0xff00ff00, dst.getRGB(x, y));
0995: }
0996: }
0997: }
0998: }
0999: for (int y = h / 2; y < h; y++) {
1000: for (int x = 0; x < w / 2; x++) {
1001: if (i + h < h / 2) {
1002: assertEquals(0xff000000, dst.getRGB(x, y));
1003: } else if (i + h < h) {
1004: if (y < i + h) {
1005: assertEquals(0xff0000ff, dst.getRGB(x, y));
1006: } else {
1007: assertEquals(0xff000000, dst.getRGB(x, y));
1008: }
1009: } else if (i < h / 2) {
1010: if (y < i + h / 2) {
1011: assertEquals(0xffff0000, dst.getRGB(x, y));
1012: } else {
1013: assertEquals(0xff0000ff, dst.getRGB(x, y));
1014: }
1015: } else if (i < h) {
1016: if (y < i) {
1017: assertEquals(0xff000000, dst.getRGB(x, y));
1018: } else {
1019: assertEquals(0xffff0000, dst.getRGB(x, y));
1020: }
1021: } else {
1022: assertEquals(0xff000000, dst.getRGB(x, y));
1023: }
1024: }
1025: }
1026: for (int y = h / 2; y < h; y++) {
1027: for (int x = w / 2; x < w; x++) {
1028: if (i + h < h / 2) {
1029: assertEquals(0xff000000, dst.getRGB(x, y));
1030: } else if (i + h < h) {
1031: if (y < i + h) {
1032: assertEquals(0xffffffff, dst.getRGB(x, y));
1033: } else {
1034: assertEquals(0xff000000, dst.getRGB(x, y));
1035: }
1036: } else if (i < h / 2) {
1037: if (y < i + h / 2) {
1038: assertEquals(0xff00ff00, dst.getRGB(x, y));
1039: } else {
1040: assertEquals(0xffffffff, dst.getRGB(x, y));
1041: }
1042: } else if (i < h) {
1043: if (y < i) {
1044: assertEquals(0xff000000, dst.getRGB(x, y));
1045: } else {
1046: assertEquals(0xff00ff00, dst.getRGB(x, y));
1047: }
1048: } else {
1049: assertEquals(0xff000000, dst.getRGB(x, y));
1050: }
1051: }
1052: }
1053:
1054: }
1055: }
1056:
1057: // PART IV. Clipping
1058: // Null Clipping test
1059: public final void test_NullClipping() {
1060: src = createImage(BufferedImage.TYPE_INT_BGR);
1061: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1062: Graphics2D g2d = dst.createGraphics();
1063: g2d.setClip(null);
1064: g2d.drawImage(src, 0, 0, null);
1065: for (int y = 0; y < h; y++) {
1066: for (int x = 0; x < w; x++) {
1067: assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
1068: }
1069: }
1070:
1071: }
1072:
1073: // One Rectangle Clipping test
1074: public final void test_OneRectangleClipping() {
1075: src = createImage(BufferedImage.TYPE_INT_BGR);
1076: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1077: Graphics2D g2d = dst.createGraphics();
1078: g2d.setClip(w / 4, h / 4, w / 2, h / 2);
1079: g2d.drawImage(src, 0, 0, null);
1080:
1081: for (int y = 0; y < h / 2; y++) {
1082: for (int x = 0; x < w / 2; x++) {
1083: if (x >= w / 4 && y >= h / 4) {
1084: assertEquals(0xffff0000, dst.getRGB(x, y));
1085: } else {
1086: assertEquals(0xff000000, dst.getRGB(x, y));
1087: }
1088: }
1089: }
1090: for (int y = 0; y < h / 2; y++) {
1091: for (int x = w / 2; x < w; x++) {
1092: if (x < w / 2 + w / 4 && y >= h / 4) {
1093: assertEquals(0xff00ff00, dst.getRGB(x, y));
1094: } else {
1095: assertEquals(0xff000000, dst.getRGB(x, y));
1096: }
1097: }
1098: }
1099: for (int y = h / 2; y < h; y++) {
1100: for (int x = 0; x < w / 2; x++) {
1101: if (x >= w / 4 && y < h / 2 + h / 4) {
1102: assertEquals(0xff0000ff, dst.getRGB(x, y));
1103: } else {
1104: assertEquals(0xff000000, dst.getRGB(x, y));
1105: }
1106: }
1107: }
1108: for (int y = h / 2; y < h; y++) {
1109: for (int x = w / 2; x < w; x++) {
1110: if (x < w / 2 + w / 4 && y < h / 2 + h / 4) {
1111: assertEquals(0xffffffff, dst.getRGB(x, y));
1112: } else {
1113: assertEquals(0xff000000, dst.getRGB(x, y));
1114: }
1115: }
1116: }
1117:
1118: }
1119:
1120: // Two Rectangles Clipping test
1121: public final void test_TwoRectanglesClipping() {
1122: src = createImage(BufferedImage.TYPE_INT_BGR);
1123: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1124: Graphics2D g2d = dst.createGraphics();
1125: Rectangle rec[] = new Rectangle[] {
1126: new Rectangle(w / 4, h / 4, w / 2, h / 2),
1127: new Rectangle(w / 4 + w / 2, h / 4 + h / 2, w / 2,
1128: h / 2) };
1129: MultiRectArea mra = new MultiRectArea(rec);
1130: g2d.setClip(mra);
1131: g2d.drawImage(src, 0, 0, null);
1132:
1133: for (int y = 0; y < h / 2; y++) {
1134: for (int x = 0; x < w / 2; x++) {
1135: if (x >= w / 4 && y >= h / 4) {
1136: assertEquals(0xffff0000, dst.getRGB(x, y));
1137: } else {
1138: assertEquals(0xff000000, dst.getRGB(x, y));
1139: }
1140: }
1141: }
1142: for (int y = 0; y < h / 2; y++) {
1143: for (int x = w / 2; x < w; x++) {
1144: if (x < w / 2 + w / 4 && y >= h / 4) {
1145: assertEquals(0xff00ff00, dst.getRGB(x, y));
1146: } else {
1147: assertEquals(0xff000000, dst.getRGB(x, y));
1148: }
1149: }
1150: }
1151: for (int y = h / 2; y < h; y++) {
1152: for (int x = 0; x < w / 2; x++) {
1153: if (x >= w / 4 && y < h / 2 + h / 4) {
1154: assertEquals(0xff0000ff, dst.getRGB(x, y));
1155: } else {
1156: assertEquals(0xff000000, dst.getRGB(x, y));
1157: }
1158: }
1159: }
1160: for (int y = h / 2; y < h; y++) {
1161: for (int x = w / 2; x < w; x++) {
1162: if (x < w / 2 + w / 4 && y < h / 2 + h / 4
1163: || x >= w / 2 + w / 4 && y >= h / 2 + h / 4) {
1164: assertEquals(0xffffffff, dst.getRGB(x, y));
1165: } else {
1166: assertEquals(0xff000000, dst.getRGB(x, y));
1167: }
1168: }
1169: }
1170:
1171: }
1172:
1173: // One Pixel Clipping test
1174: public final void test_OnePixelClipping() {
1175: src = createImage(BufferedImage.TYPE_INT_BGR);
1176: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1177: Graphics2D g2d = dst.createGraphics();
1178: g2d.setClip(w / 4, h / 4, 1, 1);
1179: g2d.drawImage(src, 0, 0, null);
1180:
1181: for (int y = 0; y < h; y++) {
1182: for (int x = 0; x < w; x++) {
1183: if (x == w / 4 && y == h / 4) {
1184: assertEquals(0xffff0000, dst.getRGB(x, y));
1185: } else {
1186: assertEquals(0xff000000, dst.getRGB(x, y));
1187: }
1188: }
1189: }
1190:
1191: }
1192:
1193: // Boundary Clipping test
1194: public final void test_BoundaryClipping() {
1195: src = createImage(BufferedImage.TYPE_INT_BGR);
1196: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1197: Graphics2D g2d = dst.createGraphics();
1198: g2d.setClip(-w, 0, w, h);
1199: g2d.drawImage(src, 0, 0, null);
1200:
1201: for (int y = 0; y < h; y++) {
1202: for (int x = 0; x < w; x++) {
1203: assertEquals(0xff000000, dst.getRGB(x, y));
1204: }
1205: }
1206:
1207: }
1208:
1209: // PART V. Alpha Composite
1210: // Default rule = SRC_OVER & alpha = 1.0f was tested above
1211: // Rule = SRC_OVER, Alpha = 0.5f
1212: public final void test_AlphaComposite_SRC_OVER_05() {
1213: src = createImage(BufferedImage.TYPE_INT_BGR);
1214: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1215: Graphics2D g2d = dst.createGraphics();
1216: AlphaComposite comp = AlphaComposite.getInstance(
1217: AlphaComposite.SRC_OVER, 0.5f);
1218: g2d.setComposite(comp);
1219: g2d.drawImage(src, 0, 0, null);
1220: for (int y = 0; y < h / 2; y++) {
1221: for (int x = 0; x < w / 2; x++) {
1222: assertEquals(0xff800000, dst.getRGB(x, y));
1223: }
1224: }
1225: for (int y = 0; y < h / 2; y++) {
1226: for (int x = w / 2; x < w; x++) {
1227: assertEquals(0xff008000, dst.getRGB(x, y));
1228: }
1229: }
1230: for (int y = h / 2; y < h; y++) {
1231: for (int x = 0; x < w / 2; x++) {
1232: assertEquals(0xff000080, dst.getRGB(x, y));
1233: }
1234: }
1235: for (int y = h / 2; y < h; y++) {
1236: for (int x = w / 2; x < w; x++) {
1237: assertEquals(0xff808080, dst.getRGB(x, y));
1238: }
1239: }
1240: }
1241:
1242: // Rule = DST, Alpha = 1.0f
1243: public final void test_AlphaComposite_DST_10() {
1244: src = createImage(BufferedImage.TYPE_INT_BGR);
1245: dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
1246: Graphics2D g2d = dst.createGraphics();
1247: AlphaComposite comp = AlphaComposite
1248: .getInstance(AlphaComposite.DST);
1249: g2d.setComposite(comp);
1250: g2d.drawImage(src, 0, 0, null);
1251: for (int y = 0; y < h; y++) {
1252: for (int x = 0; x < w; x++) {
1253: assertEquals(0xff000000, dst.getRGB(x, y));
1254: }
1255: }
1256: }
1257: }
|