1/* 2 * Copyright (c) 1997, 2013, 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 44typedef 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 */ 93typedef struct { 94 jint maskArray[MAX_NUMBANDS]; 95 jint offsets[MAX_NUMBANDS]; 96 jint nBits[MAX_NUMBANDS]; 97 jint maxBitSize; 98 jint isUsed; // flag to indicate whether the raster sample model is SPPSM 99} SPPSampleModelS_t; 100 101/* Struct that holds information for the Raster object */ 102typedef struct { 103 jobject jraster; /* The raster object */ 104 jobject jdata; /* Data storage object */ 105 jobject jsampleModel; /* The sample model */ 106 SPPSampleModelS_t sppsm; /* SinglePixelPackedSampleModel mask/offsets */ 107 108 jint *chanOffsets; /* Array of channel offsets (or bit offsets) */ 109 110 int width; /* Width of the raster */ 111 int height; /* Height of the raster */ 112 int minX; /* origin of this raster x */ 113 int minY; /* origin of this raster x */ 114 115 int baseOriginX; /* origin of base raster */ 116 int baseOriginY; /* origin of base raster x */ 117 int baseRasterWidth; /* size of baseRaster */ 118 int baseRasterHeight; /* size of baseRaster */ 119 int numDataElements; /* Number of data bands in raster */ 120 int numBands; /* Number of bands in the raster */ 121 int scanlineStride; /* Scanline Stride */ 122 int pixelStride; /* Pixel stride (or pixel bit stride) */ 123 int dataIsShared; /* If TRUE, data is shared */ 124 int rasterType; /* Type of raster */ 125 int dataType; /* Data type of the raster data */ 126 int dataSize; /* Number of bytes per data element */ 127 int type; /* Raster type */ 128} RasterS_t; 129 130 131/* Struct that holds information about the ColorModel object */ 132typedef struct { 133 jobject jrgb; /* For ICM, rgb lut object */ 134 jobject jcmodel; 135 jobject jcspace; 136 jint *nBits; /* Number of bits per component */ 137 138 int cmType; /* Type of color model */ 139 int isDefaultCM; /* If TRUE, it is the default color model */ 140 int isDefaultCompatCM; /* If TRUE, it is compatible with the default CM */ 141 /* Might be 4 byte and band order different */ 142 int is_sRGB; /* If TRUE, the color space is sRGB */ 143 int numComponents; /* Total number of components */ 144 int supportsAlpha; /* If it supports alpha */ 145 int isAlphaPre; /* If TRUE, alpha is premultiplied */ 146 int csType; /* Type of ColorSpace */ 147 int transparency; 148 int maxNbits; 149 int transIdx; /* For ICM, transparent pixel */ 150 int mapSize; /* For ICM, size of the lut */ 151} ColorModelS_t; 152 153typedef struct { 154 int *colorOrder; 155 156 int channelOffset; 157 int dataOffset; /* # bytes into the data array */ 158 int sStride; 159 int pStride; 160 int packing; 161 int numChans; 162 int alphaIndex; /* -1 if no alpha */ 163 int needToExpand; /* If true, the pixels are packed */ 164 int expandToNbits; /* If needToExpand, how many bits to allocate */ 165} HintS_t; 166 167/* Struct that holds information for the BufferedImage object */ 168typedef struct { 169 jobject jimage; /* The BufferedImage object */ 170 RasterS_t raster; /* The raster structure */ 171 ColorModelS_t cmodel; /* The color model structure */ 172 HintS_t hints; /* Hint structure */ 173 int imageType; /* Type of image */ 174} BufImageS_t; 175 176/*************************************************************************** 177 * Function Prototypes * 178 ***************************************************************************/ 179int awt_parseImage(JNIEnv *env, jobject jimage, BufImageS_t **imagePP, 180 int handleCustom); 181 182int awt_parseRaster(JNIEnv *env, jobject jraster, RasterS_t *rasterP); 183 184int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType, 185 ColorModelS_t *cmP); 186 187void awt_freeParsedRaster(RasterS_t *rasterP, int freeRasterP); 188 189void awt_freeParsedImage(BufImageS_t *imageP, int freeImageP); 190 191int awt_getPixels(JNIEnv *env, RasterS_t *rasterP, void *bufferP); 192 193int awt_setPixels(JNIEnv *env, RasterS_t *rasterP, void *bufferP); 194 195#endif /* AWT_PARSE_IMAGE_H */ 196