Search in sources :

Example 1 with SimpleHDRImage

use of org.jwildfire.image.SimpleHDRImage in project JWildfire by thargor6.

the class ScriptProcessor method executeTransformer.

public TransformResult executeTransformer(String pInputName, boolean pStoreMesh3D, String pOutputName, String pOutput3DName, boolean pRecordAction) {
    Buffer inBuffer = bufferList.bufferByName(pInputName);
    if (inBuffer == null) {
        dumpBuffers();
        throw new RuntimeException("Input buffer <" + pInputName + "> not found");
    }
    SimpleImage newImg = null;
    SimpleHDRImage newHDRImg = null;
    if (inBuffer.getBufferType() == BufferType.IMAGE) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        newImg = inBuffer.getImage().clone();
        transformer.transformImage(newImg);
    } else if (inBuffer.getBufferType() == BufferType.HDR_IMAGE) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        newHDRImg = inBuffer.getHDRImage().clone();
        transformer.transformImage(newHDRImg);
    } else if (inBuffer.getBufferType() == BufferType.MESH3D) {
        transformer.setStoreMesh3D(pStoreMesh3D);
        Mesh3D mesh3D = inBuffer.getMesh3D();
        newImg = new SimpleImage(mesh3D.getImageWidth(), mesh3D.getImageHeight());
        transformer.setInputMesh3D(mesh3D);
        transformer.transformImage(newImg);
    }
    Buffer outBuffer = null;
    if (newImg != null) {
        outBuffer = bufferList.addImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newImg);
        if ((pOutputName != null) && (pOutputName.length() > 0))
            outBuffer.setName(pOutputName);
    }
    Buffer outHDRBuffer = null;
    if (newHDRImg != null) {
        outHDRBuffer = bufferList.addHDRImageBuffer(addBuffersToDesktop ? desktop : null, transformer.getName(), newHDRImg);
        if ((pOutputName != null) && (pOutputName.length() > 0))
            outHDRBuffer.setName(pOutputName);
    }
    Buffer outBuffer3D = null;
    if (pStoreMesh3D) {
        ScaleTransformer scaleT = new ScaleTransformer();
        scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
        scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
        scaleT.setScaleWidth(120);
        SimpleImage scaledImg = newImg.clone();
        scaleT.transformImage(scaledImg);
        outBuffer3D = bufferList.addMesh3DBuffer(addBuffersToDesktop ? desktop : null, pInputName, transformer.getOutputMesh3D(true), scaledImg);
        if ((pOutput3DName != null) && (pOutput3DName.length() > 0))
            outBuffer3D.setName(pOutput3DName);
    }
    return new TransformResult(inBuffer, outBuffer, outHDRBuffer, outBuffer3D);
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) Mesh3D(org.jwildfire.transform.Mesh3D) SimpleImage(org.jwildfire.image.SimpleImage) ScaleTransformer(org.jwildfire.transform.ScaleTransformer)

Example 2 with SimpleHDRImage

use of org.jwildfire.image.SimpleHDRImage in project JWildfire by thargor6.

the class ImageFilePreview method createThumbnail.

public void createThumbnail() {
    if (currFile == null) {
        currThumbnail = null;
        return;
    }
    try {
        if (currFile.exists()) {
            String fileExt = null;
            {
                String filename = currFile.getName();
                int p = filename.lastIndexOf(".");
                if (p >= 0 && p < filename.length() - 2) {
                    fileExt = filename.substring(p + 1, filename.length());
                }
            }
            if ("hdr".equalsIgnoreCase(fileExt)) {
                SimpleHDRImage hdrImg = new ImageReader(this).loadHDRImage(currFile.getAbsolutePath());
                SimpleImage img = new FastHDRTonemapper().renderImage(hdrImg);
                ScaleTransformer scaleT = new ScaleTransformer();
                scaleT.setScaleWidth(THUMBNAIL_WIDTH);
                scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
                scaleT.setUnit(Unit.PIXELS);
                scaleT.transformImage(img);
                currThumbnail = new ImageIcon(img.getBufferedImg(), currFile.getName());
            } else {
                ImageIcon tmpIcon = new ImageIcon(currFile.getPath());
                if (tmpIcon != null) {
                    if (tmpIcon.getIconWidth() > THUMBNAIL_WIDTH) {
                        currThumbnail = new ImageIcon(tmpIcon.getImage().getScaledInstance(THUMBNAIL_WIDTH, -1, Image.SCALE_DEFAULT));
                    } else {
                        currThumbnail = tmpIcon;
                    }
                }
            }
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) FastHDRTonemapper(org.jwildfire.image.FastHDRTonemapper) ScaleTransformer(org.jwildfire.transform.ScaleTransformer) ImageReader(org.jwildfire.io.ImageReader)

Example 3 with SimpleHDRImage

use of org.jwildfire.image.SimpleHDRImage in project JWildfire by thargor6.

the class AbstractDisplacementMapWFFunc method transform.

public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount, double pInputX, double pInputY) {
    double x = (pInputX - (offsetX + 0.5) + 1.0) / scaleX * (double) (imgWidth - 1);
    double y = (pInputY - (offsetY + 0.5) + 1.0) / scaleY * (double) (imgHeight - 1);
    int ix = Tools.FTOI(x);
    int iy = Tools.FTOI(y);
    if (this.tileX == 1) {
        if (ix < 0) {
            int nx = ix / imgWidth - 1;
            ix -= nx * imgWidth;
        } else if (ix >= imgWidth) {
            int nx = ix / imgWidth;
            ix -= nx * imgWidth;
        }
    }
    if (this.tileY == 1) {
        if (iy < 0) {
            int ny = iy / imgHeight - 1;
            iy -= ny * imgHeight;
        } else if (iy >= imgHeight) {
            int ny = iy / imgHeight;
            iy -= ny * imgHeight;
        }
    }
    double r, g, b;
    if (ix >= 0 && ix < imgWidth && iy >= 0 && iy < imgHeight) {
        if (colorMap instanceof SimpleImage) {
            toolPixel.setARGBValue(((SimpleImage) colorMap).getARGBValue(ix, iy));
            r = (double) toolPixel.r / 255.0;
            g = (double) toolPixel.g / 255.0;
            b = (double) toolPixel.b / 255.0;
        } else {
            ((SimpleHDRImage) colorMap).getRGBValues(rgbArray, ix, iy);
            r = rgbArray[0];
            g = rgbArray[0];
            b = rgbArray[0];
        }
    } else {
        return;
    }
    switch(mode) {
        case MODE_TRANSLATE:
            {
                double amountX = (r - 0.5) * pAmount;
                double amountY = (g - 0.5) * pAmount;
                pVarTP.x += amountX;
                pVarTP.y += amountY;
            }
            break;
        case MODE_SCALE:
            {
                double intensity = calcIntensity(r, g, b) - bias;
                if (intensity > 0.0) {
                    double scl = 1.0 + (intensity - 0.5) * pAmount;
                    pVarTP.x *= scl;
                    pVarTP.y *= scl;
                }
            }
            break;
        case MODE_SCISSOR:
            {
                double amountX = (r - 0.5) * pAmount;
                double amountY = (g - 0.5) * pAmount;
                double newx = pVarTP.x * amountX * amountY + pVarTP.y * amountY;
                double newy = pVarTP.x * amountY - pVarTP.y * amountX * amountY;
                pVarTP.x = newx;
                pVarTP.y = newy;
            }
            break;
        case MODE_ROTATE:
        default:
            {
                double intensity = calcIntensity(r, g, b) - bias;
                if (intensity > 0.0) {
                    double angle = intensity * M_2PI * pAmount;
                    double sina = sin(angle);
                    double cosa = cos(angle);
                    double xnew = pVarTP.x * cosa - pVarTP.y * sina;
                    double ynew = pVarTP.x * sina + pVarTP.y * cosa;
                    pVarTP.x = xnew;
                    pVarTP.y = ynew;
                }
            }
    }
    switch(colorMode) {
        case COLOR_MODE_INHERIT:
            {
                pVarTP.rgbColor = true;
                pVarTP.redColor = r;
                pVarTP.greenColor = g;
                pVarTP.blueColor = b;
                pVarTP.color = getColorIdx(r, g, b);
            }
            break;
        default:
            // nothing to do
            break;
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 4 with SimpleHDRImage

use of org.jwildfire.image.SimpleHDRImage in project JWildfire by thargor6.

the class PostBumpMapWFFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    double x = (pAffineTP.x - offsetX + 1.0) / scaleX * 0.5 * (double) (imgWidth - 1);
    double y = (pAffineTP.y - offsetY + 1.0) / scaleY * 0.5 * (double) (imgHeight - 1);
    double dz = offsetZ;
    int ix = Tools.FTOI(x);
    int iy = Tools.FTOI(y);
    if (ix >= 0 && ix < imgWidth && iy >= 0 && iy < imgHeight) {
        double intensity;
        if (bumpMap instanceof SimpleImage) {
            toolPixel.setARGBValue(((SimpleImage) bumpMap).getARGBValue(ix, iy));
            double r = toolPixel.r;
            double g = toolPixel.g;
            double b = toolPixel.b;
            intensity = (0.299 * r + 0.588 * g + 0.113 * b) / 255.0;
        } else {
            ((SimpleHDRImage) bumpMap).getRGBValues(rgbArray, ix, iy);
            double r = rgbArray[0];
            double g = rgbArray[0];
            double b = rgbArray[0];
            intensity = (0.299 * r + 0.588 * g + 0.113 * b);
        }
        dz += scaleZ * intensity;
        if (resetZ != 0) {
            pVarTP.z = dz;
        } else {
            pVarTP.z += dz;
        }
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 5 with SimpleHDRImage

use of org.jwildfire.image.SimpleHDRImage in project JWildfire by thargor6.

the class Bump3DTransformer method transformMesh.

@Override
protected void transformMesh(Mesh3D pMesh3D, int pImageWidth, int pImageHeight) {
    int pCount = pMesh3D.getPCount();
    int width = pImageWidth;
    int height = pImageHeight;
    double[] x = pMesh3D.getX();
    double[] y = pMesh3D.getY();
    double[] z = pMesh3D.getZ();
    WFImage heightMap = this.heightMap.getHDRImage();
    if (heightMap != null) {
        int hwidth = heightMap.getImageWidth();
        int hheight = heightMap.getImageHeight();
        if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
            throw new IllegalArgumentException("Heightmap has the wrong size (scaling of HDR images currently not supported)");
        }
        float[] lum = new float[2];
        ((SimpleHDRImage) heightMap).getMinMaxLum(lum);
        lumMin = lum[0];
        lumMax = lum[1];
        lumRange = lumMax - lumMin;
    } else {
        heightMap = this.heightMap.getImage();
        int hwidth = heightMap.getImageWidth();
        int hheight = heightMap.getImageHeight();
        if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
            SimpleImage scaledHeightMap = ((SimpleImage) heightMap).clone();
            ScaleTransformer scaleT = new ScaleTransformer();
            scaleT.setAspect(this.aspect);
            scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
            scaleT.setScaleWidth(this.hWidth);
            scaleT.setScaleHeight(this.hHeight);
            scaleT.performImageTransformation(scaledHeightMap);
            heightMap = scaledHeightMap;
        }
    }
    double amount = 0.0 - this.amount;
    int dx = hLeft - width / 2;
    int dy = hTop - height / 2;
    if (hCentre) {
        dx += (width - this.hWidth) / 2;
        dy += (height - this.hHeight) / 2;
    }
    double[][] weights, intArray;
    if (this.smoothingMatrix == SmoothingMatrix.MATRIX_3x3) {
        int smoothSize = 3;
        weights = weights_3x3;
        intArray = new double[smoothSize][smoothSize];
    } else {
        int smoothSize = 5;
        weights = weights_5x5;
        intArray = new double[smoothSize][smoothSize];
    }
    double zmin = 0.0, zmax = 0.0;
    for (int i = 0; i < pCount; i++) {
        int xx = (int) (x[i] - (double) dx + 0.5);
        int yy = (int) (y[i] - (double) dy + 0.5);
        if ((xx >= 0) && (xx < this.hWidth) && (yy >= 0) && (yy < this.hHeight)) {
            readPixels(heightMap, xx, yy, intArray);
            double intensity = getWeightedIntensity(intArray, weights) * amount;
            if (intensity < zmin)
                zmin = intensity;
            else if (intensity > zmax)
                zmax = intensity;
            z[i] += intensity;
        }
    }
    // Subtract ground
    double fam = (zmax - zmin) / 2.0 + zmin;
    if ((fam != 0.0) && (noGround)) {
        for (int i = 0; i < pCount; i++) {
            z[i] -= fam;
        }
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) WFImage(org.jwildfire.image.WFImage) SimpleImage(org.jwildfire.image.SimpleImage)

Aggregations

SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)11 SimpleImage (org.jwildfire.image.SimpleImage)9 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)4 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ImageReader (org.jwildfire.io.ImageReader)2 ScaleTransformer (org.jwildfire.transform.ScaleTransformer)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ImageIcon (javax.swing.ImageIcon)1 PCPoint (org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)1 FastHDRTonemapper (org.jwildfire.image.FastHDRTonemapper)1 WFImage (org.jwildfire.image.WFImage)1 Mesh3D (org.jwildfire.transform.Mesh3D)1