aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2006-10-16 21:05:09 +0000
committerChien Yang <[email protected]>2006-10-16 21:05:09 +0000
commit493d0b1e80e30b30311a82492ebc27c022c5a7be (patch)
tree7d33b7ec5d61315b4208d7d8ded43ece03213a98 /src/native
parente60078c34fa46c8d6f6cd9577118d8c4c9f4d0ab (diff)
Support INT image type on 2D texture.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@719 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native')
-rw-r--r--src/native/d3d/Attributes.cpp97
-rw-r--r--src/native/d3d/Canvas3D.cpp253
-rw-r--r--src/native/d3d/D3dCtx.cpp10
-rw-r--r--src/native/d3d/D3dUtil.cpp2538
-rw-r--r--src/native/d3d/D3dUtil.hpp8
5 files changed, 1949 insertions, 957 deletions
diff --git a/src/native/d3d/Attributes.cpp b/src/native/d3d/Attributes.cpp
index 8461c66..e1d5eaf 100644
--- a/src/native/d3d/Attributes.cpp
+++ b/src/native/d3d/Attributes.cpp
@@ -787,20 +787,19 @@ void JNICALL Java_javax_media_j3d_NativePipeline_resetLineAttributes(
jobject obj,
jlong ctx)
{
- GetDevice();
+ // GetDevice();
// D3D don't support Line width
// glLineWidth(1);
- //D3D9 doesnot support line Patterns
- // @TODO must update this to use ID3DXLine Interface
-/*
- D3DLINEPATTERN pattern;
- pattern.wRepeatFactor = 0;
- pattern.wLinePattern = 0;
- device->SetRenderState(D3DRS_LINEPATTERN,
- *((LPDWORD) (&pattern)));
-
-*/
+ // D3D9 doesnot support line Patterns
+ // @TODO must update this to use ID3DXLine Interface
+ /*
+ D3DLINEPATTERN pattern;
+ pattern.wRepeatFactor = 0;
+ pattern.wLinePattern = 0;
+ device->SetRenderState(D3DRS_LINEPATTERN,
+ *((LPDWORD) (&pattern)));
+ */
}
@@ -817,9 +816,9 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateLineAttributes(
jint linePatternScaleFactor,
jboolean lineAntialiasing)
{
- GetDevice();
-
- //Alessandro
+ // GetDevice();
+
+ //Alessandro
//D3DLINEPATTERN pattern;
/*
@@ -2232,10 +2231,8 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage(
return;
}
- // TODO --- Need to re-write. Chien
void *imageObjPtr;
-
- /* Need to support INT, and NIO buffers -- Chien */
+ jbyte *dataBuffer;
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) ||
(dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
@@ -2245,23 +2242,28 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage(
imageObjPtr = (void *)env->GetDirectBufferAddress(data);
}
- // update Image data
- if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) {
- jbyte *byteData = (jbyte *) imageObjPtr;
- copyDataToSurface(imageFormat, textureFormat, xoffset, yoffset,
- imgXOffset, imgYOffset,
- width, height, tilew, byteData,
- surf, level);
- } else {
- /*
- jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(image, NULL);
+ switch (imageFormat) {
+ case IMAGE_FORMAT_BYTE_BGR:
+ case IMAGE_FORMAT_BYTE_RGB:
+ case IMAGE_FORMAT_BYTE_ABGR:
+ case IMAGE_FORMAT_BYTE_RGBA:
+ case IMAGE_FORMAT_BYTE_LA:
+ case IMAGE_FORMAT_BYTE_GRAY:
+ case IMAGE_FORMAT_INT_BGR:
+ case IMAGE_FORMAT_INT_RGB:
+ case IMAGE_FORMAT_INT_ARGB:
+ dataBuffer = (jbyte *) imageObjPtr;
copyDataToSurface(imageFormat, textureFormat, xoffset, yoffset,
imgXOffset, imgYOffset,
- width, height, tilew, shortData,
+ width, height, tilew, dataBuffer,
surf, level);
- env->ReleasePrimitiveArrayCritical(image, shortData, 0);
- */
+ break;
+ case IMAGE_FORMAT_USHORT_GRAY:
+ default:
+ throwAssert(env, "updateTexture2DSubImage : imageFormat illegal format");
+ return;
}
+
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) ||
(dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0);
@@ -2294,7 +2296,6 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DImage(
return;
}
-
INT currBindTex = d3dCtx->bindTextureId[d3dCtx->texUnitStage];
if ((currBindTex < 1) ||
@@ -2342,13 +2343,11 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DImage(
return;
}
- // TODO --- Need to re-write. Chien
// update Image data
if (data != NULL) {
void *imageObjPtr;
+ jbyte *dataBuffer;
- /* Need to support INT, and NIO buffers -- Chien */
-
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) ||
(dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)data, NULL);
@@ -2357,20 +2356,26 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateTexture2DImage(
imageObjPtr = (void *)env->GetDirectBufferAddress(data);
}
- if (imageFormat != IMAGE_FORMAT_USHORT_GRAY) {
- jbyte *byteData = (jbyte *) imageObjPtr;
+ switch (imageFormat) {
+ case IMAGE_FORMAT_BYTE_BGR:
+ case IMAGE_FORMAT_BYTE_RGB:
+ case IMAGE_FORMAT_BYTE_ABGR:
+ case IMAGE_FORMAT_BYTE_RGBA:
+ case IMAGE_FORMAT_BYTE_LA:
+ case IMAGE_FORMAT_BYTE_GRAY:
+ case IMAGE_FORMAT_INT_BGR:
+ case IMAGE_FORMAT_INT_RGB:
+ case IMAGE_FORMAT_INT_ARGB:
+ dataBuffer = (jbyte *) imageObjPtr;
copyDataToSurface(imageFormat, textureFormat, 0, 0, 0, 0,
- width, height, width, byteData,
+ width, height, width, dataBuffer,
surf, level);
- } else {
- /*
- jshort *shortData = (jshort *) env->GetPrimitiveArrayCritical(imageYup, NULL);
- copyDataToSurface(imageFormat, textureFormat, 0, 0, 0, 0,
- width, height, width, shortData,
- surf, level);
- env->ReleasePrimitiveArrayCritical(imageYup, shortData, 0);
- */
- }
+ break;
+ case IMAGE_FORMAT_USHORT_GRAY:
+ default:
+ throwAssert(env, "updateTexture2DImage : imageFormat illegal format");
+ return;
+ }
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) ||
(dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp
index 6988d57..e6a3eca 100644
--- a/src/native/d3d/Canvas3D.cpp
+++ b/src/native/d3d/Canvas3D.cpp
@@ -198,18 +198,12 @@ jboolean JNICALL Java_javax_media_j3d_NativePipeline_initTexturemapping(
objectId);
}
- Java_javax_media_j3d_NativePipeline_bindTexture2D(
- env, texture, ctx, objectId, TRUE);
-
- /* TODO : This need to rewrite -- Chien. */
- /*
- Java_javax_media_j3d_NativePipeline_updateTexture2DImage(
- env, texture, ctx, 1, 0, J3D_RGBA, 0, texWidth, texHeight, 0, NULL);
- */
+ Java_javax_media_j3d_NativePipeline_bindTexture2D(env, texture, ctx, objectId, TRUE);
+
Java_javax_media_j3d_NativePipeline_updateTexture2DImage(env, texture, ctx, 1, 0,
J3D_RGBA, 0, texWidth,
texHeight, 0, 0, NULL);
- return (d3dCtx->textureTable[objectId] != NULL);
+ return (d3dCtx->textureTable[objectId] != NULL);
}
@@ -239,6 +233,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping(
env, texture, ctx, objectId, TRUE);
// TODO --- Need to re-write. Chien
+ printf("[TODO NEEDED] Canvas3dD : *** texturemapping() ***\n");
Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage(
env, texture, ctx, 0, minX, minY, J3D_RGBA, format,
minX, minY, rasWidth, maxX-minX, maxY-minY, IMAGE_DATA_TYPE_BYTE_ARRAY,
@@ -364,7 +359,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(
GetDevice();
/* printf("Canvas3D.textureFillBackground()\n"); */
/* TODO : Implement textureFillBackground() */
- printf("[Java3D] D3D : textureFillBackground is not implemented yet.\n");
+ printf("[TODO NEEDED] Canvas3D : *** textureFillBackground is not implemented yet.\n");
}
@@ -387,7 +382,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env,
GetDevice();
/* printf("Canvas3D.textureFillRaster()\n"); */
/* TODO : Implement textureFillRaster() */
- printf("[Java3D] D3D : textureFillRaster is not implemented yet.\n");
+ printf("[TODO NEEDED] Canvas3D : *** textureFillRaster is not implemented yet.\n");
}
@@ -411,228 +406,10 @@ void JNICALL Java_javax_media_j3d_NativePipeline_executeRasterDepth(JNIEnv *env,
GetDevice();
/* printf("Canvas3D.executeRasterDepth()\n"); */
/* TODO : Implement executeRasterDepth() */
- printf("[Java3D] D3D : executeRasterDepth is not implemented yet.\n");
-
-}
-
-/* TODO : This method will be replaced by clear() and textureFill() */
-extern "C" JNIEXPORT
-void JNICALL Java_javax_media_j3d_NativePipeline_textureclear(
- JNIEnv *env,
- jobject obj,
- jlong ctx,
- jint maxX,
- jint maxY,
- jfloat r,
- jfloat g,
- jfloat b,
- jint winWidth,
- jint winHeight,
- jint objectId,
- jint imageScaleMode,
- jobject pa2d,
- jboolean update)
-{
-
-
- GetDevice();
-
- /* Java 3D always clears the Z-buffer */
- /* @TODO check same operation for stencil */
-
- if (!d3dCtx->zWriteEnable) {
- device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
- }
-
- /* clear stencil, if in used */
-
- if (d3dCtx->stencilWriteEnable )
- {// clear stencil and ZBuffer
- HRESULT hr = device->Clear(0, NULL, D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
- D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0);
- if (hr == D3DERR_INVALIDCALL)
- {
- printf("[Java3D] Error cleaning Canvas3D stencil & ZBuffer\n");
- }
- // printf("canvas3D clear stencil & ZBuffer\n");
- }
- else
- { // clear ZBuffer only
- HRESULT hr = device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
- D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0);
- if (hr == D3DERR_INVALIDCALL)
- {
- printf("[Java3D] Error cleaning Canvas3D ZBuffer\n");
- }
- // printf("canvas3D clear ZBuffer\n");
- }
-
-
- if (pa2d) {
- /*
- jclass pa2d_class = env->GetObjectClass(pa2d);
- // It is possible that (1) Another user thread will free this
- // image. (2) Another Renderer thread in case of multiple screen
- // will invoke clear() at the same time.
- lockBackground();
-
-
- jfieldID id = env->GetFieldID(pa2d_class, "hashId", "I");
- int hashCode = env->GetIntField(pa2d, id);
-
- D3dImageComponent *d3dImage =
- D3dImageComponent::find(&BackgroundImageList, d3dCtx, hashCode);
-
- id = env->GetFieldID(pa2d_class, "imageYup", "[B");
- jbyteArray pixels_obj = (jbyteArray) env->GetObjectField(pa2d, id);
-
- id = env->GetFieldID(pa2d_class, "width", "I");
- int width = env->GetIntField(pa2d, id);
- id = env->GetFieldID(pa2d_class, "height", "I");
- int height = env->GetIntField(pa2d, id);
-
- LPDIRECT3DTEXTURE9 surf;
-
- if ((d3dImage == NULL) || (d3dImage->surf == NULL)) {
- surf = createSurfaceFromImage(env, pa2d, ctx,
- width, height, pixels_obj);
- if (surf == NULL) {
- if (d3dImage != NULL) {
- D3dImageComponent::remove(&BackgroundImageList, d3dImage);
- }
- unlockBackground();
- return;
- }
-
- if (d3dImage == NULL) {
- d3dImage =
- D3dImageComponent::add(&BackgroundImageList, d3dCtx, hashCode, surf);
- } else {
- // need to add this one because the new imageDirtyFlag may
- // cause d3dImage->surf set to NULL
- d3dImage->surf = surf;
- }
- }
-
-
- D3DTLVERTEX screenCoord;
- DWORD zcmpfunc;
- boolean texModeRepeat;
- int scaleWidth, scaleHeight;
- float sw, sh;
-
- DWORD stencilcmpfunc;
-
- // sz can be any number since we already disable z buffer
- // However rhw can't be 0, otherwise texture will not shown
- screenCoord.sz = 0.999f;
- screenCoord.rhw = 1;
-
- // disable z buffer
- device->GetRenderState(D3DRS_ZFUNC, &zcmpfunc);
- device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
- device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
-
- // must disable stencil ? I guess yes
- if (d3dCtx->stencilEnable)
- {
- device->GetRenderState(D3DRS_STENCILFUNC, &stencilcmpfunc);
- device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
- device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
- }
-
-
- switch (imageScaleMode){
- case javax_media_j3d_Background_SCALE_NONE:
- screenCoord.sx = -0.5f;
- screenCoord.sy = -0.5f;
- scaleWidth = width;
- scaleHeight = height;
- texModeRepeat = FALSE;
- break;
- case javax_media_j3d_Background_SCALE_FIT_MIN:
- screenCoord.sx = -0.5f;
- screenCoord.sy = -0.5f;
- sw = winWidth/(float) width;
- sh = winHeight/(float) height;
- if (sw >= sh) {
- scaleWidth = int(width*sh);
- scaleHeight = winHeight;
- } else {
- scaleWidth = winWidth;
- scaleHeight = int(height*sw);
- }
- texModeRepeat = FALSE;
- break;
- case javax_media_j3d_Background_SCALE_FIT_MAX:
- screenCoord.sx = -0.5f;
- screenCoord.sy = -0.5f;
- sw = winWidth/(float) width;
- sh = winHeight/(float) height;
- if (sw >= sh) {
- scaleWidth = winWidth;
- scaleHeight = int(height*sw);
- } else {
- scaleWidth = int(width*sh);
- scaleHeight = winHeight;
- }
- texModeRepeat = FALSE;
- break;
- case javax_media_j3d_Background_SCALE_FIT_ALL:
- screenCoord.sx = -0.5f;
- screenCoord.sy = -0.5f;
- scaleWidth = winWidth;
- scaleHeight = winHeight;
- texModeRepeat = FALSE;
- break;
- case javax_media_j3d_Background_SCALE_REPEAT:
- screenCoord.sx = -0.5f;
- screenCoord.sy = -0.5f;
- scaleWidth = winWidth;
- scaleHeight = winHeight;
- texModeRepeat = TRUE;
- break;
- case javax_media_j3d_Background_SCALE_NONE_CENTER:
- screenCoord.sx = (winWidth - width)/2.0f - 0.5f;
- screenCoord.sy = (winHeight - height)/2.0f -0.5f;
- scaleWidth = width;
- scaleHeight = height;
- texModeRepeat = FALSE;
- break;
- default:
- printf("Unknown Background scale mode %d\n", imageScaleMode);
- }
-
- drawTextureRect(d3dCtx, device, d3dImage->surf,
- screenCoord, 0, 0, width, height,
- scaleWidth, scaleHeight, texModeRepeat);
-
- device->SetRenderState(D3DRS_ZFUNC, zcmpfunc);
- device->SetRenderState(D3DRS_ZWRITEENABLE, d3dCtx->zWriteEnable);
-
- // reenable stencil ? yes
- if (d3dCtx->stencilEnable)
- {
- device->SetRenderState(D3DRS_STENCILFUNC, stencilcmpfunc);
- device->SetRenderState(D3DRS_STENCILENABLE, d3dCtx->stencilWriteEnable);
- }
- unlockBackground();
- */
- }
- else
- {
- if (!d3dCtx->zWriteEnable) {
- device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
- }
- // disable stencil
- if (d3dCtx->stencilEnable && !d3dCtx->stencilWriteEnable) {
- device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
- }
- }
+ printf("[TODO NEEDED] Canvas3D : *** : executeRasterDepth is not implemented yet.\n");
}
-
extern "C" JNIEXPORT
void JNICALL Java_javax_media_j3d_NativePipeline_setRenderMode(
JNIEnv *env,
@@ -1036,23 +813,19 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readOffScreenBuffer(
}
}
- /* TODO : Need to re-write --- Chien. */
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
- imageObjPtr = (void *)env->GetPrimitiveArrayCritical((jarray)data, NULL);
-
- /* TODO : Can't assume it is a byte array */
- copyDataFromSurface(format, 0, 0, width, height, (jbyte *)imageObjPtr,
- d3dCtx->backSurface);
-
-
+ imageObjPtr = (void *)env->GetPrimitiveArrayCritical((jarray)data, NULL);
}
else {
imageObjPtr = (void *)env->GetDirectBufferAddress(data);
-
- /* TODO --- Do something .... */
}
+ /* TODO : Need to re-write --- Chien. */
+ printf("[TODO NEEDED] Canvas3D : *** ireadOffScreenBuffer() ***\n");
+ copyDataFromSurface(format, 0, 0, width, height, (jbyte *)imageObjPtr,
+ d3dCtx->backSurface);
+
if((dataType == IMAGE_DATA_TYPE_BYTE_ARRAY) || (dataType == IMAGE_DATA_TYPE_INT_ARRAY)) {
env->ReleasePrimitiveArrayCritical((jarray)data, imageObjPtr, 0);
diff --git a/src/native/d3d/D3dCtx.cpp b/src/native/d3d/D3dCtx.cpp
index f48b24c..dccfd8f 100644
--- a/src/native/d3d/D3dCtx.cpp
+++ b/src/native/d3d/D3dCtx.cpp
@@ -270,16 +270,6 @@ VOID D3dCtx::releaseTexture()
cubeMapTableLen = 0;
unlockSurfaceList();
- /*
- lockImage();
- D3dImageComponent::remove(&RasterList, this);
- unlockImage();
-
- lockBackground();
- D3dImageComponent::remove(&BackgroundImageList, this);
- unlockBackground();
- */
-
// free list0
freeList();
// free list1
diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp
index 8700e65..512ccba 100644
--- a/src/native/d3d/D3dUtil.cpp
+++ b/src/native/d3d/D3dUtil.cpp
@@ -211,6 +211,13 @@ typedef struct _DEPTHPIXELFORMAT {
DWORD dwStencilBitMask;
} DEPTHPIXELFORMAT;
+void throwAssert(JNIEnv *env, char *str)
+{
+ jclass rte;
+ if ((rte = (jclass)env->FindClass("java/lang/AssertionError")) != NULL) {
+ (void *)env->ThrowNew(rte, str);
+ }
+}
char *getSwapEffectName(D3DSWAPEFFECT swapEffect)
{
@@ -621,15 +628,15 @@ void getTexWidthHeight(D3dDeviceInfo *deviceInfo,
*height = texHeight;
}
+D3DFORMAT getTexFormat(jint textureFormat) {
-/* TODO : Need to modify to handle more format ---- Chien */
-D3DFORMAT getTexFormat(jint internalFormat) {
-
- switch (internalFormat) {
+ switch (textureFormat) {
case J3D_RGBA:
case INTENSITY:
+ // printf("[getTexFormat] textureFormat %d J3D_RGBA\n", textureFormat);
return D3DFMT_A8R8G8B8;
case J3D_RGB:
+ // printf("[getTexFormat] textureFormat %d J3D_RGB\n", textureFormat);
return D3DFMT_R8G8B8;
case LUMINANCE_ALPHA:
return D3DFMT_A8L8;
@@ -638,7 +645,7 @@ D3DFORMAT getTexFormat(jint internalFormat) {
case LUMINANCE:
return D3DFMT_L8;
default:
- printf("CreateTextureSurface: Unknown internal Format %d \n", internalFormat);
+ printf("CreateTextureSurface: Unknown Java 3D Texture Format %d\n", textureFormat);
return D3DFMT_UNKNOWN;
}
@@ -657,7 +664,6 @@ D3dCtx* findCtx(HWND hwnd)
return ctx;
}
-
inline VOID lock()
{
if (hSema != NULL) {
@@ -752,7 +758,7 @@ DWORD firstBit(DWORD mask)
// create a DirectDraw Texture surface of specific width and height
LPDIRECT3DTEXTURE9 createTextureSurface(D3dCtx *d3dCtx,
jint numLevels,
- jint internalFormat,
+ jint textureFormat,
jint width, jint height)
{
LPDIRECT3DTEXTURE9 pTexture;
@@ -767,7 +773,7 @@ LPDIRECT3DTEXTURE9 createTextureSurface(D3dCtx *d3dCtx,
}
getTexWidthHeight(deviceInfo, &width, &height);
- format = getTexFormat(internalFormat);
+ format = getTexFormat(textureFormat);
// If format not support, the utility function will adjust the
// calling parameters automatically
@@ -789,7 +795,7 @@ LPDIRECT3DTEXTURE9 createTextureSurface(D3dCtx *d3dCtx,
// create a DirectDraw Texture surface of specific width and height
LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx,
jint numLevels,
- jint internalFormat,
+ jint textureFormat,
jint width,
jint height,
jint depth)
@@ -806,12 +812,10 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx,
texHeight = height;
texDepth = depth;
-
if (!deviceInfo->supportMipmap) {
numLevels = 1;
}
-
// Found a texture bigger than width/height
if (deviceInfo->texturePow2Only) {
for (texWidth=1; width > texWidth; texWidth <<= 1);
@@ -819,7 +823,6 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx,
for (texDepth=1; depth > texDepth; texDepth <<= 1);
}
-
if (deviceInfo->textureSquareOnly) {
if (texWidth >= texHeight) {
texHeight = texWidth;
@@ -864,8 +867,7 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx,
texDepth = deviceInfo->maxTextureDepth;
}
-
- format = getTexFormat(internalFormat);
+ format = getTexFormat(textureFormat);
// If format not support, the utility function will adjust the
// calling parameters automatically
@@ -886,6 +888,9 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx,
}
+// TODO : No need to reverse the Y axis.
+// Handle more format ------ Chien.
+
// copy data from DirectDraw surface to memory
// and reverse the Y axis
void copyDataFromSurface(jint internalFormat,
@@ -1525,7 +1530,7 @@ void copyDataToSurfaceABGR(jint internalFormat,
int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
- int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
+ int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
int rshift = firstBit(ddpf->dwRBitMask);
int gshift = firstBit(ddpf->dwGBitMask);
int bshift = firstBit(ddpf->dwBBitMask);
@@ -1539,7 +1544,7 @@ void copyDataToSurfaceABGR(jint internalFormat,
src = srcRow;
dst = destRow;
for (int j=xoffset; j < xlimit; j++) {
- if (aDiscard >= 0) {
+ if (aDiscard >= 0) {
a = (*src++) >> aDiscard;
} else {
a = (*src++) >> -aDiscard;
@@ -1947,7 +1952,6 @@ void copyDataToSurfaceABGR(jint internalFormat,
int ashift = firstBit(ddpf->dwRGBAlphaBitMask);
DWORD mask;
-
if ((ddpf->dwRGBBitCount <= 32) &&
(ddpf->dwRGBBitCount > 24)) {
destRow += (xoffset << 2);
@@ -2300,7 +2304,7 @@ void copyDataToSurfaceBGR(jint internalFormat,
ddpf->dwRGBBitCount);
}
}
- } else if (internalFormat == LUMINANCE_ALPHA) {
+ } else if (internalFormat == LUMINANCE_ALPHA) {
int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
@@ -8910,6 +8914,1771 @@ void copyDataToSurfaceGray(jint internalFormat,
}
+/**************** NEW (1.5.0 stuff) ****************/
+/* Note this method only works on little endian architecture */
+void copyInt_ARGB_DataToSurface(jint textureFormat,
+ PIXELFORMAT *ddpf,
+ unsigned char* pRect,
+ DWORD rectPitch,
+ jbyte *data,
+ jint xoffset, jint yoffset,
+ DWORD xlimit, DWORD ylimit,
+ jint subWidth)
+{
+ unsigned char *src;
+ unsigned char *dst;
+ DWORD r, g, b, a, l;
+ const DWORD srcPitch = subWidth*4;
+ unsigned char *srcRow = (unsigned char *) data;
+ unsigned char *destRow = pRect + rectPitch*yoffset;
+
+ if ((textureFormat == J3D_RGBA) ||
+ (textureFormat == J3D_RGB)) {
+ /* printf("copyInt_ARGB_DataToSurface : RGBBitCount = %d \n",
+ ddpf->dwRGBBitCount); */
+ if ((ddpf->dwRGBBitCount == 32) &&
+ (ddpf->dwRBitMask == 0xff0000) &&
+ (ddpf->dwGBitMask == 0xff00) &&
+ (ddpf->dwBBitMask == 0xff)) {
+ // Optimize for most common case
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ *dst++ = *src++; /* b */
+ *dst++ = *src++; /* g */
+ *dst++ = *src++; /* r */
+ *dst++ = *src++; /* a */
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount == 16) &&
+ (ddpf->dwRBitMask == 0xf00) &&
+ (ddpf->dwGBitMask == 0xf0) &&
+ (ddpf->dwBBitMask == 0xf)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ b = (*src++) >> 4; // discard the lower 4 bit
+ g = (*src++) >> 4;
+ r = (*src++) >> 4;
+ a = (*src++) >> 4;
+ *dst++ = (g << 4) | b;
+ *dst++ = (a << 4) | r;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+
+ } else { // handle less common (even weird) format
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ int ashift = firstBit(ddpf->dwRGBAlphaBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) >> -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) >> -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) >> -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) >> -aDiscard;
+ }
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) |(a << ashift));
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ // should not happen, RGBBitCount > 32. Even DirectX
+ // RGB mask can't address it.
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ }
+ } else if (textureFormat == LUMINANCE_ALPHA) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ int ashift = firstBit(ddpf->dwRGBAlphaBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) |(a << ashift));
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if (textureFormat == ALPHA) {
+ int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
+ int ashift = firstBit(ddpf->dwRGBAlphaBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ src += 3;
+ mask = a << ashift;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ src += 3;
+ mask = a << ashift;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ src += 3;
+ mask = (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (aDiscard >= 0) {
+ a = (*src++) >> aDiscard;
+ } else {
+ a = (*src++) << -aDiscard;
+ }
+ src += 3;
+ *dst++ = (byte) (a << ashift);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if ((textureFormat == LUMINANCE) ||
+ (textureFormat == INTENSITY)) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int aDiscard = 8-ucountBits(ddpf->dwRGBAlphaBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ int ashift = firstBit(ddpf->dwRGBAlphaBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = l >> aDiscard;
+ } else {
+ a = l << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = l >> aDiscard;
+ } else {
+ a = l << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = l >> aDiscard;
+ } else {
+ a = l << -aDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | (a << ashift);
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ if (aDiscard >= 0) {
+ a = l >> aDiscard;
+ } else {
+ a = l << -aDiscard;
+ }
+ *dst++ = (byte) ((r << rshift) |
+ (g << gshift) |
+ (b << bshift) |
+ (a << ashift));
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else {
+ printf("Texture format %d not support.\n", textureFormat);
+ }
+}
+
+/* Note this method only works on little endian architecture */
+void copyInt_XRGB_DataToSurface(jint textureFormat,
+ PIXELFORMAT *ddpf,
+ unsigned char* pRect,
+ DWORD rectPitch,
+ jbyte *data,
+ jint xoffset, jint yoffset,
+ DWORD xlimit, DWORD ylimit,
+ jint subWidth)
+{
+ unsigned char *src;
+ unsigned char *dst;
+ DWORD r, g, b, a, l;
+ const DWORD srcPitch = subWidth*4;
+ unsigned char *srcRow = (unsigned char *) data;
+ unsigned char *destRow = pRect + rectPitch*yoffset;
+
+ if ((textureFormat == J3D_RGBA) ||
+ (textureFormat == J3D_RGB)) {
+ /* printf("copyInt_XRGB_DataToSurface : RGBBitCount = %d \n",
+ ddpf->dwRGBBitCount); */
+ if ((ddpf->dwRGBBitCount == 32) &&
+ (ddpf->dwRBitMask == 0xff0000) &&
+ (ddpf->dwGBitMask == 0xff00) &&
+ (ddpf->dwBBitMask == 0xff)) {
+ // Optimize for most common case
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ *dst++ = *src++; /* b */
+ *dst++ = *src++; /* g */
+ *dst++ = *src++; /* r */
+ *dst++ = 0xff; *src++; /* a */
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount == 16) &&
+ (ddpf->dwRBitMask == 0xf00) &&
+ (ddpf->dwGBitMask == 0xf0) &&
+ (ddpf->dwBBitMask == 0xf)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ b = (*src++) >> 4; // discard the lower 4 bit
+ g = (*src++) >> 4;
+ r = (*src++) >> 4;
+ *src++; /* a */
+ *dst++ = (g << 4) | b;
+ *dst++ = 0xf0 | r;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else { // handle less common (even weird) format
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ *src++; /* a */
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ // should not happen, RGBBitCount > 32. Even DirectX
+ // RGB mask can't address it.
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ }
+ } else if (textureFormat == LUMINANCE_ALPHA) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src++;
+ src++;
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *src++; /* a */
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) |ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if (textureFormat == ALPHA) {
+ byte m1 = (byte) (ddpf->dwRGBAlphaBitMask & 0xff);
+ byte m2 = (byte) ((ddpf->dwRGBAlphaBitMask >> 8) & 0xff);
+ byte m3 = (byte) ((ddpf->dwRGBAlphaBitMask >> 16) & 0xff);
+ byte m4 = (byte) ((ddpf->dwRGBAlphaBitMask >> 24) & 0xff);
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ *dst++ = m3;
+ *dst++ = m4;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ *dst++ = m3;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if ((textureFormat == LUMINANCE) ||
+ (textureFormat == INTENSITY)) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *dst++ = (byte) ((r << rshift) |
+ (g << gshift) |
+ (b << bshift) |
+ ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else {
+ printf("Texture format %d not support.\n", textureFormat);
+ }
+}
+
+/* Note this method only works on little endian architecture */
+void copyInt_XBGR_DataToSurface(jint textureFormat,
+ PIXELFORMAT *ddpf,
+ unsigned char* pRect,
+ DWORD rectPitch,
+ jbyte *data,
+ jint xoffset, jint yoffset,
+ DWORD xlimit, DWORD ylimit,
+ jint subWidth)
+{
+ unsigned char *src;
+ unsigned char *dst;
+ DWORD r, g, b, a, l;
+ const DWORD srcPitch = subWidth*4;
+ unsigned char *srcRow = (unsigned char *) data;
+ unsigned char *destRow = pRect + rectPitch*yoffset;
+
+ if ((textureFormat == J3D_RGBA) ||
+ (textureFormat == J3D_RGB)) {
+ /* printf("copyInt_XRGB_DataToSurface : RGBBitCount = %d \n",
+ ddpf->dwRGBBitCount); */
+ if ((ddpf->dwRGBBitCount == 32) &&
+ (ddpf->dwRBitMask == 0xff0000) &&
+ (ddpf->dwGBitMask == 0xff00) &&
+ (ddpf->dwBBitMask == 0xff)) {
+ // Optimize for most common case
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ r = *src++;
+ g = *src++;
+ b = *src++;
+ *dst++ = b; /* b */
+ *dst++ = g; /* g */
+ *dst++ = r; /* r */
+ *dst++ = 0xff; *src++; /* a */
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount == 16) &&
+ (ddpf->dwRBitMask == 0xf00) &&
+ (ddpf->dwGBitMask == 0xf0) &&
+ (ddpf->dwBBitMask == 0xf)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ r = (*src++) >> 4; // discard the lower 4 bit
+ g = (*src++) >> 4;
+ b = (*src++) >> 4;
+ *src++; /* a */
+ *dst++ = (g << 4) | b;
+ *dst++ = 0xf0 | r;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else { // handle less common (even weird) format
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ *src++; /* a */
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ if (rDiscard >= 0) {
+ r = (*src++) >> rDiscard;
+ } else {
+ r = (*src++) << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = (*src++) >> gDiscard;
+ } else {
+ g = (*src++) >> -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = (*src++) >> bDiscard;
+ } else {
+ b = (*src++) >> -bDiscard;
+ }
+ *src++; /* a */
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ // should not happen, RGBBitCount > 32. Even DirectX
+ // RGB mask can't address it.
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ }
+ } else if (textureFormat == LUMINANCE_ALPHA) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ src += 3;
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ src += 3;
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ src += 3;
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src++;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ src += 3;
+ *dst++ = (byte) ((r << rshift) | (g << gshift) |
+ (b << bshift) |ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if (textureFormat == ALPHA) {
+ byte m1 = (byte) (ddpf->dwRGBAlphaBitMask & 0xff);
+ byte m2 = (byte) ((ddpf->dwRGBAlphaBitMask >> 8) & 0xff);
+ byte m3 = (byte) ((ddpf->dwRGBAlphaBitMask >> 16) & 0xff);
+ byte m4 = (byte) ((ddpf->dwRGBAlphaBitMask >> 24) & 0xff);
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ *dst++ = m3;
+ *dst++ = m4;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ *dst++ = m3;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ *dst++ = m2;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ src += 4;
+ *dst++ = m1;
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else if ((textureFormat == LUMINANCE) ||
+ (textureFormat == INTENSITY)) {
+ int rDiscard = 8-ucountBits(ddpf->dwRBitMask);
+ int gDiscard = 8-ucountBits(ddpf->dwGBitMask);
+ int bDiscard = 8-ucountBits(ddpf->dwBBitMask);
+ int rshift = firstBit(ddpf->dwRBitMask);
+ int gshift = firstBit(ddpf->dwGBitMask);
+ int bshift = firstBit(ddpf->dwBBitMask);
+ DWORD mask;
+
+ if ((ddpf->dwRGBBitCount <= 32) &&
+ (ddpf->dwRGBBitCount > 24)) {
+ destRow += (xoffset << 2);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ *dst++ = (byte) ((mask >> 24) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 24) &&
+ (ddpf->dwRGBBitCount > 16)) {
+ destRow += (xoffset*3);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ *dst++ = (byte) ((mask >> 16) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if ((ddpf->dwRGBBitCount <= 16) &&
+ (ddpf->dwRGBBitCount > 8)) {
+ destRow += (xoffset << 1);
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ mask = (r << rshift) | (g << gshift) |
+ (b << bshift) | ddpf->dwRGBAlphaBitMask;
+ *dst++ = (byte) (mask & 0xff);
+ *dst++ = (byte) ((mask >> 8) & 0xff);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else if (ddpf->dwRGBBitCount <= 8) {
+ destRow += xoffset;
+ for (int i=yoffset; i < ylimit; i++) {
+ src = srcRow;
+ dst = destRow;
+ for (int j=xoffset; j < xlimit; j++) {
+ l = *src;
+ src += 4;
+ if (rDiscard >= 0) {
+ r = l >> rDiscard;
+ } else {
+ r = l << -rDiscard;
+ }
+ if (gDiscard >= 0) {
+ g = l >> gDiscard;
+ } else {
+ g = l << -gDiscard;
+ }
+ if (bDiscard >= 0) {
+ b = l >> bDiscard;
+ } else {
+ b = l << -bDiscard;
+ }
+ *dst++ = (byte) ((r << rshift) |
+ (g << gshift) |
+ (b << bshift) |
+ ddpf->dwRGBAlphaBitMask);
+ }
+ srcRow += srcPitch;
+ destRow += rectPitch;
+ }
+ } else {
+ printf("Texture memory with RGBBitCount = %d not support. \n",
+ ddpf->dwRGBBitCount);
+ }
+ } else {
+ printf("Texture format %d not support.\n", textureFormat);
+ }
+}
/*
* Copy data from memory to DirectDraw surface
@@ -8923,8 +10692,8 @@ void copyDataToSurfaceGray(jint internalFormat,
* offset = (xoffset, yoffset)
*
*/
-void copyDataToSurface(jint storedFormat,
- jint internalFormat,
+void copyDataToSurface(jint imageFormat,
+ jint textureFormat,
jint xoffset, jint yoffset,
jint imgXOffset, jint imgYOffset,
jint subWidth, jint subHeight,
@@ -8965,61 +10734,103 @@ void copyDataToSurface(jint storedFormat,
return;
}
int offset = tilew*imgYOffset + imgXOffset;
- switch (storedFormat) {
- case IMAGE_FORMAT_BYTE_RGBA :
- // This is the one we use when byReference = false
- copyDataToSurfaceRGBA(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + (offset << 2),
- xoffset, yoffset,
- xlimit, ylimit, tilew);
- break;
- case IMAGE_FORMAT_BYTE_RGB:
- copyDataToSurfaceRGB(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + 3*offset,
- xoffset, yoffset,
- xlimit, ylimit, tilew);
- break;
- case IMAGE_FORMAT_BYTE_ABGR:
- copyDataToSurfaceABGR(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + (offset << 2),
- xoffset, yoffset,
- xlimit, ylimit, tilew);
- break;
- case IMAGE_FORMAT_BYTE_BGR:
- copyDataToSurfaceBGR(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + 3*offset,
- xoffset, yoffset,
- xlimit, ylimit, tilew);
- break;
- case IMAGE_FORMAT_BYTE_LA:
- copyDataToSurfaceLA(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + (offset << 1),
- xoffset, yoffset,
- xlimit, ylimit, tilew);
- break;
- case IMAGE_FORMAT_BYTE_GRAY:
- copyDataToSurfaceGray(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + offset,
- xoffset, yoffset,
- xlimit, ylimit, tilew);
+ switch (imageFormat) {
+ case IMAGE_FORMAT_BYTE_RGBA :
+ /* printf("[IMAGE_FORMAT_BYTE_RGBA] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+
+ // This is the one we use when byReference = false
+ copyDataToSurfaceRGBA(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 2),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_BYTE_RGB:
+ /* printf("[IMAGE_FORMAT_BYTE_RGB] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+ copyDataToSurfaceRGB(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + 3*offset,
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_BYTE_ABGR:
+ /* printf("[IMAGE_FORMAT_BYTE_ABGR] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+
+ copyDataToSurfaceABGR(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 2),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_BYTE_BGR:
+ /* printf("[IMAGE_FORMAT_BYTE_BGR] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+
+ copyDataToSurfaceBGR(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + 3*offset,
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_BYTE_LA:
+ copyDataToSurfaceLA(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 1),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_BYTE_GRAY:
+ copyDataToSurfaceGray(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + offset,
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ case IMAGE_FORMAT_INT_BGR:
+ /* printf("[IMAGE_FORMAT_INT_BGR] imageFormat %d, textureFormat %d not support !\n",
+ imageFormat, textureFormat); */
+ copyInt_XBGR_DataToSurface(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 2),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+
+ break;
+ case IMAGE_FORMAT_INT_RGB:
+ /* printf("[IMAGE_FORMAT_INT_RGB] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+ copyInt_XRGB_DataToSurface(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 2),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
break;
- default: // should not happen
- printf("[Java 3D] StoredFormat %d, internalFormat %d not support !\n",
- storedFormat, internalFormat);
+ case IMAGE_FORMAT_INT_ARGB:
+ /* printf("[IMAGE_FORMAT_INT_ABGR] imageFormat %d, textureFormat %d\n",
+ imageFormat, textureFormat); */
+ copyInt_ARGB_DataToSurface(textureFormat, &ddpf,
+ (unsigned char *) lockedRect.pBits,
+ lockedRect.Pitch,
+ data + (offset << 2),
+ xoffset, yoffset,
+ xlimit, ylimit, tilew);
+ break;
+ default: // should not happen
+ printf("[Java 3D] imageFormat %d, textureFormat %d not support !\n",
+ imageFormat, textureFormat);
}
-
+
hr = surf->UnlockRect(level);
if (FAILED(hr)) {
printf("Fail to unlock surface: %s\n", DXGetErrorString9(hr));
@@ -9307,61 +11118,6 @@ void copyDataToSurfaceGray(jint internalFormat,
}
}
-
-// copy the texture data to DirectDraw surface
-void copyDataToSurface(jint storedFormat,
- jint internalFormat,
- jint xoffset, jint yoffset,
- jint imgXOffset, jint imgYOffset,
- jint subWidth, jint subHeight,
- jint tilew, jshort *data,
- LPDIRECT3DTEXTURE9 surf,
- jint level)
-{
- D3DSURFACE_DESC ddsd;
- D3DLOCKED_RECT lockedRect;
- PIXELFORMAT ddpf;
- HRESULT hr;
-
- if (surf == NULL) {
- return;
- }
-
- surf->GetLevelDesc(level, &ddsd);
- DWORD width = ddsd.Width;
- DWORD height = ddsd.Height;
- computePixelFormat(&ddpf, ddsd.Format);
-
- if ((xoffset >= width) || (yoffset >= height)) {
- return;
- }
- DWORD xlimit = min(xoffset + subWidth, width);
- DWORD ylimit = min(yoffset + subHeight, height);
-
- hr = surf->LockRect(level, &lockedRect, NULL, 0);
-
- if (FAILED(hr)) {
- printf("Fail to lock surface: %s\n", DXGetErrorString9(hr));
- return;
- }
-
- int offset = tilew*imgYOffset + imgXOffset;
-
- copyDataToSurfaceGray(internalFormat, &ddpf,
- (unsigned char *) lockedRect.pBits,
- lockedRect.Pitch,
- data + (offset << 1),
- xoffset, yoffset,
- xlimit, ylimit, tilew);
-
- hr = surf->UnlockRect(level);
- if (FAILED(hr)) {
- printf("Fail to unlock surface: %s\n", DXGetErrorString9(hr));
- return;
- }
-}
-
-
// copy data from DirectDraw depth surface to memory
// and reverse the Y axis
void copyDepthFromSurface(jint xoffset, jint yoffset,
@@ -10291,464 +12047,6 @@ void copyDepthToSurface(D3dCtx *d3dCtx,
}
}
-// composite data from memory to DirectDraw surface
-void compositeDataToSurface(jint px, jint py,
- jint xoffset, jint yoffset,
- jint subWidth, jint subHeight,
- jint dataWidth,
- jbyte *data,
- LPDIRECT3DSURFACE9 surf)
-{
- D3DSURFACE_DESC ddsd;
- D3DLOCKED_RECT lockedRect;
- PIXELFORMAT ddpf;
-
- HRESULT hr;
-
- if (surf == NULL) {
- return;
- }
-
- surf->GetDesc(&ddsd);
- DWORD width = ddsd.Width;
- DWORD height = ddsd.Height;
- computePixelFormat(&ddpf, ddsd.Format);
-
- if ((xoffset >= width) || (yoffset >= height)) {
- return;
- }
-
- DWORD xlimit = min(xoffset + subWidth, width);
- DWORD ylimit = min(yoffset + subHeight, height);
-
- hr = surf->LockRect(&lockedRect, NULL, 0);
-
- if (FAILED(hr)) {
- printf("Fail to lock rendering surface: %s\n", DXGetErrorString9(hr));
- return;
- }
-
- unsigned char *src;
- unsigned char *dst;
- DWORD r, g, b, a;
- DWORD srcPitch;
- int offset = (xoffset + yoffset*dataWidth) << 2;
- unsigned char *srcRow = (unsigned char *) data + offset;
- unsigned char *destRow = ((unsigned char *) lockedRect.pBits) +
- ((px + xoffset) << 2) + (py + yoffset)*lockedRect.Pitch;
- unsigned char a2;
- float inv = 1.0f/255.0f;
- ddpf.noAlpha = true;
-
- if (ddpf.dwRGBAlphaBitMask != 0) {
- ddpf.noAlpha = false;
- }
-
- srcPitch = dataWidth << 2;
-
- if ((ddpf.dwRGBBitCount == 32) &&
- (ddpf.dwRBitMask == 0xff0000) &&
- (ddpf.dwGBitMask == 0xff00) &&
- (ddpf.dwBBitMask == 0xff)) {
- // Most common case
- for (int i=yoffset; i < ylimit; i++) {
- src = srcRow;
- dst = destRow;
- for (int j=xoffset; j < xlimit; j++) {
- a = *src++;
- b = *src++;
- g = *src++;
- r = *src++;
-
- if (a != 0) {
- if (a == 0xff) {
- *dst++ = b;
- *dst++ = g;
- *dst++ = r;
- *dst++ = 0xff;
- } else {
- a2 = 255-a;
- *dst++ = (unsigned char)((*dst * a2 + b * a)*inv);
- *dst++ = (unsigned char)((*dst * a2 + g * a)*inv);
- *dst++ = (unsigned char)((*dst * a2 + r * a)*inv);
- if (ddpf.noAlpha) {
- *dst++ = a;
- } else {
- *dst++ = (unsigned char)((*dst * a2 + a * a)*inv);
- }
- }
- } else {
- dst += 4;
- }
- }
- srcRow += srcPitch;
- destRow += lockedRect.Pitch;
- }
- } else { // handle less common (even weird) format
- int rshift = firstBit(ddpf.dwRBitMask) +
- ucountBits(ddpf.dwRBitMask) - 8;
- int gshift = firstBit(ddpf.dwGBitMask) +
- ucountBits(ddpf.dwGBitMask) - 8;
- int bshift = firstBit(ddpf.dwBBitMask) +
- ucountBits(ddpf.dwBBitMask) - 8;
- int ashift = firstBit(ddpf.dwRGBAlphaBitMask) +
- ucountBits(ddpf.dwRGBAlphaBitMask) - 8;
-
- DWORD mask, dmask;
- DWORD dr, dg, db, da;
-
- if ((ddpf.dwRGBBitCount <= 32) &&
- (ddpf.dwRGBBitCount > 24)) {
- for (int i=yoffset; i < ylimit; i++) {
- src = srcRow;
- dst = destRow;
- for (int j=xoffset; j < xlimit; j++) {
- a = *src++;
- b = *src++;
- g = *src++;
- r = *src++;
-
- if (a != 0) {
- if (a != 0xff) {
- dmask = (*(dst+3) << 24) |
- (*(dst+2) << 16) |
- (*(dst+1) << 8) |
- *dst;
- if (rshift >= 0) {
- dr = (byte) ((dmask & ddpf.dwRBitMask) >>
- rshift);
- } else {
- dr = (byte) ((dmask & ddpf.dwRBitMask) <<
- -rshift);
- }
- if (gshift >= 0) {
- dg = (byte) ((dmask & ddpf.dwGBitMask) >>
- gshift);
- } else {
- dg = (byte) ((dmask & ddpf.dwGBitMask) <<
- -gshift);
- }
- if (bshift >= 0) {
- db = (byte) ((dmask & ddpf.dwBBitMask) >>
- bshift);
- } else {
- db = (byte) ((dmask & ddpf.dwBBitMask) <<
- -bshift);
- }
- a2 = 255 - a;
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) >>
- ashift);
- } else {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) <<
- -ashift);
- }
- a = DWORD((da * a2 + a * a)*inv);
- }
-
- g = DWORD((dg * a2 + g * a)*inv);
- b = DWORD((db * a2 + b * a)*inv);
- r = DWORD((dr * a2 + r * a)*inv);
- }
- if (rshift >= 0) {
- mask = (r << rshift) & ddpf.dwRBitMask;
- } else {
- mask = (r >> -rshift) & ddpf.dwRBitMask;
- }
- if (gshift >= 0) {
- mask |= (g << gshift) & ddpf.dwGBitMask;
- } else {
- mask |= (g >> -gshift) & ddpf.dwGBitMask;
- }
- if (bshift >= 0) {
- mask |= (b << bshift) & ddpf.dwBBitMask;
- } else {
- mask |= (b >> -bshift) & ddpf.dwBBitMask;
- }
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- mask |= (a << ashift) & ddpf.dwRGBAlphaBitMask;
- } else {
- mask |= (a >> -ashift) & ddpf.dwRGBAlphaBitMask;
- }
- }
- *dst++ = (byte) (mask & 0xff);
- *dst++ = (byte) ((mask >> 8) & 0xff);
- *dst++ = (byte) ((mask >> 16) & 0xff);
- *dst++ = (byte) ((mask >> 24) & 0xff);
- } else {
- dst += 4;
- }
- }
- srcRow += srcPitch;
- destRow += lockedRect.Pitch;
- }
- } else if ((ddpf.dwRGBBitCount <= 24) &&
- (ddpf.dwRGBBitCount > 16)) {
- for (int i=yoffset; i < ylimit; i++) {
- src = srcRow;
- dst = destRow;
- for (int j=xoffset; j < xlimit; j++) {
- a = *src++;
- b = *src++;
- g = *src++;
- r = *src++;
- if (a != 0) {
- if (a != 0xff) {
- dmask = (*(dst+2) << 16) |
- (*(dst+1) << 8) |
- *dst;
- if (rshift >= 0) {
- dr = (byte) ((dmask & ddpf.dwRBitMask) >>
- rshift);
- } else {
- dr = (byte) ((dmask & ddpf.dwRBitMask) <<
- -rshift);
- }
- if (gshift >= 0) {
- dg = (byte) ((dmask & ddpf.dwGBitMask) >>
- gshift);
- } else {
- dg = (byte) ((dmask & ddpf.dwGBitMask) <<
- -gshift);
- }
- if (bshift >= 0) {
- db = (byte) ((dmask & ddpf.dwBBitMask) >>
- bshift);
- } else {
- db = (byte) ((dmask & ddpf.dwBBitMask) <<
- -bshift);
- }
- a2 = 255 - a;
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) >>
- ashift);
- } else {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) <<
- -ashift);
- }
- a = DWORD((da * a2 + a * a)*inv);
- }
- g = DWORD((dg * a2 + g * a)*inv);
- b = DWORD((db * a2 + b * a)*inv);
- r = DWORD((dr * a2 + r * a)*inv);
- }
- if (rshift >= 0) {
- mask = (r << rshift) & ddpf.dwRBitMask;
- } else {
- mask = (r >> -rshift) & ddpf.dwRBitMask;
- }
- if (gshift >= 0) {
- mask |= (g << gshift) & ddpf.dwGBitMask;
- } else {
- mask |= (g >> -gshift) & ddpf.dwGBitMask;
- }
- if (bshift >= 0) {
- mask |= (b << bshift) & ddpf.dwBBitMask;
- } else {
- mask |= (b >> -bshift) & ddpf.dwBBitMask;
- }
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- mask |= (a << ashift) & ddpf.dwRGBAlphaBitMask;
- } else {
- mask |= (a >> -ashift) & ddpf.dwRGBAlphaBitMask;
- }
- }
- *dst++ = (byte) (mask & 0xff);
- *dst++ = (byte) ((mask >> 8) & 0xff);
- *dst++ = (byte) ((mask >> 16) & 0xff);
- } else {
- dst += 3;
- }
- }
- srcRow += srcPitch;
- destRow += lockedRect.Pitch;
- }
- } else if ((ddpf.dwRGBBitCount <= 16) &&
- (ddpf.dwRGBBitCount > 8)) {
-
- for (int i=yoffset; i < ylimit; i++) {
- src = srcRow;
- dst = destRow;
- for (int j=xoffset; j < xlimit; j++) {
- a = *src++;
- b = *src++;
- g = *src++;
- r = *src++;
-
- if (a != 0) {
- if (a != 0xff) {
- dmask = (*(dst+1) << 8) | *dst;
-
- if (rshift >= 0) {
- dr = (byte) ((dmask & ddpf.dwRBitMask) >>
- rshift);
- } else {
- dr = (byte) ((dmask & ddpf.dwRBitMask) <<
- -rshift);
- }
- if (gshift >= 0) {
- dg = (byte) ((dmask & ddpf.dwGBitMask) >>
- gshift);
- } else {
- dg = (byte) ((dmask & ddpf.dwGBitMask) <<
- -gshift);
- }
- if (bshift >= 0) {
- db = (byte) ((dmask & ddpf.dwBBitMask) >>
- bshift);
- } else {
- db = (byte) ((dmask & ddpf.dwBBitMask) <<
- -bshift);
- }
- a2 = 255 - a;
-
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) >>
- ashift);
- } else {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) <<
- -ashift);
- }
- a = DWORD( (da * a2 + a * a)*inv);
- }
-
- g = DWORD((dg * a2 + g * a)*inv);
- b = DWORD((db * a2 + b * a)*inv);
- r = DWORD((dr * a2 + r * a)*inv);
- }
-
- if (rshift >= 0) {
- mask = (r << rshift) & ddpf.dwRBitMask;
- } else {
- mask = (r >> -rshift) & ddpf.dwRBitMask;
- }
- if (gshift >= 0) {
- mask |= ((g << gshift) & ddpf.dwGBitMask);
- } else {
- mask |= ((g >> -gshift) & ddpf.dwGBitMask);
- }
- if (bshift >= 0) {
- mask |= ((b << bshift) & ddpf.dwBBitMask);
- } else {
- mask |= ((b >> -bshift) & ddpf.dwBBitMask);
- }
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- mask |= ((a << ashift) & ddpf.dwRGBAlphaBitMask);
- } else {
- mask |= ((a >> -ashift) & ddpf.dwRGBAlphaBitMask);
- }
- }
-
- *dst++ = (byte) (mask & 0xff);
- *dst++ = (byte) ((mask >> 8) & 0xff);
- } else {
- dst += 2;
- }
- }
- srcRow += srcPitch;
- destRow += lockedRect.Pitch;
- }
- } else if (ddpf.dwRGBBitCount <= 8) {
- for (int i=yoffset; i < ylimit; i++) {
- src = srcRow;
- dst = destRow;
- for (int j=xoffset; j < xlimit; j++) {
- a = *src++;
- b = *src++;
- g = *src++;
- r = *src++;
- if (a != 0) {
- if (a != 0xff) {
- dmask = *dst;
- if (rshift >= 0) {
- dr = (byte) ((dmask & ddpf.dwRBitMask) >>
- rshift);
- } else {
- dr = (byte) ((dmask & ddpf.dwRBitMask) <<
- -rshift);
- }
- if (gshift >= 0) {
- dg = (byte) ((dmask & ddpf.dwGBitMask) >>
- gshift);
- } else {
- dg = (byte) ((dmask & ddpf.dwGBitMask) <<
- -gshift);
- }
- if (bshift >= 0) {
- db = (byte) ((dmask & ddpf.dwBBitMask) >>
- bshift);
- } else {
- db = (byte) ((dmask & ddpf.dwBBitMask) <<
- -bshift);
- }
- a2 = 255 - a;
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) >>
- ashift);
- } else {
- da = (byte) ((dmask & ddpf.dwRGBAlphaBitMask) <<
- -ashift);
- }
- a = DWORD((da * a2 + a * a)*inv);
- }
-
- g = DWORD((dg * a2 + g * a)*inv);
- b = DWORD((db * a2 + b * a)*inv);
- r = DWORD((dr * a2 + r * a)*inv);
- }
- if (rshift >= 0) {
- mask = (r << rshift) & ddpf.dwRBitMask;
- } else {
- mask = (r >> -rshift) & ddpf.dwRBitMask;
- }
- if (gshift >= 0) {
- mask |= (g << gshift) & ddpf.dwGBitMask;
- } else {
- mask |= (g >> -gshift) & ddpf.dwGBitMask;
- }
- if (bshift >= 0) {
- mask |= (b << bshift) & ddpf.dwBBitMask;
- } else {
- mask |= (b >> -bshift) & ddpf.dwBBitMask;
- }
- if (!ddpf.noAlpha) {
- if (ashift >= 0) {
- mask |= (a << ashift) & ddpf.dwRGBAlphaBitMask;
- } else {
- mask |= (a >> -ashift) & ddpf.dwRGBAlphaBitMask;
- }
- }
- *dst++ = (byte) (mask & 0xff);
- } else {
- dst++;
- }
- }
- srcRow += srcPitch;
- destRow += lockedRect.Pitch;
- }
- } else {
- // should not happen, RGBBitCount > 32. Even DirectX
- // RGB mask can't address it.
- printf("Texture memory with RGBBitCount = %d not support. \n",
- ddpf.dwRGBBitCount);
- }
- }
-
- hr = surf->UnlockRect();
- if (FAILED(hr)) {
- printf("Fail to unlock rendering surface: %s\n", DXGetErrorString9(hr));
- return;
- }
-}
-
-
void copyDataToVolume(jint storedFormat,
jint internalFormat,
jint xoffset, jint yoffset,
@@ -10992,74 +12290,6 @@ void copyDataToVolume(jint storedFormat,
}
}
-
-LPDIRECT3DTEXTURE9 createSurfaceFromImage(JNIEnv *env,
- jobject pa2d,
- jlong ctx,
- int width,
- int height,
- jbyteArray imageYdown)
-{
- GetDevice2();
-
- int internalFormat;
- jclass pa2d_class = env->GetObjectClass(pa2d);
-
- jfieldID id = env->GetFieldID(pa2d_class, "storedYdownFormat", "I");
- int storedFormat = env->GetIntField(pa2d, id);
-
- id = env->GetFieldID(pa2d_class, "internalFormat", "I");
- internalFormat = env->GetIntField(pa2d, id);
-
-
- switch (internalFormat) {
- case IMAGE_FORMAT_BYTE_RGBA:
- internalFormat = J3D_RGBA;
- break;
- case IMAGE_FORMAT_BYTE_RGB:
- internalFormat = J3D_RGB;
- break;
- case IMAGE_FORMAT_BYTE_LA:
- internalFormat = LUMINANCE_ALPHA;
- break;
- case IMAGE_FORMAT_BYTE_GRAY:
- case IMAGE_FORMAT_USHORT_GRAY:
- internalFormat = LUMINANCE;
- break;
- default:
- printf("Format %d not support for Image Component\n", internalFormat);
- return NULL;
- }
-
-
- LPDIRECT3DTEXTURE9 surf;
-
- surf = createTextureSurface(d3dCtx, 1, internalFormat,
- width, height);
-
- if (surf == NULL) {
- return NULL;
- }
-
- if (imageYdown != NULL) {
- if (storedFormat != IMAGE_FORMAT_USHORT_GRAY) {
- jbyte *byteData = (jbyte *) (env->GetPrimitiveArrayCritical(
- imageYdown, NULL));
- copyDataToSurface(storedFormat, internalFormat, 0, 0, 0, 0,
- width, height, width, byteData, surf, 0);
- env->ReleasePrimitiveArrayCritical(imageYdown, byteData, 0);
-
- } else {
- jshort *shortData = (jshort *)(env->GetPrimitiveArrayCritical(
- imageYdown, NULL));
- copyDataToSurface(storedFormat, internalFormat, 0, 0, 0, 0,
- width, height, width, shortData, surf, 0);
- env->ReleasePrimitiveArrayCritical(imageYdown, shortData, 0);
- }
- }
- return surf;
-}
-
VOID createLineModeIndexBuffer(D3dCtx *d3dCtx)
{
HRESULT hr;
diff --git a/src/native/d3d/D3dUtil.hpp b/src/native/d3d/D3dUtil.hpp
index 7e7ea44..8035792 100644
--- a/src/native/d3d/D3dUtil.hpp
+++ b/src/native/d3d/D3dUtil.hpp
@@ -272,16 +272,10 @@ void compositeDataToSurface(jint px, jint py,
extern void CopyTextureStage(LPDIRECT3DDEVICE9 device,
int fromLevel, int toLevel);
-
-extern LPDIRECT3DTEXTURE9 createSurfaceFromImage(JNIEnv *env,
- jobject pa2d,
- jlong ctx,
- int width,
- int height,
- jbyteArray pixels);
extern "C"
DWORD countBits(DWORD mask); // Define in MasterControl.c
+extern void throwAssert(JNIEnv *env, char *str);
extern BOOL createQuadIndices(D3dCtx *d3dCtx, int vcount);
extern VOID createLineModeIndexBuffer(D3dCtx *d3dCtx);
extern char *getPixelFormatName(D3DFORMAT format);