From: <ha...@us...> - 2010-04-19 04:53:42
|
Revision: 12894 http://jmol.svn.sourceforge.net/jmol/?rev=12894&view=rev Author: hansonr Date: 2010-04-19 04:53:36 +0000 (Mon, 19 Apr 2010) Log Message: ----------- version=11.6.27 # bug fix: JPEG encoder restricts comment field size to 65535 bytes Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java trunk/Jmol/src/org/jmol/script/ParallelProcessor.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/util/JpegEncoder.java Modified: trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-04-19 04:36:26 UTC (rev 12893) +++ trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-04-19 04:53:36 UTC (rev 12894) @@ -460,7 +460,8 @@ } } - if (lines[0].indexOf("PNG") == 1 || lines[0].indexOf("JPG") == 1) + if (lines[0].indexOf("PNG") == 1 || lines[0].indexOf("JPG") == 1 + || lines[0].indexOf("JFIF") == 6) return "spt"; // presume embedded script --- allows dragging into Jmol for (int i = 0; i < lines.length; ++i) if (lines[i].indexOf("# Jmol state") >= 0) Modified: trunk/Jmol/src/org/jmol/script/ParallelProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ParallelProcessor.java 2010-04-19 04:36:26 UTC (rev 12893) +++ trunk/Jmol/src/org/jmol/script/ParallelProcessor.java 2010-04-19 04:53:36 UTC (rev 12894) @@ -42,17 +42,17 @@ this.viewer = viewer; viewer.setParallel(true); counter = 0; - System.out.println("running " + processes.size() + " processes on " + Viewer.nProcessors + " processesors"); + System.out.println("running " + processes.size() + " processes on " + + Viewer.nProcessors + " processesors"); try { - for (int i = processes.size(); --i >= 0;) { - counter++; - runProcess((Process) processes.remove(0)); - } - while (counter >= 0) { - Thread.yield(); - } - } - catch (Exception e) { + counter = processes.size(); + for (int i = processes.size(); --i >= 0;) { + runProcess((Process) processes.remove(0)); + } + while (counter >= 0) { + Thread.yield(); + } + } catch (Exception e) { // could be memory errors here as well } viewer.setParallel(false); Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-04-19 04:36:26 UTC (rev 12893) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-04-19 04:53:36 UTC (rev 12894) @@ -9263,6 +9263,7 @@ // halo star spacefill RadiusData rd = null; int tok = tokAt(1); + boolean isOnly = false; switch (tok) { case Token.only: restrictSelected(false, false); @@ -9272,13 +9273,19 @@ case Token.off: scale = 0; break; + case Token.decimal: + isOnly = (floatParameter(1) < 0); + // fall through + case Token.integer: default: - rd = encodeRadiusParameter(1); + rd = encodeRadiusParameter(1, isOnly); if (Float.isNaN(rd.value)) error(ERROR_invalidArgument); } if (rd == null) rd = new RadiusData(scale, RadiusData.TYPE_FACTOR, JmolConstants.VDW_AUTO); + if (isOnly) + restrictSelected(false, false); setShapeSize(shape, rd); } @@ -9291,7 +9298,7 @@ * 0) +30% 130% (0 80% percent (0 */ - private RadiusData encodeRadiusParameter(int index) throws ScriptException { + private RadiusData encodeRadiusParameter(int index, boolean isOnly) throws ScriptException { float value = Float.NaN; int type = RadiusData.TYPE_ABSOLUTE; @@ -9330,7 +9337,9 @@ type = RadiusData.TYPE_ABSOLUTE; vdwType = Integer.MAX_VALUE; } - value = floatParameter(index, 0, Atom.RADIUS_MAX); + value = floatParameter(index, (isOnly ? -Atom.RADIUS_MAX : 0), Atom.RADIUS_MAX); + if (isOnly) + value = -value; break; case Token.integer: value = intParameter(index); @@ -9903,7 +9912,7 @@ } break; } - RadiusData rd = (Float.isNaN(value) ? encodeRadiusParameter(1) + RadiusData rd = (Float.isNaN(value) ? encodeRadiusParameter(1, false) : new RadiusData(value, type, 0)); if (Float.isNaN(rd.value)) error(ERROR_invalidArgument); @@ -13877,7 +13886,7 @@ break; case Token.ionic: case Token.vanderwaals: - RadiusData rd = encodeRadiusParameter(i); + RadiusData rd = encodeRadiusParameter(i, false); if (Float.isNaN(rd.value)) rd.value = 100; propertyValue = rd; Modified: trunk/Jmol/src/org/jmol/util/JpegEncoder.java =================================================================== --- trunk/Jmol/src/org/jmol/util/JpegEncoder.java 2010-04-19 04:36:26 UTC (rev 12893) +++ trunk/Jmol/src/org/jmol/util/JpegEncoder.java 2010-04-19 04:53:36 UTC (rev 12894) @@ -108,9 +108,15 @@ } */ public void Compress() { - WriteHeaders(outStream, JpegObj, dct); + String longState = WriteHeaders(outStream, JpegObj, dct); WriteCompressedData(outStream, JpegObj, dct, Huf); WriteEOI(outStream); + if (longState != null) + try { + outStream.write(longState.getBytes()); + } catch (IOException e1) { + System.out.println("ERROR WRITING COMMENT"); + } try { outStream.flush(); } catch (IOException e) { @@ -209,10 +215,10 @@ WriteMarker(EOI, out); } - static private void WriteHeaders(BufferedOutputStream out, JpegInfo JpegObj, DCT dct) { + static private String WriteHeaders(BufferedOutputStream out, JpegInfo JpegObj, DCT dct) { int i, j, index, offset, length; int tempArray[]; - + // the SOI marker byte[] SOI = {(byte) 0xFF, (byte) 0xD8}; WriteMarker(SOI, out); @@ -241,18 +247,25 @@ WriteArray(JFIF, out); // Comment Header - String comment = ""; - comment = JpegObj.getComment(); - length = comment.length(); - byte COM[] = new byte[length + 4]; + String comment = JpegObj.Comment; + if (JpegObj.Comment.length() >= 65000) { + JpegObj.Comment = "JPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech.\n\n"; + } else { + JpegObj.Comment = "JPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech.\n\n" + comment; + comment = null; + } + // bug fix -- ha...@st... -- 4/2010 -- Jmol 12.0.RC7 -- + // length was two short here. + length = JpegObj.Comment.length() + 2; + byte COM[] = new byte[length + 2]; COM[0] = (byte) 0xFF; COM[1] = (byte) 0xFE; COM[2] = (byte) ((length >> 8) & 0xFF); COM[3] = (byte) (length & 0xFF); java.lang.System.arraycopy(JpegObj.Comment.getBytes(), 0, - COM, 4, JpegObj.Comment.length()); + COM, 4, JpegObj.Comment.length()); WriteArray(COM, out); - + // The DQT header // 0 is the luminance index and 1 is the chrominance index byte DQT[] = new byte[134]; @@ -312,7 +325,7 @@ SOS[index++] = (byte) JpegObj.Se; SOS[index++] = (byte) ((JpegObj.Ah << 4) + JpegObj.Al); WriteArray(SOS, out); - + return comment; } static void WriteDHTHeader(int[] bits, int[] val, BufferedOutputStream out) { @@ -1201,18 +1214,10 @@ imageobj = image; imageWidth = image.getWidth(null); imageHeight = image.getHeight(null); - Comment = comment + "\n\nJPEG Encoder Copyright 1998, James R. Weeks and BioElectroMech. "; + Comment = comment; getYCCArray(); } -/* - public void setComment(String comment) { - Comment.concat(comment); - } -*/ - String getComment() { - return Comment; - } - + /* * This method creates and fills three arrays, Y, Cb, and Cr using the * input image. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |