Changeset 8832 in josm


Ignore:
Timestamp:
2015-10-07T21:26:40+02:00 (9 years ago)
Author:
simon04
Message:

fix #11942 - Make gamma correction more robust to mysterious image types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r8733 r8832  
    1111import java.awt.Graphics2D;
    1212import java.awt.GridBagLayout;
     13import java.awt.Transparency;
    1314import java.awt.event.ActionEvent;
    1415import java.awt.font.FontRenderContext;
     
    280281        }
    281282
    282         private LookupOp getOp(int bands) {
    283             if (gamma == 1) {
    284                 return null;
    285             } else if (bands == 3) {
    286                 return op3;
    287             } else if (bands == 4) {
    288                 return op4;
    289             } else {
    290                 return null;
    291             }
    292         }
    293 
    294283        @Override
    295284        public BufferedImage process(BufferedImage image) {
    296             final LookupOp op = getOp(image.getRaster().getNumBands());
    297             final BufferedImage to = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
    298             return op == null ? image : op.filter(image, to);
     285            if (gamma == 1) {
     286                return image;
     287            }
     288            try {
     289                final int bands = image.getRaster().getNumBands();
     290                if (image.getType() != BufferedImage.TYPE_CUSTOM && bands == 3) {
     291                    return op3.filter(image, null);
     292                } else if (image.getType() != BufferedImage.TYPE_CUSTOM && bands == 4) {
     293                    return op4.filter(image, null);
     294                }
     295            } catch (IllegalArgumentException ignore) {
     296            }
     297            final int type = image.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
     298            final BufferedImage to = new BufferedImage(image.getWidth(), image.getHeight(), type);
     299            to.getGraphics().drawImage(image, 0, 0, null);
     300            return process(to);
    299301        }
    300302    }
Note: See TracChangeset for help on using the changeset viewer.