1. /*
  2. * @(#)LookupTable.java 1.21 01/11/29
  3. *
  4. * Copyright 2002 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. */
  58. public int getNumComponents() {
  59. return numComponents;
  60. }
  61. /**
  62. * Returns the offset.
  63. */
  64. public int getOffset() {
  65. return offset;
  66. }
  67. /**
  68. * Returns an int array of components for one pixel. Source and
  69. * destination may be equal. The dest array is returned. If dest
  70. * is null, a new array will be allocated.
  71. */
  72. public abstract int[] lookupPixel(int[] src, int[] dest);
  73. }