Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarolyn MacLeod2006-07-21 20:45:27 +0000
committerCarolyn MacLeod2006-07-21 20:45:27 +0000
commit9d641661f9a95af3af883ac705fdd29bdc419737 (patch)
tree5992d680f2ccf4a448b16a8818e6dd3425fb09a2 /bundles
parent60f05e834f3366737ec4eec8b5e2e74de1148952 (diff)
downloadeclipse.platform.swt-9d641661f9a95af3af883ac705fdd29bdc419737.tar.gz
eclipse.platform.swt-9d641661f9a95af3af883ac705fdd29bdc419737.tar.xz
eclipse.platform.swt-9d641661f9a95af3af883ac705fdd29bdc419737.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/PngPlteChunk.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java
index 4fd7635215..a216966533 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/image/PngPlteChunk.java
@@ -16,9 +16,12 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.Compatibility;
class PngPlteChunk extends PngChunk {
+
+ int paletteSize;
PngPlteChunk(PaletteData palette) {
super(palette.getRGBs().length * 3);
+ paletteSize = length / 3;
setType(TYPE_PLTE);
setPaletteData(palette);
setCRC(computeCRC());
@@ -26,6 +29,7 @@ PngPlteChunk(PaletteData palette) {
PngPlteChunk(byte[] reference){
super(reference);
+ paletteSize = length / 3;
}
int getChunkType() {
@@ -36,7 +40,7 @@ int getChunkType() {
* Get the number of colors in this palette.
*/
int getPaletteSize() {
- return getLength() / 3;
+ return paletteSize;
}
/**
@@ -46,9 +50,9 @@ int getPaletteSize() {
* does not store the palette data created.
*/
PaletteData getPaletteData() {
- RGB[] rgbs = new RGB[getPaletteSize()];
+ RGB[] rgbs = new RGB[paletteSize];
// int start = DATA_OFFSET;
-// int end = DATA_OFFSET + getLength();
+// int end = DATA_OFFSET + length;
for (int i = 0; i < rgbs.length; i++) {
int offset = DATA_OFFSET + (i * 3);
int red = reference[offset] & 0xFF;
@@ -102,17 +106,17 @@ void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
// Palettes cannot have more entries than 2^bitDepth
// where bitDepth is the bit depth of the image given
// in the IHDR chunk.
- if (Compatibility.pow2(headerChunk.getBitDepth()) < getPaletteSize()) {
+ if (Compatibility.pow2(headerChunk.getBitDepth()) < paletteSize) {
SWT.error(SWT.ERROR_INVALID_IMAGE);
}
// Palettes cannot have more than 256 entries.
- if (256 < getPaletteSize()) SWT.error(SWT.ERROR_INVALID_IMAGE);
+ if (256 < paletteSize) SWT.error(SWT.ERROR_INVALID_IMAGE);
}
void contributeToString(StringBuffer buffer) {
buffer.append("\n\tPalette size:");
- buffer.append(getPaletteSize());
+ buffer.append(paletteSize);
}
}

Back to the top