Changeset 7499 in josm for trunk


Ignore:
Timestamp:
2014-09-05T03:25:23+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10479 - handle transparency for paletted images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r7495 r7499  
    12401240            bi = reader.read(0, param);
    12411241            if (bi.getTransparency() != Transparency.TRANSLUCENT && (readMetadata || enforceTransparency)) {
    1242                 Color color = getTransparentColor(reader);
     1242                Color color = getTransparentColor(bi.getColorModel(), reader);
    12431243                if (color != null) {
    12441244                    Hashtable<String, Object> properties = new Hashtable<>(1);
     
    12621262    /**
    12631263     * Returns the {@code TransparentColor} defined in image reader metadata.
     1264     * @param model The image color model
    12641265     * @param reader The image reader
    12651266     * @return the {@code TransparentColor} defined in image reader metadata, or {@code null}
    12661267     * @throws IOException if an error occurs during reading
    1267      * @since 7132
     1268     * @since 7499
    12681269     * @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>
    12691270     */
    1270     public static Color getTransparentColor(ImageReader reader) throws IOException {
     1271    public static Color getTransparentColor(ColorModel model, ImageReader reader) throws IOException {
    12711272        try {
    12721273            IIOMetadata metadata = reader.getImageMetadata(0);
     
    12821283                                    Node item = list.item(0);
    12831284                                    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                                            }
    12871300                                        }
    12881301                                    }
     
    12941307                }
    12951308            }
    1296         } catch (IIOException e) {
     1309        } catch (IIOException | NumberFormatException e) {
    12971310            // JAI doesn't like some JPEG files with error "Inconsistent metadata read from stream" (see #10267)
    12981311            Main.warn(e);
Note: See TracChangeset for help on using the changeset viewer.