Skip to content

Commit

Permalink
Support negative stride
Browse files Browse the repository at this point in the history
Add support for negative stride to FrameBuffer Slice.

Change data type of stride from size_t to ptrdiff_t.

Add support for negative stride in `copyIntoFrameBuffer` and `copyFromFrameBuffer`.

Add a new `testNegativeStride` test.

Fixes: #614
Signed-off-by: 胡玮文 <[email protected]>
  • Loading branch information
huww98 authored and 胡玮文 committed Jan 13, 2023
1 parent 436fcd2 commit 55bdfd1
Show file tree
Hide file tree
Showing 25 changed files with 326 additions and 153 deletions.
14 changes: 7 additions & 7 deletions src/lib/OpenEXR/ImfAcesFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ AcesOutputFile::~AcesOutputFile ()

void
AcesOutputFile::setFrameBuffer (
const Rgba* base, size_t xStride, size_t yStride)
const Rgba* base, ptrdiff_t xStride, ptrdiff_t yStride)
{
_data->rgbaFile->setFrameBuffer (base, xStride, yStride);
}
Expand Down Expand Up @@ -282,11 +282,11 @@ class AcesInputFile::Data

RgbaInputFile* rgbaFile;

Rgba* fbBase;
size_t fbXStride;
size_t fbYStride;
int minX;
int maxX;
Rgba* fbBase;
ptrdiff_t fbXStride;
ptrdiff_t fbYStride;
int minX;
int maxX;

bool mustConvertColor;
M44f fileToAces;
Expand Down Expand Up @@ -440,7 +440,7 @@ AcesInputFile::~AcesInputFile ()
}

void
AcesInputFile::setFrameBuffer (Rgba* base, size_t xStride, size_t yStride)
AcesInputFile::setFrameBuffer (Rgba* base, ptrdiff_t xStride, ptrdiff_t yStride)
{
_data->rgbaFile->setFrameBuffer (base, xStride, yStride);
_data->fbBase = base;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/OpenEXR/ImfAcesFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class IMF_EXPORT_TYPE AcesOutputFile
//------------------------------------------------

IMF_EXPORT
void setFrameBuffer (const Rgba* base, size_t xStride, size_t yStride);
void setFrameBuffer (const Rgba* base, ptrdiff_t xStride, ptrdiff_t yStride);

//-------------------------------------------------
// Write pixel data (see class Imf::OutputFile)
Expand Down Expand Up @@ -247,7 +247,7 @@ class IMF_EXPORT_TYPE AcesInputFile
//-----------------------------------------------------

IMF_EXPORT
void setFrameBuffer (Rgba* base, size_t xStride, size_t yStride);
void setFrameBuffer (Rgba* base, ptrdiff_t xStride, ptrdiff_t yStride);

//--------------------------------------------
// Read pixel data (see class Imf::InputFile)
Expand Down
10 changes: 5 additions & 5 deletions src/lib/OpenEXR/ImfCRgbaFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ ImfCloseOutputFile (ImfOutputFile* out)

int
ImfOutputSetFrameBuffer (
ImfOutputFile* out, const ImfRgba* base, size_t xStride, size_t yStride)
ImfOutputFile* out, const ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride)
{
try
{
Expand Down Expand Up @@ -1043,8 +1043,8 @@ int
ImfTiledOutputSetFrameBuffer (
ImfTiledOutputFile* out,
const ImfRgba* base,
size_t xStride,
size_t yStride)
ptrdiff_t xStride,
ptrdiff_t yStride)
{
try
{
Expand Down Expand Up @@ -1165,7 +1165,7 @@ ImfCloseInputFile (ImfInputFile* in)

int
ImfInputSetFrameBuffer (
ImfInputFile* in, ImfRgba* base, size_t xStride, size_t yStride)
ImfInputFile* in, ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride)
{
try
{
Expand Down Expand Up @@ -1245,7 +1245,7 @@ ImfCloseTiledInputFile (ImfTiledInputFile* in)

int
ImfTiledInputSetFrameBuffer (
ImfTiledInputFile* in, ImfRgba* base, size_t xStride, size_t yStride)
ImfTiledInputFile* in, ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride)
{
try
{
Expand Down
10 changes: 5 additions & 5 deletions src/lib/OpenEXR/ImfCRgbaFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int ImfCloseOutputFile (ImfOutputFile* out);

IMF_EXPORT
int ImfOutputSetFrameBuffer (
ImfOutputFile* out, const ImfRgba* base, size_t xStride, size_t yStride);
ImfOutputFile* out, const ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride);

IMF_EXPORT
int ImfOutputWritePixels (ImfOutputFile* out, int numScanLines);
Expand Down Expand Up @@ -335,8 +335,8 @@ IMF_EXPORT
int ImfTiledOutputSetFrameBuffer (
ImfTiledOutputFile* out,
const ImfRgba* base,
size_t xStride,
size_t yStride);
ptrdiff_t xStride,
ptrdiff_t yStride);

IMF_EXPORT
int ImfTiledOutputWriteTile (
Expand Down Expand Up @@ -385,7 +385,7 @@ int ImfCloseInputFile (ImfInputFile* in);

IMF_EXPORT
int ImfInputSetFrameBuffer (
ImfInputFile* in, ImfRgba* base, size_t xStride, size_t yStride);
ImfInputFile* in, ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride);

IMF_EXPORT
int ImfInputReadPixels (ImfInputFile* in, int scanLine1, int scanLine2);
Expand Down Expand Up @@ -414,7 +414,7 @@ int ImfCloseTiledInputFile (ImfTiledInputFile* in);

IMF_EXPORT
int ImfTiledInputSetFrameBuffer (
ImfTiledInputFile* in, ImfRgba* base, size_t xStride, size_t yStride);
ImfTiledInputFile* in, ImfRgba* base, ptrdiff_t xStride, ptrdiff_t yStride);

IMF_EXPORT
int
Expand Down
4 changes: 2 additions & 2 deletions src/lib/OpenEXR/ImfDeepFrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
DeepSlice::DeepSlice (
PixelType t,
char* b,
size_t xst,
size_t yst,
ptrdiff_t xst,
ptrdiff_t yst,
size_t spst,
int xsm,
int ysm,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/OpenEXR/ImfDeepFrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ struct IMF_EXPORT_TYPE DeepSlice : public Slice
DeepSlice (
PixelType type = HALF,
char* base = 0,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
size_t sampleStride = 0,
int xSampling = 1,
int ySampling = 1,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/OpenEXR/ImfDeepScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ struct InSliceInfo
PixelType typeInFile;
char* base;
char* pointerArrayBase;
size_t xPointerStride;
size_t yPointerStride;
ptrdiff_t xPointerStride;
ptrdiff_t yPointerStride;
size_t sampleStride;
int xSampling;
int ySampling;
Expand All @@ -75,8 +75,8 @@ struct InSliceInfo
PixelType typeInFrameBuffer = HALF,
char* base = NULL,
PixelType typeInFile = HALF,
size_t xPointerStride = 0,
size_t yPointerStride = 0,
ptrdiff_t xPointerStride = 0,
ptrdiff_t yPointerStride = 0,
size_t sampleStride = 0,
int xSampling = 1,
int ySampling = 1,
Expand All @@ -89,8 +89,8 @@ InSliceInfo::InSliceInfo (
PixelType tifb,
char* b,
PixelType tifl,
size_t xpst,
size_t ypst,
ptrdiff_t xpst,
ptrdiff_t ypst,
size_t spst,
int xsm,
int ysm,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/OpenEXR/ImfDeepTiledInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ struct TInSliceInfo
PixelType typeInFrameBuffer;
PixelType typeInFile;
char* pointerArrayBase;
size_t xStride;
size_t yStride;
ptrdiff_t xStride;
ptrdiff_t yStride;
ptrdiff_t sampleStride;
bool fill;
bool skip;
Expand All @@ -73,8 +73,8 @@ struct TInSliceInfo
PixelType typeInFrameBuffer = HALF,
char* base = NULL,
PixelType typeInFile = HALF,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
ptrdiff_t sampleStride = 0,
bool fill = false,
bool skip = false,
Expand All @@ -87,8 +87,8 @@ TInSliceInfo::TInSliceInfo (
PixelType tifb,
char* b,
PixelType tifl,
size_t xs,
size_t ys,
ptrdiff_t xs,
ptrdiff_t ys,
ptrdiff_t spst,
bool f,
bool s,
Expand Down
12 changes: 6 additions & 6 deletions src/lib/OpenEXR/ImfDeepTiledOutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ struct TOutSliceInfo
PixelType type;
const char* base;
size_t sampleStride;
size_t xStride;
size_t yStride;
ptrdiff_t xStride;
ptrdiff_t yStride;
bool zero;
int xTileCoords;
int yTileCoords;

TOutSliceInfo (
PixelType type = HALF,
size_t sampleStride = 0,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
bool zero = false,
int xTileCoords = 0,
int yTileCoords = 0);
Expand All @@ -90,8 +90,8 @@ struct TOutSliceInfo
TOutSliceInfo::TOutSliceInfo (
PixelType t,
size_t spst,
size_t xStride,
size_t yStride,
ptrdiff_t xStride,
ptrdiff_t yStride,
bool z,
int xtc,
int ytc)
Expand Down
14 changes: 7 additions & 7 deletions src/lib/OpenEXR/ImfFrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
Slice::Slice (
PixelType t,
char* b,
size_t xst,
size_t yst,
ptrdiff_t xst,
ptrdiff_t yst,
int xsm,
int ysm,
double fv,
Expand All @@ -49,8 +49,8 @@ Slice::Make (
const IMATH_NAMESPACE::V2i& origin,
int64_t w,
int64_t h,
size_t xStride,
size_t yStride,
ptrdiff_t xStride,
ptrdiff_t yStride,
int xSampling,
int ySampling,
double fillValue,
Expand All @@ -69,7 +69,7 @@ Slice::Make (
THROW (IEX_NAMESPACE::ArgExc, "Invalid pixel type.");
}
}
if (yStride == 0) yStride = static_cast<size_t> (w / xSampling) * xStride;
if (yStride == 0) yStride = (w / xSampling) * xStride;

// data window is an int, so force promote to higher type to avoid
// overflow for off y (degenerate size checks should be in
Expand Down Expand Up @@ -99,8 +99,8 @@ Slice::Make (
PixelType type,
const void* ptr,
const IMATH_NAMESPACE::Box2i& dataWindow,
size_t xStride,
size_t yStride,
ptrdiff_t xStride,
ptrdiff_t yStride,
int xSampling,
int ySampling,
double fillValue,
Expand Down
18 changes: 9 additions & 9 deletions src/lib/OpenEXR/ImfFrameBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ struct IMF_EXPORT_TYPE Slice
//
//---------------------------------------------------------------------

char* base;
size_t xStride;
size_t yStride;
char* base;
ptrdiff_t xStride;
ptrdiff_t yStride;

//--------------------------------------------
// Subsampling: pixel (x, y) is present in the
Expand Down Expand Up @@ -107,8 +107,8 @@ struct IMF_EXPORT_TYPE Slice
Slice (
PixelType type = HALF,
char* base = 0,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
int xSampling = 1,
int ySampling = 1,
double fillValue = 0.0,
Expand All @@ -127,8 +127,8 @@ struct IMF_EXPORT_TYPE Slice
const IMATH_NAMESPACE::V2i& origin,
int64_t w,
int64_t h,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
int xSampling = 1,
int ySampling = 1,
double fillValue = 0.0,
Expand All @@ -141,8 +141,8 @@ struct IMF_EXPORT_TYPE Slice
PixelType type,
const void* ptr,
const IMATH_NAMESPACE::Box2i& dataWindow,
size_t xStride = 0,
size_t yStride = 0,
ptrdiff_t xStride = 0,
ptrdiff_t yStride = 0,
int xSampling = 1,
int ySampling = 1,
double fillValue = 0.0,
Expand Down
Loading

0 comments on commit 55bdfd1

Please sign in to comment.