< prev index next >

src/java.desktop/share/native/libawt/awt/image/cvutils/img_globals.c

Print this page


   1 /*
   2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * This file implements some of the standard utility procedures used
  28  * by the image conversion package.
  29  */
  30 

  31 #include "img_globals.h"
  32 
  33 #include "java_awt_image_IndexColorModel.h"
  34 #include "java_awt_Transparency.h"
  35 
  36 /*
  37  * This function constructs an 8x8 ordered dither array which can be
  38  * used to dither data into an output range with discreet values that
  39  * differ by the value specified as quantum.  A monochrome screen would
  40  * use a dither array constructed with the quantum 256.
  41  * The array values produced are unsigned and intended to be used with
  42  * a lookup table which returns the next color darker than the error
  43  * adjusted color used as the index.
  44  */
  45 void
  46 make_uns_ordered_dither_array(uns_ordered_dither_array oda,
  47                               int quantum)
  48 {
  49     int i, j, k;
  50 
  51     oda[0][0] = 0;
  52     for (k = 1; k < 8; k *= 2) {
  53         for (i = 0; i < k; i++) {
  54             for (j = 0; j < k; j++) {
  55                 oda[ i ][ j ] = oda[i][j] * 4;
  56                 oda[i+k][j+k] = oda[i][j] + 1;
  57                 oda[ i ][j+k] = oda[i][j] + 2;
  58                 oda[i+k][ j ] = oda[i][j] + 3;
  59             }
  60         }
  61     }
  62     for (i = 0; i < 8; i++) {
  63         for (j = 0; j < 8; j++) {
  64             oda[i][j] = oda[i][j] * quantum / 64;
  65         }


   1 /*
   2  * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * This file implements some of the standard utility procedures used
  28  * by the image conversion package.
  29  */
  30 
  31 #include "jni.h"
  32 #include "img_globals.h"
  33 
  34 #include "java_awt_image_IndexColorModel.h"
  35 #include "java_awt_Transparency.h"
  36 
  37 /*
  38  * This function constructs an 8x8 ordered dither array which can be
  39  * used to dither data into an output range with discreet values that
  40  * differ by the value specified as quantum.  A monochrome screen would
  41  * use a dither array constructed with the quantum 256.
  42  * The array values produced are unsigned and intended to be used with
  43  * a lookup table which returns the next color darker than the error
  44  * adjusted color used as the index.
  45  */
  46 JNIEXPORT void JNICALL
  47 make_uns_ordered_dither_array(uns_ordered_dither_array oda,
  48                               int quantum)
  49 {
  50     int i, j, k;
  51 
  52     oda[0][0] = 0;
  53     for (k = 1; k < 8; k *= 2) {
  54         for (i = 0; i < k; i++) {
  55             for (j = 0; j < k; j++) {
  56                 oda[ i ][ j ] = oda[i][j] * 4;
  57                 oda[i+k][j+k] = oda[i][j] + 1;
  58                 oda[ i ][j+k] = oda[i][j] + 2;
  59                 oda[i+k][ j ] = oda[i][j] + 3;
  60             }
  61         }
  62     }
  63     for (i = 0; i < 8; i++) {
  64         for (j = 0; j < 8; j++) {
  65             oda[i][j] = oda[i][j] * quantum / 64;
  66         }


< prev index next >