28 #ifndef OGREIMAGERESAMPLER_H
29 #define OGREIMAGERESAMPLER_H
70 uint64 sz_48 = (stepz >> 1) - 1;
71 for (
size_t z = dst.
front; z < dst.
back; z++, sz_48 += stepz) {
72 size_t srczoff = (size_t)(sz_48 >> 48) * src.
slicePitch;
74 uint64 sy_48 = (stepy >> 1) - 1;
75 for (
size_t y = dst.
top; y < dst.
bottom; y++, sy_48 += stepy) {
76 size_t srcyoff = (size_t)(sy_48 >> 48) * src.
rowPitch;
78 uint64 sx_48 = (stepx >> 1) - 1;
79 for (
size_t x = dst.
left; x < dst.
right; x++, sx_48 += stepx) {
80 uchar* psrc = srcdata +
81 elemsize*((size_t)(sx_48 >> 48) + srcyoff + srczoff);
82 memcpy(pdst, psrc, elemsize);
117 uint64 sz_48 = (stepz >> 1) - 1;
118 for (
size_t z = dst.
front; z < dst.
back; z++, sz_48+=stepz) {
119 temp =
static_cast<unsigned int>(sz_48 >> 32);
120 temp = (temp > 0x8000)? temp - 0x8000 : 0;
121 size_t sz1 = temp >> 16;
122 size_t sz2 = std::min(sz1+1,src.
getDepth()-1);
123 float szf = (temp & 0xFFFF) / 65536.f;
125 uint64 sy_48 = (stepy >> 1) - 1;
126 for (
size_t y = dst.
top; y < dst.
bottom; y++, sy_48+=stepy) {
127 temp =
static_cast<unsigned int>(sy_48 >> 32);
128 temp = (temp > 0x8000)? temp - 0x8000 : 0;
129 size_t sy1 = temp >> 16;
130 size_t sy2 = std::min(sy1+1,src.
getHeight()-1);
131 float syf = (temp & 0xFFFF) / 65536.f;
133 uint64 sx_48 = (stepx >> 1) - 1;
134 for (
size_t x = dst.
left; x < dst.
right; x++, sx_48+=stepx) {
135 temp =
static_cast<unsigned int>(sx_48 >> 32);
136 temp = (temp > 0x8000)? temp - 0x8000 : 0;
137 size_t sx1 = temp >> 16;
138 size_t sx2 = std::min(sx1+1,src.
getWidth()-1);
139 float sxf = (temp & 0xFFFF) / 65536.f;
144 #define UNPACK(dst,x,y,z) PixelUtil::unpackColour(&dst, src.format, \
145 srcdata + srcelemsize*((x)+(y)*src.rowPitch+(z)*src.slicePitch))
154 x1y1z1 * ((1.0f - sxf)*(1.0f - syf)*(1.0f - szf)) +
155 x2y1z1 * ( sxf *(1.0f - syf)*(1.0f - szf)) +
156 x1y2z1 * ((1.0f - sxf)* syf *(1.0f - szf)) +
157 x2y2z1 * ( sxf * syf *(1.0f - szf)) +
158 x1y1z2 * ((1.0f - sxf)*(1.0f - syf)* szf ) +
159 x2y1z2 * ( sxf *(1.0f - syf)* szf ) +
160 x1y2z2 * ((1.0f - sxf)* syf * szf ) +
161 x2y2z2 * ( sxf * syf * szf );
185 float* srcdata = (
float*)src.
data;
186 float* pdst = (
float*)dst.
data;
202 uint64 sz_48 = (stepz >> 1) - 1;
203 for (
size_t z = dst.
front; z < dst.
back; z++, sz_48+=stepz) {
204 temp =
static_cast<unsigned int>(sz_48 >> 32);
205 temp = (temp > 0x8000)? temp - 0x8000 : 0;
206 size_t sz1 = temp >> 16;
207 size_t sz2 = std::min(sz1+1,src.
getDepth()-1);
208 float szf = (temp & 0xFFFF) / 65536.f;
210 uint64 sy_48 = (stepy >> 1) - 1;
211 for (
size_t y = dst.
top; y < dst.
bottom; y++, sy_48+=stepy) {
212 temp =
static_cast<unsigned int>(sy_48 >> 32);
213 temp = (temp > 0x8000)? temp - 0x8000 : 0;
214 size_t sy1 = temp >> 16;
215 size_t sy2 = std::min(sy1+1,src.
getHeight()-1);
216 float syf = (temp & 0xFFFF) / 65536.f;
218 uint64 sx_48 = (stepx >> 1) - 1;
219 for (
size_t x = dst.
left; x < dst.
right; x++, sx_48+=stepx) {
220 temp =
static_cast<unsigned int>(sx_48 >> 32);
221 temp = (temp > 0x8000)? temp - 0x8000 : 0;
222 size_t sx1 = temp >> 16;
223 size_t sx2 = std::min(sx1+1,src.
getWidth()-1);
224 float sxf = (temp & 0xFFFF) / 65536.f;
227 float accum[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
229 #define ACCUM3(x,y,z,factor) \
230 { float f = factor; \
231 size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \
232 accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
233 accum[2]+=srcdata[off+2]*f; }
235 #define ACCUM4(x,y,z,factor) \
236 { float f = factor; \
237 size_t off = (x+y*src.rowPitch+z*src.slicePitch)*srcchannels; \
238 accum[0]+=srcdata[off+0]*f; accum[1]+=srcdata[off+1]*f; \
239 accum[2]+=srcdata[off+2]*f; accum[3]+=srcdata[off+3]*f; }
241 if (srcchannels == 3 || dstchannels == 3) {
243 ACCUM3(sx1,sy1,sz1,(1.0f-sxf)*(1.0f-syf)*(1.0f-szf));
244 ACCUM3(sx2,sy1,sz1, sxf *(1.0f-syf)*(1.0f-szf));
245 ACCUM3(sx1,sy2,sz1,(1.0f-sxf)* syf *(1.0f-szf));
246 ACCUM3(sx2,sy2,sz1, sxf * syf *(1.0f-szf));
247 ACCUM3(sx1,sy1,sz2,(1.0f-sxf)*(1.0f-syf)* szf );
248 ACCUM3(sx2,sy1,sz2, sxf *(1.0f-syf)* szf );
249 ACCUM3(sx1,sy2,sz2,(1.0f-sxf)* syf * szf );
250 ACCUM3(sx2,sy2,sz2, sxf * syf * szf );
254 ACCUM4(sx1,sy1,sz1,(1.0f-sxf)*(1.0f-syf)*(1.0f-szf));
255 ACCUM4(sx2,sy1,sz1, sxf *(1.0f-syf)*(1.0f-szf));
256 ACCUM4(sx1,sy2,sz1,(1.0f-sxf)* syf *(1.0f-szf));
257 ACCUM4(sx2,sy2,sz1, sxf * syf *(1.0f-szf));
258 ACCUM4(sx1,sy1,sz2,(1.0f-sxf)*(1.0f-syf)* szf );
259 ACCUM4(sx2,sy1,sz2, sxf *(1.0f-syf)* szf );
260 ACCUM4(sx1,sy2,sz2,(1.0f-sxf)* syf * szf );
261 ACCUM4(sx2,sy2,sz2, sxf * syf * szf );
264 memcpy(pdst, accum,
sizeof(
float)*dstchannels);
310 uint64 sy_48 = (stepy >> 1) - 1;
311 for (
size_t y = dst.
top; y < dst.
bottom; y++, sy_48+=stepy) {
312 temp =
static_cast<unsigned int>(sy_48 >> 36);
313 temp = (temp > 0x800)? temp - 0x800: 0;
314 unsigned int syf = temp & 0xFFF;
315 size_t sy1 = temp >> 12;
316 size_t sy2 = std::min(sy1+1, src.
bottom-src.
top-1);
320 uint64 sx_48 = (stepx >> 1) - 1;
321 for (
size_t x = dst.
left; x < dst.
right; x++, sx_48+=stepx) {
322 temp =
static_cast<unsigned int>(sx_48 >> 36);
323 temp = (temp > 0x800)? temp - 0x800 : 0;
324 unsigned int sxf = temp & 0xFFF;
325 size_t sx1 = temp >> 12;
326 size_t sx2 = std::min(sx1+1, src.
right-src.
left-1);
328 unsigned int sxfsyf = sxf*syf;
329 for (
unsigned int k = 0; k < channels; k++) {
331 srcdata[(sx1 + syoff1)*channels+k]*(0x1000000-(sxf<<12)-(syf<<12)+sxfsyf) +
332 srcdata[(sx2 + syoff1)*channels+k]*((sxf<<12)-sxfsyf) +
333 srcdata[(sx1 + syoff2)*channels+k]*((syf<<12)-sxfsyf) +
334 srcdata[(sx2 + syoff2)*channels+k]*sxfsyf;
337 *pdst++ =
static_cast<uchar>((accum + 0x800000) >> 24);
static void scale(const PixelBox &src, const PixelBox &dst)
#define ACCUM3(x, y, z, factor)
size_t rowPitch
Number of elements between the leftmost pixel of one row and the left pixel of the next...
size_t getHeight() const
Get the height of this box.
static void scale(const PixelBox &src, const PixelBox &dst)
Class representing colour.
size_t getSliceSkip() const
Get the number of elements between one past the right bottom pixel of one slice and the left top pixe...
size_t getWidth() const
Get the width of this box.
void * data
The data pointer.
#define ACCUM4(x, y, z, factor)
static void scale(const PixelBox &src, const PixelBox &dst)
PixelFormat format
The pixel format.
unsigned char uchar
In order to avoid finger-aches :)
unsigned long long uint64
size_t slicePitch
Number of elements between the top left pixel of one (depth) slice and the top left pixel of the next...
#define UNPACK(dst, x, y, z)
static void scale(const PixelBox &src, const PixelBox &dst)
size_t getDepth() const
Get the depth of this box.
static size_t getNumElemBytes(PixelFormat format)
Returns the size in bytes of an element of the given pixel format.
static void packColour(const ColourValue &colour, const PixelFormat pf, void *dest)
Pack a colour value to memory.
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
size_t getRowSkip() const
Get the number of elements between one past the rightmost pixel of one row and the leftmost pixel of ...