move addBorder to textSubtitles

This commit is contained in:
Daniel Kamil Kozar
2021-11-15 03:01:16 +01:00
parent b24a30c781
commit d1e4ca27ee
3 changed files with 62 additions and 61 deletions
+60 -1
View File
@@ -21,6 +21,65 @@ using namespace std;
double pgs_frame_rates[16] = {
0, 23.97602397602397, 24, 25, 29.97002997002997, 30, 50, 59.94005994005994, 60, 0, 0, 0, 0, 0, 0, 0};
namespace {
const static uint32_t BORDER_COLOR = 0xff020202;
const static uint32_t BORDER_COLOR_TMP = RGB(0x1, 0x1, 0x1);
inline void setBPoint(uint32_t* addr)
{
if (*addr == 0)
*addr = BORDER_COLOR_TMP;
}
void addBorder(int borderWidth, uint8_t* data, int width, int height)
{
// add black border
for (int i = 0; i < borderWidth; ++i)
{
uint32_t* dst = (uint32_t*)data;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if (*dst != 0 && *dst != BORDER_COLOR_TMP)
{
if (x > 0)
{
setBPoint(dst - 1);
if (y > 0)
setBPoint(dst - 1 - width);
if (y < height - 1)
setBPoint(dst - 1 + width);
}
if (y > 0)
setBPoint(dst - width);
if (y < height - 1)
setBPoint(dst + width);
if (x < width - 1)
{
setBPoint(dst + 1);
if (y > 0)
setBPoint(dst + 1 - width);
if (y < height - 1)
setBPoint(dst + 1 + width);
}
}
dst++;
}
}
dst = (uint32_t*)data;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
if (*dst == BORDER_COLOR_TMP)
*dst = BORDER_COLOR;
dst++;
}
}
return;
}
}
PGSStreamReader::PGSStreamReader()
{
m_curPos = m_buffer = 0;
@@ -262,7 +321,7 @@ int PGSStreamReader::readObjectDef(uint8_t* pos, uint8_t* end)
rescaleRGB(&bmpDest, &bmpRef);
if (m_fontBorder)
TextSubtitlesRender::addBorder(m_fontBorder, m_scaledRgbBuffer, m_scaled_width, m_scaled_height);
addBorder(m_fontBorder, m_scaledRgbBuffer, m_scaled_width, m_scaled_height);
// memcpy(bmpDest.buffer, bmpRef.buffer, bmpDest.Width * bmpDest.Height * 4);
}
return 0;
-57
View File
@@ -434,61 +434,4 @@ bool TextSubtitlesRender::rasterText(const std::string& text)
return forced;
}
const static uint32_t BORDER_COLOR = 0xff020202;
const static uint32_t BORDER_COLOR_TMP = RGB(0x1, 0x1, 0x1);
inline void setBPoint(uint32_t* addr)
{
if (*addr == 0)
*addr = BORDER_COLOR_TMP;
}
void TextSubtitlesRender::addBorder(int borderWidth, uint8_t* data, int width, int height)
{
// add black border
for (int i = 0; i < borderWidth; ++i)
{
uint32_t* dst = (uint32_t*)data;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
if (*dst != 0 && *dst != BORDER_COLOR_TMP)
{
if (x > 0)
{
setBPoint(dst - 1);
if (y > 0)
setBPoint(dst - 1 - width);
if (y < height - 1)
setBPoint(dst - 1 + width);
}
if (y > 0)
setBPoint(dst - width);
if (y < height - 1)
setBPoint(dst + width);
if (x < width - 1)
{
setBPoint(dst + 1);
if (y > 0)
setBPoint(dst + 1 - width);
if (y < height - 1)
setBPoint(dst + 1 + width);
}
}
dst++;
}
}
dst = (uint32_t*)data;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
if (*dst == BORDER_COLOR_TMP)
*dst = BORDER_COLOR;
dst++;
}
}
return;
}
} // namespace text_subtitles
+2 -3
View File
@@ -104,7 +104,6 @@ class TextSubtitlesRender
virtual int getBaseline() = 0;
virtual void drawText(const std::string& text, RECT* rect) = 0;
virtual void flushRasterBuffer() = 0;
static void addBorder(int borderWidth, uint8_t* data, int width, int height);
int m_width;
int m_height;
@@ -113,11 +112,11 @@ class TextSubtitlesRender
protected:
Font m_font;
int m_borderWidth;
std::vector<std::pair<Font, std::string>> processTxtLine(const std::string& line, std::vector<Font>& fontStack);
int browserSizeToRealSize(int bSize, double rSize);
private:
Font m_initFont;
int browserSizeToRealSize(int bSize, double rSize);
std::vector<std::pair<Font, std::string>> processTxtLine(const std::string& line, std::vector<Font>& fontStack);
};
} // namespace text_subtitles
#endif