ハードウェアから画像を取得し、(JOGL を使用して) OpenGL で表示するために C ライブラリと連携するプログラムを Java で作成しています。したがって、ワークフローは次のとおりです。
Hardware -> C -> disk image file -> Java -> JOGL
私はそのJava -> JOGL
部分がうまく機能しています。画像が完全に表示され、一度に複数の画像を読み込むことができます。私もHardware -> C
同様に機能しており、C の一時ビューアーは、画像が正常に作成されていることを示しています。
main()
問題の核心はこれです: C で Java プログラムのメソッドを起動し、C で JNI コードのみを使用して (作成した静的メソッドを使用して) イメージを表示できるようにしたいのです。ただし、これを行うと、画像が切り捨てられ、上位 20 行ほどしか取得できません。画像内のすべてのピクセルのピクセル値を確認できるため、画像全体を読み込んでいることがわかります。表示のみが切り捨てられます。ロードするすべての画像に対して同じ数のピクセルが表示されます。
これは一言で言えばCコードです:
int main () { ...
HMODULE * jvm_dll;
//HWND hWnd = GetConsoleWindow();
//ShowWindow( hWnd, SW_HIDE );
env = create_vm(&jvm, jvm_dll);
if (env == NULL) { return 1; }
//Create a new String array with one blank String
cls = (*env)->FindClass(env,"java/lang/String");
arg = (*env)->NewStringUTF(env,"");
args = (jobjectArray)(*env)->NewObjectArray(env, 1, cls, arg);
//Call the main method with the String array argument
cls = (*env)->FindClass(env, "path/to/package/program");
mID = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
(*env)->CallStaticVoidMethod(env, cls, mID, args);
PrintStackTrace(env);
blockAndClose(jvm, env, jvm_dll);
return ret;
}
int blockAndClose() {...
int ret = 0;
if (jvm == 0 || env == 0) {
FreeLibrary(*jvm_dll);
return 1;
}
ret = (*jvm)->DestroyJavaVM(jvm);
if(jvm_dll) {
FreeLibrary(*jvm_dll);
jvm_dll = 0;
}
env = 0;
jvm = 0;
return ret;
}
C の部分しか投稿していないことはわかっていますが、純粋に Java で実行すると、Java の部分が機能します。この時点で、C の部分は単なる「ランチャー」にすぎないので、コードの実行に影響する理由が気になります。助言がありますか?
編集:
画像を読み込むコードは次のとおりです。JAI を使用して、イメージをPlanarImage
タイプとしてロードします (TiledImage
クラスはサブクラスです)。
tempI = JAI.create("fileload", path);
DataBufferUShort dbOut = null;
ColorModel CM = PlanarImage.getDefaultColorModel(DataBuffer.TYPE_USHORT, tempI.getNumBands());
SampleModel SM = CM.createCompatibleSampleModel(tempI.getWidth(), tempI.getHeight());
//Ensure that the buffer is in the internal format (USHORT)
if (tempI.getData().getDataBuffer().getDataType() != DataBuffer.TYPE_USHORT) {
DataBuffer dBIn = tempI.getData().getDataBuffer();
short [] dBPixels = new short[dBIn.getSize()];
switch(dBIn.getDataType()) {
case DataBuffer.TYPE_BYTE:
DataBufferByte dBByte = (DataBufferByte)dBIn;
byte [] pByte = dBByte.getData();
for (int b = 0; b < pByte.length; b++)
{ dBPixels[b] = (short)((double)pByte[b] / 0xFF * 0xFFFF); }
dbOut = new DataBufferUShort(dBPixels, dBPixels.length);
break;
case DataBuffer.TYPE_SHORT:
DataBufferShort dBShort = (DataBufferShort)dBIn;
dBPixels = dBShort.getData();
dbOut = new DataBufferUShort(dBPixels, dBPixels.length);
break;
} //SWITCH DATA TYPE --END
WritableRaster rs = Raster.createWritableRaster(SM, dbOut, new Point(0,0));
tempI = new TiledImage(0,0,tempI.getWidth(),tempI.getHeight(),0,0,SM,CM);
((TiledImage)tempI).setData(rs);
}