Skip to content

Commit

Permalink
multidim: use GDALTranspose2D()
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 3, 2025
1 parent 284d5e6 commit dd8331c
Showing 1 changed file with 4 additions and 59 deletions.
63 changes: 4 additions & 59 deletions gcore/gdalmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4681,33 +4681,6 @@ static void CopyToFinalBuffer(const void *pSrcBuffer,
goto lbl_return_to_caller_in_loop;
}

/************************************************************************/
/* Transpose2D() */
/************************************************************************/

template <class T>
static void Transpose2D(T *dst, const T *src, size_t src_height,
size_t src_width)
{
constexpr size_t blocksize = 32;
for (size_t i = 0; i < src_height; i += blocksize)
{
for (size_t j = 0; j < src_width; j += blocksize)
{
// transpose the block beginning at [i,j]
const size_t max_k = std::min(i + blocksize, src_height);
for (size_t k = i; k < max_k; ++k)
{
const size_t max_l = std::min(j + blocksize, src_width);
for (size_t l = j; l < max_l; ++l)
{
dst[k + l * src_height] = src[l + k * src_width];
}
}
}
}
}

/************************************************************************/
/* TransposeLast2Dims() */
/************************************************************************/
Expand All @@ -4727,38 +4700,10 @@ static bool TransposeLast2Dims(void *pDstBuffer,
GByte *pabyDstBuffer = static_cast<GByte *>(pDstBuffer);
for (size_t i = 0; i < nEltsNonLast2Dims; ++i)
{
if (nDTSize == 1)
{
Transpose2D(
static_cast<uint8_t *>(pTempBufferForLast2DimsTranspose),
reinterpret_cast<const uint8_t *>(pabyDstBuffer),
count[nDims - 2], count[nDims - 1]);
}
else if (nDTSize == 2)
{
Transpose2D(
static_cast<uint16_t *>(pTempBufferForLast2DimsTranspose),
reinterpret_cast<const uint16_t *>(pabyDstBuffer),
count[nDims - 2], count[nDims - 1]);
}
else if (nDTSize == 4)
{
Transpose2D(
static_cast<uint32_t *>(pTempBufferForLast2DimsTranspose),
reinterpret_cast<const uint32_t *>(pabyDstBuffer),
count[nDims - 2], count[nDims - 1]);
}
else if (nDTSize == 8)
{
Transpose2D(
static_cast<uint64_t *>(pTempBufferForLast2DimsTranspose),
reinterpret_cast<const uint64_t *>(pabyDstBuffer),
count[nDims - 2], count[nDims - 1]);
}
else
{
CPLAssert(false);
}
GDALTranspose2D(pabyDstBuffer, eDT.GetNumericDataType(),
pTempBufferForLast2DimsTranspose,
eDT.GetNumericDataType(), count[nDims - 1],
count[nDims - 2]);
memcpy(pabyDstBuffer, pTempBufferForLast2DimsTranspose,
nDTSize * nEltsLast2Dims);
pabyDstBuffer += nDTSize * nEltsLast2Dims;
Expand Down

0 comments on commit dd8331c

Please sign in to comment.