Search in sources :

Example 16 with PixelReader

use of javafx.scene.image.PixelReader 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 17 with PixelReader

use of javafx.scene.image.PixelReader 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 18 with PixelReader

use of javafx.scene.image.PixelReader 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 19 with PixelReader

use of javafx.scene.image.PixelReader 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 20 with PixelReader

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

the class TexturePreview method generateLeft.

/**
 * Generates the left preview of the skin
 * @param skin The skin image
 * @param cape The cape image
 * @return The generated preview image
 */
public static Image generateLeft(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, 16, 8);
        // Left Arm
        pw.setPixels(2, 8, 4, 12, pr, 40, 52);
        // Left Leg
        pw.setPixels(2, 20, 4, 12, pr, 24, 52);
        // EXTRA ZONES
        // Head
        renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
        // Left Arm
        renderLayer(2, 8, 4, 12, pr, pw, 56, 52);
        // Left Leg
        renderLayer(2, 20, 4, 12, pr, pw, 8, 52);
    } else if (h == 32) {
        // Legacy format
        // Head
        pw.setPixels(0, 0, 8, 8, pr, 16, 8);
        // Hat
        renderLayer(0, 0, 8, 8, pr, pw, 48, 8);
        // Left Arm
        renderLayerInverse(2, 8, 4, 12, pr, pw, 40, 20);
        // Left Leg
        renderLayerInverse(2, 20, 4, 12, pr, pw, 0, 20);
    }
    if (cape != null) {
        PixelReader pr2 = cape.getPixelReader();
        pw.setPixels(6, 8, 1, 16, pr2, 0, 1);
    }
    return wi;
}
Also used : WritableImage(javafx.scene.image.WritableImage) PixelReader(javafx.scene.image.PixelReader) PixelWriter(javafx.scene.image.PixelWriter)

Aggregations

PixelReader (javafx.scene.image.PixelReader)20 WritableImage (javafx.scene.image.WritableImage)18 PixelWriter (javafx.scene.image.PixelWriter)12 SnapshotParameters (javafx.scene.SnapshotParameters)6 Image (javafx.scene.image.Image)5 Color (javafx.scene.paint.Color)5 IntStream (java.util.stream.IntStream)4 Rectangle2D (javafx.geometry.Rectangle2D)3 Node (javafx.scene.Node)3 Platform (javafx.application.Platform)2 Bounds (javafx.geometry.Bounds)2 ImageView (javafx.scene.image.ImageView)2 Pair (javafx.util.Pair)2 WaitForAsyncUtils (org.testfx.util.WaitForAsyncUtils)2 TimeoutTransition (io.github.interacto.fsm.TimeoutTransition)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1 IntBuffer (java.nio.IntBuffer)1