< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1996, 2000, 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 /* Iterative color palette generation */
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <string.h>
  30 #include <math.h>
  31 #ifdef TIMES
  32 #include <time.h>
  33 #endif /* TIMES */
  34 
  35 #ifndef MAKECUBE_EXE
  36 #include "jvm.h"
  37 #include "jni_util.h"
  38 
  39 extern JavaVM *jvm;
  40 #endif

  41 
  42 #define jio_fprintf fprintf
  43 
  44 #define TRUE 1
  45 #define FALSE 0
  46 static float monitor_gamma[3] = {2.6f, 2.6f, 2.4f}; /* r,g,b */
  47 static float mat[3][3] = {
  48     {0.3811f, 0.2073f, 0.0213f},
  49     {0.3203f, 0.6805f, 0.1430f},
  50     {0.2483f, 0.1122f, 1.2417f}
  51 };
  52 static float whiteXYZ[3] = { 0.9497f, 1.0000f, 1.4060f };
  53 #define whitex (0.9497f / (0.9497f + 1.0000f + 1.4060f))
  54 #define whitey (1.0000f / (0.9497f + 1.0000f + 1.4060f))
  55 static float uwht = 4*whitex/(-2*whitex + 12*whitey + 3);
  56 static float vwht = 9*whitey/(-2*whitex + 12*whitey + 3);
  57 
  58 static float Rmat[3][256];
  59 static float Gmat[3][256];
  60 static float Bmat[3][256];


 498                 if (!pCmap) {
 499                     continue;
 500                 }
 501 
 502                 find_nearest(pCmap);
 503 
 504                 dE = pCmap->dE;
 505                 if (dE < dEthresh) {
 506                     offenders[j] = 0;
 507                 } else {
 508                     if (offenders[i+1] == 0 || dE > offenders[i+1]->dE) {
 509                         offenders[j] = offenders[i+1];
 510                         offenders[i+1] = pCmap;
 511                     }
 512                 }
 513             }
 514         }
 515     }
 516 }
 517 
 518 void
 519 img_makePalette(int cmapsize, int tablesize, int lookupsize,
 520                 float lscale, float weight,
 521                 int prevclrs, int doMac,
 522                 unsigned char *reds,
 523                 unsigned char *greens,
 524                 unsigned char *blues,
 525                 unsigned char *lookup)
 526 {
 527     CmapEntry *pCmap;
 528     int i, ix;
 529 #ifdef STATS
 530     double ave_dL, ave_dE;
 531     double max_dL, max_dE;
 532 #endif /* STATS */
 533 #ifdef TIMES
 534     clock_t start, mid, tbl, end;
 535 
 536     start = clock();
 537 #endif /* TIMES */
 538 


   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 /* Iterative color palette generation */
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <string.h>
  30 #include <math.h>
  31 #ifdef TIMES
  32 #include <time.h>
  33 #endif /* TIMES */
  34 
  35 #ifndef MAKECUBE_EXE
  36 #include "jvm.h"
  37 #include "jni_util.h"
  38 
  39 extern JavaVM *jvm;
  40 #endif
  41 #include "img_colors.h"
  42 
  43 #define jio_fprintf fprintf
  44 
  45 #define TRUE 1
  46 #define FALSE 0
  47 static float monitor_gamma[3] = {2.6f, 2.6f, 2.4f}; /* r,g,b */
  48 static float mat[3][3] = {
  49     {0.3811f, 0.2073f, 0.0213f},
  50     {0.3203f, 0.6805f, 0.1430f},
  51     {0.2483f, 0.1122f, 1.2417f}
  52 };
  53 static float whiteXYZ[3] = { 0.9497f, 1.0000f, 1.4060f };
  54 #define whitex (0.9497f / (0.9497f + 1.0000f + 1.4060f))
  55 #define whitey (1.0000f / (0.9497f + 1.0000f + 1.4060f))
  56 static float uwht = 4*whitex/(-2*whitex + 12*whitey + 3);
  57 static float vwht = 9*whitey/(-2*whitex + 12*whitey + 3);
  58 
  59 static float Rmat[3][256];
  60 static float Gmat[3][256];
  61 static float Bmat[3][256];


 499                 if (!pCmap) {
 500                     continue;
 501                 }
 502 
 503                 find_nearest(pCmap);
 504 
 505                 dE = pCmap->dE;
 506                 if (dE < dEthresh) {
 507                     offenders[j] = 0;
 508                 } else {
 509                     if (offenders[i+1] == 0 || dE > offenders[i+1]->dE) {
 510                         offenders[j] = offenders[i+1];
 511                         offenders[i+1] = pCmap;
 512                     }
 513                 }
 514             }
 515         }
 516     }
 517 }
 518 
 519 JNIEXPORT void JNICALL
 520 img_makePalette(int cmapsize, int tablesize, int lookupsize,
 521                 float lscale, float weight,
 522                 int prevclrs, int doMac,
 523                 unsigned char *reds,
 524                 unsigned char *greens,
 525                 unsigned char *blues,
 526                 unsigned char *lookup)
 527 {
 528     CmapEntry *pCmap;
 529     int i, ix;
 530 #ifdef STATS
 531     double ave_dL, ave_dE;
 532     double max_dL, max_dE;
 533 #endif /* STATS */
 534 #ifdef TIMES
 535     clock_t start, mid, tbl, end;
 536 
 537     start = clock();
 538 #endif /* TIMES */
 539 


< prev index next >