Skip to content

Commit

Permalink
Don't do memcpy.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Feb 3, 2020
1 parent 49de562 commit 3bc8340
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
14 changes: 5 additions & 9 deletions plugins/i3s/lepcc/src/ClusterRGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ ErrCode ClusterRGB::Decode(const Byte** ppByte, int64 bufferSize, uint32& nPtsIn
return ErrCode::BufferTooSmall;

m_colorMap.resize(numColors);
memset(&m_colorMap[0], 0, m_colorMap.size() * sizeof(m_colorMap[0]));

for (uint16 i = 0; i < numColors; i++) // read colormap
{
memcpy(&m_colorMap[i], ptr, 3);
ptr += 3;
m_colorMap[i].r = *ptr++;
m_colorMap[i].g = *ptr++;
m_colorMap[i].b = *ptr++;
}

RGB_t* dstPtr = colors;
Expand All @@ -432,18 +432,14 @@ ErrCode ClusterRGB::Decode(const Byte** ppByte, int64 bufferSize, uint32& nPtsIn
for (uint32 i = 0; i < hd1.numPoints; i++) // read color index per point
{
Byte index = *ptr++;
memcpy(dstPtr, &m_colorMap[index], 3);
dstPtr++;
*dstPtr++ = m_colorMap[index];
}
}
else if (hd1.colorIndexCompressionMethod == AllConst)
{
RGBA_t rgba = m_colorMap[0];

for (uint32 i = 0; i < hd1.numPoints; i++) // special case all points have same color
{
memcpy(dstPtr, &rgba, 3);
dstPtr++;
*dstPtr++ = m_colorMap[0];
}
}

Expand Down
11 changes: 7 additions & 4 deletions plugins/i3s/lepcc/src/ClusterRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ namespace lepcc
int rMax, gMax, bMax;
};

struct RGBA_t
struct RGBA_t : public RGB_t
{
Byte r, g, b, a;
Byte a;

RGBA_t() {}
RGBA_t(Byte r0, Byte g0, Byte b0, Byte a0 = 0) : r(r0), g(g0), b(b0), a(a0) {}
RGBA_t() : a{0}
{}
RGBA_t(Byte r0, Byte g0, Byte b0, Byte a0 = 0) :
RGB_t(r0, g0, b0), a(a0)
{}

int DistRGB(RGBA_t v)
{
Expand Down
19 changes: 13 additions & 6 deletions plugins/i3s/lepcc/src/include/lepcc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,27 @@ namespace lepcc
{
Byte r, g, b;

RGB_t() {}
RGB_t(Byte r0, Byte g0, Byte b0) : r(r0), g(g0), b(b0) {}
RGB_t() : r{0}, g{0}, b{0}
{}
RGB_t(Byte r0, Byte g0, Byte b0) : r(r0), g(g0), b(b0)
{}

bool operator==(const RGB_t& v) const { return r == v.r && g == v.g && b == v.b; }
bool operator==(const RGB_t& v) const
{ return r == v.r && g == v.g && b == v.b; }
};

struct Point3D
{
double x, y, z;

Point3D() {}
Point3D(double a, double b, double c) : x(a), y(b), z(c) {}
Point3D() : x{0}, y{0}, z{0}
{}

Point3D operator-(const Point3D& b) const { return Point3D(x - b.x, y - b.y, z - b.z); }
Point3D(double a, double b, double c) : x(a), y(b), z(c)
{}

Point3D operator-(const Point3D& b) const
{ return Point3D(x - b.x, y - b.y, z - b.z); }
};

struct Extent3D
Expand Down

0 comments on commit 3bc8340

Please sign in to comment.