forked from organicmaps/organicmaps
review fixes
This commit is contained in:
parent
6c950bada3
commit
9ad17a5c9d
3 changed files with 29 additions and 28 deletions
|
@ -1,12 +1,12 @@
|
|||
#include "df_map.hpp"
|
||||
|
||||
#include "../std/algorithm.hpp"
|
||||
#include "../std/cmath.hpp"
|
||||
|
||||
DFMap::DFMap(const vector<unsigned char> & data, int width, int height, unsigned char inValue, unsigned char outValue)
|
||||
DFMap::DFMap(const vector<uint8_t> & data, int width, int height, unsigned char inValue, unsigned char outValue)
|
||||
: m_width(width)
|
||||
, m_height(height)
|
||||
{
|
||||
//m_distances = new float[m_width * m_height];
|
||||
m_distances.resize(m_width * m_height);
|
||||
for (int i = 0; i < m_width * m_height; ++i)
|
||||
m_distances[i] = 0.0f;
|
||||
|
@ -34,14 +34,14 @@ void DFMap::Normalize()
|
|||
float minSignedDistance = 0;
|
||||
for (int j = 0; j < m_height; ++j)
|
||||
for (int i = 0; i < m_width; ++i)
|
||||
minSignedDistance = fmin(minSignedDistance, GetDistance(i, j));
|
||||
minSignedDistance = min(minSignedDistance, GetDistance(i, j));
|
||||
|
||||
float maxValue = 0.0f;
|
||||
for (int j = 0; j < m_height; ++j)
|
||||
for (int i = 0; i < m_width; ++i)
|
||||
{
|
||||
float d = GetDistance(i, j) - minSignedDistance;
|
||||
maxValue = fmax(d, maxValue);
|
||||
maxValue = max(d, maxValue);
|
||||
SetDistance(d, i, j);
|
||||
}
|
||||
|
||||
|
@ -65,19 +65,20 @@ unsigned char * DFMap::GenerateImage(int & w, int & h)
|
|||
return image;
|
||||
}
|
||||
|
||||
void DFMap::Do(vector<unsigned char> const & data, unsigned char inValue, unsigned char outValue)
|
||||
void DFMap::Do(vector<uint8_t> const & data, unsigned char inValue, unsigned char outValue)
|
||||
{
|
||||
for (int j = 0; j < m_height; ++j)
|
||||
{
|
||||
for (int i = 0; i < m_width; ++i)
|
||||
{
|
||||
if (get(data, i, j) == inValue)
|
||||
SetDistance(sqrtf(findRadialDistance(data, i, j, 256, outValue)), i, j);
|
||||
SetDistance(sqrt(findRadialDistance(data, i, j, 256, outValue)), i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float DFMap::findRadialDistance(vector<unsigned char> const & data, int pointX, int pointY, int maxRadius, unsigned char outValue)
|
||||
float DFMap::findRadialDistance(vector<uint8_t> const & data, int pointX, int pointY,
|
||||
int maxRadius, unsigned char outValue) const
|
||||
{
|
||||
float minDistance = maxRadius * maxRadius;
|
||||
for (int j = pointY - maxRadius; j < pointY + maxRadius; ++j)
|
||||
|
@ -95,7 +96,7 @@ float DFMap::findRadialDistance(vector<unsigned char> const & data, int pointX,
|
|||
int xDist = pointX - i;
|
||||
int yDist = pointY - j;
|
||||
float d = xDist * xDist + yDist * yDist;
|
||||
minDistance = fmin(d, minDistance);
|
||||
minDistance = min(d, minDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "../std/vector.hpp"
|
||||
#include "../std/stdint.hpp"
|
||||
|
||||
class DFMap
|
||||
{
|
||||
public:
|
||||
DFMap(vector<unsigned char> const & data,
|
||||
DFMap(vector<uint8_t> const & data,
|
||||
int width, int height,
|
||||
unsigned char inValue,
|
||||
unsigned char outValue);
|
||||
|
@ -17,10 +18,10 @@ public:
|
|||
unsigned char * GenerateImage(int & w, int & h);
|
||||
|
||||
private:
|
||||
void Do(vector<unsigned char> const & data, unsigned char inValue, unsigned char outValue);
|
||||
float findRadialDistance(vector<unsigned char> const & data,
|
||||
void Do(vector<uint8_t> const & data, unsigned char inValue, unsigned char outValue);
|
||||
float findRadialDistance(vector<uint8_t> const & data,
|
||||
int pointX, int pointY,
|
||||
int radius, unsigned char outValue);
|
||||
int radius, unsigned char outValue) const;
|
||||
|
||||
template<typename T>
|
||||
T get(vector<T> const & data, int i, int j) const
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "../base/macros.hpp"
|
||||
|
||||
#include "../std/cmath.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
#include "../std/map.hpp"
|
||||
|
@ -47,7 +49,7 @@ namespace
|
|||
return m_height;
|
||||
}
|
||||
|
||||
ZeroPoint GetZeroPoint(int pageNumber)
|
||||
ZeroPoint GetZeroPoint(int pageNumber) const
|
||||
{
|
||||
ZeroPoint zPoint;
|
||||
zPoint.m_x = pageNumber % GetWidth();
|
||||
|
@ -92,7 +94,7 @@ namespace
|
|||
MetricTemplate(16, 4, 4)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 15; ++ i)
|
||||
for (unsigned long i = 0; i < ARRAY_SIZE(templates); ++ i)
|
||||
{
|
||||
if (templates[i].m_pageCount == pageCount)
|
||||
{
|
||||
|
@ -155,13 +157,14 @@ namespace
|
|||
if (f.open(QIODevice::ReadOnly) == false)
|
||||
throw 1;
|
||||
|
||||
unsigned char * fontBuffer = new unsigned char[f.size()];
|
||||
f.read((char *)fontBuffer, f.size());
|
||||
|
||||
stbtt_fontinfo fontInfo;
|
||||
stbtt_InitFont(&fontInfo, fontBuffer, 0);
|
||||
{
|
||||
vector<uint8_t> fontBuffer(f.size(), 0);
|
||||
f.read((char *)&fontBuffer[0], fontBuffer.size());
|
||||
stbtt_InitFont(&fontInfo, &fontBuffer[0], 0);
|
||||
}
|
||||
|
||||
float scale = stbtt_ScaleForPixelHeight(&fontInfo, /*GlyphScaler * */m_fontSize);
|
||||
delete[] fontBuffer;
|
||||
for (range_iter_t range = font.value().begin(); range != font.value().end(); ++range)
|
||||
{
|
||||
for (int unicodeCode = range->first; unicodeCode <= range->second; ++unicodeCode)
|
||||
|
@ -230,9 +233,7 @@ namespace
|
|||
int width = EtalonTextureSize * compositor.GetWidth();
|
||||
int height = EtalonTextureSize * compositor.GetHeight();
|
||||
|
||||
unsigned char * resultImg = new unsigned char[width * height];
|
||||
memset(resultImg, 0, width * height);
|
||||
|
||||
vector<uint8_t> resultImg(width * height, 0);
|
||||
bool firstEmpty = true;
|
||||
for (size_t k = 0; k < outRects.size(); ++k)
|
||||
{
|
||||
|
@ -277,13 +278,11 @@ namespace
|
|||
foreach (GlyphInfo info, infos)
|
||||
delete[] info.m_img;
|
||||
|
||||
m_image = QImage(resultImg, width, height, QImage::Format_Indexed8);
|
||||
m_image = QImage(&resultImg[0], width, height, QImage::Format_Indexed8);
|
||||
m_image.setColorCount(256);
|
||||
for (int i = 0; i < 256; ++i)
|
||||
m_image.setColor(i, qRgb(i, i, i));
|
||||
|
||||
delete[] resultImg;
|
||||
|
||||
m_infos.clear();
|
||||
m_infos.append(infos);
|
||||
m_infos.append(emptyInfos);
|
||||
|
@ -294,11 +293,11 @@ namespace
|
|||
return m_image;
|
||||
}
|
||||
|
||||
QList<GlyphInfo> const & GetInfos() { return m_infos; }
|
||||
QList<GlyphInfo> const & GetInfos() const { return m_infos; }
|
||||
|
||||
private:
|
||||
unsigned char * processGlyph(unsigned char * glyphImage, int width, int height,
|
||||
int & newW, int & newH)
|
||||
static unsigned char * processGlyph(unsigned char * glyphImage, int width, int height,
|
||||
int & newW, int & newH)
|
||||
{
|
||||
static int border = 2;
|
||||
int sWidth = width + 4 * border;
|
||||
|
|
Loading…
Add table
Reference in a new issue