Use a better image resize code

The box filter from irrlicht produces wrong brightness when using with
different size
This commit is contained in:
Benau 2019-06-23 01:02:05 +08:00
parent b8fbc79306
commit 074039d2c5
3 changed files with 42 additions and 7 deletions

View File

@ -150,6 +150,17 @@ LOCAL_CFLAGS := -I../lib/bullet/src/
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
# Graphics utils
LOCAL_MODULE := graphics_utils
LOCAL_PATH := .
LOCAL_CPP_FEATURES += rtti
LOCAL_SRC_FILES := $(wildcard ../lib/graphics_utils/mipmap/*.c)
LOCAL_CFLAGS := -I../lib/graphics_utils/mipmap
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
# Irrlicht
LOCAL_MODULE := irrlicht
LOCAL_PATH := .
@ -184,6 +195,7 @@ LOCAL_CFLAGS := -I../lib/angelscript/include \
-I../lib/ifaddrs \
-I../lib/irrlicht/include \
-I../lib/irrlicht/source/Irrlicht \
-I../lib/graphics_utils \
-I../src \
-Iobj/curl/include \
-Iobj/fribidi/include \
@ -205,7 +217,7 @@ LOCAL_CPPFLAGS := -std=gnu++0x
LOCAL_STATIC_LIBRARIES := irrlicht bullet enet ifaddrs angelscript \
vorbisfile vorbis ogg openal curl libssl libcrypto \
gnustl_static raqm fribidi harfbuzz freetype
gnustl_static raqm fribidi harfbuzz freetype graphics_utils
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)

View File

@ -368,11 +368,6 @@ void CImage::copyToScalingBoxFilter(IImage* target, s32 bias, bool blend)
s32 fy = core::ceil32( sourceYStep );
f32 sx;
f32 sy;
// Color emoji scaled wrongly with overbright color if larger than 4
if (fx > 4)
fx = 4;
if (fy > 4)
fy = 4;
sy = 0.f;
for ( u32 y = 0; y != destSize.Height; ++y )

View File

@ -36,6 +36,14 @@
#include "GlyphLayout.h"
#include <array>
#ifndef SERVER_ONLY
extern "C"
{
#include <mipmap/img.h>
#include <mipmap/imgresize.h>
}
#endif
// ----------------------------------------------------------------------------
/** Constructor. It will initialize the \ref m_spritebank and TTF files to use.
* \param name The name of face, used by irrlicht to distinguish spritebank.
@ -280,7 +288,27 @@ void FontWithFace::insertGlyph(unsigned font_number, unsigned glyph_index)
->getVideoDriver()->createImage(video::ECF_A8R8G8B8,
{ cur_glyph_width , cur_glyph_height});
assert(scaled);
unscaled->copyToScalingBoxFilter(scaled);
if (cur_glyph_width >= bits->width ||
cur_glyph_height >= bits->rows)
{
unscaled->copyToScaling(scaled);
}
else
{
imReduceOptions options;
imReduceSetOptions(&options, IM_REDUCE_FILTER_LINEAR/*filter*/,
3/*hopcount*/, 16.0f/*alpha*/, 1.0f/*amplifynormal*/,
0.0f/*normalsustainfactor*/);
int ret = imReduceImageKaiserData((unsigned char*)scaled->lock(),
(unsigned char*)unscaled->lock(), bits->width, bits->rows, 4,
bits->width * 4, cur_glyph_width , cur_glyph_height,
&options);
if (ret != 1)
{
Log::error("FontWithFace",
"Error reduce bitmap font size.");
}
}
uint8_t* scaled_data = (uint8_t*)scaled->lock();
for (unsigned int i = 0; i < cur_glyph_width * cur_glyph_height;
i++)