Search in sources :

Example 1 with FrameData

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());
            }
        }
    }
}
Also used : DeviceData(com.android.tools.idea.ddms.screenshot.DeviceArtPainter.DeviceData) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) FrameData(com.android.tools.idea.ddms.screenshot.DeviceArtPainter.FrameData) Ignore(org.junit.Ignore) DeviceSchemaTest(com.android.dvlib.DeviceSchemaTest) Test(org.junit.Test)

Example 2 with FrameData

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("\"");
    }
}
Also used : ImageUtils(com.android.tools.idea.rendering.ImageUtils) Device(com.android.sdklib.devices.Device) DeviceData(com.android.tools.idea.ddms.screenshot.DeviceArtPainter.DeviceData) BufferedImage(java.awt.image.BufferedImage) FrameData(com.android.tools.idea.ddms.screenshot.DeviceArtPainter.FrameData)

Aggregations

DeviceData (com.android.tools.idea.ddms.screenshot.DeviceArtPainter.DeviceData)2 FrameData (com.android.tools.idea.ddms.screenshot.DeviceArtPainter.FrameData)2 BufferedImage (java.awt.image.BufferedImage)2 DeviceSchemaTest (com.android.dvlib.DeviceSchemaTest)1 Device (com.android.sdklib.devices.Device)1 ImageUtils (com.android.tools.idea.rendering.ImageUtils)1 File (java.io.File)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1