From 2ce81232aade269a897be63ec9abbd0fd11d1b7d Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Tue, 11 Jul 2023 16:05:22 +0800 Subject: [PATCH] DistributionChart2D use Bitmap instead of old codes. --- DistributionChart2D.cpp | 63 +++++++++-------------------------------- 1 file changed, 13 insertions(+), 50 deletions(-) diff --git a/DistributionChart2D.cpp b/DistributionChart2D.cpp index 8c3e6fe..4d9ef86 100644 --- a/DistributionChart2D.cpp +++ b/DistributionChart2D.cpp @@ -7,33 +7,16 @@ #include #include #include +#include #include"BitmapFont.h" using namespace hgl; OSString csv_filename; -struct Bitmap -{ - uint width,height; - uint channels; +using BitmapRGB8=hgl::Bitmap; - uint8 *data; - -public: - - Bitmap() - { - data=nullptr; - } - - ~Bitmap() - { - delete[] data; - } -}; - -Bitmap *BackgroundBitmap=nullptr; +BitmapRGB8 *BackgroundBitmap=nullptr; bool LoadBackgroundBitmap() { @@ -55,17 +38,13 @@ bool LoadBackgroundBitmap() tga_desc.image_desc=tga_header.image_desc; - BackgroundBitmap=new Bitmap; + BackgroundBitmap=new BitmapRGB8; - BackgroundBitmap->width=tga_header.width; - BackgroundBitmap->height=tga_header.height; - BackgroundBitmap->channels=tga_header.bit/8; + BackgroundBitmap->Create(tga_header.width,tga_header.height); - 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->data,total_bytes)!=total_bytes) + if(fis->Read(BackgroundBitmap->GetData(),total_bytes)!=total_bytes) { delete BackgroundBitmap; BackgroundBitmap=nullptr; @@ -73,23 +52,7 @@ bool LoadBackgroundBitmap() } 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(tpFlip(); return(true); } @@ -223,8 +186,8 @@ PositionStat *ToVector2i(const UTF8StringList &sl) (*p)/=100; //Unreal单位为cm,把单位缩到米 (*p)/=4; - if(p->x>=BackgroundBitmap->width - ||p->y>=BackgroundBitmap->height) + if(p->x>=BackgroundBitmap->GetWidth() + ||p->y>=BackgroundBitmap->GetHeight()) continue; //std::cout<<"X="<x<<",Y="<y<width; - uint height=BackgroundBitmap->height; + const uint width=BackgroundBitmap->GetWidth(); + const uint height=BackgroundBitmap->GetHeight(); std::cout<<"width: "<chart_data; - uint8 *bp=BackgroundBitmap->data; + uint8 *bp=BackgroundBitmap->GetData(); uint8 alpha; for(uint row=0;row