package caida.tools; import java.io.*; import java.awt.*; import java.awt.image.*; public class GIFEncoder { protected short width_, height_; protected int numColors_; protected byte pixels_[], colors_[]; ScreenDescriptor sd_; ImageDescriptor id_; /** * A null constructor. */ protected GIFEncoder() { // does noting. Used by subclasses. } public GIFEncoder(Image image) throws AWTException { width_ = (short)image.getWidth(null); height_ = (short)image.getHeight(null); int values[] = new int[width_ * height_]; PixelGrabber grabber = new PixelGrabber( image, 0, 0, width_, height_, values, 0, width_); try { if(grabber.grabPixels() != true) throw new AWTException("Grabber returned false: " + grabber.status()); } catch (InterruptedException e) {}; byte r[][] = new byte[width_][height_]; byte g[][] = new byte[width_][height_]; byte b[][] = new byte[width_][height_]; int index = 0; for (int y = 0; y < height_; ++y) for (int x = 0; x < width_; ++x) { r[x][y] = (byte)((values[index] >> 16) & 0xFF); g[x][y] = (byte)((values[index] >> 8) & 0xFF); b[x][y] = (byte)((values[index]) & 0xFF); if (values[index] > 0) System.err.println(r[x][y] + " " + g[x][y] + " " + b[x][y]); ++index; } ToIndexedColor(r, g, b); } /** * Construct a GIFEncoder. The constructor will convert the image to * an indexed color array. This may take some time.
* * Each array stores intensity values for the image. In other words, * r[x][y] refers to the red intensity of the pixel at column x, row * y.
* * @param r An array containing the red intensity values. * @param g An array containing the green intensity values. * @param b An array containing the blue intensity values. * * @exception AWTException Will be thrown if the image contains more than * 256 colors. * */ public GIFEncoder(byte r[][], byte g[][], byte b[][]) throws AWTException { width_ = (short)(r.length); height_ = (short)(r[0].length); ToIndexedColor(r, g, b); } /** * Writes the image out to a stream in the GIF file format. This will * be a single GIF87a image, non-interlaced, with no background color. * This may take some time.
*
* @param output The stream to output to. This should probably be a
* buffered stream.
*
* @exception IOException Will be thrown if a write operation fails.
* */
public void Write(OutputStream output) throws IOException {
BitUtils.WriteString(output, "GIF87a");
ScreenDescriptor sd = new ScreenDescriptor(width_, height_,
numColors_);
sd.Write(output);
output.write(colors_, 0, colors_.length);
ImageDescriptor id = new ImageDescriptor(width_, height_, ',');
id.Write(output);
byte codesize = BitUtils.BitsNeeded(numColors_);
if (codesize == 1)
++codesize;
output.write(codesize);
LZWCompressor.LZWCompress(output, codesize, pixels_);
output.write(0);
id = new ImageDescriptor((byte)0, (byte)0, ';');
id.Write(output);
output.flush();
}
protected void ToIndexedColor(byte r[][], byte g[][],
byte b[][]) throws AWTException {
pixels_ = new byte[width_ * height_];
colors_ = new byte[256 * 3];
int colornum = 0;
for (int x = 0; x < width_; ++x) {
for (int y = 0; y < height_; ++y) {
int search;
for (search = 0; search < colornum; ++search)
if (colors_[search * 3] == r[x][y] &&
colors_[search * 3 + 1] == g[x][y] &&
colors_[search * 3 + 2] == b[x][y])
break;
if (search > 255)
throw new AWTException("Too many colors.");
pixels_[y * width_ + x] = (byte)search;
if (search == colornum) {
colors_[search * 3] = r[x][y];
colors_[search * 3 + 1] = g[x][y];
colors_[search * 3 + 2] = b[x][y];
++colornum;
}
}
}
numColors_ = 1 << BitUtils.BitsNeeded(colornum);
byte copy[] = new byte[numColors_ * 3];
System.arraycopy(colors_, 0, copy, 0, numColors_ * 3);
colors_ = copy;
}
}
class BitFile {
OutputStream output_;
byte buffer_[];
int index_, bitsLeft_;
public BitFile(OutputStream output) {
output_ = output;
buffer_ = new byte[256];
index_ = 0;
bitsLeft_ = 8;
}
public void Flush() throws IOException {
int numBytes = index_ + (bitsLeft_ == 8 ? 0 : 1);
if (numBytes > 0) {
output_.write(numBytes);
output_.write(buffer_, 0, numBytes);
buffer_[0] = 0;
index_ = 0;
bitsLeft_ = 8;
}
}
public void WriteBits(int bits, int numbits) throws IOException {
int bitsWritten = 0;
int numBytes = 255;
do {
if ((index_ == 254 && bitsLeft_ == 0) || index_ > 254) {
output_.write(numBytes);
output_.write(buffer_, 0, numBytes);
buffer_[0] = 0;
index_ = 0;
bitsLeft_ = 8;
}
if (numbits <= bitsLeft_) {
buffer_[index_] |= (bits & ((1 << numbits) - 1)) <<
(8 - bitsLeft_);
bitsWritten += numbits;
bitsLeft_ -= numbits;
numbits = 0;
}
else {
buffer_[index_] |= (bits & ((1 << bitsLeft_) - 1)) <<
(8 - bitsLeft_);
bitsWritten += bitsLeft_;
bits >>= bitsLeft_;
numbits -= bitsLeft_;
buffer_[++index_] = 0;
bitsLeft_ = 8;
}
} while (numbits != 0);
}
}
class LZWStringTable {
private final static int RES_CODES = 2;
private final static short HASH_FREE = (short)0xFFFF;
private final static short NEXT_FIRST = (short)0xFFFF;
private final static int MAXBITS = 12;
private final static int MAXSTR = (1 << MAXBITS);
private final static short HASHSIZE = 9973;
private final static short HASHSTEP = 2039;
byte strChr_[];
short strNxt_[];
short strHsh_[];
short numStrings_;
public LZWStringTable() {
strChr_ = new byte[MAXSTR];
strNxt_ = new short[MAXSTR];
strHsh_ = new short[HASHSIZE];
}
public int AddCharString(short index, byte b) {
int hshidx;
if (numStrings_ >= MAXSTR)
return 0xFFFF;
hshidx = Hash(index, b);
while (strHsh_[hshidx] != HASH_FREE)
hshidx = (hshidx + HASHSTEP) % HASHSIZE;
strHsh_[hshidx] = numStrings_;
strChr_[numStrings_] = b;
strNxt_[numStrings_] = (index != HASH_FREE) ? index : NEXT_FIRST;
return numStrings_++;
}
public short FindCharString(short index, byte b) {
int hshidx, nxtidx;
if (index == HASH_FREE)
return b;
hshidx = Hash(index, b);
while ((nxtidx = strHsh_[hshidx]) != HASH_FREE) {
if (strNxt_[nxtidx] == index && strChr_[nxtidx] == b)
return (short)nxtidx;
hshidx = (hshidx + HASHSTEP) % HASHSIZE;
}
return (short)0xFFFF;
}
public void ClearTable(int codesize) {
numStrings_ = 0;
for (int q = 0; q < HASHSIZE; q++) {
strHsh_[q] = HASH_FREE;
}
int w = (1 << codesize) + RES_CODES;
for (int q = 0; q < w; q++)
AddCharString((short)0xFFFF, (byte)q);
}
static public int Hash(short index, byte lastbyte) {
return ((int)((short)(lastbyte << 8) ^ index) & 0xFFFF) % HASHSIZE;
}
}
class LZWCompressor {
public static void LZWCompress(OutputStream output, int codesize,
byte toCompress[]) throws IOException {
byte c;
short index;
int clearcode, endofinfo, numbits, limit, errcode;
short prefix = (short)0xFFFF;
BitFile bitFile = new BitFile(output);
LZWStringTable strings = new LZWStringTable();
clearcode = 1 << codesize;
endofinfo = clearcode + 1;
numbits = codesize + 1;
limit = (1 << numbits) - 1;
strings.ClearTable(codesize);
bitFile.WriteBits(clearcode, numbits);
for (int loop = 0; loop < toCompress.length; ++loop) {
c = toCompress[loop];
if ((index = strings.FindCharString(prefix, c)) != -1)
prefix = index;
else {
bitFile.WriteBits(prefix, numbits);
if (strings.AddCharString(prefix, c) > limit) {
if (++numbits > 12) {
bitFile.WriteBits(clearcode, numbits - 1);
strings.ClearTable(codesize);
numbits = codesize + 1;
}
limit = (1 << numbits) - 1;
}
prefix = (short)((short)c & 0xFF);
}
}
if (prefix != -1)
bitFile.WriteBits(prefix, numbits);
bitFile.WriteBits(endofinfo, numbits);
bitFile.Flush();
}
}
class ScreenDescriptor {
public short localScreenWidth_, localScreenHeight_;
private byte byte_;
public byte backgroundColorIndex_, pixelAspectRatio_;
public ScreenDescriptor(short width, short height, int numColors) {
localScreenWidth_ = width;
localScreenHeight_ = height;
SetGlobalColorTableSize((byte)(BitUtils.BitsNeeded(numColors) - 1));
SetGlobalColorTableFlag((byte)1);
SetSortFlag((byte)0);
SetColorResolution((byte)7);
backgroundColorIndex_ = 0;
pixelAspectRatio_ = 0;
}
public void Write(OutputStream output) throws IOException {
BitUtils.WriteWord(output, localScreenWidth_);
BitUtils.WriteWord(output, localScreenHeight_);
output.write(byte_);
output.write(backgroundColorIndex_);
output.write(pixelAspectRatio_);
}
public void SetGlobalColorTableSize(byte num) {
byte_ |= (num & 7);
}
public void SetSortFlag(byte num) {
byte_ |= (num & 1) << 3;
}
public void SetColorResolution(byte num) {
byte_ |= (num & 7) << 4;
}
public void SetGlobalColorTableFlag(byte num) {
byte_ |= (num & 1) << 7;
}
}
class ImageDescriptor {
public byte separator_;
public short leftPosition_, topPosition_, width_, height_;
private byte byte_;
public ImageDescriptor(short width, short height, char separator) {
separator_ = (byte)separator;
leftPosition_ = 0;
topPosition_ = 0;
width_ = width;
height_ = height;
SetLocalColorTableSize((byte)0);
SetReserved((byte)0);
SetSortFlag((byte)0);
SetInterlaceFlag((byte)0);
SetLocalColorTableFlag((byte)0);
}
public void Write(OutputStream output) throws IOException {
output.write(separator_);
BitUtils.WriteWord(output, leftPosition_);
BitUtils.WriteWord(output, topPosition_);
BitUtils.WriteWord(output, width_);
BitUtils.WriteWord(output, height_);
output.write(byte_);
}
public void SetLocalColorTableSize(byte num) {
byte_ |= (num & 7);
}
public void SetReserved(byte num) {
byte_ |= (num & 3) << 3;
}
public void SetSortFlag(byte num) {
byte_ |= (num & 1) << 5;
}
public void SetInterlaceFlag(byte num) {
byte_ |= (num & 1) << 6;
}
public void SetLocalColorTableFlag(byte num) {
byte_ |= (num & 1) << 7;
}
}
class BitUtils {
public static byte BitsNeeded(int n) {
byte ret = 1;
if (n-- == 0)
return 0;
while ((n >>= 1) != 0)
++ret;
return ret;
}
public static void WriteWord(OutputStream output,
short w) throws IOException {
output.write(w & 0xFF);
output.write((w >> 8) & 0xFF);
}
static void WriteString(OutputStream output,
String string) throws IOException {
for (int loop = 0; loop < string.length(); ++loop)
output.write((byte)(string.charAt(loop)));
}
}
There was peace and harmony in the home of the Reverend Taylor. An air of neatness and prosperity was about his four-room adobe house. The mocking-bird that hung in a willow cage against the white wall, by the door, whistled sweet mimicry of the cheep of the little chickens in the back yard, and hopped to and fro and up and down on his perches, pecking at the red chili between the bars. From the corner of his eyes he could peek into the window, and it was bright with potted geraniums, white as the wall, or red as the chili, or pink as the little crumpled palm that patted against the glass to him. It was the first scene of the closing act of the tragic comedy of the Geronimo campaign. That wily old devil, weary temporarily of the bloodshed he had continued with more or less regularity for many years, had[Pg 297] sent word to the officers that he would meet them without their commands, in the Ca?on de los Embudos, across the border line, to discuss the terms of surrender. The officers had forthwith come, Crook yet hopeful that something might be accomplished by honesty and plain dealing; the others, for the most part, doubting. The two rival Ministers of England became every day more embittered against each other; and Bolingbroke grew more daring in his advances towards the Pretender, and towards measures only befitting a Stuart's reign. In order to please the High Church, whilst he was taking the surest measures to ruin it by introducing a popish prince, he consulted with Atterbury, and they agreed to bring in a Bill which should prevent Dissenters from educating their own children. This measure was sure to please the Hanoverian Tories, who were as averse from the Dissenters as the Whigs. Thus it would conciliate them and obtain their support at the[19] very moment that the chief authors of it were planning the ruin of their party. This Bill was called the Schism Bill, and enjoined that no person in Great Britain should keep any school, or act as tutor, who had not first subscribed the declaration to conform to the Church of England, and obtained a licence of the diocesan. Upon failure of so doing, the party might be committed to prison without bail; and no such licence was to be granted before the party produced a certificate of his having received the Sacrament according to the communion of the English Church within the last year, and of his having also subscribed the oaths of Allegiance and Supremacy. The earliest martial event of the year 1760 was the landing of Thurot, the French admiral, at Carrickfergus, on the 28th of February. He had been beating about between Scandinavia and Ireland till he had only three ships left, and but six hundred soldiers. But Carrickfergus being negligently garrisoned, Thurot made his way into the town and plundered it, but was soon obliged to abandon it. He was overtaken by Captain Elliot and three frigates before he had got out to sea, his ships were taken, he himself was killed, and his men were carried prisoners to Ramsey, in the Isle of Man. "I see you've got a cow here," said a large man wearing a dingy blue coat with a Captain's faded shoulder-straps. "I'm a Commissary, and it's my duty to take her." Suddenly they heard little Pete's voice calling: "Stop your ranting and tell me how the hogs got you." "Hold, Lord de Boteler," interrupted Father John, calmly; "the threat need not pass thy lips: I go; but before I depart I shall say, in spite of mortal tongue or mortal hand, that honor and true knighthood no longer preside in this hall, where four generations upheld them unsullied." HoME小明看看台湾视频发布
ENTER NUMBET 0017
www.keci3.net.cn
sishe.net.cn
www.zhuanyila.com.cn
www.ytlr.com.cn
woguo8.com.cn
sunics.com.cn
www.daofa0.net.cn
www.geri2.net.cn
zouju3.net.cn
avxcx.com.cn