Changeset 9379


Ignore:
Timestamp:
07/20/07 18:03:19 (5 years ago)
Author:
anp
Message:

maj librairie imageInfo 1.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_EXT/com/scenari/ext/img2props/ImageInfo.java

    r2853 r9379  
    22 * ImageInfo.java 
    33 * 
    4  * Version 1.7 
     4 * Version 1.9 
    55 * 
    66 * A Java class to determine image width, height and color depth for 
     
    7676 * This class is contributed to the Public Domain. 
    7777 * Use it at your own risk. 
    78  * <p> 
    79  * Last modification 2005-07-26. 
    8078 * <p> 
    8179 * <a name="history">History</a>: 
     
    139137 *  was repeatedly requested by some users). 
    140138 *  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>   
    141149 * </ul> 
    142150 * @author Marco Schmidt 
     
    249257        private int physicalHeightDpi; 
    250258        private int physicalWidthDpi; 
    251         private int bitBuf; 
    252         private int bitPos; 
    253259 
    254260        private void addComment(String s) { 
     
    523529                        if (marker == 0xffe0) { // APPx  
    524530                                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; 
    526534                                } 
    527535                                if (read(data, 0, 12) != 12) { 
     
    10021010                                        System.out.println(e); 
    10031011                                        try { 
    1004                                                 in.close(); 
     1012                                                if (in != null) { 
     1013                                                        in.close(); 
     1014                                                } 
    10051015                                        } catch (IOException ee) { 
    10061016                                        } 
     
    11271137        } 
    11281138 
    1129         private long readUBits( int numBits ) throws IOException 
    1130         { 
    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 byte 
    1137                         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 buffer 
    1151                 result |= bitBuf << shift; 
    1152                 bitsLeft -= bitPos; 
    1153  
    1154                 // Get the next byte from the input stream 
    1155                 if (in != null) { 
    1156                   bitBuf = in.read(); 
    1157                 } else { 
    1158                   bitBuf = din.readByte(); 
    1159                 } 
    1160                 bitPos = 8; 
    1161             } 
    1162             else 
    1163             { 
    1164                 // Consume a portion of the buffer 
    1165                 result |= bitBuf >> -shift; 
    1166                 bitPos -= bitsLeft; 
    1167                 bitBuf &= 0xff >> (8 - bitPos); // mask off the consumed bits 
    1168  
    1169                 return result; 
    1170             } 
    1171         }         
    1172     } 
    1173      
    1174     /** 
    1175      * Read a signed integer value from input. 
    1176      * @param numBits number of bits to read 
    1177      */ 
    1178     private int readSBits(int numBits) throws IOException 
    1179     { 
    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  
    12051139        private static void run(String sourceName, InputStream in, ImageInfo imageInfo, boolean verbose) { 
    12061140                imageInfo.setInput(in); 
     
    12721206        } 
    12731207 
    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    } 
    12871232} 
Note: See TracChangeset for help on using the changeset viewer.