mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0023272: Image comparison algorithm
A new class Image_Diff for comparison of images and a draw-command "diffimage", which compares 2 images. Image_PixMap redesigned to provide interface for low-level image operations. New Image_AlienPixMap class now intended for Save/Load functionality. Aspect_PixMap class dropped. Xw_PixMap and WNT_PixMap classes now do not inherit from Aspect_PixMap and deprecated. ToPixMap methods now retrieve Image_PixMap as argument. Conflicts: src/ViewerTest/ViewerTest.cxx Remarks applied Fix compilation (correct merging error) Eliminated Aspect <-> Image cyclic dependency Fixed GIF dump in case of BGR32 image format
This commit is contained in:
@@ -30,7 +30,7 @@ class PixMap from Xw
|
||||
---Keywords: Bitmap, Pixmap, X11
|
||||
|
||||
inherits
|
||||
PixMap from Aspect
|
||||
Transient from Standard
|
||||
uses
|
||||
Handle from Aspect,
|
||||
Color from Quantity,
|
||||
@@ -97,4 +97,7 @@ is
|
||||
fields
|
||||
myPixmap : Handle from Aspect is protected;
|
||||
myWindow : Window from Xw;
|
||||
myWidth : Integer from Standard is protected;
|
||||
myHeight : Integer from Standard is protected;
|
||||
myDepth : Integer from Standard is protected;
|
||||
end PixMap;
|
||||
|
@@ -28,6 +28,9 @@
|
||||
|
||||
#define xTRACE 1
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -36,9 +39,6 @@
|
||||
#include <Xw_Window.hxx>
|
||||
#include <Xw_Extension.h>
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <Image_PixMap.hxx>
|
||||
|
||||
XW_STATUS Xw_save_xwd_image ( void*, void*, char* );
|
||||
XW_STATUS Xw_save_bmp_image ( void*, void*, char* );
|
||||
XW_STATUS Xw_save_gif_image ( void*, void*, char* );
|
||||
@@ -63,15 +63,15 @@ Standard_Integer Xw_PixMap::PreferedDepth(
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
Xw_PixMap::Xw_PixMap ( const Handle(Aspect_Window)& aWindow,
|
||||
const Standard_Integer aWidth,
|
||||
const Standard_Integer anHeight,
|
||||
const Standard_Integer aDepth ) :
|
||||
Aspect_PixMap(aWidth, anHeight, PreferedDepth(aWindow, aDepth))
|
||||
Xw_PixMap::Xw_PixMap (const Handle(Aspect_Window)& theWindow,
|
||||
const Standard_Integer theWidth,
|
||||
const Standard_Integer theHeight,
|
||||
const Standard_Integer theDepth)
|
||||
: myWindow (Handle(Xw_Window)::DownCast(theWindow)),
|
||||
myWidth (theWidth),
|
||||
myHeight (theHeight),
|
||||
myDepth (PreferedDepth (theWindow, theDepth))
|
||||
{
|
||||
|
||||
myWindow = Handle(Xw_Window)::DownCast(aWindow);
|
||||
|
||||
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) myWindow->ExtendedWindow();
|
||||
|
||||
Xw_print_error();
|
||||
@@ -99,46 +99,54 @@ Xw_PixMap::Destroy ()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Standard_Boolean Xw_PixMap::Dump (const Standard_CString theFilename,
|
||||
const Standard_Real theGammaValue) const
|
||||
Standard_Boolean Xw_PixMap::Dump (const Standard_CString theFileName,
|
||||
const Standard_Real theGammaValue) const
|
||||
{
|
||||
// the attributes
|
||||
XWindowAttributes winAttr;
|
||||
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) myWindow->ExtendedWindow();
|
||||
XGetWindowAttributes (_DISPLAY, _WINDOW, &winAttr);
|
||||
|
||||
// find the image
|
||||
XImage* pximage = XGetImage (_DISPLAY, myPixmap,
|
||||
0, 0, myWidth, myHeight,
|
||||
AllPlanes, ZPixmap);
|
||||
if (pximage == NULL)
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
if (winAttr.visual->c_class == TrueColor)
|
||||
{
|
||||
Standard_Byte* aDataPtr = (Standard_Byte* )pximage->data;
|
||||
Handle(Image_PixMap) anImagePixMap = new Image_PixMap (aDataPtr,
|
||||
pximage->width, pximage->height,
|
||||
pximage->bytes_per_line,
|
||||
pximage->bits_per_pixel,
|
||||
Standard_True);
|
||||
// destroy the image
|
||||
XDestroyImage (pximage);
|
||||
|
||||
// save the image
|
||||
return anImagePixMap->Dump (theFilename, theGammaValue);
|
||||
}
|
||||
else
|
||||
if (winAttr.visual->c_class != TrueColor)
|
||||
{
|
||||
std::cerr << "Visual Type not supported!";
|
||||
// destroy the image
|
||||
XDestroyImage (pximage);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
Image_AlienPixMap anImage;
|
||||
bool isBigEndian = Image_PixMap::IsBigEndianHost();
|
||||
const Standard_Size aSizeRowBytes = Standard_Size(winAttr.width) * 4;
|
||||
if (!anImage.InitTrash (isBigEndian ? Image_PixMap::ImgRGB32 : Image_PixMap::ImgBGR32,
|
||||
Standard_Size(winAttr.width), Standard_Size(winAttr.height), aSizeRowBytes))
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
anImage.SetTopDown (true);
|
||||
|
||||
XImage* anXImage = XCreateImage (_DISPLAY, winAttr.visual,
|
||||
32, ZPixmap, 0, (char* )anImage.ChangeData(), winAttr.width, winAttr.height, 32, int(aSizeRowBytes));
|
||||
anXImage->bitmap_bit_order = anXImage->byte_order = (isBigEndian ? MSBFirst : LSBFirst);
|
||||
if (XGetSubImage (_DISPLAY, myPixmap,
|
||||
0, 0, winAttr.width, winAttr.height,
|
||||
AllPlanes, ZPixmap, anXImage, 0, 0) == NULL)
|
||||
{
|
||||
anXImage->data = NULL;
|
||||
XDestroyImage (anXImage);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
// destroy the image
|
||||
anXImage->data = NULL;
|
||||
XDestroyImage (anXImage);
|
||||
|
||||
// save the image
|
||||
if (Abs (theGammaValue - 1.0) > 0.001)
|
||||
{
|
||||
anImage.AdjustGamma (theGammaValue);
|
||||
}
|
||||
|
||||
// save the image
|
||||
return anImage.Save (theFileName);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@@ -49,7 +49,7 @@ uses
|
||||
Handle from Aspect,
|
||||
FillMethod from Aspect,
|
||||
GradientFillMethod from Aspect,
|
||||
PixMap from Aspect,
|
||||
PixMap from Image,
|
||||
NameOfColor from Quantity,
|
||||
Parameter from Quantity,
|
||||
Ratio from Quantity,
|
||||
@@ -330,8 +330,8 @@ is
|
||||
-- or the area is out of the Window.
|
||||
raises WindowError from Aspect is virtual;
|
||||
|
||||
ToPixMap ( me )
|
||||
returns PixMap from Aspect
|
||||
ToPixMap ( me ; theImage : in out PixMap from Image )
|
||||
returns Boolean
|
||||
---Level : Public
|
||||
---Purpose : dump the full contents of the window to a pixmap.
|
||||
is virtual;
|
||||
|
@@ -77,7 +77,7 @@
|
||||
#include <Xw_Cextern.hxx>
|
||||
//}
|
||||
#include <Aspect_Convert.hxx>
|
||||
#include <Image_PixMap.hxx>
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
|
||||
#include <Xw_Extension.h>
|
||||
|
||||
@@ -862,15 +862,14 @@ Standard_Boolean Xw_Window::DumpArea (const Standard_CString theFilename,
|
||||
return Standard_Boolean(aStatus);
|
||||
}
|
||||
|
||||
Handle(Aspect_PixMap) Xw_Window::ToPixMap() const
|
||||
Standard_Boolean Xw_Window::ToPixMap (Image_PixMap& thePixMap) const
|
||||
{
|
||||
Handle(Image_PixMap) anImagePixMap;
|
||||
int aDummy, aWidth, aHeight;
|
||||
XW_WINDOWSTATE state = Xw_get_window_position (MyExtendedWindow,
|
||||
&aDummy, &aDummy, &aWidth, &aHeight);
|
||||
if (state == XW_WS_UNKNOWN)
|
||||
{
|
||||
return anImagePixMap;
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
XW_EXT_IMAGEDATA* pimage = NULL;
|
||||
@@ -895,22 +894,27 @@ Handle(Aspect_PixMap) Xw_Window::ToPixMap() const
|
||||
|
||||
if (pimage == NULL)
|
||||
{
|
||||
return anImagePixMap;
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
XImage* pximage = (pimage->zximage) ? pimage->zximage : pimage->pximage;
|
||||
XW_EXT_WINDOW* pwindow = (XW_EXT_WINDOW* )MyExtendedWindow;
|
||||
if (pwindow->pcolormap->visual->c_class == TrueColor)
|
||||
if (pwindow->pcolormap->visual->c_class != TrueColor)
|
||||
{
|
||||
Standard_Byte* aDataPtr = (Standard_Byte* )pximage->data;
|
||||
anImagePixMap = new Image_PixMap (aDataPtr,
|
||||
pximage->width, pximage->height,
|
||||
pximage->bytes_per_line,
|
||||
pximage->bits_per_pixel,
|
||||
Standard_True);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
const bool isBigEndian = (pximage->byte_order == MSBFirst);
|
||||
Image_PixMap::ImgFormat aFormat = (pximage->bits_per_pixel == 32)
|
||||
? (isBigEndian ? Image_PixMap::ImgRGB32 : Image_PixMap::ImgBGR32)
|
||||
: (isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR);
|
||||
Image_PixMap aWrapper;
|
||||
aWrapper.InitWrapper (aFormat, (Standard_Byte* )pximage->data, pximage->width, pximage->height, pximage->bytes_per_line);
|
||||
aWrapper.SetTopDown (true);
|
||||
|
||||
Standard_Boolean isSuccess = thePixMap.InitCopy (aWrapper);
|
||||
Xw_close_image (pimage);
|
||||
return anImagePixMap;
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
Standard_Boolean Xw_Window::Load (const Standard_CString aFilename) const {
|
||||
|
@@ -34,13 +34,14 @@
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <Image_AlienPixMap.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
#include <Xw_Extension.h>
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <Image_PixMap.hxx>
|
||||
|
||||
#ifdef XW_PROTOTYPE
|
||||
XW_STATUS Xw_save_image_adv (Display *aDisplay,Window aWindow,XWindowAttributes aWinAttr,XImage *aPximage,Colormap aColormap,int aNcolors,char *filename)
|
||||
#else
|
||||
@@ -54,22 +55,22 @@ int ncolors;
|
||||
char *filename;
|
||||
#endif /*XW_PROTOTYPE*/
|
||||
{
|
||||
if (aWinAttr.visual->c_class == TrueColor)
|
||||
{
|
||||
Standard_Byte* aDataPtr = (Standard_Byte* )aPximage->data;
|
||||
Handle(Image_PixMap) anImagePixMap = new Image_PixMap (aDataPtr,
|
||||
aPximage->width, aPximage->height,
|
||||
aPximage->bytes_per_line,
|
||||
aPximage->bits_per_pixel,
|
||||
Standard_True);
|
||||
// save the image
|
||||
return anImagePixMap->Dump (filename) ? XW_SUCCESS : XW_ERROR;
|
||||
}
|
||||
else
|
||||
if (aWinAttr.visual->c_class != TrueColor)
|
||||
{
|
||||
std::cerr << "Visual Type not supported!";
|
||||
return XW_SUCCESS;
|
||||
return XW_ERROR;
|
||||
}
|
||||
|
||||
const bool isBigEndian = (aPximage->byte_order == MSBFirst);
|
||||
Image_PixMap::ImgFormat aFormat = (aPximage->bits_per_pixel == 32)
|
||||
? (isBigEndian ? Image_PixMap::ImgRGB32 : Image_PixMap::ImgBGR32)
|
||||
: (isBigEndian ? Image_PixMap::ImgRGB : Image_PixMap::ImgBGR);
|
||||
Image_PixMap aWrapper;
|
||||
aWrapper.InitWrapper (aFormat, (Standard_Byte* )aPximage->data, aPximage->width, aPximage->height, aPximage->bytes_per_line);
|
||||
aWrapper.SetTopDown (true);
|
||||
|
||||
Image_AlienPixMap anAlienImage;
|
||||
return (anAlienImage.InitCopy (aWrapper) && anAlienImage.Save (filename)) ? XW_SUCCESS : XW_ERROR;
|
||||
}
|
||||
|
||||
#ifdef XW_PROTOTYPE
|
||||
|
Reference in New Issue
Block a user