⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagesplitter.java

📁 用java写的jt-jpeg。jt表示java time package
💻 JAVA
字号:
package jpeg;
import jcp.*;
import java.awt.*;
import java.awt.image.*;

/**
 *  ImageSplitter.java
 *  A component that takes an image input and outputs
 *  its red, green, and blue components as IntMatrix signals.
 *
 *  Input(s):
 *      in - The input image, represented as a WxH array of integers.
 *  Ouput(s):
 *      red - The red component of the image.
 *      green - The green component of the image.
 *      blue - The blue component of the image.
 *
 *  @see ImageCombiner
 *  @author James S. Young, based on original source by Florian Raemy &
 *  LCAV, Swiss Federal Institute of Technology, Lausanne, Switzerland
 */

public class ImageSplitter extends SynchComponent
{

    private int width = -1;
    private int height = -1;

    private Port r,g,b;

    public ImageSplitter() {
        setName("Image Splitter");
        addPort(true,"in");
        r = addPort(false,"red");
        g = addPort(false,"green");
        b = addPort(false,"blue");
    }

    public synchronized void go(Port port) {
        Object s = port.signal();
        if (s instanceof IntMatrix) {
            int[][] image = ((IntMatrix)s).get_matrix();

            emit(new IntMatrix(getMaskedArray(image,0x00ff0000,16)),r);
            emit(new IntMatrix(getMaskedArray(image,0x0000ff00,8)),g);
            emit(new IntMatrix(getMaskedArray(image,0x000000ff,0)),b);
        }
    }

    private int[][] getMaskedArray(int[][] image, int mask, int offset)
    {
        width = image.length;
        height = image[0].length;

        int r[][] = new int[width][height];

        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                int value = (image[x][y] & mask) >> offset;
                r[x][y] = value;
                // r[x][y] = (0xff000000 | (value << 16) | (value << 8) | value);
            }
        }

        return r;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -