Skip to content

Commit

Permalink
Adding static block() method that performs a single block operation
Browse files Browse the repository at this point in the history
  • Loading branch information
asylvest committed Nov 27, 2018
1 parent d14c1a1 commit c194e53
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
34 changes: 33 additions & 1 deletion modules/c++/nitf/include/nitf/ImageBlocker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ class ImageBlocker
block(input, startRow, numRows, sizeof(DataT), output);
}

/*!
* \param input Input image of width 'numCols'
* \param numBytesPerPixel Number of bytes/pixel in 'input' and 'output'
* \param numCols Number of columns in 'input'
* \param numRowsPerBlock Number of rows per block
* \param numColsPerBlock Number of columns per block
* \param numValidRowsInBlock Number of valid rows in block (this is less
* than numRowsPerBlock for the bottom row of blocks if
* numRows % numRowsPerBlock != 0)
* \param numValidColsInBlock Number of valid columnss in block (this is
* less than numColsPerBlock for the rightmost column of blocks if
* numCols % numColsPerBlock != 0)
* \param[out] output Output image. Will contain this single block of
* 'input'. Must be at least numRowsPerBlock * numColsPerBlock pixels.
* If the number of valid rows/columns is less than the rows/columns in the
* block, these pixels will be zero-filled.
*/
static
void block(const void* input,
size_t numBytesPerPixel,
size_t numCols,
size_t numRowsPerBlock,
size_t numColsPerBlock,
size_t numValidRowsInBlock,
size_t numValidColsInBlock,
void* output);

//! \return The number of columns of blocks
size_t getNumColsOfBlocks() const
{
Expand Down Expand Up @@ -242,7 +269,12 @@ class ImageBlocker
size_t numValidRowsInBlock,
size_t numValidColsInBlock,
size_t numBytesPerPixel,
sys::byte* output) const;
sys::byte* output) const
{
block(input, numBytesPerPixel, mNumCols, mNumRowsPerBlock[seg],
mNumColsPerBlock, numValidRowsInBlock, numValidColsInBlock,
output);
}

void blockAcrossRow(size_t seg,
const sys::byte*& input,
Expand Down
41 changes: 22 additions & 19 deletions modules/c++/nitf/source/ImageBlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,51 +251,54 @@ size_t ImageBlocker::getNumBytesRequired(size_t startRow,
return numBytes;
}

void ImageBlocker::blockImpl(size_t seg,
const sys::byte* input,
size_t numValidRowsInBlock,
size_t numValidColsInBlock,
size_t numBytesPerPixel,
sys::byte* output) const
void ImageBlocker::block(const void* input,
size_t numBytesPerPixel,
size_t numCols,
size_t numRowsPerBlock,
size_t numColsPerBlock,
size_t numValidRowsInBlock,
size_t numValidColsInBlock,
void* output)
{
const size_t inStride = mNumCols * numBytesPerPixel;
const size_t inStride = numCols * numBytesPerPixel;
const size_t outNumValidBytes = numValidColsInBlock * numBytesPerPixel;
const sys::byte* inputPtr = static_cast<const sys::byte*>(input);
sys::byte* outputPtr = static_cast<sys::byte*>(output);

if (numValidColsInBlock == mNumColsPerBlock)
if (numValidColsInBlock == numColsPerBlock)
{
for (size_t row = 0;
row < numValidRowsInBlock;
++row, input += inStride, output += outNumValidBytes)
++row, inputPtr += inStride, outputPtr += outNumValidBytes)
{
::memcpy(output, input, outNumValidBytes);
::memcpy(outputPtr, inputPtr, outNumValidBytes);
}
}
else
{
// Have to deal with pad columns
const size_t outNumInvalidBytes =
(mNumColsPerBlock - numValidColsInBlock) * numBytesPerPixel;
(numColsPerBlock - numValidColsInBlock) * numBytesPerPixel;

for (size_t row = 0;
row < numValidRowsInBlock;
++row, input += inStride)
++row, inputPtr += inStride)
{
::memcpy(output, input, outNumValidBytes);
output += outNumValidBytes;
::memcpy(outputPtr, inputPtr, outNumValidBytes);
outputPtr += outNumValidBytes;

::memset(output, 0, outNumInvalidBytes);
output += outNumInvalidBytes;
::memset(outputPtr, 0, outNumInvalidBytes);
outputPtr += outNumInvalidBytes;
}
}

// Pad rows on the bottom of the block
const size_t numRowsPerBlock(mNumRowsPerBlock[seg]);
if (numValidRowsInBlock < numRowsPerBlock)
{
const size_t numPadRows = numRowsPerBlock - numValidRowsInBlock;

::memset(output, 0,
numPadRows * mNumColsPerBlock * numBytesPerPixel);
::memset(outputPtr, 0,
numPadRows * numColsPerBlock * numBytesPerPixel);
}
}

Expand Down

0 comments on commit c194e53

Please sign in to comment.