use of com.android.tools.idea.ddms.screenshot.DeviceArtPainter.FrameData in project android by JetBrains.
the class DeviceArtPainterTest method testRendering.
// This test is disabled but code is preserved here; this is handy for quickly checking rendering results when tweaking the code to
// assemble composite images. (Make sure you also turn off the thumbnail cache first! Return null from DeviceArtPainter#getCachedImage.)
@Test
@Ignore
public void testRendering() throws Exception {
DeviceArtPainter framePainter = DeviceArtPainter.getInstance();
for (DeviceArtDescriptor spec : framePainter.getDescriptors()) {
if ("wear_round".equals(spec.getId())) {
FrameData frameData = new DeviceData(null, spec).getFrameData(ScreenOrientation.LANDSCAPE, 320);
BufferedImage image = frameData.getImage(true);
@SuppressWarnings("SSBasedInspection") File file = File.createTempFile("test-rendering", "png");
if (file.exists()) {
boolean deleted = file.delete();
assertTrue(deleted);
}
ImageIO.write(image, "PNG", file);
if (file.exists() && SystemInfo.isMac) {
Runtime.getRuntime().exec("/usr/bin/open " + file.getPath());
}
}
}
}
use of com.android.tools.idea.ddms.screenshot.DeviceArtPainter.FrameData in project android by JetBrains.
the class DeviceArtPainterTest method generateCropData.
public void generateCropData() throws Exception {
DeviceArtPainter framePainter = DeviceArtPainter.getInstance();
Device device = newDevice();
for (DeviceArtDescriptor spec : framePainter.getDescriptors()) {
DeviceData data = new DeviceData(device, spec);
Rectangle cropRect = spec.getCrop(ScreenOrientation.LANDSCAPE);
if (spec.getName().startsWith("Generic ")) {
// No crop data for generic nine patches since they are stretchable
continue;
}
if (cropRect != null && !cropRect.getSize().equals(spec.getScreenSize(ScreenOrientation.LANDSCAPE))) {
// Already have crop data for this spec; skipping
continue;
}
if (spec.getName().startsWith("Android TV")) {
// These images are already cropped
continue;
}
System.out.println("for spec " + spec.getName() + " -- " + spec.getId());
FrameData landscapeData = data.getFrameData(ScreenOrientation.LANDSCAPE, Integer.MAX_VALUE);
// Must use computeImage rather than getImage here since we want to get the
// full size images, not the already cropped images
BufferedImage effectsImage;
Rectangle crop;
ImageUtils.CropFilter filter = new ImageUtils.CropFilter() {
@Override
public boolean crop(BufferedImage bufferedImage, int x, int y) {
int rgb = bufferedImage.getRGB(x, y);
return ((rgb & 0xFF000000) >>> 24) < 2;
}
};
FrameData portraitData = data.getFrameData(ScreenOrientation.PORTRAIT, Integer.MAX_VALUE);
try {
effectsImage = portraitData.computeImage(true, 0, 0, portraitData.getFrameWidth(), portraitData.getFrameHeight());
} catch (OutOfMemoryError oome) {
// This test sometimes fails on the build server because it runs out of memory; it's a memory
// hungry test which sometimes fails when run as part of thousands of other tests.
// Ignore those types of failures.
// Make sure it's not failing to allocate memory due to some crazy large bounds we didn't anticipate:
assertTrue(portraitData.getFrameWidth() < 4000);
assertTrue(portraitData.getFrameHeight() < 4000);
return;
}
assertNotNull(effectsImage);
crop = ImageUtils.getCropBounds(effectsImage, filter, null);
assertNotNull(crop);
System.out.print(" port crop=\"");
System.out.print(crop.x);
System.out.print(",");
System.out.print(crop.y);
System.out.print(",");
System.out.print(crop.width);
System.out.print(",");
System.out.print(crop.height);
System.out.println("\"");
try {
effectsImage = landscapeData.computeImage(true, 0, 0, landscapeData.getFrameWidth(), landscapeData.getFrameHeight());
} catch (OutOfMemoryError oome) {
// See portrait case above
assertTrue(landscapeData.getFrameWidth() < 4000);
assertTrue(landscapeData.getFrameHeight() < 4000);
return;
}
assertNotNull(effectsImage);
crop = ImageUtils.getCropBounds(effectsImage, filter, null);
assertNotNull(crop);
System.out.print(" landscape crop=\"");
System.out.print(crop.x);
System.out.print(",");
System.out.print(crop.y);
System.out.print(",");
System.out.print(crop.width);
System.out.print(",");
System.out.print(crop.height);
System.out.println("\"");
}
}
Aggregations