// DiffractionImageCBF.cpp // Author: F. Remacle // 25 January 2005 // // The bits of the DiffractionImage library which pertain to Raxis images // images. #include "DiffractionImage.h" #include "cbf.h" #include "cbf_simple.h" #include "cbf_string.h" #include "cbf_byte_offset.h" using namespace std; namespace DI { void DiffractionImage::loadCBF() { cbf_handle cbfh2; FILE* imagefile2; int test; //read the header loadCBFHeader(); allocateImage(); imagefile2 = fopen(filename.c_str(),"rb"); if(format.compare("MINI-CBF") == 0) { //throw(DiffractionImageException("Image Reading for Mini-CBF not supported yet")); cbf_file* ccbbff; cbf_make_file(&ccbbff,imagefile2); char* header_info= new char[256]; int skip=0; int sign=0; int nelements=0; size_t nread=0; int padding=0; string byte_ord=""; while(strstr(header_info,"--CIF-BINARY-FORMAT-SECTION--")==NULL) { fgets(header_info,256,imagefile2); skip+=strlen(header_info); } while(strcmp(header_info,"\n")!=0) { fgets(header_info,256,imagefile2); if(strstr(header_info,"signed")!=NULL) sign=1; if(strstr(header_info,"LITTLE_ENDIAN")!=NULL) byte_ord="LITTLE_ENDIAN"; if(strstr(header_info,"BIG_ENDIAN")!=NULL) byte_ord="BIG_ENDIAN"; if(strstr(header_info,"X-Binary-Number-of-Elements:")!=NULL) sscanf(header_info,"%*s %d",&nelements); if(strstr(header_info,"X-Binary-Size-Padding:")!=NULL) sscanf(header_info,"%*s %d",&padding); skip+=strlen(header_info); } fseek(imagefile2,0,SEEK_SET); cbf_set_fileposition (ccbbff, skip,SEEK_SET); int* tmpimg; tmpimg=new int[height*width]; test= cbf_decompress_byte_offset ((void *)tmpimg,sizeof(int),sign, nelements,&nread,0,32,sign,ccbbff,0, byte_ord.c_str(),2,(size_t) width, (size_t) height,1,(size_t) padding); for(int i=0;i