Skip to content

Commit

Permalink
EGE/: 修改 color_t 格式。
Browse files Browse the repository at this point in the history
参见提交 bbc890f 。
另见 wysaid/xege#12 。

Signed-off-by: FrankHB <frankhb1989@gmail.com>
  • Loading branch information
FrankHB committed Apr 14, 2020
1 parent 567e9ce commit ff16a45
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
4 changes: 4 additions & 0 deletions Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ YEGE 以 [misakamm 的 xege](http://github.com/misakamm/xege) 为基础修改,
* 参见 [wysaid/xege pull request 9](https://github.com/wysaid/xege/pull/9) 。
* 颜色转换函数添加 `ynothrow`
* 修复函数 `RGBTOBGR` 的参数类型(自从 19.01 )。
* 修改 `color_t` 的格式:交换红色和蓝色分量。
* 撤销 14.01 的修改,和原始 misakamm/xege 的 `color_t` 一致,而不再和 `::COLORREF` 一致。
* 同时修改函数 `EGERGB` 的实现,解决和其它函数的不一致问题。
* 修改后的格式和 `YSLib::Pixel` 在 Win32 上的实现以及 [wysaid/xege pull request 12](https://github.com/wysaid/xege/pull/12) 中的像素格式保持一致,存储格式都为 BGRA8888 。

## 19.01

Expand Down
2 changes: 1 addition & 1 deletion EGE/include/ege/colorbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RGBTOBGR(color_int_t color) ynothrow
yconstfn color_int_t
EGERGB(MonoType r, MonoType g, MonoType b) ynothrow
{
return (b << 16) | (g << 8) | r;
return (r << 16) | (g << 8) | b;
}

yconstfn color_int_t
Expand Down
35 changes: 12 additions & 23 deletions EGE/src/ege/gapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ setlinestyle(int linestyle, unsigned short upattern, int thickness, IMAGE* pimg)
{
auto& img(cimg_ref_c(pimg));

::LOGPEN lpen{0, ::POINT(), COLORREF()};
::LOGPEN lpen{0, ::POINT(), RGBTOBGR(getcolor(pimg))};

lpen.lopnColor = getcolor(pimg);
img.m_linestyle.thickness = thickness;
img.m_linewidth = float(thickness);
img.m_linestyle.linestyle = linestyle;
Expand All @@ -131,12 +130,9 @@ setlinestyle(int linestyle, unsigned short upattern, int thickness, IMAGE* pimg)
if(linestyle == PS_USERSTYLE)
{
unsigned long style[20]{0};
::LOGBRUSH lbr;
int n, bn = 0, len = 1, st = 0;
lbr.lbColor = lpen.lopnColor;
lbr.lbStyle = BS_SOLID;
lbr.lbHatch = 0;
st = upattern & 1;
::LOGBRUSH lbr{BS_SOLID, lpen.lopnColor, 0};
int n, bn = 0, len = 1, st(upattern & 1);

for(n = 1; n < 16; n++)
{
if(upattern & (1 << n))
Expand Down Expand Up @@ -184,10 +180,9 @@ setfillstyle(int pattern, color_t color, IMAGE* pimg)
{
auto& img(cimg_ref_c(pimg));

::LOGBRUSH lbr{0, COLORREF(), ::UINT_PTR()};
::LOGBRUSH lbr{0, RGBTOBGR(color), ::UINT_PTR()};

img.m_fillcolor = color;
lbr.lbColor = color;
//::SetBkColor(img.getdc(), color);
if(pattern < SOLID_FILL)
lbr.lbHatch = BS_NULL;
Expand Down Expand Up @@ -268,21 +263,17 @@ setcolor(color_t color, IMAGE* pimg)
::HPEN hpen;

img.m_color = color;
lPen.lopnColor = color;
lPen.lopnColor = RGBTOBGR(color);
lPen.lopnStyle = img.m_linestyle.linestyle;
lPen.lopnWidth.x = img.m_linestyle.thickness;
::SetTextColor(img.getdc(), color);
if(lPen.lopnStyle == PS_USERSTYLE)
{
unsigned long style[20]{};
::LOGBRUSH lbr;
::LOGBRUSH lbr{BS_SOLID, lPen.lopnColor, 0};
unsigned short upattern = img.m_linestyle.upattern;
int n, bn = 0, len = 1, st = 0;
int n, bn = 0, len = 1, st(upattern & 1);

lbr.lbColor = lPen.lopnColor;
lbr.lbStyle = BS_SOLID;
lbr.lbHatch = 0;
st = upattern & 1;
for(n = 1; n < 16; n++)
if(upattern & (1 << n))
{
Expand Down Expand Up @@ -321,11 +312,9 @@ setfillcolor(color_t color, IMAGE* pimg)
{
auto& img(cimg_ref_c(pimg));

::LOGBRUSH lbr{0, COLORREF(), ::ULONG_PTR()};
::LOGBRUSH lbr{0, RGBTOBGR(color), BS_SOLID};

img.m_fillcolor = color;
lbr.lbColor = color;
lbr.lbHatch = BS_SOLID;
::HBRUSH hbr = ::CreateBrushIndirect(&lbr);
if(hbr)
::DeleteObject(::SelectObject(img.getdc(), hbr));
Expand All @@ -343,7 +332,7 @@ setbkcolor(color_t color, IMAGE* pimg)
color_t col = img.m_bk_color;

img.m_bk_color = color;
::SetBkColor(img.getdc(), color);
::SetBkColor(img.getdc(), RGBTOBGR(color));
for(size_t n = 0; n < size; ++n, ++p)
if(*p == col)
*p = color;
Expand All @@ -360,7 +349,7 @@ setbkcolor_f(color_t color, IMAGE* pimg)
if(const auto dc = img.getdc())
{
img.m_bk_color = color;
::SetBkColor(dc, color);
::SetBkColor(dc, RGBTOBGR(color));
}
}

Expand All @@ -370,7 +359,7 @@ setfontbkcolor(color_t color, IMAGE* pimg)
auto& img(cimg_ref(pimg));

if(const auto dc = img.getdc())
::SetBkColor(dc, color);
::SetBkColor(dc, RGBTOBGR(color));
}

void
Expand Down
4 changes: 3 additions & 1 deletion EGE/src/ege/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ IMAGE::saveimage(const wchar_t* filename)
}

int
IMAGE::savepngimg(std::FILE * fp, int bAlpha)
IMAGE::savepngimg(std::FILE* fp, int bAlpha)
{
unsigned long i, j;
::png_structp pic_ptr;
Expand Down Expand Up @@ -755,6 +755,8 @@ IMAGE::savepngimg(std::FILE * fp, int bAlpha)
for(i = 0; i < height; i++)
{
for(j = 0; j < width; ++j)
// XXX: Assume little endiness. PNG stores RGB by default,
// which is BGR in little endian integer representations.
reinterpret_cast<unsigned long&>(image[(i * width + j)
* pixelsize]) = RGBTOBGR(m_pBuffer[i * width + j]);
row_pointers[i] = (::png_bytep)image + i * width * pixelsize;
Expand Down

0 comments on commit ff16a45

Please sign in to comment.