jdk/src/share/native/sun/awt/splashscreen/splashscreen_gfx_impl.h
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7766 42c1e9741ed0
child 23259 5bf4d2bd28f1
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7766
diff changeset
     2
 * Copyright (c) 2005, 2010, 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: 2603
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: 2603
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: 2603
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2603
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2603
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
#ifndef SPLASHSCREEN_GFX_IMPL_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define SPLASHSCREEN_GFX_IMPL_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "splashscreen_gfx.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/* here come some very simple macros */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/* advance a pointer p by sizeof(type)*n bytes */
2603
2c6a8be8dc13 6766136: corrupted gif image may cause crash in java splashscreen library.
bae
parents: 2
diff changeset
    34
#define INCPN(type,p,n) ((p) = (type*)(p)+(n))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/* advance a pointer by sizeof(type) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#define INCP(type,p) INCPN(type,(p),1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/* store a typed value to pointed location */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define PUT(type,p,v) (*(type*)(p) = (type)(v))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/* load a typed value from pointed location */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define GET(type,p) (*(type*)p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/* same as cond<0?-1:0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
enum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    IFNEG_SHIFT_BITS = sizeof(int) * 8 - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define IFNEG(cond) ((int)(cond)>>IFNEG_SHIFT_BITS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/* same as cond<0?n1:n2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define IFNEGPOS(cond,n1,n2) ((IFNEG(cond)&(n1))|((~IFNEG(cond))&(n2)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/* value shifted left by n bits, negative n is allowed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define LSHIFT(value,n) IFNEGPOS((n),(value)>>-(n),(value)<<(n))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/* value shifted right by n bits, negative n is allowed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define RSHIFT(value,n) IFNEGPOS(n,(value)<<-(n),(value)>>(n))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* converts a single i'th component to the specific format defined by format->shift[i] and format->mask[i] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#define CONVCOMP(quad,format,i) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    (LSHIFT((quad),(format)->shift[i])&(format)->mask[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
/* extracts the component defined by format->shift[i] and format->mask[i] from a specific-format value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define UNCONVCOMP(value,format,i) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    (RSHIFT((value)&(format)->mask[i],(format)->shift[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/*  dithers the color using the dither matrices and colormap from format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    indices to dither matrices are passed as arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
INLINE unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
ditherColor(rgbquad_t value, ImageFormat * format, int row, int col)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    int blue = QUAD_BLUE(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    int green = QUAD_GREEN(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    int red = QUAD_RED(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    blue = format->dithers[0].colorTable[blue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        format->dithers[0].matrix[col & DITHER_MASK][row & DITHER_MASK]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    green = format->dithers[1].colorTable[green +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        format->dithers[1].matrix[col & DITHER_MASK][row & DITHER_MASK]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    red = format->dithers[2].colorTable[red +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        format->dithers[2].matrix[col & DITHER_MASK][row & DITHER_MASK]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    return red + green + blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/*      blend (lerp between) two rgb quads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        src and dst alpha is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        the algorithm: src*alpha+dst*(1-alpha)=(src-dst)*alpha+dst, rb and g are done separately
7766
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
    91
*/
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
INLINE rgbquad_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
blendRGB(rgbquad_t dst, rgbquad_t src, rgbquad_t alpha)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
{
7766
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
    95
    const rgbquad_t a = alpha;
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
    96
    const rgbquad_t a1 = 0xFF - alpha;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
7766
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
    98
    return MAKE_QUAD(
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
    99
        (rgbquad_t)((QUAD_RED(src) * a + QUAD_RED(dst) * a1) / 0xFF),
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
   100
        (rgbquad_t)((QUAD_GREEN(src) * a + QUAD_GREEN(dst) * a1) / 0xFF),
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
   101
        (rgbquad_t)((QUAD_BLUE(src) * a + QUAD_BLUE(dst) * a1) / 0xFF),
42c1e9741ed0 6998323: Unexpected color change after invoking SplashScreen.update()
anthony
parents: 5506
diff changeset
   102
        0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/*      scales rgb quad by alpha. basically similar to what's above. src alpha is retained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        used for premultiplying alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        btw: braindead MSVC6 generates _three_ mul instructions for this function */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
INLINE rgbquad_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
premultiplyRGBA(rgbquad_t src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    rgbquad_t srb = src & 0xFF00FF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    rgbquad_t sg = src & 0xFF00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    rgbquad_t alpha = src >> QUAD_ALPHA_SHIFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    alpha += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    srb *= alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    sg *= alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    srb >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    sg >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    return (src & 0xFF000000) | (srb & 0xFF00FF) | (sg & 0xFF00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
/*      The functions below are inherently ineffective, but the performance seems to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        more or less adequate for the case of splash screens. They can be optimized later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if needed. The idea of optimization is to provide inlineable form of putRGBADither and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        getRGBA at least for certain most frequently used visuals. Something like this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        done in Java 2D ("loops"). This would be possible with C++ templates, but making it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        clean for C would require ugly preprocessor tricks. Leaving it out for later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
/*      convert a single pixel color value from rgbquad according to visual format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        and place it to pointed location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        ordered dithering used when necessary */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
INLINE void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
putRGBADither(rgbquad_t value, void *ptr, ImageFormat * format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        int row, int col)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (format->premultiplied) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        value = premultiplyRGBA(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    if (format->dithers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        value = format->colorIndex[ditherColor(value, format, row, col)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        value = CONVCOMP(value, format, 0) | CONVCOMP(value, format, 1) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            CONVCOMP(value, format, 2) | CONVCOMP(value, format, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    switch (format->byteOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    case BYTE_ORDER_LSBFIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        switch (format->depthBytes) {   /* lack of *break*'s is intentional */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            PUT(byte_t, ptr, value & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            value >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            PUT(byte_t, ptr, value & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            value >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            PUT(byte_t, ptr, value & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            value >>= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            PUT(byte_t, ptr, value & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    case BYTE_ORDER_MSBFIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        switch (format->depthBytes) {   /* lack of *break*'s is intentional */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            PUT(byte_t, ptr, (value >> 24) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            PUT(byte_t, ptr, (value >> 16) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            PUT(byte_t, ptr, (value >> 8) & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            PUT(byte_t, ptr, value & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    case BYTE_ORDER_NATIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        switch (format->depthBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            PUT(rgbquad_t, ptr, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        case 3:                /* not supported, LSB or MSB should always be specified */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            *(int *) 0 = 0;    /* crash */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            PUT(word_t, ptr, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            PUT(byte_t, ptr, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
/* load a single pixel color value and un-convert it to rgbquad according to visual format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
INLINE rgbquad_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
getRGBA(void *ptr, ImageFormat * format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
       FIXME: color is not un-alpha-premultiplied on get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
       this is not required by current code, but it makes the implementation inconsistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
       i.e. put(get) will not work right for alpha-premultiplied images */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /* get the value basing on depth and byte order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    rgbquad_t value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    switch (format->byteOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    case BYTE_ORDER_LSBFIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        switch (format->depthBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            value |= GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            value <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            value |= GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            value <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            value |= GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            value <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            value |= GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    case BYTE_ORDER_MSBFIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        switch (format->depthBytes) {   /* lack of *break*'s is intentional */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            value |= (GET(byte_t, ptr) << 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        case 3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            value |= (GET(byte_t, ptr) << 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            value |= (GET(byte_t, ptr) << 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            INCP(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            value |= GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    case BYTE_ORDER_NATIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        switch (format->depthBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        case 4:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            value = GET(rgbquad_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        case 3:                /* not supported, LSB or MSB should always be specified */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            *(int *) 0 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        case 2:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            value = (rgbquad_t) GET(word_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            value = (rgbquad_t) GET(byte_t, ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /* now un-convert the value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    if (format->colorMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (value == format->transparentColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return format->colorMap[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return UNCONVCOMP(value, format, 0) | UNCONVCOMP(value, format, 1) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            UNCONVCOMP(value, format, 2) | UNCONVCOMP(value, format, 3) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            format->fixedBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
/* fill the line with the specified color according to visual format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
INLINE void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
fillLine(rgbquad_t color, void *pDst, int incDst, int n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        ImageFormat * dstFormat, int row, int col)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    for (i = 0; i < n; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        putRGBADither(color, pDst, dstFormat, row, col++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        INCPN(byte_t, pDst, incDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
/* find the shift for specified mask, also verify the mask is valid */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
INLINE int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
getMaskShift(rgbquad_t mask, int *pShift, int *pnumBits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    int shift = 0, numBits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /* check the mask is not empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (!mask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /* calculate the shift */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    while ((mask & 1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        ++shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        mask >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /* check the mask is contigious */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    if ((mask & (mask + 1)) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /* calculate the number of bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        ++numBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        mask >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    } while ((mask & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    *pShift = shift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    *pnumBits = numBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
#endif