2 #include "kaleidoscope-config.h"
5 #define _USE_MATH_DEFINES
15 if (major && minor && patch)
17 *major = PROJECT_MAJOR_VERSION;
18 *minor = PROJECT_MINOR_VERSION;
19 *patch = PROJECT_PATCH_VERSION;
25 static char info[
sizeof(PROJECT_VERSION)];
26 strncpy(info, PROJECT_VERSION,
sizeof(PROJECT_VERSION));
33 static char info[125];
35 strncpy(info, PROJECT_VERSION,
sizeof(PROJECT_VERSION));
36 offset +=
sizeof(PROJECT_VERSION);
37 memset(&info[offset - 1], 32, 1);
38 strncpy(&info[offset], COMPILER_NAME,
sizeof(COMPILER_NAME));
39 offset +=
sizeof(COMPILER_NAME);
40 memset(&info[offset - 1], 32, 1);
41 strncpy(&info[offset], COMPILER_VERSION,
sizeof(COMPILER_VERSION));
42 offset +=
sizeof(COMPILER_VERSION);
43 memset(&info[offset - 1], 32, 1);
44 strncpy(&info[offset], BUILD_TYPE,
sizeof(BUILD_TYPE));
45 offset +=
sizeof(BUILD_TYPE);
46 memset(&info[offset - 1], 32, 1);
47 strncpy(&info[offset], PROJECT_BUILD_DATE,
sizeof(PROJECT_BUILD_DATE));
48 offset +=
sizeof(PROJECT_BUILD_DATE);
49 memset(&info[offset - 1], 32, 1);
50 strncpy(&info[offset], PROJECT_BUILD_TIME,
sizeof(PROJECT_BUILD_TIME));
56 int compare(
const void *lhsPtr,
const void *rhsPtr)
68 for (idx = 1; idx < height - 1; ++idx)
70 int heightOffset = idx * width;
71 for (jdx = 1; jdx < width - 1; ++jdx)
79 if (((ptrIn - 1)->dstLocation.x) || ((ptrIn - 1)->dstLocation.y))
84 else if (((ptrIn + 1)->dstLocation.x) || ((ptrIn + 1)->dstLocation.y))
89 else if (((ptrIn - width)->dstLocation.x) || ((ptrIn - width)->dstLocation.y))
92 ptrOut->
srcLocation.
y = (ptrIn - width)->srcLocation.y - 1;
94 else if (((ptrIn + width)->dstLocation.x) || ((ptrIn + width)->dstLocation.y))
97 ptrOut->
srcLocation.
y = (ptrIn + width)->srcLocation.y + 1;
99 else if (((ptrIn - width - 1)->dstLocation.x) || ((ptrIn - width - 1)->dstLocation.y))
101 ptrOut->
srcLocation.
x = (ptrIn - width - 1)->srcLocation.x - 1;
102 ptrOut->
srcLocation.
y = (ptrIn - width - 1)->srcLocation.y - 1;
104 else if (((ptrIn - width + 1)->dstLocation.x) || ((ptrIn - width + 1)->dstLocation.y))
106 ptrOut->
srcLocation.
x = (ptrIn - width + 1)->srcLocation.x + 1;
107 ptrOut->
srcLocation.
y = (ptrIn - width + 1)->srcLocation.y - 1;
109 else if (((ptrIn + width - 1)->dstLocation.x) || ((ptrIn + width - 1)->dstLocation.y))
111 ptrOut->
srcLocation.
x = (ptrIn + width - 1)->srcLocation.x - 1;
112 ptrOut->
srcLocation.
y = (ptrIn + width - 1)->srcLocation.y - 1;
114 else if (((ptrIn + width + 1)->dstLocation.x) || ((ptrIn + width + 1)->dstLocation.y))
116 ptrOut->
srcLocation.
x = (ptrIn + width + 1)->srcLocation.x + 1;
117 ptrOut->
srcLocation.
y = (ptrIn + width + 1)->srcLocation.y + 1;
131 double cosVal = cos(angle * M_PI / 180);
132 double sinVal = sin(angle * M_PI / 180);
134 for (idx = 0; idx < width * height; ++idx)
136 if (orgData[idx].dstLocation.x || orgData[idx].
dstLocation.
y)
138 int newX = (int)round(orgData[idx].dstLocation.x * cosVal + orgData[idx].
dstLocation.
y * sinVal);
139 int newY = (int)round(orgData[idx].dstLocation.y * cosVal - orgData[idx].
dstLocation.
x * sinVal);
143 newY += (height / 2);
145 if (newX <= width && newX >= 0 && newY <= height && newY >= 0)
160 const double topAngle = 360.0 / n;
161 const double tanVal = tan(topAngle / 2.0 * M_PI / 180.0);
162 const int triangleHeight = (int)fmin(round(width / (2.0 * tanVal)), height - 1);
163 const int heightStart = (height - triangleHeight) / 2;
164 const int heightEnd = (height + triangleHeight) / 2;
165 const int scaleDownOffset = (int)(height * scaleDown / 2);
168 assert(heightStart >= 0);
169 assert(heightStart <= height);
170 assert(heightEnd >= 0);
171 assert(heightEnd <= height);
173 for (idx = heightStart; idx < heightEnd; ++idx)
175 const int currentBaseLength = (int)((idx - heightStart) * tanVal);
177 const int widthStart = (width / 2 - currentBaseLength);
178 const int widthEnd = (width / 2 + currentBaseLength);
181 if (widthStart < 0 || widthStart > width || widthEnd < 0 || widthEnd > width)
185 for (jdx = widthStart; jdx <= widthEnd; ++jdx)
191 ptr[jdx].
dstLocation.
x = (int)((jdx - width / 2) * scaleDown);
192 ptr[jdx].
dstLocation.
y = (int)((idx - heightStart - height / 2) * scaleDown + scaleDownOffset);
203 int retval = EXIT_FAILURE;
204 const int nPixels = width * height;
208 if (handler == NULL || n <= 2 || width <= 0 || height <= 0 || nComponents <= 0 || scaleDown <= 0.0 ||
216 assert(nComponents > 0);
217 assert(scaleDown > 0.0);
218 assert(scaleDown < 1.0);
220 handler->
width = width;
226 if (!buffPtr1 || !buffPtr2)
233 for (idx = 0; idx < n; ++idx)
235 double rotationAngle = idx * (360.0 / n);
236 rotatePoints(buffPtr2, buffPtr1, width, height, rotationAngle);
245 for (idx = 0; idx < nPixels; ++idx)
251 buffPtr1[handler->
nPoints] = *ptr;
264 for (idx = 1; idx < handler->
nPoints; ++idx)
266 if (
compare(&buffPtr1[jdx], &buffPtr1[idx]))
268 buffPtr1[jdx] = buffPtr1[idx];
276 retval = EXIT_SUCCESS;
282 if (retval == EXIT_FAILURE)
291 const long long nComponents = handler->
nComponents;
294 unsigned char *srcPtr = imgIn;
295 unsigned char *destPtr = imgOut;
298 for (idx = 0; idx < nPixels; ++idx, ++destPtr, ++srcPtr)
299 *destPtr = (
unsigned char)((*srcPtr) * k);
300 for (idx = 0; idx < handler->
nPoints; ++idx, ++ptrTransform)
301 memcpy(&(imgOut[ptrTransform->dstOffset]), &(imgIn[ptrTransform->srcOffset]), nComponents);
void getKaleidoscopeVersion(int *major, int *minor, int *patch)
Get the Kaleidoscope Library version as integer.
char * getKaleidoscopeLibraryInfo()
Get the Kaleidoscope Library info as string.
int initKaleidoscope(KaleidoscopeHandle *handler, int n, int width, int height, int nComponents, double scaleDown)
Initializes kaleidoscope handler.
char * getKaleidoscopeVersionString()
Get the Kaleidoscope Library version as string.
void interpolate(TransformationInfo *dataOut, TransformationInfo *dataIn, int width, int height)
A simple interpolation function. Internal use only.
void rotatePoints(TransformationInfo *outData, TransformationInfo *orgData, int width, int height, double angle)
Rotates the coordinates of sliced triangle. Internal use only.
void processKaleidoscope(KaleidoscopeHandle *handler, double k, unsigned char *imgIn, unsigned char *imgOut)
Applies kaleidoscope effect to image.
int compare(const void *lhsPtr, const void *rhsPtr)
int sliceTriangle(TransformationInfo *transformPtr, int width, int height, int n, double scaleDown)
Slices a suitable triangle from image.
void deInitKaleidoscope(KaleidoscopeHandle *handler)
Deinitializes kaleidoscope handler.
Struct for kaleidoscope effect generator.
long long nPoints
Total number of points of transfer function.
struct TransformationInfo_t * pTransferFunc
Transformation info.
unsigned char nComponents
Number of components (eg 3 for RGB)