Search in sources :

Example 1 with ColorSpace

use of com.jme3.texture.image.ColorSpace in project jmonkeyengine by jMonkeyEngine.

the class Image method read.

public void read(JmeImporter e) throws IOException {
    InputCapsule capsule = e.getCapsule(this);
    format = capsule.readEnum("format", Format.class, Format.RGBA8);
    width = capsule.readInt("width", 0);
    height = capsule.readInt("height", 0);
    depth = capsule.readInt("depth", 0);
    mipMapSizes = capsule.readIntArray("mipMapSizes", null);
    multiSamples = capsule.readInt("multiSamples", 1);
    data = (ArrayList<ByteBuffer>) capsule.readByteBufferArrayList("data", null);
    colorSpace = capsule.readEnum("colorSpace", ColorSpace.class, null);
    if (mipMapSizes != null) {
        needGeneratedMips = false;
        mipsWereGenerated = true;
    }
}
Also used : InputCapsule(com.jme3.export.InputCapsule) ColorSpace(com.jme3.texture.image.ColorSpace) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ColorSpace

use of com.jme3.texture.image.ColorSpace in project jmonkeyengine by jMonkeyEngine.

the class MatParamTexture method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(0, "texture_unit", -1);
    // For backwards compatibility
    oc.write(texture, "texture", null);
    oc.write(colorSpace, "colorSpace", null);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 3 with ColorSpace

use of com.jme3.texture.image.ColorSpace in project jmonkeyengine by jMonkeyEngine.

the class MatParamTexture method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    texture = (Texture) value;
    colorSpace = (ColorSpace) ic.readEnum("colorSpace", ColorSpace.class, null);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 4 with ColorSpace

use of com.jme3.texture.image.ColorSpace in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readParam.

// <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [-LINEAR] [ ":" <DEFAULTVAL> ]
private void readParam(String statement) throws IOException {
    String name;
    String defaultVal = null;
    ColorSpace colorSpace = null;
    String[] split = statement.split(":");
    // Parse default val
    if (split.length == 1) {
    // Doesn't contain default value
    } else {
        if (split.length != 2) {
            throw new IOException("Parameter statement syntax incorrect");
        }
        statement = split[0].trim();
        defaultVal = split[1].trim();
    }
    if (statement.endsWith("-LINEAR")) {
        colorSpace = ColorSpace.Linear;
        statement = statement.substring(0, statement.length() - "-LINEAR".length());
    }
    // Parse ffbinding
    int startParen = statement.indexOf("(");
    if (startParen != -1) {
        // get content inside parentheses
        int endParen = statement.indexOf(")", startParen);
        String bindingStr = statement.substring(startParen + 1, endParen).trim();
        // don't care about bindingStr
        statement = statement.substring(0, startParen);
    }
    // Parse type + name
    split = statement.split(whitespacePattern);
    if (split.length != 2) {
        throw new IOException("Parameter statement syntax incorrect");
    }
    VarType type;
    if (split[0].equals("Color")) {
        type = VarType.Vector4;
    } else {
        type = VarType.valueOf(split[0]);
    }
    name = split[1];
    Object defaultValObj = null;
    if (defaultVal != null) {
        defaultValObj = readValue(type, defaultVal);
    }
    if (type.isTextureType()) {
        materialDef.addMaterialParamTexture(type, name, colorSpace);
    } else {
        materialDef.addMaterialParam(type, name, defaultValObj);
    }
}
Also used : ColorSpace(com.jme3.texture.image.ColorSpace) IOException(java.io.IOException)

Example 5 with ColorSpace

use of com.jme3.texture.image.ColorSpace in project jmonkeyengine by jMonkeyEngine.

the class ImageToAwt method convert.

public static BufferedImage convert(Image image, boolean do16bit, boolean fullalpha, int mipLevel) {
    Format format = image.getFormat();
    DecodeParams p = params.get(image.getFormat());
    if (p == null)
        throw new UnsupportedOperationException();
    int width = image.getWidth();
    int height = image.getHeight();
    int level = mipLevel;
    while (--level >= 0) {
        width /= 2;
        height /= 2;
    }
    ByteBuffer buf = image.getData(0);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    BufferedImage out;
    boolean alpha = false;
    boolean luminance = false;
    boolean rgb = false;
    if (p.am != 0)
        alpha = true;
    if (p.rm != 0 && p.gm == 0 && p.bm == 0)
        luminance = true;
    else if (p.rm != 0 && p.gm != 0 && p.bm != 0)
        rgb = true;
    // alpha OR luminance but not both
    if ((alpha && !rgb && !luminance) || (luminance && !alpha && !rgb)) {
        out = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    } else if ((rgb && alpha) || (luminance && alpha)) {
        if (do16bit) {
            if (fullalpha) {
                ColorModel model = AWTLoader.AWT_RGBA4444;
                WritableRaster raster = model.createCompatibleWritableRaster(width, width);
                out = new BufferedImage(model, raster, false, null);
            } else {
                // RGB5_A1
                ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
                int[] nBits = { 5, 5, 5, 1 };
                int[] bOffs = { 0, 1, 2, 3 };
                ColorModel colorModel = new ComponentColorModel(cs, nBits, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE);
                WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 2, 2, bOffs, null);
                out = new BufferedImage(colorModel, raster, false, null);
            }
        } else {
            out = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        }
    } else {
        if (do16bit) {
            out = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_565_RGB);
        } else {
            out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        }
    }
    int expansionA = 8 - Integer.bitCount(p.am);
    int expansionR = 8 - Integer.bitCount(p.rm);
    int expansionG = 8 - Integer.bitCount(p.gm);
    int expansionB = 8 - Integer.bitCount(p.bm);
    if (expansionR < 0) {
        expansionR = 0;
    }
    int mipPos = 0;
    for (int i = 0; i < mipLevel; i++) {
        mipPos += image.getMipMapSizes()[i];
    }
    int inputPixel;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int i = mipPos + (Ix(x, y, width) * p.bpp);
            inputPixel = (readPixel(buf, i, p.bpp) & p.im) >> p.is;
            int a = (inputPixel & p.am) >> p.as;
            int r = (inputPixel & p.rm) >> p.rs;
            int g = (inputPixel & p.gm) >> p.gs;
            int b = (inputPixel & p.bm) >> p.bs;
            r = r & 0xff;
            g = g & 0xff;
            b = b & 0xff;
            a = a & 0xff;
            a = a << expansionA;
            r = r << expansionR;
            g = g << expansionG;
            b = b << expansionB;
            if (luminance)
                b = g = r;
            if (!alpha)
                a = 0xff;
            int argb = (a << 24) | (r << 16) | (g << 8) | b;
            out.setRGB(x, y, argb);
        }
    }
    return out;
}
Also used : Format(com.jme3.texture.Image.Format) ColorSpace(java.awt.color.ColorSpace) ByteBuffer(java.nio.ByteBuffer)

Aggregations

InputCapsule (com.jme3.export.InputCapsule)2 OutputCapsule (com.jme3.export.OutputCapsule)2 ColorSpace (com.jme3.texture.image.ColorSpace)2 ByteBuffer (java.nio.ByteBuffer)2 Format (com.jme3.texture.Image.Format)1 ColorSpace (java.awt.color.ColorSpace)1 IOException (java.io.IOException)1