1 /* 2 * Copyright (c) 1997, 2006, 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 #ifndef AWT_PARSE_IMAGE_H 27 #define AWT_PARSE_IMAGE_H 28 29 #include <jni.h> 30 #include <jni_util.h> 31 32 /*************************************************************************** 33 * Definitions * 34 ***************************************************************************/ 35 36 #ifndef TRUE 37 #define TRUE (1) 38 #endif 39 40 #ifndef FALSE 41 #define FALSE (0) 42 #endif 43 44 typedef enum { 45 IMG_SUCCESS=0, 46 IMG_FAILURE=-1 47 } ImgStatus_t; 48 49 #define UNKNOWN_DATA_TYPE 0 50 #define BYTE_DATA_TYPE 1 51 #define SHORT_DATA_TYPE 2 52 #define INT_DATA_TYPE 3 53 54 #define UNKNOWN_RASTER_TYPE 0 55 #define COMPONENT_RASTER_TYPE 1 56 #define BANDED_RASTER_TYPE 2 57 #define PACKED_RASTER_TYPE 3 58 59 #define UNKNOWN_CM_TYPE 0 60 #define COMPONENT_CM_TYPE 1 61 #define DIRECT_CM_TYPE 2 62 #define INDEX_CM_TYPE 3 63 #define PACKED_CM_TYPE 4 64 65 /* Packing types */ 66 #define UNKNOWN_PACKING 0 67 #define BYTE_COMPONENTS 0x1 68 #define SHORT_COMPONENTS 0x2 69 #define PACKED_INT 0x3 70 #define PACKED_SHORT 0x4 71 #define PACKED_BYTE 0x5 72 73 /* Interleaving */ 74 #define INTERLEAVED 0x10 75 #define BANDED 0x20 76 #define SINGLE_BAND 0x30 77 #define PACKED_BAND 0x40 78 79 #define BYTE_INTERLEAVED (BYTE_COMPONENTS | INTERLEAVED) 80 #define SHORT_INTERLEAVED (SHORT_COMPONENTS | INTERLEAVED) 81 #define BYTE_SINGLE_BAND (BYTE_COMPONENTS | SINGLE_BAND) 82 #define BYTE_PACKED_BAND (BYTE_COMPONENTS | PACKED_BAND) 83 #define SHORT_SINGLE_BAND (SHORT_COMPONENTS | SINGLE_BAND) 84 #define BYTE_BANDED (BYTE_COMPONENTS | BANDED) 85 #define SHORT_BANDED (SHORT_COMPONENTS | BANDED) 86 #define PACKED_BYTE_INTER (PACKED_BYTE | INTERLEAVED) 87 #define PACKED_SHORT_INTER (PACKED_SHORT | INTERLEAVED) 88 #define PACKED_INT_INTER (PACKED_INT | INTERLEAVED) 89 90 #define MAX_NUMBANDS 32 91 92 /* Struct that holds information about a SinglePixelPackedModel object */ 93 typedef struct { 94 jint maskArray[MAX_NUMBANDS]; 95 jint offsets[MAX_NUMBANDS]; 96 jint nBits[MAX_NUMBANDS]; 97 jint maxBitSize; 98 } SPPSampleModelS_t; 99 100 /* Struct that holds information for the Raster object */ 101 typedef struct { 102 jobject jraster; /* The raster object */ 103 jobject jdata; /* Data storage object */ 104 jobject jsampleModel; /* The sample model */ 105 SPPSampleModelS_t sppsm; /* SinglePixelPackedSampleModel mask/offsets */ 106 107 jint *chanOffsets; /* Array of channel offsets (or bit offsets) */ 108 109 int width; /* Width of the raster */ 110 int height; /* Height of the raster */ 111 int minX; /* origin of this raster x */ 112 int minY; /* origin of this raster x */ 113 114 int baseOriginX; /* origin of base raster */ 115 int baseOriginY; /* origin of base raster x */ 116 int baseRasterWidth; /* size of baseRaster */ 117 int baseRasterHeight; /* size of baseRaster */ 118 int numDataElements; /* Number of data bands in raster */ 119 int numBands; /* Number of bands in the raster */ 120 int scanlineStride; /* Scanline Stride */ 121 int pixelStride; /* Pixel stride (or pixel bit stride) */ 122 int dataIsShared; /* If TRUE, data is shared */ 123 int rasterType; /* Type of raster */ 124 int dataType; /* Data type of the raster data */ 125 int dataSize; /* Number of bytes per data element */ 126 int type; /* Raster type */ 127 } RasterS_t; 128 129 130 /* Struct that holds information about the ColorModel object */ 131 typedef struct { 132 jobject jrgb; /* For ICM, rgb lut object */ 133 jobject jcmodel; 134 jobject jcspace; 135 jint *nBits; /* Number of bits per component */ 136 137 int cmType; /* Type of color model */ 138 int isDefaultCM; /* If TRUE, it is the default color model */ 139 int isDefaultCompatCM; /* If TRUE, it is compatible with the default CM */ 140 /* Might be 4 byte and band order different */ 141 int is_sRGB; /* If TRUE, the color space is sRGB */ 142 int numComponents; /* Total number of components */ 143 int supportsAlpha; /* If it supports alpha */ 144 int isAlphaPre; /* If TRUE, alpha is premultiplied */ 145 int csType; /* Type of ColorSpace */ 146 int transparency; 147 int maxNbits; 148 int transIdx; /* For ICM, transparent pixel */ 149 int mapSize; /* For ICM, size of the lut */ 150 } ColorModelS_t; 151 152 typedef struct { 153 int *colorOrder; 154 155 int channelOffset; 156 int dataOffset; /* # bytes into the data array */ 157 int sStride; 158 int pStride; 159 int packing; 160 int numChans; 161 int alphaIndex; /* -1 if no alpha */ 162 int needToExpand; /* If true, the pixels are packed */ 163 int expandToNbits; /* If needToExpand, how many bits to allocate */ 164 } HintS_t; 165 166 /* Struct that holds information for the BufferedImage object */ 167 typedef struct { 168 jobject jimage; /* The BufferedImage object */ 169 RasterS_t raster; /* The raster structure */ 170 ColorModelS_t cmodel; /* The color model structure */ 171 HintS_t hints; /* Hint structure */ 172 int imageType; /* Type of image */ 173 } BufImageS_t; 174 175 /*************************************************************************** 176 * Function Prototypes * 177 ***************************************************************************/ 178 int awt_parseImage(JNIEnv *env, jobject jimage, BufImageS_t **imagePP, 179 int handleCustom); 180 181 int awt_parseRaster(JNIEnv *env, jobject jraster, RasterS_t *rasterP); 182 183 int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType, 184 ColorModelS_t *cmP); 185 186 void awt_freeParsedRaster(RasterS_t *rasterP, int freeRasterP); 187 188 void awt_freeParsedImage(BufImageS_t *imageP, int freeImageP); 189 190 int awt_getPixelByte(JNIEnv *env, int band, RasterS_t *rasterP, 191 unsigned char *bufferP); 192 int awt_setPixelByte(JNIEnv *env, int band, RasterS_t *rasterP, 193 unsigned char *bufferP); 194 int awt_getPixelShort(JNIEnv *env, int band, RasterS_t *rasterP, 195 unsigned short *bufferP); 196 int awt_setPixelShort(JNIEnv *env, int band, RasterS_t *rasterP, 197 unsigned short *bufferP); 198 199 #endif /* AWT_PARSE_IMAGE_H */