Changeset 7499 in josm
- Timestamp:
- 2014-09-05T03:25:23+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7495 r7499 1240 1240 bi = reader.read(0, param); 1241 1241 if (bi.getTransparency() != Transparency.TRANSLUCENT && (readMetadata || enforceTransparency)) { 1242 Color color = getTransparentColor(reader); 1242 Color color = getTransparentColor(bi.getColorModel(), reader); 1243 1243 if (color != null) { 1244 1244 Hashtable<String, Object> properties = new Hashtable<>(1); … … 1262 1262 /** 1263 1263 * Returns the {@code TransparentColor} defined in image reader metadata. 1264 * @param model The image color model 1264 1265 * @param reader The image reader 1265 1266 * @return the {@code TransparentColor} defined in image reader metadata, or {@code null} 1266 1267 * @throws IOException if an error occurs during reading 1267 * @since 7 1321268 * @since 7499 1268 1269 * @see <a href="http://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/standard_metadata.html">javax_imageio_1.0 metadata</a> 1269 1270 */ 1270 public static Color getTransparentColor(ImageReader reader) throws IOException { 1271 public static Color getTransparentColor(ColorModel model, ImageReader reader) throws IOException { 1271 1272 try { 1272 1273 IIOMetadata metadata = reader.getImageMetadata(0); … … 1282 1283 Node item = list.item(0); 1283 1284 if (item instanceof Element) { 1284 String[] s = ((Element)item).getAttribute("value").split(" "); 1285 if (s.length == 3) { 1286 return parseRGB(s); 1285 // Handle different color spaces (tested with RGB and grayscale) 1286 String value = ((Element)item).getAttribute("value"); 1287 if (!value.isEmpty()) { 1288 String[] s = value.split(" "); 1289 if (s.length == 3) { 1290 return parseRGB(s); 1291 } else if (s.length == 1) { 1292 int pixel = Integer.parseInt(s[0]); 1293 int r = model.getRed(pixel); 1294 int g = model.getGreen(pixel); 1295 int b = model.getBlue(pixel); 1296 return new Color(r,g,b); 1297 } else { 1298 Main.warn("Unable to translate TransparentColor '"+value+"' with color model "+model); 1299 } 1287 1300 } 1288 1301 } … … 1294 1307 } 1295 1308 } 1296 } catch (IIOException e) { 1309 } catch (IIOException | NumberFormatException e) { 1297 1310 // JAI doesn't like some JPEG files with error "Inconsistent metadata read from stream" (see #10267) 1298 1311 Main.warn(e);
Note:
See TracChangeset
for help on using the changeset viewer.