Search in sources :

Example 11 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class EnvelopeDialog method findProperty.

private String findProperty(Object pObject, Object pProperty, String pPath) {
    if (pObject == pProperty) {
        return pPath;
    }
    Class<?> cls = pObject.getClass();
    for (Field field : cls.getDeclaredFields()) {
        field.setAccessible(true);
        Object fieldValue;
        try {
            fieldValue = field.get(pObject);
        } catch (Exception ex) {
            fieldValue = null;
        }
        if (fieldValue != null) {
            if (fieldValue == pProperty) {
                String pathExt = field.getName();
                return pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
            }
            if (fieldValue instanceof List) {
                List<?> list = (List<?>) fieldValue;
                for (int i = 0; i < list.size(); i++) {
                    String pathExt = field.getName() + "[" + i + "]";
                    String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
                    String subResult = findProperty(list.get(i), pProperty, subPath);
                    if (subResult != null) {
                        return subResult;
                    }
                }
            } else if (fieldValue instanceof Map) {
                Map<?, ?> map = (Map<?, ?>) fieldValue;
                Set<?> entrySet = map.entrySet();
                for (Object obj : entrySet) {
                    Entry<?, ?> entry = (Entry<?, ?>) obj;
                    String pathExt = field.getName() + "[" + entry.getKey().toString() + "]";
                    String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
                    String subResult = findProperty(entry.getValue(), pProperty, subPath);
                    if (subResult != null) {
                        return subResult;
                    }
                }
            } else if (fieldValue instanceof RGBPalette) {
                RGBPalette palette = (RGBPalette) fieldValue;
                String pathExt = field.getName();
                String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
                String subResult = findProperty(palette, pProperty, subPath);
                if (subResult != null) {
                    return subResult;
                }
            } else if (fieldValue instanceof SolidRenderSettings) {
                SolidRenderSettings settings = (SolidRenderSettings) fieldValue;
                String pathExt = field.getName();
                String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
                String subResult = findProperty(settings, pProperty, subPath);
                if (subResult != null) {
                    return subResult;
                }
            }
        }
    }
    return null;
}
Also used : Set(java.util.Set) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SolidRenderSettings(org.jwildfire.create.tina.base.solidrender.SolidRenderSettings) Point(java.awt.Point) Field(java.lang.reflect.Field) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 12 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class TinaController method grabPaletteFromImageButton_actionPerformed.

public void grabPaletteFromImageButton_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
    if (prefs.getInputImagePath() != null) {
        try {
            chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            SimpleImage img = new ImageReader(centerPanel).loadImage(file.getAbsolutePath());
            prefs.setLastInputImageFile(file);
            RGBPalette palette = new MedianCutQuantizer().createPalette(img);
            data.paletteKeyFrames = null;
            saveUndoPoint();
            getCurrLayer().setPalette(palette);
            setLastGradient(palette);
            refreshPaletteColorsTable();
            refreshPaletteUI(palette);
            refreshFlameImage(true, false, 1, true, false);
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 13 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class TinaController method grabPaletteFromFlameButton_actionPerformed.

public void grabPaletteFromFlameButton_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new FlameFileChooser(prefs);
    if (prefs.getInputFlamePath() != null) {
        try {
            chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        List<Flame> flames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
        Flame flame = flames.get(0);
        prefs.setLastInputFlameFile(file);
        RGBPalette palette = flame.getFirstLayer().getPalette();
        data.paletteKeyFrames = null;
        saveUndoPoint();
        getCurrLayer().setPalette(palette);
        setLastGradient(palette);
        refreshPaletteColorsTable();
        refreshPaletteUI(palette);
        refreshFlameImage(true, false, 1, true, false);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FlameReader(org.jwildfire.create.tina.io.FlameReader) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 14 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class TinaController method refreshPaletteColorsTable.

private void refreshPaletteColorsTable() {
    final int COL_COLOR = 0;
    final int COL_RED = 1;
    final int COL_GREEN = 2;
    final int COL_BLUE = 3;
    data.createPaletteColorsTable.setDefaultRenderer(Object.class, new PaletteTableCustomRenderer());
    data.createPaletteColorsTable.setModel(new DefaultTableModel() {

        private static final long serialVersionUID = 1L;

        @Override
        public int getRowCount() {
            return Integer.parseInt(data.paletteRandomPointsREd.getText());
        }

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public String getColumnName(int columnIndex) {
            switch(columnIndex) {
                case COL_COLOR:
                    return "Color";
                case COL_RED:
                    return "Red";
                case COL_GREEN:
                    return "Green";
                case COL_BLUE:
                    return "Blue";
            }
            return null;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (data.paletteKeyFrames != null && data.paletteKeyFrames.size() > rowIndex) {
                switch(columnIndex) {
                    case COL_COLOR:
                        return String.valueOf(rowIndex + 1);
                    case COL_RED:
                        return String.valueOf(data.paletteKeyFrames.get(rowIndex).getRed());
                    case COL_GREEN:
                        return String.valueOf(data.paletteKeyFrames.get(rowIndex).getGreen());
                    case COL_BLUE:
                        return String.valueOf(data.paletteKeyFrames.get(rowIndex).getBlue());
                }
            }
            return null;
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return column == COL_RED || column == COL_GREEN || column == COL_BLUE;
        }

        @Override
        public void setValueAt(Object aValue, int row, int column) {
            if (getCurrFlame() != null && data.paletteKeyFrames != null && data.paletteKeyFrames.size() > row) {
                String valStr = (String) aValue;
                if (valStr == null || valStr.length() == 0) {
                    valStr = "0";
                }
                switch(column) {
                    case COL_RED:
                        data.paletteKeyFrames.get(row).setRed(Tools.limitColor(Tools.stringToInt(valStr)));
                        break;
                    case COL_GREEN:
                        data.paletteKeyFrames.get(row).setGreen(Tools.limitColor(Tools.stringToInt(valStr)));
                        break;
                    case COL_BLUE:
                        data.paletteKeyFrames.get(row).setBlue(Tools.limitColor(Tools.stringToInt(valStr)));
                        break;
                    default:
                        // nothing to do
                        break;
                }
                refreshPaletteColorsTable();
                RGBPalette palette = RandomGradientGenerator.generatePalette(data.paletteKeyFrames, data.paletteFadeColorsCBx.isSelected(), data.paletteUniformWidthCBx.isSelected());
                saveUndoPoint();
                getCurrLayer().setPalette(palette);
                setLastGradient(palette);
                refreshPaletteUI(palette);
                refreshFlameImage(true, false, 1, true, false);
            }
            super.setValueAt(aValue, row, column);
        }
    });
    data.createPaletteColorsTable.getTableHeader().setFont(data.transformationsTable.getFont());
    data.createPaletteColorsTable.getColumnModel().getColumn(COL_COLOR).setWidth(20);
    data.createPaletteColorsTable.getColumnModel().getColumn(COL_RED).setPreferredWidth(60);
    data.createPaletteColorsTable.getColumnModel().getColumn(COL_GREEN).setPreferredWidth(60);
    data.createPaletteColorsTable.getColumnModel().getColumn(COL_BLUE).setPreferredWidth(60);
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 15 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class TinaController method addLayerBtn_clicked.

public void addLayerBtn_clicked() {
    Flame flame = getCurrFlame();
    Layer layer = new Layer();
    RGBPalette palette = RandomGradientGeneratorList.getRandomGradientGeneratorInstance((String) data.paletteRandomGeneratorCmb.getSelectedItem()).generatePalette(Integer.parseInt(data.paletteRandomPointsREd.getText()), data.paletteFadeColorsCBx.isSelected(), data.paletteUniformWidthCBx.isSelected());
    layer.setPalette(palette);
    setLastGradient(palette);
    saveUndoPoint();
    flame.getLayers().add(layer);
    gridRefreshing = true;
    try {
        refreshLayersTable();
    } finally {
        gridRefreshing = false;
    }
    int row = getCurrFlame().getLayers().size() - 1;
    data.layersTable.getSelectionModel().setSelectionInterval(row, row);
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) Layer(org.jwildfire.create.tina.base.Layer) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)29 ArrayList (java.util.ArrayList)12 Layer (org.jwildfire.create.tina.base.Layer)9 File (java.io.File)8 Flame (org.jwildfire.create.tina.base.Flame)8 RGBColor (org.jwildfire.create.tina.palette.RGBColor)5 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)5 SimpleImage (org.jwildfire.image.SimpleImage)5 Field (java.lang.reflect.Field)4 JFileChooser (javax.swing.JFileChooser)4 XForm (org.jwildfire.create.tina.base.XForm)4 ImageReader (org.jwildfire.io.ImageReader)4 List (java.util.List)3 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)3 HashMap (java.util.HashMap)2 JLabel (javax.swing.JLabel)2 Test (org.junit.Test)2 QualityProfile (org.jwildfire.base.QualityProfile)2 ResolutionProfile (org.jwildfire.base.ResolutionProfile)2 MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)2