home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / IAVAZIP.EXE / DATA.Z / ImageLoaderBMP.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-18  |  5.4 KB  |  284 lines

  1. package com.sfs.iavazip.viewer;
  2.  
  3. import java.awt.Image;
  4. import java.io.IOException;
  5.  
  6. public class ImageLoaderBMP extends ImageLoader implements ProgressStatus {
  7.    private int[] bmiColors;
  8.    // $FF: renamed from: zl int
  9.    private int field_0;
  10.    private int biPlanes;
  11.    private int biBitCount;
  12.    private int colNum;
  13.    private int redColor15 = 31744;
  14.    private int greenColor15 = 992;
  15.    private int blueColor15 = 31;
  16.    private int redColor24 = 16711680;
  17.    private int greenColor24 = 65280;
  18.    private int blueColor24 = 255;
  19.    private int orientation;
  20.    private int pixels;
  21.    private int framePtr;
  22.    private int cachePtr;
  23.    private int red;
  24.    private int green;
  25.    private int blue;
  26.    private int col;
  27.    private int cacheStep;
  28.    private int stepFrameCol;
  29.    private int stepFrameRow;
  30.    private int pixelCt;
  31.    private int pixel;
  32.    private int lastFramePos;
  33.    private int alpha;
  34.    private int fileLength;
  35.    private int RLEtype;
  36.    private int RLElength;
  37.    private int RLEpause;
  38.    private int padding;
  39.    private int scanLineSize;
  40.    private int actLine;
  41.    private int lastPercent;
  42.    private int actPercent;
  43.    private String bfType;
  44.    private long bfSize;
  45.    private long bfOffBits;
  46.    private long biSize;
  47.    private long biWidth;
  48.    private long biHeight;
  49.    private long biCompression;
  50.    private long biSizeImage;
  51.    private long biClrUsed;
  52.    private long biClrImportant;
  53.    private byte[] cache;
  54.    private boolean loaded;
  55.    private boolean RLEencoded;
  56.  
  57.    protected void loadPicture() throws IOException {
  58.       int var1 = 0;
  59.       if (this.biCompression != 0L) {
  60.          this.RLEencoded = true;
  61.       }
  62.  
  63.       if (this.biBitCount < 24) {
  64.          if (this.biClrUsed > 0L) {
  65.             this.colNum = (int)this.biClrUsed;
  66.          }
  67.  
  68.          this.bmiColors = new int[this.colNum];
  69.  
  70.          for(this.field_0 = 0; this.field_0 < this.colNum; ++this.field_0) {
  71.             this.blue = super.imageFile.readByte() & 255;
  72.             this.green = super.imageFile.readByte() & 255;
  73.             this.red = super.imageFile.readByte() & 255;
  74.             this.bmiColors[this.field_0] = this.red * 65536 + this.green * 256 + this.blue;
  75.             super.imageFile.skipBytes(1);
  76.          }
  77.       }
  78.  
  79.       this.scanLineSize = (int)((this.biWidth * (long)this.biBitCount + 31L) / 32L) * 4;
  80.       if (this.biSizeImage != 0L) {
  81.          var1 = (int)this.biSizeImage;
  82.       } else {
  83.          var1 = (int)((long)this.scanLineSize * this.biHeight);
  84.       }
  85.  
  86.       this.pixels = (int)(this.biWidth * this.biHeight);
  87.       this.cache = super.imageFile.readBytes(var1, this);
  88.       ((ImageLoader)this).print("bytes in the frame's buffer: " + super.frameBuffer.length);
  89.       ((ImageLoader)this).print("bytes in cache: " + this.cache.length);
  90.       ((ImageLoader)this).print("pixels: " + this.pixels);
  91.       this.cachePtr = 0;
  92.       this.stepFrameCol = 1;
  93.       this.stepFrameRow = -(2 * super.xRes);
  94.       this.framePtr = (super.yRes - 1) * super.xRes;
  95.       this.pixelCt = 0;
  96.       this.RLEpause = 0;
  97.       this.RLElength = 1;
  98.       if (this.biBitCount == 8) {
  99.          this.decodeCMAP();
  100.       }
  101.  
  102.       if (this.biBitCount == 24) {
  103.          this.decodeTC();
  104.       }
  105.  
  106.       super.imageFile.close();
  107.       super.imageLoaded = true;
  108.       this.cache = null;
  109.       this.bmiColors = null;
  110.       System.gc();
  111.    }
  112.  
  113.    private void decodeCMAP() throws IOException {
  114.       int var3 = 0;
  115.       int var4 = (int)this.biWidth;
  116.       int var5 = var4 / 4;
  117.       int var6 = 0;
  118.       int var7 = var4 - var5 * 4;
  119.       if (var7 > 0) {
  120.          var7 = (var5 + 1) * 4 - var4;
  121.       }
  122.  
  123.       if (!this.RLEencoded) {
  124.          ((ImageLoader)this).print("8-bit BMP image with palette, not encoded");
  125.  
  126.          for(; this.pixelCt < this.pixels; ++this.pixelCt) {
  127.             this.pixel = this.cache[this.cachePtr++] & 255;
  128.             super.frameBuffer[this.framePtr++] = this.bmiColors[this.pixel];
  129.             ++this.col;
  130.             if (this.col == super.xRes) {
  131.                this.framePtr += this.stepFrameRow;
  132.                this.col = 0;
  133.                this.cachePtr += var7;
  134.             }
  135.          }
  136.  
  137.          ((ImageLoader)this).print("decoding ended");
  138.       } else {
  139.          this.lastFramePos = this.framePtr;
  140.          this.stepFrameRow = 0 - super.xRes;
  141.          ((ImageLoader)this).print("8-bit BMP image with palette, RLE encoded");
  142.  
  143.          while(this.pixelCt < this.pixels) {
  144.             var3 = (boolean)0;
  145.             this.RLElength = this.cache[this.cachePtr++] & 255;
  146.             if (this.RLElength > 0) {
  147.                this.pixel = this.cache[this.cachePtr++] & 255;
  148.                var6 = this.bmiColors[this.pixel];
  149.  
  150.                for(this.field_0 = 0; this.field_0 < this.RLElength; ++this.field_0) {
  151.                   super.frameBuffer[this.framePtr++] = var6;
  152.                   ++this.pixelCt;
  153.                }
  154.             } else {
  155.                this.RLEtype = this.cache[this.cachePtr++] & 255;
  156.                if (this.RLEtype == 0) {
  157.                   this.newLine();
  158.                } else {
  159.                   if (this.RLEtype == 1) {
  160.                      return;
  161.                   }
  162.  
  163.                   if (this.RLEtype == 2) {
  164.                      int var1 = this.cache[this.cachePtr++] & 255;
  165.                      int var2 = this.cache[this.cachePtr++] & 255;
  166.                      ((ImageLoader)this).print("delta xOff: " + var1 + " yoff: " + var2);
  167.                      if (var2 > 0) {
  168.                         for(this.field_0 = 0; this.field_0 < var2; ++this.field_0) {
  169.                            this.framePtr -= super.xRes;
  170.                            this.pixelCt += super.xRes;
  171.                         }
  172.                      }
  173.  
  174.                      if (var1 > 0) {
  175.                         this.framePtr += var1;
  176.                         this.col += var1;
  177.                         this.pixelCt += var1;
  178.                      }
  179.                   } else if (this.RLEtype <= 2) {
  180.                      ((ImageLoader)this).print("RLEtype strange: " + this.RLEtype);
  181.                   } else {
  182.                      this.RLElength = this.RLEtype;
  183.                      var3 = this.RLElength / 2;
  184.                      var3 *= 2;
  185.                      var3 = this.RLElength - var3;
  186.  
  187.                      for(this.field_0 = 0; this.field_0 < this.RLElength; ++this.field_0) {
  188.                         this.pixel = this.cache[this.cachePtr++] & 255;
  189.                         super.frameBuffer[this.framePtr++] = this.bmiColors[this.pixel];
  190.                         ++this.pixelCt;
  191.                      }
  192.  
  193.                      this.cachePtr += var3;
  194.                   }
  195.                }
  196.             }
  197.          }
  198.  
  199.       }
  200.    }
  201.  
  202.    private final void newLine() {
  203.       this.lastFramePos += this.stepFrameRow;
  204.       this.framePtr = this.lastFramePos;
  205.       this.col = 0;
  206.       this.cachePtr += this.padding;
  207.    }
  208.  
  209.    public void imageLoaded(int var1, Image var2, String var3) {
  210.    }
  211.  
  212.    public String getInfo() {
  213.       return "";
  214.    }
  215.  
  216.    protected void readHeader() throws IOException {
  217.       ((ImageLoader)this).print(this.getInfo() + " running");
  218.       super.imageFile.setIntelSwitch(true);
  219.       this.bfType = super.imageFile.readString(2);
  220.       if (!this.bfType.equals("BM")) {
  221.       }
  222.  
  223.       this.bfSize = super.imageFile.read32Bit();
  224.       super.imageFile.skipBytes(4);
  225.       this.bfOffBits = super.imageFile.read32Bit();
  226.       ((ImageLoader)this).print("bfType: " + this.bfType);
  227.       ((ImageLoader)this).print("bfSize: " + this.bfSize);
  228.       ((ImageLoader)this).print("bfOffBits: " + this.bfOffBits);
  229.       this.biSize = super.imageFile.read32Bit();
  230.       this.biWidth = super.imageFile.read32Bit();
  231.       this.biHeight = super.imageFile.read32Bit();
  232.       this.biPlanes = super.imageFile.read16Bit();
  233.       this.biBitCount = super.imageFile.read16Bit();
  234.       if (this.biBitCount < 8) {
  235.       }
  236.  
  237.       if (this.biBitCount < 24) {
  238.          this.colNum = 256;
  239.       }
  240.  
  241.       this.biCompression = super.imageFile.read32Bit();
  242.       this.biSizeImage = super.imageFile.read32Bit();
  243.       super.imageFile.skipBytes(8);
  244.       this.biClrUsed = super.imageFile.read32Bit();
  245.       this.biClrImportant = super.imageFile.read32Bit();
  246.       ((ImageLoader)this).print("biSize: " + this.biSize);
  247.       ((ImageLoader)this).print("biWidth: " + this.biWidth);
  248.       ((ImageLoader)this).print("biHeight: " + this.biHeight);
  249.       ((ImageLoader)this).print("biPlanes: " + this.biPlanes);
  250.       ((ImageLoader)this).print("biBitCount: " + this.biBitCount);
  251.       ((ImageLoader)this).print("biCompression: " + this.biCompression);
  252.       ((ImageLoader)this).print("biSizeImage: " + this.biSizeImage);
  253.       ((ImageLoader)this).print("biClrUsed: " + this.biClrUsed);
  254.       ((ImageLoader)this).print("biClrImportant: " + this.biClrImportant);
  255.       ((ImageLoader)this).initFrameBuffer((int)this.biWidth, (int)this.biHeight);
  256.    }
  257.  
  258.    private void decodeTC() throws IOException {
  259.       ((ImageLoader)this).print("load True Color BMP image");
  260.       int var1 = (int)(this.biWidth * 3L);
  261.       int var2 = var1 >> 2;
  262.       this.padding = var1 - (var2 << 2);
  263.       if (this.padding > 0) {
  264.          this.padding = (var2 + 1 << 2) - var1;
  265.       }
  266.  
  267.       for(; this.pixelCt < this.pixels; ++this.pixelCt) {
  268.          this.red = this.cache[this.cachePtr + 2];
  269.          this.green = this.cache[this.cachePtr + 1];
  270.          this.blue = this.cache[this.cachePtr];
  271.          this.cachePtr += 3;
  272.          super.frameBuffer[this.framePtr] = (this.alpha << 24) + (this.red << 16) + (this.green << 8) + this.blue;
  273.          this.framePtr += this.stepFrameCol;
  274.          ++this.col;
  275.          if (this.col == super.xRes) {
  276.             this.cachePtr += this.padding;
  277.             this.framePtr += this.stepFrameRow;
  278.             this.col = 0;
  279.          }
  280.       }
  281.  
  282.    }
  283. }
  284.