From 25c2ab644b1f9861d1f1611d983272cd7918d051 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 3 Dec 2019 20:49:25 +0800 Subject: [PATCH] first fix RGBA order --- TextureFileCreater.cpp | 4 ++-- TextureFileCreaterRGB.cpp | 4 ++-- TextureFileCreaterRGBA.cpp | 22 +++++++++++----------- main.cpp | 6 +++--- pixel_format.cpp | 17 +++++++++-------- pixel_format.h | 19 ++++++++++--------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/TextureFileCreater.cpp b/TextureFileCreater.cpp index 61d3598..310bd34 100644 --- a/TextureFileCreater.cpp +++ b/TextureFileCreater.cpp @@ -96,8 +96,8 @@ bool TextureFileCreater::WriteFileHeader(const OSString &old_filename) dos->WriteUint32(image->width()); dos->WriteUint32(image->height()); dos->WriteUint8(fmt->channels); //颜色通道数 - dos->WriteUint8((uint8 *)fmt->color,fmt->channels); //颜色标记 - dos->WriteUint8(fmt->bits,fmt->channels); //颜色位数 + dos->WriteUint8((uint8 *)fmt->color,4); //颜色标记 + dos->WriteUint8(fmt->bits,4); //颜色位数 dos->WriteUint8((uint8)fmt->type); //数据类型 return(true); diff --git a/TextureFileCreaterRGB.cpp b/TextureFileCreaterRGB.cpp index 4594069..a99f286 100644 --- a/TextureFileCreaterRGB.cpp +++ b/TextureFileCreaterRGB.cpp @@ -12,9 +12,9 @@ public: { for(uint i=0;i>3); + | (src[2]>>3); ++target; src+=3; diff --git a/TextureFileCreaterRGBA.cpp b/TextureFileCreaterRGBA.cpp index 88d014a..0979fc2 100644 --- a/TextureFileCreaterRGBA.cpp +++ b/TextureFileCreaterRGBA.cpp @@ -12,10 +12,10 @@ public: { for(uint i=0;i>4); + *target=((src[0]<<8)&0xF000) + |((src[1]<<4)&0xF00) + |((src[2] )&0xF0) + | (src[3]>>4); ++target; src+=4; @@ -27,9 +27,9 @@ public: for(uint i=0;i>3); + | (src[2]>>3); ++target; src+=4; @@ -41,9 +41,9 @@ public: for(uint i=0;i> 6); + | (src[0]>> 6); ++target; src+=4; @@ -54,8 +54,8 @@ public: bool Write() override { - if(fmt->format==ColorFormat::RGBA8UN - ||fmt->format==ColorFormat::RGBA16UN + if(fmt->format==ColorFormat::RGBA8 + ||fmt->format==ColorFormat::RGBA16 ||fmt->format==ColorFormat::RGBA16F ||fmt->format==ColorFormat::RGBA32U ||fmt->format==ColorFormat::RGBA32I @@ -90,7 +90,7 @@ public: return TextureFileCreater::Write(a1_rgb5); } - else if(fmt->format==ColorFormat::A2BGR10UN) + else if(fmt->format==ColorFormat::A2BGR10) { void *origin_rgba=image->GetRGBA(IL_UNSIGNED_SHORT); diff --git a/main.cpp b/main.cpp index 178e898..4732c52 100644 --- a/main.cpp +++ b/main.cpp @@ -40,10 +40,10 @@ const PixelFormat *ParseParamFormat(const CmdParse &cmd,const os_char *flag,cons void ParseParamFormat(const CmdParse &cmd) { //指定格式 - pixel_fmt[0]=ParseParamFormat(cmd,OS_TEXT("/R:"), GetPixelFormat(ColorFormat::R8UN)); - pixel_fmt[1]=ParseParamFormat(cmd,OS_TEXT("/RG:"), GetPixelFormat(ColorFormat::RG8UN)); + pixel_fmt[0]=ParseParamFormat(cmd,OS_TEXT("/R:"), GetPixelFormat(ColorFormat::R8)); + pixel_fmt[1]=ParseParamFormat(cmd,OS_TEXT("/RG:"), GetPixelFormat(ColorFormat::RG8)); pixel_fmt[2]=ParseParamFormat(cmd,OS_TEXT("/RGB:"), GetPixelFormat(ColorFormat::RGB565)); - pixel_fmt[3]=ParseParamFormat(cmd,OS_TEXT("/RGBA:"), GetPixelFormat(ColorFormat::RGBA8UN)); + pixel_fmt[3]=ParseParamFormat(cmd,OS_TEXT("/RGBA:"), GetPixelFormat(ColorFormat::RGBA8)); for(uint i=0;i<4;i++) std::cout<<(i+1)<<": "<name<