/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sun_awt_image_ImagingLib.h"
#include "java_awt_Transparency.h"
#include "java_awt_image_AffineTransformOp.h"
#include "java_awt_image_BufferedImage.h"
#include "java_awt_color_ColorSpace.h"
#include "java_awt_image_ConvolveOp.h"
#include "sun_awt_image_IntegerComponentRaster.h"
#include "awt_ImagingLib.h"
#include "awt_parseImage.h"
#include "imageInitIDs.h"
#include <jni.h>
#include <jni_util.h>
#include <assert.h>
#include "awt_Mlib.h"
#include "gdefs.h"
#include "safe_alloc.h"
#include "safe_math.h"
/***************************************************************************
* Definitions *
***************************************************************************/
#ifndef TRUE
#endif /* TRUE */
#ifndef FALSE
#define FALSE 0
#endif /* FALSE */
/* (alpha*color)>>nbits + alpha>>(nbits-1) */
/* ((color - (alpha>>(nBits-1)))<<nBits)/alpha */
/* Enumeration of all of the mlib functions used */
typedef enum {
} mlibTypeE_t;
typedef struct {
int needToCopy;
int addAlpha;
} mlibHintS_t;
/***************************************************************************
* Static Variables/Structures *
***************************************************************************/
NULL, // placeholder for j2d_mlib_ImageCreate
NULL, // placeholder for j2d_mlib_ImageCreateStruct
NULL, // placeholder for j2d_mlib_ImageDelete
};
{NULL, "j2d_mlib_ImageConvMxN"},
{NULL, "j2d_mlib_ImageAffine"},
{NULL, "j2d_mlib_ImageLookUp"},
{NULL, "j2d_mlib_ImageConvKernelConvert"},
};
static int s_timeIt = 0;
static int s_printIt = 0;
static int s_startOff = 0;
static int s_nomlib = 0;
/***************************************************************************
* Static Function Prototypes *
***************************************************************************/
static int
int cvtToDefault, int addAlpha);
static int
static void
void *dstdataP);
static void
void *dstdataP);
static int
static int
static int
static int
static int
unsigned char *outDataP);
unsigned char *outDataP);
unsigned char *outDataP);
int forceAlpha);
int forceAlpha);
int forceAlpha);
unsigned char *outDataP);
unsigned char *outDataP);
unsigned char *outDataP);
int supportsAlpha);
int supportsAlpha);
int supportsAlpha);
/***************************************************************************
* Debugging Definitions *
***************************************************************************/
#ifdef DEBUG
static void
switch(status) {
case MLIB_FAILURE:
break;
case MLIB_NULLPOINTER:
break;
case MLIB_OUTOFRANGE:
break;
default:
break;
}
}
#else /* ! DEBUG */
# define printMedialibError(x)
#endif /* ! DEBUG */
static int
switch (edgeHint) {
return MLIB_EDGE_DST_COPY_SRC;
default:
return MLIB_EDGE_DST_FILL_ZERO;
}
}
/***************************************************************************
* External Functions *
***************************************************************************/
{
int i, scale;
int klen;
float kmax;
float *kern;
int kwidth;
int kheight;
int w, h;
int x, y;
int nbands;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
/* out of memory exception already thrown */
return 0;
}
if ((kwidth&0x1) == 0) {
/* Kernel has even width */
w = kwidth+1;
}
else {
w = kwidth;
}
if ((kheight&0x1) == 0) {
/* Kernel has even height */
h = kheight+1;
}
else {
h = kheight;
}
if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_d64))) {
}
return 0;
}
/* Need to flip and find max value of the kernel.
* Also, save the kernel values as mlib_d64 values.
* The flip is to operate correctly with medialib,
* which doesn't do the mathemetically correct thing,
* i.e. it doesn't rotate the kernel by 180 degrees.
* REMIND: This should perhaps be done at the Java
* level by ConvolveOp.
* REMIND: Should the max test be looking at absolute
* values?
* REMIND: What if klen != kheight * kwidth?
*/
i = klen-1;
for (y=0; y < kheight; y++) {
for (x=0; x < kwidth; x++, i--) {
}
}
}
/* We can only handle 16 bit max */
return 0;
}
/* Parse the source image */
/* Can't handle any custom images */
return 0;
}
/* Parse the destination image */
/* Can't handle any custom images */
return 0;
}
if (nbands < 1) {
/* Can't handle any custom images */
return 0;
}
/* Allocate the arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_s32))) {
}
return 0;
}
return 0;
}
if (s_printIt) {
for (y=kheight-1; y >= 0; y--) {
for (x=kwidth-1; x >= 0; x--) {
}
}
for (y=kheight-1; y >= 0; y--) {
for (x=kwidth-1; x >= 0; x--) {
}
}
}
if (status != MLIB_SUCCESS) {
retStatus = 0;
}
if (s_printIt) {
unsigned int *dP;
if (s_startOff != 0) {
}
}
else {
}
printf("src is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
else {
}
printf("dst is \n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
/* Means that we couldn't write directly into the destination buffer */
/* Need to store it back into the array */
/* Error */
retStatus = 0;
}
}
/* Release the pinned memory */
return retStatus;
}
{
int i, scale;
int klen;
float kmax;
void *sdata;
void *ddata;
int kwidth;
int kheight;
int w, h;
int x, y;
float *kern;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
/* out of memory exception already thrown */
return 0;
}
if ((kwidth&0x1) == 0) {
/* Kernel has even width */
w = kwidth+1;
}
else {
w = kwidth;
}
if ((kheight&0x1) == 0) {
/* Kernel has even height */
h = kheight+1;
}
else {
h = kheight;
}
if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_d64))) {
}
return 0;
}
/* Need to flip and find max value of the kernel.
* Also, save the kernel values as mlib_d64 values.
* The flip is to operate correctly with medialib,
* which doesn't do the mathemetically correct thing,
* i.e. it doesn't rotate the kernel by 180 degrees.
* REMIND: This should perhaps be done at the Java
* level by ConvolveOp.
* REMIND: Should the max test be looking at absolute
* values?
* REMIND: What if klen != kheight * kwidth?
*/
i = klen-1;
for (y=0; y < kheight; y++) {
for (x=0; x < kwidth; x++, i--) {
}
}
}
/* We can only handle 16 bit max */
return 0;
}
/* Parse the source image */
return -1;
}
return -1;
}
/* Parse the source raster */
/* Can't handle any custom rasters */
return 0;
}
/* Parse the destination raster */
/* Can't handle any custom images */
return 0;
}
/* Allocate the arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
if (SAFE_TO_ALLOC_3(w, h, sizeof(mlib_s32))) {
}
return 0;
}
return 0;
}
if (s_printIt) {
for (y=kheight-1; y >= 0; y--) {
for (x=kwidth-1; x >= 0; x--) {
}
}
for (y=kheight-1; y >= 0; y--) {
for (x=kwidth-1; x >= 0; x--) {
}
}
}
if (status != MLIB_SUCCESS) {
retStatus = 0;
}
if (s_printIt) {
unsigned int *dP;
if (s_startOff != 0) {
}
}
else {
}
printf("src is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
else {
}
printf("dst is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
/* Means that we couldn't write directly into the destination buffer */
unsigned char *bdataP;
unsigned short *sdataP;
/* Punt for now */
switch (dstRasterP->dataType) {
case BYTE_DATA_TYPE:
break;
case SHORT_DATA_TYPE:
break;
default:
retStatus = 0;
}
}
/* Release the pinned memory */
return retStatus;
}
{
int i;
double *matrix;
void *sdata;
void *ddata;
unsigned int *dP;
int useIndexed;
int nbands;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
if (s_timeIt) {
(*start_timer)(3600);
}
switch(interpType) {
break;
break;
break;
default:
return -1;
}
/*
* Very unlikely, however we should check for this:
* if given matrix array is too short, we can't handle it
*/
return 0;
}
/* out of memory error already thrown */
return 0;
}
if (s_printIt) {
}
/* Parse the source image */
/* Can't handle any custom images */
return 0;
}
/* Parse the destination image */
/* Can't handle any custom images */
return 0;
}
/* REMIND!! Can't assume that it is the same LUT!! */
/* Fix 4213160, 4184283 */
if (nbands < 1) {
/* Can't handle any custom images */
return 0;
}
/* Allocate the arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
#if 0
#endif
/* Need to clear the destination to the transparent pixel */
}
/* Perform the transformation */
{
return 0;
}
if (s_printIt) {
}
else {
}
printf("src is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
else {
}
printf("dst is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
/* Means that we couldn't write directly into the destination buffer */
/* Need to store it back into the array */
/* Error */
retStatus = 0;
}
}
else {
/* Release the pinned memory */
}
return retStatus;
}
{
int i;
double *matrix;
void *sdata;
void *ddata;
unsigned int *dP;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
if (s_timeIt) {
(*start_timer)(3600);
}
switch(interpType) {
break;
break;
break;
default:
return -1;
}
return -1;
}
return -1;
}
/*
* Very unlikely, however we should check for this:
* if given matrix array is too short, we can't handle it.
*/
return 0;
}
/* out of memory error already thrown */
return 0;
}
if (s_printIt) {
}
/* Parse the source raster */
/* Can't handle any custom rasters */
return 0;
}
/* Parse the destination raster */
/* Can't handle any custom images */
return 0;
}
/* Allocate the arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
#if 0
#endif
{
}
/* Perform the transformation */
{
/* REMIND: Free the regions */
return 0;
}
if (s_printIt) {
}
else {
}
printf("src is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
else {
}
printf("dst is\n");
for (i=0; i < 20; i++) {
}
printf("\n");
}
/* Means that we couldn't write directly into the destination buffer */
unsigned char *bdataP;
unsigned short *sdataP;
/* Need to store it back into the array */
/* Punt for now */
case MLIB_BYTE:
break;
case MLIB_SHORT:
break;
default:
retStatus = 0;
}
}
}
/* Release the pinned memory */
return retStatus;
}
typedef struct {
unsigned char *table;
#ifdef _LITTLE_ENDIAN
#else
#endif
{
int x, y;
return 0;
}
#ifdef SIMPLE_LOOKUP_LOOP
unsigned short s = *srcPixel++;
/* we can not handle source image using
* byte lookup table. Fall back to processing
* images in java
*/
return 0;
}
}
#else
/* Get to 32 bit-aligned point */
unsigned short s = *srcPixel++;
return 0;
}
npix--;
}
/*
* Do NLUT pixels per loop iteration.
* Pack into ints and write out 2 at a time.
*/
for(x=nloop; x!=0; x--) {
int i = 0;
for (i = 0; i < NLUT; i++) {
return 0;
}
}
dstP[0] = (int)
dstP[1] = (int)
}
/*
* Complete any remaining pixels
*/
for(x=nx; x!=0; x--) {
unsigned short s = *srcPixel++;
return 0;
}
}
#endif
}
return 1;
}
{
unsigned char **tbl;
int i;
int lut_nbands;
int nbands;
int ncomponents;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
/* Parse the source image */
/* Can't handle any custom images */
return 0;
}
/* Parse the destination image */
/* Can't handle any custom images */
return 0;
}
/* Can't handle any custom images */
return 0;
}
? 4
/* Make sure that color order can be used for
* re-ordering of lookup arrays.
*/
for (i = 0; i < nbands; i++) {
return 0;
}
}
if (lut_nbands > ncomponents) {
}
if (SAFE_TO_ALLOC_2(ncomponents, sizeof(unsigned char *))) {
tbl = (unsigned char **)
}
}
return 0;
}
/* Need to grab these pointers before we lock down arrays */
for (i=0; i < lut_nbands; i++) {
/* we may read outside the table during lookup */
}
}
return 0;
}
}
/* Allocate the arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
/* Set up a straight lut so we don't mess around with alpha */
/*
* NB: medialib lookup routine expects lookup array for each
* component of source image including alpha.
* If lookup table we got form the java layer does not contain
* sufficient number of lookup arrays we add references to identity
* lookup array to make medialib happier.
*/
if (lut_nbands < ncomponents) {
int j;
/* REMIND: This should be the size of the input lut!! */
for (j=0; j < 256; j++) {
lut[j] = j;
}
for (j=0; j < ncomponents; j++) {
}
}
for (i=0; i < lut_nbands; i++) {
/* Free what we've got so far. */
int j;
for (j = 0; j < i; j++) {
}
return 0;
}
}
if (lut_nbands == 1) {
for (i=1; i < nbands -
}
}
/* Mlib needs 16bit lookuptable and must be signed! */
if (nbands > 1) {
retStatus = 0;
}
else {
}
}
/* How about ddata == null? */
}
(void **)tbl) != MLIB_SUCCESS)) {
retStatus = 0;
}
/*
* Means that we couldn't write directly into
* the destination buffer
*/
/* Need to store it back into the array */
/* Error */
retStatus = 0;
}
}
/* Release the LUT */
for (i=0; i < lut_nbands; i++) {
}
/* Release the pinned memory */
return retStatus;
}
{
void* sdata;
void* ddata;
int i;
int jlen;
int lut_nbands;
int src_nbands;
int dst_nbands;
/* This function requires a lot of local refs ??? Is 64 enough ??? */
return 0;
if (s_nomlib) return 0;
return -1;
}
return -1;
}
/* Parse the source raster - reject custom images */
return 0;
}
/* Parse the destination image - reject custom images */
return 0;
}
lut_nbands = jlen;
/* adjust number of lookup bands */
if (lut_nbands > src_nbands) {
}
/* MediaLib can't do more than 4 bands */
src_nbands != dst_nbands ||
{
// we should free parsed rasters here
return 0;
}
/* Allocate the raster arrays */
/* Must be some problem */
return 0;
}
/* Must be some problem */
return 0;
}
/*
* Well, until now we have analyzed number of bands in
* src and dst rasters.
* However, it is not enough because medialib lookup routine uses
* number of channels of medialib image. Note that in certain
* case number of channels may differs form the number of bands.
* Good example is raster that is used in TYPE_INT_RGB buffered
* image: it has 3 bands, but their medialib representation has
* 4 channels.
*
* In order to avoid the lookup routine failure, we need:
*
* 1. verify that src and dst have same number of channels.
* 2. provide lookup array for every channel. If we have "extra"
* channel (like the raster described above) then we need to
* provide identical lookup array.
*/
return 0;
}
for (i = 0; i < 256; i++) {
ilut[i] = i;
}
}
/* Get references to the lookup table arrays */
/* Need to grab these pointers before we lock down arrays */
for (i=0; i < lut_nbands; i++) {
/* we may read outside the table during lookup */
}
}
{
return 0;
}
}
for (i=0; i < lut_nbands; i++) {
/* Free what we've got so far. */
int j;
for (j = 0; j < i; j++) {
}
return 0;
}
}
/*
* Medialib routine expects lookup array for each band of raster.
* Setup the rest of lookup arrays if supplied lookup table
* contains single lookup array.
*/
for (i = lut_nbands; i < src_nbands; i++) {
}
/*
* Setup lookup array for "extra" channels
*/
mlib_lookupTable[i] = ilut;
}
/* Mlib needs 16bit lookuptable and must be signed! */
if (lut_nbands > 1) {
retStatus = 0;
} else {
}
}
/* How about ddata == null? */
(void **)mlib_lookupTable) != MLIB_SUCCESS)) {
retStatus = 0;
}
/*
* Means that we couldn't write directly into
* the destination buffer
*/
unsigned char* bdataP;
unsigned short* sdataP;
switch (dstRasterP->dataType) {
case BYTE_DATA_TYPE:
break;
case SHORT_DATA_TYPE:
break;
default:
retStatus = 0;
}
}
/* Release the LUT */
for (i=0; i < lut_nbands; i++) {
}
/* Release the pinned memory */
return retStatus;
}
char *start;
if (getenv("IMLIB_DEBUG")) {
if (start_timer && stop_timer) {
s_timeIt = 1;
}
}
if (getenv("IMLIB_PRINT")) {
s_printIt = 1;
}
}
if (getenv ("IMLIB_NOMLIB")) {
s_nomlib = 1;
return JNI_FALSE;
}
/* This function is platform-dependent and is in awt_mlib.c */
{
s_nomlib = 1;
return JNI_FALSE;
}
return JNI_TRUE;
}
/* REMIND: How to specify border? */
int width;
int height;
/* Useful for convolution? */
#ifdef WORKING
int xOff;
int yOff;
int baseWidth;
int baseHeight;
int baseXoff;
int baseYoff;
/* Not the same object so get the width and height */
/* Can use edge */
width++;
}
/* Can use edge */
height++;
}
}
#endif
}
static int
{
int nbands = 0;
int ncomponents;
/* Are the color spaces the same? */
/* If the src is GRAY and dst RGB, we can handle it */
/* Nope, need to handle that in java for now */
return -1;
}
else {
}
}
else {
}
else {
/* Need to initialize this */
}
}
ncomponents--; /* ?? */
/* Not really, more like shrink src to get rid of alpha */
}
if (expandICM) {
if (dstCMP->isDefaultCompatCM) {
}
else if (dstCMP->isDefaultCompatCM) {
}
}
else {
nbands = 1;
}
}
else {
}
else {
nbands = 1;
}
/* Look at the packing */
/* Can use src directly */
}
else {
/* Must be packed or custom */
}
}
}
if (hintP->cvtSrcToDefault) {
/* By definition */
}
/* Not necessarily */
}
else {
}
}
else {
/* Special case where we need to fill in alpha values */
int i;
}
for (i=0; i < srcCMP->numComponents; i++) {
if (!srcCMP->isDefaultCM) {
}
if (!dstCMP->isDefaultCM) {
}
break;
}
}
}
{
/* We've already handled the index case. This is for the rest of the cases */
}
if (srcImageType == dstImageType) {
/* Same image type so use it */
}
else if (srcImageType == TYPE_INT_RGB &&
(dstImageType == TYPE_INT_ARGB ||
dstImageType == TYPE_INT_ARGB_PRE)) {
}
else if (srcImageType == TYPE_INT_BGR &&
(dstImageType == TYPE_4BYTE_ABGR ||
dstImageType == TYPE_4BYTE_ABGR_PRE)) {
}
/* Now what? */
/* Check color order */
/* Check if just need to scale the data */
}
else {
/* Don't know what it is so convert it */
}
}
return nbands;
}
static int
case BYTE_DATA_TYPE:
/* Must have been an error */
return -1;
}
break;
case SHORT_DATA_TYPE:
/* Must have been an error */
return -1;
}
break;
case INT_DATA_TYPE:
/* Must have been an error */
return -1;
}
break;
default:
/* REMIND: Return some sort of error */
return -1;
}
}
else {
/* REMIND: Return some sort of error */
return -1;
}
return 0;
}
static int
unsigned char *dataP) {
int y;
/* it is safe to calculate the scan length, because width has been verified
* on creation of the mlib image
*/
int nbytes = 0;
return -1;
}
/* getData, one scanline at a time */
}
g_BImgGetRGBMID, 0, y,
return -1;
}
}
return 0;
}
static int
unsigned char *dataP) {
int y;
return -1;
}
}
/* JNI error */
return -1;
}
/* setData, one scanline at a time */
/* Fix 4223648, 4184283 */
return -1;
}
}
/* Need to release the array */
return 0;
}
static int
int cvtToDefault, int addAlpha) {
void *dataP;
unsigned char *cDataP;
int width;
int height;
/* Useful for convolution? */
/* This code is zero'ed out so that it cannot be called */
/* To do this correctly, we need to expand src and dst in the */
/* in that direction. Expanding right and down is easy - */
/* increment width. Expanding top and left requires bumping */
#if 0
if (0 && useEdges) {
/* Can use edge */
width++;
}
/* Can use edge */
height++;
}
/* Can use edge */
width++;
/* NEED TO BUMP POINTER BACK A PIXELSTRIDE */
}
/* Can use edge */
height++;
/* NEED TO BUMP POINTER BACK A SCANLINE */
}
}
#endif
if (cvtToDefault) {
int status = 0;
if (*mlibImagePP == NULL) {
return -1;
}
/* Make sure the image is cleared.
* NB: the image dimension is already verified, so we can
* safely calculate the length of the buffer.
*/
if (!isSrc) {
return 0;
}
case INDEX_CM_TYPE:
/* REMIND: Need to rearrange according to dst cm */
/* Fix 4213160, 4184283 */
}
else {
}
case DIRECT_CM_TYPE:
case BYTE_DATA_TYPE:
case SHORT_DATA_TYPE:
case INT_DATA_TYPE:
}
} /* switch(imageP->cmodel.cmType) */
}
/* Interleaved with shared data */
NULL);
return -1;
}
/* Means we need to fill in alpha */
if (!cvtToDefault && addAlpha) {
if (*mlibImagePP != NULL) {
unsigned int *dstP = (unsigned int *)
unsigned int *srcP = (unsigned int *)
int x, y;
for (x=0; x < width; x++) {
}
}
}
return 0;
}
/* Easy case. It is or is similar to the default CM so use
* the array. Must be byte data.
*/
/* Create the medialib image */
(unsigned char *)dataP
+ hintP->dataOffset);
}
(unsigned short *)dataP
+ hintP->channelOffset);
}
else {
/* Release the data array */
return -1;
}
return 0;
}
static int
void *dataP;
unsigned char *cDataP;
unsigned short *sdataP;
int width;
int height;
int dataSize;
int offset;
/* REMIND: Fix this */
return -1;
}
/* Useful for convolution? */
/* This code is zero'ed out so that it cannot be called */
/* To do this correctly, we need to expand src and dst in the */
/* in that direction. Expanding right and down is easy - */
/* increment width. Expanding top and left requires bumping */
#if 0
if (0 && useEdges) {
/* Can use edge */
width++;
}
/* Can use edge */
height++;
}
/* Can use edge */
width++;
/* NEED TO BUMP POINTER BACK A PIXELSTRIDE */
}
/* Can use edge */
height++;
/* NEED TO BUMP POINTER BACK A SCANLINE */
}
}
#endif
{
return -1;
}
{
// raster data buffer is too short
return -1;
}
NULL);
return -1;
}
return 0;
{
return -1;
}
{
// raster data buffer is too short
return -1;
}
NULL);
return -1;
}
return 0;
{
return -1;
}
{
// raster data buffer is too short
return -1;
}
NULL);
return -1;
}
return 0;
if (*mlibImagePP == NULL) {
return -1;
}
if (!isSrc) return 0;
if (*mlibImagePP == NULL) {
return -1;
}
if (!isSrc) return 0;
}
break;
if (*mlibImagePP == NULL) {
return -1;
}
if (!isSrc) return 0;
}
break;
}
/* Just expand it right now */
case BYTE_DATA_TYPE:
return -1;
}
if (isSrc) {
return -1;
}
}
break;
case SHORT_DATA_TYPE:
return -1;
}
if (isSrc) {
return -1;
}
}
break;
default:
return -1;
}
return 0;
}
static void
void *dstdataP) {
}
static void
void *dstdataP)
{
/* Free the medialib image */
if (srcmlibImP) {
}
/* Release the array */
if (srcdataP) {
}
/* Free the medialib image */
if (dstmlibImP) {
}
/* Release the array */
if (dstdataP) {
dstdataP, 0);
}
}
static int
/* Nothing to do since it is the same image type */
/* REMIND: Should check the ICM LUTS to see if it is the same */
return 0;
}
/* These types are compatible with TYPE_INT_RGB */
return 0;
}
if (hintP->cvtSrcToDefault &&
{
return 0;
}
return 0;
}
}
else {
/* REMIND: */
}
}
/* Just need to move bits */
}
}
}
return 0;
}
do { \
int offset = (start_offset); \
int lastScanOffset; \
\
{ \
return ERR_BAD_IMAGE_LAYOUT; \
} \
\
return ERR_BAD_IMAGE_LAYOUT; \
} \
lastScanOffset += offset; \
\
return ERR_BAD_IMAGE_LAYOUT; \
} \
\
return ERR_BAD_IMAGE_LAYOUT; \
} \
lastScanOffset += offset; \
\
if (dataArrayLength < lastScanOffset) { \
return ERR_BAD_IMAGE_LAYOUT; \
} \
} while(0); \
static int
mlib_image *mlibImP) {
int mStride;
int y;
/* REMIND: Store mlib data type? */
/* Check if it is an IndexColorModel */
}
else {
/* Packed or some other custom raster */
}
}
/* Write it back to the destination */
{
}
}
/* Write it back to the destination */
{
}
}
/* Just need to move bits */
}
}
}
}
else {
}
return 0;
}
static int
mlib_image *mlibImP) {
unsigned char *cDataP;
}
break;
}
}
return -1;
}
static int
{
int *argb;
int x, y;
unsigned char *sP;
/* REMIND: Only works for RGB */
return -1;
}
{
aIdx = 0;
rIdx = 1;
gIdx = 2;
bIdx = 3;
}
{
aIdx = 0;
rIdx = 3;
gIdx = 2;
bIdx = 1;
}
rIdx = 2;
gIdx = 1;
bIdx = 0;
aIdx = 0; /* Ignored */
}
rIdx = 0;
gIdx = 1;
bIdx = 2;
}
else {
return -1;
}
/* Lock down the destination raster */
return -1;
}
return -1;
}
}
}
return -1;
}
{
int *rgb;
int status = 0;
unsigned int *mP;
int x, y;
/* Need to grab the lookup tables. Right now only bytes */
/* Interleaved with shared data */
/* Release the lookup tables */
if (rgb) {
}
if (dataP) {
}
return -1;
}
for (y=0; y < height; y++) {
}
}
}
for (y=0; y < height; y++) {
}
}
}
else {
/* Unknown type */
status = -1;
}
/* Release the lookup table data */
/* Release the data array */
return status;
}
/* This routine is expecting a ByteComponentRaster with a PackedColorModel */
unsigned char *outDataP)
{
int x, y, c;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Convert the all bands */
/* Need to put in alpha */
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
else {
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
*outP++ = (unsigned char)
inP++;
}
}
}
return 0;
}
/* This routine is expecting a ByteComponentRaster with a PackedColorModel */
int forceAlpha)
{
int x, y, c;
int a = numBands;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Need to put in alpha */
if (forceAlpha) {
*outP++ = 0xff;
for (c=0; c < numBands; c++) {
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
else {
*outP++ = (unsigned char)
<<loff[a]);
for (c=0; c < numBands; c++) {
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
*outP++ = (unsigned char)
inP++;
}
}
}
return 0;
}
/* This routine is expecting a ShortComponentRaster with a PackedColorModel */
unsigned char *outDataP)
{
int x, y, c;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Convert the all bands */
/* Need to put in alpha */
/*
*Not correct. Might need to unpremult,
* shift, etc
*/
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
} else {
/*
*Not correct. Might need to unpremult,
* shift, etc
*/
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
*outP++ = (unsigned char)
inP++;
}
}
}
return 0;
}
/* This routine is expecting a ShortComponentRaster with a PackedColorModel */
int forceAlpha)
{
int x, y, c;
int a = numBands;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Need to put in alpha */
if (forceAlpha) {
*outP++ = 0xff;
for (c=0; c < numBands; c++) {
/*
* Not correct. Might need to unpremult,
* shift, etc
*/
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
else {
*outP++ = (unsigned char)
<<loff[a]);
for (c=0; c < numBands; c++) {
/*
* Not correct. Might need to
* unpremult, shift, etc
*/
*outP++ = (unsigned char)
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
*outP++ = (unsigned char)
inP++;
}
}
}
return 0;
}
/* This routine is expecting a IntegerComponentRaster with a PackedColorModel*/
unsigned char *outDataP)
{
int x, y, c;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Convert the all bands */
/*
* Not correct. Might need to unpremult,
* shift, etc
*/
<<loff[c]);
}
inP++;
}
}
}
else {
/*
* Not correct. Might need to
* unpremult, shift, etc
*/
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
inP++;
}
}
}
return 0;
}
/* This routine is expecting a IntegerComponentRaster with a PackedColorModel*/
int forceAlpha)
{
int x, y, c;
int a = numBands;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
if (component < 0) {
if (roff[c] < 0) {
roff[c] = 0;
}
else loff[c] = 0;
}
/* Need to put in alpha */
if (forceAlpha) {
*outP++ = 0xff;
for (c=0; c < numBands; c++) {
/*
* Not correct. Might need to unpremult,
* shift, etc
*/
<<loff[c]);
}
inP++;
}
}
}
else {
<<loff[a]);
for (c=0; c < numBands; c++) {
/*
* Not correct. Might need to
* unpremult, shift, etc
*/
<<loff[c]);
}
inP++;
}
}
}
}
else {
c = component;
if (roff[0] < 0) {
roff[0] = 0;
}
else loff[c] = 0;
inP++;
}
}
}
return 0;
}
/* This routine is expecting a ByteComponentRaster with a PackedColorModel */
unsigned char *inDataP)
{
int x, y, c;
unsigned char *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
*outP = 0;
}
outP++;
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This routine is expecting a ShortComponentRaster with a PackedColorModel */
unsigned char *inDataP)
{
int x, y, c;
unsigned short *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This routine is expecting a IntegerComponentRaster with a PackedColorModel*/
unsigned char *inDataP)
{
int x, y, c;
unsigned int *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This routine is expecting a ByteComponentRaster with a PackedColorModel */
int supportsAlpha)
{
int x, y, c;
unsigned char *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
if (supportsAlpha) {
*outP = 0;
inP++;
}
outP++;
}
}
}
else {
*outP = 0;
inP++;
}
outP++;
}
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This routine is expecting a ShortComponentRaster with a PackedColorModel */
int supportsAlpha)
{
int x, y, c;
unsigned short *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
if (supportsAlpha) {
inP++;
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
else {
inP++;
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This routine is expecting a IntegerComponentRaster with a PackedColorModel*/
int supportsAlpha)
{
int x, y, c;
unsigned int *outDataP;
return -1;
}
/* Grab data ptr, strides, offsets from raster */
return -1;
}
return -1;
}
if (component < 0) {
if (loff[c] < 0) {
loff[c] = 0;
}
else roff[c] = 0;
}
/* Convert the all bands */
if (supportsAlpha) {
inP++;
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
else {
inP++;
/* Not correct. Might need to unpremult, shift, etc */
}
outP++;
}
}
}
}
else {
c = component;
if (loff[0] < 0) {
loff[0] = 0;
}
else roff[c] = 0;
outP++;
}
}
}
return 0;
}
/* This is temporary code. Should go away when there is better color
* conversion code available.
* REMIND: Ignoring alpha
*/
/* returns the absolute value x */
#define ABS(x) ((x) < 0 ? -(x) : (x))
static int
int besti = 0;
int mindist, i, t, d;
r = CLIP(r, 0, 255);
g = CLIP(g, 0, 255);
b = CLIP(b, 0, 255);
/* look for pure gray match */
if ((r == g) && (g == b)) {
mindist = 256;
continue;
}
if (d == 0)
return i;
if (d < mindist) {
besti = i;
mindist = d;
}
}
return besti;
}
/* look for non-pure gray match */
t = red - r;
d = t * t;
if (d >= mindist) {
continue;
}
t = green - g;
d += t * t;
if (d >= mindist) {
continue;
}
t = blue - b;
d += t * t;
if (d >= mindist) {
continue;
}
if (d == 0)
return i;
if (d < mindist) {
besti = i;
mindist = d;
}
}
return besti;
}