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 provides some global definitions needed by the image
  28  * conversion package.
  29  */
  30 
  31 #ifndef IMAGE_GLOBALS_H
  32 #define IMAGE_GLOBALS_H
  33 
  34 #include "jni.h"
  35 
  36 /* Image Conversion function return codes. */
  37 #define SCALEFAILURE    -1
  38 #define SCALENOOP       0
  39 #define SCALESUCCESS    1
  40 
  41 /*
  42  * The constants needed to choose from among the many variants of image
  43  * conversion functions that can be constructed with the standard header
  44  * files.  The types of input for the image conversion functions are
  45  * broken down into 5 different attributes each with 2 to 4 different
  46  * variants:
  47  *
  48  *      SCALING:        SCALED or UNSCALED
  49  *      INPUT SIZE:     BYTEIN (8-bit) or INTIN (32-bit)
  50  *      ALPHA:          OPAQUE or ALPHA
  51  *      ORDER:          TDLR or RANDOM
  52  *      COLORMODEL:     ICM, DCM, DCM8 (8-bits for each component) or ANY
  53  *
  54  * For each attribute, a mask is defined with the "BITS" suffix which
  55  * identifies which bits contain the variation information for that
  56  * particular attribute.  The input information should be analyzed and
  57  * characterized for each of the above categories and the appropriate
  58  * bit constants OR'd together to produce a unique constant that
  59  * identifies which conversion function is needed.  The reason that
  60  * attributes of the output space are not indicated in the masks is
  61  * that typically only a single output device type needs to be supported
  62  * at a time and so a vector of the functions specific to the necessary
  63  * output device can be constructed at AWT initialization time and then
  64  * indexed into with the constant identifier that characterizes the
  65  * input data, which is only known and constantly varies at run-time.
  66  */
  67 #define IMGCV_UNSCALED          (0 << 0)
  68 #define IMGCV_SCALED            (1 << 0)
  69 #define IMGCV_SCALEBITS         (1 << 0)
  70 #define IMGCV_BYTEIN            (0 << 1)
  71 #define IMGCV_INTIN             (1 << 1)
  72 #define IMGCV_INSIZEBITS        (1 << 1)
  73 #define IMGCV_OPAQUE            (0 << 2)
  74 #define IMGCV_ALPHA             (1 << 2)
  75 #define IMGCV_ALPHABITS         (1 << 2)
  76 #define IMGCV_TDLRORDER         (0 << 3)
  77 #define IMGCV_RANDORDER         (1 << 3)
  78 #define IMGCV_ORDERBITS         (1 << 3)
  79 #define IMGCV_ICM               (0 << 4)
  80 #define IMGCV_DCM               (1 << 4)
  81 #define IMGCV_DCM8              (2 << 4)
  82 #define IMGCV_ANYCM             (3 << 4)
  83 #define IMGCV_CMBITS            (3 << 4)
  84 
  85 #define NUM_IMGCV               (1 << 6)        /* total # of IMGCV variants */
  86 
  87 /*
  88  * The structure which holds the image conversion data.
  89  */
  90 typedef struct {
  91     void *outbuf;
  92     void *maskbuf;
  93     void *fserrors;
  94 } ImgConvertData;
  95 
  96 /*
  97  * The standard structure which holds information about the pixels
  98  * used in the output device.
  99  */
 100 typedef struct {
 101     int grayscale;
 102     int bitsperpixel;
 103     int rOff;
 104     int gOff;
 105     int bOff;
 106     int rScale;
 107     int gScale;
 108     int bScale;
 109 } ImgColorData;
 110 
 111 /*
 112  * The private data member attached to a ColorModel which caches
 113  * the information needed to characterize and use a ColorModel
 114  * object on the fly.
 115  */
 116 typedef struct {
 117     int type;
 118     struct methodblock *mb;
 119 } ImgCMData;
 120 
 121 /*
 122  * The standard signature of all of the image conversion functions
 123  * that can be produced with this package of include files.
 124  */
 125 
 126 /*
 127  * FIXME!
 128  */
 129 typedef int ImgConvertFcn(void *colormodel,
 130                           int srcOX, int srcOY, int srcW, int srcH,
 131                           void *srcpix, int srcOff, int srcBPP, int srcScan,
 132                           int srcTotalWidth, int srcTotalHeight,
 133                           int dstTotalWidth, int dstTotalHeight,
 134                           ImgConvertData *cvdata, ImgColorData *clrdata);
 135 
 136 /*
 137  * The type of the error matrix used in the ordered dithering code.
 138  */
 139 typedef unsigned char uns_ordered_dither_array[8][8];
 140 typedef char sgn_ordered_dither_array[8][8];
 141 
 142 /*
 143  * The function provided for constructing the ordered dithering error
 144  * matrices based on a given quantum (i.e. the amplitude of the maximum
 145  * error values appearing in the matrix which should be the same as the
 146  * distance between adjacent allocated component values in the color cube).
 147  */
 148 JNIEXPORT void JNICALL
 149 make_uns_ordered_dither_array(uns_ordered_dither_array oda,
 150                               int quantum);
 151 extern void make_sgn_ordered_dither_array(char* oda, int errmin, int errmax);
 152 
 153 /*
 154  * The function provided for calculating the contents of the ImgCMData
 155  * structure which can be attached to ColorModels to simplify the
 156  * work of characterizing their data.
 157  */
 158 extern ImgCMData *img_getCMData(void *cmh);
 159 
 160 #endif /* IMAGE_GLOBALS_H */