Revision: 20311
          http://sourceforge.net/p/jmol/code/20311
Author:   hansonr
Date:     2015-02-22 06:59:02 +0000 (Sun, 22 Feb 2015)
Log Message:
-----------


Modified Paths:
--------------
    trunk/Jmol/src/javajs/img/BMPDecoder.java
    trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/ImageDialog.java

Modified: trunk/Jmol/src/javajs/img/BMPDecoder.java
===================================================================
--- trunk/Jmol/src/javajs/img/BMPDecoder.java   2015-02-22 06:16:39 UTC (rev 
20310)
+++ trunk/Jmol/src/javajs/img/BMPDecoder.java   2015-02-22 06:59:02 UTC (rev 
20311)
@@ -69,10 +69,10 @@
       // read BITMAPFILEHEADER
       if (readByte() != 'B' || readByte() != 'M')
         return null;
-      readInt();   // file size; ignored
+      readInt(); // file size; ignored
       readShort(); // reserved
       readShort(); // reserved
-      readInt();   // ptr to pixel array; ignored
+      readInt(); // ptr to pixel array; ignored
       int imageWidth, imageHeight, bitsPerPixel, nColors = 0, imageSize = 0;
       // read BITMAP header
       int headerSize = readInt();
@@ -99,7 +99,7 @@
         imageSize = readInt();
         readInt(); // hres
         readInt(); // vres
-        nColors = readInt(); 
+        nColors = readInt();
         readInt(); // colors used
         break;
       default:
@@ -109,58 +109,62 @@
       }
       boolean isYReversed = (imageHeight < 0);
       if (isYReversed)
-        imageHeight = - imageHeight;
+        imageHeight = -imageHeight;
       int nPixels = imageHeight * imageWidth;
       int bytesPerPixel = bitsPerPixel / 8;
-      int npad = (bytesPerPixel == 4 ? 0 : imageSize == 0 ? 4 - (imageWidth % 
4)
-          : (imageSize / imageHeight) - imageWidth * bytesPerPixel) % 4;
+      nColors = (nColors > 0 ? nColors : 1 << bitsPerPixel);
+      int npad = (bytesPerPixel == 4 ? 0
+          : imageSize == 0 ? 4 - (imageWidth % 4) : (imageSize / imageHeight)
+              - imageWidth * bytesPerPixel) % 4;
+      int[] palette;
       int[] buf = new int[nPixels];
       int dpt = (isYReversed ? imageWidth : -imageWidth);
       int pt0 = (isYReversed ? 0 : nPixels + dpt);
-      int pt1 = (isYReversed ? nPixels : -dpt);
+      int pt1 = (isYReversed ? nPixels : dpt);
       switch (bitsPerPixel) {
       case 32:
       case 24:
-        for (int pt = pt0; pt != pt1; pt += dpt) {
+        for (int pt = pt0; pt != pt1; pt += dpt, pad(npad))
           for (int i = 0; i < imageWidth; i++)
             buf[pt + i] = readColor(bytesPerPixel);
-          for (int i = 0; i < npad; i++)
-            readByte();
-        }
         break;
       case 8:
-        nColors = (nColors > 0 ? nColors : 1 << bitsPerPixel);
-        int[] palette = new int[nColors];
+        palette = new int[nColors];
         for (int i = 0; i < nColors; i++)
           palette[i] = readColor(4);
-        for (int pt = pt0; pt != pt1; pt += dpt) {
+        for (int pt = pt0; pt != pt1; pt += dpt, pad(npad))
           for (int i = 0; i < imageWidth; i++)
             buf[pt + i] = palette[readByte()];
-          for (int i = 0; i < npad; i++)
-            readByte();
-        }
         break;
+      case 4:
+        npad = (4 - (((imageWidth + 1) / 2) % 4)) % 4;
+        palette = new int[nColors];
+        for (int i = 0; i < nColors; i++)
+          palette[i] = readColor(4);
+        int b4 = 0;
+        for (int pt = pt0; pt != pt1; pt += dpt, pad(npad))
+          for (int i = 0, shift = 4; i < imageWidth; i++, shift = 4 - shift)
+            buf[pt + i] = palette[((shift == 4 ? (b4 = readByte()) : b4) >> 
shift) & 0xF];
+        break;
       case 1:
         int color1 = readColor(3);
         int color2 = readColor(3);
         npad = (4 - (((imageWidth + 7) / 8) % 4)) % 4;
         int b = 0;
-        for (int pt = pt0; pt != pt1; pt += dpt) {
+        for (int pt = pt0; pt != pt1; pt += dpt, pad(npad))
           for (int i = 0, bpt = -1; i < imageWidth; i++, bpt--) {
             if (bpt < 0) {
               b = readByte();
               bpt = 7;
             }
-            buf[pt + i] = ((b & (1 << bpt)) == 0 ? color1
-                : color2);
+            buf[pt + i] = ((b & (1 << bpt)) == 0 ? color1 : color2);
           }
-          for (int i = 0; i < npad; i++)
-            readByte();
-        }
         break;
+      case 64:
+      case 2:
       default:
         System.out
-            .println("Not a 32-, 24-, 8-, or 1-bit Windows Bitmap, 
aborting...");
+            .println("Not a 32-, 24-, 8-, 4-, or 1-bit Windows Bitmap, 
aborting...");
         return null;
       }
       return new Object[] { buf, Integer.valueOf(imageWidth),
@@ -171,6 +175,12 @@
     return null;
   }
 
+  private boolean pad(int npad) throws IOException {
+    for (int i = 0; i < npad; i++)
+      readByte();
+    return true;
+  }
+
   private byte[] temp;
   
   private int readColor(int n) throws IOException {

Modified: trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/ImageDialog.java
===================================================================
--- trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/ImageDialog.java  
2015-02-22 06:16:39 UTC (rev 20310)
+++ trunk/Jmol/src/org/openscience/jmol/app/jmolpanel/ImageDialog.java  
2015-02-22 06:59:02 UTC (rev 20311)
@@ -36,6 +36,7 @@
 
 import java.awt.BorderLayout;
 import java.awt.Canvas;
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.event.ActionEvent;
@@ -68,6 +69,7 @@
     this.imageMap = imageMap;
     imageMap.put(title, this);
     JPanel wrapper = new JPanel(new BorderLayout());
+    wrapper.setBackground(new Color(255,0,0));
     canvas = new ImageCanvas();
     wrapper.add(canvas, BorderLayout.CENTER);
     JPanel container = new JPanel();

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to