1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0023425: diffimage generate OSD_Exception during execution

diffimage out-of-image access during border filter execution

Verify neighbor pixel position for out-of-image access
A list of referenced articles and books is added to Image_Diff.hxx file.

Adding test case bugs/vis/CR23425

Image_Diff - fix compilation error on x86_64 target using msvc
There no std::abs for ptrdiff_t in Microsoft STL implementation

Image_PixMap - fixed compilation on gcc 3

Removed extra newlines in TCL script
Image_Diff, move back extra modifications
This commit is contained in:
kgv 2012-09-27 12:43:54 +04:00
parent 3695b8c227
commit 185e6ec099
4 changed files with 55 additions and 7 deletions

View File

@ -63,6 +63,12 @@ inline void int2Pixel (const Standard_Size theValue,
namespace namespace
{ {
inline ptrdiff_t getAbs (const ptrdiff_t theValue)
{
return theValue >= 0 ? theValue : -theValue;
}
static const Standard_Size NEIGHBOR_PIXELS_NB = 8; static const Standard_Size NEIGHBOR_PIXELS_NB = 8;
struct struct
{ {
@ -83,6 +89,16 @@ namespace
return ::isBlack (theData.Value (theRowCenter + Standard_Size(row_inc), return ::isBlack (theData.Value (theRowCenter + Standard_Size(row_inc),
theColCenter + Standard_Size(col_inc))); theColCenter + Standard_Size(col_inc)));
} }
inline bool isValid (const Image_PixMapData<Image_ColorRGB>& theData,
const Standard_Size theRowCenter,
const Standard_Size theColCenter) const
{
const Standard_Size aRow = theRowCenter + Standard_Size(row_inc);
const Standard_Size aCol = theColCenter + Standard_Size(col_inc);
return aRow < theData.SizeX() // this unsigned math checks Standard_Size(-1) at-once
&& aCol < theData.SizeY();
}
} }
static const NEIGHBOR_PIXELS[NEIGHBOR_PIXELS_NB] = static const NEIGHBOR_PIXELS[NEIGHBOR_PIXELS_NB] =
{ {
@ -408,8 +424,8 @@ Standard_Integer Image_Diff::ignoreBorderEffect()
{ {
const Standard_Size aValue2 = myDiffPixels.Value (aPixelId2); const Standard_Size aValue2 = myDiffPixels.Value (aPixelId2);
int2Pixel (aValue2, aRow2, aCol2); int2Pixel (aValue2, aRow2, aCol2);
if (std::abs (ptrdiff_t (aCol1 - aCol2)) <= 1 && if (getAbs (ptrdiff_t (aCol1 - aCol2)) <= 1 &&
std::abs (ptrdiff_t (aRow1 - aRow2)) <= 1) getAbs (ptrdiff_t (aRow1 - aRow2)) <= 1)
{ {
// A neighbour is found. Create a new group and add both pixels. // A neighbour is found. Create a new group and add both pixels.
if (myGroupsOfDiffPixels.IsEmpty()) if (myGroupsOfDiffPixels.IsEmpty())
@ -463,7 +479,8 @@ Standard_Integer Image_Diff::ignoreBorderEffect()
// check all neighbour pixels on presence in the group // check all neighbour pixels on presence in the group
for (Standard_Size aNgbrIter = 0; aNgbrIter < NEIGHBOR_PIXELS_NB; ++aNgbrIter) for (Standard_Size aNgbrIter = 0; aNgbrIter < NEIGHBOR_PIXELS_NB; ++aNgbrIter)
{ {
if (aGroup->Contains (NEIGHBOR_PIXELS[aNgbrIter].pixel2Int (aRow1, aCol1))) if (NEIGHBOR_PIXELS[aNgbrIter].isValid (aDataRef, aRow1, aCol1)
&& aGroup->Contains (NEIGHBOR_PIXELS[aNgbrIter].pixel2Int (aRow1, aCol1)))
{ {
++aNeighboursNb; ++aNeighboursNb;
} }
@ -485,7 +502,8 @@ Standard_Integer Image_Diff::ignoreBorderEffect()
aNeighboursNb = 0; aNeighboursNb = 0;
for (Standard_Size aNgbrIter = 0; aNgbrIter < NEIGHBOR_PIXELS_NB; ++aNgbrIter) for (Standard_Size aNgbrIter = 0; aNgbrIter < NEIGHBOR_PIXELS_NB; ++aNgbrIter)
{ {
if (!NEIGHBOR_PIXELS[aNgbrIter].isBlack (aDataRef, aRow1, aCol1)) if ( NEIGHBOR_PIXELS[aNgbrIter].isValid (aDataRef, aRow1, aCol1)
&& !NEIGHBOR_PIXELS[aNgbrIter].isBlack (aDataRef, aRow1, aCol1))
{ {
++aNeighboursNb; ++aNeighboursNb;
} }

View File

@ -52,6 +52,13 @@
//! In this case the whole group of pixels is ignored (considered as same). //! In this case the whole group of pixels is ignored (considered as same).
//! Otherwise, the group of pixels may represent a geometrical curve in the viewer 3D //! Otherwise, the group of pixels may represent a geometrical curve in the viewer 3D
//! and should be considered as "different". //! and should be considered as "different".
//!
//! References:
//! 1. http://pdiff.sourceforge.net/ypg01.pdf
//! 2. http://pdiff.sourceforge.net/metric.html
//! 3. http://www.cs.ucf.edu/~sumant/publications/sig99.pdf
//! 4. http://www.worldscientific.com/worldscibooks/10.1142/2641#t=toc (there is a list of articles and books in PDF format)
class Image_Diff : public Standard_Transient class Image_Diff : public Standard_Transient
{ {

View File

@ -19,8 +19,12 @@
#include <Image_PixMap.hxx> #include <Image_PixMap.hxx>
#ifndef _MSC_VER #ifdef _MSC_VER
//
#elif (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 1)
#include <mm_malloc.h> #include <mm_malloc.h>
#else
extern "C" int posix_memalign (void** thePtr, size_t theAlign, size_t theBytesCount);
#endif #endif
template<typename TypePtr> template<typename TypePtr>
@ -29,8 +33,15 @@ inline TypePtr MemAllocAligned (const Standard_Size& theBytesCount,
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
return (TypePtr )_aligned_malloc (theBytesCount, theAlign); return (TypePtr )_aligned_malloc (theBytesCount, theAlign);
#else #elif (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 1)
return (TypePtr ) _mm_malloc (theBytesCount, theAlign); return (TypePtr ) _mm_malloc (theBytesCount, theAlign);
#else
void* aPtr;
if (posix_memalign (&aPtr, theAlign, theBytesCount))
{
aPtr = NULL;
}
return (TypePtr )aPtr;
#endif #endif
} }
@ -38,8 +49,10 @@ inline void MemFreeAligned (void* thePtrAligned)
{ {
#if defined(_MSC_VER) #if defined(_MSC_VER)
_aligned_free (thePtrAligned); _aligned_free (thePtrAligned);
#else #elif (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 1)
_mm_free (thePtrAligned); _mm_free (thePtrAligned);
#else
free (thePtrAligned);
#endif #endif
} }

10
tests/bugs/vis/CR23425 Executable file
View File

@ -0,0 +1,10 @@
puts "============"
puts "CR23425"
puts "============"
puts ""
#######################################################################
# diffimage generate OSD_Exception during execution
#######################################################################
diffimage [locate_data_file CR23425-B8_Linux.gif] [locate_data_file CR23425-B8_Win.gif] 0.01 0 1
diffimage [locate_data_file CR23425-B8_Win.gif] [locate_data_file CR23425-B8_Linux.gif] 0.01 0 1