< prev index next >

src/java.desktop/share/native/libawt/awt/image/dither.c

Print this page


   1 /*
   2  * Copyright (c) 2001, 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 #include "dither.h"
  27 
  28 sgn_ordered_dither_array std_img_oda_red;
  29 sgn_ordered_dither_array std_img_oda_green;
  30 sgn_ordered_dither_array std_img_oda_blue;
  31 int std_odas_computed = 0;
  32 
  33 void initInverseGrayLut(int* prgb, int rgbsize, ColorData *cData) {

  34     int *inverse;
  35     int lastindex, lastgray, missing, i;
  36 
  37     if (!cData) {
  38         return;
  39     }
  40 
  41     inverse = calloc(256, sizeof(int));
  42     if (!inverse) {
  43         return;
  44     }
  45     cData->pGrayInverseLutData = inverse;
  46 
  47     for (i = 0; i < 256; i++) {
  48         inverse[i] = -1;
  49     }
  50 
  51     /* First, fill the gray values */
  52     for (i = 0; i < rgbsize; i++) {
  53         int r, g, b, rgb = prgb[i];


 250 }
 251 
 252 void
 253 initDitherTables(ColorData* cData) {
 254 
 255 
 256     if(std_odas_computed) {
 257         cData->img_oda_red   = &(std_img_oda_red[0][0]);
 258         cData->img_oda_green = &(std_img_oda_green[0][0]);
 259         cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
 260     } else {
 261         cData->img_oda_red   = &(std_img_oda_red[0][0]);
 262         cData->img_oda_green = &(std_img_oda_green[0][0]);
 263         cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
 264         make_dither_arrays(256, cData);
 265         std_odas_computed = 1;
 266     }
 267 
 268 }
 269 
 270 void make_dither_arrays(int cmapsize, ColorData *cData) {

 271     int i, j, k;
 272 
 273     /*
 274      * Initialize the per-component ordered dithering arrays
 275      * Choose a size based on how far between elements in the
 276      * virtual cube.  Assume the cube has cuberoot(cmapsize)
 277      * elements per axis and those elements are distributed
 278      * over 256 colors.
 279      * The calculation should really divide by (#comp/axis - 1)
 280      * since the first and last elements are at the extremes of
 281      * the 256 levels, but in a practical sense this formula
 282      * produces a smaller error array which results in smoother
 283      * images that have slightly less color fidelity but much
 284      * less dithering noise, especially for grayscale images.
 285      */
 286     i = (int) (256 / pow(cmapsize, 1.0/3.0));
 287     make_sgn_ordered_dither_array(cData->img_oda_red, -i / 2, i / 2);
 288     make_sgn_ordered_dither_array(cData->img_oda_green, -i / 2, i / 2);
 289     make_sgn_ordered_dither_array(cData->img_oda_blue, -i / 2, i / 2);
 290 
   1 /*
   2  * Copyright (c) 2001, 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 #include "jni.h"
  27 #include "dither.h"
  28 
  29 JNIEXPORT sgn_ordered_dither_array std_img_oda_red;
  30 JNIEXPORT sgn_ordered_dither_array std_img_oda_green;
  31 JNIEXPORT sgn_ordered_dither_array std_img_oda_blue;
  32 JNIEXPORT int std_odas_computed = 0;
  33 
  34 JNIEXPORT void JNICALL
  35 initInverseGrayLut(int* prgb, int rgbsize, ColorData *cData) {
  36     int *inverse;
  37     int lastindex, lastgray, missing, i;
  38 
  39     if (!cData) {
  40         return;
  41     }
  42 
  43     inverse = calloc(256, sizeof(int));
  44     if (!inverse) {
  45         return;
  46     }
  47     cData->pGrayInverseLutData = inverse;
  48 
  49     for (i = 0; i < 256; i++) {
  50         inverse[i] = -1;
  51     }
  52 
  53     /* First, fill the gray values */
  54     for (i = 0; i < rgbsize; i++) {
  55         int r, g, b, rgb = prgb[i];


 252 }
 253 
 254 void
 255 initDitherTables(ColorData* cData) {
 256 
 257 
 258     if(std_odas_computed) {
 259         cData->img_oda_red   = &(std_img_oda_red[0][0]);
 260         cData->img_oda_green = &(std_img_oda_green[0][0]);
 261         cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
 262     } else {
 263         cData->img_oda_red   = &(std_img_oda_red[0][0]);
 264         cData->img_oda_green = &(std_img_oda_green[0][0]);
 265         cData->img_oda_blue  = &(std_img_oda_blue[0][0]);
 266         make_dither_arrays(256, cData);
 267         std_odas_computed = 1;
 268     }
 269 
 270 }
 271 
 272 JNIEXPORT void JNICALL
 273 make_dither_arrays(int cmapsize, ColorData *cData) {
 274     int i, j, k;
 275 
 276     /*
 277      * Initialize the per-component ordered dithering arrays
 278      * Choose a size based on how far between elements in the
 279      * virtual cube.  Assume the cube has cuberoot(cmapsize)
 280      * elements per axis and those elements are distributed
 281      * over 256 colors.
 282      * The calculation should really divide by (#comp/axis - 1)
 283      * since the first and last elements are at the extremes of
 284      * the 256 levels, but in a practical sense this formula
 285      * produces a smaller error array which results in smoother
 286      * images that have slightly less color fidelity but much
 287      * less dithering noise, especially for grayscale images.
 288      */
 289     i = (int) (256 / pow(cmapsize, 1.0/3.0));
 290     make_sgn_ordered_dither_array(cData->img_oda_red, -i / 2, i / 2);
 291     make_sgn_ordered_dither_array(cData->img_oda_green, -i / 2, i / 2);
 292     make_sgn_ordered_dither_array(cData->img_oda_blue, -i / 2, i / 2);
 293 
< prev index next >