本文整理匯總了Java中java.awt.image.SinglePixelPackedSampleModel.getBitOffsets方法的典型用法代碼示例。如果您正苦於以下問題:Java SinglePixelPackedSampleModel.getBitOffsets方法的具體用法?Java SinglePixelPackedSampleModel.getBitOffsets怎麽用?Java SinglePixelPackedSampleModel.getBitOffsets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.SinglePixelPackedSampleModel
的用法示例。
在下文中一共展示了SinglePixelPackedSampleModel.getBitOffsets方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateAlphaOffset
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Calculates byte offset of the alpha channel from the beginning of the pixel data
* @param sm - sample model
* @param r - raster
* @return byte offset of the alpha channel
*/
private static int calculateAlphaOffset(SampleModel sm, Raster r) {
if (sm instanceof ComponentSampleModel) {
ComponentSampleModel csm = (ComponentSampleModel) sm;
int dataTypeSize =
DataBuffer.getDataTypeSize(r.getDataBuffer().getDataType()) / 8;
return
csm.getBandOffsets()[csm.getBandOffsets().length - 1] * dataTypeSize;
} else if (sm instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
return sppsm.getBitOffsets()[sppsm.getBitOffsets().length - 1] / 8;
} else {
return -1; // No offset, don't copy alpha
}
}
示例2: IntegerComponentRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Constructs a IntegerComponentRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferInt and
* SampleModel must be of type SinglePixelPackedSampleModel.
* When translated into the base Raster's
* coordinate system, aRegion must be contained by the base Raster.
* Origin is the coodinate in the new Raster's coordinate system of
* the origin of the base Raster. (The base Raster is the Raster's
* ancestor which has no parent.)
*
* Note that this constructor should generally be called by other
* constructors or create methods, it should not be used directly.
* @param sampleModel The SampleModel that specifies the layout.
* @param dataBuffer The DataBufferInt that contains the image data.
* @param aRegion The Rectangle that specifies the image area.
* @param origin The Point that specifies the origin.
* @param parent The parent (if any) of this raster.
*/
public IntegerComponentRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
IntegerComponentRaster parent){
super(sampleModel,dataBuffer,aRegion,origin,parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferInt)) {
throw new RasterFormatException("IntegerComponentRasters must have" +
"integer DataBuffers");
}
DataBufferInt dbi = (DataBufferInt)dataBuffer;
if (dbi.getNumBanks() != 1) {
throw new
RasterFormatException("DataBuffer for IntegerComponentRasters"+
" must only have 1 bank.");
}
this.data = stealData(dbi, 0);
if (sampleModel instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm =
(SinglePixelPackedSampleModel)sampleModel;
int[] boffsets = sppsm.getBitOffsets();
boolean notByteBoundary = false;
for (int i=1; i < boffsets.length; i++) {
if ((boffsets[i]%8) != 0) {
notByteBoundary = true;
}
}
this.type = (notByteBoundary
? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
: IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);
this.scanlineStride = sppsm.getScanlineStride();
this.pixelStride = 1;
this.dataOffsets = new int[1];
this.dataOffsets[0] = dbi.getOffset();
this.bandOffset = this.dataOffsets[0];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
dataOffsets[0] += xOffset+yOffset*scanlineStride;
this.numDataElems = sppsm.getNumDataElements();
} else {
throw new RasterFormatException("IntegerComponentRasters must have"+
" SinglePixelPackedSampleModel");
}
verify();
}
示例3: IntegerComponentRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Constructs a IntegerComponentRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferInt and
* SampleModel must be of type SinglePixelPackedSampleModel.
* When translated into the base Raster's
* coordinate system, aRegion must be contained by the base Raster.
* Origin is the coodinate in the new Raster's coordinate system of
* the origin of the base Raster. (The base Raster is the Raster's
* ancestor which has no parent.)
*
* Note that this constructor should generally be called by other
* constructors or create methods, it should not be used directly.
* @param sampleModel The SampleModel that specifies the layout.
* @param dataBuffer The DataBufferInt that contains the image data.
* @param aRegion The Rectangle that specifies the image area.
* @param origin The Point that specifies the origin.
* @param parent The parent (if any) of this raster.
*/
public IntegerComponentRaster(SampleModel sampleModel,
DataBufferInt dataBuffer,
Rectangle aRegion,
Point origin,
IntegerComponentRaster parent)
{
super(sampleModel,dataBuffer,aRegion,origin,parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (dataBuffer.getNumBanks() != 1) {
throw new
RasterFormatException("DataBuffer for IntegerComponentRasters"+
" must only have 1 bank.");
}
this.data = stealData(dataBuffer, 0);
if (sampleModel instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm =
(SinglePixelPackedSampleModel)sampleModel;
int[] boffsets = sppsm.getBitOffsets();
boolean notByteBoundary = false;
for (int i=1; i < boffsets.length; i++) {
if ((boffsets[i]%8) != 0) {
notByteBoundary = true;
}
}
this.type = (notByteBoundary
? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
: IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);
this.scanlineStride = sppsm.getScanlineStride();
this.pixelStride = 1;
this.dataOffsets = new int[1];
this.dataOffsets[0] = dataBuffer.getOffset();
this.bandOffset = this.dataOffsets[0];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
dataOffsets[0] += xOffset+yOffset*scanlineStride;
this.numDataElems = sppsm.getNumDataElements();
} else {
throw new RasterFormatException("IntegerComponentRasters must have"+
" SinglePixelPackedSampleModel");
}
verify();
}
示例4: IntegerComponentRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Constructs a IntegerComponentRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferInt and
* SampleModel must be of type SinglePixelPackedSampleModel.
* When translated into the base Raster's
* coordinate system, aRegion must be contained by the base Raster.
* Origin is the coodinate in the new Raster's coordinate system of
* the origin of the base Raster. (The base Raster is the Raster's
* ancestor which has no parent.)
*
* Note that this constructor should generally be called by other
* constructors or create methods, it should not be used directly.
* @param sampleModel The SampleModel that specifies the layout.
* @param dataBuffer The DataBufferInt that contains the image data.
* @param aRegion The Rectangle that specifies the image area.
* @param origin The Point that specifies the origin.
* @param parent The parent (if any) of this raster.
*/
public IntegerComponentRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
IntegerComponentRaster parent){
super(sampleModel,dataBuffer,aRegion,origin,parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferInt)) {
throw new RasterFormatException("IntegerComponentRasters must have" +
"integer DataBuffers");
}
DataBufferInt dbi = (DataBufferInt)dataBuffer;
if (dbi.getNumBanks() != 1) {
throw new
RasterFormatException("DataBuffer for IntegerComponentRasters"+
" must only have 1 bank.");
}
this.data = stealData(dbi, 0);
if (sampleModel instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm =
(SinglePixelPackedSampleModel)sampleModel;
int[] boffsets = sppsm.getBitOffsets();
boolean notByteBoundary = false;
for (int i=1; i < boffsets.length; i++) {
if ((boffsets[i]%8) != 0) {
notByteBoundary = true;
}
}
this.type = (notByteBoundary
? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
: IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);
this.scanlineStride = sppsm.getScanlineStride();
this.pixelStride = 1;
this.dataOffsets = new int[1];
this.dataOffsets[0] = dbi.getOffset();
this.bandOffset = this.dataOffsets[0];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
dataOffsets[0] += xOffset+yOffset*scanlineStride;
this.numDataElems = sppsm.getNumDataElements();
} else {
throw new RasterFormatException("IntegerComponentRasters must have"+
" SinglePixelPackedSampleModel");
}
verify(false);
}
示例5: transformS
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
synchronized void transformS(WritableRaster iwr, WritableRaster ewr) {
synchronized (this) {
if (BMl == null) {// || BMm == null || BOl == null || BOm == null
// initialization of raster band configuration (should only occur once)
SinglePixelPackedSampleModel SMl = (SinglePixelPackedSampleModel)ewr.getSampleModel();
SinglePixelPackedSampleModel SMm = (SinglePixelPackedSampleModel)iwr.getSampleModel();
BMl = SMl.getBitMasks();
BMm = SMm.getBitMasks();
BOl = SMl.getBitOffsets();
BOm = SMm.getBitOffsets();
}
// get source pixels in an array
iwr.getDataElements(lurd[0], lurd[1], lensWidth, lensHeight, oPixelsS);
// get magnified source pixels in a second array
ewr.getDataElements(0, 0, mbw, mbh, mPixelsS);
// transfer them to the target array taking the gain function into account
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
/*
* SPATIAL DISTORTION
*/
/*
* gain is computed w.r.t main buffer pixels
* (we do not want to compute the gain for pixels that won't be in the output)
*/
this.gf(x, y, gain);
ti = (y - lurd[1]) * (lensWidth) + (x - lurd[0]);
tmPixelsS[ti] =
mPixelsS[Math.round(((y - lurd[1]) * MM - hmbh) / gain[1] + hmbh) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / gain[0] + hmbw)];
toPixelsS[ti] =
oPixelsS[(Math.round((((float)y - sh - ly) / gain[1]) + sh + ly) - lurd[1]) * (lensWidth) + (Math.round((((float)x - sw - lx) / gain[0]) + sw + lx) - lurd[0])];
/*
* ALPHA BLENDING
*/
// get pixel from lens raster
Pl = tmPixelsS[ti];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = toPixelsS[ti];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsS[ti] = (short)((Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]));
}
}
// transfer pixels in the target array back to the raster
iwr.setDataElements(lurd[0], lurd[1], lensWidth, lensHeight, tPixelsS);
}
}
示例6: transformI
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
synchronized void transformI(WritableRaster iwr, WritableRaster ewr) {
synchronized (this) {
if (BMl == null) {
// || BMm == null || BOl == null || BOm == null
// initialization of raster band configuration (should only occur once)
SinglePixelPackedSampleModel SMl = (SinglePixelPackedSampleModel)ewr.getSampleModel();
SinglePixelPackedSampleModel SMm = (SinglePixelPackedSampleModel)iwr.getSampleModel();
BMl = SMl.getBitMasks();
BMm = SMm.getBitMasks();
BOl = SMl.getBitOffsets();
BOm = SMm.getBitOffsets();
}
// get source pixels in an array
iwr.getDataElements(lurd[0], lurd[1], lensWidth, lensHeight, oPixelsI);
// get magnified source pixels in a second array
ewr.getDataElements(0, 0, mbw, mbh, mPixelsI);
// transfer them to the target array taking the gain function into account
if (BMl.length == 4) {
// the sample model features four bands
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
this.gf(x, y, gain);
// get pixel from lens raster
Pl = mPixelsI[Math.round(((y - lurd[1]) * MM - hmbh) / gain[1] + hmbh) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / gain[0] + hmbw)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
Am = (Pm & BMm[3]) >>> BOm[3];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]) | (Am << BOl[3]);
}
}
} else {
// the sample model probably features 3 bands
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
this.gf(x, y, gain);
// get pixel from lens raster
Pl = mPixelsI[Math.round(((y - lurd[1]) * MM - hmbh) / gain[1] + hmbh) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / gain[0] + hmbw)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]);
}
}
}
// transfer pixels in the target array back to the raster
iwr.setDataElements(lurd[0], lurd[1], lensWidth, lensHeight, tPixelsI);
}
}
示例7: transformS
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
synchronized void transformS(WritableRaster iwr, WritableRaster ewr) {
synchronized (this) {
if (BMl == null) {
// || BMmS == null || BOlS == null || BOmS == null
// initialization of raster band configuration (should only occur once)
SinglePixelPackedSampleModel SMl = (SinglePixelPackedSampleModel)ewr.getSampleModel();
SinglePixelPackedSampleModel SMm = (SinglePixelPackedSampleModel)iwr.getSampleModel();
BMl = SMl.getBitMasks();
BMm = SMm.getBitMasks();
BOl = SMl.getBitOffsets();
BOm = SMm.getBitOffsets();
}
// get source pixels in an array
iwr.getDataElements(lurd[0], lurd[1], lensWidth, lensHeight, oPixelsS);
// get magnified source pixels in a second array
ewr.getDataElements(0, 0, mbw, mbh, mPixelsS);
// transfer them to the target array taking the gain function into account
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
this.gf(x, y, gain);
// get pixel from lens raster
Pl = mPixelsS[Math.round(((y - lurd[1]) * MM - hmbh) / gain[1] + hmbh) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / gain[0] + hmbw)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsS[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsS[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (short)((Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]));
}
}
// transfer pixels in the target array back to the raster
iwr.setDataElements(lurd[0], lurd[1], lensWidth, lensHeight, tPixelsS);
}
}
示例8: transformI
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
synchronized void transformI(WritableRaster iwr, WritableRaster ewr) {
synchronized (this) {
if (BMl == null) {
// || BMm == null || BOl == null || BOm == null
// initialization of raster band configuration (should only occur once)
SinglePixelPackedSampleModel SMl = (SinglePixelPackedSampleModel)ewr.getSampleModel();
SinglePixelPackedSampleModel SMm = (SinglePixelPackedSampleModel)iwr.getSampleModel();
BMl = SMl.getBitMasks();
BMm = SMm.getBitMasks();
BOl = SMl.getBitOffsets();
BOm = SMm.getBitOffsets();
}
// get source pixels in an array
iwr.getDataElements(lurd[0], lurd[1], lensWidth, lensHeight, oPixelsI);
// get magnified source pixels in a second array
ewr.getDataElements(0, 0, mbw, mbh, mPixelsI);
// transfer them to the target array taking the gain function into account
if (BMl.length == 4) {
// the sample model features four bands
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
//this.gf(x,y,gain);
// get pixel from lens raster
Pl = mPixelsI[Math.round(((y - lurd[1]) * MM - hmbh) / MM + hmbh + dy) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / MM + hmbw + dx)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
Am = (Pm & BMm[3]) >>> BOm[3];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]) | (Am << BOl[3]);
}
}
} else {
// the sample model probably features 3 bands
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
//this.gf(x,y,gain);
// get pixel from lens raster
Pl = mPixelsI[Math.round(((y - lurd[1]) * MM - hmbh) / MM + hmbh + dy) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / MM + hmbw + dx)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsI[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]);
}
}
}
// transfer pixels in the target array back to the raster
iwr.setDataElements(lurd[0], lurd[1], lensWidth, lensHeight, tPixelsI);
}
}
示例9: transformS
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
@Override
synchronized void transformS(WritableRaster iwr, WritableRaster ewr) {
synchronized (this) {
if (BMl == null) {
// || BMmS == null || BOlS == null || BOmS == null
// initialization of raster band configuration (should only occur once)
SinglePixelPackedSampleModel SMl = (SinglePixelPackedSampleModel)ewr.getSampleModel();
SinglePixelPackedSampleModel SMm = (SinglePixelPackedSampleModel)iwr.getSampleModel();
BMl = SMl.getBitMasks();
BMm = SMm.getBitMasks();
BOl = SMl.getBitOffsets();
BOm = SMm.getBitOffsets();
}
// get source pixels in an array
iwr.getDataElements(lurd[0], lurd[1], lensWidth, lensHeight, oPixelsS);
// get magnified source pixels in a second array
ewr.getDataElements(0, 0, mbw, mbh, mPixelsS);
// transfer them to the target array taking the gain function into account
for (int x = lurd[0]; x < lurd[2]; x++) {
for (int y = lurd[1]; y < lurd[3]; y++) {
//this.gf(x,y,gain);
// get pixel from lens raster
Pl = mPixelsS[Math.round(((y - lurd[1]) * MM - hmbh) / MM + hmbh + dy) * mbw + Math.round(((x - lurd[0]) * MM - hmbw) / MM + hmbw + dx)];
Rl = (Pl & BMl[0]) >>> BOl[0];
Gl = (Pl & BMl[1]) >>> BOl[1];
Bl = (Pl & BMl[2]) >>> BOl[2];
// get pixel from main raster
Pm = oPixelsS[(y - lurd[1]) * (lensWidth) + (x - lurd[0])];
Rm = (Pm & BMm[0]) >>> BOm[0];
Gm = (Pm & BMm[1]) >>> BOm[1];
Bm = (Pm & BMm[2]) >>> BOm[2];
// compute contribution from each pixel, for each band
// Use the Porter-Duff Source Atop Destination rule to achieve our effect.
// Fs = Ad and Fd = (1-As), thus:
// Cd = Cs*Ad + Cd*(1-As)
// Ad = As*Ad + Ad*(1-As) = Ad
this.gfT(x, y, gainT);
Rr = Math.round(Rl * gainT[0] + Rm * (1 - gainT[0]));
Gr = Math.round(Gl * gainT[0] + Gm * (1 - gainT[0]));
Br = Math.round(Bl * gainT[0] + Bm * (1 - gainT[0]));
// set new pixel value in target raster
tPixelsS[(y - lurd[1]) * (lensWidth) + (x - lurd[0])] = (short)((Rr << BOm[0]) | (Gr << BOl[1]) | (Br << BOl[2]));
}
}
// transfer pixels in the target array back to the raster
iwr.setDataElements(lurd[0], lurd[1], lensWidth, lensHeight, tPixelsS);
}
}