18 #include "precompiled.h"
42 for (
size_t i = 0; i <
m_Mipmap.size(); ++i)
63 for (
size_t i = 0; i <
m_Mipmap.size(); ++i)
70 top = clamp<size_t>((size_t)ceilf((
float)top / mapSize *
m_Mipmap[i].m_MapSize), 0,
m_Mipmap[i].m_MapSize);
92 while (mipmapSize > 1)
109 const size_t iy = (size_t)clamp<ssize_t>((
ssize_t)floorf(y), 0,
m_Mipmap.size() - 2);
111 const float fy = y - iy;
116 return (1 - fy) * h0 + fy * h1;
124 const size_t xi = (size_t)clamp<ssize_t>((
ssize_t)floor(x), 0, mipmap.
m_MapSize - 2);
125 const size_t zi = (size_t)clamp<ssize_t>((
ssize_t)floor(z), 0, mipmap.
m_MapSize - 2);
127 const float xf = clamp<float>(x-xi, 0.0f, 1.0f);
128 const float zf = clamp<float>(z-zi, 0.0f, 1.0f);
136 (1.f - xf) * (1.f - zf) * h00 +
137 xf * (1.f - zf) * h10 +
138 (1.f - xf) * zf * h01 +
157 for (
size_t dstZ = bottom; dstZ < top; ++dstZ)
159 for (
size_t dstX = left; dstX < right; ++dstX)
161 size_t srcX = dstX << 1;
162 size_t srcZ = dstZ << 1;
164 u16 h00 = ptr[srcX + 0 + srcZ * mapSize];
165 u16 h10 = ptr[srcX + 1 + srcZ * mapSize];
166 u16 h01 = ptr[srcX + 0 + (srcZ + 1) * mapSize];
167 u16 h11 = ptr[srcX + 1 + (srcZ + 1) * mapSize];
194 for (
size_t dstZ = bottom; dstZ < top; ++dstZ)
196 for (
size_t dstX = left; dstX < right; ++dstX)
198 const float x = ((float)dstX / (
float)out_mipmap.
m_MapSize) * mapSize;
199 const float z = ((float)dstZ / (
float)out_mipmap.
m_MapSize) * mapSize;
201 const size_t srcX = clamp<size_t>((size_t)x, 0, mapSize - 2);
202 const size_t srcZ = clamp<size_t>((size_t)z, 0, mapSize - 2);
204 const float fx = clamp<float>(x - srcX, 0.0f, 1.0f);
205 const float fz = clamp<float>(z - srcZ, 0.0f, 1.0f);
207 const float h00 = ptr[srcX + 0 + srcZ * mapSize];
208 const float h10 = ptr[srcX + 1 + srcZ * mapSize];
209 const float h01 = ptr[srcX + 0 + (srcZ + 1) * mapSize];
210 const float h11 = ptr[srcX + 1 + (srcZ + 1) * mapSize];
213 ((1.f - fx) * (1.f - fz) * h00 +
214 fx * (1.f - fz) * h10 +
215 (1.f - fx) * fz * h01 +
226 const size_t bpp = 8;
229 const size_t img_size = w * h * bpp/8;
233 void* img = buf.get() + hdr_size;
237 memset(img, 0x00, img_size);
239 for (
size_t i = 0; i <
m_Mipmap.size(); ++i)
241 size_t size =
m_Mipmap[i].m_MapSize;
244 for (
size_t y = 0; y < size; ++y)
246 for (
size_t x = 0; x < size; ++x)
248 u16 val = heightmap[x + y*size];
249 ((
u8*)img)[x + (y+yoff)*w] = val >> 8;
void DumpToDisk(const VfsPath &path) const
#define WARN_IF_ERR(expression)
float BilinearFilter(const SMipmap &mipmap, float x, float z) const
static const uintptr_t maxSectorSize
provides a memory range that can be expanded but doesn't waste physical memory or relocate itself...
float GetTrilinearGroundLevel(float x, float z, float radius) const
indicates the image is 8bpp greyscale.
size_t tex_hdr_size(const VfsPath &filename)
return the minimum header size (i.e.
void BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
void HalfResizeUpdate(SMipmap &out_mipmap, size_t mapSize, const u16 *ptr, size_t left, size_t bottom, size_t right, size_t top)
void Initialize(size_t mapSize, const u16 *ptr)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
void Update(const u16 *ptr)
shared_ptr< T > DummySharedPtr(T *ptr)
stores all data describing an image.
std::vector< SMipmap > m_Mipmap
static Status AllocateAligned(shared_ptr< T > &p, size_t size, size_t alignment=cacheLineSize)
Status tex_wrap(size_t w, size_t h, size_t bpp, size_t flags, const shared_ptr< u8 > &data, size_t ofs, Tex *t)
store the given image data into a Tex object; this will be as if it had been loaded via tex_load...
Status da_free(DynArray *da)
free all memory (address space + physical) that constitutes the given array.
#define debug_warn(expr)
display the error dialog with the given text.
T round_down_to_pow2(T x)
round down to next larger power of two.
void tex_free(Tex *t)
free all resources associated with the image and make further use of it impossible.
Status tex_encode(Tex *t, const OsPath &extension, DynArray *da)
encode a texture into a memory buffer in the desired file format.