FileDocCategorySizeDatePackage
TexturePaintContext.javaAPI DocJava SE 5 API22234Fri Aug 26 14:56:46 BST 2005java.awt

TexturePaintContext

public abstract class TexturePaintContext extends Object implements PaintContext

Fields Summary
public static ColorModel
xrgbmodel
public static ColorModel
argbmodel
ColorModel
colorModel
int
bWidth
int
bHeight
int
maxWidth
WritableRaster
outRas
double
xOrg
double
yOrg
double
incXAcross
double
incYAcross
double
incXDown
double
incYDown
int
colincx
int
colincy
int
colincxerr
int
colincyerr
int
rowincx
int
rowincy
int
rowincxerr
int
rowincyerr
private static WeakReference
xrgbRasRef
private static WeakReference
argbRasRef
private static WeakReference
byteRasRef
Constructors Summary
TexturePaintContext(ColorModel cm, AffineTransform xform, int bWidth, int bHeight, int maxw)

	this.colorModel = getInternedColorModel(cm);
	this.bWidth = bWidth;
	this.bHeight = bHeight;
	this.maxWidth = maxw;

	try {
	    xform = xform.createInverse();
        } catch (NoninvertibleTransformException e) {
	    xform.setToScale(0, 0);
	}
	this.incXAcross = mod(xform.getScaleX(), bWidth);
	this.incYAcross = mod(xform.getShearY(), bHeight);
	this.incXDown = mod(xform.getShearX(), bWidth);
	this.incYDown = mod(xform.getScaleY(), bHeight);
        this.xOrg = xform.getTranslateX();
        this.yOrg = xform.getTranslateY();
	this.colincx = (int) incXAcross;
	this.colincy = (int) incYAcross;
	this.colincxerr = fractAsInt(incXAcross);
	this.colincyerr = fractAsInt(incYAcross);
	this.rowincx = (int) incXDown;
	this.rowincy = (int) incYDown;
	this.rowincxerr = fractAsInt(incXDown);
	this.rowincyerr = fractAsInt(incYDown);

    
Methods Summary
public static intblend(int[] rgbs, int xmul, int ymul)

	// xmul/ymul are 31 bits wide, (0 => 2^31-1)
	// shift them to 12 bits wide, (0 => 2^12-1)
	xmul = (xmul >>> 19);
	ymul = (ymul >>> 19);
	int accumA, accumR, accumG, accumB;
	accumA = accumR = accumG = accumB = 0;
	for (int i = 0; i < 4; i++) {
	    int rgb = rgbs[i];
	    // The complement of the [xy]mul values (1-[xy]mul) can result
	    // in new values in the range (1 => 2^12).  Thus for any given
	    // loop iteration, the values could be anywhere in (0 => 2^12).
	    xmul = (1<<12) - xmul;
	    if ((i & 1) == 0) {
		ymul = (1<<12) - ymul;
	    }
	    // xmul and ymul are each 12 bits (0 => 2^12)
	    // factor is thus 24 bits (0 => 2^24)
	    int factor = xmul * ymul;
	    if (factor != 0) {
		// accum variables will accumulate 32 bits
		// bytes extracted from rgb fit in 8 bits (0 => 255)
		// byte * factor thus fits in 32 bits (0 => 255 * 2^24)
		accumA += (((rgb >>> 24)       ) * factor);
		accumR += (((rgb >>> 16) & 0xff) * factor);
		accumG += (((rgb >>>  8) & 0xff) * factor);
		accumB += (((rgb       ) & 0xff) * factor);
	    }
	}
	return ((((accumA + (1<<23)) >>> 24) << 24) |
		(((accumR + (1<<23)) >>> 24) << 16) |
		(((accumG + (1<<23)) >>> 24) <<  8) |
		(((accumB + (1<<23)) >>> 24)      ));
    
public voiddispose()
Release the resources allocated for the operation.

	dropRaster(colorModel, outRas);
    
static synchronized voiddropByteRaster(java.awt.image.Raster outRas)

	if (outRas == null) {
	    return;
	}
	byteRasRef = new WeakReference(outRas);
    
static synchronized voiddropRaster(java.awt.image.ColorModel cm, java.awt.image.Raster outRas)

	if (outRas == null) {
	    return;
	}
	if (xrgbmodel == cm) {
	    xrgbRasRef = new WeakReference(outRas);
	} else if (argbmodel == cm) {
	    argbRasRef = new WeakReference(outRas);
	}
    
static intfractAsInt(double d)

	return (int) ((d % 1.0) * Integer.MAX_VALUE);
    
public java.awt.image.ColorModelgetColorModel()
Return the ColorModel of the output.

        return colorModel;
    
public static java.awt.PaintContextgetContext(java.awt.image.BufferedImage bufImg, java.awt.geom.AffineTransform xform, java.awt.RenderingHints hints, java.awt.Rectangle devBounds)


        
					   
					   
					    
        WritableRaster raster = bufImg.getRaster();
	ColorModel cm = bufImg.getColorModel();
	int maxw = devBounds.width;
	Object val = hints.get(hints.KEY_INTERPOLATION);
	boolean filter =
	    (val == null
	     ? (hints.get(hints.KEY_RENDERING) == hints.VALUE_RENDER_QUALITY)
	     : (val != hints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
	if (raster instanceof IntegerInterleavedRaster &&
	    (!filter || isFilterableDCM(cm)))
	{
	    IntegerInterleavedRaster iir = (IntegerInterleavedRaster) raster;
	    if (iir.getNumDataElements() == 1 && iir.getPixelStride() == 1) {
		return new Int(iir, cm, xform, maxw, filter);
	    }
	} else if (raster instanceof ByteInterleavedRaster) {
	    ByteInterleavedRaster bir = (ByteInterleavedRaster) raster;
	    if (bir.getNumDataElements() == 1 && bir.getPixelStride() == 1) {
		if (filter) {
		    if (isFilterableICM(cm)) {
			return new ByteFilter(bir, cm, xform, maxw);
		    }
		} else {
		    return new Byte(bir, cm, xform, maxw);
		}
	    }
	}
	return new Any(raster, cm, xform, maxw, filter);
    
public static java.awt.image.ColorModelgetInternedColorModel(java.awt.image.ColorModel cm)

	if (xrgbmodel == cm || xrgbmodel.equals(cm)) {
	    return xrgbmodel;
	}
	if (argbmodel == cm || argbmodel.equals(cm)) {
	    return argbmodel;
	}
	return cm;
    
public java.awt.image.RastergetRaster(int x, int y, int w, int h)
Return a Raster containing the colors generated for the graphics operation.

param
x,y,w,h The area in device space for which colors are generated.

	if (outRas == null ||
	    outRas.getWidth() < w ||
	    outRas.getHeight() < h)
	{
	    // If h==1, we will probably get lots of "scanline" rects
	    outRas = makeRaster((h == 1 ? Math.max(w, maxWidth) : w), h);
	}
	double X = mod(xOrg + x * incXAcross + y * incXDown, bWidth);
	double Y = mod(yOrg + x * incYAcross + y * incYDown, bHeight);

	setRaster((int) X, (int) Y, fractAsInt(X), fractAsInt(Y),
		  w, h, bWidth, bHeight,
		  colincx, colincxerr,
		  colincy, colincyerr,
		  rowincx, rowincxerr,
		  rowincy, rowincyerr);

	return outRas;
    
public static booleanisFilterableDCM(java.awt.image.ColorModel cm)

	if (cm instanceof DirectColorModel) {
	    DirectColorModel dcm = (DirectColorModel) cm;
	    return (isMaskOK(dcm.getAlphaMask(), true) &&
		    isMaskOK(dcm.getRedMask(), false) &&
		    isMaskOK(dcm.getGreenMask(), false) &&
		    isMaskOK(dcm.getBlueMask(), false));
	}
	return false;
    
public static booleanisFilterableICM(java.awt.image.ColorModel cm)

	if (cm instanceof IndexColorModel) {
	    IndexColorModel icm = (IndexColorModel) cm;
	    if (icm.getMapSize() <= 256) {
		return true;
	    }
	}
	return false;
    
public static booleanisMaskOK(int mask, boolean canbezero)

	if (canbezero && mask == 0) {
	    return true;
	}
	return (mask == 0xff ||
		mask == 0xff00 ||
		mask == 0xff0000 ||
		mask == 0xff000000);
    
static synchronized java.awt.image.WritableRastermakeByteRaster(java.awt.image.Raster srcRas, int w, int h)

	if (byteRasRef != null) {
	    WritableRaster wr = (WritableRaster) byteRasRef.get();
	    if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
		byteRasRef = null;
		return wr;
	    }
	}
	// If we are going to cache this Raster, make it non-tiny
	if (w <= 32 && h <= 32) {
	    w = h = 32;
	}
	return srcRas.createCompatibleWritableRaster(w, h);
    
static synchronized java.awt.image.WritableRastermakeRaster(java.awt.image.ColorModel cm, java.awt.image.Raster srcRas, int w, int h)

	if (xrgbmodel == cm) {
	    if (xrgbRasRef != null) {
		WritableRaster wr = (WritableRaster) xrgbRasRef.get();
		if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
		    xrgbRasRef = null;
		    return wr;
		}
	    }
	    // If we are going to cache this Raster, make it non-tiny
	    if (w <= 32 && h <= 32) {
		w = h = 32;
	    }
	} else if (argbmodel == cm) {
	    if (argbRasRef != null) {
		WritableRaster wr = (WritableRaster) argbRasRef.get();
		if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) {
		    argbRasRef = null;
		    return wr;
		}
	    }
	    // If we are going to cache this Raster, make it non-tiny
	    if (w <= 32 && h <= 32) {
		w = h = 32;
	    }
	}
	if (srcRas != null) {
	    return srcRas.createCompatibleWritableRaster(w, h);
	} else {
	    return cm.createCompatibleWritableRaster(w, h);
	}
    
public abstract java.awt.image.WritableRastermakeRaster(int w, int h)

static doublemod(double num, double den)

	num = num % den;
	if (num < 0) {
	    num += den;
	    if (num >= den) {
		// For very small negative numerators, the answer might
		// be such a tiny bit less than den that the difference
		// is smaller than the mantissa of a double allows and
		// the result would then be rounded to den.  If that is
		// the case then we map that number to 0 as the nearest
		// modulus representation.
		num = 0;
	    }
	}
	return num;
    
public abstract voidsetRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr)