diff --git a/DistributionChart2D.cpp b/DistributionChart2D.cpp index e043fd6..237a4ac 100644 --- a/DistributionChart2D.cpp +++ b/DistributionChart2D.cpp @@ -3,12 +3,97 @@ #include #include #include +#include #include +#include #include #include"BitmapFont.h" using namespace hgl; +OSString csv_filename; + +struct Bitmap +{ + uint width,height; + uint channels; + + uint8 *data; + +public: + + Bitmap() + { + data=nullptr; + } + + ~Bitmap() + { + delete[] data; + } +}; + +Bitmap *BackgroundBitmap=nullptr; + +bool LoadBackgroundBitmap() +{ + io::OpenFileInputStream fis(OS_TEXT("mini_map.tga")); + + if(!fis) + return(false); + + util::TGAHeader tga_header; + util::TGAImageDesc tga_desc; + + fis->Read(&tga_header,sizeof(util::TGAHeader)); + + if(tga_header.image_type!=util::TGA_IMAGE_TYPE_TRUE_COLOR) + return(false); + + if(tga_header.bit!=24) + return(false); + + tga_desc.image_desc=tga_header.image_desc; + + BackgroundBitmap=new Bitmap; + + BackgroundBitmap->width=tga_header.width; + BackgroundBitmap->height=tga_header.height; + BackgroundBitmap->channels=tga_header.bit/8; + + uint total_bytes=BackgroundBitmap->width*BackgroundBitmap->height*BackgroundBitmap->channels; + + BackgroundBitmap->data=new uint8[total_bytes]; + + if(fis->Read(BackgroundBitmap->data,total_bytes)!=total_bytes) + { + delete BackgroundBitmap; + BackgroundBitmap=nullptr; + return(false); + } + + if(tga_desc.direction==util::TGA_DIRECTION_LOWER_LEFT) + { + uint line_bytes=tga_header.width*3; + + uint8 *temp=new uint8[line_bytes]; + uint8 *tp=BackgroundBitmap->data; + uint8 *bp=tp+line_bytes*(tga_header.height-1); + + while(tpx>=1024 - ||p->y>=1024) + if(p->x>=BackgroundBitmap->width + ||p->y>=BackgroundBitmap->height) continue; //std::cout<<"X="<x<<",Y="<y<maxp.x-ps->minp.x+1; - uint height=ps->maxp.y-ps->minp.y+1; + uint width=BackgroundBitmap->width; + uint height=BackgroundBitmap->height; std::cout<<"width: "<DrawString(str,col,row,black_color,255); + + row+=CHAR_BITMAP_HEIGHT*2; - str=AnsiString("TOTAL - ")+str_total; + str=AnsiString("Total: ")+str_total; chart->DrawString(str,col,row,white_color,255); row+=CHAR_BITMAP_HEIGHT; @@ -509,6 +601,30 @@ Chart *ToChart32(const PositionStat *ps) } } + //混合底图 + if(BackgroundBitmap) + { + uint8 *p=chart->chart_data; + uint8 *bp=BackgroundBitmap->data; + uint8 alpha; + + for(uint row=0;row chart=ToChart32(ps); + OSString tga_filename; + { + tga_filename=filesystem::ReplaceExtName(csv_filename,OSString(OS_TEXT(".tga"))); + + os_out<width,chart->height,4); - io::OpenFileOutputStream fos(OS_TEXT("chart.tga"),io::FileOpenMode::CreateTrunc); + io::OpenFileOutputStream fos(tga_filename.c_str(),io::FileOpenMode::CreateTrunc); if(fos) { @@ -557,8 +694,8 @@ int os_main(int argc,os_char **argv) std::cerr<<"Create chart.tga failed!"<