DistributionChart2D use Bitmap<uint8,3> instead of old codes.

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-11 16:05:22 +08:00
parent f34c066dbd
commit 2ce81232aa

View File

@ -7,33 +7,16 @@
#include<hgl/io/FileOutputStream.h> #include<hgl/io/FileOutputStream.h>
#include<hgl/filesystem/Filename.h> #include<hgl/filesystem/Filename.h>
#include<iostream> #include<iostream>
#include<hgl/2d/Bitmap.h>
#include"BitmapFont.h" #include"BitmapFont.h"
using namespace hgl; using namespace hgl;
OSString csv_filename; OSString csv_filename;
struct Bitmap using BitmapRGB8=hgl::Bitmap<uint8,3>;
{
uint width,height;
uint channels;
uint8 *data; BitmapRGB8 *BackgroundBitmap=nullptr;
public:
Bitmap()
{
data=nullptr;
}
~Bitmap()
{
delete[] data;
}
};
Bitmap *BackgroundBitmap=nullptr;
bool LoadBackgroundBitmap() bool LoadBackgroundBitmap()
{ {
@ -55,17 +38,13 @@ bool LoadBackgroundBitmap()
tga_desc.image_desc=tga_header.image_desc; tga_desc.image_desc=tga_header.image_desc;
BackgroundBitmap=new Bitmap; BackgroundBitmap=new BitmapRGB8;
BackgroundBitmap->width=tga_header.width; BackgroundBitmap->Create(tga_header.width,tga_header.height);
BackgroundBitmap->height=tga_header.height;
BackgroundBitmap->channels=tga_header.bit/8;
uint total_bytes=BackgroundBitmap->width*BackgroundBitmap->height*BackgroundBitmap->channels; const uint total_bytes=BackgroundBitmap->GetTotalBytes();
BackgroundBitmap->data=new uint8[total_bytes]; if(fis->Read(BackgroundBitmap->GetData(),total_bytes)!=total_bytes)
if(fis->Read(BackgroundBitmap->data,total_bytes)!=total_bytes)
{ {
delete BackgroundBitmap; delete BackgroundBitmap;
BackgroundBitmap=nullptr; BackgroundBitmap=nullptr;
@ -73,23 +52,7 @@ bool LoadBackgroundBitmap()
} }
if(tga_desc.direction==util::TGA_DIRECTION_LOWER_LEFT) if(tga_desc.direction==util::TGA_DIRECTION_LOWER_LEFT)
{ BackgroundBitmap->Flip();
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(tp<bp)
{
memcpy(temp,tp,line_bytes);
memcpy(tp,bp,line_bytes);
memcpy(bp,temp,line_bytes);
tp+=line_bytes;
bp-=line_bytes;
}
}
return(true); return(true);
} }
@ -223,8 +186,8 @@ PositionStat *ToVector2i(const UTF8StringList &sl)
(*p)/=100; //Unreal单位为cm,把单位缩到米 (*p)/=100; //Unreal单位为cm,把单位缩到米
(*p)/=4; (*p)/=4;
if(p->x>=BackgroundBitmap->width if(p->x>=BackgroundBitmap->GetWidth()
||p->y>=BackgroundBitmap->height) ||p->y>=BackgroundBitmap->GetHeight())
continue; continue;
//std::cout<<"X="<<p->x<<",Y="<<p->y<<std::endl; //std::cout<<"X="<<p->x<<",Y="<<p->y<<std::endl;
@ -410,8 +373,8 @@ public:
Chart *ToChart32(const PositionStat *ps) Chart *ToChart32(const PositionStat *ps)
{ {
uint width=BackgroundBitmap->width; const uint width=BackgroundBitmap->GetWidth();
uint height=BackgroundBitmap->height; const uint height=BackgroundBitmap->GetHeight();
std::cout<<"width: "<<width<<",height: "<<height<<std::endl; std::cout<<"width: "<<width<<",height: "<<height<<std::endl;
@ -607,7 +570,7 @@ Chart *ToChart32(const PositionStat *ps)
if(BackgroundBitmap) if(BackgroundBitmap)
{ {
uint8 *p=chart->chart_data; uint8 *p=chart->chart_data;
uint8 *bp=BackgroundBitmap->data; uint8 *bp=BackgroundBitmap->GetData();
uint8 alpha; uint8 alpha;
for(uint row=0;row<height;row++) for(uint row=0;row<height;row++)