jdk/src/share/native/sun/awt/image/cvutils/img_dcm.h
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 12748 720f7c4690cb
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * This file contains macro definitions for the Decoding category of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * the macros used by the generic scaleloop function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * This implementation can decode the pixel information associated
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 12748
diff changeset
    31
 * with any Java DirectColorModel object.  This implementation will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * scale the decoded color components to 8-bit quantities if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Another file is provided to optimize DCM parsing when the masks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * are guaranteed to be at least 8-bits wide.  This implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * examines some of the private fields of the DirectColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * object and decodes the red, green, blue, and possibly alpha values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * directly rather than calling the getRGB method on the Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * These definitions vector the standard macro names to the "DCM"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * versions of those macros only if the "DecodeDeclared" keyword has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * not yet been defined elsewhere.  The "DecodeDeclared" keyword is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * also defined here to claim ownership of the primary implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * even though this file does not rely on the definitions in any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifndef DecodeDeclared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define DeclareDecodeVars       DeclareDCMVars
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define InitPixelDecode(CM)     InitPixelDCM(unhand(CM))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define PixelDecode             PixelDCMDecode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#define DecodeDeclared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define DeclareDCMVars                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    IfAlpha(int alpha_mask;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            int alpha_scale;                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            unsigned int alpha_off;)                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int red_mask, green_mask, blue_mask;                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int red_scale, green_scale, blue_scale;                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    unsigned int red_off, green_off, blue_off;                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    int scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define InitPixelDCM(CM)                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    do {                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        Classjava_awt_image_DirectColorModel *dcm =                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            (Classjava_awt_image_DirectColorModel *) CM;                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        red_mask = dcm->red_mask;                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        red_off = dcm->red_offset;                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        red_scale = dcm->red_scale;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        green_mask = dcm->green_mask;                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        green_off = dcm->green_offset;                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        green_scale = dcm->green_scale;                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        blue_mask = dcm->blue_mask;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        blue_off = dcm->blue_offset;                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        blue_scale = dcm->blue_scale;                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        IfAlpha(alpha_mask = dcm->alpha_mask;                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                alpha_off = dcm->alpha_offset;                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                alpha_scale = dcm->alpha_scale;)                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        scale = (red_scale | green_scale | blue_scale                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                 IfAlpha(| alpha_scale));                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define PixelDCMDecode(CM, pixel, red, green, blue, alpha)              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    do {                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        IfAlpha(alpha = ((alpha_mask == 0)                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                         ? 255                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                         : ((pixel & alpha_mask) >> alpha_off));)       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        red = ((pixel & red_mask) >> red_off);                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        green = ((pixel & green_mask) >> green_off);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        blue = ((pixel & blue_mask) >> blue_off);                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (scale) {                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (red_scale) {                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                red = red * 255 / (red_scale);                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            if (green_scale) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                green = green * 255 / (green_scale);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (blue_scale) {                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                blue = blue * 255 / (blue_scale);                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            IfAlpha(if (alpha_scale) {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                alpha = alpha * 255 / (alpha_scale);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            })                                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }                                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    } while (0)