📄 imageunblocker.java
字号:
package jpeg;
import jcp.*;
import jcp.clocked.*;
/**
* ImageUnblocker.java
* A component that reconstructs a single image from a stream of 8x8 image blocks.
*
* Input(s):
* block in - An 8x8 matrix of integers representing an image block.
* width - The width of the input image.
* height - The height of the input image.
* done - A Boolean that is set true after the final block has been received.
* Ouput(s):
* image out - A WxH matrix representing the reconstructed image.
*
* @see IntMatrix
* @see ImageBlocker
*/
/**
* @author James S. Young, based on original source by Florian Raemy &
* LCAV, Swiss Federal Institute of Technology, Lausanne, Switzerland
*/
public class ImageUnblocker extends Synchronous
{
private int[][] image;
private Port blk_p, w_p, h_p, done_p, img_p;
public ImageUnblocker() {
setName("Image Unblocker");
blk_p = addPort(true,"block in");
w_p = addPort(false,"width");
h_p = addPort(false,"height");
done_p = addPort(true,"done");
img_p = addPort(false,"image out");
Integer temp = new Integer(42);
w_p.setType(temp.getClass());
h_p.setType(temp.getClass());
}
public void run() {
while (true) {
waitClock();
waitClock();
int width = ((Integer)w_p.signal()).intValue();
int height = ((Integer)h_p.signal()).intValue();
image = new int[width][height];
int[][] block = new int[8][8];
int xpos = 0;
int ypos = 0;
int blockCount = 0;
while (done_p.signal() == Signal.FALSE) {
Object s0 = blk_p.signal();
if (s0 instanceof IntMatrix) {
block = ((IntMatrix)s0).get_matrix();
}
for (int a=0; a < 8; a++) {
for (int b=0; b < 8; b++) {
image[xpos+a][ypos+b] = block[a][b];
}
}
xpos = xpos + 8;
if (xpos >= image.length) {
xpos = 0;
ypos = (ypos + 8);
if (ypos >= image[0].length) {
ypos = 0;
}
}
blockCount++;
waitClock();
}
emit(new IntMatrix(image),img_p);
waitClock();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -