use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.
the class LCMSImageLayout method createImageLayout.
public static LCMSImageLayout createImageLayout(Raster r) {
LCMSImageLayout l = new LCMSImageLayout();
if (r instanceof ByteComponentRaster && r.getSampleModel() instanceof ComponentSampleModel) {
ByteComponentRaster br = (ByteComponentRaster) r;
ComponentSampleModel csm = (ComponentSampleModel) r.getSampleModel();
l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);
int[] bandOffsets = csm.getBandOffsets();
BandOrder order = BandOrder.getBandOrder(bandOffsets);
int firstBand = 0;
switch(order) {
case INVERTED:
l.pixelType |= DOSWAP;
firstBand = csm.getNumBands() - 1;
break;
case DIRECT:
// do nothing
break;
default:
// unable to create the image layout;
return null;
}
l.nextRowOffset = br.getScanlineStride();
l.nextPixelOffset = br.getPixelStride();
l.offset = br.getDataOffset(firstBand);
l.dataArray = br.getDataStorage();
l.dataType = DT_BYTE;
l.width = br.getWidth();
l.height = br.getHeight();
if (l.nextRowOffset == l.width * br.getPixelStride()) {
l.imageAtOnce = true;
}
return l;
}
return null;
}
use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.
the class ImageUtil method getBandSize.
public static long getBandSize(SampleModel sm) {
int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());
if (sm instanceof ComponentSampleModel) {
ComponentSampleModel csm = (ComponentSampleModel) sm;
int pixelStride = csm.getPixelStride();
int scanlineStride = csm.getScanlineStride();
long size = Math.min(pixelStride, scanlineStride);
if (pixelStride > 0)
size += pixelStride * (sm.getWidth() - 1);
if (scanlineStride > 0)
size += scanlineStride * (sm.getHeight() - 1);
return size * ((elementSize + 7) / 8);
} else
return getTileSize(sm);
}
use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.
the class BMPImageReader method read8Bit.
// Method to read 8 bit BMP image data
private void read8Bit(byte[] bdata) throws IOException {
// Padding bytes at the end of each scanline
int padding = width % 4;
if (padding != 0) {
padding = 4 - padding;
}
int lineLength = width + padding;
if (noTransform) {
int j = isBottomUp ? (height - 1) * width : 0;
for (int i = 0; i < height; i++) {
if (abortRequested()) {
break;
}
iis.readFully(bdata, j, width);
iis.skipBytes(padding);
j += isBottomUp ? -width : width;
processImageUpdate(bi, 0, i, destinationRegion.width, 1, 1, 1, new int[] { 0 });
processImageProgress(100.0F * i / destinationRegion.height);
}
} else {
byte[] buf = new byte[lineLength];
int lineStride = ((ComponentSampleModel) sampleModel).getScanlineStride();
if (isBottomUp) {
int lastLine = sourceRegion.y + (destinationRegion.height - 1) * scaleY;
iis.skipBytes(lineLength * (height - 1 - lastLine));
} else
iis.skipBytes(lineLength * sourceRegion.y);
int skipLength = lineLength * (scaleY - 1);
int k = destinationRegion.y * lineStride;
if (isBottomUp)
k += (destinationRegion.height - 1) * lineStride;
k += destinationRegion.x;
for (int j = 0, y = sourceRegion.y; j < destinationRegion.height; j++, y += scaleY) {
if (abortRequested())
break;
iis.read(buf, 0, lineLength);
for (int i = 0, m = sourceRegion.x; i < destinationRegion.width; i++, m += scaleX) {
//get the bit and assign to the data buffer of the raster
bdata[k + i] = buf[m];
}
k += isBottomUp ? -lineStride : lineStride;
iis.skipBytes(skipLength);
processImageUpdate(bi, 0, j, destinationRegion.width, 1, 1, 1, new int[] { 0 });
processImageProgress(100.0F * j / destinationRegion.height);
}
}
}
use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.
the class BMPImageReader method decodeRLE8.
private void decodeRLE8(int imSize, int padding, byte[] values, byte[] bdata) throws IOException {
byte[] val = new byte[width * height];
int count = 0, l = 0;
int value;
boolean flag = false;
int lineNo = isBottomUp ? height - 1 : 0;
int lineStride = ((ComponentSampleModel) sampleModel).getScanlineStride();
int finished = 0;
while (count != imSize) {
value = values[count++] & 0xff;
if (value == 0) {
switch(values[count++] & 0xff) {
case 0:
// End-of-scanline marker
if (lineNo >= sourceRegion.y && lineNo < sourceRegion.y + sourceRegion.height) {
if (noTransform) {
int pos = lineNo * width;
for (int i = 0; i < width; i++) bdata[pos++] = val[i];
processImageUpdate(bi, 0, lineNo, destinationRegion.width, 1, 1, 1, new int[] { 0 });
finished++;
} else if ((lineNo - sourceRegion.y) % scaleY == 0) {
int currentLine = (lineNo - sourceRegion.y) / scaleY + destinationRegion.y;
int pos = currentLine * lineStride;
pos += destinationRegion.x;
for (int i = sourceRegion.x; i < sourceRegion.x + sourceRegion.width; i += scaleX) bdata[pos++] = val[i];
processImageUpdate(bi, 0, currentLine, destinationRegion.width, 1, 1, 1, new int[] { 0 });
finished++;
}
}
processImageProgress(100.0F * finished / destinationRegion.height);
lineNo += isBottomUp ? -1 : 1;
l = 0;
if (abortRequested()) {
flag = true;
}
break;
case 1:
// End-of-RLE marker
flag = true;
break;
case 2:
// delta or vector marker
int xoff = values[count++] & 0xff;
int yoff = values[count] & 0xff;
// Move to the position xoff, yoff down
l += xoff + yoff * width;
break;
default:
int end = values[count - 1] & 0xff;
for (int i = 0; i < end; i++) {
val[l++] = (byte) (values[count++] & 0xff);
}
// an extra padding byte will be present, so skip that.
if ((end & 1) == 1) {
count++;
}
}
} else {
for (int i = 0; i < value; i++) {
val[l++] = (byte) (values[count] & 0xff);
}
count++;
}
// If End-of-RLE data, then exit the while loop
if (flag) {
break;
}
}
}
use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.
the class ImageUtil method imageIsContiguous.
/**
* Returns whether the image has contiguous data across rows.
*/
public static final boolean imageIsContiguous(RenderedImage image) {
SampleModel sm;
if (image instanceof BufferedImage) {
WritableRaster ras = ((BufferedImage) image).getRaster();
sm = ras.getSampleModel();
} else {
sm = image.getSampleModel();
}
if (sm instanceof ComponentSampleModel) {
// Ensure image rows samples are stored contiguously
// in a single bank.
ComponentSampleModel csm = (ComponentSampleModel) sm;
if (csm.getPixelStride() != csm.getNumBands()) {
return false;
}
int[] bandOffsets = csm.getBandOffsets();
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != i) {
return false;
}
}
int[] bankIndices = csm.getBankIndices();
for (int i = 0; i < bandOffsets.length; i++) {
if (bankIndices[i] != 0) {
return false;
}
}
return true;
}
// pixel stride.
return ImageUtil.isBinary(sm);
}
Aggregations