use of java.awt.image.BufferedImage in project MinecraftForge by MinecraftForge.
the class TextureDump method saveGlTexture.
public static void saveGlTexture(String name, int textureId, int mipmapLevels) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
for (int level = 0; level <= mipmapLevels; level++) {
int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH);
int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT);
int size = width * height;
BufferedImage bufferedimage = new BufferedImage(width, height, 2);
File output = new File("texture_atlas_dump_" + name + "_mipmap_" + level + ".png");
IntBuffer buffer = BufferUtils.createIntBuffer(size);
int[] data = new int[size];
GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
buffer.get(data);
bufferedimage.setRGB(0, 0, width, height, data, 0, width);
try {
ImageIO.write(bufferedimage, "png", output);
FMLLog.info("[TextureDump] Exported png to: %s", output.getAbsolutePath());
} catch (IOException ioexception) {
FMLLog.info("[TextureDump] Unable to write: ", ioexception);
}
}
}
use of java.awt.image.BufferedImage in project screenbird by adamhub.
the class PreviewPlayer method setScreenshot.
/**
* Sets the displayed screenshot on the PreviewPlayer.
* @param screenshot BufferedImage object of the screenshot to be displayed
* @param center Not used
* @param show true if to display PreviewPlayer after setting the displayed screenshot
*/
public void setScreenshot(final BufferedImage screenshot, boolean center, boolean show) {
BufferedImage image = screenshot;
// Get image size
imageSize.width = image.getWidth();
imageSize.height = image.getHeight();
Dimension displaySize = ScreenUtil.getScreenDimension(getGraphicsConfiguration().getDevice());
// Scale images if dimensions are larger than the current screen
if (imageSize.width > displaySize.width || imageSize.height > displaySize.height) {
// Allows previewing of larger external displays
// Adjust for full screen preview from external display
screenshotSize.width = (int) (displaySize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
screenshotSize.height = (int) (displaySize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
} else if (screenSize.equals(imageSize)) {
// For fullscreen display
// Adjust for full screen preview
screenshotSize.width = (int) (imageSize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
screenshotSize.height = (int) (imageSize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
} else {
// Adjust for custom screen preview
if (1.0 * (imageSize.width + 100) / displaySize.width >= Settings.FULLSCREEN_PREVIEW_SCALE || 1.0 * (imageSize.height + 100) / displaySize.height >= Settings.FULLSCREEN_PREVIEW_SCALE) {
screenshotSize.width = (int) (displaySize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
screenshotSize.height = (int) (displaySize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
} else {
screenshotSize.width = (int) (imageSize.width * Settings.CUSTOMSCREEN_PREVIEW_SCALE);
screenshotSize.height = (int) (imageSize.height * Settings.CUSTOMSCREEN_PREVIEW_SCALE);
}
}
// Change screen size
loadPlayerOffset();
this.jpImage.setImage(screenshot, screenshotSize.width, screenshotSize.height);
ScreenUtil.changeSize(jfPreviewPlayer.getFrame(), new Dimension(playerSize.width, playerSize.height));
if (centerPreviewPlayer) {
this.jfPreviewPlayer.loadSmartPosition(show);
}
}
use of java.awt.image.BufferedImage in project screenbird by adamhub.
the class PreviewPlayerTest method generateTestImageFile.
/**
* Generates screenshot for JUnit testing
* @return
* File pointer to screen shot
*/
private File generateTestImageFile(Rectangle captureArea) {
Robot awtRobot;
String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
if (captureArea == null) {
//Get full screen if no defined area of screen capture is defined
captureArea = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
try {
BufferedImage bufferedImage = generateTestImage(captureArea);
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1.0F);
File imageFile = new File(currentCaptureDir, "test.jpeg");
FileImageOutputStream stream = new FileImageOutputStream(imageFile);
//Set up file access
writer.setOutput(stream);
//Create image
IIOImage image = new IIOImage(bufferedImage, null, null);
//write image
writer.write(null, image, iwp);
//Close image stream
stream.close();
return imageFile;
} catch (IOException e) {
System.err.println(e);
}
return null;
}
use of java.awt.image.BufferedImage in project screenbird by adamhub.
the class PreviewPlayerTest method testSetScreenshot_BufferedImage.
/**
* Test of setScreenshot method, of class PreviewPlayer.
*/
@Test
public void testSetScreenshot_BufferedImage() {
System.out.println("setScreenshot");
BufferedImage screenshot = generateTestImage(null);
instance.setScreenshot(screenshot);
instance.setScreenshot(screenshot);
instance.updateRecordNowButtonPosition();
TimeUtil.skipToMyLou(2);
screenshot = generateTestImage(new Rectangle(0, 0, 600, 400));
instance.setScreenshot(screenshot);
instance.setScreenshot(screenshot);
instance.updateRecordNowButtonPosition();
TimeUtil.skipToMyLou(2);
screenshot = generateTestImage(new Rectangle(100, 100, 600, 400));
instance.setScreenshot(screenshot);
instance.setScreenshot(screenshot);
instance.updateRecordNowButtonPosition();
TimeUtil.skipToMyLou(2);
screenshot = generateTestImage(null);
instance.setScreenshot(screenshot);
instance.setScreenshot(screenshot);
instance.updateRecordNowButtonPosition();
TimeUtil.skipToMyLou(2);
}
use of java.awt.image.BufferedImage in project screenbird by adamhub.
the class VideoCacheTest method generateTestImage.
/**
* Generates screenshot for JUnit testing
* @return
* File pointer to screen shot
*/
private File generateTestImage() {
Robot awtRobot;
String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
try {
awtRobot = new Robot();
BufferedImage bufferedImage = awtRobot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1.0F);
File imageFile = new File(currentCaptureDir, "test.jpeg");
FileImageOutputStream stream = new FileImageOutputStream(imageFile);
//Set up file access
writer.setOutput(stream);
//Create image
IIOImage image = new IIOImage(bufferedImage, null, null);
//write image
writer.write(null, image, iwp);
//Close image stream
stream.close();
return imageFile;
} catch (AWTException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
}
return null;
}
Aggregations