Chinaunix首页 | 论坛 | 博客
  • 博客访问: 558766
  • 博文数量: 158
  • 博客积分: 4380
  • 博客等级: 上校
  • 技术积分: 2356
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-21 10:45
文章分类

全部博文(158)

文章存档

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;
}

阅读(3356) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~