Path: blob/master/src/java.desktop/share/native/libawt/awt/image/dither.h
41159 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdio.h>26#include <stdlib.h>27#include <math.h>28#include <string.h>2930#include "colordata.h"31#include "jni.h"3233#ifdef __cplusplus34extern "C" {35#endif3637JNIEXPORT extern sgn_ordered_dither_array std_img_oda_red;38JNIEXPORT extern sgn_ordered_dither_array std_img_oda_green;39JNIEXPORT extern sgn_ordered_dither_array std_img_oda_blue;40JNIEXPORT extern int std_odas_computed;4142JNIEXPORT void JNICALL43make_dither_arrays(int cmapsize, ColorData *cData);4445JNIEXPORT void JNICALL46initInverseGrayLut(int* prgb, int rgbsize, ColorData* cData);4748/*49* state info needed for breadth-first recursion of color cube from50* initial palette entries within the cube51*/5253typedef struct {54unsigned int depth;55unsigned int maxDepth;5657unsigned char *usedFlags;58unsigned int activeEntries;59unsigned short *rgb;60unsigned char *indices;61unsigned char *iLUT;62} CubeStateInfo;6364#define INSERTNEW(state, rgb, index) do { \65if (!state.usedFlags[rgb]) { \66state.usedFlags[rgb] = 1; \67state.iLUT[rgb] = index; \68state.rgb[state.activeEntries] = rgb; \69state.indices[state.activeEntries] = index; \70state.activeEntries++; \71} \72} while (0);737475#define ACTIVATE(code, mask, delta, state, index) do { \76if (((rgb & mask) + delta) <= mask) { \77rgb += delta; \78INSERTNEW(state, rgb, index); \79rgb -= delta; \80} \81if ((rgb & mask) >= delta) { \82rgb -= delta; \83INSERTNEW(state, rgb, index); \84rgb += delta; \85} \86} while (0);8788#ifdef __cplusplus89} /* extern "C" */90#endif919293