Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod2006-07-21 20:29:22 +0000
committerCarolyn MacLeod2006-07-21 20:29:22 +0000
commit60f05e834f3366737ec4eec8b5e2e74de1148952 (patch)
tree36d44bb2012c537d8fe0b2740bf7d931bc38d3b7 /bundles
parent74bf23c887e16240672a94edbe743cb74ce252c3 (diff)
downloadeclipse.platform.swt-60f05e834f3366737ec4eec8b5e2e74de1148952.tar.gz
eclipse.platform.swt-60f05e834f3366737ec4eec8b5e2e74de1148952.tar.xz
eclipse.platform.swt-60f05e834f3366737ec4eec8b5e2e74de1148952.zip
cache chunk fields instead of getting from reference every time
Diffstat (limited to 'bundles')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java6
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java8
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java76
3 files changed, 52 insertions, 38 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java
index 2c8159ca23..1847884c6a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngChunk.java
@@ -56,6 +56,8 @@ class PngChunk extends Object {
}
}
+ int length;
+
/**
* Construct a PngChunk using the reference bytes
* given.
@@ -63,6 +65,7 @@ class PngChunk extends Object {
PngChunk(byte[] reference) {
super();
setReference(reference);
+ length = getInt32(LENGTH_OFFSET);
}
/**
@@ -137,7 +140,7 @@ void setInt32(int offset, int value) {
* This is not the length of the entire chunk.
*/
int getLength() {
- return getInt32(LENGTH_OFFSET);
+ return length;
}
/**
@@ -146,6 +149,7 @@ int getLength() {
*/
void setLength(int value) {
setInt32(LENGTH_OFFSET, value);
+ length = value;
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java
index 7d228871ae..de5ccd5670 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngDecodingDataStream.java
@@ -57,14 +57,12 @@ int getNextIdatBits(int length) {
return value;
}
-byte getNextIdatBit() {
+int getNextIdatBit() {
if (nextBitIndex > MAX_BIT) {
currentByte = getNextIdatByte();
nextBitIndex = 0;
- }
- int mask = 1 << nextBitIndex;
- nextBitIndex++;
- return ((currentByte & mask) > 0) ? (byte) 1 : (byte) 0;
+ }
+ return (currentByte & (1 << nextBitIndex)) >> nextBitIndex++;
}
private PngIdatChunk getNextChunk() {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java
index dbc9ab38c7..987f559cc2 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngIhdrChunk.java
@@ -44,6 +44,9 @@ class PngIhdrChunk extends PngChunk {
static final byte[] ValidBitDepths = {1, 2, 4, 8, 16};
static final byte[] ValidColorTypes = {0, 2, 3, 4, 6};
+ int width, height;
+ byte bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod;
+
PngIhdrChunk(int width, int height, byte bitDepth, byte colorType, byte compressionMethod, byte filterMethod, byte interlaceMethod) {
super(IHDR_DATA_LENGTH);
setType(TYPE_IHDR);
@@ -63,6 +66,13 @@ PngIhdrChunk(int width, int height, byte bitDepth, byte colorType, byte compress
*/
PngIhdrChunk(byte[] reference) {
super(reference);
+ width = getInt32(WIDTH_DATA_OFFSET);
+ height = getInt32(HEIGHT_DATA_OFFSET);
+ bitDepth = reference[BIT_DEPTH_OFFSET];
+ colorType = reference[COLOR_TYPE_OFFSET];
+ compressionMethod = reference[COMPRESSION_METHOD_OFFSET];
+ filterMethod = reference[FILTER_METHOD_OFFSET];
+ interlaceMethod = reference[INTERLACE_METHOD_OFFSET];
}
int getChunkType() {
@@ -73,7 +83,7 @@ int getChunkType() {
* Get the image's width in pixels.
*/
int getWidth() {
- return getInt32(WIDTH_DATA_OFFSET);
+ return width;
}
/**
@@ -81,13 +91,14 @@ int getWidth() {
*/
void setWidth(int value) {
setInt32(WIDTH_DATA_OFFSET, value);
+ width = value;
}
/**
* Get the image's height in pixels.
*/
int getHeight() {
- return getInt32(HEIGHT_DATA_OFFSET);
+ return height;
}
/**
@@ -95,6 +106,7 @@ int getHeight() {
*/
void setHeight(int value) {
setInt32(HEIGHT_DATA_OFFSET, value);
+ height = value;
}
/**
@@ -102,7 +114,7 @@ void setHeight(int value) {
* This is limited to the values 1, 2, 4, 8, or 16.
*/
byte getBitDepth() {
- return reference[BIT_DEPTH_OFFSET];
+ return bitDepth;
}
/**
@@ -111,6 +123,7 @@ byte getBitDepth() {
*/
void setBitDepth(byte value) {
reference[BIT_DEPTH_OFFSET] = value;
+ bitDepth = value;
}
/**
@@ -123,7 +136,7 @@ void setBitDepth(byte value) {
* 6 - RGB with Alpha channel.
*/
byte getColorType() {
- return reference[COLOR_TYPE_OFFSET];
+ return colorType;
}
/**
@@ -137,6 +150,7 @@ byte getColorType() {
*/
void setColorType(byte value) {
reference[COLOR_TYPE_OFFSET] = value;
+ colorType = value;
}
/**
@@ -144,7 +158,7 @@ void setColorType(byte value) {
* This value must be 0.
*/
byte getCompressionMethod() {
- return reference[COMPRESSION_METHOD_OFFSET];
+ return compressionMethod;
}
/**
@@ -153,6 +167,7 @@ byte getCompressionMethod() {
*/
void setCompressionMethod(byte value) {
reference[COMPRESSION_METHOD_OFFSET] = value;
+ compressionMethod = value;
}
/**
@@ -160,7 +175,7 @@ void setCompressionMethod(byte value) {
* This value must be 0.
*/
byte getFilterMethod() {
- return reference[FILTER_METHOD_OFFSET];
+ return filterMethod;
}
/**
@@ -169,6 +184,7 @@ byte getFilterMethod() {
*/
void setFilterMethod(byte value) {
reference[FILTER_METHOD_OFFSET] = value;
+ filterMethod = value;
}
/**
@@ -178,7 +194,7 @@ void setFilterMethod(byte value) {
* 1 - Adam7 interlacing used.
*/
byte getInterlaceMethod() {
- return reference[INTERLACE_METHOD_OFFSET];
+ return interlaceMethod;
}
/**
@@ -189,6 +205,7 @@ byte getInterlaceMethod() {
*/
void setInterlaceMethod(byte value) {
reference[INTERLACE_METHOD_OFFSET] = value;
+ interlaceMethod = value;
}
/**
@@ -209,15 +226,14 @@ void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
super.validate(readState, headerChunk);
- if (getLength() != IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (getCompressionMethod() != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
- if (getInterlaceMethod() != INTERLACE_METHOD_NONE &&
- getInterlaceMethod() != INTERLACE_METHOD_ADAM7) {
+ if (length != IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
+ if (compressionMethod != 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
+ if (interlaceMethod != INTERLACE_METHOD_NONE &&
+ interlaceMethod != INTERLACE_METHOD_ADAM7) {
SWT.error(SWT.ERROR_INVALID_IMAGE);
}
boolean colorTypeIsValid = false;
- byte colorType = getColorType();
for (int i = 0; i < ValidColorTypes.length; i++) {
if (ValidColorTypes[i] == colorType) {
colorTypeIsValid = true;
@@ -227,7 +243,6 @@ void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
if (!colorTypeIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE);
boolean bitDepthIsValid = false;
- byte bitDepth = getBitDepth();
for (int i = 0; i < ValidBitDepths.length; i++) {
if (ValidBitDepths[i] == bitDepth) {
bitDepthIsValid = true;
@@ -250,18 +265,18 @@ void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
}
String getColorTypeString() {
- switch (getColorType()) {
+ switch (colorType) {
case COLOR_TYPE_GRAYSCALE: return "Grayscale";
case COLOR_TYPE_RGB: return "RGB";
case COLOR_TYPE_PALETTE: return "Palette";
case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: return "Grayscale with Alpha";
case COLOR_TYPE_RGB_WITH_ALPHA: return "RGB with Alpha";
- default: return "Unknown - " + getColorType();
+ default: return "Unknown - " + colorType;
}
}
String getFilterMethodString() {
- switch (getFilterMethod()) {
+ switch (filterMethod) {
case FILTER_NONE: return "None";
case FILTER_SUB: return "Sub";
case FILTER_UP: return "Up";
@@ -272,7 +287,7 @@ String getFilterMethodString() {
}
String getInterlaceMethodString() {
- switch (getInterlaceMethod()) {
+ switch (interlaceMethod) {
case INTERLACE_METHOD_NONE: return "Not Interlaced";
case INTERLACE_METHOD_ADAM7: return "Interlaced - ADAM7";
default: return "Unknown";
@@ -281,15 +296,15 @@ String getInterlaceMethodString() {
void contributeToString(StringBuffer buffer) {
buffer.append("\n\tWidth: ");
- buffer.append(getWidth());
+ buffer.append(width);
buffer.append("\n\tHeight: ");
- buffer.append(getHeight());
+ buffer.append(height);
buffer.append("\n\tBit Depth: ");
- buffer.append(getBitDepth());
+ buffer.append(bitDepth);
buffer.append("\n\tColor Type: ");
buffer.append(getColorTypeString());
buffer.append("\n\tCompression Method: ");
- buffer.append(getCompressionMethod());
+ buffer.append(compressionMethod);
buffer.append("\n\tFilter Method: ");
buffer.append(getFilterMethodString());
buffer.append("\n\tInterlace Method: ");
@@ -297,11 +312,10 @@ void contributeToString(StringBuffer buffer) {
}
boolean getMustHavePalette() {
- return getColorType() == COLOR_TYPE_PALETTE;
+ return colorType == COLOR_TYPE_PALETTE;
}
boolean getCanHavePalette() {
- int colorType = getColorType();
return colorType != COLOR_TYPE_GRAYSCALE &&
colorType != COLOR_TYPE_GRAYSCALE_WITH_ALPHA;
}
@@ -311,8 +325,7 @@ boolean getCanHavePalette() {
* and bit depth.
*/
int getBitsPerPixel() {
- int bitDepth = getBitDepth();
- switch (getColorType()) {
+ switch (colorType) {
case COLOR_TYPE_RGB_WITH_ALPHA:
return 4 * bitDepth;
case COLOR_TYPE_RGB:
@@ -333,8 +346,7 @@ int getBitsPerPixel() {
* and bit depth.
*/
int getSwtBitsPerPixel() {
- int bitDepth = getBitDepth();
- switch (getColorType()) {
+ switch (colorType) {
case COLOR_TYPE_RGB_WITH_ALPHA:
case COLOR_TYPE_RGB:
case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
@@ -349,12 +361,12 @@ int getSwtBitsPerPixel() {
}
int getFilterByteOffset() {
- if (getBitDepth() < 8) return 1;
+ if (bitDepth < 8) return 1;
return getBitsPerPixel() / 8;
}
boolean usesDirectColor() {
- switch (getColorType()) {
+ switch (colorType) {
case COLOR_TYPE_GRAYSCALE:
case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
case COLOR_TYPE_RGB:
@@ -366,8 +378,8 @@ boolean usesDirectColor() {
}
PaletteData createGrayscalePalette() {
- int bitDepth = Math.min(getBitDepth(), 8);
- int max = Compatibility.pow2(bitDepth) - 1;
+ int depth = Math.min(bitDepth, 8);
+ int max = Compatibility.pow2(depth) - 1;
int delta = 255 / max;
int gray = 0;
RGB[] rgbs = new RGB[max + 1];
@@ -379,7 +391,7 @@ PaletteData createGrayscalePalette() {
}
PaletteData getPaletteData() {
- switch (getColorType()) {
+ switch (colorType) {
case COLOR_TYPE_GRAYSCALE:
return createGrayscalePalette();
case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:

Back to the top