jpegcontroller.java

来自「用java写的jt-jpeg。jt表示java time package」· Java 代码 · 共 77 行

JAVA
77
字号
package jpeg;
import jcp.*;

/**
 *  JPEGController.java
 *
 *  A component that coordinates the execution of the encoding and decoding
 *  process in a JPEGBlock. Specifically, it controls the "clock" component
 *  that is responsible for synchronizing the image serialization and
 *  deserialization procedures. The "clock" is enabled when a new image is
 *  presented for processing, and is disabled once the processing has
 *  completed.
 */

public class JPEGController extends SynchComponent
{
    private Port intImg;
    private Port out;
    private Port start;
    private Port resolution;
    private Port quality;

    private long startTime;
    private boolean started;

    public JPEGController() {
        setName("JPG Controller");
        intImg = addPort(true,"internal");
        start = addPort(true,"start");
        out = addPort(false,"out");
        resolution = addPort(true,"resolution");
        quality = addPort(false,"quality");
        started = false;
    }

    public void go(Port p) {
        if ((p == start) && (!started)){
            if (start.signal() == Signal.TRUE) {
                startClock();
                started = true;
                JTSystem.println("Decoding started");
                startTime = System.currentTimeMillis();
            }
        } else if (p == intImg) {
            stopClock();
            started = false;
            long elapsed = System.currentTimeMillis() - startTime;
            JTSystem.println("Elapsed time: "+elapsed);
        } else if (p == resolution) {
            int res = ((Integer)p.signal()).intValue();
            switch (res) {
                case 0:
                    emit(new Integer(100),quality);
                    break;
                case 1:
                    emit(new Integer(66),quality);
                    break;
                case 2:
                    emit(new Integer(33),quality);
                    break;
                case 3:
                    emit(new Integer(1),quality);
                    break;
            }
        }
    }

    private void startClock() {
        emit(Signal.TRUE,out);
    }

    private void stopClock() {
        emit(Signal.FALSE,out);
    }

}

⌨️ 快捷键说明

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