|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 jMonkeyEngine |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * |
| 12 | + * * Redistributions in binary form must reproduce the above copyright |
| 13 | + * notice, this list of conditions and the following disclaimer in the |
| 14 | + * documentation and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | +package org.jmonkeyengine.screenshottests.texture; |
| 33 | + |
| 34 | +import com.jme3.app.Application; |
| 35 | +import com.jme3.app.SimpleApplication; |
| 36 | +import com.jme3.app.state.BaseAppState; |
| 37 | +import com.jme3.texture.Texture; |
| 38 | +import com.jme3.texture.Texture2D; |
| 39 | +import com.jme3.ui.Picture; |
| 40 | +import org.jmonkeyengine.screenshottests.testframework.ScreenshotTestBase; |
| 41 | +import org.jmonkeyengine.screenshottests.testframework.TestResolution; |
| 42 | +import org.junit.jupiter.api.Test; |
| 43 | + |
| 44 | +/** |
| 45 | + * Screenshot test for single-channel PNG loading. |
| 46 | + */ |
| 47 | +public class TestSingleChannelTexture extends ScreenshotTestBase { |
| 48 | + |
| 49 | + private static final int TEXTURE_SIZE = 251; |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testSingleChannelTexture() { |
| 53 | + screenshotTest(new BaseAppState() { |
| 54 | + @Override |
| 55 | + protected void initialize(Application app) { |
| 56 | + SimpleApplication simpleApplication = (SimpleApplication) app; |
| 57 | + |
| 58 | + attachPicture(simpleApplication, "single-channel-r16", |
| 59 | + "Textures/singleChannel/R16.png", 0f); |
| 60 | + attachPicture(simpleApplication, "single-channel-r8", |
| 61 | + "Textures/singleChannel/R8.png", TEXTURE_SIZE); |
| 62 | + } |
| 63 | + |
| 64 | + private void attachPicture(SimpleApplication app, String name, String texturePath, float x) { |
| 65 | + Texture texture = app.getAssetManager().loadTexture(texturePath); |
| 66 | + Picture picture = new Picture(name); |
| 67 | + picture.setTexture(app.getAssetManager(), (Texture2D) texture, false); |
| 68 | + picture.setPosition(x, 0f); |
| 69 | + picture.setWidth(TEXTURE_SIZE); |
| 70 | + picture.setHeight(TEXTURE_SIZE); |
| 71 | + app.getGuiNode().attachChild(picture); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + protected void cleanup(Application app) { |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected void onEnable() { |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + protected void onDisable() { |
| 84 | + } |
| 85 | + }) |
| 86 | + .setTestResolution(new TestResolution(TEXTURE_SIZE * 2, TEXTURE_SIZE)) |
| 87 | + .setFramesToTakeScreenshotsOn(1) |
| 88 | + .run(); |
| 89 | + } |
| 90 | +} |
0 commit comments