Max 5 API Reference
00001 #include "jit.common.h" 00002 #include "jit.javaob.h" 00003 #include "ext_obex.h" 00004 00005 static t_symbol *ps_getmatrix,*ps_getcell,*ps_setall,*ps_setcell,*ps_setcell3d,*ps_val,*ps_plane; 00006 //JNI 00007 00008 00009 t_atom jit_java_jitmatrix_getcell_helper(JNIEnv *env, jobject obj, jobject array); 00010 jobject JNICALL jit_java_jitmatrix_getcell_int(JNIEnv *env, jobject obj, jobject array); 00011 jobject JNICALL jit_java_jitmatrix_getcell_float(JNIEnv *env, jobject obj, jobject array); 00012 jobject JNICALL jit_java_jitmatrix_getcell_double(JNIEnv *env, jobject obj, jobject array); 00013 t_atom jit_java_jitmatrix_getcell3d_helper(JNIEnv *env, jobject obj, jint x, jint y, jint z); 00014 jobject JNICALL jit_java_jitmatrix_getcell3d_atom(JNIEnv *env, jobject obj, jint x, jint y, jint z); 00015 jobject JNICALL jit_java_jitmatrix_getcell3d_int(JNIEnv *env, jobject obj, jint x, jint y, jint z); 00016 jobject JNICALL jit_java_jitmatrix_getcell3d_float(JNIEnv *env, jobject obj, jint x, jint y, jint z); 00017 jobject JNICALL jit_java_jitmatrix_getcell3d_double(JNIEnv *env, jobject obj, jint x, jint y, jint z); 00018 void JNICALL jit_java_jitmatrix_setall_double(JNIEnv *env, jobject obj, jdouble val); 00019 void JNICALL jit_java_jitmatrix_setcell_int(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array); 00020 void JNICALL jit_java_jitmatrix_setcell_float(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array); 00021 void JNICALL jit_java_jitmatrix_setcell_double(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array); 00022 void JNICALL jit_java_jitmatrix_setcell_plane_int(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jint val); 00023 void JNICALL jit_java_jitmatrix_setcell_plane_float(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jfloat val); 00024 void JNICALL jit_java_jitmatrix_setcell_plane_double(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jdouble val); 00025 void JNICALL jit_java_jitmatrix_setcell3d_int(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array); 00026 void JNICALL jit_java_jitmatrix_setcell3d_float(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array); 00027 void JNICALL jit_java_jitmatrix_setcell3d_double(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array); 00028 00029 00030 void jit_java_jitmatrix_register_natives(JNIEnv *env, jclass clazz); 00031 00032 //internal 00033 t_object *get_jit_java_jitobj(JNIEnv *env, jobject obj); 00034 jobject JNICALL jit_java_jitobj_returnvalue(JNIEnv *env, t_atom a); 00035 void jit_java_jitter_register_natives(JNIEnv*, jclass); 00036 00037 t_atom jit_java_jitmatrix_getcell_helper(JNIEnv *env, jobject obj, jobject array) 00038 { 00039 long i,ac=0; 00040 t_atom av[JIT_MATRIX_MAX_DIMCOUNT]; 00041 t_atom arv; 00042 t_max_err res; 00043 t_object *o; 00044 jint *elements; 00045 jboolean is_copy; 00046 00047 arv.a_type = A_NOTHING; 00048 00049 o = get_jit_java_jitobj(env,obj); 00050 if(!o) 00051 return arv; 00052 00053 if (array) { 00054 ac = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,array); 00055 if (ac>JIT_MATRIX_MAX_DIMCOUNT) 00056 ac = JIT_MATRIX_MAX_DIMCOUNT; 00057 00058 elements = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)array,&is_copy); 00059 checkException(env); // inefficient? 00060 00061 for(i=0;i<ac;i++) 00062 atom_setlong(av+i,elements[i]); 00063 if (is_copy) 00064 { 00065 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)array,elements,0); 00066 checkException(env); 00067 } 00068 00069 } 00070 00071 res = object_method_typed(o,ps_getcell,ac,av,&arv); 00072 00073 return arv; 00074 } 00075 00076 jobject JNICALL jit_java_jitmatrix_getcell_int(JNIEnv *env, jobject obj, jobject array) 00077 { 00078 t_atom arv; 00079 00080 arv = jit_java_jitmatrix_getcell_helper(env,obj,array); 00081 return jit_java_jitobj_returnvalue_intarray(env,arv); 00082 } 00083 00084 jobject JNICALL jit_java_jitmatrix_getcell_float(JNIEnv *env, jobject obj, jobject array) 00085 { 00086 t_atom arv; 00087 00088 arv = jit_java_jitmatrix_getcell_helper(env,obj,array); 00089 return jit_java_jitobj_returnvalue_floatarray(env,arv); 00090 } 00091 00092 jobject JNICALL jit_java_jitmatrix_getcell_double(JNIEnv *env, jobject obj, jobject array) 00093 { 00094 t_atom arv; 00095 00096 arv = jit_java_jitmatrix_getcell_helper(env,obj,array); 00097 return jit_java_jitobj_returnvalue_doublearray(env,arv); 00098 } 00099 00100 t_atom jit_java_jitmatrix_getcell3d_helper(JNIEnv *env, jobject obj, jint x, jint y, jint z) 00101 { 00102 t_atom a[3]; 00103 t_atom arv; 00104 t_max_err res; 00105 t_object *o; 00106 00107 arv.a_type = A_NOTHING; 00108 00109 o = get_jit_java_jitobj(env,obj); 00110 if(!o) 00111 return arv; 00112 00113 atom_setlong(a,x); 00114 atom_setlong(a+1,y); 00115 atom_setlong(a+2,z); 00116 res = object_method_typed(o,ps_getcell,3,a,&arv); 00117 00118 return arv; 00119 } 00120 00121 jobject JNICALL jit_java_jitmatrix_getcell3d_atom(JNIEnv *env, jobject obj, jint x, jint y, jint z) 00122 { 00123 t_atom arv; 00124 00125 arv = jit_java_jitmatrix_getcell3d_helper(env,obj,x,y,z); 00126 return jit_java_jitobj_returnvalue(env,arv); 00127 } 00128 00129 00130 jobject JNICALL jit_java_jitmatrix_getcell3d_int(JNIEnv *env, jobject obj, jint x, jint y, jint z) 00131 { 00132 t_atom arv; 00133 00134 arv = jit_java_jitmatrix_getcell3d_helper(env,obj,x,y,z); 00135 return jit_java_jitobj_returnvalue_intarray(env,arv); 00136 } 00137 00138 jobject JNICALL jit_java_jitmatrix_getcell3d_float(JNIEnv *env, jobject obj, jint x, jint y, jint z) 00139 { 00140 t_atom arv; 00141 00142 arv = jit_java_jitmatrix_getcell3d_helper(env,obj,x,y,z); 00143 return jit_java_jitobj_returnvalue_floatarray(env,arv); 00144 } 00145 00146 jobject JNICALL jit_java_jitmatrix_getcell3d_double(JNIEnv *env, jobject obj, jint x, jint y, jint z) 00147 { 00148 t_atom arv; 00149 00150 arv = jit_java_jitmatrix_getcell3d_helper(env,obj,x,y,z); 00151 return jit_java_jitobj_returnvalue_doublearray(env,arv); 00152 } 00153 00154 void JNICALL jit_java_jitmatrix_setall_double(JNIEnv *env, jobject obj, jdouble val) 00155 { 00156 t_atom a; 00157 t_atom arv; 00158 t_max_err res; 00159 t_object *o; 00160 00161 // later on this function should use special double precision methods for setting with doubles 00162 00163 o = get_jit_java_jitobj(env,obj); 00164 if(!o)//would be weird 00165 return; 00166 00167 atom_setfloat(&a,val); 00168 res = object_method_typed(o,ps_setall,1,&a,&arv); 00169 } 00170 00171 00172 void JNICALL jit_java_jitmatrix_setcell_int(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array) 00173 { 00174 long ac=0; 00175 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00176 t_atom arv; 00177 t_max_err res; 00178 t_object *o; 00179 00180 arv.a_type = A_NOTHING; 00181 00182 o = get_jit_java_jitobj(env,obj); 00183 if(!o) 00184 return; 00185 00186 if (pos_array) { 00187 // copy position array as as atoms 00188 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00189 } 00190 00191 if (val_array) { 00192 // set value symbol 00193 atom_setsym(av+ac,ps_val); 00194 ac++; 00195 // copy value array as as atoms 00196 ac += jit_java_atomsfromintarray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00197 } 00198 00199 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00200 } 00201 00202 void JNICALL jit_java_jitmatrix_setcell_float(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array) 00203 { 00204 long ac=0; 00205 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00206 t_atom arv; 00207 t_max_err res; 00208 t_object *o; 00209 00210 arv.a_type = A_NOTHING; 00211 00212 o = get_jit_java_jitobj(env,obj); 00213 if(!o) 00214 return; 00215 00216 if (pos_array) { 00217 // copy position array as as atoms 00218 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00219 } 00220 00221 if (val_array) { 00222 // set value symbol 00223 atom_setsym(av+ac,ps_val); 00224 ac++; 00225 // copy value array as as atoms 00226 ac += jit_java_atomsfromfloatarray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00227 } 00228 00229 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00230 } 00231 00232 void JNICALL jit_java_jitmatrix_setcell_double(JNIEnv *env, jobject obj, jobject pos_array, jobject val_array) 00233 { 00234 long ac=0; 00235 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00236 t_atom arv; 00237 t_max_err res; 00238 t_object *o; 00239 00240 // later on this function should use special double precision methods for setting with doubles 00241 arv.a_type = A_NOTHING; 00242 00243 o = get_jit_java_jitobj(env,obj); 00244 if(!o) 00245 return; 00246 00247 if (pos_array) { 00248 // copy position array as as atoms 00249 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00250 } 00251 00252 if (val_array) { 00253 // set value symbol 00254 atom_setsym(av+ac,ps_val); 00255 ac++; 00256 // copy value array as as atoms 00257 ac += jit_java_atomsfromdoublearray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00258 } 00259 00260 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00261 } 00262 00263 void JNICALL jit_java_jitmatrix_setcell_plane_int(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jint val) 00264 { 00265 long ac=0; 00266 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00267 t_atom arv; 00268 t_max_err res; 00269 t_object *o; 00270 00271 arv.a_type = A_NOTHING; 00272 00273 o = get_jit_java_jitobj(env,obj); 00274 if(!o) 00275 return; 00276 00277 if (pos_array) { 00278 // copy position array as as atoms 00279 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00280 } 00281 00282 // set plane 00283 atom_setsym(av+ac,ps_plane); ac++; 00284 atom_setlong(av+ac,plane); ac++; 00285 // set value 00286 atom_setsym(av+ac,ps_val); ac++; 00287 atom_setlong(av+ac,val); ac++; 00288 00289 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00290 } 00291 00292 void JNICALL jit_java_jitmatrix_setcell_plane_float(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jfloat val) 00293 { 00294 long ac=0; 00295 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00296 t_atom arv; 00297 t_max_err res; 00298 t_object *o; 00299 00300 arv.a_type = A_NOTHING; 00301 00302 o = get_jit_java_jitobj(env,obj); 00303 if(!o) 00304 return; 00305 00306 if (pos_array) { 00307 // copy position array as as atoms 00308 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00309 } 00310 00311 // set plane 00312 atom_setsym(av+ac,ps_plane); ac++; 00313 atom_setlong(av+ac,plane); ac++; 00314 // set value 00315 atom_setsym(av+ac,ps_val); ac++; 00316 atom_setfloat(av+ac,val); ac++; 00317 00318 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00319 } 00320 00321 void JNICALL jit_java_jitmatrix_setcell_plane_double(JNIEnv *env, jobject obj, jobject pos_array, jint plane, jdouble val) 00322 { 00323 long ac=0; 00324 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00325 t_atom arv; 00326 t_max_err res; 00327 t_object *o; 00328 00329 arv.a_type = A_NOTHING; 00330 00331 o = get_jit_java_jitobj(env,obj); 00332 if(!o) 00333 return; 00334 00335 if (pos_array) { 00336 // copy position array as as atoms 00337 ac = jit_java_atomsfromintarray(env,pos_array,JIT_MATRIX_MAX_DIMCOUNT,av); 00338 } 00339 00340 // set plane 00341 atom_setsym(av+ac,ps_plane); ac++; 00342 atom_setlong(av+ac,plane); ac++; 00343 // set value 00344 atom_setsym(av+ac,ps_val); ac++; 00345 atom_setfloat(av+ac,val); ac++; 00346 00347 res = object_method_typed(o,ps_setcell,ac,av,&arv); 00348 } 00349 00350 void JNICALL jit_java_jitmatrix_setcell3d_int(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array) 00351 { 00352 long ac=0; 00353 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00354 t_atom arv; 00355 t_max_err res; 00356 t_object *o; 00357 00358 arv.a_type = A_NOTHING; 00359 00360 o = get_jit_java_jitobj(env,obj); 00361 if(!o) 00362 return; 00363 00364 atom_setlong(av+ac,x); ac++; 00365 atom_setlong(av+ac,y); ac++; 00366 atom_setlong(av+ac,z); ac++; 00367 00368 if (val_array) { 00369 // copy value array as as atoms 00370 ac += jit_java_atomsfromintarray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00371 } 00372 00373 res = object_method_typed(o,ps_setcell3d,ac,av,&arv); 00374 } 00375 00376 void JNICALL jit_java_jitmatrix_setcell3d_float(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array) 00377 { 00378 long ac=0; 00379 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00380 t_atom arv; 00381 t_max_err res; 00382 t_object *o; 00383 00384 arv.a_type = A_NOTHING; 00385 00386 o = get_jit_java_jitobj(env,obj); 00387 if(!o) 00388 return; 00389 00390 atom_setlong(av+ac,x); ac++; 00391 atom_setlong(av+ac,y); ac++; 00392 atom_setlong(av+ac,z); ac++; 00393 00394 if (val_array) { 00395 // copy value array as as atoms 00396 ac += jit_java_atomsfromfloatarray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00397 } 00398 00399 res = object_method_typed(o,ps_setcell3d,ac,av,&arv); 00400 } 00401 00402 void JNICALL jit_java_jitmatrix_setcell3d_double(JNIEnv *env, jobject obj, jint x, jint y, jint z, jobject val_array) 00403 { 00404 long ac=0; 00405 t_atom av[JIT_MATRIX_MAX_DIMCOUNT+JIT_MATRIX_MAX_PLANECOUNT+1]; 00406 t_atom arv; 00407 t_max_err res; 00408 t_object *o; 00409 00410 arv.a_type = A_NOTHING; 00411 00412 o = get_jit_java_jitobj(env,obj); 00413 if(!o) 00414 return; 00415 00416 atom_setlong(av+ac,x); ac++; 00417 atom_setlong(av+ac,y); ac++; 00418 atom_setlong(av+ac,z); ac++; 00419 00420 if (val_array) { 00421 // copy value array as as atoms 00422 ac += jit_java_atomsfromdoublearray(env,val_array,JIT_MATRIX_MAX_PLANECOUNT,av+ac); 00423 } 00424 00425 res = object_method_typed(o,ps_setcell3d,ac,av,&arv); 00426 } 00427 00428 uchar *jit_java_jitmatrix_copyvectorsetup(JNIEnv *env, t_object *o, jint *dim, jobject dimoffset, jobject array, jint *count, jint *arrayoffset, 00429 t_jit_matrix_info *minfo, jint *doa, jint *arraylen, long planar) 00430 { 00431 long i,maxcount,offset_count; 00432 jint *offset_elements; 00433 uchar *bp=NULL; 00434 jboolean is_copy; 00435 00436 // get array length 00437 *arraylen = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,array); 00438 CLIP(*arrayoffset,0,*arraylen-1); 00439 *arraylen -= *arrayoffset; 00440 if (*count<=0) 00441 *count = *arraylen; 00442 00443 // limit dim and count 00444 CLIP(*dim,0,JIT_MATRIX_MAX_DIMCOUNT-1); 00445 CLIP(*count,0,*arraylen); 00446 00447 // get pointer and matrix info 00448 jit_object_method(o,_jit_sym_getinfo,minfo); 00449 jit_object_method(o,_jit_sym_getdata,&bp); 00450 if (!bp) 00451 return NULL; 00452 00453 // get offset array count (if it exists) 00454 i=0; 00455 if (dimoffset) 00456 { 00457 offset_count = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,dimoffset); 00458 offset_elements = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)dimoffset,&is_copy); 00459 // offset pointer 00460 for (i=0;i<offset_count;i++) { 00461 doa[i] = CLAMP(offset_elements[i],0,MAX(minfo->dim[i]-1,0)); 00462 bp += doa[i] * minfo->dimstride[i]; 00463 } 00464 // release offset array 00465 if (is_copy) { 00466 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)dimoffset,offset_elements,0); 00467 } 00468 } 00469 for (;i<JIT_MATRIX_MAX_DIMCOUNT;i++) { 00470 doa[i] = 0; 00471 } 00472 00473 //limit count based on matrix info and offset across dimension of interest 00474 maxcount = minfo->dim[*dim]-doa[*dim]; 00475 if (!planar) 00476 maxcount *= minfo->planecount; 00477 if ((*count)>maxcount) 00478 *count = maxcount; 00479 00480 return bp; 00481 } 00482 00483 jint JNICALL jit_java_jitmatrix_copyvectortoarray_int(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00484 jint JNICALL jit_java_jitmatrix_copyvectortoarray_int(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00485 { 00486 t_object *o,*mat; 00487 t_jit_matrix_info minfo; 00488 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00489 jint arraylen; 00490 jint *elements; 00491 jboolean is_copy; 00492 uchar *bp=NULL; 00493 long i,j,k; 00494 long stride,planecount,cellcount; 00495 long tmp; 00496 00497 o = get_jit_java_jitobj(env,obj); 00498 if(!o||!array) 00499 return 0; 00500 00501 mat = jit_object_method(o,ps_getmatrix); 00502 if(!mat) 00503 return 0; 00504 00505 // setup all our info, common to all copyvector methods 00506 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 00507 if (!bp) 00508 return 0; 00509 00510 // allocate temp memory for array 00511 elements = jit_getbytes(count*sizeof(jint)); 00512 00513 stride = minfo.dimstride[dim]; 00514 planecount = minfo.planecount; 00515 cellcount = count/planecount; 00516 if (minfo.type==_jit_sym_char) { 00517 if (planecount==4) { 00518 for (i=0,j=0,k=0;i<cellcount;i++) { 00519 elements[j++] = bp[k++]; 00520 elements[j++] = bp[k++]; 00521 elements[j++] = bp[k++]; 00522 elements[j++] = bp[k++]; 00523 } 00524 } else { 00525 for (i=0,k=0;i<cellcount;i++) { 00526 for (j=0;j<planecount;j++) { 00527 elements[k++] = bp[j]; 00528 } 00529 bp += stride; 00530 } 00531 } 00532 } else if (minfo.type==_jit_sym_long) { 00533 for (i=0,k=0;i<cellcount;i++) { 00534 for (j=0;j<planecount;j++) { 00535 elements[k++] = ((long *)bp)[j]; 00536 } 00537 bp += stride; 00538 } 00539 } else if (minfo.type==_jit_sym_float32) { 00540 for (i=0,k=0;i<cellcount;i++) { 00541 for (j=0;j<planecount;j++) { 00542 elements[k++] = (long)((float *)bp)[j]; 00543 } 00544 bp += stride; 00545 } 00546 } else if (minfo.type==_jit_sym_float64) { 00547 for (i=0,k=0;i<cellcount;i++) { 00548 for (j=0;j<planecount;j++) { 00549 elements[k++] = (long) ((double *)bp)[j]; 00550 } 00551 bp += stride; 00552 } 00553 } 00554 00555 JIT_JAVA_JNI_CALL(env,SetIntArrayRegion)(env,(jintArray)array,arrayoffset,count,elements); 00556 00557 // free temp memory for array 00558 jit_freebytes(elements,count*sizeof(jint)); 00559 00560 return count; 00561 } 00562 00563 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_int(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00564 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_int(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00565 { 00566 t_object *o,*mat; 00567 t_jit_matrix_info minfo; 00568 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00569 jint arraylen; 00570 jint *elements; 00571 jboolean is_copy; 00572 uchar *bp=NULL; 00573 long i,j,k; 00574 long stride,planecount,cellcount; 00575 long tmp; 00576 00577 o = get_jit_java_jitobj(env,obj); 00578 if(!o||!array) 00579 return 0; 00580 00581 mat = jit_object_method(o,ps_getmatrix); 00582 if(!mat) 00583 return 0; 00584 00585 // setup all our info, common to all copyvector methods 00586 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 00587 if (!bp) 00588 return 0; 00589 00590 // get array 00591 elements = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)array,&is_copy); 00592 //checkException(env); //inefficient? 00593 00594 stride = minfo.dimstride[dim]; 00595 planecount = minfo.planecount; 00596 cellcount = count; 00597 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 00598 if (minfo.type==_jit_sym_char) { 00599 for (i=0,k=arrayoffset;i<cellcount;i++) { 00600 elements[k++] = (*bp); 00601 bp += stride; 00602 } 00603 } else if (minfo.type==_jit_sym_long) { 00604 for (i=0,k=arrayoffset;i<cellcount;i++) { 00605 elements[k++] = *((long *)bp); 00606 bp += stride; 00607 } 00608 } else if (minfo.type==_jit_sym_float32) { 00609 for (i=0,k=arrayoffset;i<cellcount;i++) { 00610 elements[k++] = (long) *((float *)bp); 00611 bp += stride; 00612 } 00613 } else if (minfo.type==_jit_sym_float64) { 00614 for (i=0,k=arrayoffset;i<cellcount;i++) { 00615 elements[k++] = (long) *((double *)bp); 00616 bp += stride; 00617 } 00618 } 00619 00620 JIT_JAVA_JNI_CALL(env,SetIntArrayRegion)(env,(jintArray)array,arrayoffset,count,elements+arrayoffset); 00621 00622 // release array 00623 if (is_copy) { 00624 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)array,elements,0); 00625 checkException(env); 00626 } 00627 00628 return count; 00629 } 00630 00631 jint JNICALL jit_java_jitmatrix_copyvectortoarray_float(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00632 jint JNICALL jit_java_jitmatrix_copyvectortoarray_float(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00633 { 00634 t_object *o,*mat; 00635 t_jit_matrix_info minfo; 00636 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00637 jint arraylen; 00638 jfloat *elements; 00639 jboolean is_copy; 00640 uchar *bp=NULL; 00641 long i,j,k; 00642 long stride,planecount,cellcount; 00643 long tmp; 00644 00645 o = get_jit_java_jitobj(env,obj); 00646 if(!o||!array) 00647 return 0; 00648 00649 mat = jit_object_method(o,ps_getmatrix); 00650 if(!mat) 00651 return 0; 00652 00653 // setup all our info, common to all copyvector methods 00654 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 00655 if (!bp) 00656 return 0; 00657 00658 // get array 00659 elements = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env,(jfloatArray)array,&is_copy); 00660 //checkException(env); //inefficient? 00661 00662 stride = minfo.dimstride[dim]; 00663 planecount = minfo.planecount; 00664 cellcount = count/planecount; 00665 if (minfo.type==_jit_sym_char) { 00666 if (planecount==4) { 00667 for (i=0,j=0,k=0;i<cellcount;i++) { 00668 elements[j++] = bp[k++]*(1./255.); 00669 elements[j++] = bp[k++]*(1./255.); 00670 elements[j++] = bp[k++]*(1./255.); 00671 elements[j++] = bp[k++]*(1./255.); 00672 } 00673 } else { 00674 for (i=0,k=arrayoffset;i<cellcount;i++) { 00675 for (j=0;j<planecount;j++) { 00676 elements[k++] = bp[j]*(1./255.); 00677 } 00678 bp += stride; 00679 } 00680 } 00681 } else if (minfo.type==_jit_sym_long) { 00682 for (i=0,k=arrayoffset;i<cellcount;i++) { 00683 for (j=0;j<planecount;j++) { 00684 elements[k++] = (float) ((long *)bp)[j]; 00685 } 00686 bp += stride; 00687 } 00688 } else if (minfo.type==_jit_sym_float32) { 00689 for (i=0,k=arrayoffset;i<cellcount;i++) { 00690 for (j=0;j<planecount;j++) { 00691 elements[k++] = ((float *)bp)[j]; 00692 } 00693 bp += stride; 00694 } 00695 } else if (minfo.type==_jit_sym_float64) { 00696 for (i=0,k=arrayoffset;i<cellcount;i++) { 00697 for (j=0;j<planecount;j++) { 00698 elements[k++] = (double) ((double *)bp)[j]; 00699 } 00700 bp += stride; 00701 } 00702 } 00703 00704 JIT_JAVA_JNI_CALL(env,SetFloatArrayRegion)(env,(jfloatArray)array,arrayoffset,count,elements+arrayoffset); 00705 00706 // release array 00707 if (is_copy) { 00708 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)array,elements,0); 00709 checkException(env); 00710 } 00711 00712 return count; 00713 } 00714 00715 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_float(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00716 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_float(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00717 { 00718 t_object *o,*mat; 00719 t_jit_matrix_info minfo; 00720 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00721 jint arraylen; 00722 jfloat *elements; 00723 jboolean is_copy; 00724 uchar *bp=NULL; 00725 long i,j,k; 00726 long stride,planecount,cellcount; 00727 long tmp; 00728 00729 o = get_jit_java_jitobj(env,obj); 00730 if(!o||!array) 00731 return 0; 00732 00733 mat = jit_object_method(o,ps_getmatrix); 00734 if(!mat) 00735 return 0; 00736 00737 // setup all our info, common to all copyvector methods 00738 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 00739 if (!bp) 00740 return 0; 00741 00742 // get array 00743 elements = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env,(jfloatArray)array,&is_copy); 00744 //checkException(env); //inefficient? 00745 00746 stride = minfo.dimstride[dim]; 00747 planecount = minfo.planecount; 00748 cellcount = count; 00749 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 00750 if (minfo.type==_jit_sym_char) { 00751 for (i=0,k=arrayoffset;i<cellcount;i++) { 00752 elements[k++] = (*bp)*(1./255.); 00753 bp += stride; 00754 } 00755 } else if (minfo.type==_jit_sym_long) { 00756 for (i=0,k=arrayoffset;i<cellcount;i++) { 00757 elements[k++] = (float) *((long *)bp); 00758 bp += stride; 00759 } 00760 } else if (minfo.type==_jit_sym_float32) { 00761 for (i=0,k=arrayoffset;i<cellcount;i++) { 00762 elements[k++] = *((float *)bp); 00763 bp += stride; 00764 } 00765 } else if (minfo.type==_jit_sym_float64) { 00766 for (i=0,k=arrayoffset;i<cellcount;i++) { 00767 elements[k++] = (float) *((double *)bp); 00768 bp += stride; 00769 } 00770 } 00771 00772 JIT_JAVA_JNI_CALL(env,SetFloatArrayRegion)(env,(jfloatArray)array,arrayoffset,count,elements+arrayoffset); 00773 00774 // release array 00775 if (is_copy) { 00776 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)array,elements,0); 00777 checkException(env); 00778 } 00779 00780 return count; 00781 } 00782 00783 jint JNICALL jit_java_jitmatrix_copyvectortoarray_double(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00784 jint JNICALL jit_java_jitmatrix_copyvectortoarray_double(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00785 { 00786 t_object *o,*mat; 00787 t_jit_matrix_info minfo; 00788 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00789 jint arraylen; 00790 jdouble *elements; 00791 jboolean is_copy; 00792 uchar *bp=NULL; 00793 long i,j,k; 00794 long stride,planecount,cellcount; 00795 long tmp; 00796 00797 o = get_jit_java_jitobj(env,obj); 00798 if(!o||!array) 00799 return 0; 00800 00801 mat = jit_object_method(o,ps_getmatrix); 00802 if(!mat) 00803 return 0; 00804 00805 // setup all our info, common to all copyvector methods 00806 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 00807 if (!bp) 00808 return 0; 00809 00810 // get array 00811 elements = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env,(jdoubleArray)array,&is_copy); 00812 //checkException(env); //inefficient? 00813 00814 stride = minfo.dimstride[dim]; 00815 planecount = minfo.planecount; 00816 cellcount = count/planecount; 00817 if (minfo.type==_jit_sym_char) { 00818 for (i=0,k=arrayoffset;i<cellcount;i++) { 00819 for (j=0;j<planecount;j++) { 00820 elements[k++] = bp[j]*(1./255.); 00821 } 00822 bp += stride; 00823 } 00824 } else if (minfo.type==_jit_sym_long) { 00825 for (i=0,k=arrayoffset;i<cellcount;i++) { 00826 for (j=0;j<planecount;j++) { 00827 elements[k++] = (double) ((long *)bp)[j]; 00828 } 00829 bp += stride; 00830 } 00831 } else if (minfo.type==_jit_sym_float32) { 00832 for (i=0,k=arrayoffset;i<cellcount;i++) { 00833 for (j=0;j<planecount;j++) { 00834 elements[k++] = (double) ((float *)bp)[j]; 00835 } 00836 bp += stride; 00837 } 00838 } else if (minfo.type==_jit_sym_float64) { 00839 for (i=0,k=arrayoffset;i<cellcount;i++) { 00840 for (j=0;j<planecount;j++) { 00841 elements[k++] = ((double *)bp)[j]; 00842 } 00843 bp += stride; 00844 } 00845 } 00846 00847 JIT_JAVA_JNI_CALL(env,SetDoubleArrayRegion)(env,(jdoubleArray)array,arrayoffset,count,elements+arrayoffset); 00848 00849 // release array 00850 if (is_copy) { 00851 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)array,elements,0); 00852 checkException(env); 00853 } 00854 00855 return count; 00856 } 00857 00858 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_double(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00859 jint JNICALL jit_java_jitmatrix_copyvectortoarrayplanar_double(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00860 { 00861 t_object *o,*mat; 00862 t_jit_matrix_info minfo; 00863 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00864 jint arraylen; 00865 jdouble *elements; 00866 jboolean is_copy; 00867 uchar *bp=NULL; 00868 long i,j,k; 00869 long stride,planecount,cellcount; 00870 long tmp; 00871 00872 o = get_jit_java_jitobj(env,obj); 00873 if(!o||!array) 00874 return 0; 00875 00876 mat = jit_object_method(o,ps_getmatrix); 00877 if(!mat) 00878 return 0; 00879 00880 // setup all our info, common to all copyvector methods 00881 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 00882 if (!bp) 00883 return 0; 00884 00885 // get array 00886 elements = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env,(jdoubleArray)array,&is_copy); 00887 //checkException(env); //inefficient? 00888 00889 stride = minfo.dimstride[dim]; 00890 planecount = minfo.planecount; 00891 cellcount = count; 00892 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 00893 if (minfo.type==_jit_sym_char) { 00894 for (i=0,k=arrayoffset;i<cellcount;i++) { 00895 elements[k++] = *bp *(1./255.); 00896 bp += stride; 00897 } 00898 } else if (minfo.type==_jit_sym_long) { 00899 for (i=0,k=arrayoffset;i<cellcount;i++) { 00900 elements[k++] = (double)(*((long *)bp)); 00901 bp += stride; 00902 } 00903 } else if (minfo.type==_jit_sym_float32) { 00904 for (i=0,k=arrayoffset;i<cellcount;i++) { 00905 elements[k++] = (double)(*(float *)bp); 00906 bp += stride; 00907 } 00908 } else if (minfo.type==_jit_sym_float64) { 00909 for (i=0,k=arrayoffset;i<cellcount;i++) { 00910 elements[k++] = (*(double *)bp); 00911 bp += stride; 00912 } 00913 } 00914 00915 JIT_JAVA_JNI_CALL(env,SetDoubleArrayRegion)(env,(jdoubleArray)array,arrayoffset,count,elements+arrayoffset); 00916 00917 // release array 00918 if (is_copy) { 00919 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)array,elements,0); 00920 checkException(env); 00921 } 00922 00923 return count; 00924 } 00925 00926 jint JNICALL jit_java_jitmatrix_copyarraytovector_int(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 00927 jint JNICALL jit_java_jitmatrix_copyarraytovector_int(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 00928 { 00929 t_object *o,*mat; 00930 t_jit_matrix_info minfo; 00931 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 00932 jint arraylen; 00933 jint *elements; 00934 jboolean is_copy; 00935 uchar *bp=NULL; 00936 long i,j,k; 00937 long stride,planecount,cellcount; 00938 long tmp; 00939 00940 o = get_jit_java_jitobj(env,obj); 00941 if(!o||!array) 00942 return 0; 00943 00944 mat = jit_object_method(o,ps_getmatrix); 00945 if(!mat) 00946 return 0; 00947 00948 // setup all our info, common to all copyvector methods 00949 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 00950 if (!bp) 00951 return 0; 00952 00953 // get array 00954 elements = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)array,&is_copy); 00955 //checkException(env); //inefficient? 00956 00957 stride = minfo.dimstride[dim]; 00958 planecount = minfo.planecount; 00959 cellcount = count/planecount; 00960 if (minfo.type==_jit_sym_char) { 00961 if (planecount==4) { 00962 for (i=0,j=0,k=arrayoffset;i<cellcount;i++) { 00963 tmp = elements[k++]; 00964 bp[j++] = CLAMP(tmp,0,255); 00965 tmp = elements[k++]; 00966 bp[j++] = CLAMP(tmp,0,255); 00967 tmp = elements[k++]; 00968 bp[j++] = CLAMP(tmp,0,255); 00969 tmp = elements[k++]; 00970 bp[j++] = CLAMP(tmp,0,255); 00971 } 00972 } else { 00973 for (i=0,k=arrayoffset;i<cellcount;i++) { 00974 for (j=0;j<planecount;j++) { 00975 tmp = elements[k++]; 00976 bp[j] = CLAMP(tmp,0,255); 00977 } 00978 bp += stride; 00979 } 00980 } 00981 } else if (minfo.type==_jit_sym_long) { 00982 for (i=0,k=arrayoffset;i<cellcount;i++) { 00983 for (j=0;j<planecount;j++) { 00984 ((long *)bp)[j] = elements[k++]; 00985 } 00986 bp += stride; 00987 } 00988 } else if (minfo.type==_jit_sym_float32) { 00989 for (i=0,k=arrayoffset;i<cellcount;i++) { 00990 for (j=0;j<planecount;j++) { 00991 ((float *)bp)[j] = (float) elements[k++]; 00992 } 00993 bp += stride; 00994 } 00995 } else if (minfo.type==_jit_sym_float64) { 00996 for (i=0,k=arrayoffset;i<cellcount;i++) { 00997 for (j=0;j<planecount;j++) { 00998 ((double *)bp)[j] = (double) elements[k++]; 00999 } 01000 bp += stride; 01001 } 01002 } 01003 01004 // release array 01005 if (is_copy) { 01006 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)array,elements,0); 01007 checkException(env); 01008 } 01009 01010 return count; 01011 } 01012 01013 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_int(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 01014 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_int(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 01015 { 01016 t_object *o,*mat; 01017 t_jit_matrix_info minfo; 01018 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 01019 jint arraylen; 01020 jint *elements; 01021 jboolean is_copy; 01022 uchar *bp=NULL; 01023 long i,j,k; 01024 long stride,planecount,cellcount; 01025 long tmp; 01026 01027 o = get_jit_java_jitobj(env,obj); 01028 if(!o||!array) 01029 return 0; 01030 01031 mat = jit_object_method(o,ps_getmatrix); 01032 if(!mat) 01033 return 0; 01034 01035 // setup all our info, common to all copyvector methods 01036 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 01037 if (!bp) 01038 return 0; 01039 01040 // get array 01041 elements = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)array,&is_copy); 01042 //checkException(env); //inefficient? 01043 01044 stride = minfo.dimstride[dim]; 01045 planecount = minfo.planecount; 01046 cellcount = count; 01047 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 01048 if (minfo.type==_jit_sym_char) { 01049 for (i=0,k=arrayoffset;i<cellcount;i++) { 01050 tmp = elements[k++]; 01051 *bp = CLAMP(tmp,0,255); 01052 bp += stride; 01053 } 01054 } else if (minfo.type==_jit_sym_long) { 01055 for (i=0,k=arrayoffset;i<cellcount;i++) { 01056 *((long *)bp) = elements[k++]; 01057 bp += stride; 01058 } 01059 } else if (minfo.type==_jit_sym_float32) { 01060 for (i=0,k=arrayoffset;i<cellcount;i++) { 01061 *((float *)bp) = (float) elements[k++]; 01062 bp += stride; 01063 } 01064 } else if (minfo.type==_jit_sym_float64) { 01065 for (i=0,k=arrayoffset;i<cellcount;i++) { 01066 *((double *)bp) = (double) elements[k++]; 01067 bp += stride; 01068 } 01069 } 01070 01071 // release array 01072 if (is_copy) { 01073 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)array,elements,0); 01074 checkException(env); 01075 } 01076 01077 return count; 01078 } 01079 01080 jint JNICALL jit_java_jitmatrix_copyarraytovector_float(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 01081 jint JNICALL jit_java_jitmatrix_copyarraytovector_float(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 01082 { 01083 t_object *o,*mat; 01084 t_jit_matrix_info minfo; 01085 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 01086 jint arraylen; 01087 jfloat *elements; 01088 jboolean is_copy; 01089 uchar *bp=NULL; 01090 long i,j,k; 01091 long stride,planecount,cellcount; 01092 long tmp; 01093 01094 o = get_jit_java_jitobj(env,obj); 01095 if(!o||!array) 01096 return 0; 01097 01098 mat = jit_object_method(o,ps_getmatrix); 01099 if(!mat) 01100 return 0; 01101 01102 // setup all our info, common to all copyvector methods 01103 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 01104 if (!bp) 01105 return 0; 01106 01107 // get array 01108 elements = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env,(jfloatArray)array,&is_copy); 01109 //checkException(env); //inefficient? 01110 01111 stride = minfo.dimstride[dim]; 01112 planecount = minfo.planecount; 01113 cellcount = count/planecount; 01114 if (minfo.type==_jit_sym_char) { 01115 if (planecount==4) { 01116 for (i=0,j=0,k=0;i<cellcount;i++) { 01117 tmp = elements[k++]*255.; 01118 bp[j++] = CLAMP(tmp,0,255); 01119 tmp = elements[k++]*255.; 01120 bp[j++] = CLAMP(tmp,0,255); 01121 tmp = elements[k++]*255.; 01122 bp[j++] = CLAMP(tmp,0,255); 01123 tmp = elements[k++]*255.; 01124 bp[j++] = CLAMP(tmp,0,255); 01125 } 01126 } else { 01127 for (i=0,k=arrayoffset;i<cellcount;i++) { 01128 for (j=0;j<planecount;j++) { 01129 tmp = elements[k++]*255.; 01130 bp[j] = CLAMP(tmp,0,255); 01131 } 01132 bp += stride; 01133 } 01134 } 01135 } else if (minfo.type==_jit_sym_long) { 01136 for (i=0,k=arrayoffset;i<cellcount;i++) { 01137 for (j=0;j<planecount;j++) { 01138 ((long *)bp)[j] = (long) elements[k++]; 01139 } 01140 bp += stride; 01141 } 01142 } else if (minfo.type==_jit_sym_float32) { 01143 for (i=0,k=arrayoffset;i<cellcount;i++) { 01144 for (j=0;j<planecount;j++) { 01145 ((float *)bp)[j] = (float) elements[k++]; 01146 } 01147 bp += stride; 01148 } 01149 } else if (minfo.type==_jit_sym_float64) { 01150 for (i=0,k=arrayoffset;i<cellcount;i++) { 01151 for (j=0;j<planecount;j++) { 01152 ((double *)bp)[j] = (double) elements[k++]; 01153 } 01154 bp += stride; 01155 } 01156 } 01157 01158 // release array 01159 if (is_copy) { 01160 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)array,elements,0); 01161 checkException(env); 01162 } 01163 01164 return count; 01165 } 01166 01167 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_float(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 01168 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_float(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 01169 { 01170 t_object *o,*mat; 01171 t_jit_matrix_info minfo; 01172 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 01173 jint arraylen; 01174 jfloat *elements; 01175 jboolean is_copy; 01176 uchar *bp=NULL; 01177 long i,j,k; 01178 long stride,planecount,cellcount; 01179 long tmp; 01180 01181 o = get_jit_java_jitobj(env,obj); 01182 if(!o||!array) 01183 return 0; 01184 01185 mat = jit_object_method(o,ps_getmatrix); 01186 if(!mat) 01187 return 0; 01188 01189 // setup all our info, common to all copyvector methods 01190 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 01191 if (!bp) 01192 return 0; 01193 01194 // get array 01195 elements = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env,(jfloatArray)array,&is_copy); 01196 //checkException(env); //inefficient? 01197 01198 stride = minfo.dimstride[dim]; 01199 planecount = minfo.planecount; 01200 cellcount = count; 01201 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 01202 if (minfo.type==_jit_sym_char) { 01203 for (i=0,k=arrayoffset;i<cellcount;i++) { 01204 tmp = elements[k++]*255.; 01205 *bp = CLAMP(tmp,0,255); 01206 bp += stride; 01207 } 01208 } else if (minfo.type==_jit_sym_long) { 01209 for (i=0,k=arrayoffset;i<cellcount;i++) { 01210 *((long *)bp) = (long) elements[k++]; 01211 bp += stride; 01212 } 01213 } else if (minfo.type==_jit_sym_float32) { 01214 for (i=0,k=arrayoffset;i<cellcount;i++) { 01215 *((float *)bp) = (float) elements[k++]; 01216 bp += stride; 01217 } 01218 } else if (minfo.type==_jit_sym_float64) { 01219 for (i=0,k=arrayoffset;i<cellcount;i++) { 01220 *((double *)bp) = (double) elements[k++]; 01221 bp += stride; 01222 } 01223 } 01224 01225 // release array 01226 if (is_copy) { 01227 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)array,elements,0); 01228 checkException(env); 01229 } 01230 01231 return count; 01232 } 01233 01234 jint JNICALL jit_java_jitmatrix_copyarraytovector_double(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 01235 jint JNICALL jit_java_jitmatrix_copyarraytovector_double(JNIEnv *env, jobject obj, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 01236 { 01237 t_object *o,*mat; 01238 t_jit_matrix_info minfo; 01239 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 01240 jint arraylen; 01241 jdouble *elements; 01242 jboolean is_copy; 01243 uchar *bp=NULL; 01244 long i,j,k; 01245 long stride,planecount,cellcount; 01246 long tmp; 01247 01248 o = get_jit_java_jitobj(env,obj); 01249 if(!o||!array) 01250 return 0; 01251 01252 mat = jit_object_method(o,ps_getmatrix); 01253 if(!mat) 01254 return 0; 01255 01256 // setup all our info, common to all copyvector methods 01257 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,0); 01258 if (!bp) 01259 return 0; 01260 01261 // get array 01262 elements = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env,(jdoubleArray)array,&is_copy); 01263 //checkException(env); //inefficient? 01264 01265 stride = minfo.dimstride[dim]; 01266 planecount = minfo.planecount; 01267 cellcount = count/planecount; 01268 if (minfo.type==_jit_sym_char) { 01269 for (i=0,k=arrayoffset;i<cellcount;i++) { 01270 for (j=0;j<planecount;j++) { 01271 tmp = elements[k++]*255.; 01272 bp[j] = CLAMP(tmp,0,255); 01273 } 01274 bp += stride; 01275 } 01276 } else if (minfo.type==_jit_sym_long) { 01277 for (i=0,k=arrayoffset;i<cellcount;i++) { 01278 for (j=0;j<planecount;j++) { 01279 ((long *)bp)[j] = (long) elements[k++]; 01280 } 01281 bp += stride; 01282 } 01283 } else if (minfo.type==_jit_sym_float32) { 01284 for (i=0,k=arrayoffset;i<cellcount;i++) { 01285 for (j=0;j<planecount;j++) { 01286 ((float *)bp)[j] = (float) elements[k++]; 01287 } 01288 bp += stride; 01289 } 01290 } else if (minfo.type==_jit_sym_float64) { 01291 for (i=0,k=arrayoffset;i<cellcount;i++) { 01292 for (j=0;j<planecount;j++) { 01293 ((double *)bp)[j] = (double) elements[k++]; 01294 } 01295 bp += stride; 01296 } 01297 } 01298 01299 // release array 01300 if (is_copy) { 01301 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)array,elements,0); 01302 checkException(env); 01303 } 01304 01305 return count; 01306 } 01307 01308 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_double(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset); 01309 jint JNICALL jit_java_jitmatrix_copyarraytovectorplanar_double(JNIEnv *env, jobject obj, jint plane, jint dim, jobject dimoffset, jobject array, jint count, jint arrayoffset) 01310 { 01311 t_object *o,*mat; 01312 t_jit_matrix_info minfo; 01313 jint doa[JIT_MATRIX_MAX_DIMCOUNT]; 01314 jint arraylen; 01315 jdouble *elements; 01316 jboolean is_copy; 01317 uchar *bp=NULL; 01318 long i,j,k; 01319 long stride,planecount,cellcount; 01320 long tmp; 01321 01322 o = get_jit_java_jitobj(env,obj); 01323 if(!o||!array) 01324 return 0; 01325 01326 mat = jit_object_method(o,ps_getmatrix); 01327 if(!mat) 01328 return 0; 01329 01330 // setup all our info, common to all copyvector methods 01331 bp = jit_java_jitmatrix_copyvectorsetup(env,mat,&dim,dimoffset,array,&count,&arrayoffset,&minfo,doa,&arraylen,1); 01332 if (!bp) 01333 return 0; 01334 01335 // get array 01336 elements = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env,(jdoubleArray)array,&is_copy); 01337 //checkException(env); //inefficient? 01338 01339 stride = minfo.dimstride[dim]; 01340 planecount = minfo.planecount; 01341 cellcount = count; 01342 bp += (plane%planecount)*jit_matrix_info_typesize(&minfo); 01343 if (minfo.type==_jit_sym_char) { 01344 for (i=0,k=arrayoffset;i<cellcount;i++) { 01345 tmp = elements[k++]*255.; 01346 *bp = CLAMP(tmp,0,255); 01347 bp += stride; 01348 } 01349 } else if (minfo.type==_jit_sym_long) { 01350 for (i=0,k=arrayoffset;i<cellcount;i++) { 01351 *((long *)bp) = (long) elements[k++]; 01352 bp += stride; 01353 } 01354 } else if (minfo.type==_jit_sym_float32) { 01355 for (i=0,k=arrayoffset;i<cellcount;i++) { 01356 *((float *)bp) = (float) elements[k++]; 01357 bp += stride; 01358 } 01359 } else if (minfo.type==_jit_sym_float64) { 01360 for (i=0,k=arrayoffset;i<cellcount;i++) { 01361 *((double *)bp) = (double) elements[k++]; 01362 bp += stride; 01363 } 01364 } 01365 01366 // release array 01367 if (is_copy) { 01368 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)array,elements,0); 01369 checkException(env); 01370 } 01371 01372 return count; 01373 } 01374 01375 void jit_java_jitmatrix_copypackedintarraytomatrix_ndim(uchar *bp, jint *data, long *dim, long dimcount, long *dimstride, long *current, long intarraylen); 01376 jint JNICALL jit_java_jitmatrix_copypackedintarraytomatrix(JNIEnv *env, jobject obj, jobject intarray); 01377 jint JNICALL jit_java_jitmatrix_copypackedintarraytomatrix(JNIEnv *env, jobject obj, jobject intarray) 01378 { 01379 t_object *o,*mat; 01380 t_jit_matrix_info minfo; 01381 uchar *bp = NULL; 01382 long intarraylen,current,i,dimcount[JIT_MATRIX_MAX_DIMCOUNT]; 01383 jint *data; 01384 jboolean is_copy; 01385 01386 o = get_jit_java_jitobj(env,obj); 01387 if(!o||!intarray) 01388 return 0; 01389 01390 mat = jit_object_method(o,ps_getmatrix); 01391 if(!mat) 01392 return 0; 01393 01394 // get pointer and matrix info 01395 jit_object_method(mat,_jit_sym_getinfo,&minfo); 01396 jit_object_method(mat,_jit_sym_getdata,&bp); 01397 if (!bp) 01398 return 0; 01399 if ((minfo.type != _jit_sym_char)||(minfo.planecount != 4)) 01400 return 0; 01401 01402 intarraylen = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,intarray); 01403 data = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)intarray,&is_copy); 01404 01405 current = 0; 01406 01407 jit_java_jitmatrix_copypackedintarraytomatrix_ndim(bp, data, minfo.dim, minfo.dimcount, minfo.dimstride, ¤t, intarraylen); 01408 01409 if (is_copy) { 01410 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)intarray,data,0); 01411 01412 checkException(env); 01413 } 01414 01415 01416 return current; 01417 } 01418 01419 void jit_java_jitmatrix_copypackedintarraytomatrix_ndim( uchar *bp, jint *data, long *dim, long dimcount, long *dimstride, long *current, long intarraylen ) 01420 { 01421 long i,j; 01422 uchar *bp2; 01423 switch (dimcount) 01424 { 01425 case 1: 01426 dim[1] = 1; 01427 case 2: 01428 for (j=0; (j<dim[1])&&(*current < intarraylen); j++) 01429 for (i=0; (i<dim[0])&&(*current < intarraylen); i++) 01430 { 01431 long temp = data[(*current)++]; 01432 *((jint *)(bp + dimstride[0]*i + dimstride[1]*j)) = BE_I32(temp); 01433 } 01434 01435 break; 01436 default: 01437 for (i=0;(i<dim[dimcount-1])&&(*current < intarraylen);i++) 01438 { 01439 bp2 = bp + i*dimstride[dimcount-1]; 01440 jit_java_jitmatrix_copypackedintarraytomatrix_ndim(bp2, data, dim, dimcount-1, dimstride, current, intarraylen); 01441 } 01442 break; 01443 } 01444 } 01445 01446 01447 //////////////////////////////////////////////////// 01448 01449 //// 01450 /// full matrix copies 01451 01452 //////////////////////////////////////////////// 01453 01454 01455 jint JNICALL jit_java_jitmatrix_copymatrixtoarray(JNIEnv *env, jobject obj, jobject jarray, t_symbol *type); 01456 01457 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_int(JNIEnv *env, jobject obj, jobject jarray); 01458 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_int(JNIEnv *env, jobject obj, jobject jarray) 01459 { 01460 return jit_java_jitmatrix_copymatrixtoarray(env, obj, jarray, _jit_sym_long); 01461 } 01462 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_float(JNIEnv *env, jobject obj, jobject jarray); 01463 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_float(JNIEnv *env, jobject obj, jobject jarray) 01464 { 01465 return jit_java_jitmatrix_copymatrixtoarray(env, obj, jarray, _jit_sym_float32); 01466 } 01467 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_double(JNIEnv *env, jobject obj, jobject jarray); 01468 jint JNICALL jit_java_jitmatrix_copymatrixtoarray_double(JNIEnv *env, jobject obj, jobject jarray) 01469 { 01470 return jit_java_jitmatrix_copymatrixtoarray(env, obj, jarray, _jit_sym_float64); 01471 } 01472 01473 void jit_java_jitmatrix_copymatrixtoarray_ndim( uchar *bp, void *data, long *dim, long dimcount, long *dimstride, long planecount, 01474 long *current, long jarraylen, t_symbol *matrixtype, t_symbol *jarraytype ); 01475 01476 jint JNICALL jit_java_jitmatrix_copymatrixtoarray(JNIEnv *env, jobject obj, jobject jarray, t_symbol *type) 01477 { 01478 t_object *o,*mat; 01479 t_jit_matrix_info minfo; 01480 uchar *bp = NULL; 01481 long matrixlen,jarraylen,current,i,dimcount[JIT_MATRIX_MAX_DIMCOUNT]; 01482 void *jdata; 01483 jboolean is_copy; 01484 01485 o = get_jit_java_jitobj(env,obj); 01486 if(!o||!jarray) 01487 return 0; 01488 01489 mat = jit_object_method(o,ps_getmatrix); 01490 if(!mat) 01491 return 0; 01492 01493 // get pointer and matrix info 01494 jit_object_method(mat,_jit_sym_getinfo,&minfo); 01495 jit_object_method(mat,_jit_sym_getdata,&bp); 01496 if (!bp) 01497 return 0; 01498 01499 //get length and data pointer to array passed in by Java 01500 jarraylen = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,jarray); 01501 01502 current = 0; 01503 01504 matrixlen = minfo.planecount; 01505 for (i=0;i<minfo.dimcount;i++) 01506 matrixlen *= minfo.dim[i]; 01507 01508 // support larger, but not smaller arrays -jkc 01509 if (jarraylen < matrixlen) 01510 return 0; 01511 01512 // had to move this after our test and return, since if is_copy==TRUE and 01513 // the arraylen isn't the right size, we have a memory leak. -jkc 01514 if (type == _jit_sym_long) 01515 jdata = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)jarray,&is_copy); 01516 else if (type == _jit_sym_float32) 01517 jdata = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env, (jfloatArray)jarray,&is_copy); 01518 else if (type == _jit_sym_float64) 01519 jdata = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env, (jdoubleArray)jarray,&is_copy); 01520 01521 01522 jit_java_jitmatrix_copymatrixtoarray_ndim(bp, jdata, minfo.dim, minfo.dimcount, minfo.dimstride, minfo.planecount, 01523 ¤t, jarraylen, minfo.type, type); 01524 01525 if (type == _jit_sym_long) 01526 JIT_JAVA_JNI_CALL(env,SetIntArrayRegion)(env,(jintArray)jarray,0,jarraylen,jdata); 01527 else if (type == _jit_sym_float32) 01528 JIT_JAVA_JNI_CALL(env,SetFloatArrayRegion)(env,(jfloatArray)jarray,0,jarraylen,jdata); 01529 else if (type == _jit_sym_float64) 01530 JIT_JAVA_JNI_CALL(env,SetDoubleArrayRegion)(env,(jdoubleArray)jarray,0,jarraylen,jdata); 01531 01532 if (is_copy) { 01533 if (type == _jit_sym_long) 01534 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)jarray,jdata,0); 01535 else if (type == _jit_sym_float32) 01536 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)jarray,jdata,0); 01537 else if (type == _jit_sym_float64) 01538 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)jarray,jdata,0); 01539 01540 checkException(env); 01541 } 01542 01543 return current; 01544 } 01545 01546 01547 void jit_java_jitmatrix_copymatrixtoarray_ndim( uchar *bp, void *data, long *dim, long dimcount, long *dimstride, long planecount, 01548 long *current, long jarraylen, t_symbol *matrixtype, t_symbol *jarraytype ) 01549 { 01550 long i,j,p; 01551 uchar *bp2; 01552 long *ldata = data; 01553 float *fdata = data; 01554 double *ddata = data; 01555 switch (dimcount) 01556 { 01557 case 1: 01558 dim[1] = 1; 01559 case 2: 01560 01561 for (j=0; j<dim[1]; j++) 01562 for (i=0; i<dim[0]; i++) 01563 for (p=0;p<planecount;p++) 01564 { 01565 //this code would traditionally be considered slow, but hooray for branch prediction!! 01566 01567 if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_long)) 01568 *(ldata + (*current)++) = (long)(*(uchar *)(bp + p + dimstride[0]*i + dimstride[1]*j)); 01569 else if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_float32)) 01570 *(fdata + (*current)++) = (float)(*(uchar *)(bp + p + dimstride[0]*i + dimstride[1]*j)); 01571 else if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_float64)) 01572 *(ddata + (*current)++) = (double)(*(uchar *)(bp + p + dimstride[0]*i + dimstride[1]*j)); 01573 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_long)) 01574 *(ldata + (*current)++) = *(long *)(bp + p*sizeof(long) + dimstride[0]*i + dimstride[1]*j); 01575 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_float32)) 01576 *(fdata + (*current)++) = (float)(*(long *)(bp + p*sizeof(long) + dimstride[0]*i + dimstride[1]*j)); 01577 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_float64)) 01578 *(ddata + (*current)++) = (double)(*(long *)(bp + p*sizeof(long) + dimstride[0]*i + dimstride[1]*j)); 01579 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_long)) 01580 *(ldata + (*current)++) = (long)(*(float *)(bp + p*sizeof(float) + dimstride[0]*i + dimstride[1]*j)); 01581 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_float32)) 01582 *(fdata + (*current)++) = *(float *)(bp + p*sizeof(float) + dimstride[0]*i + dimstride[1]*j); 01583 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_float64)) 01584 *(ddata + (*current)++) = (double)(*(float *)(bp + p*sizeof(float) + dimstride[0]*i + dimstride[1]*j)); 01585 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_long)) 01586 *(ldata + (*current)++) = (long)(*(double *)(bp + p*sizeof(double) + dimstride[0]*i + dimstride[1]*j)); 01587 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_float32)) 01588 *(fdata + (*current)++) = (float)(*(double *)(bp + p*sizeof(float) + dimstride[0]*i + dimstride[1]*j)); 01589 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_float64)) 01590 *(ddata + (*current)++) = *(double *)(bp + p*sizeof(float) + dimstride[0]*i + dimstride[1]*j); 01591 } 01592 01593 break; 01594 default: 01595 for (i=0;(i<dim[dimcount-1])&&(*current < jarraylen);i++) 01596 { 01597 bp2 = bp + i*dimstride[dimcount-1]; 01598 jit_java_jitmatrix_copymatrixtoarray_ndim(bp2, data, dim, dimcount-1, dimstride, planecount, 01599 current, jarraylen, matrixtype, jarraytype); 01600 } 01601 break; 01602 } 01603 } 01604 01605 01606 01607 jint JNICALL jit_java_jitmatrix_copyarraytomatrix(JNIEnv *env, jobject obj, jobject jarray, t_symbol *type); 01608 01609 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_int(JNIEnv *env, jobject obj, jobject jarray); 01610 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_int(JNIEnv *env, jobject obj, jobject jarray) 01611 { 01612 return jit_java_jitmatrix_copyarraytomatrix(env, obj, jarray, _jit_sym_long); 01613 } 01614 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_float(JNIEnv *env, jobject obj, jobject jarray); 01615 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_float(JNIEnv *env, jobject obj, jobject jarray) 01616 { 01617 return jit_java_jitmatrix_copyarraytomatrix(env, obj, jarray, _jit_sym_float32); 01618 } 01619 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_double(JNIEnv *env, jobject obj, jobject jarray); 01620 jint JNICALL jit_java_jitmatrix_copyarraytomatrix_double(JNIEnv *env, jobject obj, jobject jarray) 01621 { 01622 return jit_java_jitmatrix_copyarraytomatrix(env, obj, jarray, _jit_sym_float64); 01623 } 01624 01625 void jit_java_jitmatrix_copyarraytomatrix_ndim( void *bp, void *data, long *dim, long dimcount, long *dimstride, long planecount, 01626 long *current, long jarraylen, t_symbol *matrixtype, t_symbol *jarraytype ); 01627 01628 jint JNICALL jit_java_jitmatrix_copyarraytomatrix(JNIEnv *env, jobject obj, jobject jarray, t_symbol *type) 01629 { 01630 t_object *o,*mat; 01631 t_jit_matrix_info minfo; 01632 uchar *bp = NULL; 01633 long matrixlen,jarraylen,current,i,dimcount[JIT_MATRIX_MAX_DIMCOUNT]; 01634 void *jdata; 01635 jboolean is_copy; 01636 01637 o = get_jit_java_jitobj(env,obj); 01638 if(!o||!jarray) 01639 return 0; 01640 01641 mat = jit_object_method(o,ps_getmatrix); 01642 if(!mat) 01643 return 0; 01644 01645 // get pointer and matrix info 01646 jit_object_method(mat,_jit_sym_getinfo,&minfo); 01647 jit_object_method(mat,_jit_sym_getdata,&bp); 01648 if (!bp) 01649 return 0; 01650 01651 //get length and data pointer to array passed in by Java 01652 jarraylen = JIT_JAVA_JNI_CALL(env,GetArrayLength)(env,jarray); 01653 current = 0; 01654 01655 matrixlen = minfo.planecount; 01656 for (i=0;i<minfo.dimcount;i++) 01657 matrixlen *= minfo.dim[i]; 01658 if (jarraylen != matrixlen) 01659 return 0; 01660 01661 if (type == _jit_sym_long) 01662 jdata = JIT_JAVA_JNI_CALL(env, GetIntArrayElements)(env,(jintArray)jarray,&is_copy); 01663 else if (type == _jit_sym_float32) 01664 jdata = JIT_JAVA_JNI_CALL(env, GetFloatArrayElements)(env, (jfloatArray)jarray,&is_copy); 01665 else if (type == _jit_sym_float64) 01666 jdata = JIT_JAVA_JNI_CALL(env, GetDoubleArrayElements)(env, (jdoubleArray)jarray,&is_copy); 01667 01668 jit_java_jitmatrix_copyarraytomatrix_ndim(bp, jdata, minfo.dim, minfo.dimcount, minfo.dimstride, minfo.planecount, 01669 ¤t, jarraylen, minfo.type, type); 01670 01671 if (is_copy) { 01672 if (type == _jit_sym_long) 01673 JIT_JAVA_JNI_CALL(env, ReleaseIntArrayElements)(env,(jintArray)jarray,jdata,0); 01674 else if (type == _jit_sym_float32) 01675 JIT_JAVA_JNI_CALL(env, ReleaseFloatArrayElements)(env,(jfloatArray)jarray,jdata,0); 01676 else if (type == _jit_sym_float64) 01677 JIT_JAVA_JNI_CALL(env, ReleaseDoubleArrayElements)(env,(jdoubleArray)jarray,jdata,0); 01678 01679 checkException(env); 01680 } 01681 01682 return current; 01683 } 01684 01685 01686 void jit_java_jitmatrix_copyarraytomatrix_ndim( void *bp, void *data, long *dim, long dimcount, long *dimstride, long planecount, 01687 long *current, long jarraylen, t_symbol *matrixtype, t_symbol *jarraytype ) 01688 { 01689 long i,j,p; 01690 uchar *bp2; 01691 long *ldata = data; 01692 float *fdata = data; 01693 double *ddata = data; 01694 uchar *cbp = bp; 01695 long *lbp = bp; 01696 float *fbp = bp; 01697 double *dbp = bp; 01698 switch (dimcount) 01699 { 01700 case 1: 01701 dim[1] = 1; 01702 case 2: 01703 01704 for (j=0; j<dim[1]; j++) 01705 for (i=0; i<dim[0]; i++) 01706 for (p=0;p<planecount;p++) 01707 { 01708 //this code would traditionally be considered slow, but hooray for branch prediction!! 01709 01710 if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_long)) 01711 *(cbp + p + dimstride[0]*i + dimstride[1]*j) = *(ldata + (*current)++); 01712 else if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_float32)) 01713 *(cbp + p + dimstride[0]*i + dimstride[1]*j) = *(fdata + (*current)++); 01714 else if ((matrixtype == _jit_sym_char) && (jarraytype == _jit_sym_float64)) 01715 *(cbp + p + dimstride[0]*i + dimstride[1]*j) = *(ddata + (*current)++); 01716 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_long)) 01717 *(lbp + p + dimstride[0]*i/sizeof(long) + dimstride[1]/sizeof(long)*j) = *(ldata + (*current)++); 01718 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_float32)) 01719 *(lbp + p + dimstride[0]*i/sizeof(long) + dimstride[1]/sizeof(long)*j) = *(fdata + (*current)++); 01720 else if ((matrixtype == _jit_sym_long) && (jarraytype == _jit_sym_float64)) 01721 *(lbp + p + dimstride[0]*i/sizeof(long) + dimstride[1]/sizeof(long)*j) = *(ddata + (*current)++); 01722 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_long)) 01723 *(fbp + p + dimstride[0]*i/sizeof(float) + dimstride[1]/sizeof(float)*j) = *(ldata + (*current)++); 01724 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_float32)) 01725 *(fbp + p + dimstride[0]*i/sizeof(float) + dimstride[1]/sizeof(float)*j) = *(fdata + (*current)++); 01726 else if ((matrixtype == _jit_sym_float32) && (jarraytype == _jit_sym_float64)) 01727 *(fbp + p + dimstride[0]*i/sizeof(float) + dimstride[1]/sizeof(float)*j) = *(ddata + (*current)++); 01728 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_long)) 01729 *(dbp + p + dimstride[0]*i/sizeof(double) + dimstride[1]/sizeof(double)*j) = *(ldata + (*current)++); 01730 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_float32)) 01731 *(dbp + p + dimstride[0]*i/sizeof(double) + dimstride[1]/sizeof(double)*j) = *(fdata + (*current)++); 01732 else if ((matrixtype == _jit_sym_float64) && (jarraytype == _jit_sym_float64)) 01733 *(dbp + p + dimstride[0]*i/sizeof(double) + dimstride[1]/sizeof(double)*j) = *(ddata + (*current)++); 01734 } 01735 01736 break; 01737 default: 01738 for (i=0;(i<dim[dimcount-1])&&(*current < jarraylen);i++) 01739 { 01740 bp2 = (void *)((char *)(bp) + i*dimstride[dimcount-1]); 01741 jit_java_jitmatrix_copyarraytomatrix_ndim(bp2, data, dim, dimcount-1, dimstride, planecount, 01742 current, jarraylen, matrixtype, jarraytype); 01743 } 01744 break; 01745 } 01746 } 01747 01748 01749 01750 01751 t_jit_err jit_java_jitmatrix_init(void) 01752 { 01753 JNIEnv *env=NULL; 01754 t_jit_err err = JIT_ERR_GENERIC; 01755 THREADENV(env); 01756 01757 ps_getmatrix = gensym("getmatrix"); 01758 ps_getcell = gensym("getcell"); 01759 ps_setall = gensym("setall"); 01760 ps_setcell = gensym("setcell"); 01761 ps_setcell3d = gensym("setcell3d"); 01762 ps_val = gensym("val"); 01763 ps_plane = gensym("plane"); 01764 01765 JIT_JAVA_JNI_CALL(env,PushLocalFrame)(env,JIT_JAVA_FRAME_SIZE); 01766 01767 g_jit_java_jitmatrix_clazz = jit_java_getclassbyname(env, JIT_JAVA_JITMATRIX_CLASSNAME); 01768 checkException(env); 01769 jit_java_jitmatrix_register_natives(env,g_jit_java_jitmatrix_clazz); 01770 checkException(env); 01771 01772 err = JIT_ERR_NONE; 01773 JIT_JAVA_JNI_CALL(env,PopLocalFrame)(env,NULL); 01774 return err; 01775 } 01776 01777 void jit_java_jitmatrix_register_natives(JNIEnv *env, jclass clazz) 01778 { 01779 int i,count=0; 01780 JNINativeMethod methods[] = 01781 { 01782 01783 // getcell methods 01784 //public native Atom[] getcell3d(int x, int y, int z); 01785 { "getcell3d","(III)[Lcom/cycling74/max/Atom;",jit_java_jitmatrix_getcell3d_atom }, 01786 //public native int[] getcellInt(int[] position); 01787 { "getcellInt","([I)[I",jit_java_jitmatrix_getcell_int }, 01788 //public native int[] getcell3dInt(int x, int y, int z); 01789 { "getcell3dInt","(III)[I",jit_java_jitmatrix_getcell3d_int }, 01790 //public native float[] getcellFloat(int[] position); 01791 { "getcellFloat","([I)[F",jit_java_jitmatrix_getcell_float }, 01792 //public native float[] getcell3dFloat(int x, int y, int z); 01793 { "getcell3dFloat","(III)[F",jit_java_jitmatrix_getcell3d_float }, 01794 //public native double[] getcellDouble(int[] position); 01795 { "getcellDouble","([I)[D",jit_java_jitmatrix_getcell_double }, 01796 //public native double[] getcell3dDouble(int x, int y, int z); 01797 { "getcell3dDouble","(III)[D",jit_java_jitmatrix_getcell3d_double }, 01798 01799 // setcell methods 01800 //public native void setall(double[] vals); 01801 { "setall","([D)V",jit_java_jitmatrix_setall_double }, 01802 //public native void setcell(int[] position, int[] vals); 01803 { "setcell","([I[I)V",jit_java_jitmatrix_setcell_int }, 01804 //public native void setcell(int[] position, float[] vals); 01805 { "setcell","([I[F)V",jit_java_jitmatrix_setcell_float }, 01806 //public native void setcell(int[] position, double[] vals); 01807 { "setcell","([I[D)V",jit_java_jitmatrix_setcell_double }, 01808 //public native void setcell(int[] position, int plane, int val); 01809 { "setcell","([III)V",jit_java_jitmatrix_setcell_plane_int }, 01810 //public native void setcell(int[] position, int plane, float val); 01811 { "setcell","([IIF)V",jit_java_jitmatrix_setcell_plane_float }, 01812 //public native void setcell(int[] position, int plane, double val); 01813 { "setcell","([IID)V",jit_java_jitmatrix_setcell_plane_double }, 01814 //public native void setcell3d(int x, int y, int z, int[] vals); 01815 { "setcell3d","(III[I)V",jit_java_jitmatrix_setcell3d_int }, 01816 //public native void setcell3d(int x, int y, int z, float[] vals); 01817 { "setcell3d","(III[F)V",jit_java_jitmatrix_setcell3d_float }, 01818 //public native void setcell3d(int x, int y, int z, double[] vals); 01819 { "setcell3d","(III[D)V",jit_java_jitmatrix_setcell3d_double }, 01820 01821 // vector copy methods 01822 //public native int copyVectorToArray(int dim, int[] offset, int[] array, int count, int arrayoffset); 01823 { "copyVectorToArray","(I[I[III)I",jit_java_jitmatrix_copyvectortoarray_int }, 01824 //public native int copyVectorToArray(int dim, int[] offset, float[] array, int count, int arrayoffset); 01825 { "copyVectorToArray","(I[I[FII)I",jit_java_jitmatrix_copyvectortoarray_float }, 01826 //public native int copyVectorToArray(int dim, int[] offset, double[] array, int count, int arrayoffset); 01827 { "copyVectorToArray","(I[I[DII)I",jit_java_jitmatrix_copyvectortoarray_double }, 01828 //public native int copyVectorToArrayPlanar(int plane, int dim, int[] offset, int[] array, int count, int arrayoffset); 01829 { "copyVectorToArrayPlanar","(II[I[III)I",jit_java_jitmatrix_copyvectortoarrayplanar_int }, 01830 //public native int copyVectorToArrayPlanar(int plane, int dim, int[] offset, float[] array, int count, int arrayoffset); 01831 { "copyVectorToArrayPlanar","(II[I[FII)I",jit_java_jitmatrix_copyvectortoarrayplanar_float }, 01832 //public native int copyVectorToArrayPlanar(int plane, int dim, int[] offset, double[] array, int count, int arrayoffset); 01833 { "copyVectorToArrayPlanar","(II[I[DII)I",jit_java_jitmatrix_copyvectortoarrayplanar_double }, 01834 //public native int copyArrayToVector(int dim, int[] offset, int[] array, int count, int arrayoffset); 01835 { "copyArrayToVector","(I[I[III)I",jit_java_jitmatrix_copyarraytovector_int }, 01836 //public native int copyArrayToVector(int dim, int[] offset, float[] array, int count, int arrayoffset); 01837 { "copyArrayToVector","(I[I[FII)I",jit_java_jitmatrix_copyarraytovector_float }, 01838 //public native int copyArrayToVector(int dim, int[] offset, double[] array, int count, int arrayoffset); 01839 { "copyArrayToVector","(I[I[DII)I",jit_java_jitmatrix_copyarraytovector_double }, 01840 //public native int copyArrayToVectorPlanar(int plane, int dim, int[] offset, int[] array, int count, int arrayoffset); 01841 { "copyArrayToVectorPlanar","(II[I[III)I",jit_java_jitmatrix_copyarraytovectorplanar_int }, 01842 //public native int copyArrayToVectorPlanar(int plane, int dim, int[] offset, float[] array, int count, int arrayoffset); 01843 { "copyArrayToVectorPlanar","(II[I[FII)I",jit_java_jitmatrix_copyarraytovectorplanar_float }, 01844 //public native int copyArrayToVectorPlanar(int plane, int dim, int[] offset, double[] array, int count, int arrayoffset); 01845 { "copyArrayToVectorPlanar","(II[I[DII)I",jit_java_jitmatrix_copyarraytovectorplanar_double }, 01846 01847 {"copyPackedIntArrayToMatrix","([I)I",jit_java_jitmatrix_copypackedintarraytomatrix }, 01848 01849 { "copyMatrixToArray", "([I)I", jit_java_jitmatrix_copymatrixtoarray_int }, 01850 { "copyMatrixToArray", "([F)I", jit_java_jitmatrix_copymatrixtoarray_float }, 01851 { "copyMatrixToArray", "([D)I", jit_java_jitmatrix_copymatrixtoarray_double }, 01852 01853 { "copyArrayToMatrix", "([I)I", jit_java_jitmatrix_copyarraytomatrix_int }, 01854 { "copyArrayToMatrix", "([F)I", jit_java_jitmatrix_copyarraytomatrix_float }, 01855 { "copyArrayToMatrix", "([D)I", jit_java_jitmatrix_copyarraytomatrix_double }, 01856 01857 // buffered image methods? 01858 // TODO 01859 01860 // NIO methods? 01861 // TODO 01862 01863 { NULL, NULL, NULL } 01864 }; 01865 01866 if (!clazz) 01867 return; 01868 while (methods[count].name) count++; 01869 JIT_JAVA_JNI_CALL(env,RegisterNatives)(env,clazz,methods,count); 01870 checkException(env); 01871 }
Copyright © 2008, Cycling '74