home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.iavazip.viewer;
-
- import java.awt.Image;
- import java.io.IOException;
-
- public class ImageLoaderTGA extends ImageLoader implements ProgressStatus {
- // $FF: renamed from: zl int
- private int field_0;
- private int redColor15 = 31744;
- private int greenColor15 = 992;
- private int blueColor15 = 31;
- private int redColor24 = 16711680;
- private int greenColor24 = 65280;
- private int blueColor24 = 255;
- private int orientation;
- private int imgType;
- private int IDlength;
- private int cMapFirst;
- private int xOrigin;
- private int yOrigin;
- private int description;
- private int depth;
- private int pixels;
- private int cMapType;
- private int cMapLength;
- private int cMapEntrySize;
- private int framePtr;
- private int cachePtr;
- private int red;
- private int green;
- private int blue;
- private int col;
- private int cacheStep;
- private int stepFrameCol;
- private int stepFrameRow;
- private int pixelCt;
- private int pixel;
- private int alpha;
- private int fileLength;
- private int RLEtype;
- private int RLElength;
- private int RLEcounter;
- private int RLEpause;
- // $FF: renamed from: w int
- private int field_1;
- // $FF: renamed from: h int
- private int field_2;
- private int value;
- private boolean loaded;
- private boolean RLEencoded;
- private byte[] cache;
- private int[] palette;
-
- protected void loadPicture() throws IOException {
- this.depth = super.imageFile.readByte();
- this.description = super.imageFile.readByte();
- this.orientation = (this.description & 240) >> 4;
- ((ImageLoader)this).print("ID field length: " + this.IDlength);
- ((ImageLoader)this).print("Color map type: " + this.cMapType);
- ((ImageLoader)this).print("Image type: " + this.imgType);
- ((ImageLoader)this).print("First color map entry: " + this.cMapFirst);
- ((ImageLoader)this).print("Color map length: " + this.cMapLength);
- ((ImageLoader)this).print("Color map entry size: " + this.cMapEntrySize);
- ((ImageLoader)this).print("X Origin: " + this.xOrigin);
- ((ImageLoader)this).print("Y Origin: " + this.yOrigin);
- ((ImageLoader)this).print("width: " + this.field_1);
- ((ImageLoader)this).print("height: " + this.field_2);
- ((ImageLoader)this).print("depth: " + this.depth);
- ((ImageLoader)this).print("orientation: " + this.orientation);
- this.RLEpause = 0;
- this.RLEcounter = 0;
- this.RLElength = 1;
- if (this.imgType == 9 | this.imgType == 10 | this.imgType == 11) {
- ((ImageLoader)this).print("RLE encoded picture");
- this.RLEencoded = true;
- }
-
- super.imageFile.skipBytes(this.IDlength);
- if (this.cMapType == 1) {
- if (this.cMapEntrySize == 16) {
- }
-
- ((ImageLoader)this).print("loading color map");
- this.palette = new int[this.cMapLength * (this.cMapEntrySize / 8)];
- this.value = 0;
-
- for(this.field_0 = 0; this.field_0 < this.cMapLength; ++this.field_0) {
- if (this.cMapEntrySize == 24) {
- this.palette[this.value++] = super.imageFile.readByte();
- this.palette[this.value++] = super.imageFile.readByte();
- this.palette[this.value++] = super.imageFile.readByte();
- }
- }
- }
-
- this.pixels = this.field_1 * this.field_2;
- if (!this.RLEencoded) {
- this.cache = super.imageFile.readBytes(this.pixels * (this.depth / 8), this);
- ((ImageLoader)this).print("data bytes in cache: " + this.cache.length);
- }
-
- ((ImageLoader)this).print("converting " + super.frameBuffer.length + " pixels");
- this.stepFrameCol = 1;
- this.stepFrameRow = -(2 * super.xRes);
- this.framePtr = (super.yRes - 1) * super.xRes;
- this.pixelCt = 0;
- if (this.orientation == 16) {
- this.stepFrameCol = -1;
- this.stepFrameRow = 0;
- this.framePtr = this.pixels - 1;
- } else if (this.orientation == 32) {
- this.stepFrameCol = 1;
- this.stepFrameRow = 0;
- this.framePtr = 0;
- } else if (this.orientation == 48) {
- this.stepFrameCol = -1;
- this.stepFrameRow = 2 * super.xRes;
- this.framePtr = super.xRes - 1;
- }
-
- if (this.imgType == 1 | this.imgType == 9) {
- this.decodeCMAP();
- } else if (this.imgType == 2 | this.imgType == 10) {
- this.decodeTC();
- } else if (this.imgType == 3 | this.imgType == 11) {
- this.decodeGray();
- }
-
- ((ImageLoader)this).print("image decoded, closing file");
- super.imageFile.close();
- super.imageLoaded = true;
- this.cache = null;
- this.palette = null;
- System.gc();
- }
-
- private void decodeGray() throws IOException {
- ((ImageLoader)this).print("loading a grayscale image");
-
- while(this.pixelCt < this.pixels) {
- if (this.RLEencoded) {
- if (this.RLEpause == 0) {
- this.decodeRLE();
- }
-
- this.pixel = super.imageFile.readByte();
- } else {
- this.pixel = this.cache[this.cachePtr++] & 255;
- }
-
- this.value = (this.alpha << 24) + (this.pixel << 16) + (this.pixel << 8) + this.pixel;
-
- for(this.RLEcounter = 0; this.RLEcounter < this.RLElength; ++this.RLEcounter) {
- super.frameBuffer[this.framePtr] = this.value;
- this.framePtr += this.stepFrameCol;
- ++this.col;
- if (this.col == super.xRes) {
- this.framePtr += this.stepFrameRow;
- this.col = 0;
- }
-
- ++this.pixelCt;
- }
-
- if (this.RLEpause > 0) {
- this.RLEpause += -1;
- }
- }
-
- }
-
- private void decodeCMAP() throws IOException {
- if (this.depth != 16 && this.depth == 8) {
- ((ImageLoader)this).print("decoding an 8-bit TGA image with palette");
-
- while(this.pixelCt < this.pixels) {
- if (this.RLEencoded) {
- if (this.RLEpause == 0) {
- this.decodeRLE();
- }
-
- this.pixel = super.imageFile.readByte() * 3;
- } else {
- this.pixel = (this.cache[this.cachePtr] & 255) * 3;
- ++this.cachePtr;
- }
-
- this.red = this.palette[this.pixel + 2];
- this.green = this.palette[this.pixel + 1];
- this.blue = this.palette[this.pixel];
- this.value = (this.red << 16) + (this.green << 8) + this.blue;
-
- for(this.RLEcounter = 0; this.RLEcounter < this.RLElength; ++this.RLEcounter) {
- super.frameBuffer[this.framePtr] = this.value;
- this.framePtr += this.stepFrameCol;
- ++this.col;
- if (this.col == super.xRes) {
- this.framePtr += this.stepFrameRow;
- this.col = 0;
- }
-
- ++this.pixelCt;
- }
-
- if (this.RLEpause > 0) {
- this.RLEpause += -1;
- }
- }
- }
-
- }
-
- public void imageLoaded(int var1, Image var2, String var3) {
- }
-
- private final void decodeRLE() throws IOException {
- int var1 = super.imageFile.readByte();
- this.RLEtype = var1 & 128;
- this.RLElength = (var1 & 127) + 1;
- if (this.RLEtype == 0) {
- this.RLEpause = this.RLElength;
- this.RLElength = 1;
- }
-
- }
-
- public String getInfo() {
- return "";
- }
-
- protected void readHeader() throws IOException {
- ((ImageLoader)this).print(this.getInfo() + " running");
- super.imageFile.setIntelSwitch(true);
- this.IDlength = super.imageFile.readByte();
- this.cMapType = super.imageFile.readByte();
- this.imgType = super.imageFile.readByte();
- this.cMapFirst = super.imageFile.read16Bit();
- this.cMapLength = super.imageFile.read16Bit();
- this.cMapEntrySize = super.imageFile.readByte();
- this.xOrigin = super.imageFile.read16Bit();
- this.yOrigin = super.imageFile.read16Bit();
- this.field_1 = super.imageFile.read16Bit();
- this.field_2 = super.imageFile.read16Bit();
- ((ImageLoader)this).initFrameBuffer(this.field_1, this.field_2);
- }
-
- private final void decodeTC() throws IOException {
- ((ImageLoader)this).print("loading a True Color image");
- if (this.depth == 16) {
- while(this.pixelCt < this.pixels) {
- if (this.RLEencoded) {
- if (this.RLEpause == 0) {
- this.decodeRLE();
- }
-
- this.pixel = super.imageFile.readByte();
- this.pixel += super.imageFile.readByte() * 256;
- } else {
- this.pixel = this.cache[this.cachePtr + 1] & 255;
- this.pixel = (this.pixel << 8) + (this.cache[this.cachePtr] & 255);
- this.cachePtr += 2;
- }
-
- this.red = (this.pixel & this.redColor15) >> 10;
- this.green = (this.pixel & this.greenColor15) >> 5;
- this.blue = this.pixel & this.blueColor15;
- this.red = this.red << 8 >> 5;
- this.green = this.green << 8 >> 5;
- this.blue = this.blue << 8 >> 5;
- this.value = (this.alpha << 24) + (this.red << 16) + (this.green << 8) + this.blue;
-
- for(this.RLEcounter = 0; this.RLEcounter < this.RLElength; ++this.RLEcounter) {
- super.frameBuffer[this.framePtr] = this.value;
- this.framePtr += this.stepFrameCol;
- ++this.col;
- if (this.col == super.xRes) {
- this.framePtr += this.stepFrameRow;
- this.col = 0;
- }
-
- ++this.pixelCt;
- }
-
- if (this.RLEpause > 0) {
- this.RLEpause += -1;
- }
- }
-
- } else if (this.depth == 24) {
- while(this.pixelCt < this.pixels) {
- if (this.RLEencoded) {
- if (this.RLEpause == 0) {
- this.decodeRLE();
- }
-
- this.blue = super.imageFile.readByte();
- this.green = super.imageFile.readByte();
- this.red = super.imageFile.readByte();
- } else {
- this.red = this.cache[this.cachePtr + 2];
- this.green = this.cache[this.cachePtr + 1];
- this.blue = this.cache[this.cachePtr];
- this.cachePtr += 3;
- }
-
- this.value = (this.alpha << 24) + (this.red << 16) + (this.green << 8) + this.blue;
-
- for(this.RLEcounter = 0; this.RLEcounter < this.RLElength; ++this.RLEcounter) {
- super.frameBuffer[this.framePtr] = this.value;
- this.framePtr += this.stepFrameCol;
- ++this.col;
- if (this.col == super.xRes) {
- this.framePtr += this.stepFrameRow;
- this.col = 0;
- }
-
- ++this.pixelCt;
- }
-
- if (this.RLEpause > 0) {
- this.RLEpause += -1;
- }
- }
-
- } else {
- if (this.depth == 32) {
- while(this.pixelCt < this.pixels) {
- if (this.RLEencoded) {
- if (this.RLEpause == 0) {
- this.decodeRLE();
- }
-
- this.blue = super.imageFile.readByte();
- this.green = super.imageFile.readByte();
- this.red = super.imageFile.readByte();
- this.alpha = super.imageFile.readByte();
- } else {
- this.red = this.cache[this.cachePtr + 2];
- this.green = this.cache[this.cachePtr + 1];
- this.blue = this.cache[this.cachePtr];
- this.alpha = this.cache[this.cachePtr + 3];
- this.cachePtr += 4;
- }
-
- this.value = (this.alpha << 24) + (this.red << 16) + (this.green << 8) + this.blue;
-
- for(this.RLEcounter = 0; this.RLEcounter < this.RLElength; ++this.RLEcounter) {
- super.frameBuffer[this.framePtr] = this.value;
- this.framePtr += this.stepFrameCol;
- ++this.col;
- if (this.col == super.xRes) {
- this.framePtr += this.stepFrameRow;
- this.col = 0;
- }
-
- ++this.pixelCt;
- }
-
- if (this.RLEpause > 0) {
- this.RLEpause += -1;
- }
- }
- }
-
- }
- }
- }
-