Changeset 9379
- Timestamp:
- 07/20/07 18:03:19 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jav_EXT/com/scenari/ext/img2props/ImageInfo.java
r2853 r9379 2 2 * ImageInfo.java 3 3 * 4 * Version 1. 74 * Version 1.9 5 5 * 6 6 * A Java class to determine image width, height and color depth for … … 76 76 * This class is contributed to the Public Domain. 77 77 * Use it at your own risk. 78 * <p>79 * Last modification 2005-07-26.80 78 * <p> 81 79 * <a name="history">History</a>: … … 139 137 * was repeatedly requested by some users). 140 138 * Released as 1.7.</li> 139 * <li><strong>2006-02-23</strong> Removed Flash helper methods which weren't used elsewhere. 140 * Updated skip method which tries "read" whenever "skip(Bytes)" returns a result of 0. 141 * The old method didn't work with certain input stream types on truncated data streams. 142 * Thanks to Martin Leidig for reporting this and sending in code. 143 * Released as 1.8.</li> 144 * </li> 145 * <li><strong>2006-11-13</strong> Removed check that made ImageInfo report JPEG APPx 146 * markers smaller than 14 bytes as files in unknown format. Such JPEGs seem to be 147 * generated by Google's Picasa application. First reported with fix by 148 * Karl von Randow. Released as 1.9.</li> 141 149 * </ul> 142 150 * @author Marco Schmidt … … 249 257 private int physicalHeightDpi; 250 258 private int physicalWidthDpi; 251 private int bitBuf;252 private int bitPos;253 259 254 260 private void addComment(String s) { … … 523 529 if (marker == 0xffe0) { // APPx 524 530 if (size < 14) { 525 return false; // APPx header must be >= 14 bytes 531 // not an APPx header as we know it, skip 532 skip(size - 2); 533 continue; 526 534 } 527 535 if (read(data, 0, 12) != 12) { … … 1002 1010 System.out.println(e); 1003 1011 try { 1004 in.close(); 1012 if (in != null) { 1013 in.close(); 1014 } 1005 1015 } catch (IOException ee) { 1006 1016 } … … 1127 1137 } 1128 1138 1129 private long readUBits( int numBits ) throws IOException1130 {1131 if (numBits == 0) {1132 return 0;1133 }1134 int bitsLeft = numBits;1135 long result = 0;1136 if (bitPos == 0) { //no value in the buffer - read a byte1137 if (in != null) {1138 bitBuf = in.read();1139 } else {1140 bitBuf = din.readByte();1141 }1142 bitPos = 8;1143 }1144 1145 while( true )1146 {1147 int shift = bitsLeft - bitPos;1148 if( shift > 0 )1149 {1150 // Consume the entire buffer1151 result |= bitBuf << shift;1152 bitsLeft -= bitPos;1153 1154 // Get the next byte from the input stream1155 if (in != null) {1156 bitBuf = in.read();1157 } else {1158 bitBuf = din.readByte();1159 }1160 bitPos = 8;1161 }1162 else1163 {1164 // Consume a portion of the buffer1165 result |= bitBuf >> -shift;1166 bitPos -= bitsLeft;1167 bitBuf &= 0xff >> (8 - bitPos); // mask off the consumed bits1168 1169 return result;1170 }1171 }1172 }1173 1174 /**1175 * Read a signed integer value from input.1176 * @param numBits number of bits to read1177 */1178 private int readSBits(int numBits) throws IOException1179 {1180 // Get the number as an unsigned value.1181 long uBits = readUBits( numBits );1182 1183 // Is the number negative?1184 if( ( uBits & (1L << (numBits - 1))) != 0 )1185 {1186 // Yes. Extend the sign.1187 uBits |= -1L << numBits;1188 }1189 1190 return (int)uBits;1191 }1192 1193 /* private void synchBits()1194 {1195 bitBuf = 0;1196 bitPos = 0;1197 }*/1198 1199 /* private String readLine(int firstChar) throws IOException {1200 StringBuffer result = new StringBuffer();1201 result.append((char)firstChar);1202 return readLine(result);1203 }*/1204 1205 1139 private static void run(String sourceName, InputStream in, ImageInfo imageInfo, boolean verbose) { 1206 1140 imageInfo.setInput(in); … … 1272 1206 } 1273 1207 1274 private void skip(int num) throws IOException { 1275 while (num > 0) { 1276 long result; 1277 if (in != null) { 1278 result = in.skip(num); 1279 } else { 1280 result = din.skipBytes(num); 1281 } 1282 if (result > 0) { 1283 num -= result; 1284 } 1285 } 1286 } 1208 private void skip(int num) throws IOException { 1209 while (num > 0) { 1210 long result; 1211 if (in != null) { 1212 result = in.skip(num); 1213 } else { 1214 result = din.skipBytes(num); 1215 } 1216 if (result > 0) { 1217 num -= result; 1218 } else { 1219 if (in != null) { 1220 result = in.read(); 1221 } else { 1222 result = din.readByte(); 1223 } 1224 if (result == -1) { 1225 throw new IOException("Premature end of input."); 1226 } else { 1227 num--; 1228 } 1229 } 1230 } 1231 } 1287 1232 }
Note: See TracChangeset
for help on using the changeset viewer.