src/java.desktop/share/native/libawt/awt/image/cvutils/img_globals.c
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 26751 jdk/src/java.desktop/share/native/libawt/awt/image/cvutils/img_globals.c@70bac69b37c9
child 49440 396ea30afbd5
child 56106 40e61db323c2
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 13165
diff changeset
     2
 * Copyright (c) 1996, 2012, 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 implements some of the standard utility procedures used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * by the image conversion package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "img_globals.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "java_awt_image_IndexColorModel.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "java_awt_Transparency.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This function constructs an 8x8 ordered dither array which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * used to dither data into an output range with discreet values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * differ by the value specified as quantum.  A monochrome screen would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * use a dither array constructed with the quantum 256.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The array values produced are unsigned and intended to be used with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a lookup table which returns the next color darker than the error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * adjusted color used as the index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
make_uns_ordered_dither_array(uns_ordered_dither_array oda,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                              int quantum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    int i, j, k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    oda[0][0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    for (k = 1; k < 8; k *= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        for (i = 0; i < k; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            for (j = 0; j < k; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                oda[ i ][ j ] = oda[i][j] * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                oda[i+k][j+k] = oda[i][j] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                oda[ i ][j+k] = oda[i][j] + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                oda[i+k][ j ] = oda[i][j] + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    for (i = 0; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        for (j = 0; j < 8; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            oda[i][j] = oda[i][j] * quantum / 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * This function constructs an 8x8 ordered dither array which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * used to dither data into an output range with discreet values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * are distributed over the range from minerr to maxerr around a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * target color value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * The array values produced are signed and intended to be used with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * a lookup table which returns the closest color to the error adjusted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * color used as an index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
make_sgn_ordered_dither_array(char* oda, int minerr, int maxerr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    int i, j, k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    oda[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    for (k = 1; k < 8; k *= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        for (i = 0; i < k; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            for (j = 0; j < k; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                oda[(i<<3) + j] = oda[(i<<3)+j] * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                oda[((i+k)<<3) + j+k] = oda[(i<<3)+j] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                oda[(i<<3) + j+k] = oda[(i<<3)+j] + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                oda[((i+k)<<3) + j] = oda[(i<<3)+j] + 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    for (i = 0; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        for (j = 0; j < 8; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            oda[k] = oda[k] * (maxerr - minerr) / 64 + minerr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            k++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#ifdef TESTING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/* Function to test the ordered dither error matrix initialization function. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
main(int argc, char **argv)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    int quantum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int max, val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    uns_ordered_dither_array oda;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    if (argc > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        quantum = atoi(argv[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        quantum = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    make_uns_ordered_dither_array(oda, quantum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    for (i = 0; i < 8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        for (j = 0; j < 8; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            val = oda[i][j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            printf("%4d", val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (max < val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                max = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    printf("\nmax = %d\n", max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#endif /* TESTING */