1. package org.jr.awt.image;
  2. /**
  3. * Copyright: Copyright (c) 2002-2004
  4. * Company: JavaResearch(http://www.javaresearch.org)
  5. * 最后更新日期:2003年2月13日
  6. * @author Cherami
  7. */
  8. import java.awt.image.*;
  9. /**
  10. * 颜色反转变换模型。
  11. * @since 0.1
  12. */
  13. public class ReverseColorModel
  14. extends ColorModel {
  15. ColorModel sourceModel;
  16. /**
  17. * 构造方法,根据原颜色变换模型构造颜色反转变换模型。
  18. * @param sourceModel 原颜色变换模型
  19. */
  20. public ReverseColorModel(ColorModel sourceModel) {
  21. super(sourceModel.getPixelSize());
  22. this.sourceModel = sourceModel;
  23. }
  24. /**
  25. * 得到Alpha值
  26. * @param pixel 象素的原RGB值
  27. * @return 返回原色彩模型的Alpha值
  28. */
  29. public int getAlpha(int pixel) {
  30. return sourceModel.getAlpha(pixel);
  31. }
  32. /**
  33. * 得到红色分量值
  34. * @param pixel 象素的原RGB值
  35. * @return 返回原色彩模型的红色分量值的取反
  36. */
  37. public int getRed(int pixel) {
  38. return~sourceModel.getRed(pixel);
  39. }
  40. /**
  41. * 得到绿色分量值
  42. * @param pixel 象素的原RGB值
  43. * @return 返回原色彩模型的绿色分量值的取反
  44. */
  45. public int getGreen(int pixel) {
  46. return~sourceModel.getGreen(pixel);
  47. }
  48. /**
  49. * 得到蓝色分量值
  50. * @param pixel 象素的原RGB值
  51. * @return 返回原色彩模型的蓝色分量值的取反
  52. */
  53. public int getBlue(int pixel) {
  54. return~sourceModel.getBlue(pixel);
  55. }
  56. /**
  57. * 得到变换后的RGB值
  58. * @param pixel 象素的原RGB值
  59. * @return 返回原色彩模型的RGB值的RGB分量值取反
  60. */
  61. public int getRGB(int pixel) {
  62. return (getAlpha(pixel) << 24) + (getRed(pixel) << 16) +
  63. (getGreen(pixel) << 8) + getBlue(pixel);
  64. }
  65. }