Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加 ege/types.h 头文件 #251

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
817 changes: 691 additions & 126 deletions src/types.h → include/ege/types.h

Large diffs are not rendered by default.

33 changes: 16 additions & 17 deletions src/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "ege_def.h"
#include "ege_math.h"
#include "types.h"

// 交换颜色中 R 通道和 B 通道: 0xAARRGGBB -> 0xAABBGGRR
#define RGBTOBGR(color) ((color_t)((((color) & 0xFF) << 16) | (((color) & 0xFF0000) >> 16) | ((color) & 0xFF00FF00)))
Expand Down Expand Up @@ -52,11 +51,11 @@ typedef struct COLORRGB
* @param alpha 透明度(0~255)
* @return 混合后的 RGB 颜色,透明度与背景色一致
*/
EGE_FORCEINLINE color_t colorblend_inline(color_t dst, color_t src, byte alpha)
EGE_FORCEINLINE color_t colorblend_inline(color_t dst, color_t src, uint8_t alpha)
{
byte r = DIVIDE_255_FAST(255 * EGEGET_R(dst) + ((int)(EGEGET_R(src) - EGEGET_R(dst)) * alpha + 255/2));
byte g = DIVIDE_255_FAST(255 * EGEGET_G(dst) + ((int)(EGEGET_G(src) - EGEGET_G(dst)) * alpha + 255/2));
byte b = DIVIDE_255_FAST(255 * EGEGET_B(dst) + ((int)(EGEGET_B(src) - EGEGET_B(dst)) * alpha + 255/2));
uint8_t r = DIVIDE_255_FAST(255 * EGEGET_R(dst) + ((int)(EGEGET_R(src) - EGEGET_R(dst)) * alpha + 255/2));
uint8_t g = DIVIDE_255_FAST(255 * EGEGET_G(dst) + ((int)(EGEGET_G(src) - EGEGET_G(dst)) * alpha + 255/2));
uint8_t b = DIVIDE_255_FAST(255 * EGEGET_B(dst) + ((int)(EGEGET_B(src) - EGEGET_B(dst)) * alpha + 255/2));

return EGEARGB(EGEGET_A(dst),r, g, b);
}
Expand All @@ -70,7 +69,7 @@ EGE_FORCEINLINE color_t colorblend_inline(color_t dst, color_t src, byte alpha)
* @return 混合后的 RGB 颜色,透明度与背景色一致
* @note 结果与标准公式相比有一定误差
*/
EGE_FORCEINLINE color_t colorblend_inline_fast(color_t dst, color_t src, byte alpha)
EGE_FORCEINLINE color_t colorblend_inline_fast(color_t dst, color_t src, uint8_t alpha)
{
#define COLORBLEND_INLINE_FAST_OPTION 1
#if COLORBLEND_INLINE_FAST_OPTION == 0
Expand Down Expand Up @@ -107,12 +106,12 @@ EGE_FORCEINLINE color_t colorblend_inline_fast(color_t dst, color_t src, byte al
* G = G(dst) + alpha * (G(src) - G(dst));
* B = B(dst) + alpha * (B(src) - B(dst));
*/
EGE_FORCEINLINE color_t alphablend_specify_inline(color_t dst, color_t src, byte alpha)
EGE_FORCEINLINE color_t alphablend_specify_inline(color_t dst, color_t src, uint8_t alpha)
{
const byte a = DIVIDE_255_FAST(255 * EGEGET_A(dst) + ((int)( 255 - EGEGET_A(dst)) * alpha + 255/2));
const byte r = DIVIDE_255_FAST(255 * EGEGET_R(dst) + ((int)(EGEGET_R(src) - EGEGET_R(dst)) * alpha + 255/2));
const byte g = DIVIDE_255_FAST(255 * EGEGET_G(dst) + ((int)(EGEGET_G(src) - EGEGET_G(dst)) * alpha + 255/2));
const byte b = DIVIDE_255_FAST(255 * EGEGET_B(dst) + ((int)(EGEGET_B(src) - EGEGET_B(dst)) * alpha + 255/2));
const uint8_t a = DIVIDE_255_FAST(255 * EGEGET_A(dst) + ((int)( 255 - EGEGET_A(dst)) * alpha + 255/2));
const uint8_t r = DIVIDE_255_FAST(255 * EGEGET_R(dst) + ((int)(EGEGET_R(src) - EGEGET_R(dst)) * alpha + 255/2));
const uint8_t g = DIVIDE_255_FAST(255 * EGEGET_G(dst) + ((int)(EGEGET_G(src) - EGEGET_G(dst)) * alpha + 255/2));
const uint8_t b = DIVIDE_255_FAST(255 * EGEGET_B(dst) + ((int)(EGEGET_B(src) - EGEGET_B(dst)) * alpha + 255/2));

return EGEARGB(a, r, g, b);
}
Expand All @@ -137,9 +136,9 @@ EGE_FORCEINLINE color_t alphablend_inline(color_t dst, color_t src)
* @param srcAlphaFactor 前景色的比例系数,0~255 对应 0.0~1.0
* @return 混合后的 ARGB 颜色
*/
EGE_FORCEINLINE color_t alphablend_inline(color_t dst, color_t src, byte srcAlphaFactor)
EGE_FORCEINLINE color_t alphablend_inline(color_t dst, color_t src, uint8_t srcAlphaFactor)
{
byte alpha = DIVIDE_255_FAST(EGEGET_A(src) * srcAlphaFactor + 255/2);
uint8_t alpha = DIVIDE_255_FAST(EGEGET_A(src) * srcAlphaFactor + 255/2);
return alphablend_specify_inline(dst, src, alpha);
}

Expand All @@ -157,10 +156,10 @@ EGE_FORCEINLINE color_t alphablend_inline(color_t dst, color_t src, byte srcAlph
*/
EGE_FORCEINLINE color_t alphablend_premultiplied_inline(color_t dst, color_t src)
{
const byte a = DIVIDE_255_FAST(255 * EGEGET_A(src) + (255 - EGEGET_A(src)) * EGEGET_A(dst));
const byte r = DIVIDE_255_FAST(255 * EGEGET_R(src) + (255 - EGEGET_A(src)) * EGEGET_R(dst));
const byte g = DIVIDE_255_FAST(255 * EGEGET_G(src) + (255 - EGEGET_A(src)) * EGEGET_G(dst));
const byte b = DIVIDE_255_FAST(255 * EGEGET_B(src) + (255 - EGEGET_A(src)) * EGEGET_B(dst));
const uint8_t a = DIVIDE_255_FAST(255 * EGEGET_A(src) + (255 - EGEGET_A(src)) * EGEGET_A(dst));
const uint8_t r = DIVIDE_255_FAST(255 * EGEGET_R(src) + (255 - EGEGET_A(src)) * EGEGET_R(dst));
const uint8_t g = DIVIDE_255_FAST(255 * EGEGET_G(src) + (255 - EGEGET_A(src)) * EGEGET_G(dst));
const uint8_t b = DIVIDE_255_FAST(255 * EGEGET_B(src) + (255 - EGEGET_A(src)) * EGEGET_B(dst));

return EGEARGB(a, r, g, b);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ege_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @brief
*/

#include "../include/ege/types.h"

#include "sbt.h"
#include "array.h"
#include "set.h"
Expand All @@ -14,7 +16,6 @@
#include "ege_graph.h"
#include "ege_dllimport.h"

#include "types.h"
#include "utils.h"
#include "color.h"
#include "encodeconv.h"
Expand Down
8 changes: 8 additions & 0 deletions src/ege_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
# endif
#endif

#if !defined(EGE_W64)
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
#define EGE_W64 __w64
#else
#define EGE_W64
#endif
#endif



1 change: 1 addition & 0 deletions src/ege_extension.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "ege_head.h"
#include "../include/ege/types.h"
#include "../include/ege/egecontrolbase.h"
#include "../include/ege/button.h"
#include "../include/ege/fps.h"
Expand Down
3 changes: 1 addition & 2 deletions src/ege_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define EGE_DEPRECATE(function, msg)

#include "../include/ege.h"
#include "../include/ege/types.h"

#define EGE_TOSTR_(x) #x
#define EGE_TOSTR(x) EGE_TOSTR_(x)
Expand Down Expand Up @@ -124,8 +125,6 @@
#define DEFAULT_CHARSET ANSI_CHARSET
#endif

#include "types.h"


namespace ege
{
Expand Down
32 changes: 0 additions & 32 deletions src/enums.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ int IMAGE::getpngimg(FILE* fp)

{
char header[16];
uint32 number = 8;
uint32_t number = 8;
fread(header, 1, number, fp);
int isn_png = png_sig_cmp((png_const_bytep)header, 0, number);

Expand Down Expand Up @@ -597,8 +597,8 @@ int IMAGE::savepngimg(FILE* fp, bool withAlphaChannel) const
png_bytep* row_pointers;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

uint32 pixelsize = withAlphaChannel ? 4 : 3;
uint32 width = m_width, height = m_height;
uint32_t pixelsize = withAlphaChannel ? 4 : 3;
uint32_t width = m_width, height = m_height;

if (png_ptr == NULL) {
return -1;
Expand Down
16 changes: 0 additions & 16 deletions src/types.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <windows.h>
#include <windef.h>
#include "types.h"
#include <string>
#include <wchar.h>

Expand Down