src/java.desktop/share/native/libsplashscreen/splashscreen_gfx_impl.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
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) 2005, 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
#include "splashscreen_gfx_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/* *INDENT-OFF* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
const byte_t baseDitherMatrix[DITHER_SIZE][DITHER_SIZE] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  /* Bayer's order-4 dither array.  Generated by the code given in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
   * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  {   0,192, 48,240, 12,204, 60,252,  3,195, 51,243, 15,207, 63,255 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  {  32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  {   8,200, 56,248,  4,196, 52,244, 11,203, 59,251,  7,199, 55,247 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  {  40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  {   2,194, 50,242, 14,206, 62,254,  1,193, 49,241, 13,205, 61,253 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  {  34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  {  10,202, 58,250,  6,198, 54,246,  9,201, 57,249,  5,197, 53,245 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  {  42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/* *INDENT-ON* */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
// FIXME: tinting on some colormaps (e.g. 1-2-1) means something is slightly wrong with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
// colormap calculation... probably it's some rounding error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/*  calculates the colorTable for mapping from 0..255 to 0..numColors-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    also calculates the dithering matrix, scaling baseDitherMatrix accordingly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
initDither(DitherSettings * pDither, int numColors, int scale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    pDither->numColors = numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    for (i = 0; i < (MAX_COLOR_VALUE + 1) * 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        pDither->colorTable[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            (((i > MAX_COLOR_VALUE) ? MAX_COLOR_VALUE : i) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
             (numColors - 1) / MAX_COLOR_VALUE) * scale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    for (i = 0; i < DITHER_SIZE; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        for (j = 0; j < DITHER_SIZE; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            pDither->matrix[i][j] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                (int) baseDitherMatrix[i][j] / (numColors - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* scale a number on the range of 0..numColorsIn-1 to 0..numColorsOut-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 0 maps to 0 and numColorsIn-1 maps to numColorsOut-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 intermediate values are spread evenly between 0 and numColorsOut-1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
INLINE int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
scaleColor(int color, int numColorsIn, int numColorsOut)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    return (color * (numColorsOut - 1) + (numColorsIn - 1) / 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        / (numColorsIn - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
/*  build a colormap for a color cube and a dithering matrix. color cube is quantized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    according to the provided maximum number of colors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
quantizeColors(int maxNumColors, int *numColors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // static const int scale[3]={10000/11,10000/69,10000/30};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // FIXME: sort out the adaptive color cube subdivision... realistic 11:69:30 is good on photos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // but would be bad on other pictures. A stupid approximation is used now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static const int scale[3] = { 8, 4, 6 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // maxNumColors should be at least 2x2x2=8, or we lose some color components completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    numColors[0] = numColors[1] = numColors[2] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    while (1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int idx[3] = { 0, 1, 2 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        /* bubble sort the three indexes according to scaled numColors values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define SORT(i,j) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (numColors[idx[i]]*scale[idx[i]]>numColors[idx[j]]*scale[idx[j]]) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            { int t = idx[i]; idx[i] = idx[j]; idx[j] = t; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        SORT(0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        SORT(1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        SORT(0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        /* try increasing numColors for the first color */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if ((numColors[idx[0]] + 1) * numColors[idx[1]] *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            numColors[idx[2]] <= maxNumColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                numColors[idx[0]]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else if (numColors[idx[0]] * (numColors[idx[1]] + 1) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            numColors[idx[2]] <= maxNumColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            numColors[idx[1]]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        } else if (numColors[idx[0]] * numColors[idx[1]] *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            (numColors[idx[2]] + 1) <= maxNumColors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            numColors[idx[2]]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    return numColors[0] * numColors[1] * numColors[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
initColorCube(int *numColors, rgbquad_t * pColorMap, DitherSettings * pDithers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
              rgbquad_t * colorIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    int r, g, b, n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    for (r = 0; r < numColors[2]; r++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        for (g = 0; g < numColors[1]; g++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            for (b = 0; b < numColors[0]; b++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                pColorMap[colorIndex[n++]] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    scaleColor(b, numColors[0], MAX_COLOR_VALUE) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    (scaleColor(g, numColors[1], MAX_COLOR_VALUE) << 8) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    (scaleColor(r, numColors[2], MAX_COLOR_VALUE) << 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    initDither(pDithers + 0, numColors[0], 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    initDither(pDithers + 1, numColors[1], numColors[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    initDither(pDithers + 2, numColors[2], numColors[1] * numColors[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    the function below is a line conversion loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    incSrc and incDst are pSrc and pDst increment values for the loop, in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    mode defines how the pixels should be processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    mode==CVT_COPY means the pixels should be copied as is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    mode==CVT_ALPHATEST means pixels should be skipped when source pixel alpha is above the threshold
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    mode==CVT_BLEND means alpha blending between source and destination should be performed, while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    destination alpha should be retained. source alpha is used for blending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
convertLine(void *pSrc, int incSrc, void *pDst, int incDst, int numSamples,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            ImageFormat * srcFormat, ImageFormat * dstFormat, int doAlpha,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            void *pSrc2, int incSrc2, ImageFormat * srcFormat2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            int row, int col)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    switch (doAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    case CVT_COPY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        for (i = 0; i < numSamples; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            putRGBADither(getRGBA(pSrc, srcFormat), pDst, dstFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                row, col++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            INCPN(byte_t, pSrc, incSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            INCPN(byte_t, pDst, incDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    case CVT_ALPHATEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        for (i = 0; i < numSamples; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            rgbquad_t color = getRGBA(pSrc, srcFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (color >= ALPHA_THRESHOLD) {     // test for alpha component >50%. that's an extra branch, and it's bad...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                putRGBADither(color, pDst, dstFormat, row, col++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            INCPN(byte_t, pSrc, incSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            INCPN(byte_t, pDst, incDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    case CVT_BLEND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        for (i = 0; i < numSamples; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            rgbquad_t src = getRGBA(pSrc, srcFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            rgbquad_t src2 = getRGBA(pSrc2, srcFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            putRGBADither(blendRGB(src, src2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                QUAD_ALPHA(src2)) | (src & QUAD_ALPHA_MASK), pDst, dstFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                row, col++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            INCPN(byte_t, pSrc, incSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            INCPN(byte_t, pDst, incDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            INCPN(byte_t, pSrc2, incSrc2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
/* initialize ImageRect structure according to function arguments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
initRect(ImageRect * pRect, int x, int y, int width, int height, int jump,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         int stride, void *pBits, ImageFormat * format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    int depthBytes = format->depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    pRect->pBits = pBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    INCPN(byte_t, pRect->pBits, y * stride + x * depthBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    pRect->numLines = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    pRect->numSamples = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    pRect->stride = stride * jump;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    pRect->depthBytes = depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    pRect->format = format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    pRect->row = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    pRect->col = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    pRect->jump = jump;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
/*  copy image rectangle from source to destination, or from two sources with blending */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
convertRect(ImageRect * pSrcRect, ImageRect * pDstRect, int mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    return convertRect2(pSrcRect, pDstRect, mode, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
convertRect2(ImageRect * pSrcRect, ImageRect * pDstRect, int mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             ImageRect * pSrcRect2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    int numLines = pSrcRect->numLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    int numSamples = pSrcRect->numSamples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    void *pSrc = pSrcRect->pBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    void *pDst = pDstRect->pBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    void *pSrc2 = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    int j, row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    if (pDstRect->numLines < numLines)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        numLines = pDstRect->numLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    if (pDstRect->numSamples < numSamples) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        numSamples = pDstRect->numSamples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if (pSrcRect2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (pSrcRect2->numLines < numLines) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            numLines = pSrcRect2->numLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (pSrcRect2->numSamples < numSamples) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            numSamples = pSrcRect2->numSamples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        pSrc2 = pSrcRect2->pBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    row = pDstRect->row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    for (j = 0; j < numLines; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        convertLine(pSrc, pSrcRect->depthBytes, pDst, pDstRect->depthBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            numSamples, pSrcRect->format, pDstRect->format, mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            pSrc2, pSrcRect2 ? pSrcRect2->depthBytes : 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            pSrcRect2 ? pSrcRect2->format : 0, row, pDstRect->col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        INCPN(byte_t, pSrc, pSrcRect->stride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        INCPN(byte_t, pDst, pDstRect->stride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (pSrcRect2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            INCPN(byte_t, pSrc2, pSrcRect2->stride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        row += pDstRect->jump;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    return numLines * pSrcRect->stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
fillRect(rgbquad_t color, ImageRect * pDstRect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    int numLines = pDstRect->numLines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    int numSamples = pDstRect->numSamples;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    void *pDst = pDstRect->pBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    int j, row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    row = pDstRect->row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    for (j = 0; j < numLines; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        fillLine(color, pDst, pDstRect->depthBytes, numSamples,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            pDstRect->format, row, pDstRect->col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        INCPN(byte_t, pDst, pDstRect->stride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        row += pDstRect->jump;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    return numLines * pDstRect->stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
/* init the masks; all other parameters are initialized to default values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
initFormat(ImageFormat * format, int redMask, int greenMask, int blueMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
           int alphaMask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    int i, shift, numBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    format->byteOrder = BYTE_ORDER_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    format->colorMap = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    format->depthBytes = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    format->fixedBits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    format->premultiplied = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    format->mask[0] = blueMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    format->mask[1] = greenMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    format->mask[2] = redMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    format->mask[3] = alphaMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    for (i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        getMaskShift(format->mask[i], &shift, &numBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        format->shift[i] = shift + numBits - i * 8 - 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
/* dump the visual format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
dumpFormat(ImageFormat * format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
#ifdef _DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    printf("byteorder=%d colormap=%08x depthBytes=%d fixedBits=%08x transparentColor=%u ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        format->byteOrder, (unsigned) format->colorMap, format->depthBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        (unsigned) format->fixedBits, (unsigned) format->transparentColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    for (i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        printf("mask[%d]=%08x shift[%d]=%d\n", i, (unsigned) format->mask[i], i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            format->shift[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/* optimize the format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
optimizeFormat(ImageFormat * format)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    if (platformByteOrder() == format->byteOrder && format->depthBytes != 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        format->byteOrder = BYTE_ORDER_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /* FIXME: some advanced optimizations are possible, especially for format pairs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
int
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   338
platformByteOrder(void)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    int test = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    *(char *) &test = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    return test ? BYTE_ORDER_MSBFIRST : BYTE_ORDER_LSBFIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}