0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include "splashscreen_gfx_impl.h"
0N/A
0N/A/* *INDENT-OFF* */
0N/Aconst byte_t baseDitherMatrix[DITHER_SIZE][DITHER_SIZE] = {
0N/A /* Bayer's order-4 dither array. Generated by the code given in
0N/A * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I.
0N/A */
0N/A { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
0N/A { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
0N/A { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
0N/A { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
0N/A { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
0N/A { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
0N/A { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
0N/A { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
0N/A { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
0N/A { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
0N/A { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
0N/A { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
0N/A { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
0N/A { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
0N/A { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
0N/A { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
0N/A};
0N/A/* *INDENT-ON* */
0N/A
0N/A// FIXME: tinting on some colormaps (e.g. 1-2-1) means something is slightly wrong with
0N/A// colormap calculation... probably it's some rounding error
0N/A
0N/A/* calculates the colorTable for mapping from 0..255 to 0..numColors-1
0N/A also calculates the dithering matrix, scaling baseDitherMatrix accordingly */
0N/Avoid
0N/AinitDither(DitherSettings * pDither, int numColors, int scale)
0N/A{
0N/A int i, j;
0N/A
0N/A pDither->numColors = numColors;
0N/A for (i = 0; i < (MAX_COLOR_VALUE + 1) * 2; i++) {
0N/A pDither->colorTable[i] =
0N/A (((i > MAX_COLOR_VALUE) ? MAX_COLOR_VALUE : i) *
0N/A (numColors - 1) / MAX_COLOR_VALUE) * scale;
0N/A }
0N/A for (i = 0; i < DITHER_SIZE; i++)
0N/A for (j = 0; j < DITHER_SIZE; j++)
0N/A pDither->matrix[i][j] =
0N/A (int) baseDitherMatrix[i][j] / (numColors - 1);
0N/A}
0N/A
0N/A/* scale a number on the range of 0..numColorsIn-1 to 0..numColorsOut-1
0N/A 0 maps to 0 and numColorsIn-1 maps to numColorsOut-1
0N/A intermediate values are spread evenly between 0 and numColorsOut-1 */
0N/AINLINE int
0N/AscaleColor(int color, int numColorsIn, int numColorsOut)
0N/A{
0N/A return (color * (numColorsOut - 1) + (numColorsIn - 1) / 2)
0N/A / (numColorsIn - 1);
0N/A}
0N/A
0N/A/* build a colormap for a color cube and a dithering matrix. color cube is quantized
0N/A according to the provided maximum number of colors */
0N/Aint
0N/AquantizeColors(int maxNumColors, int *numColors)
0N/A{
0N/A
0N/A // static const int scale[3]={10000/11,10000/69,10000/30};
0N/A // FIXME: sort out the adaptive color cube subdivision... realistic 11:69:30 is good on photos,
0N/A // but would be bad on other pictures. A stupid approximation is used now.
0N/A
0N/A static const int scale[3] = { 8, 4, 6 };
0N/A
0N/A // maxNumColors should be at least 2x2x2=8, or we lose some color components completely
0N/A numColors[0] = numColors[1] = numColors[2] = 2;
0N/A
0N/A while (1) {
0N/A int idx[3] = { 0, 1, 2 };
0N/A /* bubble sort the three indexes according to scaled numColors values */
0N/A#define SORT(i,j) \
0N/A if (numColors[idx[i]]*scale[idx[i]]>numColors[idx[j]]*scale[idx[j]]) \
0N/A { int t = idx[i]; idx[i] = idx[j]; idx[j] = t; }
0N/A SORT(0, 1);
0N/A SORT(1, 2);
0N/A SORT(0, 1);
0N/A /* try increasing numColors for the first color */
0N/A if ((numColors[idx[0]] + 1) * numColors[idx[1]] *
0N/A numColors[idx[2]] <= maxNumColors) {
0N/A numColors[idx[0]]++;
0N/A } else if (numColors[idx[0]] * (numColors[idx[1]] + 1) *
0N/A numColors[idx[2]] <= maxNumColors) {
0N/A numColors[idx[1]]++;
0N/A } else if (numColors[idx[0]] * numColors[idx[1]] *
0N/A (numColors[idx[2]] + 1) <= maxNumColors) {
0N/A numColors[idx[2]]++;
0N/A } else {
0N/A break;
0N/A }
0N/A }
0N/A return numColors[0] * numColors[1] * numColors[2];
0N/A}
0N/A
0N/Avoid
0N/AinitColorCube(int *numColors, rgbquad_t * pColorMap, DitherSettings * pDithers,
0N/A rgbquad_t * colorIndex)
0N/A{
0N/A int r, g, b, n;
0N/A
0N/A n = 0;
0N/A for (r = 0; r < numColors[2]; r++) {
0N/A for (g = 0; g < numColors[1]; g++)
0N/A for (b = 0; b < numColors[0]; b++) {
0N/A pColorMap[colorIndex[n++]] =
0N/A scaleColor(b, numColors[0], MAX_COLOR_VALUE) +
0N/A (scaleColor(g, numColors[1], MAX_COLOR_VALUE) << 8) +
0N/A (scaleColor(r, numColors[2], MAX_COLOR_VALUE) << 16);
0N/A }
0N/A }
0N/A initDither(pDithers + 0, numColors[0], 1);
0N/A initDither(pDithers + 1, numColors[1], numColors[0]);
0N/A initDither(pDithers + 2, numColors[2], numColors[1] * numColors[0]);
0N/A}
0N/A
0N/A/*
0N/A the function below is a line conversion loop
0N/A
0N/A incSrc and incDst are pSrc and pDst increment values for the loop, in bytes
0N/A mode defines how the pixels should be processed
0N/A
0N/A mode==CVT_COPY means the pixels should be copied as is
0N/A mode==CVT_ALPHATEST means pixels should be skipped when source pixel alpha is above the threshold
0N/A mode==CVT_BLEND means alpha blending between source and destination should be performed, while
0N/A destination alpha should be retained. source alpha is used for blending.
0N/A*/
0N/Avoid
0N/AconvertLine(void *pSrc, int incSrc, void *pDst, int incDst, int numSamples,
0N/A ImageFormat * srcFormat, ImageFormat * dstFormat, int doAlpha,
0N/A void *pSrc2, int incSrc2, ImageFormat * srcFormat2,
0N/A int row, int col)
0N/A{
0N/A int i;
0N/A
0N/A switch (doAlpha) {
0N/A case CVT_COPY:
0N/A for (i = 0; i < numSamples; ++i) {
0N/A putRGBADither(getRGBA(pSrc, srcFormat), pDst, dstFormat,
0N/A row, col++);
0N/A INCPN(byte_t, pSrc, incSrc);
0N/A INCPN(byte_t, pDst, incDst);
0N/A }
0N/A break;
0N/A case CVT_ALPHATEST:
0N/A for (i = 0; i < numSamples; ++i) {
0N/A rgbquad_t color = getRGBA(pSrc, srcFormat);
0N/A
0N/A if (color >= ALPHA_THRESHOLD) { // test for alpha component >50%. that's an extra branch, and it's bad...
0N/A putRGBADither(color, pDst, dstFormat, row, col++);
0N/A }
0N/A INCPN(byte_t, pSrc, incSrc);
0N/A INCPN(byte_t, pDst, incDst);
0N/A }
0N/A break;
0N/A case CVT_BLEND:
0N/A for (i = 0; i < numSamples; ++i) {
0N/A rgbquad_t src = getRGBA(pSrc, srcFormat);
0N/A rgbquad_t src2 = getRGBA(pSrc2, srcFormat);
0N/A
0N/A putRGBADither(blendRGB(src, src2,
0N/A QUAD_ALPHA(src2)) | (src & QUAD_ALPHA_MASK), pDst, dstFormat,
0N/A row, col++);
0N/A INCPN(byte_t, pSrc, incSrc);
0N/A INCPN(byte_t, pDst, incDst);
0N/A INCPN(byte_t, pSrc2, incSrc2);
0N/A }
0N/A break;
0N/A }
0N/A}
0N/A
0N/A/* initialize ImageRect structure according to function arguments */
0N/Avoid
0N/AinitRect(ImageRect * pRect, int x, int y, int width, int height, int jump,
0N/A int stride, void *pBits, ImageFormat * format)
0N/A{
0N/A int depthBytes = format->depthBytes;
0N/A
0N/A pRect->pBits = pBits;
0N/A INCPN(byte_t, pRect->pBits, y * stride + x * depthBytes);
0N/A pRect->numLines = height;
0N/A pRect->numSamples = width;
0N/A pRect->stride = stride * jump;
0N/A pRect->depthBytes = depthBytes;
0N/A pRect->format = format;
0N/A pRect->row = y;
0N/A pRect->col = x;
0N/A pRect->jump = jump;
0N/A}
0N/A
0N/A/* copy image rectangle from source to destination, or from two sources with blending */
0N/A
0N/Aint
0N/AconvertRect(ImageRect * pSrcRect, ImageRect * pDstRect, int mode)
0N/A{
0N/A return convertRect2(pSrcRect, pDstRect, mode, NULL);
0N/A}
0N/A
0N/Aint
0N/AconvertRect2(ImageRect * pSrcRect, ImageRect * pDstRect, int mode,
0N/A ImageRect * pSrcRect2)
0N/A{
0N/A int numLines = pSrcRect->numLines;
0N/A int numSamples = pSrcRect->numSamples;
0N/A void *pSrc = pSrcRect->pBits;
0N/A void *pDst = pDstRect->pBits;
0N/A void *pSrc2 = NULL;
0N/A int j, row;
0N/A
0N/A if (pDstRect->numLines < numLines)
0N/A numLines = pDstRect->numLines;
0N/A if (pDstRect->numSamples < numSamples) {
0N/A numSamples = pDstRect->numSamples;
0N/A }
0N/A if (pSrcRect2) {
0N/A if (pSrcRect2->numLines < numLines) {
0N/A numLines = pSrcRect2->numLines;
0N/A }
0N/A if (pSrcRect2->numSamples < numSamples) {
0N/A numSamples = pSrcRect2->numSamples;
0N/A }
0N/A pSrc2 = pSrcRect2->pBits;
0N/A }
0N/A row = pDstRect->row;
0N/A for (j = 0; j < numLines; j++) {
0N/A convertLine(pSrc, pSrcRect->depthBytes, pDst, pDstRect->depthBytes,
0N/A numSamples, pSrcRect->format, pDstRect->format, mode,
0N/A pSrc2, pSrcRect2 ? pSrcRect2->depthBytes : 0,
0N/A pSrcRect2 ? pSrcRect2->format : 0, row, pDstRect->col);
0N/A INCPN(byte_t, pSrc, pSrcRect->stride);
0N/A INCPN(byte_t, pDst, pDstRect->stride);
0N/A if (pSrcRect2) {
0N/A INCPN(byte_t, pSrc2, pSrcRect2->stride);
0N/A }
0N/A row += pDstRect->jump;
0N/A }
0N/A return numLines * pSrcRect->stride;
0N/A}
0N/A
0N/Aint
0N/AfillRect(rgbquad_t color, ImageRect * pDstRect)
0N/A{
0N/A int numLines = pDstRect->numLines;
0N/A int numSamples = pDstRect->numSamples;
0N/A void *pDst = pDstRect->pBits;
0N/A int j, row;
0N/A
0N/A row = pDstRect->row;
0N/A for (j = 0; j < numLines; j++) {
0N/A fillLine(color, pDst, pDstRect->depthBytes, numSamples,
0N/A pDstRect->format, row, pDstRect->col);
0N/A INCPN(byte_t, pDst, pDstRect->stride);
0N/A row += pDstRect->jump;
0N/A }
0N/A return numLines * pDstRect->stride;
0N/A}
0N/A
0N/A/* init the masks; all other parameters are initialized to default values */
0N/Avoid
0N/AinitFormat(ImageFormat * format, int redMask, int greenMask, int blueMask,
0N/A int alphaMask)
0N/A{
0N/A int i, shift, numBits;
0N/A
0N/A format->byteOrder = BYTE_ORDER_NATIVE;
0N/A format->colorMap = NULL;
0N/A format->depthBytes = 4;
0N/A format->fixedBits = 0;
0N/A format->premultiplied = 0;
0N/A format->mask[0] = blueMask;
0N/A format->mask[1] = greenMask;
0N/A format->mask[2] = redMask;
0N/A format->mask[3] = alphaMask;
0N/A for (i = 0; i < 4; i++) {
0N/A getMaskShift(format->mask[i], &shift, &numBits);
0N/A format->shift[i] = shift + numBits - i * 8 - 8;
0N/A }
0N/A}
0N/A
0N/A/* dump the visual format */
0N/Avoid
0N/AdumpFormat(ImageFormat * format)
0N/A{
0N/A#ifdef _DEBUG
0N/A int i;
0N/A
0N/A printf("byteorder=%d colormap=%08x depthBytes=%d fixedBits=%08x transparentColor=%u ",
0N/A format->byteOrder, (unsigned) format->colorMap, format->depthBytes,
0N/A (unsigned) format->fixedBits, (unsigned) format->transparentColor);
0N/A for (i = 0; i < 4; i++) {
0N/A printf("mask[%d]=%08x shift[%d]=%d\n", i, (unsigned) format->mask[i], i,
0N/A format->shift[i]);
0N/A }
0N/A printf("\n");
0N/A#endif
0N/A}
0N/A
0N/A/* optimize the format */
0N/Avoid
0N/AoptimizeFormat(ImageFormat * format)
0N/A{
0N/A if (platformByteOrder() == format->byteOrder && format->depthBytes != 3) {
0N/A format->byteOrder = BYTE_ORDER_NATIVE;
0N/A }
0N/A /* FIXME: some advanced optimizations are possible, especially for format pairs */
0N/A}
0N/A
0N/Aint
0N/AplatformByteOrder()
0N/A{
0N/A int test = 1;
0N/A
0N/A *(char *) &test = 0;
0N/A return test ? BYTE_ORDER_MSBFIRST : BYTE_ORDER_LSBFIRST;
0N/A}