use of java.awt.image.DataBufferByte in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method createUnderlyingImage.
/**
* Method createUnderlyingImage.
* @param image UShortImage
* @return BufferedImage
*/
private BufferedImage createUnderlyingImage(UShortImage image) {
int[] cmap = new int[256];
// colormap (grayscale)
for (int i = 0; i < 256; i += 1) {
int iv = (0x000000FF & i);
cmap[i] = 0xFF000000 | iv << 16 | iv << 8 | i;
}
IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, false, /*false means NOT USE alpha*/
-1, /*NO transparent single pixel*/
java.awt.image.DataBuffer.TYPE_BYTE);
int width = image.getNumX();
int height = image.getNumY();
ImageStatistics imageStats = image.getImageStatistics();
short[] pixels = image.getPixels();
BufferedImage underImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
byte[] byteData = ((DataBufferByte) underImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < byteData.length; i++) {
byteData[i] = (imageStats.maxValue < SHORT_TO_BYTE_FACTOR ? (byte) pixels[i] : (byte) (((pixels[i] & 0x0000FFFF)) / SHORT_TO_BYTE_FACTOR));
}
return underImage;
}
use of java.awt.image.DataBufferByte in project vcell by virtualcell.
the class FormatSpecificSpecs method getVideoMediaSample.
public static VideoMediaSample getVideoMediaSample(int width, int height, int sampleDuration, boolean isGrayScale, int compressionType, float compressionQuality, int[] argbData) throws Exception {
if (isGrayScale) {
// convert 32bit to 8bit
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
byte[] buffer = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < buffer.length; i++) {
buffer[i] = (byte) (argbData[i] & 0x000000FF);
}
if (compressionType == FormatSpecificSpecs.CODEC_JPEG) {
return FormatSpecificSpecs.encodeJPEG(bufferedImage, compressionQuality, width, height, sampleDuration, Byte.SIZE, true);
} else {
return new VideoMediaSampleRaw(width, height, sampleDuration, buffer, 8, true);
}
}
if (compressionType == FormatSpecificSpecs.CODEC_JPEG) {
BufferedImage bufferedImage = null;
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
System.arraycopy(argbData, 0, ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData(), 0, argbData.length);
return FormatSpecificSpecs.encodeJPEG(bufferedImage, compressionQuality, width, height, sampleDuration, Integer.SIZE, false);
} else {
ByteArrayOutputStream sampleBytes = new ByteArrayOutputStream();
DataOutputStream sampleData = new DataOutputStream(sampleBytes);
for (int j = 0; j < argbData.length; j++) {
sampleData.writeInt(argbData[j]);
}
sampleData.close();
byte[] bytes = sampleBytes.toByteArray();
return new VideoMediaSampleRaw(width, height, sampleDuration, bytes, Integer.SIZE, false);
}
}
use of java.awt.image.DataBufferByte in project vcell by virtualcell.
the class GeometryThumbnailImageFactoryAWT method getImage.
private static BufferedImage getImage(IndexColorModel indexColorModel, byte[] imageIndiciesIntoPalette, int width, int height) {
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
WritableRaster raster = bufferedImage.getRaster();
DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
System.arraycopy(imageIndiciesIntoPalette, 0, dataBuffer.getData(), 0, imageIndiciesIntoPalette.length);
return bufferedImage;
}
use of java.awt.image.DataBufferByte in project vcell by virtualcell.
the class OverlayEditorPanelJAI method createHighlightImageFromROI.
/**
* Method createHighlightImageFromROI.
* @return BufferedImage
*/
private BufferedImage createHighlightImageFromROI(ROI highlightImageROI) {
UShortImage roiImage = highlightImageROI.getRoiImages()[getRoiImageIndex()];
int width = roiImage.getNumX();
int height = roiImage.getNumY();
BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, getHiliteColorModel());
byte[] hiLiteArr = ((DataBufferByte) hiLiteImage.getRaster().getDataBuffer()).getData();
for (int i = 0; i < roiImage.getPixels().length; i++) {
hiLiteArr[i] = (roiImage.getPixels()[i] != 0 ? (byte) highlightColor.getRed() : 0);
}
return hiLiteImage;
}
use of java.awt.image.DataBufferByte in project vcell by virtualcell.
the class OverlayEditorPanelJAI method updateLabel.
/**
* Updates cursor probe label. * @param x int
* @param y int
*/
private void updateLabel(int inx, int iny) {
if (imageDataset == null) {
return;
}
float zoom = imagePane.getZoom();
if ((inx / zoom) >= imageDataset.getISize().getX() || (iny / zoom) >= imageDataset.getISize().getY()) {
inx = -1;
iny = -1;
}
int x = (int) (inx / zoom);
int y = (int) (iny / zoom);
UShortImage[] images = imageDataset.getAllImages();
sb.setLength(0);
boolean bMultipleZ = imageDataset.getSizeZ() > 1;
if (bMultipleZ) {
sb.append("; Z=");
sb.append(getZ() + 1);
sb.append("/");
sb.append(imageDataset.getSizeZ());
if (calcCoords != null) {
sb.append(" " + NumberUtils.formatNumber(calcCoords.calcZ(getZ()), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentZ(), 6));
}
}
if (imageDataset.getSizeT() > 1) {
sb.append((bMultipleZ ? "; " : "") + "T=");
sb.append(imageDataset.getImageTimeStamps()[getT()]);
}
int w = imageDataset == null ? -1 : imageDataset.getISize().getX();
int h = imageDataset == null ? -1 : imageDataset.getISize().getY();
if (x >= w)
x = w - 1;
if (y >= h)
y = h - 1;
if (x >= 0 && y >= 0 && inx >= 0 && iny >= 0 && x < imageDataset.getISize().getX() && y < imageDataset.getISize().getY()) {
if (images.length > 1)
sb.append("; ");
sb.append("X=");
sb.append(x);
if (w > 0) {
sb.append("/");
sb.append(w);
if (calcCoords != null) {
sb.append(" " + NumberUtils.formatNumber(calcCoords.calcX(inx), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentX(), 6));
}
}
sb.append("; Y=");
sb.append(y);
if (h > 0) {
sb.append("/");
sb.append(h);
if (calcCoords != null) {
sb.append(" " + NumberUtils.formatNumber(calcCoords.calcY(iny), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentY(), 6));
}
}
sb.append("; zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
sb.append("; contr(" + imagePane.getContrastDescription() + ")");
if (imageDataset != null) {
short[] pix = null;
try {
pix = new short[imageDataset.getSizeC()];
for (int i = 0; i < pix.length; i++) {
pix[i] = imageDataset.getImage(getZ(), i, getT()).getPixel(x, y, 0);
}
} catch (Exception e) {
pix = null;
e.printStackTrace();
// do nothing
}
sb.append("; value(img)" + (isOriginalValueScaled() ? "(scld)" : ""));
if (pix != null) {
if (histogramPanel.isVisible()) {
histogramPanel.setSpecialValue((int) (pix[0] & 0x0000FFFF));
}
sb.append(pix.length > 1 ? "s=(" : "=");
for (int i = 0; i < pix.length; i++) {
if (i > 0)
sb.append(", ");
sb.append((int) (pix[i] & 0x0000FFFF));
}
if (pix.length > 1)
sb.append(")");
} else {
sb.append(" error");
}
if (isOriginalValueScaled()) {
sb.append("; value(img)(orig)");
if (pix != null) {
sb.append(pix.length > 1 ? "s=(" : "=");
for (int i = 0; i < pix.length; i++) {
if (i > 0)
sb.append(", ");
sb.append(NumberUtils.formatNumber((((int) (pix[i] & 0x0000FFFF)) - originalOffsetFactor) / originalScaleFactor, 6));
}
if (pix.length > 1)
sb.append(")");
} else {
sb.append(" error");
}
}
}
if (allROICompositeImageArr != null) {
// System.out.println(getZ()+" "+x+" "+y);
DataBufferByte dataBufferByte = (DataBufferByte) (allROICompositeImageArr[getZ()].getRaster().getDataBuffer());
sb.append(" val(roi)=" + dataBufferByte.getData()[y * allROICompositeImageArr[0].getWidth() + x]);
}
} else {
sb.append((sb.length() != 0 ? "; " : "") + "zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
sb.append("; contr(" + imagePane.getContrastDescription() + ")");
if (histogramPanel.isVisible()) {
histogramPanel.setSpecialValue(null);
}
}
sb.append(" ");
textLabel.setText(sb.toString());
}
Aggregations