< prev index next >

src/java.desktop/share/classes/java/awt/image/CropImageFilter.java

Print this page




  51 
  52     /**
  53      * Constructs a CropImageFilter that extracts the absolute rectangular
  54      * region of pixels from its source Image as specified by the x, y,
  55      * w, and h parameters.
  56      * @param x the x location of the top of the rectangle to be extracted
  57      * @param y the y location of the top of the rectangle to be extracted
  58      * @param w the width of the rectangle to be extracted
  59      * @param h the height of the rectangle to be extracted
  60      */
  61     public CropImageFilter(int x, int y, int w, int h) {
  62         cropX = x;
  63         cropY = y;
  64         cropW = w;
  65         cropH = h;
  66     }
  67 
  68     /**
  69      * Passes along  the properties from the source object after adding a
  70      * property indicating the cropped region.
  71      * This method invokes <code>super.setProperties</code>,
  72      * which might result in additional properties being added.
  73      * <p>
  74      * Note: This method is intended to be called by the
  75      * <code>ImageProducer</code> of the <code>Image</code> whose pixels
  76      * are being filtered. Developers using
  77      * this class to filter pixels from an image should avoid calling
  78      * this method directly since that operation could interfere
  79      * with the filtering operation.
  80      */
  81     public void setProperties(Hashtable<?,?> props) {
  82         @SuppressWarnings("unchecked")
  83         Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
  84         p.put("croprect", new Rectangle(cropX, cropY, cropW, cropH));
  85         super.setProperties(p);
  86     }
  87 
  88     /**
  89      * Override the source image's dimensions and pass the dimensions
  90      * of the rectangular cropped region to the ImageConsumer.
  91      * <p>
  92      * Note: This method is intended to be called by the
  93      * <code>ImageProducer</code> of the <code>Image</code> whose
  94      * pixels are being filtered. Developers using
  95      * this class to filter pixels from an image should avoid calling
  96      * this method directly since that operation could interfere
  97      * with the filtering operation.
  98      * @see ImageConsumer
  99      */
 100     public void setDimensions(int w, int h) {
 101         consumer.setDimensions(cropW, cropH);
 102     }
 103 
 104     /**
 105      * Determine whether the delivered byte pixels intersect the region to
 106      * be extracted and passes through only that subset of pixels that
 107      * appear in the output region.
 108      * <p>
 109      * Note: This method is intended to be called by the
 110      * <code>ImageProducer</code> of the <code>Image</code> whose
 111      * pixels are being filtered. Developers using
 112      * this class to filter pixels from an image should avoid calling
 113      * this method directly since that operation could interfere
 114      * with the filtering operation.
 115      */
 116     public void setPixels(int x, int y, int w, int h,
 117                           ColorModel model, byte pixels[], int off,
 118                           int scansize) {
 119         int x1 = x;
 120         if (x1 < cropX) {
 121             x1 = cropX;
 122         }
 123     int x2 = addWithoutOverflow(x, w);
 124         if (x2 > cropX + cropW) {
 125             x2 = cropX + cropW;
 126         }
 127         int y1 = y;
 128         if (y1 < cropY) {
 129             y1 = cropY;
 130         }
 131 
 132     int y2 = addWithoutOverflow(y, h);
 133         if (y2 > cropY + cropH) {
 134             y2 = cropY + cropH;
 135         }
 136         if (x1 >= x2 || y1 >= y2) {
 137             return;
 138         }
 139         consumer.setPixels(x1 - cropX, y1 - cropY, (x2 - x1), (y2 - y1),
 140                            model, pixels,
 141                            off + (y1 - y) * scansize + (x1 - x), scansize);
 142     }
 143 
 144     /**
 145      * Determine if the delivered int pixels intersect the region to
 146      * be extracted and pass through only that subset of pixels that
 147      * appear in the output region.
 148      * <p>
 149      * Note: This method is intended to be called by the
 150      * <code>ImageProducer</code> of the <code>Image</code> whose
 151      * pixels are being filtered. Developers using
 152      * this class to filter pixels from an image should avoid calling
 153      * this method directly since that operation could interfere
 154      * with the filtering operation.
 155      */
 156     public void setPixels(int x, int y, int w, int h,
 157                           ColorModel model, int pixels[], int off,
 158                           int scansize) {
 159         int x1 = x;
 160         if (x1 < cropX) {
 161             x1 = cropX;
 162         }
 163     int x2 = addWithoutOverflow(x, w);
 164         if (x2 > cropX + cropW) {
 165             x2 = cropX + cropW;
 166         }
 167         int y1 = y;
 168         if (y1 < cropY) {
 169             y1 = cropY;
 170         }




  51 
  52     /**
  53      * Constructs a CropImageFilter that extracts the absolute rectangular
  54      * region of pixels from its source Image as specified by the x, y,
  55      * w, and h parameters.
  56      * @param x the x location of the top of the rectangle to be extracted
  57      * @param y the y location of the top of the rectangle to be extracted
  58      * @param w the width of the rectangle to be extracted
  59      * @param h the height of the rectangle to be extracted
  60      */
  61     public CropImageFilter(int x, int y, int w, int h) {
  62         cropX = x;
  63         cropY = y;
  64         cropW = w;
  65         cropH = h;
  66     }
  67 
  68     /**
  69      * Passes along  the properties from the source object after adding a
  70      * property indicating the cropped region.
  71      * This method invokes {@code super.setProperties},
  72      * which might result in additional properties being added.
  73      * <p>
  74      * Note: This method is intended to be called by the
  75      * {@code ImageProducer} of the {@code Image} whose pixels
  76      * are being filtered. Developers using
  77      * this class to filter pixels from an image should avoid calling
  78      * this method directly since that operation could interfere
  79      * with the filtering operation.
  80      */
  81     public void setProperties(Hashtable<?,?> props) {
  82         @SuppressWarnings("unchecked")
  83         Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
  84         p.put("croprect", new Rectangle(cropX, cropY, cropW, cropH));
  85         super.setProperties(p);
  86     }
  87 
  88     /**
  89      * Override the source image's dimensions and pass the dimensions
  90      * of the rectangular cropped region to the ImageConsumer.
  91      * <p>
  92      * Note: This method is intended to be called by the
  93      * {@code ImageProducer} of the {@code Image} whose
  94      * pixels are being filtered. Developers using
  95      * this class to filter pixels from an image should avoid calling
  96      * this method directly since that operation could interfere
  97      * with the filtering operation.
  98      * @see ImageConsumer
  99      */
 100     public void setDimensions(int w, int h) {
 101         consumer.setDimensions(cropW, cropH);
 102     }
 103 
 104     /**
 105      * Determine whether the delivered byte pixels intersect the region to
 106      * be extracted and passes through only that subset of pixels that
 107      * appear in the output region.
 108      * <p>
 109      * Note: This method is intended to be called by the
 110      * {@code ImageProducer} of the {@code Image} whose
 111      * pixels are being filtered. Developers using
 112      * this class to filter pixels from an image should avoid calling
 113      * this method directly since that operation could interfere
 114      * with the filtering operation.
 115      */
 116     public void setPixels(int x, int y, int w, int h,
 117                           ColorModel model, byte pixels[], int off,
 118                           int scansize) {
 119         int x1 = x;
 120         if (x1 < cropX) {
 121             x1 = cropX;
 122         }
 123     int x2 = addWithoutOverflow(x, w);
 124         if (x2 > cropX + cropW) {
 125             x2 = cropX + cropW;
 126         }
 127         int y1 = y;
 128         if (y1 < cropY) {
 129             y1 = cropY;
 130         }
 131 
 132     int y2 = addWithoutOverflow(y, h);
 133         if (y2 > cropY + cropH) {
 134             y2 = cropY + cropH;
 135         }
 136         if (x1 >= x2 || y1 >= y2) {
 137             return;
 138         }
 139         consumer.setPixels(x1 - cropX, y1 - cropY, (x2 - x1), (y2 - y1),
 140                            model, pixels,
 141                            off + (y1 - y) * scansize + (x1 - x), scansize);
 142     }
 143 
 144     /**
 145      * Determine if the delivered int pixels intersect the region to
 146      * be extracted and pass through only that subset of pixels that
 147      * appear in the output region.
 148      * <p>
 149      * Note: This method is intended to be called by the
 150      * {@code ImageProducer} of the {@code Image} whose
 151      * pixels are being filtered. Developers using
 152      * this class to filter pixels from an image should avoid calling
 153      * this method directly since that operation could interfere
 154      * with the filtering operation.
 155      */
 156     public void setPixels(int x, int y, int w, int h,
 157                           ColorModel model, int pixels[], int off,
 158                           int scansize) {
 159         int x1 = x;
 160         if (x1 < cropX) {
 161             x1 = cropX;
 162         }
 163     int x2 = addWithoutOverflow(x, w);
 164         if (x2 > cropX + cropW) {
 165             x2 = cropX + cropW;
 166         }
 167         int y1 = y;
 168         if (y1 < cropY) {
 169             y1 = cropY;
 170         }


< prev index next >