src/java.desktop/share/classes/java/awt/image/LookupTable.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47971 75686e8da573
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * This abstract class defines a lookup table object.  ByteLookupTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and ShortLookupTable are subclasses, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * contain byte and short data, respectively.  A lookup table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * contains data arrays for one or more bands (or components) of an image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (for example, separate arrays for R, G, and B),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * and it contains an offset which will be subtracted from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * input values before indexing into the arrays.  This allows an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * smaller than the native data size to be provided for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * constrained input.  If there is only one array in the lookup
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * table, it will be applied to all bands.  All arrays must be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * same size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @see ByteLookupTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see ShortLookupTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see LookupOp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
    46
public abstract class LookupTable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    int  numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int  offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int  numEntries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Constructs a new LookupTable from the number of components and an offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * into the lookup table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param offset the offset to subtract from input values before indexing
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    60
     *        into the data arrays for this {@code LookupTable}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param numComponents the number of data arrays in this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    62
     *        {@code LookupTable}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    63
     * @throws IllegalArgumentException if {@code offset} is less than 0
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    64
     *         or if {@code numComponents} is less than 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected LookupTable(int offset, int numComponents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (offset < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                IllegalArgumentException("Offset must be greater than 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        if (numComponents < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            throw new IllegalArgumentException("Number of components must "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                               " be at least 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.numComponents = numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        this.offset = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the number of components in the lookup table.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    81
     * @return the number of components in this {@code LookupTable}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public int getNumComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return numComponents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Returns the offset.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    89
     * @return the offset of this {@code LookupTable}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    96
     * Returns an {@code int} array of components for
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    97
     * one pixel.  The {@code dest} array contains the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * result of the lookup and is returned.  If dest is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
    99
     * {@code null}, a new array is allocated.  The
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * source and destination can be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param src the source array of components of one pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param dest the destination array of components for one pixel,
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   103
     *        translated with this {@code LookupTable}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   104
     * @return an {@code int} array of components for one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *         pixel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public abstract int[] lookupPixel(int[] src, int[] dest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}