1 /* 2 * Copyright (c) 1997, 2010, 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 23 * questions. 24 */ 25 26 package java.awt; 27 28 import java.awt.image.ColorModel; 29 import javax.tools.annotation.GenerateNativeHeader; 30 import sun.java2d.SunCompositeContext; 31 32 /** 33 * The <code>AlphaComposite</code> class implements basic alpha 34 * compositing rules for combining source and destination colors 35 * to achieve blending and transparency effects with graphics and 36 * images. 37 * The specific rules implemented by this class are the basic set 38 * of 12 rules described in 39 * T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84, 40 * 253-259. 41 * The rest of this documentation assumes some familiarity with the 42 * definitions and concepts outlined in that paper. 43 * 44 * <p> 45 * This class extends the standard equations defined by Porter and 46 * Duff to include one additional factor. 47 * An instance of the <code>AlphaComposite</code> class can contain 48 * an alpha value that is used to modify the opacity or coverage of 49 * every source pixel before it is used in the blending equations. 333 * and thus they would all match. 334 * 335 * <p> 336 * <li> 337 * Because of the technique of simplifying the equations for 338 * calculation efficiency, some implementations might perform 339 * differently when encountering result alpha values of 0.0 340 * on a non-premultiplied destination. 341 * Note that the simplification of removing the divide by alpha 342 * in the case of the SRC rule is technically not valid if the 343 * denominator (alpha) is 0. 344 * But, since the results should only be expected to be accurate 345 * when viewed in premultiplied form, a resulting alpha of 0 346 * essentially renders the resulting color components irrelevant 347 * and so exact behavior in this case should not be expected. 348 * </ul> 349 * @see Composite 350 * @see CompositeContext 351 */ 352 353 /* No native methods here, but the constants are needed in the supporting JNI code */ 354 @GenerateNativeHeader 355 public final class AlphaComposite implements Composite { 356 /** 357 * Both the color and the alpha of the destination are cleared 358 * (Porter-Duff Clear rule). 359 * Neither the source nor the destination is used as input. 360 *<p> 361 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 0, thus: 362 *<pre> 363 * <em>A<sub>r</sub></em> = 0 364 * <em>C<sub>r</sub></em> = 0 365 *</pre> 366 */ 367 public static final int CLEAR = 1; 368 369 /** 370 * The source is copied to the destination 371 * (Porter-Duff Source rule). 372 * The destination is not used as input. 373 *<p> 374 * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = 0, thus: 375 *<pre> 376 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em> 377 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em> 378 *</pre> 379 */ 380 public static final int SRC = 2; 381 382 /** 383 * The destination is left untouched 384 * (Porter-Duff Destination rule). 385 *<p> 386 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 1, thus: 387 *<pre> 388 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em> 389 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em> 390 *</pre> 391 * @since 1.4 392 */ 393 public static final int DST = 9; 394 // Note that DST was added in 1.4 so it is numbered out of order... 395 396 /** 397 * The source is composited over the destination 398 * (Porter-Duff Source Over Destination rule). 399 *<p> 400 * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 401 *<pre> 402 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 403 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 404 *</pre> 405 */ 406 public static final int SRC_OVER = 3; 407 408 /** 409 * The destination is composited over the source and 410 * the result replaces the destination 411 * (Porter-Duff Destination Over Source rule). 412 *<p> 413 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 1, thus: 414 *<pre> 415 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em> 416 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em> 417 *</pre> 418 */ 419 public static final int DST_OVER = 4; 420 421 /** 422 * The part of the source lying inside of the destination replaces 423 * the destination 424 * (Porter-Duff Source In Destination rule). 425 *<p> 426 * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = 0, thus: 427 *<pre> 428 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em> 429 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em> 430 *</pre> 431 */ 432 public static final int SRC_IN = 5; 433 434 /** 435 * The part of the destination lying inside of the source 436 * replaces the destination 437 * (Porter-Duff Destination In Source rule). 438 *<p> 439 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus: 440 *<pre> 441 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em> 442 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em> 443 *</pre> 444 */ 445 public static final int DST_IN = 6; 446 447 /** 448 * The part of the source lying outside of the destination 449 * replaces the destination 450 * (Porter-Duff Source Held Out By Destination rule). 451 *<p> 452 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 0, thus: 453 *<pre> 454 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) 455 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) 456 *</pre> 457 */ 458 public static final int SRC_OUT = 7; 459 460 /** 461 * The part of the destination lying outside of the source 462 * replaces the destination 463 * (Porter-Duff Destination Held Out By Source rule). 464 *<p> 465 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 466 *<pre> 467 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 468 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 469 *</pre> 470 */ 471 public static final int DST_OUT = 8; 472 473 // Rule 9 is DST which is defined above where it fits into the 474 // list logically, rather than numerically 475 // 476 // public static final int DST = 9; 477 478 /** 479 * The part of the source lying inside of the destination 480 * is composited onto the destination 481 * (Porter-Duff Source Atop Destination rule). 482 *<p> 483 * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 484 *<pre> 485 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) = <em>A<sub>d</sub></em> 486 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 487 *</pre> 488 * @since 1.4 489 */ 490 public static final int SRC_ATOP = 10; 491 492 /** 493 * The part of the destination lying inside of the source 494 * is composited over the source and replaces the destination 495 * (Porter-Duff Destination Atop Source rule). 496 *<p> 497 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus: 498 *<pre> 499 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em> = <em>A<sub>s</sub></em> 500 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em> 501 *</pre> 502 * @since 1.4 503 */ 504 public static final int DST_ATOP = 11; 505 506 /** 507 * The part of the source that lies outside of the destination 508 * is combined with the part of the destination that lies outside 509 * of the source 510 * (Porter-Duff Source Xor Destination rule). 511 *<p> 512 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 513 *<pre> 514 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 515 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 516 *</pre> 517 * @since 1.4 518 */ 519 public static final int XOR = 12; 520 521 /** 522 * <code>AlphaComposite</code> object that implements the opaque CLEAR rule 523 * with an alpha of 1.0f. 524 * @see #CLEAR 525 */ 526 public static final AlphaComposite Clear = new AlphaComposite(CLEAR); 527 528 /** 529 * <code>AlphaComposite</code> object that implements the opaque SRC rule 530 * with an alpha of 1.0f. 531 * @see #SRC 532 */ 533 public static final AlphaComposite Src = new AlphaComposite(SRC); 534 535 /** 536 * <code>AlphaComposite</code> object that implements the opaque DST rule 537 * with an alpha of 1.0f. 538 * @see #DST 539 * @since 1.4 589 * @since 1.4 590 */ 591 public static final AlphaComposite SrcAtop = new AlphaComposite(SRC_ATOP); 592 593 /** 594 * <code>AlphaComposite</code> object that implements the opaque DST_ATOP rule 595 * with an alpha of 1.0f. 596 * @see #DST_ATOP 597 * @since 1.4 598 */ 599 public static final AlphaComposite DstAtop = new AlphaComposite(DST_ATOP); 600 601 /** 602 * <code>AlphaComposite</code> object that implements the opaque XOR rule 603 * with an alpha of 1.0f. 604 * @see #XOR 605 * @since 1.4 606 */ 607 public static final AlphaComposite Xor = new AlphaComposite(XOR); 608 609 private static final int MIN_RULE = CLEAR; 610 private static final int MAX_RULE = XOR; 611 612 float extraAlpha; 613 int rule; 614 615 private AlphaComposite(int rule) { 616 this(rule, 1.0f); 617 } 618 619 private AlphaComposite(int rule, float alpha) { 620 if (rule < MIN_RULE || rule > MAX_RULE) { 621 throw new IllegalArgumentException("unknown composite rule"); 622 } 623 if (alpha >= 0.0f && alpha <= 1.0f) { 624 this.rule = rule; 625 this.extraAlpha = alpha; 626 } else { 627 throw new IllegalArgumentException("alpha value out of range"); 628 } 629 } 630 | 1 /* 2 * Copyright (c) 1997, 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 23 * questions. 24 */ 25 26 package java.awt; 27 28 import java.awt.image.ColorModel; 29 import java.lang.annotation.Native; 30 import sun.java2d.SunCompositeContext; 31 32 /** 33 * The <code>AlphaComposite</code> class implements basic alpha 34 * compositing rules for combining source and destination colors 35 * to achieve blending and transparency effects with graphics and 36 * images. 37 * The specific rules implemented by this class are the basic set 38 * of 12 rules described in 39 * T. Porter and T. Duff, "Compositing Digital Images", SIGGRAPH 84, 40 * 253-259. 41 * The rest of this documentation assumes some familiarity with the 42 * definitions and concepts outlined in that paper. 43 * 44 * <p> 45 * This class extends the standard equations defined by Porter and 46 * Duff to include one additional factor. 47 * An instance of the <code>AlphaComposite</code> class can contain 48 * an alpha value that is used to modify the opacity or coverage of 49 * every source pixel before it is used in the blending equations. 333 * and thus they would all match. 334 * 335 * <p> 336 * <li> 337 * Because of the technique of simplifying the equations for 338 * calculation efficiency, some implementations might perform 339 * differently when encountering result alpha values of 0.0 340 * on a non-premultiplied destination. 341 * Note that the simplification of removing the divide by alpha 342 * in the case of the SRC rule is technically not valid if the 343 * denominator (alpha) is 0. 344 * But, since the results should only be expected to be accurate 345 * when viewed in premultiplied form, a resulting alpha of 0 346 * essentially renders the resulting color components irrelevant 347 * and so exact behavior in this case should not be expected. 348 * </ul> 349 * @see Composite 350 * @see CompositeContext 351 */ 352 353 public final class AlphaComposite implements Composite { 354 /** 355 * Both the color and the alpha of the destination are cleared 356 * (Porter-Duff Clear rule). 357 * Neither the source nor the destination is used as input. 358 *<p> 359 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 0, thus: 360 *<pre> 361 * <em>A<sub>r</sub></em> = 0 362 * <em>C<sub>r</sub></em> = 0 363 *</pre> 364 */ 365 @Native public static final int CLEAR = 1; 366 367 /** 368 * The source is copied to the destination 369 * (Porter-Duff Source rule). 370 * The destination is not used as input. 371 *<p> 372 * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = 0, thus: 373 *<pre> 374 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em> 375 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em> 376 *</pre> 377 */ 378 @Native public static final int SRC = 2; 379 380 /** 381 * The destination is left untouched 382 * (Porter-Duff Destination rule). 383 *<p> 384 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = 1, thus: 385 *<pre> 386 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em> 387 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em> 388 *</pre> 389 * @since 1.4 390 */ 391 @Native public static final int DST = 9; 392 // Note that DST was added in 1.4 so it is numbered out of order... 393 394 /** 395 * The source is composited over the destination 396 * (Porter-Duff Source Over Destination rule). 397 *<p> 398 * <em>F<sub>s</sub></em> = 1 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 399 *<pre> 400 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 401 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 402 *</pre> 403 */ 404 @Native public static final int SRC_OVER = 3; 405 406 /** 407 * The destination is composited over the source and 408 * the result replaces the destination 409 * (Porter-Duff Destination Over Source rule). 410 *<p> 411 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 1, thus: 412 *<pre> 413 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em> 414 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em> 415 *</pre> 416 */ 417 @Native public static final int DST_OVER = 4; 418 419 /** 420 * The part of the source lying inside of the destination replaces 421 * the destination 422 * (Porter-Duff Source In Destination rule). 423 *<p> 424 * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = 0, thus: 425 *<pre> 426 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em> 427 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em> 428 *</pre> 429 */ 430 @Native public static final int SRC_IN = 5; 431 432 /** 433 * The part of the destination lying inside of the source 434 * replaces the destination 435 * (Porter-Duff Destination In Source rule). 436 *<p> 437 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus: 438 *<pre> 439 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em> 440 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em> 441 *</pre> 442 */ 443 @Native public static final int DST_IN = 6; 444 445 /** 446 * The part of the source lying outside of the destination 447 * replaces the destination 448 * (Porter-Duff Source Held Out By Destination rule). 449 *<p> 450 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = 0, thus: 451 *<pre> 452 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) 453 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) 454 *</pre> 455 */ 456 @Native public static final int SRC_OUT = 7; 457 458 /** 459 * The part of the destination lying outside of the source 460 * replaces the destination 461 * (Porter-Duff Destination Held Out By Source rule). 462 *<p> 463 * <em>F<sub>s</sub></em> = 0 and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 464 *<pre> 465 * <em>A<sub>r</sub></em> = <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 466 * <em>C<sub>r</sub></em> = <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 467 *</pre> 468 */ 469 @Native public static final int DST_OUT = 8; 470 471 // Rule 9 is DST which is defined above where it fits into the 472 // list logically, rather than numerically 473 // 474 // public static final int DST = 9; 475 476 /** 477 * The part of the source lying inside of the destination 478 * is composited onto the destination 479 * (Porter-Duff Source Atop Destination rule). 480 *<p> 481 * <em>F<sub>s</sub></em> = <em>A<sub>d</sub></em> and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 482 *<pre> 483 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) = <em>A<sub>d</sub></em> 484 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*<em>A<sub>d</sub></em> + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 485 *</pre> 486 * @since 1.4 487 */ 488 @Native public static final int SRC_ATOP = 10; 489 490 /** 491 * The part of the destination lying inside of the source 492 * is composited over the source and replaces the destination 493 * (Porter-Duff Destination Atop Source rule). 494 *<p> 495 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = <em>A<sub>s</sub></em>, thus: 496 *<pre> 497 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*<em>A<sub>s</sub></em> = <em>A<sub>s</sub></em> 498 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*<em>A<sub>s</sub></em> 499 *</pre> 500 * @since 1.4 501 */ 502 @Native public static final int DST_ATOP = 11; 503 504 /** 505 * The part of the source that lies outside of the destination 506 * is combined with the part of the destination that lies outside 507 * of the source 508 * (Porter-Duff Source Xor Destination rule). 509 *<p> 510 * <em>F<sub>s</sub></em> = (1-<em>A<sub>d</sub></em>) and <em>F<sub>d</sub></em> = (1-<em>A<sub>s</sub></em>), thus: 511 *<pre> 512 * <em>A<sub>r</sub></em> = <em>A<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>A<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 513 * <em>C<sub>r</sub></em> = <em>C<sub>s</sub></em>*(1-<em>A<sub>d</sub></em>) + <em>C<sub>d</sub></em>*(1-<em>A<sub>s</sub></em>) 514 *</pre> 515 * @since 1.4 516 */ 517 @Native public static final int XOR = 12; 518 519 /** 520 * <code>AlphaComposite</code> object that implements the opaque CLEAR rule 521 * with an alpha of 1.0f. 522 * @see #CLEAR 523 */ 524 public static final AlphaComposite Clear = new AlphaComposite(CLEAR); 525 526 /** 527 * <code>AlphaComposite</code> object that implements the opaque SRC rule 528 * with an alpha of 1.0f. 529 * @see #SRC 530 */ 531 public static final AlphaComposite Src = new AlphaComposite(SRC); 532 533 /** 534 * <code>AlphaComposite</code> object that implements the opaque DST rule 535 * with an alpha of 1.0f. 536 * @see #DST 537 * @since 1.4 587 * @since 1.4 588 */ 589 public static final AlphaComposite SrcAtop = new AlphaComposite(SRC_ATOP); 590 591 /** 592 * <code>AlphaComposite</code> object that implements the opaque DST_ATOP rule 593 * with an alpha of 1.0f. 594 * @see #DST_ATOP 595 * @since 1.4 596 */ 597 public static final AlphaComposite DstAtop = new AlphaComposite(DST_ATOP); 598 599 /** 600 * <code>AlphaComposite</code> object that implements the opaque XOR rule 601 * with an alpha of 1.0f. 602 * @see #XOR 603 * @since 1.4 604 */ 605 public static final AlphaComposite Xor = new AlphaComposite(XOR); 606 607 @Native private static final int MIN_RULE = CLEAR; 608 @Native private static final int MAX_RULE = XOR; 609 610 float extraAlpha; 611 int rule; 612 613 private AlphaComposite(int rule) { 614 this(rule, 1.0f); 615 } 616 617 private AlphaComposite(int rule, float alpha) { 618 if (rule < MIN_RULE || rule > MAX_RULE) { 619 throw new IllegalArgumentException("unknown composite rule"); 620 } 621 if (alpha >= 0.0f && alpha <= 1.0f) { 622 this.rule = rule; 623 this.extraAlpha = alpha; 624 } else { 625 throw new IllegalArgumentException("alpha value out of range"); 626 } 627 } 628 |