2012年(158)
分类: C/C++
2012-11-26 16:12:42
因为找不到能打开SPE格式图像的软件,因此手写了一个。
写得比较马虎,因为只是为了看一眼图片中是啥。
没有经过测试,因为我手里就只有一幅SPE图像
#include
typedef unsigned int uint32;
void spe2bmp( const char* filename )
{
FILE* f = fopen( filename,
"rb" );
{
fseek( f, 0, SEEK_END );
long len =
ftell( f );
if( len > 4100 )
{
fseek( f,
0x6C, SEEK_SET );
unsigned short data_type; // float32, int32,
int16, uint16
fread( &data_type, sizeof(data_type), 1, f
);
if( data_type==0 || data_type==2 || data_type==3
)
{
unsigned depth = data_type<=1 ? 4 :
2;
unsigned short xdim, ydim;
uint32
frames;
fseek( f, 0x2A, SEEK_SET );
fread(
&xdim, sizeof(xdim), 1, f );
fseek( f, 0x290, SEEK_SET
);
fread( &ydim, sizeof(ydim), 1, f );
fseek( f, 0x5A6, SEEK_SET );
fread( &frames,
sizeof(frames), 1, f );
if( depth*xdim*ydim*frames ==
len-4100 )
{
int cvdepth =
data_type==0 ? IPL_DEPTH_32F : (data_type==2 ? IPL_DEPTH_16S : IPL_DEPTH_16U
);
IplImage* img = cvCreateImage( cvSize(xdim,ydim),
cvdepth, 1 );
for( int frm=0; frm<(int)frames; ++frm
)
{
fseek( f,
4100+depth*xdim*ydim*frm, SEEK_SET );
for( int y=0;
y
char* v = img->imageData +
img->widthStep*y;
fread( v, depth*xdim, 1, f
);
}
char
outname[520];
sprintf( outname, "%s.%03u.bmp",
filename, frm );
cvSaveImage( outname, img
);
}
cvReleaseImage( &img
);
}
}
}
fclose( f
);
}
}
int main()
{
spe2bmp( "5.spe" );
return 0;
}