Package plugin.examples.math

Source Code of plugin.examples.math.RawImport

package plugin.examples.math;

import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import plugin.annotations.IO;
import plugin.annotations.Plugin;
import plugin.typeinterfaces.DataStreamSource;
import skomp.io.ColorInputStream;
import skomp.io.ColorMode;

@Plugin(IO = @IO(In="", Out="BufferedImage"))
public class RawImport extends DataStreamSource<Image> {

  private int height;

  private int width;

  private String imageFile;

  private ColorMode colorDepth;

  @Override
  public Image compute() {
    BufferedImage ret = new BufferedImage(width, height,
        BufferedImage.TYPE_4BYTE_ABGR);
    FileInputStream fis = null;
    try {
      fis = new FileInputStream(imageFile);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      return null;
    }
    ColorInputStream cis = new ColorInputStream(fis, colorDepth, true);
    Color in;
    try {
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          if ((in = cis.readNextColor()) == null) {
            return ret;
          }
          try {
            ret.setRGB(j, i, in.getRGB());
          } catch (Exception e) {
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
      try {
        cis.close();
      } catch (IOException e1) {
      }
    }
    return ret;
  }

  public int getHeight() {
    return height;
  }

  public void setHeight(int height) {
    this.height = height;
  }

  public int getWidth() {
    return width;
  }

  public void setWidth(int width) {
    this.width = width;
  }

  public ColorMode getColorDepth() {
    return colorDepth;
  }

  public void setColorDepth(ColorMode colorDepth) {
    this.colorDepth = colorDepth;
  }

  public String getImageFile() {
    return imageFile;
  }

  public void setImageFile(String imageFile) {
    this.imageFile = imageFile;
  }
}
TOP

Related Classes of plugin.examples.math.RawImport

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.