Max 5 API Reference
00001 /* 00002 jit.bin.c 00003 Copyright 2001-2005 - Cycling '74 00004 Jeremy Bernstein jeremy@bootsquad.com 00005 Joshua Kit Clayton jkc@cycling74.com 00006 */ 00007 00008 #include "jit.common.h" 00009 #include "jit.bin.h" 00010 00011 /** 00012 * @defgroup binmod Binary Module 00013 @ingroup jitter 00014 */ 00015 00016 t_jit_err jit_bin_read_matrix_ndim (t_filehandle fh, long dimcount, long *dim, t_jit_matrix_info *info, char *bp); 00017 t_jit_err jit_bin_read_matrix_char (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00018 t_jit_err jit_bin_read_matrix_long (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00019 t_jit_err jit_bin_read_matrix_float32 (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00020 t_jit_err jit_bin_read_matrix_float64 (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00021 00022 t_jit_err jit_bin_write_matrix_ndim (t_filehandle fh, long dimcount, long *dim, t_jit_matrix_info *info, char *bp); 00023 t_jit_err jit_bin_write_matrix_char (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00024 t_jit_err jit_bin_write_matrix_long (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00025 t_jit_err jit_bin_write_matrix_float32 (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00026 t_jit_err jit_bin_write_matrix_float64 (t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp); 00027 00028 /** 00029 * Reads the header of a JXF binary file. 00030 * 00031 * @ingroup binmod 00032 * 00033 * @param fh t_filehandle file handle 00034 * @param version version of the binary file format (ie JIT_BIN_VERSION_1) 00035 * @param filesize the size of the file 00036 * 00037 * @return t_jit_err error code. 00038 * 00039 */ 00040 t_jit_err jit_bin_read_header(t_filehandle fh, ulong *version, long *filesize) 00041 { 00042 long err=JIT_ERR_NONE,size; 00043 long tmp[6]; 00044 00045 *version = 0; 00046 *filesize = 0; 00047 00048 if (fh) { 00049 size=24; 00050 sysfile_setpos(fh,fsFromStart,0); 00051 if ((err=sysfile_read(fh, &size, &tmp))||(size!=24)) 00052 goto out; 00053 00054 if ((BE_I32(tmp[0])!=JIT_BIN_CHUNK_CONTAINER)&&(BE_I32(tmp[2])!=JIT_BIN_FORMAT)) { 00055 err = JIT_ERR_GENERIC; 00056 goto out; 00057 } 00058 00059 *filesize = BE_I32(tmp[1]); 00060 00061 if ((BE_I32(tmp[3])!=JIT_BIN_CHUNK_FORMAT_VERSION)&&(tmp[4]!=BE_I32(12))) { 00062 err = JIT_ERR_GENERIC; 00063 goto out; 00064 } 00065 00066 *version = BE_I32(tmp[5]); 00067 00068 } else { 00069 err = JIT_ERR_INVALID_PTR; 00070 } 00071 out: 00072 return err; 00073 } 00074 00075 00076 /** 00077 * Reads the the info of a chunk from a JXF binary file. 00078 * 00079 * @ingroup binmod 00080 * 00081 * @param fh t_filehandle file handle 00082 * @param ckid chunk ID (ie JIT_BIN_CHUNK_CONTAINER, JIT_BIN_CHUNK_MATRIX) 00083 * @param cksize the size of the chunk 00084 * 00085 * @return t_jit_err error code. 00086 * 00087 */ 00088 t_jit_err jit_bin_read_chunk_info(t_filehandle fh, ulong *ckid, long *cksize) 00089 { 00090 long err=JIT_ERR_NONE,size; 00091 long tmp[2]; 00092 00093 *ckid = 0; 00094 *cksize = 0; 00095 00096 if (fh) { 00097 size=8; 00098 if ((err=sysfile_read(fh, &size, &tmp))&&(size!=8)) 00099 goto out; 00100 00101 *ckid = BE_I32(tmp[0]); 00102 *cksize = BE_I32(tmp[1]); 00103 sysfile_setpos(fh,fsFromMark,-8); 00104 } else { 00105 err = JIT_ERR_INVALID_PTR; 00106 } 00107 out: 00108 return err; 00109 } 00110 00111 /** 00112 * Writes the header of a JXF binary file. 00113 * 00114 * @ingroup binmod 00115 * 00116 * @param fh t_filehandle file handle 00117 * @param filesize the size of the file 00118 * 00119 * @return t_jit_err error code. 00120 * 00121 */ 00122 t_jit_err jit_bin_write_header(t_filehandle fh, long filesize) 00123 { 00124 long err=JIT_ERR_NONE,size; 00125 long tmp[6]; 00126 00127 if (fh) { 00128 tmp[0] = BE_I32(JIT_BIN_CHUNK_CONTAINER); 00129 tmp[1] = BE_I32(filesize); 00130 tmp[2] = BE_I32(JIT_BIN_FORMAT); 00131 tmp[3] = BE_I32(JIT_BIN_CHUNK_FORMAT_VERSION); 00132 tmp[4] = BE_I32(12); 00133 tmp[5] = BE_I32(JIT_BIN_VERSION_1); 00134 00135 size=24; 00136 sysfile_setpos(fh,fsFromStart,0); 00137 err = sysfile_write(fh, &size, &tmp); 00138 00139 } else { 00140 err = JIT_ERR_INVALID_PTR; 00141 } 00142 00143 return err; 00144 } 00145 00146 /** 00147 * Reads matrix data from a JXF binary file. 00148 * 00149 * @ingroup binmod 00150 * 00151 * @param fh t_filehandle file handle 00152 * @param matrix the matrix data 00153 * 00154 * @return t_jit_err error code. 00155 * 00156 */ 00157 t_jit_err jit_bin_read_matrix(t_filehandle fh, void *matrix) 00158 { 00159 long err = JIT_ERR_NONE, i; 00160 t_jit_matrix_info info; 00161 long dim[JIT_MATRIX_MAX_DIMCOUNT]; 00162 char *bp; 00163 long savelock; 00164 long tmp[JIT_MATRIX_MAX_DIMCOUNT],cksize,size,offset,points,typesize,typeID; 00165 00166 if (fh&&matrix) { 00167 00168 //read standard matrix chunk info 00169 size = 24; 00170 if (err = sysfile_read(fh, &size, &tmp)) 00171 goto out; 00172 00173 if (BE_I32(tmp[0])!=JIT_BIN_CHUNK_MATRIX) { 00174 err = JIT_ERR_GENERIC; 00175 goto out; 00176 } 00177 00178 info.flags = 0; 00179 00180 cksize = BE_I32(tmp[1]); 00181 offset = BE_I32(tmp[2]); 00182 typeID = BE_I32(tmp[3]); 00183 info.planecount = BE_I32(tmp[4]); 00184 info.dimcount = BE_I32(tmp[5]); 00185 00186 switch (typeID) { 00187 case JIT_BIN_TYPE_CHAR: 00188 info.type = _jit_sym_char; 00189 break; 00190 case JIT_BIN_TYPE_LONG: 00191 info.type = _jit_sym_long; 00192 break; 00193 case JIT_BIN_TYPE_FLOAT32: 00194 info.type = _jit_sym_float32; 00195 break; 00196 case JIT_BIN_TYPE_FLOAT64: 00197 info.type = _jit_sym_float64; 00198 break; 00199 default: 00200 err = JIT_ERR_GENERIC; 00201 goto out; 00202 } 00203 00204 //read dim values 00205 size = info.dimcount*4; 00206 if (err = sysfile_read(fh, &size, &tmp)) 00207 goto out; 00208 00209 for (i=0;i<info.dimcount;i++) { 00210 dim[i] = info.dim[i] = BE_I32(tmp[i]); 00211 } 00212 00213 //resize the matrix 00214 00215 if (err=(t_jit_err)jit_object_method(matrix,_jit_sym_setinfo,&info)) 00216 goto out; 00217 00218 savelock = (long) jit_object_method(matrix,_jit_sym_lock,1); 00219 jit_object_method(matrix,_jit_sym_getinfo, &info); 00220 jit_object_method(matrix, _jit_sym_getdata, &bp); 00221 if (!bp) { err=JIT_ERR_GENERIC; goto clean;} 00222 00223 //read the data 00224 err = jit_bin_read_matrix_ndim(fh, info.dimcount, dim, &info, bp); 00225 } else { 00226 return JIT_ERR_INVALID_PTR; 00227 } 00228 00229 clean: 00230 jit_object_method(matrix, gensym("lock"), savelock); 00231 out: 00232 //exporting this as part of API, so removed error posting -bbn 00233 //if (err) jit_object_post((t_object *)x,"error %ld reading file", err); 00234 return err; 00235 } 00236 00237 00238 t_jit_err jit_bin_read_matrix_ndim(t_filehandle fh, long dimcount, long *dim, t_jit_matrix_info *info, char *bp) 00239 { 00240 char *p; 00241 long i; 00242 t_jit_err err = JIT_ERR_NONE; 00243 00244 if (dimcount<1) return err; //safety 00245 00246 switch(dimcount) { 00247 case 1: 00248 dim[1]=1; 00249 case 2: 00250 if (info->type == _jit_sym_char) // these functions located in m2t.c 00251 err = jit_bin_read_matrix_char(fh, dim, info, bp); 00252 else if (info->type == _jit_sym_long) 00253 err = jit_bin_read_matrix_long(fh, dim, info, bp); 00254 else if (info->type == _jit_sym_float32) 00255 err = jit_bin_read_matrix_float32(fh, dim, info, bp); 00256 else if (info->type == _jit_sym_float64) 00257 err = jit_bin_read_matrix_float64(fh, dim, info, bp); 00258 break; 00259 default: 00260 for (i = 0; i < dim[dimcount-1]; i++) { 00261 p = bp + i * info->dimstride[dimcount-1]; 00262 jit_bin_read_matrix_ndim(fh, dimcount-1, dim, info, p); 00263 } 00264 } 00265 return err; 00266 } 00267 00268 00269 t_jit_err jit_bin_read_matrix_char(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00270 { 00271 long i,width,height,planecount; 00272 uchar *p; 00273 long err=JIT_ERR_NONE; 00274 long size,size0; 00275 00276 width = dim[0]; 00277 height = dim[1]; 00278 planecount = info->planecount; 00279 size0 = width*planecount; 00280 00281 for (i=0;i<height;i++) { 00282 p = (uchar *)(bp + i*info->dimstride[1]); 00283 size = size0; 00284 if ((err=sysfile_read(fh,&size,p))||(size!=size0)) { 00285 //exporting this as part of API, so removed error posting -bbn 00286 //jit_object_post((t_object *)x,"error %ld reading file", err); 00287 goto out; 00288 } 00289 } 00290 00291 out: 00292 return err; 00293 } 00294 00295 t_jit_err jit_bin_read_matrix_long(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00296 { 00297 long i,width,height,planecount; 00298 uchar *p; 00299 long err=JIT_ERR_NONE; 00300 long size,size0; 00301 00302 width = dim[0]; 00303 height = dim[1]; 00304 planecount = info->planecount; 00305 size0 = width*planecount*4; 00306 00307 for (i=0;i<height;i++) { 00308 p = (uchar *)(bp + i*info->dimstride[1]); 00309 size = size0; 00310 if ((err=sysfile_read(fh,&size,p))||(size!=size0)) { 00311 //exporting this as part of API, so removed error posting -bbn 00312 //jit_object_post((t_object *)x,"error %ld reading file", err); 00313 goto out; 00314 } 00315 } 00316 #ifdef JIT_LITTLE_ENDIAN 00317 { 00318 long j,k,tmp,*lp; 00319 00320 for (i=0;i<height;i++) { 00321 lp = (long *)(bp + i*info->dimstride[1]); 00322 for (j=0;j<width;j++) { 00323 for (k=0;k<planecount;k++) { 00324 tmp = *lp; 00325 *lp++ = SWAP32(tmp); 00326 } 00327 } 00328 } 00329 } 00330 #endif 00331 out: 00332 return err; 00333 } 00334 00335 t_jit_err jit_bin_read_matrix_float32(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00336 { 00337 long i,width,height,planecount; 00338 uchar *p; 00339 long err=JIT_ERR_NONE; 00340 long size,size0; 00341 00342 width = dim[0]; 00343 height = dim[1]; 00344 planecount = info->planecount; 00345 size0 = width*planecount*4; 00346 00347 for (i=0;i<height;i++) { 00348 p = (uchar *)(bp + i*info->dimstride[1]); 00349 size = size0; 00350 if ((err=sysfile_read(fh,&size,p))||(size!=size0)) { 00351 //exporting this as part of API, so removed error posting -bbn 00352 //jit_object_post((t_object *)x,"error %ld reading file", err); 00353 goto out; 00354 } 00355 } 00356 #ifdef JIT_LITTLE_ENDIAN 00357 { 00358 long j,k; 00359 float tmp,*fp; 00360 00361 for (i=0;i<height;i++) { 00362 fp = (float *)(bp + i*info->dimstride[1]); 00363 for (j=0;j<width;j++) { 00364 for (k=0;k<planecount;k++) { 00365 tmp = *fp; 00366 *fp++ = swapf32(tmp); 00367 } 00368 } 00369 } 00370 } 00371 #endif 00372 out: 00373 return err; 00374 } 00375 00376 t_jit_err jit_bin_read_matrix_float64(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00377 { 00378 long i,width,height,planecount; 00379 uchar *p; 00380 long err=JIT_ERR_NONE; 00381 long size,size0; 00382 00383 width = dim[0]; 00384 height = dim[1]; 00385 planecount = info->planecount; 00386 size0 = width*planecount*8; 00387 00388 for (i=0;i<height;i++) { 00389 p = (uchar *)(bp + i*info->dimstride[1]); 00390 size = size0; 00391 if ((err=sysfile_read(fh,&size,p))||(size!=size0)) { 00392 //exporting this as part of API, so removed error posting -bbn 00393 //jit_object_post((t_object *)x,"error %ld reading file", err); 00394 goto out; 00395 } 00396 } 00397 #ifdef JIT_LITTLE_ENDIAN 00398 { 00399 long j,k; 00400 double tmp,*fp; 00401 00402 for (i=0;i<height;i++) { 00403 fp = (double *)(bp + i*info->dimstride[1]); 00404 for (j=0;j<width;j++) { 00405 for (k=0;k<planecount;k++) { 00406 tmp = *fp; 00407 *fp++ = swapf64(tmp); 00408 } 00409 } 00410 } 00411 } 00412 #endif 00413 out: 00414 return err; 00415 } 00416 00417 /** 00418 * Writes a matrix to a JXF binary file. 00419 * 00420 * @ingroup binmod 00421 * 00422 * @param fh t_filehandle file handle 00423 * @param matrix the matrix data 00424 * 00425 * @return t_jit_err error code. 00426 * 00427 */ 00428 t_jit_err jit_bin_write_matrix(t_filehandle fh, void *matrix) 00429 { 00430 long err = JIT_ERR_NONE, i; 00431 t_jit_matrix_info info; 00432 long dim[JIT_MATRIX_MAX_DIMCOUNT]; 00433 char *bp; 00434 long savelock; 00435 long tmp[JIT_MATRIX_MAX_DIMCOUNT],cksize,size,offset,points,typesize,typeID; 00436 00437 if (fh&&matrix) { 00438 savelock = (long) jit_object_method(matrix,gensym("lock"),1); 00439 jit_object_method(matrix,gensym("getinfo"), &info); 00440 jit_object_method(matrix, gensym("getdata"), &bp); 00441 if (!bp) { err=JIT_ERR_GENERIC; goto out;} 00442 00443 cksize = 24; 00444 points = 1; 00445 00446 for (i = 0; i < info.dimcount; i++) { 00447 dim[i] = info.dim[i]; 00448 cksize += 4; 00449 points *= dim[i]; 00450 } 00451 00452 if (info.type==_jit_sym_char) { 00453 typeID = JIT_BIN_TYPE_CHAR; 00454 typesize = 1; 00455 } else if (info.type==_jit_sym_long) { 00456 typeID = JIT_BIN_TYPE_LONG; 00457 typesize = 4; 00458 } else if (info.type==_jit_sym_float32) { 00459 typeID = JIT_BIN_TYPE_FLOAT32; 00460 typesize = 4; 00461 } else if (info.type==_jit_sym_float64) { 00462 typeID = JIT_BIN_TYPE_FLOAT64; 00463 typesize = 8; 00464 } else { 00465 err = JIT_ERR_GENERIC; 00466 goto out; 00467 } 00468 00469 offset = cksize; 00470 cksize += points*info.planecount*typesize; 00471 00472 //write standard matrix chunk info 00473 tmp[0] = BE_I32(JIT_BIN_CHUNK_MATRIX); 00474 tmp[1] = BE_I32(cksize); 00475 tmp[2] = BE_I32(offset); 00476 tmp[3] = BE_I32(typeID); 00477 tmp[4] = BE_I32(info.planecount); 00478 tmp[5] = BE_I32(info.dimcount); 00479 size = 24; 00480 00481 if (err = sysfile_write(fh, &size, &tmp)) { 00482 goto out; 00483 } 00484 00485 //write dim values 00486 for (i=0;i<info.dimcount;i++) 00487 tmp[i] = BE_I32(dim[i]); 00488 size = info.dimcount*4; 00489 00490 if (err = sysfile_write(fh, &size, &tmp)) { 00491 goto out; 00492 } 00493 00494 //write the data 00495 err = jit_bin_write_matrix_ndim(fh, info.dimcount, dim, &info, bp); 00496 } else { 00497 err = JIT_ERR_INVALID_PTR; 00498 } 00499 00500 out: 00501 //exporting this as part of API, so removed error posting -bbn 00502 //if (err) jit_object_post((t_object *)x,"error %ld writing file", err); 00503 jit_object_method(matrix, gensym("lock"), savelock); 00504 return err; 00505 } 00506 00507 t_jit_err jit_bin_write_matrix_ndim(t_filehandle fh, long dimcount, long *dim, t_jit_matrix_info *info, char *bp) 00508 { 00509 char *p; 00510 long i; 00511 t_jit_err err = JIT_ERR_NONE; 00512 00513 if (dimcount<1) return err; //safety 00514 00515 switch(dimcount) { 00516 case 1: 00517 dim[1]=1; 00518 case 2: 00519 if (info->type == _jit_sym_char) // these functions located in m2t.c 00520 err = jit_bin_write_matrix_char(fh, dim, info, bp); 00521 else if (info->type == _jit_sym_long) 00522 err = jit_bin_write_matrix_long(fh, dim, info, bp); 00523 else if (info->type == _jit_sym_float32) 00524 err = jit_bin_write_matrix_float32(fh, dim, info, bp); 00525 else if (info->type == _jit_sym_float64) 00526 err = jit_bin_write_matrix_float64(fh, dim, info, bp); 00527 break; 00528 default: 00529 for (i = 0; i < dim[dimcount-1]; i++) { 00530 p = bp + i * info->dimstride[dimcount-1]; 00531 jit_bin_write_matrix_ndim(fh, dimcount-1, dim, info, p); 00532 } 00533 } 00534 return err; 00535 } 00536 00537 t_jit_err jit_bin_write_matrix_char(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00538 { 00539 long i,width,height,planecount; 00540 uchar *p; 00541 long err=JIT_ERR_NONE; 00542 long size,size0; 00543 00544 width = dim[0]; 00545 height = dim[1]; 00546 planecount = info->planecount; 00547 size0 = width*planecount; 00548 00549 for (i=0;i<height;i++) { 00550 p = (uchar *)(bp + i*info->dimstride[1]); 00551 size = size0; 00552 if ((err=sysfile_write(fh,&size,p))||(size!=size0)) { 00553 //exporting this as part of API, so removed error posting -bbn 00554 //jit_object_post((t_object *)x,"error %ld writing file", err); 00555 goto out; 00556 } 00557 } 00558 00559 out: 00560 return err; 00561 } 00562 00563 t_jit_err jit_bin_write_matrix_long(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00564 { 00565 long i,width,height,planecount; 00566 uchar *p; 00567 long err=JIT_ERR_NONE; 00568 long size,size0; 00569 #ifdef JIT_LITTLE_ENDIAN 00570 long j,k,tmp,*p0,*p1,*p2; 00571 #endif 00572 00573 width = dim[0]; 00574 height = dim[1]; 00575 planecount = info->planecount; 00576 size0 = width*planecount*4; 00577 00578 #ifdef JIT_LITTLE_ENDIAN 00579 if (!(p0=(long *)jit_getbytes(size0))) { 00580 //exporting this as part of API, so removed error posting -bbn 00581 //jit_object_post((t_object *)x,"could not allocate memory to write file"); 00582 goto out; 00583 } 00584 #endif 00585 00586 for (i=0;i<height;i++) { 00587 p = (uchar *)(bp + i*info->dimstride[1]); 00588 size = size0; 00589 #ifdef JIT_LITTLE_ENDIAN 00590 p1 = p0; 00591 p2 = (long *)p; 00592 for (j=0;j<width;j++) { 00593 for (k=0;k<planecount;k++) { 00594 tmp = *p2++; 00595 *p1++ = SWAP32(tmp); 00596 } 00597 } 00598 p = (uchar *)p0; 00599 #endif 00600 if ((err=sysfile_write(fh,&size,p))||(size!=size0)) { 00601 //exporting this as part of API, so removed error posting -bbn 00602 //jit_object_post((t_object *)x,"error %ld writing file", err); 00603 goto out; 00604 } 00605 } 00606 00607 #ifdef JIT_LITTLE_ENDIAN 00608 jit_freebytes(p0,size0); 00609 #endif 00610 00611 out: 00612 return err; 00613 } 00614 00615 t_jit_err jit_bin_write_matrix_float32(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00616 { 00617 long i,width,height,planecount; 00618 uchar *p; 00619 long err=JIT_ERR_NONE; 00620 long size,size0; 00621 #ifdef JIT_LITTLE_ENDIAN 00622 long j,k; 00623 float tmp,*p0,*p1,*p2; 00624 #endif 00625 00626 width = dim[0]; 00627 height = dim[1]; 00628 planecount = info->planecount; 00629 size0 = width*planecount*4; 00630 00631 #ifdef JIT_LITTLE_ENDIAN 00632 if (!(p0=(float *)jit_getbytes(size0))) { 00633 //exporting this as part of API, so removed error posting -bbn 00634 //jit_object_post((t_object *)x,"could not allocate memory to write file"); 00635 goto out; 00636 } 00637 #endif 00638 00639 for (i=0;i<height;i++) { 00640 p = (uchar *)(bp + i*info->dimstride[1]); 00641 size = size0; 00642 #ifdef JIT_LITTLE_ENDIAN 00643 p1 = p0; 00644 p2 = (float *)p; 00645 for (j=0;j<width;j++) { 00646 for (k=0;k<planecount;k++) { 00647 tmp = *p2++; 00648 *p1++ = swapf32(tmp); 00649 } 00650 } 00651 p = (uchar *)p0; 00652 #endif 00653 if ((err=sysfile_write(fh,&size,p))||(size!=size0)) { 00654 //exporting this as part of API, so removed error posting -bbn 00655 //jit_object_post((t_object *)x,"error %ld writing file", err); 00656 goto out; 00657 } 00658 } 00659 00660 #ifdef JIT_LITTLE_ENDIAN 00661 jit_freebytes(p0,size0); 00662 #endif 00663 00664 out: 00665 return err; 00666 } 00667 00668 t_jit_err jit_bin_write_matrix_float64(t_filehandle fh, long *dim, t_jit_matrix_info *info, char *bp) 00669 { 00670 long i,width,height,planecount; 00671 uchar *p; 00672 long err=JIT_ERR_NONE; 00673 long size,size0; 00674 #ifdef JIT_LITTLE_ENDIAN 00675 long j,k; 00676 double tmp,*p0,*p1,*p2; 00677 #endif 00678 00679 width = dim[0]; 00680 height = dim[1]; 00681 planecount = info->planecount; 00682 size0 = width*planecount*8; 00683 00684 #ifdef JIT_LITTLE_ENDIAN 00685 if (!(p0=(double *)jit_getbytes(size0))) { 00686 //exporting this as part of API, so removed error posting -bbn 00687 //jit_object_post((t_object *)x,"could not allocate memory to write file"); 00688 goto out; 00689 } 00690 #endif 00691 00692 for (i=0;i<height;i++) { 00693 p = (uchar *)(bp + i*info->dimstride[1]); 00694 size = size0; 00695 #ifdef JIT_LITTLE_ENDIAN 00696 p1 = p0; 00697 p2 = (double *)p; 00698 for (j=0;j<width;j++) { 00699 for (k=0;k<planecount;k++) { 00700 tmp = *p2++; 00701 *p1++ = swapf64(tmp); 00702 } 00703 } 00704 p = (uchar *)p0; 00705 #endif 00706 if ((err=sysfile_write(fh,&size,p))||(size!=size0)) { 00707 //exporting this as part of API, so removed error posting -bbn 00708 //jit_object_post((t_object *)x,"error %ld writing file", err); 00709 goto out; 00710 } 00711 } 00712 00713 #ifdef JIT_LITTLE_ENDIAN 00714 jit_freebytes(p0,size0); 00715 #endif 00716 00717 out: 00718 return err; 00719 }
Copyright © 2008, Cycling '74