📄 fscoder.java
字号:
int start = ptr;
int value = readWord(numberOfBytes, signed);
ptr = start;
return value;
}
/*
* Methods for accessing fixed point (8.8) and (16.16) values.
*/
/**
* Read a fixed point number, in either (8.8) or (16.16) format from a bit
* field.
*
* @param numberOfBits the number of bits the number is encoded in.
* @param fractionSize the number of bits occupied by the fractional
* part of the number. The integer part will be signed extended.
*
* @return the value read as a floating-point number.
*/
public float readFixedBits(int numberOfBits, int fractionSize)
{
float divisor = (float)(1 << fractionSize);
float value = ((float)readBits(numberOfBits, true)) / divisor;
return value;
}
/**
* Write a fixed point number, in either (8.8) or (16.16) format to a bit
* field.
*
* @param value the value to be ecoded.
* @param numberOfBits the number of bits the number is encoded in.
* @param fractionSize the number of bits occupied by the fractional
* part of the number. The integer part will be signed extended.
*/
public void writeFixedBits(float value, int numberOfBits, int fractionSize)
{
float multiplier = (float)(1 << fractionSize);
writeBits((int)(value*multiplier), numberOfBits);
}
/**
* Read a fixed point number, in either (8.8) or (16.16) format from a
* word field, accounting for the byte-ordering used.
*
* @param mantissaSize the number of bits occupied by the integer
* part of the number. This will be signed extended.
* @param fractionSize the number of bits occupied by the fractional
* part of the number.
*
* @return the value read as a floating-point number.
*/
public float readFixedWord(int mantissaSize, int fractionSize)
{
float divisor = (float)(1 << (fractionSize*8));
int fraction = readWord(fractionSize, false);
int mantissa = readWord(mantissaSize, true) << (fractionSize*8);
return (mantissa + fraction) / divisor;
}
/**
* Write a fixed point number, in either (8.8) or (16.16) format to a
* word field, accounting for the byte-ordering used.
*
* @param value the value to be written.
* @param mantissaSize the number of bits occupied by the integer
* part of the number.
* @param fractionSize the number of bits occupied by the fractional
* part of the number.
*/
public void writeFixedWord(float value, int mantissaSize, int fractionSize)
{
float multiplier = (float)(1 << (fractionSize*8));
int fraction = (int)(value*multiplier);
int mantissa = (int)value;
writeWord(fraction, fractionSize);
writeWord(mantissa, mantissaSize);
}
/*
* Methods for reading specific data types
*/
/**
* Read a double-precision floating point number from a sequence of bytes
* using the byte-ordering of the buffer.
*
* @return the value.
*/
public double readDouble()
{
int upperInt = readWord(4, false);
int lowerInt = readWord(4, false);
long longValue = (long)upperInt << 32;
longValue |= (long)lowerInt & 0x00000000FFFFFFFFL;
return Double.longBitsToDouble(longValue);
}
/**
* Write a double-precision floating point number as a sequence of bytes
* using the byte-ordering of the buffer.
*
* @param value the value to be written.
*/
public void writeDouble(double value)
{
long longValue = Double.doubleToLongBits(value);
int lowerInt = (int)longValue;
int upperInt = (int)(longValue >>> 32);
writeWord(upperInt, 4);
writeWord(lowerInt, 4);
}
/**
* Read a string containing the specified number of characters using the
* default character encoding scheme.
*
* @param length the number of characters to read.
*
* @return the string containing the specified number of characters.
*/
public String readString(int length)
{
return readString(length, encoding);
}
/**
* Read a string containing the specified number of characters with the
* given character encoding scheme.
*
* @param length the number of characters to read.
* @return enc, the string the name of the encoding schemd for characters.
*
* @return the string containing the specified number of characters.
*/
public String readString(int length, String enc)
{
if (length == 0)
return "";
String value = null;
byte[] str = new byte[length];
int len = readBytes(str);
try {
value = new String(str, 0, len, enc);
}
catch (java.io.UnsupportedEncodingException e)
{
value = "";
}
return value;
}
/**
* Read a null-terminated string using the default character encoding scheme.
*
* @return the string read from the internal buffer.
*/
public String readString()
{
return readString(encoding);
}
/**
* Read a null-terminated string using the specified character encoding scheme.
*
* @return the string read from the internal buffer.
*/
public String readString(String enc)
{
String value = null;
int start = ptr>>3;
int length = 0;
while (start < data.length && data[start++] != 0) length++;
byte[] str = new byte[length];
int len = readBytes(str);
try {
value = new String(str, 0, len, enc);
}
catch (java.io.UnsupportedEncodingException e)
{
value = "";
}
readWord(1, false);
len++;
return value;
}
/**
* Write a string to the internal buffer using the default character
* encoding scheme.
*
* @param str the string.
*
* @return the number of bytes written.
*/
public int writeString(String str)
{
return writeString(str, encoding);
}
/**
* Write a string to the internal buffer using the specified character
* encoding scheme.
*
* @param str the string.
*
* @return the number of bytes written.
*/
public int writeString(String str, String enc)
{
int bytesWritten = 0;
try
{
bytesWritten = writeBytes(str.getBytes(enc));
}
catch (java.io.UnsupportedEncodingException e)
{
}
return bytesWritten;
}
/*
* Methods for searching the data
*/
/**
* Searches the internal buffer for a bit pattern and advances the pointer
* to the start of the bit field, returning true to signal a successful
* search. If the bit pattern cannot be found then the method returns false
* and the position of the internal pointer is not changed.
*
* The step, in bits, added to the pointer can be specified, allowing the
* number of bits being searched to be independent of the location in the
* internal buffer. This is useful for example when searching for a bit
* field that begins on a byte or word boundary.
*
* @param value an integer containing the bit patter to search for.
* @param numberOfBits least significant n bits in the value to search for.
* @param step the increment in bits to add to the internal pointer as the
* buffer is searched.
*
* @return true if the pattern was found, false otherwise.
*/
public boolean findBits(int value, int numberOfBits, int step)
{
boolean found = false;
int start = ptr;
for (; ptr < end; ptr += step)
{
if (scanBits(numberOfBits, false) == value)
{
found = true;
break;
}
}
if (found == false)
ptr = start;
return found;
}
/**
* Searches the internal buffer for a word and advances the pointer to the
* location where the word was found, returning true to signal a successful
* search. The search will begin on the next byte boundary. If word cannot
* be found then the method returns false and the position of the internal
* pointer is not changed.
*
* Specifying the number of bytes in the search value allows word of either
* 8, 16, 24 or 32 bits to be searched for. Searches for words are performed
* faster than using the findBits() method.
*
* @param value an integer containing the word to search for.
*
* @param numberOfBytes least significant n bytes in the value to search
* for.
*
* @param step the increment in bits to add to the internal pointer as the
* buffer is searched.
*
* @return true if the pattern was found, false otherwise.
*/
public boolean findWord(int value, int numberOfBytes, int step)
{
boolean found = false;
for (; ptr < end; ptr += step)
{
if (scanWord(numberOfBytes, false) == value)
{
found = true;
break;
}
}
return found;
}
/*
* Context variables are used to pass information between objects when
* they are being encoded or decoded. Context variables are primarily
* used within the Transform classes however they are also used when
* performing unit tests on classes.
*/
/**
* TransparentColors is used to pass information to FSCOlor objects when
* they are being encoded or decoded so that the alpha channel will be
* included.
*/
public static final int TransparentColors = 0;
static final int Action = 1;
/**
* Version is used to pass the current version of Flash that an object is
* being encoded or decoded for.
*/
public static final int Version = 2;
static final int Type = 3;
static final int Empty = 4;
static final int Identifier = 5;
static final int NumberOfFillBits = 6;
static final int NumberOfLineBits = 7;
static final int NumberOfAdvanceBits = 8;
static final int NumberOfGlyphBits = 9;
static final int NumberOfShapeBits = 10;
static final int ArrayCountExtended = 11;
static final int WideCodes = 12;
static final int Delta = 13;
static final int CodingError = 14;
static final int TypeInError = 15;
static final int StartOfError = 16;
static final int ExpectedLength = 17;
static final int DecodeActions = 18;
static final int DecodeShapes = 19;
static final int DecodeGlyphs = 20;
int[] context = new int[21];
private void clearContext()
{
for (int i=0; i<context.length; i++)
context[i] = 0;
}
public int getContext(int key)
{
return context[key];
}
public void setContext(int key, int value)
{
context[key] = value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -