Skip to content

Instantly share code, notes, and snippets.

@tclarke
Last active December 13, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tclarke/4987644 to your computer and use it in GitHub Desktop.
Save tclarke/4987644 to your computer and use it in GitHub Desktop.
Flip an Opticks RasterElement
DataAccessor acc = pRaster->getDataAccessor();
DataAccessor outacc = pOutRaster->getDataAccessor(writableDataRequest.release());
/** code to flip horizontally **/
for (int row = 0; row < numrows; ++row) {
VERIFY(acc.valid() && outacc.valid());
memcpy(outacc->getRow(), acc->getRow(), rowSizeInBytes);
// note: pixeldatatype is the C++ type for BSQ..for BIP, you'll need to use a struct..somthing like this for 10 bands 2-byte data
// struct {uint16_t data[10];}
// or just use a second loop with appropriate memcpy's
std::reverse((pixeldatatype*)outacc->getRow(), ((pixeldatatype*)outacc->getRow()) + pixelsPerRow);
acc->nextRow();
outacc->nextRow();
}
pOutRaster->update();
/** or, code to flip vertically **/
for (int row = 0; row < numrows; ++row) {
outacc->toPixel(numrows - row - 1, 0);
VERIFY(acc.valid() && outacc.valid());
memcpy(outacc->getRow(), acc->getRow(), rowSizeInBytes);
acc->nextRow();
}
pOutRaster->update();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment