Coverage Report - org.dishevelled.iconbundle.impl.SelectionRasterOp
 
Classes in this File Line Coverage Branch Coverage Complexity
SelectionRasterOp
100%
14/14
83%
5/6
2.5
 
 1  
 /*
 2  
 
 3  
     dsh-iconbundle  Bundles of variants for icon images.
 4  
     Copyright (c) 2003-2013 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.iconbundle.impl;
 25  
 
 26  
 import java.awt.Color;
 27  
 
 28  
 import java.awt.image.Raster;
 29  
 import java.awt.image.WritableRaster;
 30  
 
 31  
 /**
 32  
  * Selection RasterOp.
 33  
  *
 34  
  * @author  Michael Heuer
 35  
  */
 36  
 final class SelectionRasterOp
 37  
     extends AbstractRasterOp
 38  
 {
 39  
     /** Pixel array size. */
 40  
     private static final int PIXEL_ARRAY_SIZE = 4;
 41  
 
 42  
     /** White color component. */
 43  
     private static final int WHITE = 255;
 44  
 
 45  
     /** Selection color. */
 46  
     private final Color selectionColor;
 47  
 
 48  
 
 49  
     /**
 50  
      * Create a new selection RasterOp with the specified
 51  
      * selection color.
 52  
      *
 53  
      * @param selectionColor selection color
 54  
      */
 55  
     public SelectionRasterOp(final Color selectionColor)
 56  1820
     {
 57  1820
         this.selectionColor = selectionColor;
 58  1820
     }
 59  
 
 60  
 
 61  
     /** {@inheritDoc} */
 62  
     public WritableRaster filter(final Raster src, final WritableRaster dest)
 63  
     {
 64  1820
         if (selectionColor != null)
 65  
         {
 66  1820
             float[] pixel = new float[PIXEL_ARRAY_SIZE];
 67  1820
             float[] selection = selectionColor.getColorComponents(new float[PIXEL_ARRAY_SIZE]);
 68  
 
 69  109720
             for (int x = 0, w = src.getWidth(); x < w; x++)
 70  
             {
 71  9124440
                 for (int y = 0, h = src.getHeight(); y < h; y++)
 72  
                 {
 73  9016540
                     pixel = src.getPixel(x, y, pixel);
 74  9016540
                     pixel[0] = Math.min(pixel[0], selection[0] * WHITE);
 75  9016540
                     pixel[1] = Math.min(pixel[1], selection[1] * WHITE);
 76  9016540
                     pixel[2] = Math.min(pixel[2], selection[2] * WHITE);
 77  
 
 78  9016540
                     dest.setPixel(x, y, pixel);
 79  
                 }
 80  
             }
 81  
         }
 82  1820
         return dest;
 83  
     }
 84  
 }