Search in sources :

Example 56 with WritableImage

use of javafx.scene.image.WritableImage in project Krothium-Launcher by DarkLBP.

the class TexturePreview method generateRight.

/**
 * Generates the right preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @return The generated preview image
 */
public static Image generateRight(Image skin, Image cape) {
    double h = skin.getHeight();
    PixelReader pr = skin.getPixelReader();
    WritableImage wi = new WritableImage(8, 32);
    PixelWriter pw = wi.getPixelWriter();
    if (h == 64) {
        // New format
        // MAIN ZONES
        // Head
        pw.setPixels(0, 0, 8, 8, pr, 0, 8);
        // Right Arm
        pw.setPixels(2, 8, 4, 12, pr, 40, 20);
        // Right Leg
        pw.setPixels(2, 20, 4, 12, pr, 0, 20);
        // EXTRA ZONES
        // Head
        renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
        // Right Arm
        renderLayer(2, 8, 4, 12, pr, pw, 40, 36);
        // Right Leg
        renderLayer(2, 20, 4, 12, pr, pw, 0, 36);
    } else if (h == 32) {
        // Legacy format
        // Head
        pw.setPixels(0, 0, 8, 8, pr, 0, 8);
        // Hat
        renderLayer(0, 0, 8, 8, pr, pw, 32, 8);
        // Right Arm
        pw.setPixels(2, 8, 4, 12, pr, 40, 20);
        // Right Leg
        pw.setPixels(2, 20, 4, 12, pr, 0, 20);
    }
    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(1, 8, 1, 16, pr2, 11, 1);
    }
    return wi;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter)

Example 57 with WritableImage

use of javafx.scene.image.WritableImage in project Krothium-Launcher by DarkLBP.

the class TexturePreview method generateBack.

/**
 * Generates the back preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @param slim If the format is slim
 * @return The generated preview image
 */
public static Image generateBack(Image skin, Image cape, boolean slim) {
    double h = skin.getHeight();
    PixelReader pr = skin.getPixelReader();
    WritableImage wi = new WritableImage(slim && h == 64 ? 14 : 16, 32);
    PixelWriter pw = wi.getPixelWriter();
    if (h == 64) {
        // New format
        // MAIN ZONES
        // Head
        pw.setPixels(slim ? 3 : 4, 0, 8, 8, pr, 24, 8);
        // Right Arm
        pw.setPixels(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, slim ? 51 : 52, 20);
        // Left Arm
        pw.setPixels(0, 8, slim ? 3 : 4, 12, pr, slim ? 43 : 44, 52);
        // Body
        pw.setPixels(slim ? 3 : 4, 8, 8, 12, pr, 32, 20);
        // Right Leg
        pw.setPixels(slim ? 7 : 8, 20, 4, 12, pr, 12, 20);
        // Left Leg
        pw.setPixels(slim ? 3 : 4, 20, 4, 12, pr, 28, 52);
        // EXTRA ZONES
        // Head
        renderLayer(slim ? 3 : 4, 0, 8, 8, pr, pw, 56, 8);
        // Right Arm
        renderLayer(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, pw, slim ? 51 : 52, 36);
        // Left Arm
        renderLayer(0, 8, slim ? 3 : 4, 12, pr, pw, slim ? 59 : 60, 52);
        // Body
        renderLayer(slim ? 3 : 4, 8, 8, 12, pr, pw, 32, 36);
        // Right Leg
        renderLayer(slim ? 7 : 8, 20, 4, 12, pr, pw, 12, 36);
        // Left Leg
        renderLayer(slim ? 3 : 4, 20, 4, 12, pr, pw, 12, 52);
    } else if (h == 32) {
        // Legacy format
        // Head
        pw.setPixels(4, 0, 8, 8, pr, 24, 8);
        // Hat
        renderLayer(4, 0, 8, 8, pr, pw, 56, 8);
        // Right Arm
        pw.setPixels(12, 8, 4, 12, pr, 52, 20);
        // Left Arm
        renderLayerInverse(0, 8, 4, 12, pr, pw, 52, 20);
        // Body
        pw.setPixels(4, 8, 8, 12, pr, 32, 20);
        // Right Leg
        pw.setPixels(8, 20, 4, 12, pr, 12, 20);
        // Left Leg
        renderLayerInverse(4, 20, 4, 12, pr, pw, 12, 20);
    }
    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(slim && h == 64 ? 2 : 3, 8, 10, 16, pr2, 1, 1);
    }
    return wi;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter)

Example 58 with WritableImage

use of javafx.scene.image.WritableImage in project Krothium-Launcher by DarkLBP.

the class TexturePreview method resampleImage.

/**
 * This method receives an image scales it
 *
 * @param input       Input image
 * @param scaleFactor Output scale factor
 * @return The resampled image
 */
public static Image resampleImage(Image input, int scaleFactor) {
    int W = (int) input.getWidth();
    int H = (int) input.getHeight();
    WritableImage output = new WritableImage(W * scaleFactor, H * scaleFactor);
    PixelReader reader = input.getPixelReader();
    PixelWriter writer = output.getPixelWriter();
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            int argb = reader.getArgb(x, y);
            for (int dy = 0; dy < scaleFactor; dy++) {
                for (int dx = 0; dx < scaleFactor; dx++) {
                    writer.setArgb(x * scaleFactor + dx, y * scaleFactor + dy, argb);
                }
            }
        }
    }
    return output;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter)

Example 59 with WritableImage

use of javafx.scene.image.WritableImage in project Krothium-Launcher by DarkLBP.

the class TexturePreview method generateFront.

/**
 * Generates the front preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @param slim If the format is slim
 * @return The generated preview image
 */
public static Image generateFront(Image skin, Image cape, boolean slim) {
    double h = skin.getHeight();
    PixelReader pr = skin.getPixelReader();
    WritableImage wi = new WritableImage(slim && h == 64 ? 14 : 16, 32);
    PixelWriter pw = wi.getPixelWriter();
    if (h == 64) {
        // New format
        // MAIN ZONES
        // Head
        pw.setPixels(slim ? 3 : 4, 0, 8, 8, pr, 8, 8);
        // Right Arm
        pw.setPixels(0, 8, slim ? 3 : 4, 12, pr, 44, 20);
        // Left Arm
        pw.setPixels(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, 36, 52);
        // Body
        pw.setPixels(slim ? 3 : 4, 8, 8, 12, pr, 20, 20);
        // Right Leg
        pw.setPixels(slim ? 3 : 4, 20, 4, 12, pr, 4, 20);
        // Left Leg
        pw.setPixels(slim ? 7 : 8, 20, 4, 12, pr, 20, 52);
        // EXTRA ZONES
        // Head
        renderLayer(slim ? 3 : 4, 0, 8, 8, pr, pw, 40, 8);
        // Right Arm
        renderLayer(0, 8, slim ? 3 : 4, 12, pr, pw, 44, 36);
        // Left Arm
        renderLayer(slim ? 11 : 12, 8, slim ? 3 : 4, 12, pr, pw, 52, 52);
        // Body
        renderLayer(slim ? 3 : 4, 8, 8, 12, pr, pw, 20, 36);
        // Right Leg
        renderLayer(slim ? 3 : 4, 20, 4, 12, pr, pw, 4, 36);
        // Left Leg
        renderLayer(slim ? 7 : 8, 20, 4, 12, pr, pw, 4, 52);
    } else if (h == 32) {
        // Head
        pw.setPixels(4, 0, 8, 8, pr, 8, 8);
        // Hat
        renderLayer(4, 0, 8, 8, pr, pw, 40, 8);
        // Right Arm
        pw.setPixels(0, 8, 4, 12, pr, 44, 20);
        // Left Arm
        renderLayerInverse(12, 8, 4, 12, pr, pw, 44, 20);
        // Body
        pw.setPixels(4, 8, 8, 12, pr, 20, 20);
        // Right Leg
        pw.setPixels(4, 20, 4, 12, pr, 4, 20);
        // Left Leg
        renderLayerInverse(8, 20, 4, 12, pr, pw, 4, 20);
    }
    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(slim && h == 64 ? 2 : 3, 20, 1, 4, pr2, 12, 1);
        pw.setPixels(slim && h == 64 ? 11 : 12, 20, 1, 4, pr2, 21, 1);
    }
    return wi;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter)

Example 60 with WritableImage

use of javafx.scene.image.WritableImage in project TestFX by TestFX.

the class GlassRobotAdapter method convertFromGlassPixels.

private Image convertFromGlassPixels(Pixels glassPixels) {
    int width = glassPixels.getWidth();
    int height = glassPixels.getHeight();
    WritableImage image = new WritableImage(width, height);
    int bytesPerComponent = glassPixels.getBytesPerComponent();
    if (bytesPerComponent == INT_BUFFER_BYTES_PER_COMPONENT) {
        IntBuffer intBuffer = (IntBuffer) glassPixels.getPixels();
        writeIntBufferToImage(intBuffer, image);
    } else if (bytesPerComponent == BYTE_BUFFER_BYTES_PER_COMPONENT) {
        ByteBuffer byteBuffer = (ByteBuffer) glassPixels.getPixels();
        writeByteBufferToImage(byteBuffer, image);
    }
    return image;
}
Also used : WritableImage(javafx.scene.image.WritableImage) IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

WritableImage (javafx.scene.image.WritableImage)74 SnapshotParameters (javafx.scene.SnapshotParameters)26 PixelWriter (javafx.scene.image.PixelWriter)23 PixelReader (javafx.scene.image.PixelReader)13 IOException (java.io.IOException)12 Color (javafx.scene.paint.Color)11 BufferedImage (java.awt.image.BufferedImage)9 File (java.io.File)8 Image (javafx.scene.image.Image)7 ImageView (javafx.scene.image.ImageView)7 Point2D (javafx.geometry.Point2D)6 Group (javafx.scene.Group)5 Random (java.util.Random)4 Canvas (javafx.scene.canvas.Canvas)4 GraphicsContext (javafx.scene.canvas.GraphicsContext)4 Texture (com.almasb.fxgl.texture.Texture)3 OutputStream (java.io.OutputStream)3 Scene (javafx.scene.Scene)3 Background (javafx.scene.layout.Background)3 Scale (javafx.scene.transform.Scale)3