// Set up pixel colors to check against int clippedPixelColor = clippedColor.getRGB(); int unclippedPixelColor = unclippedColor.getRGB(); int wrongPixelColor = clippedPixelColor; boolean insideClip = false; for (int row = 0; row < getHeight(); ++row) { for (int col = 0; col < getWidth(); ++col) { if (row >= clipY1 && row < (clipY1 + clipSize) &&
col >= clipX1 && col < (clipX1 + clipSize))
{ // Inside clip bounds - should not see unclipped color
wrongPixelColor = unclippedPixelColor;
} else { // Outside clip - should not see clipped color
wrongPixelColor = clippedPixelColor;
} int pixel = imageChecker.getRGB(col, row); if (pixel == wrongPixelColor) {
System.out.println("FAILED: pixel = " +
Integer.toHexString(pixel) + " at (x, y) = " + col + ", " + row); // Draw magenta rectangle around problem pixel in buffer // for visual feedback to user
g.setColor(Color.magenta);
g.drawRect(col - 1, row - 1, 2, 2);
error = true;
}
}
} return error;
}
/** *Drawalltestlinesandcheckforerrors(unlessrunning *with-dynamicoption)
*/ void drawLineGrid(Graphics screenGraphics, Graphics g) { // Fill buffer with background color
g.setColor(Color.white);
g.fillRect(0, 0, getWidth(), getHeight());
// Now, iterate through all quadrants for (int srcQuad = 0; srcQuad < NUM_QUADS; ++srcQuad) { // Draw lines to all other quadrants for (int dstQuad = 0; dstQuad < NUM_QUADS; ++dstQuad) { for (int srcPoint = 0;
srcPoint < quadrants[srcQuad].length;
++srcPoint)
{ // For every point in the source quadrant int sx = quadrants[srcQuad][srcPoint].x; int sy = quadrants[srcQuad][srcPoint].y; for (int dstPoint = 0;
dstPoint < quadrants[dstQuad].length;
++dstPoint)
{ int dx = quadrants[dstQuad][dstPoint].x; int dy = quadrants[dstQuad][dstPoint].y; if (!rectTest) { // Draw unclipped/clipped lines to every // point in the dst quadrant
g.setColor(unclippedColor);
g.drawLine(sx, sy, dx, dy);
g.setClip(clipX1, clipY1, clipSize, clipSize);
g.setColor(clippedColor);
g.drawLine(sx,sy, dx, dy);
} else { // Draw unclipped/clipped rectangles to every // point in the dst quadrant
g.setColor(unclippedColor); int w = dx - sx; int h = dy - sy;
g.drawRect(sx, sy, w, h);
g.setClip(clipX1, clipY1, clipSize, clipSize);
g.setColor(clippedColor);
g.drawRect(sx, sy, w, h);
}
g.setClip(null);
} if (!dynamic) { // Draw screen update for visual feedback
screenGraphics.drawImage(testImage, 0, 0, this); // On default test, check for errors after every // src point if (!quickTest && gridError(g)) { thrownew java.lang.RuntimeException("Failed");
}
}
}
} if (!dynamic && quickTest && gridError(g)) { // On quick test, check for errors only after every // src quadrant thrownew java.lang.RuntimeException("Failed"); //return;
}
} if (!dynamic) {
System.out.println("PASSED"); if (!keepRunning) {
f.dispose();
}
}
}
/* *Createthequadrantofpointsandrunthetesttodrawallthelines
*/ publicvoid runTest(Graphics screenGraphics) { if (getWidth() == 0 || getHeight() == 0) { // May get here before window is really ready return;
}
clipX1 = (getWidth() - clipSize) / 2;
clipY1 = (getHeight() - clipSize) / 2; int clipX2 = clipX1 + clipSize; int clipY2 = clipY1 + clipSize; int centerX = getWidth()/2; int centerY = getHeight()/2; int leftX = 0; int topY = 0; int rightX = getWidth() - 1; int bottomY = getHeight() - 1; int quadIndex = 0; // Offsets are used to force diagonal (versus hor/vert) lines int xOffset = 0; int yOffset = 0;
if (quadrants[0] == null) { for (int i = 0; i < 9; ++i) { int numPoints = (i == 4) ? 9 : 3;
quadrants[i] = new Point[numPoints];
}
} // Upper-left
quadrants[quadIndex] = new Point[] { new Point(leftX + xOffset, clipY1 - 1 - yOffset), new Point(leftX + xOffset, topY + yOffset), new Point(clipX1 - 1 - xOffset, topY + yOffset),
};
quadIndex++;
yOffset++; // Upper-middle
quadrants[quadIndex] = new Point[] { new Point(clipX1 + 1 + xOffset, topY + yOffset), new Point(centerX + xOffset, topY + yOffset), new Point(clipX2 - 1 - xOffset, topY + yOffset),
};
quadIndex++;
++yOffset; // Upper-right
quadrants[quadIndex] = new Point[] { new Point(clipX2 + 1 + xOffset, topY + yOffset), new Point(rightX - xOffset, topY + yOffset), new Point(rightX - xOffset, clipY1 - 1 - yOffset),
};
quadIndex++;
yOffset = 0;
++xOffset; // Middle-left
quadrants[quadIndex] = new Point[] { new Point(leftX + xOffset, clipY1 + 1 + yOffset), new Point(leftX + xOffset, centerY + yOffset), new Point(leftX + xOffset, clipY2 - 1 - yOffset),
};
quadIndex++;
++yOffset; // Middle-middle
quadrants[quadIndex] = new Point[] { new Point(clipX1 + 1 + xOffset, clipY1 + 1 + yOffset), new Point(centerX + xOffset, clipY1 + 1 + yOffset), new Point(clipX2 - 1 - xOffset, clipY1 + 1 + yOffset), new Point(clipX1 + 1 + xOffset, centerY + yOffset), new Point(centerX + xOffset, centerY + yOffset), new Point(clipX2 - 1 - xOffset, centerY + yOffset), new Point(clipX1 + 1 + xOffset, clipY2 - 1 - yOffset), new Point(centerX + xOffset, clipY2 - 1 - yOffset), new Point(clipX2 - 1 - xOffset, clipY2 - 1 - yOffset),
};
quadIndex++;
++yOffset; // Middle-right
quadrants[quadIndex] = new Point[] { new Point(rightX - xOffset, clipY1 + 1 + yOffset), new Point(rightX - xOffset, centerY + yOffset), new Point(rightX - xOffset, clipY2 - 1 - yOffset),
};
quadIndex++;
yOffset = 0;
++xOffset; // Lower-left
quadrants[quadIndex] = new Point[] { new Point(leftX + xOffset, clipY2 + 1 + yOffset), new Point(leftX + xOffset, bottomY - yOffset), new Point(clipX1 - 1 - xOffset, bottomY - yOffset),
};
quadIndex++;
++yOffset; // Lower-middle
quadrants[quadIndex] = new Point[] { new Point(clipX1 + 1 + xOffset, bottomY - yOffset), new Point(centerX + xOffset, bottomY - yOffset), new Point(clipX2 - 1 - xOffset, bottomY - yOffset),
};
quadIndex++;
++yOffset; // Lower-right
quadrants[quadIndex] = new Point[] { new Point(clipX2 + 1 + xOffset, bottomY - yOffset), new Point(rightX - xOffset, bottomY - yOffset), new Point(rightX - xOffset, clipY2 + 1 + yOffset),
};
if (testImage != null) {
testImage.flush();
}
testW = getWidth();
testH = getHeight();
testImage = createVolatileImage(testW, testH);
Graphics g = testImage.getGraphics(); do { int valCode = testImage.validate(getGraphicsConfiguration()); if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) {
testImage.flush();
testImage = createVolatileImage(testW, testH);
g = testImage.getGraphics();
}
drawLineGrid(screenGraphics, g);
} while (testImage.contentsLost()); if (dynamic) { // Draw clip box if dynamic
g.setClip(null);
g.setColor(Color.black);
g.drawRect(clipX1, clipY1, clipSize, clipSize);
screenGraphics.drawImage(testImage, 0, 0, this);
}
runTestDone = true;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.