Package org.jwildfire.create.tina.io

Source Code of org.jwildfire.create.tina.io.MapGradientWriter

package org.jwildfire.create.tina.io;

import org.jwildfire.base.Tools;
import org.jwildfire.create.tina.palette.RGBColor;
import org.jwildfire.create.tina.palette.RGBPalette;

public class MapGradientWriter {

  public void writeGradient(RGBPalette pGradient, String pFilename) throws Exception {
    Tools.writeUTF8Textfile(pFilename, getGradientAsMap(pGradient));
  }

  public String getGradientAsMap(RGBPalette pGradient) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
      RGBColor color = pGradient.getRawColor(i);
      sb.append(alignColValue(color.getRed()));
      sb.append(" ");
      sb.append(alignColValue(color.getGreen()));
      sb.append(" ");
      sb.append(alignColValue(color.getBlue()));
      if (i == 0) {
        sb.append(" \"");
        sb.append(pGradient.getFlam3Name());
        sb.append("\", created with " + Tools.APP_TITLE + " " + Tools.APP_VERSION);
      }
      sb.append("\n");
    }
    return sb.toString();
  }

  private String alignColValue(int pValue) {
    String res = String.valueOf(pValue);
    while (res.length() < 3) {
      res = " " + res;
    }
    return res;
  }
}
TOP

Related Classes of org.jwildfire.create.tina.io.MapGradientWriter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.