/*
* 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.
*/
#import "ImageSurfaceData.h"
#import "java_awt_Transparency.h"
#import "java_awt_image_BufferedImage.h"
#import "sun_awt_image_BufImgSurfaceData.h"
#import "sun_java2d_OSXOffScreenSurfaceData.h"
#import "jni_util.h"
#import "BufImgSurfaceData.h"
#import "ThreadUtilities.h"
//#define DEBUG 1
#else
// same value as defined in Sun's own code
// for vImage framework headers
{
{YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_CUSTOM // special case
{YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_INT_ARGB
{YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_INT_ARGB_PRE
{YES, NO, 8, 4, 0, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_3BYTE_BGR // use the default ARGB_PRE context synce we have to sync by hand anyway
{YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_4BYTE_ABGR
{YES, YES, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_4BYTE_ABGR_PRE
{YES, YES, 5, 2, 0, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host, NULL}, // TYPE_USHORT_565_RGB
{YES, YES, 5, 2, 0, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder16Host, NULL}, // TYPE_USHORT_555_RGB
#else
{YES, NO, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_USHORT_GRAY // use the default ARGB_PRE context synce we have to sync by hand anyway
{NO, NO, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_BYTE_BINARY mapped to TYPE_CUSTOM
{YES, NO, 8, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_BYTE_INDEXED // use the default ARGB_PRE context synce we have to sync by hand anyway
};
{
{8, 32, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_INT_ARGB_PRE
{8, 32, 4, 0, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_4BYTE_ABGR_PRE
#else
{8, 32, 4, 0, kCGImageAlphaFirst | kCGBitmapByteOrder32Host, NULL}, // TYPE_BYTE_INDEXED // Fully OPAQUE INDEXED images will use kCGImageAlphaNoneSkipFirst for performance reasosn. see <rdar://4224874>
};
{
//fprintf(stderr, "\t magicID=%d\n", (jint)isdo->magicID);
//fprintf(stderr, "\n");
}
// if there is no image created for isdo.imgRef, it creates and image using the isdo.dataProvider
// If there is an image present, this is a no-op
{
{
NULL,
NO,
}
}
{
PRINT(" customPixelsFromJava")
JNFCallVoidMethod([ThreadUtilities getJNIEnv], sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object)
}
IMAGE_SURFACE_INLINE void copyBits(jint w, jint h, jint javaPixelsBytesPerRow, Pixel8bit *pixelsSrc, jint dstPixelsBytesPerRow, Pixel8bit *pixelsDst)
{
PRINT(" copyBits")
{
}
else
{
for (y=0; y<h; y++)
{
}
}
}
IMAGE_SURFACE_INLINE void copySwapRandB_32bit_TYPE_4BYTE(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
{
PRINT(" copySwapRandB_32bit_TYPE_4BYTE")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
}
}
}
IMAGE_SURFACE_INLINE void copySwapRandB_32bit_TYPE_INT(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
{
PRINT(" copySwapRandB_32bit_TYPE_INT")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
}
}
}
IMAGE_SURFACE_INLINE void copyBGR_24bitToXRGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
{
PRINT(" copyBGR_24bitToXRGB_32bit")
register jint skip = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsSrc units
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
pixelsDst++;
}
}
}
IMAGE_SURFACE_INLINE void copyRGB_24bitToXRGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc, Pixel32bit *pixelsDst, size_t extraBytesPerRow)
{
PRINT(" copyRGB_24bitToXRGB_32bit")
register jint skip = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsSrc units
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
pixelsDst++;
}
}
}
IMAGE_SURFACE_INLINE void copyIndexed_8bitToARGB_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsSrc,
{
PRINT(" copyIndexed_8bitToARGB_32bit")
//gznote: how is the performance if the extraBytesPerRow != 0 ?
vImage_Error err = vImageLookupTable_Planar8toPlanarF(&src, &dest, (Pixel_F*)lutdata, kvImageDoNotTile);
if (err != kvImageNoError)
{
fprintf(stderr, "Error in copyIndexed_8bitToARGB_32bit: vImageLookupTable_Planar8toPlanarF returns %ld\n", (long)err);
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
//*pixelsDst++ = *(lutdata + *pixelsSrc++); // case 2: at best ~1% better than case 1
}
}
}
}
IMAGE_SURFACE_INLINE void copy565_16bitTo555_16bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsSrc, Pixel16bit *pixelsDst, size_t extraBytesPerRow)
{
PRINT(" copy565_16bitTo555_16bit")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
green = ((pixel >> 5) & 63); // rrrrrggggggbbbbb => shift 5 right = 00000rrrrrgggggg => and 63 = 0000000000gggggg
green = ((jint) (((CGFloat) green / 63.0f) * 31.0f)) & 31; // first normalize to value between 0 and 1 and then un-normalize to 5 bit (31 = 0000000000011111)
}
}
}
{
PRINT(" customPixelsToJava")
JNFCallVoidMethod([ThreadUtilities getJNIEnv], sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object)
}
IMAGE_SURFACE_INLINE void removeAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
{
PRINT(" removeAlphaPre_32bit")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
if (alpha != 0)
{
// get color components
// remove alpha pre
// clamp
}
else
{
*pixelsSrc++ = 0;
}
}
}
}
IMAGE_SURFACE_INLINE void swapRandBAndRemoveAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
{
PRINT(" swapRandBAndRemoveAlphaPre_32bit")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
if (alpha != 0)
{
// get color components
// remove alpha pre
// clamp
pixel = CFSwapInt32HostToBig(pixel); // the jint is little endian, we need to swap the bits before we send it back to Java
}
else
{
*pixelsSrc++ = 0;
}
}
}
}
IMAGE_SURFACE_INLINE void swapRandB_32bit_TYPE_INT(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
{
PRINT(" swapRandB_32bit_TYPE_INT")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
}
}
}
IMAGE_SURFACE_INLINE void swapRandB_32bit_TYPE_4BYTE(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
{
PRINT(" swapRandB_32bit_TYPE_4BYTE")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
pixel = CFSwapInt32HostToBig(pixel); // the jint is little endian, we need to swap the bits before we send it back to Java
}
}
}
IMAGE_SURFACE_INLINE void map555_16bitTo565_16bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsSrc)
{
PRINT(" map555_16bitTo565_16bit")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
green = ((pixel >> 5) & 31); // rrrrrgggggbbbbb => shift 5 right = 000000rrrrrggggg => and 31 = 00000000000ggggg
green = ((jint) (((CGFloat) green / 31.0f) * 63.0f)) & 63; // first normalize between 0 and 1 and then un-normalize to 6 bit (63 = 0000000000111111)
}
}
}
IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToBGR_24bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst)
{
PRINT(" copyARGB_PRE_32bitToBGR_24bit")
register jint skipDst = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsDst units
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
if (alpha != 0)
{
// extract color components
// remove alpha pre
// clamp
}
else
{
}
pixelsSrc++;
}
}
}
IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToRGB_24bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst)
{
PRINT(" copyARGB_PRE_32bitToRGB_24bit")
register jint skipDst = ((javaPixelsBytesPerRow/javaPixelBytes)-w)*javaPixelBytes; // in pixelsDst units
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
if (alpha != 0)
{
// extract color components
// remove alpha pre
// clamp
}
else
{
}
pixelsSrc++;
}
}
}
// gray = 0.3red + 0.59green + 0.11blue - NTSC standard (according to Luke Wallis)
IMAGE_SURFACE_INLINE void copyARGB_PRE_32bitToGray_16bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel16bit *pixelsDst)
{
PRINT(" copyARGB_PRE_32bitToGray_16bit")
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
// gznote: do we remove alpha pre here?
if (alpha != 0)
{
}
else
{
pixelFloat = 0;
}
pixelsDst++;
pixelsSrc++;
}
}
}
// 1. first "dither" the true color down by creating a 16 bit value of the real color that will serve as an index into the cache of indexes
// 2. if the cache has a valid entry use it otherwise go through 3 and 4
// 3. go through the color table and calculate Euclidian distance between the true color and the indexed colors
// 4. map the shortest distance into the one and true index color and stick it into the dst (and cache)
IMAGE_SURFACE_INLINE UInt16* copyARGB_PRE_bitToIndexed_8bit(jint w, jint h, jint nativePixelsBytesPerRow, Pixel32bit *pixelsSrc, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel8bit *pixelsDst, Pixel32bit* lutdata, UInt32 lutDataSize, UInt16 *indexedColorTable)
{
PRINT(" copyARGB_PRE_bitToIndexed_8bit")
if (indexedColorTable == NULL)
{
indexedColorTable = (UInt16*)malloc(indexSize*sizeof(UInt16)); // 15 bit precision, each entry capable of holding a 2 byte value
if (indexedColorTable != NULL)
{
}
else
{
fprintf(stderr, "ERROR: malloc returns NULL for isdo->indexedColorTable in copyARGB_PRE_bitToIndexed_8bit");
return NULL;
}
}
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
{
if (p1a != 0)
{
// extract color components
// remove alpha pre
// clamp
}
else
{
p1r = 0;
p1g = 0;
p1b = 0;
}
cacheIndex = (UInt16)(((p1a & indexMask) << 8) | ((p1r & indexMask) << 4) | ((p1g & indexMask) << 0) | ((p1b & indexMask) >> 4));
{
indexOfBest = 0;
for (i=0; i<lutDataSize; i++)
{
if (distance < distanceOfBest)
{
indexOfBest = i;
}
}
}
else
{
}
}
else
{
}
*pixelsDst = indexOfBest;
pixelsDst++;
pixelsSrc++;
}
}
return indexedColorTable;
}
// callback from CG telling us it's done with the data. <rdar://problem/4762033>
{
{
}
}
{
PRINT("createContext")
{
{
fprintf(stderr, "malloc failed for size %d bytes in ImageSurfaceData.createContext()\n", (int) size);
}
//fprintf(stderr, "isdo=%p isdo->type=%d, bitsPerComponent=%d, bytesPerRow=%d, colorSpace=%p, alphaInfo=%d, width=%d, height=%d, size=%d\n", isdo, type, (jint)bitsPerComponent, (jint)bytesPerRow, colorSpace, (jint)alphaInfo, (jint) isdo->width, (jint) isdo->height, (jint) size);
qsdo->cgRef = CGBitmapContextCreate(isdo->nativePixels, isdo->width, isdo->height, bitsPerComponent, bytesPerRow, colorSpace, alphaInfo);
isdo->dataProvider = CGDataProviderCreateWithData(NULL, isdo->nativePixels, size, releaseDataFromProvider);
}
//fprintf(stderr, "cgRef=%p\n", qsdo->cgRef);
{
}
// intitalize the context to match the Java coordinate system
// BG, since the context is created above, we can just concat
CGContextSaveGState(qsdo->cgRef); // this will put user settings on top, used by LazyStateManagement code
}
{
PRINT("holdJavaPixels")
{
{
{
}
else
{
}
}
isdo->nrOfPixelsOwners++;
}
{
}
}
{
PRINT("unholdJavaPixels")
{
isdo->nrOfPixelsOwners--;
{
(*env)->ReleasePrimitiveArrayCritical(env, isdo->array, isdo->pixelsLocked, 0); // Do not use JNI_COMMIT, as that will not free the buffer copy when +ProtectJavaHeap is on.
}
}
}
{
PRINT("imageDataProvider_UnholdJavaPixels")
}
{
PRINT("imageDataProvider_FreeTempPixels")
}
{
PRINT("syncFromJavaPixels")
// check to see if we have any work to do
{
// if we do, lock down Java pixels, this halts GarbageCollector!
{
void *dataProviderData = NULL;
void *dataProviderInfo = NULL;
void *dataProviderCallback = NULL;
{
//case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
holdJavaPixels(env, isdo); // we lock again since we are reusing pixels, but we must ensure CGImageRef immutability
// we can lock these pixels down because they are nio based, so we don't halt the GarbageCollector
break;
default:
}
{
//case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
break;
copyBits(width, height, isdo->javaPixelsBytesPerRow, (Pixel8bit*)isdo->pixels, bytesPerRow, dataProviderData);
break;
copySwapRandB_32bit_TYPE_INT(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
break;
copySwapRandB_32bit_TYPE_4BYTE(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
break;
copyBGR_24bitToXRGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, dataProviderData, extraBytesPerRow);
break;
copyRGB_24bitToXRGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, dataProviderData, extraBytesPerRow);
break;
copy565_16bitTo555_16bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels, dataProviderData, extraBytesPerRow);
break;
copyIndexed_8bitToARGB_32bit(width, height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, isdo->lutData, dataProviderData, extraBytesPerRow);
break;
default:
break;
}
CGDataProviderRef provider = CGDataProviderCreateWithData(dataProviderInfo, dataProviderData, dataProviderDataSize, dataProviderCallback);
isdo->imageInfo.colorSpace, isdo->imageInfo.alphaInfo, provider, NULL, NO, kCGRenderingIntentDefault);
//fprintf(stderr, "javaImg=%p\n", javaImg);
{
{
}
{
}
{
}
else
{
}
}
else
{
//fprintf(stderr, "isdo->type=%d, isdo->width=%d, isdo->height=%d, isdo->imageInfo.bitsPerComponent=%d, isdo->imageInfo.bytesPerPixel=%d, isdo->imageInfo.bitsPerPixel=%d, isdo->imageInfo.bytesPerRow=%d, isdo->imageInfo.colorSpace=%p, isdo->imageInfo.alphaInfo=%d\n",
//(jint)isdo->type, (jint)isdo->width, (jint)isdo->height, (jint)isdo->imageInfo.bitsPerComponent, (jint)isdo->imageInfo.bytesPerPixel, (jint)isdo->imageInfo.bitsPerPixel, (jint)isdo->imageInfo.bytesPerRow, isdo->imageInfo.colorSpace, (jint)isdo->imageInfo.alphaInfo);
}
}
}
}
IMAGE_SURFACE_INLINE void processPixels(ImageSDOps* isdo, jint x, jint y, jint width, jint height, void (*processPixelsCallback) (ImageSDOps *, jint, Pixel32bit *, jint, jint, jint, jint))
{
processPixelsCallback(isdo, (jint) isdo->contextInfo.bytesPerRow, (Pixel32bit *) isdo->nativePixels, x, y, width, height);
}
IMAGE_SURFACE_INLINE void syncToJavaPixels_processPixelsCallback(ImageSDOps* isdo, jint nativePixelsBytesPerRow, Pixel32bit *dataSrc, jint x, jint y, jint width, jint height)
{
{
copyARGB_PRE_32bitToBGR_24bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels);
break;
copyARGB_PRE_32bitToRGB_24bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels);
break;
copyARGB_PRE_32bitToGray_16bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels);
break;
isdo->indexedColorTable = copyARGB_PRE_bitToIndexed_8bit(isdo->width, isdo->height, nativePixelsBytesPerRow, dataSrc, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, isdo->pixels, isdo->lutData, isdo->lutDataSize, isdo->indexedColorTable);
break;
default:
break;
}
}
{
PRINT("syncToJavaPixels")
{
}
{
if (srcBytesPerRow == dstBytesPerRow)
{
}
else
{
jint y;
for (y=0; y < h; y++)
{
}
}
{
//case java_awt_image_BufferedImage_TYPE_BYTE_BINARY: // mapped to TYPE_CUSTOM
break;
removeAlphaPre_32bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
break;
swapRandBAndRemoveAlphaPre_32bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
break;
swapRandB_32bit_TYPE_INT(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
break;
swapRandB_32bit_TYPE_4BYTE(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel32bit*)isdo->pixels);
break;
map555_16bitTo565_16bit(isdo->width, isdo->height, isdo->javaPixelsBytesPerRow, isdo->javaPixelBytes, (Pixel16bit*)isdo->pixels);
break;
default:
break;
}
}
else
{
}
}
IMAGE_SURFACE_INLINE jboolean xorSurfacePixels(JNIEnv *env, jobject dstIsd, jobject srcIsd, jint colorXOR, jint x, jint y, jint w, jint h)
{
PRINT("xorSurfacePixels")
if ((x < 0) || (y < 0) || (x+w > dstIsdo->width) || (y+h > dstIsdo->height) || (w > srcIsdo->width) || (h > srcIsdo->height))
{
fprintf(stderr, " dstIsdo->width=%d, dstIsdo->height=%d, biqsdoPixels->width=%d, biqsdoPixels->height=%d\n",
return JNI_FALSE;
}
{
{
{
}
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
if (pixelAlpha > XOR_ALPHA_CUTOFF)
{
}
}
srcPixels += skipPixels;
}
break;
}
default:
{
#if defined(PRINT_WARNINGS)
}
}
return handled;
}
{
PRINT("clearSurfacePixels")
{
if ((w < isdo->width) || (h < isdo->height)) //cmcnote: necessary to special-case for small height? wouldn't 4*w*h do it?
{
for (i=0; i<h; i++)
{
}
}
else
{
}
}
return handled;
}
{
PRINT("ImageSD_startCGContext")
{
}
{
}
else
{
}
{
{
}
// sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex can be set right above or somewhere else
{
}
}
}
{
PRINT("ImageSD_finishCGContext")
{
{
}
}
}
{
PRINT("ImageSD_dispose")
// copied from BufImg_Dispose in BufImgSurfaceData.c
{
/* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
}
}
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
}
}
// used by XOR (Java pixels must be up to date)
{
PRINT("LockImagePixels")
// if we need to access this image's pixels we need to convert native pixels (if any) back to Java
{
}
return isdo;
}
{
PRINT("UnlockImagePixels")
// don't do that since the native pixels haven't changed (Java pixels == native pixels)
//syncToJavaPixels(env, isdo);
}
// used by drawImage (native pixels must be up to date)
{
PRINT("LockImage")
// if we need to access this image's pixels we need to convert native pixels (if any) back to Java
// for those images whose context type doesn't match layer type or is a custom image
{
}
// sun_java2d_OSXOffScreenSurfaceData_kNeedToSyncFromJavaPixelsIndex can be set right above or somewhere else
{
}
return isdo;
}
{
PRINT("UnlockImage")
// don't do that since the native pixels haven't changed (Java pixels == native pixels)
//syncToJavaPixels(env, isdo);
}
{
if (sDataID == 0)
{
static char *bimgName = "java/awt/image/BufferedImage";
}
}
{
if (sDataID == 0)
{
static char *bimgName = "java/awt/image/BufferedImage";
}
}
{
//PRINT("initIDs")
// copied from Java_sun_awt_image_BufImgSurfaceData_initIDs in BufImgSurfaceData.c
{
static char *icmName = "java/awt/image/IndexColorModel";
return;
}
return;
}
}
}
//fprintf(stderr, "gColorspaceRGB=%p, gColorspaceGray=%p\n", gColorspaceRGB, gColorspaceGray);
}
{
PRINT("getSurfaceData")
}
{
PRINT("setSurfaceData")
}
static jint ImageSD_Lock(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo, jint lockflags)
{
// copied from BufImg_Lock in BufImgSurfaceData.c
{
/* REMIND: Should this be an InvalidPipe exception? */
return SD_FAILURE;
}
// TODO:BG
/*
if ((lockflags & SD_LOCK_INVCOLOR) != 0 ||
(lockflags & SD_LOCK_INVGRAY) != 0)
{
bipriv->cData = BufImg_SetupICM(env, bisdo);
if (bipriv->cData == NULL) {
JNU_ThrowNullPointerException(env, "Could not initialize "
"inverse tables");
return SD_FAILURE;
}
} else {
bipriv->cData = NULL;
}
*/
/* TODO:BG
if ((bipriv->lockFlags & SD_LOCK_WRITE) &&
bisdo->sdOps.dirty != TRUE) {
SurfaceData_MarkDirty(env, &bisdo->sdOps);
} */
return SD_SUCCESS;
}
}
{
// For every ImageSD_Unlock, we need to be be conservative and mark the pixels
// as modified by the Sun2D renderer.
}
{
// copied from BufImg_GetRasInfo in BufImgSurfaceData.c
{
}
}
} else {
}
} else {
}
} else {
}
}
}
{
// copied from BufImg_Release in BufImgSurfaceData.c
{
? 0 : JNI_ABORT);
}
}
}
}
JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(JNIEnv *env, jobject bisd, jobject array, jint offset, jint width, jint height,
{
PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_initRaster")
// copied (and modified) from Java_sun_awt_image_BufImgSurfaceData_initRaster in BufImgSurfaceData.c
{
BufImgSDOps *bisdo =
//(BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
(BufImgSDOps*)isdo;
//bisdo->sdOps.Lock = BufImg_Lock;
//bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;
//bisdo->sdOps.Release = BufImg_Release;
//bisdo->sdOps.Unlock = NULL;
//bisdo->sdOps.Dispose = BufImg_Dispose;
//bisdo->scanStr = scanStr;
//bisdo->pixStr = pixStr;
if (!icm) {
} else {
}
}
switch (type)
{
break;
break;
default:
break;
}
// parameters specifying this image given to us from Java
{
// don't waste (precious, precious) VRAM on stolen or custom images that will be slow no matter what
}
// needed by TYPE_BYTE_INDEXED
if ((type == java_awt_image_BufferedImage_TYPE_BYTE_INDEXED) && ((*env)->IsSameObject(env, icm, NULL) == NO))
{
{
{
}
{
{
{
jint i;
{
if (i != transparent_index)
{
// rdar://problem/3390518 - don't force all indexed colors
// to be fully opaque. They could be set up for us.
// we used to call: *dst = 0xff000000 | *src;
// but that was forcing colors to be opaque when developers
// could have set the alpha.
}
else
{
}
}
}
else //if ((transparency == java_awt_Transparency_OPAQUE) || (transparency == java_awt_Transparency_TRANSLUCENT))
{
// <rdar://4224874> If the color model is OPAQUE than we need to create an opaque image for performance purposes.
// the default alphaInfo for INDEXED images is kCGImageAlphaFirst. Therefore we need to special case this.
if ((transparency == java_awt_Transparency_OPAQUE))
{
}
jint i;
{
}
}
}
else
{
}
}
else
{
}
}
}
//PrintImageInfo(isdo);
}
JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initCustomRaster(JNIEnv* env, jobject bisd, jobject array, jint width, jint height,
{
PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_initCustomRaster")
Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(env, bisd, array, offset, width, height, pixelStride, scanStride, icm, type, jGraphicsState, jGraphicsStateObject, jImageInfo);
}
JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_syncToJavaPixels(JNIEnv *env, jobject bisd)
{
PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_syncToJavaPixels")
}
{
PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_xorSurfacePixels")
}
{
PRINT("Java_sun_java2d_OSXOffScreenSurfaceData_clearSurfacePixels")
}