tahoma2d/toonz/sources/toonzlib/sandor_fxs/CallCircle.cpp
Campbell Barton b3bd842e04 Make functions static, ensure declarations match headers (#610)
This patch used -Wmissing-declarations warning
to show functions and symbols that had no declarations, and either:

- Make static
- Add to header

This helps avoid possability that declarations and functions get out of sync.
And ensures all source files reference headers correctly.

It also makes sure functions defined with extern "C",
have this defined in the header. An error found in calligraph.h while writing this patch.

This has been applied to toonzlib, to avoid making very large global changes.
If accepted, -Wmissing-declarations warning could be added to CMake.
2016-07-13 21:05:06 +09:00

91 lines
2.2 KiB
C++

// CallCircle.cpp: implementation of the CCallCircle class.
//
//////////////////////////////////////////////////////////////////////
#include <math.h>
#include <stdlib.h>
#include <search.h>
//#include "myetc.h"
#include "CallCircle.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
static int callcircle_xydwCompare(const void *a, const void *b) {
SXYDW *aa = (SXYDW *)a;
SXYDW *bb = (SXYDW *)b;
if (aa->w < bb->w) return -1;
if (aa->w > bb->w) return 1;
return 0;
}
CCallCircle::CCallCircle(const double r) : m_r(r), m_nb(0) {
int rr = (int)r + 1;
rr *= 2;
int dd = rr * 2 + 1;
int dd2 = dd * dd;
if (dd2 == 0) {
null();
return;
}
m_c.reset(new SXYDW[dd2]);
if (!m_c) throw SMemAllocError("in callCircle");
for (int y = -rr; y <= rr; y++)
for (int x = -rr; x <= rr; x++) {
double d = sqrt((double)(x * x + y * y));
if (d <= r && m_nb < dd2) {
m_c[m_nb].x = x;
m_c[m_nb].y = y;
m_c[m_nb].w = d;
m_nb++;
}
}
qsort(m_c.get(), m_nb, sizeof(SXYDW), callcircle_xydwCompare);
}
void CCallCircle::null() {
m_nb = 0;
m_r = 0.0;
m_c.reset();
}
CCallCircle::~CCallCircle() { null(); }
void CCallCircle::print() {
/*smsg_info(" --- CCallCircle ---");
smsg_info(" m_nb=%d", m_nb);
smsg_info(" m_r=%f", m_r);
for( int i=0; i<m_nb; i++ )
smsg_info(" %d. = (%d,%d,%f)", i, m_c[i].x,m_c[i].y,m_c[i].w);
smsg_info(" --- ----------- ---\n");
*/
}
void CCallCircle::draw(UCHAR *drawB, const int lX, const int lY, const int xx,
const int yy, const double r) {
double aa = 2.0 * r / 3.0; // Size of antialising
for (int i = 0; i < m_nb && m_c[i].w <= r; i++) {
double w = m_c[i].w;
int x = xx + m_c[i].x;
int y = yy + m_c[i].y;
if (x >= 0 && y >= 0 && x < lX && y < lY) {
UCHAR *pDB = drawB + y * lX + x;
if (w <= aa) {
*pDB = (UCHAR)255;
} else {
double q = 255.0 * (r - w) / (r - aa);
q = D_CUT_0_255(q);
UCHAR ucq = UC_ROUND(q);
(*pDB) = (*pDB) < ucq ? ucq : (*pDB);
}
}
}
}