use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlameRenderer method renderImageStereo3d.
private RenderedFlame renderImageStereo3d(RenderInfo pRenderInfo) {
Stereo3dEye storedEye = eye;
double storedAngle = flame.getStereo3dAngle();
double storedEyeDist = flame.getStereo3dEyeDist();
try {
switch(pRenderInfo.getRenderMode()) {
case PREVIEW:
switch(flame.getStereo3dPreview()) {
case SIDE_BY_SIDE:
{
RenderedFlame result = renderStereo3dSideBySide(pRenderInfo);
ScaleTransformer scaleTransformer = new ScaleTransformer();
scaleTransformer.setAspect(ScaleAspect.IGNORE);
scaleTransformer.setScaleWidth(pRenderInfo.getImageWidth() * renderScale);
scaleTransformer.setScaleHeight(pRenderInfo.getImageHeight() * renderScale);
scaleTransformer.transformImage(result.getImage());
return result;
}
case SIDE_BY_SIDE_FULL:
{
int oldWidth = pRenderInfo.getImageWidth();
pRenderInfo.setImageWidth(oldWidth / 2);
RenderedFlame result = renderStereo3dSideBySide(pRenderInfo);
pRenderInfo.setImageWidth(oldWidth);
return result;
}
case ANAGLYPH:
{
return renderStereo3dAnaglyph(pRenderInfo);
}
case NONE:
return renderImageNormal(pRenderInfo, 1, 0);
default:
throw new IllegalStateException(pRenderInfo.getRenderMode().toString());
}
case PRODUCTION:
switch(flame.getStereo3dMode()) {
case ANAGLYPH:
return renderStereo3dAnaglyph(pRenderInfo);
case INTERPOLATED_IMAGES:
{
RenderInfo localRenderInfo = pRenderInfo.makeCopy();
localRenderInfo.setRenderHDR(false);
localRenderInfo.setRenderZBuffer(false);
RenderedFlame[] leftRenders = new RenderedFlame[flame.getStereo3dInterpolatedImageCount()];
double dAngle = storedAngle / (double) leftRenders.length;
double dEyeDist = storedEyeDist / (double) leftRenders.length;
int totalImageCount = 2 * leftRenders.length;
int totalImageIdx = 0;
for (int i = 0; i < leftRenders.length; i++) {
eye = Stereo3dEye.LEFT;
flame.setStereo3dAngle((i + 1) * dAngle);
flame.setStereo3dEyeDist((i + 1) * dEyeDist);
leftRenders[i] = renderImageNormal(localRenderInfo, totalImageCount, totalImageIdx++);
}
RenderedFlame[] rightRenders = new RenderedFlame[flame.getStereo3dInterpolatedImageCount()];
for (int i = 0; i < rightRenders.length; i++) {
eye = Stereo3dEye.RIGHT;
flame.setStereo3dAngle((i + 1) * dAngle);
flame.setStereo3dEyeDist((i + 1) * dEyeDist);
rightRenders[i] = renderImageNormal(localRenderInfo, totalImageCount, totalImageIdx++);
}
if (flame.isStereo3dSwapSides()) {
RenderedFlame[] tmp = leftRenders;
leftRenders = rightRenders;
rightRenders = tmp;
}
RenderedFlame mergedRender = new RenderedFlame();
localRenderInfo.setImageWidth(2 * pRenderInfo.getImageWidth());
localRenderInfo.setImageHeight(leftRenders.length * pRenderInfo.getImageHeight());
mergedRender.init(localRenderInfo, flame);
SimpleImage mergedImg = mergedRender.getImage();
ComposeTransformer composeTransformer = new ComposeTransformer();
composeTransformer.setHAlign(HAlignment.OFF);
composeTransformer.setVAlign(VAlignment.OFF);
int yOff = 0;
for (int i = 0; i < leftRenders.length; i++) {
composeTransformer.setLeft(0);
composeTransformer.setTop(yOff);
composeTransformer.setForegroundImage(leftRenders[i].getImage());
composeTransformer.transformImage(mergedImg);
yOff += pRenderInfo.getImageHeight();
}
yOff = 0;
for (int i = 0; i < rightRenders.length; i++) {
composeTransformer.setLeft(pRenderInfo.getImageWidth());
composeTransformer.setTop(yOff);
composeTransformer.setForegroundImage(rightRenders[i].getImage());
composeTransformer.transformImage(mergedImg);
yOff += pRenderInfo.getImageHeight();
}
return mergedRender;
}
case SIDE_BY_SIDE:
return renderStereo3dSideBySide(pRenderInfo);
case NONE:
return renderImageNormal(pRenderInfo, 1, 0);
default:
throw new IllegalStateException(flame.getStereo3dMode().toString());
}
default:
throw new IllegalStateException(pRenderInfo.getRenderMode().toString());
}
} finally {
eye = storedEye;
flame.setStereo3dAngle(storedAngle);
flame.setStereo3dEyeDist(storedEyeDist);
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class LogDensityFilter method addSolidColors.
private boolean addSolidColors(LogDensityPoint dest, RasterPoint rp, double colorScale) {
if (solidRendering && rp.hasNormals) {
LightViewCalculator lightViewCalculator = raster.getLightViewCalculator();
double avgVisibility;
if (rp.hasShadows) {
avgVisibility = 0.0;
int shadowCount = 0;
for (int i = 0; i < rp.visibility.length; i++) {
avgVisibility += rp.visibility[i];
shadowCount++;
}
if (shadowCount > 0) {
avgVisibility /= (double) shadowCount;
} else {
avgVisibility = 1.0;
}
} else {
avgVisibility = 1.0;
}
RGBColorD rawColor;
MaterialSettings material = flame.getSolidRenderSettings().getInterpolatedMaterial(rp.material);
if (material == null) {
RGBColorD bgColor = new RGBColorD(dest.bgRed, dest.bgGreen, dest.bgBlue, 1.0 / VecMathLib.COLORSCL);
double visibility = 0.0;
for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
visibility += light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
}
visibility = GfxMathLib.clamp(visibility);
rawColor = new RGBColorD(bgColor, visibility);
} else {
double aoInt = Tools.limitValue(flame.getSolidRenderSettings().getAoIntensity(), 0.0, 4.0);
boolean withSSAO = flame.getSolidRenderSettings().isAoEnabled();
double ambientIntensity = Math.max(0.0, withSSAO ? (material.getAmbient() - rp.ao * aoInt) : material.getAmbient());
double aoDiffuseInfluence = flame.getSolidRenderSettings().getAoAffectDiffuse();
double diffuseIntensity = Math.max(0.0, withSSAO ? (material.getDiffuse() - rp.ao * aoInt * aoDiffuseInfluence) : material.getDiffuse());
double specularIntensity = material.getPhong();
SimpleImage reflectionMap = null;
if (material.getReflMapIntensity() > MathLib.EPSILON && material.getReflMapFilename() != null && material.getReflMapFilename().length() > 0) {
try {
reflectionMap = (SimpleImage) RessourceManager.getImage(material.getReflMapFilename());
} catch (Exception e) {
material.setReflMapFilename(null);
e.printStackTrace();
}
}
RGBColorD objColor = new RGBColorD(rp.solidRed * logScaleCalculator.getBalanceRed(), rp.solidGreen * logScaleCalculator.getBalanceGreen(), rp.solidBlue * logScaleCalculator.getBalanceBlue(), 1.0 / VecMathLib.COLORSCL);
rawColor = new RGBColorD(objColor, ambientIntensity * avgVisibility);
VectorD normal = new VectorD(rp.nx, rp.ny, rp.nz);
VectorD viewDir = new VectorD(0.0, 0.0, 1.0);
for (int i = 0; i < flame.getSolidRenderSettings().getLights().size(); i++) {
DistantLight light = flame.getSolidRenderSettings().getLights().get(i);
VectorD lightDir = lightViewCalculator.getLightDir()[i];
double visibility = light.isCastShadows() && rp.hasShadows ? rp.visibility[i] : avgVisibility;
double cosa = VectorD.dot(lightDir, normal);
if (cosa > MathLib.EPSILON) {
double diffResponse = material.getLightDiffFunc().evaluate(cosa);
rawColor.addFrom(light.getRed() + objColor.r * ambientIntensity / 3.0, light.getGreen() + objColor.g * ambientIntensity / 3.0, light.getBlue() + objColor.b * ambientIntensity / 3.0, visibility * diffResponse * diffuseIntensity * light.getIntensity());
}
if (specularIntensity > MathLib.EPSILON) {
VectorD r = VectorD.reflect(lightDir, normal);
double vr = VectorD.dot(viewDir, r);
if (vr < MathLib.EPSILON) {
double specularResponse = MathLib.pow(material.getLightDiffFunc().evaluate(-vr), material.getPhongSize());
rawColor.addFrom(material.getPhongRed(), material.getPhongGreen(), material.getPhongBlue(), visibility * specularResponse * specularIntensity * light.getIntensity());
}
}
// http://www.reindelsoftware.com/Documents/Mapping/Mapping.html
if (reflectionMap != null) {
double reflectionMapIntensity = Math.max(0.0, withSSAO ? (material.getReflMapIntensity() - rp.ao * aoInt * aoDiffuseInfluence) : material.getReflMapIntensity());
VectorD r = VectorD.reflect(viewDir, normal);
UVPairD uv;
switch(material.getReflectionMapping()) {
case SPHERICAL:
uv = UVPairD.sphericalOpenGlMapping(r);
break;
case BLINN_NEWELL:
default:
uv = UVPairD.sphericalBlinnNewellLatitudeMapping(r);
break;
}
RGBColorD reflMapColor = uv.getColorFromMap(reflectionMap);
rawColor.addFrom(reflMapColor.r * logScaleCalculator.getBalanceRed(), reflMapColor.g * logScaleCalculator.getBalanceGreen(), reflMapColor.b * logScaleCalculator.getBalanceBlue(), visibility * reflectionMapIntensity);
}
}
}
dest.solidRed += rawColor.r * colorScale * VecMathLib.COLORSCL;
dest.solidGreen += rawColor.g * colorScale * VecMathLib.COLORSCL;
dest.solidBlue += rawColor.b * colorScale * VecMathLib.COLORSCL;
dest.hasSolidColors = true;
return true;
}
return false;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FilterKernelVisualisation3dRenderer method createKernelVisualisation.
public SimpleImage createKernelVisualisation(int pWidth, int pHeight) {
String key = makeKey(pWidth, pHeight);
SimpleImage img = cache.get(key);
if (img == null) {
img = new SimpleImage(pWidth, pHeight);
if (noiseFilterSize > 0) {
Scene scene = createScene(pWidth, pHeight);
double sunflowScale = 10.0;
double sunflowZScale = 0.6;
int rectCount = noiseFilterSize;
double dx = (double) pWidth / (double) rectCount;
double dy = (double) pHeight / (double) rectCount;
double w2 = (double) pWidth / 2.0;
double h2 = (double) pHeight / 2.0;
double xOff = 0.0, yOff = 0.0;
for (int i = 0; i < noiseFilterSize; i++) {
xOff = 0;
for (int j = 0; j < noiseFilterSize; j++) {
double fValue = filter[i][j];
Color rectColor;
if (fValue >= 0) {
int fValueClr = Tools.FTOI(255.0 * fValue);
if (fValueClr > 255) {
fValueClr = 255;
}
rectColor = new Color(fValueClr, fValueClr, fValueClr);
} else {
int fValueClr = Tools.FTOI(-255.0 * (fValue - 0.5));
if (fValueClr > 255) {
fValueClr = 255;
}
rectColor = new Color(fValueClr, 0, 0);
}
addCube(scene, sunflowScale * (xOff - w2) / (double) pWidth, sunflowScale * (yOff - h2) / (double) pHeight, sunflowScale * dx / (double) pWidth, sunflowScale * dy / (double) pHeight, sunflowScale * fValue * sunflowZScale, rectColor);
xOff += dx;
}
yOff += dy;
}
try {
SunflowAPI api = createSunflowRenderer(scene);
SunFlowImagePanel imagePanel = new SunFlowImagePanel();
imagePanel.setBounds(0, 0, pWidth, pHeight);
api.render(SunflowAPI.DEFAULT_OPTIONS, imagePanel);
img.setBufferedImage(imagePanel.getImage(), imagePanel.getWidth(), imagePanel.getHeight());
} catch (Exception e) {
e.printStackTrace();
img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
}
} else {
img.fillBackground(emptyFilterColor.getRed(), emptyFilterColor.getGreen(), emptyFilterColor.getBlue());
}
cache.put(key, img);
}
return img;
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class IFlamesController method refreshFlameLibrary.
private void refreshFlameLibrary() {
if (flameLibraryScrollPane != null) {
flameLibraryPanel.remove(flameLibraryScrollPane);
flameLibraryScrollPane = null;
}
int panelWidth = FlameThumbnail.IMG_WIDTH + 2 * FlameThumbnail.BORDER_SIZE;
int panelHeight = (FlameThumbnail.IMG_HEIGHT + FlameThumbnail.BORDER_SIZE) * flameLibrary.size();
JPanel batchPanel = new JPanel();
batchPanel.setLayout(null);
batchPanel.setSize(panelWidth, panelHeight);
batchPanel.setPreferredSize(new Dimension(panelWidth, panelHeight));
for (int i = 0; i < flameLibrary.size(); i++) {
SimpleImage img = flameLibrary.get(i).getPreview(3 * prefs.getTinaRenderPreviewQuality() / 4);
// add it to the main panel
ImagePanel imgPanel = new ImagePanel(img, 0, 0, img.getImageWidth());
imgPanel.setImage(img);
imgPanel.setLocation(FlameThumbnail.BORDER_SIZE, i * FlameThumbnail.IMG_HEIGHT + (i + 1) * FlameThumbnail.BORDER_SIZE);
flameLibrary.get(i).setImgPanel(imgPanel);
final int idx = i;
addRemoveFlameFromLibraryButton(imgPanel, idx);
imgPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if (e.getClickCount() > 1 || e.getButton() != MouseEvent.BUTTON1) {
importFromFlameLibrary(idx);
}
}
});
batchPanel.add(imgPanel);
}
flameLibraryScrollPane = new JScrollPane(batchPanel);
flameLibraryScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
flameLibraryScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
flameLibraryPanel.add(flameLibraryScrollPane, BorderLayout.CENTER);
flameLibraryScrollPane.validate();
flameLibraryScrollPane.getParent().validate();
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class IFlamesController method getBaseFlamePreviewPanel.
private FlamePanel getBaseFlamePreviewPanel() {
if (baseFlamePreviewPanel == null) {
int width = baseFlamePreviewRootPnl.getWidth();
int height = baseFlamePreviewRootPnl.getHeight();
SimpleImage img = new SimpleImage(width, height);
img.fillBackground(0, 0, 0);
baseFlamePreviewPanel = new FlamePanel(prefs, img, 0, 0, baseFlamePreviewRootPnl.getWidth(), this, null);
ResolutionProfile resProfile = getResolutionProfile();
baseFlamePreviewPanel.setRenderWidth(resProfile.getWidth());
baseFlamePreviewPanel.setRenderHeight(resProfile.getHeight());
baseFlamePreviewPanel.setFocusable(true);
baseFlamePreviewRootPnl.add(baseFlamePreviewPanel, BorderLayout.CENTER);
baseFlamePreviewRootPnl.getParent().validate();
baseFlamePreviewRootPnl.repaint();
baseFlamePreviewPanel.requestFocusInWindow();
}
return baseFlamePreviewPanel;
}
Aggregations