From 090fab9c0eca5fa157f1f3280713fd42954a21a2 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 28 Feb 2022 14:25:58 +0800 Subject: [PATCH 01/11] renamed to FULL_WIDTH_SPACE from FULL_SPACE --- inc/hgl/TypeFunc.h | 4 ++-- inc/hgl/type/StrChar.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h index 280c73b..294551b 100644 --- a/inc/hgl/TypeFunc.h +++ b/inc/hgl/TypeFunc.h @@ -31,8 +31,8 @@ namespace hgl #define NULL 0 #endif// - constexpr u16char U16_FULL_SPACE=U16_TEXT(' '); //全角空格 - constexpr u32char U32_FULL_SPACE=U32_TEXT(' '); //全角空格 + constexpr u16char U16_FULL_WIDTH_SPACE=U16_TEXT(' '); //全角空格 + constexpr u32char U32_FULL_WIDTH_SPACE=U32_TEXT(' '); //全角空格 template inline T *zero_new(const int count) diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index bb11d14..a91243b 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -171,7 +171,7 @@ namespace hgl { return(ch==0 ||ch==U' ' //半角空格 - ||ch==U32_FULL_SPACE //全角空格 + ||ch==U32_FULL_WIDTH_SPACE //全角空格 ||ch==U'\a' ||ch==U'\b' ||ch==U'\f' @@ -188,7 +188,7 @@ namespace hgl { return(ch==0 ||ch==U16_TEXT(' ') //半角空格 - ||ch==U16_FULL_SPACE //全角空格 + ||ch==U16_FULL_WIDTH_SPACE //全角空格 ||ch==U16_TEXT('\a') ||ch==U16_TEXT('\b') ||ch==U16_TEXT('\f') From d1f7b588a3dc839a68776c4931225ff49edb7495 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 9 Mar 2022 18:39:39 +0800 Subject: [PATCH 02/11] deleted codes of lookat --- inc/hgl/math/Matrix.h | 8 -------- src/Math/Matrix4f.cpp | 29 ----------------------------- 2 files changed, 37 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 4697539..7f45f25 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -68,14 +68,6 @@ namespace hgl float znear, float zfar); - /** - * 产生一个lookat变换矩阵 - * @param eye 眼睛位置 - * @param target 目标位置 - * @param up 向上向量 - */ - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up); - inline Matrix4f translate(const Vector3f &v) { return glm::translate(Matrix4f(1.0f),v); diff --git a/src/Math/Matrix4f.cpp b/src/Math/Matrix4f.cpp index 4e13032..a4fa3da 100644 --- a/src/Math/Matrix4f.cpp +++ b/src/Math/Matrix4f.cpp @@ -102,33 +102,4 @@ namespace hgl 0.0f ); } - - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up) - { - Vector3f forward=normalize(target-eye); - Vector3f right=normalize(cross(forward,up)); - - Vector3f nup=cross(right,forward); - - return Matrix4f( right.x, - nup.x, - -forward.x, - 0.0f, - - right.y, - nup.y, - -forward.y, - 0.0f, - - right.z, - nup.z, - -forward.z/2.0f, - 0.0f, - - dot(eye,right ), - dot(eye,nup ), - dot(eye,forward), - 1.0f - ); - } }//namespace hgl From 716407fa2d16b17efa51c70396e6518fc7275676 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 9 Mar 2022 19:24:51 +0800 Subject: [PATCH 03/11] added many define of color --- inc/hgl/type/Color.h | 8 ++++++++ src/Color/Color.cpp | 12 ++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/inc/hgl/type/Color.h b/inc/hgl/type/Color.h index 17f6fdf..7d8f7fa 100644 --- a/inc/hgl/type/Color.h +++ b/inc/hgl/type/Color.h @@ -57,13 +57,16 @@ namespace hgl Crimson, ///<暗深红 Cyan, ///<青色 DarkBlue, ///<暗蓝色 + DarkCharcoal, ///<炭黑色 DarkCyan, ///<暗青色 DarkGoldenrod, ///<暗金黄 DarkGray, ///<暗灰色 DarkGreen, ///<暗绿色 DarkGrey, ///<暗白色 + DarkGunmetal, ///<黑炮铜 DarkKhaki, ///<暗黄褐色 DarkMagenta, ///<暗洋红 + DarkMidnightBlue, ///<暗夜蓝 DarkOliveGreen, ///<暗橄榄绿 DarkOrange, ///<暗桔黄 DarkOrchid, ///<暗紫色 @@ -80,6 +83,7 @@ namespace hgl DimGray, ///<暗灰色 DimGrey, ///<暗灰白 DodgerBlue, ///<闪兰色 + EerieBlack, ///<怪异黑 FireBrick, ///<火砖色 FloralWhite, ///<花白色 ForestGreen, ///<森林绿 @@ -133,6 +137,7 @@ namespace hgl Lion, ///<獅子棕 Magenta, ///<红紫色 Maroon, ///<粟色 + MaastrichtBlue, ///<马斯特里赫特蓝色 MediumAquamarine, ///<间绿色 MediumBlue, ///<间兰色 MediumOrchid, ///<间淡紫 @@ -172,6 +177,9 @@ namespace hgl Orange, ///<橙色 OrangeRed, ///<红橙色 Orchid, ///<淡紫色 + + OxfordBlue, ///<牛津蓝 + PaleGoldenrod, ///<苍麒麟色 PaleGreen, ///<苍绿色 PaleTurquoise, ///<苍宝石绿 diff --git a/src/Color/Color.cpp b/src/Color/Color.cpp index 8e4fe1a..2b0b3f6 100644 --- a/src/Color/Color.cpp +++ b/src/Color/Color.cpp @@ -51,13 +51,16 @@ namespace hgl DEF_COLOR(Crimson, 220, 20, 60,"暗深红") DEF_COLOR(Cyan, 0,255,255,"青色") DEF_COLOR(DarkBlue, 0, 0,139,"暗蓝色") + DEF_COLOR(DarkCharcoal, 47, 49, 51,"炭黑色") DEF_COLOR(DarkCyan, 0,139,139,"暗青色") DEF_COLOR(DarkGoldenrod, 184,134, 11,"暗金黄") DEF_COLOR(DarkGray, 169,169,169,"暗灰色") DEF_COLOR(DarkGreen, 0,100, 0,"暗绿色") DEF_COLOR(DarkGrey, 169,169,169,"暗白色") + DEF_COLOR(DarkGunmetal, 30, 37, 41,"黑炮铜") DEF_COLOR(DarkKhaki, 189,183,107,"暗黄褐色") - DEF_COLOR(DarkMagenta, 139, 0,139,"暗洋红") + DEF_COLOR(DarkMagenta, 139, 0,139,"暗洋红") + DEF_COLOR(DarkMidnightBlue, 0, 51,103,"暗夜蓝") DEF_COLOR(DarkOliveGreen, 85,107, 47,"暗橄榄绿") DEF_COLOR(DarkOrange, 255,140, 0,"暗桔黄") DEF_COLOR(DarkOrchid, 153, 50,204,"暗紫色") @@ -73,7 +76,8 @@ namespace hgl DEF_COLOR(DeepSkyBlue, 0,191,255,"深天蓝") DEF_COLOR(DimGray, 105,105,105,"暗灰色") DEF_COLOR(DimGrey, 105,105,105,"暗灰白") - DEF_COLOR(DodgerBlue, 30,144,255,"闪兰色") + DEF_COLOR(DodgerBlue, 30,144,255,"闪兰色") + DEF_COLOR(EerieBlack, 23, 29, 32,"怪异黑") DEF_COLOR(FireBrick, 178, 34, 34,"火砖色") DEF_COLOR(FloralWhite, 255,250,240,"花白色") DEF_COLOR(ForestGreen, 34,139, 34,"森林绿") @@ -127,6 +131,8 @@ namespace hgl DEF_COLOR(Lion, 193,154,107,"獅子棕") DEF_COLOR(Magenta, 255, 0,255,"红紫色") DEF_COLOR(Maroon, 128, 0, 0,"粟色") + + DEF_COLOR(MaastrichtBlue, 0, 26, 56,"马斯特里赫特蓝色") DEF_COLOR(MediumAquamarine, 102,205,170,"间绿色") DEF_COLOR(MediumBlue, 0, 0,205,"间兰色") DEF_COLOR(MediumOrchid, 186, 85,211,"间淡紫") @@ -166,6 +172,8 @@ namespace hgl DEF_COLOR(Orange, 255,165, 0,"橙色") DEF_COLOR(OrangeRed, 255, 69, 0,"红橙色") DEF_COLOR(Orchid, 218,112,214,"淡紫色") + DEF_COLOR(OxfordBlue, 0, 34, 78,"牛津蓝") + DEF_COLOR(PaleGoldenrod, 238,232,170,"苍麒麟色") DEF_COLOR(PaleGreen, 152,251,152,"苍绿色") DEF_COLOR(PaleTurquoise, 175,238,238,"苍宝石绿") From 0ea0fccfc64f0b857ca135382c8c164c402dc886 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 11 Mar 2022 16:58:04 +0800 Subject: [PATCH 04/11] fixed error from Color List. --- inc/hgl/TypeFunc.h | 3 -- inc/hgl/type/Color.h | 72 ++++++++++++++++++++++++++++++----------- src/Color/Color.cpp | 76 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 112 insertions(+), 39 deletions(-) diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h index 294551b..2aa03de 100644 --- a/inc/hgl/TypeFunc.h +++ b/inc/hgl/TypeFunc.h @@ -134,9 +134,6 @@ namespace hgl return count; } - #define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f} - #define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f} - constexpr uint HGL_SIZE_1KB =1024; constexpr uint HGL_SIZE_1MB =HGL_SIZE_1KB*1024; constexpr uint HGL_SIZE_1GB =HGL_SIZE_1MB*1024; diff --git a/inc/hgl/type/Color.h b/inc/hgl/type/Color.h index 7d8f7fa..db90ac0 100644 --- a/inc/hgl/type/Color.h +++ b/inc/hgl/type/Color.h @@ -2,8 +2,22 @@ #define HGL_COLOR_TABLE_INCLUDE #include +#include namespace hgl { + #define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f} + #define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f} + + inline constexpr uint8 RGB2Lum(const uint8 red,const uint8 green,const uint8 blue) + { + return float(red)*0.299+float(green)*0.587+float(blue)*0.114; + } + + inline constexpr float RGB2Lumf(const float red,const float green,const float blue) + { + return red*0.299+green*0.587+blue*0.114; + } + void GetSpectralColor(double &r,double &g,double &b,const double l); ///<根据光谱值获取对应的RGB值 /** @@ -32,10 +46,8 @@ namespace hgl AppleGreen, ///<苹果绿 Aqua, ///<浅绿色 AquaMarine, ///<碧绿色 - - ArdenRed, ///<雅顿红(注:商业使用需获得Elizabeth Arden公司授权) - Azure, ///<天蓝色 + BananaMania, ///<香蕉黄(芯) BananaYellow, ///<香蕉黄(皮) Beige, ///<米色 @@ -46,6 +58,7 @@ namespace hgl BlueViolet, ///<紫罗兰色 Brown, ///<褐色 BurlyWood, ///<实木色 + CadetBlue, ///<军兰色 CaribbeanGreen, ///<加勒比海绿 Chartreuse, ///<黄绿色 @@ -56,6 +69,7 @@ namespace hgl Cornsilk, ///<米绸色 Crimson, ///<暗深红 Cyan, ///<青色 + DarkBlue, ///<暗蓝色 DarkCharcoal, ///<炭黑色 DarkCyan, ///<暗青色 @@ -78,12 +92,15 @@ namespace hgl DarkSlateGrey, ///<暗灰绿 DarkTurquoise, ///<暗宝石绿 DarkViolet, ///<暗紫罗兰 + DeepPink, ///<深粉红 DeepSkyBlue, ///<深天蓝 DimGray, ///<暗灰色 DimGrey, ///<暗灰白 DodgerBlue, ///<闪兰色 + EerieBlack, ///<怪异黑 + FireBrick, ///<火砖色 FloralWhite, ///<花白色 ForestGreen, ///<森林绿 @@ -91,6 +108,7 @@ namespace hgl FrenchBlue, ///<法国兰 FrenchLilac, ///<法国丁香色 Fuchsia, ///<紫红色 + Gainsboro, ///<淡灰色 GhostWhite, ///<幽灵白 Gold, ///<金色 @@ -100,22 +118,27 @@ namespace hgl Green, ///<绿色 GreenYellow, ///<蓝绿色 Grey, ///<灰白色 + HollywoodCerise, ///<好莱坞樱桃红 Honeydew, ///<蜜色 HotPink, ///<火热粉 HunterGreen, ///<猎人绿 + IndianGreen, ///<印度绿 IndianRed, ///<印度红 IndianYellow, ///<印度黄 Indigo, ///<靛青色 Ivory, ///<象牙白 + Khaki, ///<黄褐色 + Lavender, ///<淡紫色 LavenderBlush, ///<淡紫红 LawnGreen, ///<草绿色 Lemon, ///<柠檬色 LemonYellow, ///<柠檬黄 LemonChiffon, ///<柠檬绸 + LightBlue, ///<亮蓝色 LightCoral, ///<亮珊瑚色 LightCyan, ///<亮青色 @@ -131,13 +154,16 @@ namespace hgl LightSlateGrey, ///<亮蓝白 LightSteelBlue, ///<亮钢兰 LightYellow, ///<亮黄色 + Lime, ///<酸橙色 LimeGreen, ///<橙绿色 Linen, ///<亚麻色 Lion, ///<獅子棕 + Magenta, ///<红紫色 Maroon, ///<粟色 MaastrichtBlue, ///<马斯特里赫特蓝色 + MediumAquamarine, ///<间绿色 MediumBlue, ///<间兰色 MediumOrchid, ///<间淡紫 @@ -147,6 +173,7 @@ namespace hgl MediumSpringGreen, ///<间春绿 MediumTurquoise, ///<间绿宝石 MediumVioletRed, ///<间紫罗兰 + MidNightBlue, ///<中灰蓝 Mint, ///<薄荷色 MintCream, ///<薄荷霜 @@ -167,10 +194,6 @@ namespace hgl NavajoWhite, ///<纳瓦白 Navy, ///<海军色 - NiveaBlue, ///<妮维雅蓝(注:商业使用需获得Beiersdorf AG授权) - - NokiaBlue, ///<诺基亚蓝 - OldLace, ///<老花色 Olive, ///<橄榄色 Olivedrab, ///<深绿褐色 @@ -201,16 +224,15 @@ namespace hgl PowderBlue, ///<粉蓝色 Purple, ///<紫色 + Red, ///<红色 Rose, ///<玫瑰红 RosyBrown, ///<褐玫瑰红 RoyalBlue, ///<皇家蓝 Ruby, ///<宝石红 + SaddleBrown, ///<重褐色 Salmon, ///<鲜肉色 - - SamsungBlue, ///<三星蓝 - SandyBrown, ///<沙褐色 SeaGreen, ///<海绿色 SeaShell, ///<海贝色 @@ -224,33 +246,45 @@ namespace hgl SpringGreen, ///<春绿色 SteelBlue, ///<钢兰色 - SUSEBlack, /// Date: Fri, 11 Mar 2022 17:37:32 +0800 Subject: [PATCH 05/11] cleared "COLOR enum class" at Color3f/4f --- inc/hgl/type/Color.h | 17 ++++++++++++++++- inc/hgl/type/Color3f.h | 4 ---- inc/hgl/type/Color4f.h | 5 +---- src/Color/Color.cpp | 11 ++++++----- src/Color/Color3f.cpp | 14 +++----------- src/Color/Color4f.cpp | 13 ++----------- 6 files changed, 28 insertions(+), 36 deletions(-) diff --git a/inc/hgl/type/Color.h b/inc/hgl/type/Color.h index db90ac0..0d15cd5 100644 --- a/inc/hgl/type/Color.h +++ b/inc/hgl/type/Color.h @@ -3,6 +3,7 @@ #include #include +#include namespace hgl { #define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f} @@ -18,7 +19,7 @@ namespace hgl return red*0.299+green*0.587+blue*0.114; } - void GetSpectralColor(double &r,double &g,double &b,const double l); ///<根据光谱值获取对应的RGB值 + const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值 /** * 颜色数据定义 @@ -288,5 +289,19 @@ namespace hgl };//enum COLOR_ENUM extern COLOR_DEF prv_color[size_t(COLOR::RANGE_SIZE)]; + + inline const Color3f GetColor3f(const enum class COLOR &ce) + { + const COLOR_DEF &c=prv_color[size_t(ce)]; + + return Color3f(c.r,c.g,c.b); + } + + inline const Color4f GetColor4f(const enum class COLOR &ce,const float &alpha) + { + const COLOR_DEF &c=prv_color[size_t(ce)]; + + return Color4f(c.r,c.g,c.b,alpha); + } }//namespace hgl #endif//HGL_COLOR_TABLE_INCLUDE diff --git a/inc/hgl/type/Color3f.h b/inc/hgl/type/Color3f.h index 7380fe3..7bfdfcd 100644 --- a/inc/hgl/type/Color3f.h +++ b/inc/hgl/type/Color3f.h @@ -1,7 +1,6 @@ #ifndef HGL_COLOR_3_FLOAT_INCLUDE #define HGL_COLOR_3_FLOAT_INCLUDE -#include namespace hgl { /** @@ -18,12 +17,10 @@ namespace hgl public: Color3f(){r=0,g=0,b=0;} ///<本类构造函数 - Color3f(COLOR ce){Use(ce);} ///<本类构造函数 Color3f(float l){r=l,g=l,b=l;Clamp();} ///<本类构造函数 Color3f(float vr,float vg,float vb){r=vr,g=vg,b=vb;Clamp();} ///<本类构造函数 Color3f(const Color3f &v){r=v.r;g=v.g;b=v.b;Clamp();} ///<本类构造函数 - void Use(COLOR); void Zero(){r=0,g=0,b=0;} ///<全清为0 void One() {r=1,g=1,b=1;} ///<全清为1 void Rand(); ///<全随机 @@ -54,7 +51,6 @@ namespace hgl //操作符重载 void operator = (const float *v){r=*v++;g=*v++;b=*v;} - void operator = (COLOR ce){Use(ce);} bool operator == (const Color3f &); bool operator != (const Color3f &); diff --git a/inc/hgl/type/Color4f.h b/inc/hgl/type/Color4f.h index 2efbce5..0252c37 100644 --- a/inc/hgl/type/Color4f.h +++ b/inc/hgl/type/Color4f.h @@ -2,6 +2,7 @@ #define HGL_COLOR_4_FLOAT_INCLUDE #include +#include namespace hgl { #define HGL_FLOAT_TO_U32(c1,c2,c3,c4) uint32( \ @@ -29,13 +30,10 @@ namespace hgl public: Color4f(){r=0,g=0,b=0,a=1;} ///<本类构造函数 - Color4f(COLOR ce){Use(ce,1);} ///<本类构造函数 - Color4f(COLOR ce,float ta){Use(ce,ta);} ///<本类构造函数 Color4f(float v){r=v,g=v,b=v,a=1;Clamp();} ///<本类构造函数 Color4f(float vr,float vg,float vb,float va){r=vr,g=vg,b=vb;a=va;Clamp();} ///<本类构造函数 Color4f(const Color3f &v,float va=1){Set(v,va);} ///<本类构造函数 - void Use(COLOR,float); void Zero(){r=0,g=0,b=0,a=0;} ///<全清为0 void One() {r=1,g=1,b=1,a=1;} ///<全清为1 @@ -65,7 +63,6 @@ namespace hgl void operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;} void operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;} void operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;} - void operator = (COLOR ce){Use(ce,a);} bool operator == (const Color4f &); bool operator != (const Color4f &); diff --git a/src/Color/Color.cpp b/src/Color/Color.cpp index fdf9f02..eb285aa 100644 --- a/src/Color/Color.cpp +++ b/src/Color/Color.cpp @@ -281,15 +281,14 @@ namespace hgl /** * 根据光谱值获取对应的RGB值 * @param l 光谱值(从400到700) - * @return r/g/b 该光谱对应的RGB(0至1) */ - void GetSpectralColor(double &r,double &g,double &b,const double l) + const Color3f GetSpectralColor(const double l) { double t; - r=0.0; - g=0.0; - b=0.0; + double r=0.0; + double g=0.0; + double b=0.0; if ((l>=400.0)&&(l<410.0)) { t=(l-400.0)/(410.0-400.0); r= +(0.33*t)-(0.20*t*t); } else if ((l>=410.0)&&(l<475.0)) { t=(l-410.0)/(475.0-410.0); r=0.14 -(0.13*t*t); } @@ -303,5 +302,7 @@ namespace hgl if ((l>=400.0)&&(l<475.0)) { t=(l-400.0)/(475.0-400.0); b= +(2.20*t)-(1.50*t*t); } else if ((l>=475.0)&&(l<560.0)) { t=(l-475.0)/(560.0-475.0); b=0.7 -( t)+(0.30*t*t); } + + return Color3f(r,g,b); } }//namespace hgl diff --git a/src/Color/Color3f.cpp b/src/Color/Color3f.cpp index fc4f62f..c0b1275 100644 --- a/src/Color/Color3f.cpp +++ b/src/Color/Color3f.cpp @@ -1,15 +1,7 @@ #include +#include namespace hgl { - void Color3f::Use(COLOR ce) - { - const COLOR_DEF *pc=prv_color+size_t(ce); - - r=pc->r; - g=pc->g; - b=pc->b; - } - void Color3f::Clamp() { if(r<0)r=0;if(r>1)r=1; @@ -40,7 +32,7 @@ namespace hgl //-------------------------------------------------------------------------------------------------- void Color3f::Grey(float v1,float v2,float v3) { - float lum=v1*0.299+v2*0.587+v3*0.114; + float lum=RGB2Lum(v1,v2,v3); r=lum; g=lum; @@ -49,7 +41,7 @@ namespace hgl //-------------------------------------------------------------------------------------------------- void Color3f::Grey() { - float lum=r*0.299+g*0.587+b*0.114; + float lum=RGB2Lum(r,g,b); r=lum; g=lum; diff --git a/src/Color/Color4f.cpp b/src/Color/Color4f.cpp index 237cd2e..d14879d 100644 --- a/src/Color/Color4f.cpp +++ b/src/Color/Color4f.cpp @@ -1,16 +1,7 @@ #include +#include namespace hgl { - void Color4f::Use(COLOR ce,float ta) - { - const COLOR_DEF *pc=prv_color+size_t(ce); - - r=pc->r; - g=pc->g; - b=pc->b; - a=ta; - } - void Color4f::Clamp() { if(r<0)r=0;if(r>1)r=1; @@ -42,7 +33,7 @@ namespace hgl //-------------------------------------------------------------------------------------------------- void Color4f::Grey() { - float lum=r*0.299+g*0.587+b*0.114; + float lum=RGB2Lum(r,g,b); r=lum; g=lum; From afec00dc90aecfacd84450d65b09dacbe3828e5e Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 11 Mar 2022 17:48:59 +0800 Subject: [PATCH 06/11] defined union/struct at Color3f/4f --- inc/hgl/type/Color3f.h | 10 +++++++++- inc/hgl/type/Color4f.h | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/inc/hgl/type/Color3f.h b/inc/hgl/type/Color3f.h index 7bfdfcd..792f5ab 100644 --- a/inc/hgl/type/Color3f.h +++ b/inc/hgl/type/Color3f.h @@ -12,7 +12,15 @@ namespace hgl public: - float r,g,b; /// Date: Fri, 11 Mar 2022 17:58:08 +0800 Subject: [PATCH 07/11] delete hgl_cpy(T *,T *) function. --- inc/hgl/TypeFunc.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h index 2aa03de..f3c05c8 100644 --- a/inc/hgl/TypeFunc.h +++ b/inc/hgl/TypeFunc.h @@ -331,15 +331,6 @@ namespace hgl memcpy(&dst,&src,sizeof(T)); } - /** - * 同类型指针数据复制 - */ - template - inline void hgl_cpy(T *dst,const T *src) - { - memcpy(dst,src,sizeof(T)); - } - /** * 数据类型转换赋值 */ From 98978c5363b1886e4fd50c142e8ed25ab64dd887 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 12 Mar 2022 19:30:08 +0800 Subject: [PATCH 08/11] added a newly clamp function that only a param --- inc/hgl/math/Vector.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index 113263c..e8ae4c3 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -94,13 +94,19 @@ namespace hgl } template - inline T clamp(const T &v,const T &min_v,const T &max_v) + inline T clamp(const T v,const T min_v,const T max_v) { if(vmax_v)return max_v; return v; } + template + inline const T clamp(const T in) + { + return clamp(in,0.0f,1.0f); + } + template inline T normalized(const T &v) { From 2958c9c448c50f20216110054e14959de0355737 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 12 Mar 2022 19:30:26 +0800 Subject: [PATCH 09/11] fixed isspace --- inc/hgl/type/StrChar.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index a91243b..bc1b243 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -164,9 +164,12 @@ namespace hgl return(false); } + template inline const bool isspace(const T &); + /** * 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n') */ + template<> inline const bool isspace(const u32char &ch) { return(ch==0 @@ -184,6 +187,7 @@ namespace hgl /** * 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n') */ + template<> inline const bool isspace(const u16char &ch) { return(ch==0 @@ -201,7 +205,8 @@ namespace hgl /** * 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n') */ - inline const bool isspace(const char ch) + template<> + inline const bool isspace(const char &ch) { return(ch==0 ||ch==' ' //半角空格 @@ -215,6 +220,7 @@ namespace hgl } #ifdef char8_t + template<> inline const bool isspace(const char8_t ch) { return(ch==0 @@ -1148,11 +1154,11 @@ namespace hgl * 截去字符串前端所有的指定字符 * @param src 源字符串指针 * @param len 源字符串长度(同样用于返回结果字符串长度) - * @param trimfunc 截取字符判断函数(默认isspace) + * @param trimfunc 截取字符判断函数(默认isspace) * @return 新的字符串起始指针 */ template - const T *trimleft(const T *src,int &len,const bool (*trimfunc)(const T)=isspace) + const T *trimleft(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace) { const T *p=src; @@ -1172,11 +1178,11 @@ namespace hgl * 截去字符串尾端所有的指定字符 * @param src 源字符串指针 * @param len 源字符串长度(同样用于返回结果字符串长度) - * @param trimfunc 截取字符判断函数(默认isspace) + * @param trimfunc 截取字符判断函数(默认isspace) * @return 新的字符串起始指针 */ template - const T *trimright(const T *src,int &len,const bool (*trimfunc)(const T)=isspace) + const T *trimright(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace) { const T *p=src+len-1; @@ -1196,11 +1202,11 @@ namespace hgl * 截去字符串前端和尾端的所有指定字符 * @param src 源字符串指针 * @param len 源字符串长度(同样用于返回结果字符串长度) - * @param trimfunc 截取字符判断函数(默认isspace) + * @param trimfunc 截取字符判断函数(默认isspace) * @return 新的字符串起始指针 */ template - const T *trim(const T *src,int &len,const bool (*trimfunc)(const T)=isspace) + const T *trim(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace) { const T *sp=src; const T *ep=src+len-1; @@ -1227,11 +1233,11 @@ namespace hgl * 截取字符串前端的字符串 * @param src 源字符串指针 * @param len 源字符串长度(同样用于返回结果字符串长度) - * @param clipfunc 不可用字符判断函数(默认isspace) + * @param clipfunc 不可用字符判断函数(默认isspace) * @return 新的字符串起始指针 */ template - const T *clipleft(const T *src,int &len,const bool (*clipfunc)(const T)=isspace) + const T *clipleft(const T *src,int &len,const bool (*clipfunc)(const T &)=isspace) { const T *p=src; @@ -1249,11 +1255,11 @@ namespace hgl * 截去字符串尾端的字符串 * @param src 源字符串指针 * @param len 源字符串长度(同样用于返回结果字符串长度) - * @param clipfunc 不可用字符判断函数(默认isspace) + * @param clipfunc 不可用字符判断函数(默认isspace) * @return 新的字符串起始指针 */ template - const T *clipright(const T *src,int &len,const bool (*clipfunc)(const T)=isspace) + const T *clipright(const T *src,int &len,const bool (*clipfunc)(const T &)=isspace) { const T *p=src+len-1; From 6c2f5b255c0c04e20531e2fc8ac7843df264fa5b Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 15 Mar 2022 18:01:38 +0800 Subject: [PATCH 10/11] added & at multi places. --- inc/hgl/filesystem/Filename.h | 1 + inc/hgl/type/StrChar.h | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index 49c1989..acc365f 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -58,6 +58,7 @@ namespace hgl return String::newOf(fullname,p-fullname); } + /** * 组合文件名.
* 根据离散的每一级目录名称和最终名称合成完整文件名 diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index bc1b243..65af87c 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -46,7 +46,7 @@ namespace hgl * 参见https://unicode.org/Public/emoji/12.0/emoji-data.txt */ template - const bool isemoji(const T ch) + const bool isemoji(const T &ch) { if(ch==0x23)return(true); //# if(ch==0x2A)return(true); //* @@ -62,7 +62,7 @@ namespace hgl * 测试当前字符是否为小写字母 */ template - const bool islower(const T ch) + const bool islower(const T &ch) { return(ch>='a'&&ch<='z'); } @@ -71,7 +71,7 @@ namespace hgl * 测试当前字符是否为大写字母 */ template - const bool isupper(const T ch) + const bool isupper(const T &ch) { return(ch>='A'&&ch<='Z'); } @@ -80,7 +80,7 @@ namespace hgl * 测试当前字符是否为字母 */ template - const bool isalpha(const T ch) + const bool isalpha(const T &ch) { return(islower(ch)||isupper(ch)); } @@ -89,7 +89,7 @@ namespace hgl * 测试当前字符是否为10进制数字 */ template - const bool isdigit(const T ch) + const bool isdigit(const T &ch) { return(ch>='0'&&ch<='9'); } @@ -98,7 +98,7 @@ namespace hgl * 测试当前字符串是否为10进制数字以及小数点、正负符号、指数字符 */ template - const bool isfloat(const T ch) + const bool isfloat(const T &ch) { return isdigit(ch) ||ch=='-' @@ -111,7 +111,7 @@ namespace hgl } template - const bool isinteger(const T ch) + const bool isinteger(const T &ch) { return isdigit(ch) ||ch=='-' @@ -122,7 +122,7 @@ namespace hgl * 测试当前字符是否为16进制数用字符(0-9,A-F) */ template - const bool isxdigit(const T ch) + const bool isxdigit(const T &ch) { return((ch>='0'&&ch<='9') ||(ch>='a'&&ch<='f') @@ -156,7 +156,7 @@ namespace hgl * 是否为斜杠 */ template - const bool isslash(const T ch) + const bool isslash(const T &ch) { if(ch=='\\')return(true); if(ch=='/')return(true); @@ -239,7 +239,7 @@ namespace hgl * 测试当前字符是否为字母或数字 */ template - const bool isalnum(const T ch) + const bool isalnum(const T &ch) { return(isalpha(ch)||isdigit(ch)); } @@ -248,7 +248,7 @@ namespace hgl * 测试当前字符是否为代码可用字符(仅字母,数字,下划线,常用于文件名之类) */ template - const bool iscodechar(const T ch) + const bool iscodechar(const T &ch) { return(isalnum(ch)||ch=='_'); } @@ -257,7 +257,7 @@ namespace hgl * 测试当前字符是否不是代码可用字符(仅字母,数字,下划线,常用于文件名之类) */ template - const bool notcodechar(const T ch) + const bool notcodechar(const T &ch) { return(!iscodechar(ch)); } @@ -266,7 +266,7 @@ namespace hgl * 测试当前字符是否为BASE64编码字符 */ template - const bool isbase64(const T c) + const bool isbase64(const T &c) { return (c == 43 || // + (c >= 47 && c <= 57) || // /-9 From bfed461c84e7b780a3ab7a86d2c45e27b247f29f Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 21 Mar 2022 21:29:14 +0800 Subject: [PATCH 11/11] fixed half_to_float --- inc/hgl/math/MathConst.h | 41 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/inc/hgl/math/MathConst.h b/inc/hgl/math/MathConst.h index 4becbc3..4487377 100644 --- a/inc/hgl/math/MathConst.h +++ b/inc/hgl/math/MathConst.h @@ -77,9 +77,46 @@ namespace hgl return double(floor(value*per))/per; } - inline constexpr float half_to_float(const uint16 &h) + inline const float half_to_float(const uint16 &h) { - return ((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13); + union + { + float f; + uint32 u; + }x; + + x.u=(((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13)); + + return x.f; + } + + inline void half_to_float(uint32 *target,const uint16 *source,uint32 count) + { + while (count--) + { + *target = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13)); + ++target; + ++source; + } + } + + inline void half_to_uint16(uint16 *target, const uint16 *source, uint32 count) + { + union + { + float f; + uint32 u; + }x; + + while (count--) + { + x.u = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13)); + + *target=x.f*65535; + + ++target; + ++source; + } } inline constexpr uint16 float_to_half(const float &f)