CorTeX Core ABI 7
ToolTech Software · C++ library reference
Loading...
Searching...
No Matches
ctxImageInterpolation.h
Go to the documentation of this file.
1//*****************************************************************************
2// File : ctxImageInterpolation.h
3// Description : Shared component interpolation for SDK and standalone C++
4// Author : Anders Moden
5// Product : CorTeX 2.0.1
6// Copyright (C) 2026 Anders Moden, Sweden
7// Revision History...
8// AMO 261021 Share existing interpolation without a runtime-library dependency (2.0.2)
9//*****************************************************************************
10#ifndef __CTX_IMAGE_INTERPOLATION_H__
11#define __CTX_IMAGE_INTERPOLATION_H__
12
13#ifdef CTX_CPP_STANDALONE
14#include <ctxVirtualMachine.h>
15#ifndef CTX_CPP_STANDALONE_RUNTIME
16#error Standalone interpolation requires the small standalone header first in the include path
17#endif
18#else
19#include "ctxBase.h"
20#endif
21#include <math.h>
22
29
37template <class ImageAccess> inline gzFloat ctxInterpolateImageComponent(ImageAccess& access,
38 gzUInt32 id, double x, double y, gzInt32 depth, ctxImageInterpolationType interpolation)
39{
40 if (!isfinite(x) || !isfinite(y) || x < -2147483647.0 || y < -2147483647.0 ||
41 x > 2147483646.0 || y > 2147483646.0 || id >= access.getNumberOfImages() ||
42 depth < 0 || (gzUInt32)depth >= access.getImageDepth())
43 return 0.0f;
44
45 if (interpolation == CTX_IMAGE_INTERPOLATION_NEAREST)
46 return access.getComponentValue(id, (gzInt32)floor(x + 0.5), (gzInt32)floor(y + 0.5), depth);
47
48 if (interpolation != CTX_IMAGE_INTERPOLATION_LINEAR)
49 return 0.0f;
50
51 gzInt32 ix = (gzInt32)floor(x), iy = (gzInt32)floor(y);
52 double fx = x - ix, fy = y - iy;
53 return (gzFloat)((1.0 - fy) * ((1.0 - fx) * access.getComponentValue(id, ix, iy, depth) +
54 fx * access.getComponentValue(id, ix + 1, iy, depth)) + fy *
55 ((1.0 - fx) * access.getComponentValue(id, ix, iy + 1, depth) +
56 fx * access.getComponentValue(id, ix + 1, iy + 1, depth)));
57}
58
59#endif
ctxImageInterpolationType
Explicit interpolation for caller-owned image accessors.
@ CTX_IMAGE_INTERPOLATION_LINEAR
@ CTX_IMAGE_INTERPOLATION_NEAREST
gzFloat ctxInterpolateImageComponent(ImageAccess &access, gzUInt32 id, double x, double y, gzInt32 depth, ctxImageInterpolationType interpolation)
Read a component with the same kernel in SDK and standalone builds.