< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 110      * method clears the current {@code ColorModel} of this
 111      * {@code BufferedImageFilter}.
 112      * <p>
 113      * Note: This method is intended to be called by the
 114      * {@code ImageProducer} of the {@code Image}
 115      * whose pixels are being filtered.  Developers using this
 116      * class to retrieve pixels from an image
 117      * should avoid calling this method directly since that
 118      * operation could result in problems with retrieving the
 119      * requested pixels.
 120      * @param model the {@link ColorModel} to which to set the
 121      *        {@code ColorModel} of this {@code BufferedImageFilter}
 122      * @see ImageConsumer#setColorModel
 123      */
 124     public void setColorModel(ColorModel model) {
 125         this.model = model;
 126     }
 127 
 128     private void convertToRGB() {
 129         int size = width * height;
 130         int newpixels[] = new int[size];
 131         if (bytePixels != null) {
 132             for (int i = 0; i < size; i++) {
 133                 newpixels[i] = this.model.getRGB(bytePixels[i] & 0xff);
 134             }
 135         } else if (intPixels != null) {
 136             for (int i = 0; i < size; i++) {
 137                 newpixels[i] = this.model.getRGB(intPixels[i]);
 138             }
 139         }
 140         bytePixels = null;
 141         intPixels = newpixels;
 142         this.model = ColorModel.getRGBdefault();
 143     }
 144 
 145     /**
 146      * Filters the information provided in the {@code setPixels}
 147      * method of the {@code ImageConsumer} interface which takes
 148      * an array of bytes.
 149      * <p>
 150      * Note: This method is intended to be called by the
 151      * {@code ImageProducer} of the {@code Image} whose pixels
 152      * are being filtered.  Developers using
 153      * this class to retrieve pixels from an image should avoid calling
 154      * this method directly since that operation could result in problems
 155      * with retrieving the requested pixels.
 156      * @throws IllegalArgumentException if width or height are less than
 157      * zero.
 158      * @see ImageConsumer#setPixels(int, int, int, int, ColorModel, byte[],
 159                                     int, int)
 160      */
 161     public void setPixels(int x, int y, int w, int h,
 162                           ColorModel model, byte pixels[], int off,
 163                           int scansize) {
 164         // Fix 4184230
 165         if (w < 0 || h < 0) {
 166             throw new IllegalArgumentException("Width ("+w+
 167                                                 ") and height ("+h+
 168                                                 ") must be > 0");
 169         }
 170         // Nothing to do
 171         if (w == 0 || h == 0) {
 172             return;
 173         }
 174         if (y < 0) {
 175             int diff = -y;
 176             if (diff >= h) {
 177                 return;
 178             }
 179             off += scansize * diff;
 180             y += diff;
 181             h -= diff;
 182         }


 229             }
 230         }
 231     }
 232     /**
 233      * Filters the information provided in the {@code setPixels}
 234      * method of the {@code ImageConsumer} interface which takes
 235      * an array of integers.
 236      * <p>
 237      * Note: This method is intended to be called by the
 238      * {@code ImageProducer} of the {@code Image} whose
 239      * pixels are being filtered.  Developers using this class to
 240      * retrieve pixels from an image should avoid calling this method
 241      * directly since that operation could result in problems
 242      * with retrieving the requested pixels.
 243      * @throws IllegalArgumentException if width or height are less than
 244      * zero.
 245      * @see ImageConsumer#setPixels(int, int, int, int, ColorModel, int[],
 246                                     int, int)
 247      */
 248     public void setPixels(int x, int y, int w, int h,
 249                           ColorModel model, int pixels[], int off,
 250                           int scansize) {
 251         // Fix 4184230
 252         if (w < 0 || h < 0) {
 253             throw new IllegalArgumentException("Width ("+w+
 254                                                 ") and height ("+h+
 255                                                 ") must be > 0");
 256         }
 257         // Nothing to do
 258         if (w == 0 || h == 0) {
 259             return;
 260         }
 261         if (y < 0) {
 262             int diff = -y;
 263             if (diff >= h) {
 264                 return;
 265             }
 266             off += scansize * diff;
 267             y += diff;
 268             h -= diff;
 269         }


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 110      * method clears the current {@code ColorModel} of this
 111      * {@code BufferedImageFilter}.
 112      * <p>
 113      * Note: This method is intended to be called by the
 114      * {@code ImageProducer} of the {@code Image}
 115      * whose pixels are being filtered.  Developers using this
 116      * class to retrieve pixels from an image
 117      * should avoid calling this method directly since that
 118      * operation could result in problems with retrieving the
 119      * requested pixels.
 120      * @param model the {@link ColorModel} to which to set the
 121      *        {@code ColorModel} of this {@code BufferedImageFilter}
 122      * @see ImageConsumer#setColorModel
 123      */
 124     public void setColorModel(ColorModel model) {
 125         this.model = model;
 126     }
 127 
 128     private void convertToRGB() {
 129         int size = width * height;
 130         int[] newpixels = new int[size];
 131         if (bytePixels != null) {
 132             for (int i = 0; i < size; i++) {
 133                 newpixels[i] = this.model.getRGB(bytePixels[i] & 0xff);
 134             }
 135         } else if (intPixels != null) {
 136             for (int i = 0; i < size; i++) {
 137                 newpixels[i] = this.model.getRGB(intPixels[i]);
 138             }
 139         }
 140         bytePixels = null;
 141         intPixels = newpixels;
 142         this.model = ColorModel.getRGBdefault();
 143     }
 144 
 145     /**
 146      * Filters the information provided in the {@code setPixels}
 147      * method of the {@code ImageConsumer} interface which takes
 148      * an array of bytes.
 149      * <p>
 150      * Note: This method is intended to be called by the
 151      * {@code ImageProducer} of the {@code Image} whose pixels
 152      * are being filtered.  Developers using
 153      * this class to retrieve pixels from an image should avoid calling
 154      * this method directly since that operation could result in problems
 155      * with retrieving the requested pixels.
 156      * @throws IllegalArgumentException if width or height are less than
 157      * zero.
 158      * @see ImageConsumer#setPixels(int, int, int, int, ColorModel, byte[],
 159                                     int, int)
 160      */
 161     public void setPixels(int x, int y, int w, int h,
 162                           ColorModel model, byte[] pixels, int off,
 163                           int scansize) {
 164         // Fix 4184230
 165         if (w < 0 || h < 0) {
 166             throw new IllegalArgumentException("Width ("+w+
 167                                                 ") and height ("+h+
 168                                                 ") must be > 0");
 169         }
 170         // Nothing to do
 171         if (w == 0 || h == 0) {
 172             return;
 173         }
 174         if (y < 0) {
 175             int diff = -y;
 176             if (diff >= h) {
 177                 return;
 178             }
 179             off += scansize * diff;
 180             y += diff;
 181             h -= diff;
 182         }


 229             }
 230         }
 231     }
 232     /**
 233      * Filters the information provided in the {@code setPixels}
 234      * method of the {@code ImageConsumer} interface which takes
 235      * an array of integers.
 236      * <p>
 237      * Note: This method is intended to be called by the
 238      * {@code ImageProducer} of the {@code Image} whose
 239      * pixels are being filtered.  Developers using this class to
 240      * retrieve pixels from an image should avoid calling this method
 241      * directly since that operation could result in problems
 242      * with retrieving the requested pixels.
 243      * @throws IllegalArgumentException if width or height are less than
 244      * zero.
 245      * @see ImageConsumer#setPixels(int, int, int, int, ColorModel, int[],
 246                                     int, int)
 247      */
 248     public void setPixels(int x, int y, int w, int h,
 249                           ColorModel model, int[] pixels, int off,
 250                           int scansize) {
 251         // Fix 4184230
 252         if (w < 0 || h < 0) {
 253             throw new IllegalArgumentException("Width ("+w+
 254                                                 ") and height ("+h+
 255                                                 ") must be > 0");
 256         }
 257         // Nothing to do
 258         if (w == 0 || h == 0) {
 259             return;
 260         }
 261         if (y < 0) {
 262             int diff = -y;
 263             if (diff >= h) {
 264                 return;
 265             }
 266             off += scansize * diff;
 267             y += diff;
 268             h -= diff;
 269         }


< prev index next >