1 /*
2 * Copyright (c) 1995, 2013, 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
412 }
413
414 /**
415 * The setColorModel method is part of the ImageConsumer API which
416 * this class must implement to retrieve the pixels.
417 * <p>
418 * Note: This method is intended to be called by the ImageProducer
419 * of the Image whose pixels are being grabbed. Developers using
420 * this class to retrieve pixels from an image should avoid calling
421 * this method directly since that operation could result in problems
422 * with retrieving the requested pixels.
423 * @param model the specified {@code ColorModel}
424 * @see #getColorModel
425 */
426 public void setColorModel(ColorModel model) {
427 return;
428 }
429
430 private void convertToRGB() {
431 int size = dstW * dstH;
432 int newpixels[] = new int[size];
433 if (bytePixels != null) {
434 for (int i = 0; i < size; i++) {
435 newpixels[i] = imageModel.getRGB(bytePixels[i] & 0xff);
436 }
437 } else if (intPixels != null) {
438 for (int i = 0; i < size; i++) {
439 newpixels[i] = imageModel.getRGB(intPixels[i]);
440 }
441 }
442 bytePixels = null;
443 intPixels = newpixels;
444 dstScan = dstW;
445 dstOff = 0;
446 imageModel = ColorModel.getRGBdefault();
447 }
448
449 /**
450 * The setPixels method is part of the ImageConsumer API which
451 * this class must implement to retrieve the pixels.
452 * <p>
453 * Note: This method is intended to be called by the ImageProducer
454 * of the Image whose pixels are being grabbed. Developers using
455 * this class to retrieve pixels from an image should avoid calling
456 * this method directly since that operation could result in problems
457 * with retrieving the requested pixels.
458 * @param srcX the X coordinate of the upper-left corner
459 * of the area of pixels to be set
460 * @param srcY the Y coordinate of the upper-left corner
461 * of the area of pixels to be set
462 * @param srcW the width of the area of pixels
463 * @param srcH the height of the area of pixels
464 * @param model the specified {@code ColorModel}
465 * @param pixels the array of pixels
466 * @param srcOff the offset into the pixels array
467 * @param srcScan the distance from one row of pixels to the next
468 * in the pixels array
469 * @see #getPixels
470 */
471 public void setPixels(int srcX, int srcY, int srcW, int srcH,
472 ColorModel model,
473 byte pixels[], int srcOff, int srcScan) {
474 if (srcY < dstY) {
475 int diff = dstY - srcY;
476 if (diff >= srcH) {
477 return;
478 }
479 srcOff += srcScan * diff;
480 srcY += diff;
481 srcH -= diff;
482 }
483 if (srcY + srcH > dstY + dstH) {
484 srcH = (dstY + dstH) - srcY;
485 if (srcH <= 0) {
486 return;
487 }
488 }
489 if (srcX < dstX) {
490 int diff = dstX - srcX;
491 if (diff >= srcW) {
492 return;
493 }
540 * Note: This method is intended to be called by the ImageProducer
541 * of the Image whose pixels are being grabbed. Developers using
542 * this class to retrieve pixels from an image should avoid calling
543 * this method directly since that operation could result in problems
544 * with retrieving the requested pixels.
545 * @param srcX the X coordinate of the upper-left corner
546 * of the area of pixels to be set
547 * @param srcY the Y coordinate of the upper-left corner
548 * of the area of pixels to be set
549 * @param srcW the width of the area of pixels
550 * @param srcH the height of the area of pixels
551 * @param model the specified {@code ColorModel}
552 * @param pixels the array of pixels
553 * @param srcOff the offset into the pixels array
554 * @param srcScan the distance from one row of pixels to the next
555 * in the pixels array
556 * @see #getPixels
557 */
558 public void setPixels(int srcX, int srcY, int srcW, int srcH,
559 ColorModel model,
560 int pixels[], int srcOff, int srcScan) {
561 if (srcY < dstY) {
562 int diff = dstY - srcY;
563 if (diff >= srcH) {
564 return;
565 }
566 srcOff += srcScan * diff;
567 srcY += diff;
568 srcH -= diff;
569 }
570 if (srcY + srcH > dstY + dstH) {
571 srcH = (dstY + dstH) - srcY;
572 if (srcH <= 0) {
573 return;
574 }
575 }
576 if (srcX < dstX) {
577 int diff = dstX - srcX;
578 if (diff >= srcW) {
579 return;
580 }
|
1 /*
2 * Copyright (c) 1995, 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
412 }
413
414 /**
415 * The setColorModel method is part of the ImageConsumer API which
416 * this class must implement to retrieve the pixels.
417 * <p>
418 * Note: This method is intended to be called by the ImageProducer
419 * of the Image whose pixels are being grabbed. Developers using
420 * this class to retrieve pixels from an image should avoid calling
421 * this method directly since that operation could result in problems
422 * with retrieving the requested pixels.
423 * @param model the specified {@code ColorModel}
424 * @see #getColorModel
425 */
426 public void setColorModel(ColorModel model) {
427 return;
428 }
429
430 private void convertToRGB() {
431 int size = dstW * dstH;
432 int[] newpixels = new int[size];
433 if (bytePixels != null) {
434 for (int i = 0; i < size; i++) {
435 newpixels[i] = imageModel.getRGB(bytePixels[i] & 0xff);
436 }
437 } else if (intPixels != null) {
438 for (int i = 0; i < size; i++) {
439 newpixels[i] = imageModel.getRGB(intPixels[i]);
440 }
441 }
442 bytePixels = null;
443 intPixels = newpixels;
444 dstScan = dstW;
445 dstOff = 0;
446 imageModel = ColorModel.getRGBdefault();
447 }
448
449 /**
450 * The setPixels method is part of the ImageConsumer API which
451 * this class must implement to retrieve the pixels.
452 * <p>
453 * Note: This method is intended to be called by the ImageProducer
454 * of the Image whose pixels are being grabbed. Developers using
455 * this class to retrieve pixels from an image should avoid calling
456 * this method directly since that operation could result in problems
457 * with retrieving the requested pixels.
458 * @param srcX the X coordinate of the upper-left corner
459 * of the area of pixels to be set
460 * @param srcY the Y coordinate of the upper-left corner
461 * of the area of pixels to be set
462 * @param srcW the width of the area of pixels
463 * @param srcH the height of the area of pixels
464 * @param model the specified {@code ColorModel}
465 * @param pixels the array of pixels
466 * @param srcOff the offset into the pixels array
467 * @param srcScan the distance from one row of pixels to the next
468 * in the pixels array
469 * @see #getPixels
470 */
471 public void setPixels(int srcX, int srcY, int srcW, int srcH,
472 ColorModel model,
473 byte[] pixels, int srcOff, int srcScan) {
474 if (srcY < dstY) {
475 int diff = dstY - srcY;
476 if (diff >= srcH) {
477 return;
478 }
479 srcOff += srcScan * diff;
480 srcY += diff;
481 srcH -= diff;
482 }
483 if (srcY + srcH > dstY + dstH) {
484 srcH = (dstY + dstH) - srcY;
485 if (srcH <= 0) {
486 return;
487 }
488 }
489 if (srcX < dstX) {
490 int diff = dstX - srcX;
491 if (diff >= srcW) {
492 return;
493 }
540 * Note: This method is intended to be called by the ImageProducer
541 * of the Image whose pixels are being grabbed. Developers using
542 * this class to retrieve pixels from an image should avoid calling
543 * this method directly since that operation could result in problems
544 * with retrieving the requested pixels.
545 * @param srcX the X coordinate of the upper-left corner
546 * of the area of pixels to be set
547 * @param srcY the Y coordinate of the upper-left corner
548 * of the area of pixels to be set
549 * @param srcW the width of the area of pixels
550 * @param srcH the height of the area of pixels
551 * @param model the specified {@code ColorModel}
552 * @param pixels the array of pixels
553 * @param srcOff the offset into the pixels array
554 * @param srcScan the distance from one row of pixels to the next
555 * in the pixels array
556 * @see #getPixels
557 */
558 public void setPixels(int srcX, int srcY, int srcW, int srcH,
559 ColorModel model,
560 int[] pixels, int srcOff, int srcScan) {
561 if (srcY < dstY) {
562 int diff = dstY - srcY;
563 if (diff >= srcH) {
564 return;
565 }
566 srcOff += srcScan * diff;
567 srcY += diff;
568 srcH -= diff;
569 }
570 if (srcY + srcH > dstY + dstH) {
571 srcH = (dstY + dstH) - srcY;
572 if (srcH <= 0) {
573 return;
574 }
575 }
576 if (srcX < dstX) {
577 int diff = dstX - srcX;
578 if (diff >= srcW) {
579 return;
580 }
|