📄 rawimage.java
字号:
package ergo.ui;
// $Id: RawImage.java,v 1.1 1999/08/15 01:40:29 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import java.awt.image.MemoryImageSource;
/**
* RawImage is a "bare image" class, designed for maximum speed and convenience.
* It is basically a glorified wrapper for int[].
*/
class RawImage {
int[] data;
int width, height;
private int xorig, yorig;
private MemoryImageSource mis;
public RawImage() {
width = 0;
height = 0;
}
public RawImage (int width1, int height1) {
width = width1;
height = height1;
data = new int[width * height];
init();
}
public RawImage (int[] data1, int width1) {
data = data1;
width = width1;
height = data.length / width;
init();
}
public RawImage reinit (int width1, int height1) {
if (width != width1 || height != height1) {
width = width1;
height = height1;
data = new int[width * height];
init();
}
else
blank(0);
return this;
}
public RawImage bclone () {
return new RawImage(width, height);
}
private void init () {
mis = new MemoryImageSource(width, height, data, 0, width);
mis.setAnimated(true);
mis.setFullBufferUpdates(true);
}
public void setorig (int xorig1, int yorig1) {
xorig = xorig1;
yorig = yorig1;
}
public void setpixel (int color, int x1, int y1) {
int x2 = x1 + xorig;
int y2 = y1 + yorig;
if (x2 < 0) x2 = 0; else if (x2 >= width) x2 = width - 1;
if (y2 < 0) y2 = 0; else if (y2 >= height) y2 = height - 1;
data[x2 + y2 * width] = color;
}
public void setband (int color, int xl, int xr, int y1) {
int xl1 = xl + xorig;
int xr1 = xr + xorig;
int y2 = y1 + yorig;
if (xl1 < 0) xl1 = 0; else if (xl1 >= width) xl1 = width - 1;
if (xr1 < 0) xr1 = 0; else if (xr1 >= width) xr1 = width - 1;
if (y2 < 0) y2 = 0; else if (y2 >= height) y2 = height - 1;
for (int i = xl1; i <= xr1; ++i) {
data[i + y2 * width] = color;
}
}
public RawImage blank (int color) {
int length = data.length;
for (int i = 0; i < length; ++i) {
data[i] = color;
}
return this;
}
public MemoryImageSource mis () {
return mis;
}
public String toString () {
String r = "";
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
r += (data[j + width * i] & 0xff)+" ";
}
r += "\n";
}
return r;
}
} // end class RawImage
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -