1. /*
  2. * @(#)LookupTable.java 1.26 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.image;
  8. /**
  9. * This abstract class defines a lookup table object. ByteLookupTable
  10. * and ShortLookupTable are subclasses, which
  11. * contain byte and short data, respectively. A lookup table
  12. * contains data arrays for one or more bands (or components) of an image
  13. * (for example, separate arrays for R, G, and B),
  14. * and it contains an offset which will be subtracted from the
  15. * input values before indexing into the arrays. This allows an array
  16. * smaller than the native data size to be provided for a
  17. * constrained input. If there is only one array in the lookup
  18. * table, it will be applied to all bands. All arrays must be the
  19. * same size.
  20. *
  21. * @see ByteLookupTable
  22. * @see ShortLookupTable
  23. * @see LookupOp
  24. * @version 10 Feb 1997
  25. */
  26. public abstract class LookupTable extends Object{
  27. /**
  28. * Constants
  29. */
  30. int numComponents;
  31. int offset;
  32. int numEntries;
  33. /**
  34. * Constructs a new LookupTable from the number of components and an offset
  35. * into the lookup table.
  36. * @param offset the offset to subtract from input values before indexing
  37. * into the data arrays for this <code>LookupTable</code>
  38. * @param numComponents the number of data arrays in this
  39. * <code>LookupTable</code>
  40. * @throws IllegalArgumentException if <code>offset</code> is less than 0
  41. * or if <code>numComponents</code> is less than 1
  42. */
  43. protected LookupTable(int offset, int numComponents) {
  44. if (offset < 0) {
  45. throw new
  46. IllegalArgumentException("Offset must be greater than 0");
  47. }
  48. if (numComponents < 1) {
  49. throw new IllegalArgumentException("Number of components must "+
  50. " be at least 1");
  51. }
  52. this.numComponents = numComponents;
  53. this.offset = offset;
  54. }
  55. /**
  56. * Returns the number of components in the lookup table.
  57. * @return the number of components in this <code>LookupTable</code>.
  58. */
  59. public int getNumComponents() {
  60. return numComponents;
  61. }
  62. /**
  63. * Returns the offset.
  64. * @return the offset of this <code>LookupTable</code>.
  65. */
  66. public int getOffset() {
  67. return offset;
  68. }
  69. /**
  70. * Returns an <code>int</code> array of components for
  71. * one pixel. The <code>dest</code> array contains the
  72. * result of the lookup and is returned. If dest is
  73. * <code>null</code>, a new array is allocated. The
  74. * source and destination can be equal.
  75. * @param src the source array of components of one pixel
  76. * @param dest the destination array of components for one pixel,
  77. * translated with this <code>LookupTable</code>
  78. * @return an <code>int</code> array of components for one
  79. * pixel.
  80. */
  81. public abstract int[] lookupPixel(int[] src, int[] dest);
  82. }