Java 类java.awt.image.RescaleOp 实例源码
项目:freecol
文件:ImageLibrary.java
/**
* Create a faded version of an image.
*
* @param img The {@code Image} to fade.
* @param fade The amount of fading.
* @param target The offset.
* @return The faded image.
*/
public static BufferedImage fadeImage(Image img, float fade, float target) {
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(img, 0, 0, null);
float offset = target * (1.0f - fade);
float[] scales = { fade, fade, fade, 1.0f };
float[] offsets = { offset, offset, offset, 0.0f };
RescaleOp rop = new RescaleOp(scales, offsets, null);
g.drawImage(bi, rop, 0, 0);
g.dispose();
return bi;
}
项目:openjdk-jdk10
文件:ImageRescaleOpTest.java
private void runTest(int sType, int dType, int expect) {
BufferedImage src = new BufferedImage(w, h, sType);
BufferedImage dst = new BufferedImage(w, h, dType);
String msg = getMsgText(sType, dType);
Graphics2D g2d = src.createGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, w, h);
RescaleOp res = new RescaleOp(scaleFactor, offset, null);
res.filter(src, dst);
if (saveImage) {
try {
String fname = getFileName(sType, dType);
ImageIO.write(dst, "png", new File(fname));
} catch (IOException e) {
}
}
check(dst, expect, msg);
}
项目:FreeCol
文件:ImageLibrary.java
/**
* Create a faded version of an image.
*
* @param img The {@code Image} to fade.
* @param fade The amount of fading.
* @param target The offset.
* @return The faded image.
*/
public static BufferedImage fadeImage(Image img, float fade, float target) {
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(img, 0, 0, null);
float offset = target * (1.0f - fade);
float[] scales = { fade, fade, fade, 1.0f };
float[] offsets = { offset, offset, offset, 0.0f };
RescaleOp rop = new RescaleOp(scales, offsets, null);
g.drawImage(bi, rop, 0, 0);
g.dispose();
return bi;
}
项目:orbit-image-analysis
文件:JSliderOrbit.java
@Override
protected Icon getIcon ()
{
// TODO Use that to get the state (-> highlight or not)
TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
// stateTransitionTracker.getModelStateInfo().getCurrModelState();
final Icon icon = super.getIcon();
final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics iconGraphics = image.createGraphics();
icon.paintIcon(slider, iconGraphics, 0, 0);
// Make it brighter (very simple approach)
final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null);
rescaleOp.filter(image, image);
ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
op.filter(image, image);
return new ImageIcon(image);
}
项目:Push2Display
文件:SVGBufferedImageOp.java
/**
* @param op BufferedImageOp to be converted to SVG
* @param filterRect Rectangle, in device space, that defines the area
* to which filtering applies. May be null, meaning that the
* area is undefined.
* @return an SVGFilterDescriptor representing the SVG filter
* equivalent of the input BufferedImageOp
*/
public SVGFilterDescriptor toSVG(BufferedImageOp op,
Rectangle filterRect){
SVGFilterDescriptor filterDesc =
svgCustomBufferedImageOp.toSVG(op, filterRect);
if(filterDesc == null){
if(op instanceof LookupOp)
filterDesc = svgLookupOp.toSVG(op, filterRect);
else if(op instanceof RescaleOp)
filterDesc = svgRescaleOp.toSVG(op, filterRect);
else if(op instanceof ConvolveOp)
filterDesc = svgConvolveOp.toSVG(op, filterRect);
}
return filterDesc;
}
项目:SporeModder
文件:StdDrawable.java
protected void paintImage(Graphics2D graphics, Image image, Rectangle bounds, Color tint) {
if (tint == null || tint.equals(Color.white)) {
paintImage(graphics, image, bounds);
}
else {
BufferedImage graphicsBuffer = new BufferedImage(Math.abs(bounds.width), Math.abs(bounds.height), BufferedImage.TYPE_INT_ARGB);
paintImage(graphicsBuffer.createGraphics(), image, new Rectangle(0, 0, bounds.width, bounds.height));
float[] scaleFactors = new float[4];
float[] offsets = new float[4];
scaleFactors[0] = tint.getRed() / 255f;
scaleFactors[1] = tint.getGreen() / 255f;
scaleFactors[2] = tint.getBlue() / 255f;
scaleFactors[3] = tint.getAlpha() / 255f;
// we must use another image, otherwise the tint isn't applied correctly (check the Sporepedia button transparency in the editor)
BufferedImage img = new BufferedImage(Math.abs(bounds.width), Math.abs(bounds.height), BufferedImage.TYPE_INT_ARGB);
img.createGraphics().drawImage(graphicsBuffer, new RescaleOp(scaleFactors, offsets, null), 0, 0);
graphics.drawImage(img, bounds.x, bounds.y, null);
}
}
项目:SporeModder
文件:Image.java
public static BufferedImage drawTintedImage(BufferedImage image, Dimension dim, int[] uvCoordinates, Color tint) {
BufferedImage temp = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = temp.createGraphics();
Image.drawImage(g, image,
0, 0, dim.width, dim.height,
uvCoordinates[0], uvCoordinates[1], uvCoordinates[2], uvCoordinates[3]);
float[] scaleFactors = new float[4];
float[] offsets = new float[4];
scaleFactors[0] = tint.getRed() / 255f;
scaleFactors[1] = tint.getGreen() / 255f;
scaleFactors[2] = tint.getBlue() / 255f;
scaleFactors[3] = tint.getAlpha() / 255f;
BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
img.createGraphics().drawImage(temp, new RescaleOp(scaleFactors, offsets, null), 0, 0);
return img;
}
项目:paintmultimedia
文件:EditorImagen.java
/**
*
* @param e Evento
*/
public void sBrillo_stateChanged(ChangeEvent e) {
//Comprobamos que se ha cargado una imagen
if (this.imagenAbierta) {
RescaleOp rop = new RescaleOp(1.0f,
(float) this.sBrillo.getValue(), null);
BufferedImage aux = new BufferedImage(this.imagenSinModificar.getWidth(),
this.imagenSinModificar.getHeight(),
this.imagenSinModificar.getType());
//Aplicamos el filtro de brillo a la imagen transformada por los filtros
rop.filter(this.imagenTransformada, aux);
//Establecemos la nueva imagen a mostrar
this.PanelTapiz.setImagen(aux);
//Ponemos que se ha modificado la imagen
this.modificado = true;
}
}
项目:stendhal
文件:ItemPanel.java
/**
* Prepare a version of the place holder Sprite, that is suitable for the
* transparency mode of the client.
*
* @param original original placeholder Sprite
* @return an adjusted Sprite, or the original if no adjusting is needed
*/
private Sprite preparePlaceholder(Sprite original) {
if ((original == null) || (TransparencyMode.TRANSPARENCY == Transparency.BITMASK)) {
return original;
}
/*
* Using full alpha in the client.
*
* Create a black and white, but translucent version of the same image.
* The filtering has been chosen so that the slot images we use become
* suitably B&W, not for any general rule.
*
* What we'd really want is drawing an opaque B&W image in soft light
* mode, but swing back buffer does not actually support Composites
* despite being accessed via Graphics2D.
*/
BufferedImage img = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics g = img.createGraphics();
original.draw(g, 0, 0);
RescaleOp rescaleOp = new RescaleOp(new float[] {3.0f, 3.0f, 3.0f, 0.5f }, new float[] {-450f, -450f, -450f, 0f}, null);
rescaleOp.filter(img, img);
g.dispose();
return new ImageSprite(img);
}
项目:SafariBowl
文件:GameRenderer.java
public void drawMovingPlayer(Graphics2D g) {
if(getGameCanvas().getMovingPlayer() != null) {
AffineTransform transform = new AffineTransform();
double tx = getGameCanvas().getStoredMousePosition()[0] / getT(),
ty = getGameCanvas().getStoredMousePosition()[1] / getT();
BufferedImage sprite;
if(isLeft()) sprite = getGameCanvas().getMovingPlayer().getSpriteR();
else sprite = getGameCanvas().getMovingPlayer().getSpriteL();
if(sprite == null) sprite = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB);
transform.scale(getT(), getT());
transform.translate(tx, ty);
double rotation = -(getGameCanvas().getGameFrame().getOldMousePositions().get(0)[0]-getGameCanvas().getGameFrame().getOldMousePositions().get(1)[0]) / getPW();
if(rotation > GameFrame.MAX_DRAG_ROTATION) rotation = GameFrame.MAX_DRAG_ROTATION;
else if(rotation < -GameFrame.MAX_DRAG_ROTATION) rotation = -GameFrame.MAX_DRAG_ROTATION;
transform.rotate(rotation);
g.transform(transform);
g.drawImage(sprite, new RescaleOp(new float[]{0.8f, 0.8f, 0.8f, 0.6f}, new float[4], null), -ResourceManager.IMAGE_WIDTH / 2, 0);
try { g.transform(transform.createInverse()); }
catch (NoninvertibleTransformException ignored) {}
}
}
项目:SafariBowl
文件:GameRenderer.java
private BufferedImage filterImage(BufferedImage original, int hash, RescaleOp op) {
HashMap<Integer, BufferedImage> imageMap = imageFilterBuffer.get(hash);
float[] scaleFactors = op.getScaleFactors(null);
int opHash = (int) (10*scaleFactors[0]+100*scaleFactors[1]+1000*scaleFactors[2]+10000*scaleFactors[3]);
if(imageMap != null) {
if(imageMap.size() > MAX_IMAGE_BUFFER_SIZE) emptyImageBuffer(); // empty image buffer of this image if it is too full.
else if(imageMap.containsKey(opHash)) return imageMap.get(opHash); // return the buffered resized image if it was resized before.
}
BufferedImage filtered = gameCanvas.getGraphicsConfiguration().createCompatibleImage(original.getWidth(), original.getHeight(), Transparency.BITMASK);
Graphics2D filteredG = filtered.createGraphics();
filteredG.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
filteredG.drawImage(original, op, 0, 0);
filteredG.dispose();
if(imageMap != null) imageMap.put(opHash, filtered);
else {
imageMap = new HashMap<Integer, BufferedImage>();
imageMap.put(opHash, filtered);
imageFilterBuffer.put(hash, imageMap);
}
return filtered;
}
项目:Push2Display
文件:SVGBufferedImageOp.java
/**
* @param op BufferedImageOp to be converted to SVG
* @param filterRect Rectangle, in device space, that defines the area
* to which filtering applies. May be null, meaning that the
* area is undefined.
* @return an SVGFilterDescriptor representing the SVG filter
* equivalent of the input BufferedImageOp
*/
public SVGFilterDescriptor toSVG(BufferedImageOp op,
Rectangle filterRect){
SVGFilterDescriptor filterDesc =
svgCustomBufferedImageOp.toSVG(op, filterRect);
if(filterDesc == null){
if(op instanceof LookupOp)
filterDesc = svgLookupOp.toSVG(op, filterRect);
else if(op instanceof RescaleOp)
filterDesc = svgRescaleOp.toSVG(op, filterRect);
else if(op instanceof ConvolveOp)
filterDesc = svgConvolveOp.toSVG(op, filterRect);
}
return filterDesc;
}
项目:uimaster
文件:ImageUtil.java
public static BufferedImage getStyledImage(File img, float brightness, float transparency, int size) {
BufferedImage outputImage = null;
try {
BufferedImage readBufferedImage = ImageIO.read(img);
BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
outputImage = inputBufferedImage;
if (size > 0) {
outputImage = Scalr.resize(inputBufferedImage
, Method.BALANCED
, size
, size);
}
float brightnessFactor = 1.0f + brightness/100.0f;
float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
RescaleOp rescale = new RescaleOp(
new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
new float[]{0f, 0f, 0f, 0f}, null);
rescale.filter(outputImage, outputImage);
} catch (Exception e) {
e.printStackTrace();
}
return outputImage;
}
项目:feathers-sdk
文件:SVGBufferedImageOp.java
/**
* @param op BufferedImageOp to be converted to SVG
* @param filterRect Rectangle, in device space, that defines the area
* to which filtering applies. May be null, meaning that the
* area is undefined.
* @return an SVGFilterDescriptor representing the SVG filter
* equivalent of the input BufferedImageOp
*/
public SVGFilterDescriptor toSVG(BufferedImageOp op,
Rectangle filterRect){
SVGFilterDescriptor filterDesc =
svgCustomBufferedImageOp.toSVG(op, filterRect);
if(filterDesc == null){
if(op instanceof LookupOp)
filterDesc = svgLookupOp.toSVG(op, filterRect);
else if(op instanceof RescaleOp)
filterDesc = svgRescaleOp.toSVG(op, filterRect);
else if(op instanceof ConvolveOp)
filterDesc = svgConvolveOp.toSVG(op, filterRect);
}
return filterDesc;
}
项目:AndroidDevToolbox
文件:StatefulButtonController.java
private BufferedImage getStyledImage(float brightness, float transparency, int size) {
BufferedImage outputImage = null;
try {
BufferedImage readBufferedImage = ImageIO.read(new File(imageFilePath));
BufferedImage inputBufferedImage = convertToArgb(readBufferedImage);
outputImage = inputBufferedImage;
if (size > 0) {
outputImage = Scalr.resize(inputBufferedImage
, Method.BALANCED
, size
, size);
}
float brightnessFactor = 1.0f + brightness/100.0f;
float transparencyFactor = Math.abs(transparency/100.0f - 1.0f);
RescaleOp rescale = new RescaleOp(
new float[]{brightnessFactor, brightnessFactor, brightnessFactor, transparencyFactor},
new float[]{0f, 0f, 0f, 0f}, null);
rescale.filter(outputImage, outputImage);
} catch (Exception e) {
e.printStackTrace();
}
return outputImage;
}
项目:Sistemas-Multimedia
文件:VentanaPrincipal.java
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
项目:Sistemas-Multimedia
文件:VentanaPrincipal.java
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
项目:Sistemas-Multimedia
文件:VentanaPrincipal.java
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows();
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
项目:Sistemas-Multimedia
文件:VentanaPrincipal.java
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(convertImageType(imgSource, BufferedImage.TYPE_INT_RGB), null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
项目:Sistemas-Multimedia
文件:VentanaPrincipal.java
private void menuRescaleOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuRescaleOpActionPerformed
VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
if (vi != null) {
BufferedImage imgSource = vi.getLienzo().getImageOriginal();
if (imgSource != null) {
try {
RescaleOp rop = new RescaleOp(1.0F, 100.0F, null);
BufferedImage imgdest = rop.filter(imgSource, null);
vi.getLienzo().setImageOriginal(imgdest);
vi.getLienzo().repaint();
} catch (IllegalArgumentException e) {
System.err.println(e.getLocalizedMessage());
}
}
}
}
项目:moa
文件:StreamOutlierPanel.java
public void applyDrawDecay(float factor, boolean bRedrawPointImg){
//System.out.println("applyDrawDecay: factor="+factor);
// 1)
int v = Color.GRAY.getRed();
//System.out.println("applyDrawDecay: v="+v);
RescaleOp brightenOp = new RescaleOp(1f, (255-v)*factor, null);
// 2)
//RescaleOp brightenOp = new RescaleOp(1f + factor, 0, null);
// 3)
//RescaleOp brightenOp = new RescaleOp(1f, (255)*factor, null);
pointImg = brightenOp.filter(pointImg, null);
if (bRedrawPointImg) {
ApplyToCanvas(pointImg);
RedrawPointLayer();
}
}
项目:Programacion
文件:Canvas.java
/**
* Takes a snapshot of the screen, fades it, and sets it as the background.
*/
public static void snapshot()
{
Dimension dim = getInstance().component.getPreferredSize();
java.awt.Rectangle rect = new java.awt.Rectangle(0, 0, dim.width, dim.height);
BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(java.awt.Color.WHITE);
g.fillRect(0, 0, rect.width, rect.height);
g.setColor(java.awt.Color.BLACK);
getInstance().component.paintComponent(g);
float factor = 0.8f;
float base = 255f * (1f - factor);
RescaleOp op = new RescaleOp(factor, base, null);
BufferedImage filteredImage
= new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
op.filter(image, filteredImage);
getInstance().background = filteredImage;
getInstance().component.repaint();
}
项目:jpdfsigner
文件:MultiDocumentThumb.java
@Override
public void paint(Graphics g) {
g.drawImage(renderedImage, 0, 0, getWidth(), getHeight(), null);
newAlpha = 0.0f;
if (getWidth() >= alphaFrom && getWidth() <= alphaTo) {
range = alphaTo - alphaFrom;
currentRange = getWidth() - alphaFrom;
newAlpha = currentRange / range;
} else {
if (getWidth() < alphaFrom) {
newAlpha = 0.0f;
} else if (getWidth() > alphaTo) {
newAlpha = 1.0f;
}
}
scales = new float[4];
scales[0] = 1.0f;
scales[1] = 1.0f;
scales[2] = 1.0f;
scales[3] = newAlpha;
rop = new RescaleOp(scales, offset, null);
((Graphics2D) g).drawImage(drawDocumentName(), rop, 0, 0);
}
项目:Klondike
文件:Sprite.java
/**
* create a new sprite
* also creates a selection variant image for the sprite
* @param image the image to be encapsulated within the sprite
*/
public Sprite(BufferedImage image) {
this.image = image;
float scale[] = {1.f,1.f,0.3f};
float offset[] = {0,0,-0};
//create the yellow filter
BufferedImageOp op = new RescaleOp(scale,offset,null);
//create the selection variant
selectedImage = new BufferedImage(image.getWidth(),image.getHeight()
,image.getType());
//apply the filter to the variant
op.filter(image,selectedImage);
}
项目:SOEN6471-FreeCol
文件:BuildingPanel.java
public BufferedImage fadeImage(Image img, float fade, float target) {
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.getGraphics();
g.drawImage(img, 0, 0, null);
float offset = target * (1.0f - fade);
float[] scales = { fade, fade, fade, 1.0f };
float[] offsets = { offset, offset, offset, 0.0f };
RescaleOp rop = new RescaleOp(scales, offsets, null);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(bi, rop, 0, 0);
return bi;
}
项目:SmartSensorMobility
文件:FadeInkyDrawPanel.java
@Override
public JPanel getSpecialConfigPanel() {
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
JLabel scaleLbl = new JLabel("Scale:");
p.add(scaleLbl);
final SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(0.9, 0, 1, 0.05);
JSpinner scaleSpn = new JSpinner(spinnerNumberModel);
scaleSpn.setPreferredSize(new Dimension(50, 10));
p.add(scaleSpn);
scaleLbl.setLabelFor(scaleSpn);
JButton okBtn = new JButton("OK");
p.add(okBtn);
okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scaleParam = spinnerNumberModel.getNumber().floatValue();
float[] scales = {1f, 1f, 1f, scaleParam};
float[] offsets = new float[4];
alphaScale = new RescaleOp(scales, offsets, null);
}
});
return p;
}
项目:digilib
文件:ImageLoaderDocuImage.java
public void enhanceRGB(float[] rgbm, float[] rgba) throws ImageOpException {
logger.debug("enhanceRGB: rgbm=" + rgbm + " rgba=" + rgba);
/*
* The number of constants must match the number of bands in the image.
* We do only 3 (RGB) bands.
*/
int ncol = img.getColorModel().getNumColorComponents();
if ((ncol != 3) || (rgbm.length != 3) || (rgba.length != 3)) {
logger.error("enhanceRGB: unknown number of color bands or coefficients (" + ncol + ")");
return;
}
if (img.getColorModel().hasAlpha()) {
// add constant for alpha
rgbm = new float[] { rgbm[0], rgbm[1], rgbm[2], 1 };
rgba = new float[] { rgba[0], rgba[1], rgba[2], 0 };
}
RescaleOp scaleOp = new RescaleOp(rgbm, rgba, renderHint);
scaleOp.filter(img, img);
}
项目:Botnak
文件:FaceManager.java
public static URL getExSubscriberIcon(String channel) {
try {
if (exSubscriberIcon == null) {
URL subIconNormal = FaceManager.getSubIcon(channel);
if (subIconNormal != null) {
BufferedImage img = ImageIO.read(subIconNormal);
//rescaleop does not work with sub icons as is, we need to recreate them as ARGB images
BufferedImage bimage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimage.createGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
RescaleOp op = new RescaleOp(.35f, 0f, null);
img = op.filter(bimage, bimage);//then re-assign them
exSubscriberIcon = new File(Settings.subIconsDir + File.separator + channel + "_ex.png");
ImageIO.write(img, "PNG", exSubscriberIcon);
exSubscriberIcon.deleteOnExit();
}
}
return exSubscriberIcon.toURI().toURL();
} catch (Exception e) {
GUIMain.log(e);
}
return null;
}
项目:WorldPainter
文件:OffsetViewer.java
private void paintBlock(Graphics2D g2, int baseLine, int middle, int x, int y, int depth, Material material) {
if (material.blockType == Constants.BLK_AIR) {
return;
}
if (texturePack != null) {
if (depth > 0) {
RescaleOp rescaleOp = new RescaleOp(new float[] {1.0f, 1.0f, 1.0f, (float) Math.pow(2.0, -depth)}, new float[] {0.0f, 0.0f, 0.0f, 0.0f}, null);
g2.drawImage(material.getImage(texturePack), rescaleOp, middle + x * 16 - 8, baseLine - y * 16 - 8);
} else {
g2.drawImage(material.getImage(texturePack), middle + x * 16 - 8, baseLine - y * 16 - 8, null);
}
} else {
int colour = colourScheme.getColour(material);
if (depth > 0) {
colour = ColourUtils.mix(colour, WHITE, (int) (Math.pow(0.5, depth) * 256 + 0.5));
}
g2.setColor(new Color(colour));
g2.fillRect(middle + x * 16 - 8, baseLine - y * 16 - 8, 16, 16);
}
}
项目:sumo
文件:ImageLayer.java
public void setActiveBand(int val) {
if (futures.size() > 0) {
return;
}
this.activeBand = val;
if (contrast.get(createBandsString(activeBand)) == null) {
setInitialContrast();
} else {
rescale = new RescaleOp(contrast.get(createBandsString(activeBand)), brightness, null);
}
}
项目:sumo
文件:KmlIO.java
private static URL createOverview(GeoImageReader gir, boolean toFlip) throws IOException {
File f = File.createTempFile("kmloverview", ".png");
// generate a suitable size image
double ratio = Math.max(((double) gir.getWidth()) / 1024., ((double) gir.getHeight()) / 1024.);
// generate overview image
BufferedImage temp = new BufferedImage((int) (gir.getWidth() * (1.0 / ratio)), (int) (gir.getHeight() * (1.0 / ratio)), gir.getType(true));
// get a handle on the raster data
WritableRaster raster = temp.getRaster();
int[] data = gir.readAndDecimateTile(0, 0, gir.getWidth(), gir.getHeight(), 1.0 / ratio, true,0);
raster.setSamples(0, 0, temp.getWidth(), temp.getHeight(), 0, data);
float average = 0;
for (int i = 0; i < data.length; i++) {
average = average + data[i];
}
average = average / data.length;
RescaleOp rescale = new RescaleOp(((1 << (8 * gir.getNumberOfBytes())) / 5f / average), 0, null);
rescale.filter(temp, temp);
ColorConvertOp bop = new ColorConvertOp(null);
BufferedImage out = bop.createCompatibleDestImage(temp, new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE));
out = bop.filter(temp, out);
//flip the image if necessary
if (toFlip) {
int w = out.getWidth();
int h = out.getHeight();
BufferedImage dimg = new BufferedImage(w, h, out.getType());
Graphics2D g = dimg.createGraphics();
g.drawImage(out, 0, 0, w, h, w, 0, 0, h, null);
g.dispose();
ImageIO.write(dimg, "png", f);
} else {
ImageIO.write(out, "png", f);
}
return f.toURI().toURL();
}
项目:myqq
文件:ScreenFram.java
@Override
public void paint(Graphics g)
{
RescaleOp ro = new RescaleOp(0.8f, 0, null);
tempImage = ro.filter(image, null);
g.drawImage(tempImage, 0, 0, this);
}
项目:freecol
文件:TileViewer.java
/**
* Displays the given {@code Tile}.
*
* @param g The Graphics2D on which to draw the {@code Tile}.
* @param tile The {@code Tile} to draw.
* @param overlayImage The BufferedImage for the tile overlay.
*/
private void displayTile(Graphics2D g, Tile tile, BufferedImage overlayImage) {
displayTileWithBeachAndBorder(g, tile);
if (tile.isExplored()) {
RescaleOp rop = hasFogOfWar(tile)
? new RescaleOp(new float[] { 0.8f, 0.8f, 0.8f, 1f },
new float[] { 0, 0, 0, 0 },
null)
: null;
displayTileItems(g, tile, rop, overlayImage);
displaySettlementWithChipsOrPopulationNumber(g, tile, false, rop);
displayOptionalTileText(g, tile);
}
}
项目:OpenJSharp
文件:BufferedBufImgOps.java
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
项目:OpenJSharp
文件:BufferedBufImgOps.java
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
项目:OpenJSharp
文件:BufferedBufImgOps.java
/**************************** RescaleOp support *****************************/
public static boolean isRescaleOpValid(RescaleOp rop,
BufferedImage srcImg)
{
int numFactors = rop.getNumFactors();
ColorModel srcCM = srcImg.getColorModel();
if (srcCM instanceof IndexColorModel) {
throw new
IllegalArgumentException("Rescaling cannot be "+
"performed on an indexed image");
}
if (numFactors != 1 &&
numFactors != srcCM.getNumColorComponents() &&
numFactors != srcCM.getNumComponents())
{
throw new IllegalArgumentException("Number of scaling constants "+
"does not equal the number of"+
" of color or color/alpha "+
" components");
}
int csType = srcCM.getColorSpace().getType();
if (csType != ColorSpace.TYPE_RGB &&
csType != ColorSpace.TYPE_GRAY)
{
// Not prepared to deal with other color spaces
return false;
}
if (numFactors == 2 || numFactors > 4) {
// Not really prepared to handle this at the native level, so...
return false;
}
return true;
}
项目:ChessBot
文件:ChessBoardUtils.java
public static BufferedImage brighten(BufferedImage src, float level) {
BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
float[] scales = {2.2f, 2.2f, 2.2f};
float[] offsets = new float[4];
RescaleOp rop = new RescaleOp(scales, offsets, null);
Graphics2D g = dst.createGraphics();
g.drawImage(src, rop, 0, 0);
g.dispose();
return dst;
}
项目:jdk8u-jdk
文件:BufferedBufImgOps.java
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
项目:jdk8u-jdk
文件:BufferedBufImgOps.java
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
项目:jdk8u-jdk
文件:BufferedBufImgOps.java
/**************************** RescaleOp support *****************************/
public static boolean isRescaleOpValid(RescaleOp rop,
BufferedImage srcImg)
{
int numFactors = rop.getNumFactors();
ColorModel srcCM = srcImg.getColorModel();
if (srcCM instanceof IndexColorModel) {
throw new
IllegalArgumentException("Rescaling cannot be "+
"performed on an indexed image");
}
if (numFactors != 1 &&
numFactors != srcCM.getNumColorComponents() &&
numFactors != srcCM.getNumComponents())
{
throw new IllegalArgumentException("Number of scaling constants "+
"does not equal the number of"+
" of color or color/alpha "+
" components");
}
int csType = srcCM.getColorSpace().getType();
if (csType != ColorSpace.TYPE_RGB &&
csType != ColorSpace.TYPE_GRAY)
{
// Not prepared to deal with other color spaces
return false;
}
if (numFactors == 2 || numFactors > 4) {
// Not really prepared to handle this at the native level, so...
return false;
}
return true;
}