1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

1
src/Image/EXTERNLIB Normal file
View File

@@ -0,0 +1 @@
CSF_FreeImagePlus

9
src/Image/FILES Executable file
View File

@@ -0,0 +1,9 @@
Image_GImage.gxx
Image_GPixelField.gxx
Image_GPixelField.lxx
Image_PixelAddress.cxx
Image_PixelAddress.hxx
Image.edl
Image_CMPLRS.edl
Image_CRawBufferData.hxx
Image_HPrivateImage.hxx

193
src/Image/Image.cdl Executable file
View File

@@ -0,0 +1,193 @@
-- File: Image.cdl
-- Created: Tue Jul 27 18:51:28 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
package Image
---Purpose: The package Image provide PseudoColorImage and ColorImage
-- definition and a set of key functions from the fields
-- of image.
uses
TCollection,
TColStd,
Aspect,
Quantity,
gp,
MMgt
is
------------------------
---Category: The classes
------------------------
deferred class Image;
class PixelInterpolation;
class AveragePixelInterpolation;
class BalancedPixelInterpolation;
class PlanarPixelInterpolation;
class BilinearPixelInterpolation;
---Purpose : Several methods to compute Pixel on non-integer Image
-- coordinate.
private generic class GPixelField;
---Purpose : Generic Image definition .
deferred generic class GImage, PixelRow, PixelField;
---Purpose : Generic Image definition .
deferred class DColorImage
instantiates GImage from Image (ColorPixel from Aspect);
---Purpose : instantiates GImage for ColorImage definition .
deferred class DIndexedImage
instantiates GImage from Image (IndexPixel from Aspect);
---Purpose : instantiates GImage for PseudoColorImage definition .
class PseudoColorImage;
---Purpose : PseudoColorImage definition .
class ColorImage;
---Purpose : ColorImage definition .
class Convertor;
---Purpose: converts aPseudoColorImage to a ColorImage and vice-versa.
class ColorPixelMapHasher instantiates
MapHasher from TCollection( ColorPixel from Aspect );
class ColorPixelDataMap instantiates
DataMap from TCollection ( ColorPixel from Aspect,
Integer from Standard,
ColorPixelMapHasher from Image ) ;
class IndexPixelMapHasher instantiates
MapHasher from TCollection( IndexPixel from Aspect );
class LookupTable instantiates
DataMap from TCollection( IndexPixel from Aspect,
IndexPixel from Aspect,
IndexPixelMapHasher );
class PixMap;
---Purpose: Aspect_PixMap implementation.
-----------------------------
---Category: Imported types:
-----------------------------
imported PixelAddress;
imported HPrivateImage;
imported CRawBufferData;
-----------------------------
---Category: The Enumerations
-----------------------------
enumeration FlipType is FT_HORIZONTAL,
FT_VERTICAL,
FT_MAINDIAGONAL,
FT_ANTIDIAGONAL,
FT_CENTER,
FT_90,
FT_180,
FT_270
end FlipType ;
---Purpose: Type of orientation in a symmetry.
-- - FT_HORIZONTAL : symmetry with respect to an horizontal axis.
-- - FT_VERTICAL : symmetry with respect to a vertical axis.
-- - FT_MAINDIAGONAL : symmetry with respect to a
-- diagonal oriented at 45 degrees.
-- - FT_ANTIDIAGONAL : symmetry with respect to a
-- diagonal oriented at -45 degrees.
-- - FT_CENTER :
-- - FT_90 : rotation of 90 degrees.
-- - FT_180 : rotation of 180 degrees.
-- - FT_270 : rotation of -90 degrees.
enumeration DitheringMethod is DM_NearestColor,
DM_ErrorDiffusion
end DitheringMethod ;
---Purpose: Type of dithering method.
enumeration TypeOfImage is TOI_ColorImage,
TOI_PseudoColorImage,
TOI_RGB,
TOI_RGBA,
TOI_RGBF,
TOI_RGBAF,
TOI_FLOAT
end TypeOfImage ;
Zoom ( aImage : mutable Image from Image ;
aInterpolation : PixelInterpolation from Image;
aCoefX,aCoefY : in Real from Standard ) ;
---Purpose : Zoom an Image with a specific PixelInterpolation method.
Zoom ( aImage : mutable Image from Image ;
aCoefX,aCoefY : in Real from Standard ) ;
---Purpose : Zoom an Image with the default PixelInterpolation method.
Rotate ( aImage : mutable Image from Image ;
aInterpolation : PixelInterpolation from Image;
aAngle : in PlaneAngle from Quantity ) ;
---Purpose : Rotate an Image with a specific PixelInterpolation method.
Rotate ( aImage : mutable Image from Image ;
aAngle : in PlaneAngle from Quantity ) ;
---Purpose : Rotate an Image with the default PixelInterpolation method.
Translate( aImage : mutable Image from Image ;
aInterpolation : PixelInterpolation from Image;
DX, DY : in Real from Standard ) ;
---Purpose : Translate an Image with a specific PixelInterpolation
-- method.
Translate( aImage : mutable Image from Image ;
DX, DY : in Real from Standard ) ;
---Purpose : Translate an Image with the default PixelInterpolation
-- method.
Affine( aImage : mutable Image from Image ;
aInterpolation : PixelInterpolation from Image;
Trsf : in GTrsf2d from gp ) ;
---Purpose : General transformation of an Image with a specific
-- PixelInterpolation method.
-- Warning:
-- Raises an exception if the matrix of the transformation
-- is not inversible.
Affine( aImage : mutable Image from Image ;
Trsf : in GTrsf2d from gp ) ;
---Purpose : General transformation of an Image with the default
-- PixelInterpolation method.
-- Warning:
-- Raises an exception if the matrix of the transformation
-- is not inversible.
Affine( aImage : mutable Image from Image ;
aInterpolation : PixelInterpolation from Image;
Trsf : in Trsf from gp ) ;
---Purpose : General transformation of an Image with a specific
-- PixelInterpolation method.
-- Warning:
-- Raises an exception if the matrix of the transformation
-- is not inversible.
Affine( aImage : mutable Image from Image ;
Trsf : in Trsf from gp ) ;
---Purpose : General transformation of an Image with the default
-- PixelInterpolation method.
-- Warning:
-- Raises an exception if the matrix of the transformation
-- is not inversible.
end Image;

167
src/Image/Image.cxx Executable file
View File

@@ -0,0 +1,167 @@
// Modified 27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
//
#include <Image_DIndexedImage.hxx>
#include <Image_DColorImage.hxx>
#include <Image_PixelInterpolation.hxx>
#include <Image.ixx>
#define LOPTIM
#ifndef LOPTIM
static Image_PixelInterpolation DefaultPixelInterpolation ;
#else
static Image_PixelInterpolation& _DefaultPixelInterpolation() {
static Image_PixelInterpolation DefaultPixelInterpolation ;
return DefaultPixelInterpolation;
}
#define DefaultPixelInterpolation _DefaultPixelInterpolation()
#endif // LOPTIM
//------------------------------- Image::Zoom --------------------------------
void Image::Zoom( const Handle(Image_Image)& aImage,
const Standard_Real CoefX, const Standard_Real CoefY )
{ if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Zoom(
DefaultPixelInterpolation, CoefX, CoefY ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Zoom(
DefaultPixelInterpolation, CoefX, CoefY ) ;
}
}
void Image::Zoom( const Handle(Image_Image)& aImage,
const Image_PixelInterpolation& aInterpolation,
const Standard_Real CoefX, const Standard_Real CoefY )
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Zoom(
aInterpolation, CoefX, CoefY ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Zoom(
aInterpolation, CoefX, CoefY ) ;
}
}
//------------------------------- Image::Translate ---------------------------
void Image::Translate( const Handle(Image_Image)& aImage,
const Standard_Real DX, const Standard_Real DY )
{ if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Translate(
DefaultPixelInterpolation, DX, DY ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Translate(
DefaultPixelInterpolation, DX, DY ) ;
}
}
void Image::Translate( const Handle(Image_Image)& aImage,
const Image_PixelInterpolation& aInterpolation,
const Standard_Real DX, const Standard_Real DY )
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Translate(
aInterpolation, DX, DY ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Translate(
aInterpolation, DX, DY ) ;
}
}
//------------------------------- Image::Rotate ------------------------------
void Image::Rotate( const Handle(Image_Image)& aImage,
const Quantity_PlaneAngle aAngle )
{ if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Rotate(
DefaultPixelInterpolation, aAngle ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Rotate(
DefaultPixelInterpolation, aAngle ) ;
}
}
void Image::Rotate( const Handle(Image_Image)& aImage,
const Image_PixelInterpolation& aInterpolation,
const Quantity_PlaneAngle aAngle )
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Rotate(
aInterpolation,aAngle ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Rotate(
aInterpolation,aAngle ) ;
}
}
//------------------------------- Image::Affine ------------------------------
void Image::Affine( const Handle(Image_Image)& aImage,
const gp_GTrsf2d& aTrsf )
{ if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Affine(
DefaultPixelInterpolation, aTrsf ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Affine(
DefaultPixelInterpolation, aTrsf ) ;
}
}
void Image::Affine( const Handle(Image_Image)& aImage,
const Image_PixelInterpolation& aInterpolation,
const gp_GTrsf2d& aTrsf )
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Affine(
aInterpolation,aTrsf ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Affine(
aInterpolation,aTrsf ) ;
}
}
void Image::Affine( const Handle(Image_Image)& aImage,
const gp_Trsf& aTrsf )
{ if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Affine(
DefaultPixelInterpolation, aTrsf ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Affine(
DefaultPixelInterpolation, aTrsf ) ;
}
}
void Image::Affine( const Handle(Image_Image)& aImage,
const Image_PixelInterpolation& aInterpolation,
const gp_Trsf& aTrsf )
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
(Handle(Image_DIndexedImage)::DownCast( aImage ))->Affine(
aInterpolation,aTrsf ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
(Handle(Image_DColorImage)::DownCast( aImage ))->Affine(
aInterpolation,aTrsf ) ;
}
}

10
src/Image/Image.edl Executable file
View File

@@ -0,0 +1,10 @@
--
-- File: Image.edl
-- Author: Jean GAUTIER
-- History: Thu Oct 3 13:25:43 1996 Jean GAUTIER Creation
-- Copyright: Matra Datavision 1996
--
@ifnotdefined ( %Image_EDL) then
@set %Image_EDL = "";
@endif;

View File

@@ -0,0 +1,76 @@
-- File: Image_AveragePixelInterpolation.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class AveragePixelInterpolation from Image inherits PixelInterpolation from Image
---Purpose: The class AveragePixelInterpolation is used to compute a SubPixel
-- value on non integer Image coordinate
-- AveragePixelInterpolation redefined a new method to compute a
-- SubPixel value .
-- SubPixel value is the average of the three nearest Pixel in
-- the Image .
-- If V1, V2, V3, V4 is the value of the three nearest Image
-- Pixel V = ( V1+V2+V3 ) / 3 is the Image SubPixel value
-- on non integer coordinate (FX,FY)
uses
Image from Image,
Pixel from Aspect,
ColorPixel from Aspect,
IndexPixel from Aspect,
DColorImage from Image,
DIndexedImage from Image
is
Create returns AveragePixelInterpolation from Image ;
---Level: Public
---Purpose: Create a AveragePixelInterpolation object.
Interpolate( me ; aImage : Image from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard is redefined ;
---Level: Public
---Purpose: Redefined the method to compute SubPixel's value
-- on non integer Image coordinate.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's use
-- check if the SubPixel coordinate FX,FY is outside of image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DColorImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out ColorPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DColorImage and ColorPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's use
-- check if the SubPixel coordinate FX,FY is outside of image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DIndexedImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out IndexPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DIndexedImage and IndexPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's use
-- check if the SubPixel coordinate X,Y is outside of image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
end AveragePixelInterpolation from Image;

View File

@@ -0,0 +1,333 @@
#include <Image_AveragePixelInterpolation.ixx>
Image_AveragePixelInterpolation::Image_AveragePixelInterpolation() {}
Standard_Boolean Image_AveragePixelInterpolation::Interpolate(
const Handle(Image_Image)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
return Interpolate( Handle(Image_DIndexedImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_IndexPixel &)aPixel ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
return Interpolate( Handle(Image_DColorImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_ColorPixel &)aPixel ) ;
}
else {
return Image_PixelInterpolation::Interpolate( aImage,
FX,FY,LowX,LowY,UpX,UpY,aPixel ) ;
}
}
Standard_Boolean Image_AveragePixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ Standard_Integer NX[3], NY[3] ;
Standard_Real NZ[3] ;
Standard_Real R,G,B ;
static Quantity_Color Col ;
Standard_Boolean SamePixels = 1 ;
if ( FX < 0. ) NX[0] = Standard_Integer(FX-0.5) ;
else NX[0] = Standard_Integer(FX+0.5) ;
if ( FY < 0. ) NY[0] = Standard_Integer(FY-0.5) ;
else NY[0] = Standard_Integer(FY+0.5) ;
if ( NX[0] < LowX || NX[0] > UpX ||
NY[0] < LowY || NY[0] > UpY ) {
return Standard_False ;
}
else if ( ( FX-NX[0] ) == 0. && ( FY-NY[0] ) == 0. ) {
aImage->Pixel( NX[0], NY[0], aPixel );
return Standard_True ;
}
else {
if ( ( FX-NX[0] ) >= 0. ) { NX[1] = NX[0]+1 ; NY[1] = NY[0] ; }
else { NX[1] = NX[0]-1 ; NY[1] = NY[0] ; }
if ( ( FY-NY[0] ) >= 0. ) { NX[2] = NX[0] ; NY[2] = NY[0]+1 ; }
else { NX[2] = NX[0] ; NY[2] = NY[0]-1 ; }
if ( NX[1] < LowX || NX[1] > UpX || NY[1] < LowY || NY[1] > UpY ||
NX[2] < LowX || NX[2] > UpX || NY[2] < LowY || NY[2] > UpY ) {
aImage->Pixel( NX[0], NY[0], aPixel );
}
else {
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Red() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Red() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Red() ;
if ( NZ[0] == NZ[1] && NZ[0] == NZ[2] ) {
R = NZ[0] ;
}
else {
R = ( NZ[0] + NZ[1] + NZ[2] ) / 3. ;
SamePixels = 0 ;
}
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Green() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Green() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Green() ;
if ( NZ[0] == NZ[1] && NZ[0] == NZ[2] ) {
G = NZ[0] ;
}
else {
G = ( NZ[0] + NZ[1] + NZ[2] ) / 3. ;
SamePixels = 0 ;
}
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Blue() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Blue() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Blue() ;
if ( NZ[0] == NZ[1] && NZ[0] == NZ[2] ) {
B = NZ[0] ;
}
else {
B = ( NZ[0] + NZ[1] + NZ[2] ) / 3. ;
SamePixels = 0 ;
}
if ( SamePixels ) {
aPixel.SetValue( aImage->Pixel( NX[0],NY[0] ).Value() );
}
else {
Col.SetValues( R, G, B, Quantity_TOC_RGB ) ;
aPixel.SetValue( Col ) ;
}
}
return Standard_True ;
}
}
Standard_Boolean Image_AveragePixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ Standard_Integer NX[3], NY[3] ;
Standard_Real NZ[3] ;
if ( FX < 0. ) NX[0] = Standard_Integer(FX-0.5) ;
else NX[0] = Standard_Integer(FX+0.5) ;
if ( FY < 0. ) NY[0] = Standard_Integer(FY-0.5) ;
else NY[0] = Standard_Integer(FY+0.5) ;
if ( NX[0] < LowX || NX[0] > UpX ||
NY[0] < LowY || NY[0] > UpY ) {
return Standard_False ;
}
else if ( ( FX-NX[0] ) == 0. && ( FY-NY[0] ) == 0. ) {
aImage->Pixel( NX[0], NY[0], aPixel );
return Standard_True ;
}
else {
if ( ( FX-NX[0] ) >= 0. ) { NX[1] = NX[0]+1 ; NY[1] = NY[0] ; }
else { NX[1] = NX[0]-1 ; NY[1] = NY[0] ; }
if ( ( FY-NY[0] ) >= 0. ) { NX[2] = NX[0] ; NY[2] = NY[0]+1 ; }
else { NX[2] = NX[0] ; NY[2] = NY[0]-1 ; }
if ( NX[1] < LowX || NX[1] > UpX || NY[1] < LowY || NY[1] > UpY ||
NX[2] < LowX || NX[2] > UpX || NY[2] < LowY || NY[2] > UpY ) {
aImage->Pixel( NX[0], NY[0], aPixel );
}
else {
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value() ;
if ( NZ[0] == NZ[1] && NZ[0] == NZ[2] ) {
aPixel.SetValue( Standard_Integer( NZ[0] ) ) ;
}
else {
aPixel.SetValue( Standard_Integer((NZ[0]+NZ[1]+NZ[2])/3.) ) ;
}
}
return Standard_True ;
}
}
//##############################################################################
#ifdef OLD
Standard_Boolean Image_AveragePixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X,Y ;
Standard_Real SD, SR, SG, SB, R, G, B ;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
SR = SG = SB = SD = 0. ;
// (0,0)
X = NX ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
aImage->Pixel( X,Y ).Value().Values( R, G, B, Quantity_TOC_RGB ) ;
SR += R ; SG += G ; SB += B ; SD += 1. ;
}
// (1,0)
X = NX+1 ; Y = NY ;
if ( !( X < LowX || X > UpX || Y < LowY || Y > UpY ) ) {
aImage->Pixel( X,Y ).Value().Values( R, G, B, Quantity_TOC_RGB ) ;
SR += R ; SG += G ; SB += B ; SD += 1. ;
}
// (0,1)
X = NX ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
aImage->Pixel( X,Y ).Value().Values( R, G, B, Quantity_TOC_RGB ) ;
SR += R ; SG += G ; SB += B ; SD += 1. ;
}
// (1,1)
X = NX+1 ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
aImage->Pixel( X,Y ).Value().Values( R, G, B, Quantity_TOC_RGB ) ;
SR += R ; SG += G ; SB += B ; SD += 1. ;
}
// Result
if ( SD != 0. ) {
SR /= SD ; SG /= SD ; SB /= SD ;
aPixel.SetValue( Quantity_Color( SR, SG, SB, Quantity_TOC_RGB ) ) ;
return Standard_True ;
}
else {
return Standard_False ;
}
}
}
Standard_Boolean Image_AveragePixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X,Y ;
Standard_Real SD, SP ;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
SP = SD = 0. ;
// (0,0)
X = NX ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
SP += aImage->Pixel( X,Y ).Value() ; SD += 1. ;
}
// (1,0)
X = NX+1 ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
SP += aImage->Pixel( X,Y ).Value() ; SD += 1. ;
}
// (0,1)
X = NX ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
SP += aImage->Pixel( X,Y ).Value() ; SD += 1. ;
}
// (1,1)
X = NX+1 ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
SP += aImage->Pixel( X,Y ).Value() ; SD += 1. ;
}
// Result
if ( SD != 0. ) {
SP /= SD ;
aPixel.SetValue( Standard_Integer(SP+0.5) ) ;
return Standard_True ;
}
else {
return Standard_False ;
}
}
}
#endif

View File

@@ -0,0 +1,88 @@
-- File: Image_BalancedPixelInterpolation.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class BalancedPixelInterpolation from Image inherits PixelInterpolation from Image
---Purpose: The class BalancedPixelInterpolation is used to compute a
-- SubPixel value on non integer Image coordinate
-- BalancedPixelInterpolation redefined a new method to compute
-- a SubPixel value .
-- The value is the proportional to the distance of the
-- four nearest Image Pixel.
-- A B
-- SubPixel
-- C D
-- If VA, VB, VC, VD is the value of the four nearest Image
-- Pixel, if ColDelta and RowDelta is the distance from non
-- integer coordinate (FX,FY) to the upper left nearest Image
-- Pixel , then :
-- ColDelta = FX - XA ;
-- RowDelta = FY - YA ;
-- CAB = ColDelta*( VB - VA ) + VA
-- CCD = ColDelta*( VD - VC ) + VD
-- V = RowDelta*( CCD - CAB ) + CAB
-- is the Image SubPixel value on non integer
-- coordinate (FX,FY).
uses
Image from Image,
Pixel from Aspect,
ColorPixel from Aspect,
IndexPixel from Aspect,
DColorImage from Image,
DIndexedImage from Image
is
Create returns BalancedPixelInterpolation from Image ;
---Level: Public
---Purpose: Create a BalancedPixelInterpolation object.
Interpolate( me ; aImage : Image from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard is redefined ;
---Level: Public
---Purpose: Redefined the method to compute SubPixel's value
-- on non integer Image coordinate.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DColorImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out ColorPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DColorImage and ColorPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DIndexedImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out IndexPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DIndexedImage and IndexPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate X,Y is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
end BalancedPixelInterpolation from Image;

View File

@@ -0,0 +1,604 @@
#include <Image_BalancedPixelInterpolation.ixx>
Image_BalancedPixelInterpolation::Image_BalancedPixelInterpolation() {}
Standard_Boolean Image_BalancedPixelInterpolation::Interpolate(
const Handle(Image_Image)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
return Interpolate( Handle(Image_DIndexedImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_IndexPixel &)aPixel ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
return Interpolate( Handle(Image_DColorImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_ColorPixel &)aPixel ) ;
}
else {
return Image_PixelInterpolation::Interpolate( aImage,
FX,FY,LowX,LowY,UpX,UpY,aPixel ) ;
}
}
Standard_Boolean Image_BalancedPixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X[4],Y[4], i ;
Standard_Real R[4], G[4], B[4];
Standard_Boolean DoV[4], SamePixels = 1 ;
Standard_Real SR, SG, SB;
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) DoV[i] = 0 ;
// (0,0)
i = 0; X[i] = NX ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
else {
return Standard_False ;
}
// (1,0)
i++ ; X[i] = NX+1 ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
else {
R[i] = R[0] ; G[i] = G[0] ; B[i] = B[0] ;
}
// (0,1)
i++ ; X[i] = NX ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
else {
R[i] = R[0] ; G[i] = G[0] ; B[i] = B[0] ;
}
// (1,1)
i++ ; X[i] = NX+1 ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
else {
R[i] = R[0] ; G[i] = G[0] ; B[i] = B[0] ;
}
// Pixel A [0] Pixel B [1]
// Pixel X
// Pixel C [2] Pixel D [3]
Standard_Boolean First ;
Standard_Integer Ref ;
Standard_Real ColDelta,RowDelta, ContribFromAB, ContribFromCD ;
ColDelta = FX - X[0] ;
RowDelta = FY - Y[0] ;
// Red Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( R[i] != R[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SR = R[Ref] ;
}
else {
ContribFromAB = ColDelta * ( R[1] - R[0] ) + R[0] ;
ContribFromCD = ColDelta * ( R[3] - R[2] ) + R[2] ;
SR = ContribFromAB +
( ContribFromCD - ContribFromAB ) * RowDelta ;
}
// Green Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( G[i] != G[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SG = G[Ref] ;
}
else {
ContribFromAB = ColDelta * ( G[1] - G[0] ) + G[0] ;
ContribFromCD = ColDelta * ( G[3] - G[2] ) + G[2] ;
SG = ContribFromAB +
( ContribFromCD - ContribFromAB ) * RowDelta ;
}
// Blue Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( B[i] != B[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SB = B[Ref] ;
}
else {
ContribFromAB = ColDelta * ( B[1] - B[0] ) + B[0] ;
ContribFromCD = ColDelta * ( B[3] - B[2] ) + B[2] ;
SB = ContribFromAB +
( ContribFromCD - ContribFromAB ) * RowDelta ;
}
// Result
aPixel.SetValue( Quantity_Color( SR, SG, SB, Quantity_TOC_RGB ) ) ;
return Standard_True ;
}
}
Standard_Boolean Image_BalancedPixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X[4],Y[4] ;
Standard_Integer V[4], i ;
Standard_Boolean DoV[4], SamePixels = 1 ;
Standard_Real SP ;
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) DoV[i] = 0 ;
i = 0;
// (0,0)
i = 0; X[i] = NX ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
else {
return Standard_False ;
}
// (1,0)
i++ ; X[i] = NX+1 ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
else {
V[i] = V[0] ;
}
// (0,1)
i++ ; X[i] = NX ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
else {
V[i] = V[0] ;
}
// (1,1)
i++ ; X[i] = NX+1 ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
else {
V[i] = V[0] ;
}
// Pixel A [0] Pixel B [1]
// Pixel X
// Pixel C [2] Pixel D [3]
Standard_Boolean First ;
Standard_Integer Ref ;
Standard_Real ColDelta,RowDelta, ContribFromAB, ContribFromCD ;
for ( i = 0 , First = 1, Ref = -1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( V[i] != V[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
aPixel.SetValue( V[Ref] ) ;
return Standard_True ;
}
else {
ColDelta = FX - X[0] ;
RowDelta = FY - Y[0] ;
ContribFromAB = ColDelta * ( V[1] - V[0] ) + V[0] ;
ContribFromCD = ColDelta * ( V[3] - V[2] ) + V[2] ;
SP = ContribFromAB +
( ContribFromCD - ContribFromAB ) * RowDelta ;
aPixel.SetValue( Standard_Integer(SP+0.5) ) ;
return Standard_True ;
}
}
}
#ifdef OLD
Standard_Boolean Image_BalancedPixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X[4],Y[4], i ;
Standard_Real R[4], G[4], B[4];
Standard_Boolean DoV[4], SamePixels = 1 ;
Standard_Real D[4], SD, SR, SG, SB;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
for ( i = 0 ; i < 4 ; i++ ) DoV[i] = 0 ;
// (0,0)
i = 0; X[i] = NX ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
// (1,0)
i++ ; X[i] = NX+1 ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
// (0,1)
i++ ; X[i] = NX ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
// (1,1)
i++ ; X[i] = NX+1 ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
aImage->Pixel(X[i],Y[i]).Value().
Values( R[i],G[i],B[i],Quantity_TOC_RGB);
DoV[i] = 1 ;
}
Standard_Boolean First, DIsComputed ;
Standard_Integer Ref ;
SR = SG = SB = SD = 0. ;
DIsComputed = 0 ;
// Red Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( R[i] != R[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SR = R[Ref] ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
D[i] = Sqrt( (X[i]-FX)*(X[i]-FX) + (Y[i]-FY)*(Y[i]-FY) );
SD += D[i] ;
SR += D[i] * R[i] ;
}
}
DIsComputed = 1 ;
if ( SD != 0. ) SR /= SD ;
else {
return Standard_False ;
}
}
// Green Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( G[i] != G[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SG = G[Ref] ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( !DIsComputed ) {
D[i] = Sqrt( (X[i]-FX)*(X[i]-FX) + (Y[i]-FY)*(Y[i]-FY) );
SD += D[i] ;
}
SG += D[i] * G[i] ;
}
}
DIsComputed = 1 ;
if ( SD != 0. ) SG /= SD ;
else {
return Standard_False ;
}
}
// Blue Componant
for ( i = 0 , First = 1, Ref = -1, SamePixels = 1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( B[i] != B[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
SB = B[Ref] ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( !DIsComputed ) {
D[i] = Sqrt( (X[i]-FX)*(X[i]-FX) + (Y[i]-FY)*(Y[i]-FY) );
SD += D[i] ;
}
SB += D[i] * B[i] ;
}
}
DIsComputed = 1 ;
if ( SD != 0. ) SB /= SD ;
else {
return Standard_False ;
}
}
// Result
aPixel.SetValue( Quantity_Color( SR, SG, SB, Quantity_TOC_RGB ) ) ;
return Standard_True ;
}
}
Standard_Boolean Image_BalancedPixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X[4],Y[4] ;
Standard_Integer V[4], i ;
Standard_Boolean DoV[4], SamePixels = 1 ;
Standard_Real D, SD, SP ;
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
SP = SD = 0. ;
for ( i = 0 ; i < 4 ; i++ ) DoV[i] = 0 ;
i = 0;
// (0,0)
i = 0; X[i] = NX ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
// (1,0)
i++ ; X[i] = NX+1 ; Y[i] = NY ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
// (0,1)
i++ ; X[i] = NX ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
// (1,1)
i++ ; X[i] = NX+1 ; Y[i] = NY+1 ;
if ( !( X[i] < LowX || X[i] > UpX ||
Y[i] < LowY || Y[i] > UpY ) ) {
V[i] = aImage->Pixel( X[i],Y[i] ).Value() ; DoV[i] = 1 ;
}
Standard_Boolean First ;
Standard_Integer Ref ;
for ( i = 0 , First = 1, Ref = -1 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
if ( First ) { Ref = i ; First = 0 ; }
else if ( V[i] != V[Ref] ) { SamePixels = 0 ; break ;}
}
}
if ( Ref == -1 ) {
return Standard_False ;
}
else if ( SamePixels ) {
aPixel.SetValue( V[Ref] ) ;
return Standard_True ;
}
else {
for ( i = 0 ; i < 4 ; i++ ) {
if ( DoV[i] ) {
D = Sqrt( (X[i]-FX)*(X[i]-FX) + (Y[i]-FY)*(Y[i]-FY) );
SP += D * V[i] ; SD += D ;
}
}
// Result
if ( SD != 0. ) {
SP /= SD ;
aPixel.SetValue( Standard_Integer(SP+0.5) ) ;
return Standard_True ;
}
else {
return Standard_False ;
}
}
}
}
#endif

View File

@@ -0,0 +1,85 @@
-- File: Image_BilinearPixelInterpolation.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class BilinearPixelInterpolation from Image inherits PixelInterpolation from Image
---Purpose: The class BilinearPixelInterpolation is used to compute a
-- SubPixel value on non integer Image coordinate
-- BilinearPixelInterpolation redefined a new method to compute
-- a SubPixel value .
-- The value is the bilinear interpolation of the
-- four nearest Image Pixel.
-- If V1, V2, V3, V4 is the value and (X1,Y1) , (X2,Y2),
-- (X3,Y3), (X4,Y4) the coordinates of the four nearest
-- Image Pixel then first we solve :
-- V1 = a*X1 + b*Y1 + c*X1*Y1 + d
-- V2 = a*X2 + b*Y2 + c*X2*Y2 + d
-- V3 = a*X3 + b*Y3 + c*X3*Y3 + d
-- V1 = a*X4 + b*Y4 + c*X4*Y4 + d
--
-- and V = a*FX + b*XY + c*FX*FY + d
-- is the Image SubPixel value on non integer
-- coordinate (FX,FY).
uses
Image from Image,
Pixel from Aspect,
ColorPixel from Aspect,
IndexPixel from Aspect,
DColorImage from Image,
DIndexedImage from Image
is
Create returns BilinearPixelInterpolation from Image ;
---Level: Public
---Purpose: Create a BilinearPixelInterpolation object.
Interpolate( me ; aImage : Image from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard is redefined ;
---Level: Public
---Purpose: Redefined the method to compute SubPixel's value
-- on non integer Image coordinate.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DColorImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out ColorPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DColorImage and ColorPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DIndexedImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out IndexPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DIndexedImage and IndexPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate X,Y is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
end BilinearPixelInterpolation from Image;

View File

@@ -0,0 +1,300 @@
/***********************************************************************
FONCTION :
----------
Fichier Image_BilinearPixelInterpolation.cxx :
HISTORIQUE DES MODIFICATIONS :
--------------------------------
-------- : BBL ; Creation
31-12-97 : CAL ; Retrait de la dependance avec math. Calcul developpe.
************************************************************************/
/*----------------------------------------------------------------------*/
/*
* Constantes
*/
#ifdef TRACE
static int Verbose = 0 ;
#endif
/*----------------------------------------------------------------------*/
/*
* Includes
*/
#include <Aspect.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <Image_BilinearPixelInterpolation.ixx>
Image_BilinearPixelInterpolation::Image_BilinearPixelInterpolation() {}
Standard_Boolean Image_BilinearPixelInterpolation::Interpolate(
const Handle(Image_Image)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
return Interpolate( Handle(Image_DIndexedImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_IndexPixel &)aPixel ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
return Interpolate( Handle(Image_DColorImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_ColorPixel &)aPixel ) ;
}
else {
return Image_PixelInterpolation::Interpolate( aImage,
FX,FY,LowX,LowY,UpX,UpY,aPixel ) ;
}
}
static Standard_Real DoInterpolation( const TColStd_Array1OfReal& NXF,
const TColStd_Array1OfReal& NYF,
const TColStd_Array1OfReal& NZF,
const Standard_Real FX,
const Standard_Real FY )
{ Standard_Real Result ;
if ( NZF(1) == NZF(2) && NZF(2) == NZF(3) ) {
Result = NZF(1) ;
}
else {
Standard_Integer i;
Standard_Boolean BResult;
TColStd_Array1OfReal V(1,4), R(1,4) ;
TColStd_Array2OfReal M( 1, 4, 1, 4 ) ;
TColStd_Array2OfReal MINV( 1, 4, 1, 4 ) ;
for ( i = 1 ; i <= 4 ; i++ ) {
M(i,1) = NXF(i) ; M( i,2 ) = NYF(i) ; M( i,3 ) = NXF(i)*NYF(i) ;
M(i,4) = 1. ;
V(i) = NZF(i) ;
}
BResult = Aspect::Inverse (M, MINV);
// R = M * V ;
R (1) = M (1, 1) * V (1) + M (1, 2) * V (2)
+ M (1, 3) * V (3) + M (1, 4) * V (4);
R (2) = M (2, 1) * V (1) + M (2, 2) * V (2)
+ M (2, 3) * V (3) + M (2, 4) * V (4);
R (3) = M (3, 1) * V (1) + M (3, 2) * V (2)
+ M (3, 3) * V (3) + M (3, 4) * V (4);
R (4) = M (4, 1) * V (1) + M (4, 2) * V (2)
+ M (4, 3) * V (3) + M (4, 4) * V (4);
Result = R(1)*FX + R(2)*FY + R(3)*FX*FY + R(4) ;
}
return Result ;
}
Standard_Boolean Image_BilinearPixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X,Y ;
TColStd_Array1OfReal NXF(1,4), NYF(1,4), NZFR(1,4), NZFG(1,4), NZFB(1,4);
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
// (0,0)
X = NX ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(1) = Standard_Real( X ) ;
NYF(1) = Standard_Real( Y ) ;
NZFR(1) = aImage->Pixel( X, Y ).Value().Red() ;
NZFG(1) = aImage->Pixel( X, Y ).Value().Green() ;
NZFB(1) = aImage->Pixel( X, Y ).Value().Blue() ;
}
else {
return Standard_False ;
}
// (1,0)
X = NX+1 ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(2) = Standard_Real( X ) ;
NYF(2) = Standard_Real( Y ) ;
NZFR(2) = aImage->Pixel( X, Y ).Value().Red() ;
NZFG(2) = aImage->Pixel( X, Y ).Value().Green() ;
NZFB(2) = aImage->Pixel( X, Y ).Value().Blue() ;
}
else {
return Standard_False ;
}
// (0,1)
X = NX ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(3) = Standard_Real( X ) ;
NYF(3) = Standard_Real( Y ) ;
NZFR(3) = aImage->Pixel( X, Y ).Value().Red() ;
NZFG(3) = aImage->Pixel( X, Y ).Value().Green() ;
NZFB(3) = aImage->Pixel( X, Y ).Value().Blue() ;
}
else {
return Standard_False ;
}
// (1,1)
X = NX+1 ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(4) = Standard_Real( X ) ;
NYF(4) = Standard_Real( Y ) ;
NZFR(4) = aImage->Pixel( X, Y ).Value().Red() ;
NZFG(4) = aImage->Pixel( X, Y ).Value().Green() ;
NZFB(4) = aImage->Pixel( X, Y ).Value().Blue() ;
}
else {
return Standard_False ;
}
// Result
Quantity_Color Res;
Standard_Real R,G,B ;
R = DoInterpolation(NXF,NYF,NZFR,FX,FY );
G = DoInterpolation(NXF,NYF,NZFG,FX,FY );
B = DoInterpolation(NXF,NYF,NZFB,FX,FY );
// Some times we get number like -0.3412341234e-14
#ifdef TRACE
if ( Verbose )
if ( R < 0. || R > 1. || G < 0. || G > 1. || B < 0. || B > 1. ) {
cout << "\tError in BilinearPixelInterpolation " <<
R << " " << G << " " << B << endl << flush ;
}
#endif
if ( R < 0. && R > -0.000001 ) R = 0. ;
if ( G < 0. && G > -0.000001 ) G = 0. ;
if ( B < 0. && B > -0.000001 ) B = 0. ;
Res.SetValues( R,G,B, Quantity_TOC_RGB ) ;
aPixel.SetValue( Res );
return Standard_True ;
}
}
Standard_Boolean Image_BilinearPixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel) const
{ Standard_Integer NX = Standard_Integer(FX) ;
Standard_Integer NY = Standard_Integer(FY) ;
Standard_Integer X,Y ;
TColStd_Array1OfReal NXF(1,4), NYF(1,4), NZF(1,4);
if ( NX < ( LowX-1 ) || NX > UpX ||
NY < ( LowY-1 ) || NY > UpY ) {
return Standard_False ;
}
else {
if ( FX < 0. ) NX-- ;
if ( FY < 0. ) NY-- ;
// (0,0)
X = NX ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(1) = Standard_Real( X ) ;
NYF(1) = Standard_Real( Y ) ;
NZF(1) = Standard_Real( aImage->Pixel( X, Y ).Value() ) ;
}
else {
return Standard_False ;
}
// (1,0)
X = NX+1 ; Y = NY ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(2) = Standard_Real( X ) ;
NYF(2) = Standard_Real( Y ) ;
NZF(2) = Standard_Real( aImage->Pixel( X, Y ).Value() ) ;
}
else {
return Standard_False ;
}
// (0,1)
X = NX ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(3) = Standard_Real( X ) ;
NYF(3) = Standard_Real( Y ) ;
NZF(3) = Standard_Real( aImage->Pixel( X, Y ).Value() ) ;
}
else {
return Standard_False ;
}
// (1,1)
X = NX+1 ; Y = NY+1 ;
if ( !( X < LowX || X > UpX ||
Y < LowY || Y > UpY ) ) {
NXF(4) = Standard_Real( X ) ;
NYF(4) = Standard_Real( Y ) ;
NZF(4) = Standard_Real( aImage->Pixel( X, Y ).Value() ) ;
}
else {
return Standard_False ;
}
// Result
aPixel.SetValue( Standard_Integer(DoInterpolation(NXF,NYF,NZF,FX,FY )));
return Standard_True ;
}
}

26
src/Image/Image_CMPLRS.edl Executable file
View File

@@ -0,0 +1,26 @@
--
-- File: Image_CMPLRS.edl
-- Author: Jean GAUTIER
-- History: Thu Oct 3 13:12:20 1996 Jean GAUTIER Creation
-- Copyright: Matra Datavision 1996
--
@ifnotdefined ( %Image_CMPLRS_EDL) then
@set %Image_CMPLRS_EDL = "";
--@uses "Image.edl";
@if ( %Station == "sun" ) then
@endif;
@if ( %Station == "sil" ) then
@endif;
@if ( %Station == "ao1" ) then
@endif;
@if ( %Station == "hp" ) then
@endif;
--@string %CMPLRS_CXX_Options = %CMPLRS_CXX_Options " -DSTANDARD_TYPE=TYPE";
@endif;

View File

@@ -0,0 +1,13 @@
#ifndef _Image_CRawBufferData_HeaderFile
#define _Image_CRawBufferData_HeaderFile
#include <InterfaceGraphic_RawBufferData.hxx>
typedef TRawBufferData Image_CRawBufferData;
#if defined(__cplusplus) || defined(c_plusplus)
#include <Standard_Type.hxx>
const Handle(Standard_Type)& TYPE(Image_CRawBufferData);
#endif
#endif /*_Image_CRawBufferData_HeaderFile*/

74
src/Image/Image_ColorImage.cdl Executable file
View File

@@ -0,0 +1,74 @@
-- File: Image_ColorImage.cdl
-- Created: Tue Jul 27 18:53:48 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class ColorImage from Image inherits DColorImage from Image
---Purpose : A ColorImage is a DColorImage with specific method.
-- Each Pixel in the Image ,as a ColorPixel
-- from Aspect, can be use directly as a Color.
-- A ColorImage is also called a "true color image".
uses
Color from Quantity,
ColorPixel from Aspect,
GenericColorMap from Aspect,
Image from Image,
ColorPixelMapHasher from Image,
TypeOfImage from Image
is
Create( x,y,dx,dy : in Integer from Standard )
returns mutable ColorImage from Image;
---Level: Public
---Purpose : Create a ColorImage object.
-- The default Background Pixel is set to Black .
-- All the Image is initialised with Background Pixel
Create( x,y,dx,dy : in Integer from Standard;
BackPixel : ColorPixel from Aspect )
returns mutable ColorImage from Image;
---Level: Public
---Purpose : Create a ColorImage object and set the Background Pixel.
-- All the Image is initialised with Background Pixel
ChooseColorMap( me : immutable ; aSize : Integer from Standard )
returns GenericColorMap from Aspect ;
---Purpose : Create a GenericColorMap object with the best ColorMap
-- of a particular size to use in Dithering method .
-- The best ColorMap is defined to be the one that contains as
-- many as possible of the most frequently used colors.
Type ( me : immutable ) returns TypeOfImage from Image ;
---Level: Public
---Purpose : Returns the Image Type.
PixelColor( me : immutable ; X,Y : in Integer from Standard )
returns Color from Quantity ;
---C++: return const &
---Purpose : Returns the Pixel Color .
Dup ( me : immutable ) returns mutable Image from Image ;
---Purpose : Duplicates a Image.
-- ******************* Redefined method ***************************
-- ShallowCopy (me) returns mutable like me ;
---Level: Public
-- ---Purpose: Returns a copy at the first level of <me>. The objects
-- -- referenced are not copied. Entities copied by
-- -- ShallowCopy are equal.
-- ---C++: function call
-- DeepCopy (me) returns mutable like me ;
---Level: Public
-- ---Purpose: Returns a deep copy of <me>. The objects
-- -- referenced are copied. Entities copied by
-- -- DeepCopy are similar (c.f the Method IsSimilar).
-- ---C++: function call
end ColorImage from Image;

145
src/Image/Image_ColorImage.cxx Executable file
View File

@@ -0,0 +1,145 @@
#include <Image_ColorImage.ixx>
#include <Image_ColorPixelDataMap.hxx>
#include <Image_DataMapIteratorOfColorPixelDataMap.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <Quantity_Array1OfColor.hxx>
#include <Aspect_ColorMapEntry.hxx>
#ifdef TRACE
static int Verbose = 0 ;
#endif
Image_ColorImage::Image_ColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy)
: Image_DColorImage( x, y, dx, dy,
Aspect_ColorPixel( Quantity_Color(0.,0.,0.,Quantity_TOC_RGB)) )
{
}
Image_ColorImage::Image_ColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy,
const Aspect_ColorPixel& BackPixel )
: Image_DColorImage( x, y, dx, dy, BackPixel )
{
}
Handle(Image_Image) Image_ColorImage::Dup() const {
Handle(Image_ColorImage) aImage =
new Image_ColorImage( LowerX(), LowerY(), Width(), Height(),
BackgroundPixel() ) ;
aImage->InternalDup( this ) ;
return aImage ;
}
Image_TypeOfImage Image_ColorImage::Type () const {
return Image_TOI_ColorImage ;
}
const Quantity_Color& Image_ColorImage::PixelColor(
const Standard_Integer x,
const Standard_Integer y ) const
{ return( Pixel( x, y ).Value() ) ;
}
Handle(Aspect_GenericColorMap) Image_ColorImage::ChooseColorMap(
const Standard_Integer aSize ) const
{ Handle(Aspect_GenericColorMap) TheColorMap = new Aspect_GenericColorMap() ;
Standard_Integer x,y,i,bblcount, UpX, UpY ;
Image_ColorPixelDataMap DataMap( 4000 ) ; // a Big DataMap !!!
Aspect_ColorPixel pix ;
UpX = UpperX() ;
UpY = UpperY() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
pix = Pixel(x,y) ;
if ( !DataMap.IsBound( pix ) ) DataMap.Bind( pix, 1 ) ;
else DataMap( pix )++ ;
}
}
#ifdef TRACE
Standard_Integer CheckSum = 0 ;
if ( Verbose )
cout << "ChooseColorMap : Extent " << DataMap.Extent() << endl << flush ;
#endif
Image_DataMapIteratorOfColorPixelDataMap It( DataMap ) ;
TColStd_Array1OfInteger Tab( 1, aSize ) ; Tab.Init(0) ;
Quantity_Array1OfColor Col( 1, aSize) ; Col.Init(
Quantity_Color( 0.,0.,0., Quantity_TOC_RGB ) ) ;
Standard_Integer MaxOfTab = 0 ;
Standard_Integer MinOfTab = 0 ;
while ( It.More() ) {
bblcount = It.Value() ;
#ifdef TRACE
if ( Verbose ) {
cout << CheckSum << "," << It.Key() << "," << bblcount << endl ;
CheckSum += bblcount ;
}
#endif
if ( bblcount > MinOfTab ) {
for ( i = 1 ; i <= aSize ; i++ ) {
if ( Tab( i ) == MinOfTab ) {
Tab( i ) = bblcount ;
Col( i ) = It.Key().Value() ;
break ;
}
}
for ( i = 1 ; i <= aSize ; i++ ) {
MaxOfTab = Max( MaxOfTab, Tab( i ) ) ;
MinOfTab = Min( MinOfTab, Tab( i ) ) ;
}
}
It.Next() ;
}
Aspect_ColorMapEntry aEntry ;
for ( i = 1, bblcount = 0 ; i <= aSize ; i++ ) {
if ( Tab( i ) != 0 ) {
aEntry.SetValue( bblcount++, Col( i ) ) ;
TheColorMap->AddEntry( aEntry ) ;
}
}
cout << flush ;
return TheColorMap ;
}
#ifdef OLD
Handle(Standard_Transient) Image_ColorImage::ShallowCopy() const {
return DeepCopy() ;
}
Handle(Standard_Transient) Image_ColorImage::DeepCopy() const {
return Dup() ;
}
#endif

121
src/Image/Image_Convertor.cdl Executable file
View File

@@ -0,0 +1,121 @@
-- File: Image_Convertor.cdl
-- Created: Wed Jul 28 16:08:03 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class Convertor from Image
---Purpose: This class is used to convert :
-- a PseudoColorImage to a ColorImage
-- a ColorImage to a PseudoColorImage
-- a PseudoColorImage to a PseudoColorImage with a
-- different ColorMap.
--
-- To convert a PseudoColoImage to a ColorImage we use
-- the PseudoColoImage ColorMap to compute the Color of each
-- Image Pixel ( Lookup operation ) , the resulting image
-- look similar as the original image.
--
-- To convert a ColorImage to a PseudoColorImage or
-- a PseudoColorImage to another PseudoColorImage we use
-- Dithering.
--
-- A dither operation is an inverse lookup operation.For
-- example if we want to dither a ColorImage to a
-- PseudoColorImage, for each Pixel in the ColorImage we search
-- in the PseudoColorImage ColorMap the Entry with the nearest
-- Color, then we write the ColorMap Entry Index in to the
-- PseudoColorImage. The result is a PseudoColorImage that when
-- it is displayed using its own ColorMap it will look as much
-- like the original ColorImage as possible.
--
-- This class provides 2 Dithering method.
--
-- DM_NearestColor : this dithering method is the simplest
-- one ,it just finds the nearest entry in the ColorMap.
-- This algorithm provide no provision for eliminating unwanted
-- contours in the dithered image.This algorithm is much
-- faster on ColorRamp and ColorCube than on Generic
-- ColorMap.Indeed on ColorRamp and ColorCube ColorMap the
-- ColorMap Entry Index can be computed by using the ColorMap
-- BasePixel and ColorDimension.
--
-- DM_ErrorDiffusion: In this method the difference ( error )
-- between the original and the dithered image is distribued
-- to the oginal image pixels immediatly to the right of and
-- below the last pixel processed. The ErrorDiffusion method
-- uses a "floyd-steinberg" error-distribution kernel.This
-- algorithm is fairly time-consuming, but can greatly reduce
-- contouring in the dithered image.
--
uses
ColorMap from Aspect,
GenericColorMap from Aspect,
ColorCubeColorMap from Aspect,
ColorRampColorMap from Aspect,
PseudoColorImage from Image,
ColorImage from Image,
DitheringMethod from Image
is
Create returns Convertor from Image;
---Level: Public
---Purpose: Create a Convertor object with the default DitheringMethod
-- ( DM_NearestColor ).
SetDitheringMethod( me : in out ;
aMethod : in DitheringMethod from Image );
---Level: Public
---Purpose: Set DitheringMethod.
Convert (me : in ;aColorImage: ColorImage from Image;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image;
---Level: Public
---Purpose: Dither a ColorImage into a PseudoColorImage using the
-- ColorMap parameter.
Convert (me : in ; aPseudoColorImage: PseudoColorImage from Image;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image;
---Level: Public
---Purpose: Dither a PseudoColorImage into a PseudoColorImage using the
-- ColorMap parameter.
Convert (me : in; aPseudoColorImage: PseudoColorImage from Image)
returns mutable ColorImage from Image;
---Level: Public
---Purpose: Lookup a PseudoColorImage into a ColorImage using the
-- PseudoColorImage ColorMap.
-- ******************* Private Method *******************
NearestDithering(me : in;
aColorImage: ColorImage from Image ;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image is private ;
NearestDithering(me : in;
aPseudoColorImage : PseudoColorImage from Image ;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image is private ;
ErrorDiffusionDithering(me : in;
aColorImage : ColorImage from Image ;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image is private ;
ErrorDiffusionDithering(me : in;
aPseudoColorImage : PseudoColorImage from Image ;
aColorMap : ColorMap from Aspect)
returns mutable PseudoColorImage from Image is private ;
fields
myDitheringMethod : DitheringMethod from Image ;
end Convertor;

384
src/Image/Image_Convertor.cxx Executable file
View File

@@ -0,0 +1,384 @@
#include <Image_Convertor.ixx>
#include <Image_PseudoColorImage.hxx>
#include <Image_ColorImage.hxx>
#include <Image_LookupTable.hxx>
#include <Aspect_ColorMapEntry.hxx>
#ifdef TRACE
static int Verbose = 0 ;
#endif
Image_Convertor::Image_Convertor() { myDitheringMethod = Image_DM_NearestColor;}
void Image_Convertor::SetDitheringMethod( const Image_DitheringMethod Method )
{ myDitheringMethod = Method ; }
Handle(Image_PseudoColorImage) Image_Convertor::Convert(
const Handle(Image_ColorImage)& aImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
if ( myDitheringMethod == Image_DM_NearestColor ) {
ret_image = NearestDithering( aImage, aColorMap ) ;
}
else if ( myDitheringMethod == Image_DM_ErrorDiffusion ) {
ret_image = ErrorDiffusionDithering( aImage, aColorMap ) ;
}
return ret_image ;
}
Handle(Image_PseudoColorImage) Image_Convertor::Convert(
const Handle(Image_PseudoColorImage)& aImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
if ( myDitheringMethod == Image_DM_NearestColor ) {
ret_image = NearestDithering( aImage, aColorMap ) ;
}
else if ( myDitheringMethod == Image_DM_ErrorDiffusion ) {
ret_image = ErrorDiffusionDithering( aImage, aColorMap ) ;
}
return ret_image ;
}
Handle(Image_ColorImage) Image_Convertor::Convert(
const Handle(Image_PseudoColorImage)& aImage ) const
{ Handle(Image_ColorImage) ret_image = NULL ;
Standard_Integer x, y, val, lastval ;
Quantity_Color aColor ;
Standard_Integer UpX = aImage->UpperX() ;
Standard_Integer UpY = aImage->UpperY() ;
ret_image = new Image_ColorImage( aImage->LowerX(), aImage->LowerY(),
aImage->Width() , aImage->Height() ) ;
lastval = aImage->Pixel(aImage->LowerX(), aImage->LowerY() ).Value() ;
aColor = aImage->ColorMap()->FindEntry(lastval).Color() ;
for ( y = aImage->LowerY() ; y <= UpY ; y++ ) {
for ( x = aImage->LowerX() ; x <= UpX ; x++ ) {
val = aImage->Pixel(x,y).Value() ;
if ( lastval != val ) {
lastval = val ;
aColor = aImage->ColorMap()->FindEntry(lastval).Color() ;
}
ret_image->SetPixel( x, y, aColor );
}
}
return( ret_image ) ;
}
Handle(Image_PseudoColorImage) Image_Convertor::NearestDithering(
const Handle(Image_ColorImage)& aImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
Standard_Integer x, y, index ;
Quantity_Color lastval, val ;
Standard_Integer UpX = aImage->UpperX() ;
Standard_Integer UpY = aImage->UpperY() ;
ret_image = new Image_PseudoColorImage( aImage->LowerX(), aImage->LowerY(),
aImage->Width() , aImage->Height(),
aColorMap );
lastval = aImage->PixelColor(aImage->LowerX(),aImage->LowerY()) ;
index = aColorMap->NearestEntry( lastval ).Index() ;
for ( y = aImage->LowerY() ; y <= UpY ; y++ ) {
for ( x = aImage->LowerX() ; x <= UpX ; x++ ) {
val = aImage->PixelColor(x,y) ;
if ( !( val == lastval ) ) {
lastval = val ;
index = aColorMap->NearestEntry( lastval ).Index() ;
}
ret_image->SetPixel( x, y, index ) ;
}
}
return( ret_image ) ;
}
Handle(Image_PseudoColorImage) Image_Convertor::NearestDithering(
const Handle(Image_PseudoColorImage)& aImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
Standard_Integer x,y, val, lastval, index ;
Standard_Integer UpX = aImage->UpperX() ;
Standard_Integer UpY = aImage->UpperY() ;
Image_LookupTable ColorMapLookup ;
Aspect_ColorMapEntry aEntry ;
Standard_Integer i, size ;
for ( i = 1 , size = aImage->ColorMap()->Size() ; i <= size ; i++ ) {
aEntry = aImage->ColorMap()->Entry(i) ;
index = aColorMap->NearestEntry( aEntry.Color() ).Index() ;
ColorMapLookup.Bind( aEntry.Index(), index ) ;
}
ret_image = new Image_PseudoColorImage( aImage->LowerX(), aImage->LowerY(),
aImage->Width() , aImage->Height(),
aColorMap );
lastval = aImage->Pixel( aImage->LowerX(), aImage->LowerY() ).Value() ;
index = ColorMapLookup.Find( lastval ).Value() ;
for ( y = aImage->LowerY() ; y <= UpY ; y++ ) {
for ( x = aImage->LowerX() ; x <= UpX ; x++ ) {
val = aImage->Pixel(x,y).Value() ;
if ( val != lastval ) {
lastval = val ;
index = ColorMapLookup.Find( lastval ).Value() ;
}
ret_image->SetPixel( x, y, index ) ;
}
}
return( ret_image ) ;
}
static Standard_Boolean ManageLastKernelError = 1 ;
static struct {
Standard_Real v ;
Standard_Integer dx, dy ;
} Kernel[4] = { { 7./16., 1, 0 },
{ 3./16., -1, 1 },
{ 5./16., 0, 1 },
{ 1./16., 1, 1 } } ;
Handle(Image_PseudoColorImage) Image_Convertor::ErrorDiffusionDithering(
const Handle(Image_PseudoColorImage)& RefImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
Standard_Integer UpX = RefImage->UpperX() ;
Standard_Integer UpY = RefImage->UpperY() ;
Standard_Integer LowX = RefImage->LowerX() ;
Standard_Integer LowY = RefImage->LowerY() ;
Standard_Integer x,y, index, i, nx,ny ;
Standard_Integer val, lastval ;
Standard_Integer Error, ErrorDiff, pix, npix, MinIndex, MaxIndex ;
Aspect_IndexPixel aPixel ;
Image_LookupTable ColorMapLookup ;
Aspect_ColorMapEntry aEntry ;
Standard_Integer size ;
MaxIndex = MinIndex = RefImage->ColorMap()->Entry(1).Index() ;
for ( i = 1 , size = RefImage->ColorMap()->Size() ; i <= size ; i++ ) {
aEntry = RefImage->ColorMap()->Entry(i) ;
MinIndex = Min( aEntry.Index(), MinIndex ) ;
MaxIndex = Max( aEntry.Index(), MaxIndex ) ;
index = aColorMap->NearestEntry( aEntry.Color() ).Index() ;
ColorMapLookup.Bind( aEntry.Index(), index ) ;
}
Handle(Image_PseudoColorImage) aImage =
Handle(Image_PseudoColorImage)::DownCast( RefImage->Dup() ) ;
ret_image = new Image_PseudoColorImage( aImage->LowerX(), aImage->LowerY(),
aImage->Width() , aImage->Height(),
aColorMap );
lastval = aImage->Pixel( aImage->LowerX(), aImage->LowerY() ).Value() ;
index = ColorMapLookup.Find( lastval ).Value() ;
for ( y = aImage->LowerY() ; y <= UpY ; y++ ) {
for ( x = aImage->LowerX() ; x <= UpX ; x++ ) {
val = aImage->Pixel(x,y).Value() ;
if ( ! ( val == lastval ) ) {
lastval = val ;
index = ColorMapLookup.Find( lastval ).Value() ;
}
ErrorDiff = Error = val - index ;
#ifdef TRACE
if ( Verbose > 3 )
cout << "ErrorDiffusion : " << Error << endl << flush ;
#endif
if ( Error != 0 ) {
for ( i = 0 ; i < 4 ; i++ ) {
nx = x+Kernel[i].dx ;
ny = y+Kernel[i].dy ;
if ( nx >= LowX && nx <= UpX &&
ny >= LowY && ny <= UpY ) {
aImage->Pixel( nx, ny, aPixel ) ;
pix = aPixel.Value() ;
if ( ManageLastKernelError && i == 3 ) {
// Last one
npix = pix + ErrorDiff ;
}
else {
npix = pix + Standard_Integer( Kernel[i].v * Error ) ;
}
// ErrorDiffusion may produce Pixel out of ColorMap
// Clamp value to min max of ColorMap
npix = Max( npix, MinIndex ) ;
npix = Min( npix, MaxIndex ) ;
ErrorDiff -= ( npix - pix ) ;
#ifdef TRACE
if ( Verbose > 2 && i == 3 ) {
cout << "ErrorDiffusion Last Error: " <<
(ErrorDiff-( Kernel[i].v*Error)) <<endl<<flush ;
}
#endif
aPixel.SetValue( npix ) ;
aImage->SetPixel( nx, ny, aPixel ) ;
}
}
}
ret_image->SetPixel( x, y, index ) ;
}
}
return( ret_image ) ;
}
Handle(Image_PseudoColorImage) Image_Convertor::ErrorDiffusionDithering(
const Handle(Image_ColorImage)& RefImage,
const Handle(Aspect_ColorMap)& aColorMap ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
Standard_Integer UpX = RefImage->UpperX() ;
Standard_Integer UpY = RefImage->UpperY() ;
Standard_Integer LowX = RefImage->LowerX() ;
Standard_Integer LowY = RefImage->LowerY() ;
Standard_Integer x,y, index, i, nx,ny ;
Quantity_Color val, lastval, NewCol ;
Aspect_ColorMapEntry aEntry ;
Aspect_ColorPixel aPixel ;
Standard_Real RedError, GreenError, BlueError, r,g,b,cr,cg,cb ;
Standard_Real RedDiffError, GreenDiffError, BlueDiffError ;
Handle(Image_ColorImage) aImage =
Handle(Image_ColorImage)::DownCast( RefImage->Dup() ) ;
ret_image = new Image_PseudoColorImage( aImage->LowerX(), aImage->LowerY(),
aImage->Width() , aImage->Height(),
aColorMap );
lastval = aImage->PixelColor( aImage->LowerX(), aImage->LowerY() ) ;
aEntry = aColorMap->NearestEntry( lastval ) ;
index = aEntry.Index() ;
for ( y = aImage->LowerY() ; y <= UpY ; y++ ) {
for ( x = aImage->LowerX() ; x <= UpX ; x++ ) {
val = aImage->PixelColor(x,y) ;
if ( ! ( val == lastval ) ) {
lastval = val ;
aEntry = aColorMap->NearestEntry( lastval ) ;
index = aEntry.Index() ;
}
RedDiffError = RedError = val.Red() - aEntry.Color().Red() ;
GreenDiffError = GreenError = val.Green() - aEntry.Color().Green() ;
BlueDiffError = BlueError = val.Blue() - aEntry.Color().Blue() ;
#ifdef TRACE
if ( Verbose > 3 )
cout << "ErrorDiffusion : " << RedError << "," <<
GreenError << "," <<
BlueError << "," << endl << flush ;
#endif
if ( RedError != 0. && GreenError != 0. && BlueError != 0. ) {
for ( i = 0 ; i < 4 ; i++ ) {
nx = x+Kernel[i].dx ;
ny = y+Kernel[i].dy ;
if ( nx >= LowX && nx <= UpX &&
ny >= LowY && ny <= UpY ) {
aImage->Pixel( nx, ny, aPixel ) ;
aPixel.Value().Values( r,g,b, Quantity_TOC_RGB ) ;
if ( ManageLastKernelError && i == 3 ) {
// Last one
cr = r + RedDiffError ;
cg = g + GreenDiffError ;
cb = b + BlueDiffError ;
}
else {
cr = r + ( Kernel[i].v * RedError ) ;
cg = g + ( Kernel[i].v * GreenError ) ;
cb = b + ( Kernel[i].v * BlueError ) ;
}
// ErrorDiffusion may produce Pixel out of ColorMap
// Clamp Color
cr = Max( cr, 0. ) ; cr = Min( cr, 1. ) ;
cg = Max( cg, 0. ) ; cg = Min( cg, 1. ) ;
cb = Max( cb, 0. ) ; cb = Min( cb, 1. ) ;
RedDiffError -= ( cr - r ) ;
GreenDiffError -= ( cg - g ) ;
BlueDiffError -= ( cb - b ) ;
#ifdef TRACE
if ( Verbose > 2 && i == 3 ) {
cout << "ErrorDiffusion Last Error: " <<
RedDiffError << "," <<
GreenDiffError << "," <<
BlueDiffError << "," << endl << flush ;
}
#endif
NewCol.SetValues( cr,cg,cb, Quantity_TOC_RGB ) ;
aPixel.SetValue( NewCol ) ;
aImage->SetPixel( nx, ny, aPixel ) ;
}
}
}
ret_image->SetPixel( x, y, index ) ;
}
}
return( ret_image ) ;
}

340
src/Image/Image_GImage.cdl Executable file
View File

@@ -0,0 +1,340 @@
-- File: Image_GImage.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
deferred generic class GImage from Image (anyPixel as Pixel from Aspect)
inherits Image from Image
---Purpose: Provide genmeric Image method independent from Pixel type.
uses
Pixel from Aspect,
PixelInterpolation from Image,
PixelAddress from Image,
FlipType from Image,
TypeOfImage from Image,
PlaneAngle from Quantity,
Trsf from gp,
GTrsf2d from gp
class PixelRow instantiates Array1 from TCollection (anyPixel);
---Level: Public
---Purpose: Manipulates PixelRow.
class PixelField instantiates GPixelField from Image (anyPixel);
---Level: Public
---Purpose: Resizable Image PixelField.
is
Initialize( x,y,dx,dy : in Integer from Standard ;
BackPixel : in anyPixel ) ;
---Level: Public
---Purpose: GImage constructor ,initialise Image origin, create Image
-- PixelField .
Destroy (me : mutable )
---Level: Public
---Purpose: Frees the allocated area corresponding to the
-- PixelField.
--
---C++: alias ~
is redefined;
SetBackgroundPixel( me : mutable ; aPixel: in anyPixel ) ;
---Level: Public
---Purpose: Sets the Image BackgroundPixel.
BackgroundPixel ( me : immutable ) returns anyPixel ;
---C++: return const &
---Level: Public
---Purpose: Return the Image BackgroundPixel.
Pixel ( me : immutable ; X,Y : in Integer from Standard )
returns anyPixel ;
---C++: return const &
---C++: alias operator()
---Level: Public
---Purpose: Return the Image Pixel Value at X,Y coordinate.
-- The returned Pixel is ReadOnly .
SetPixel( me : mutable ; X,Y : in Integer from Standard ;
aPixel: in anyPixel ) ;
---Level: Public
---Purpose: Sets the Image Pixel at X,Y coordinate with aPixel.
MutPixel ( me : mutable ; X,Y : in Integer from Standard )
returns anyPixel ;
---C++: return &
---C++: alias operator()
---Level: Public
---Purpose: Return the Image Pixel Value at X,Y coordinate.
-- The returned Pixel is ReadWrite .
SetRow ( me : mutable ; X,Y : in Integer from Standard ;
aRow: in PixelRow from Image);
---Level: Public
---Purpose: Sets an Image PixelRow starting at X,Y coordinate with aRow.
Row ( me : immutable ; X,Y : in Integer from Standard ;
aRow: in out PixelRow from Image);
---Level: Public
---Purpose: Get an Image PixelRow starting at X,Y coordinate in aRow.
SwapRow ( me : mutable ; I,J : Integer from Standard);
---Level: Public
---Purpose: Swap row.
SwapCol ( me : mutable ; I,J : Integer from Standard);
---Level: Public
---Purpose: Swap columns.
Zoom ( me : mutable ;
anInterpolation : PixelInterpolation from Image;
aCoefX,aCoefY : in Real from Standard ) ;
---Level: Public
---Purpose: Zoom an Image with a specific PixelInterpolation method.
-- Warning: image size change after a Zoom.
Rotate ( me : mutable ;
anInterpolation : PixelInterpolation from Image;
aAngle : in PlaneAngle from Quantity ) ;
---Level: Public
---Purpose: Rotate an Image with a specific PixelInterpolation method.
Translate( me : mutable ;
anInterpolation : PixelInterpolation from Image;
DX, DY : in Real from Standard ) ;
---Level: Public
---Purpose: Translate an Image with a specific PixelInterpolation method.
Affine( me : mutable ;
anInterpolation : PixelInterpolation from Image;
Trsf : in GTrsf2d from gp ) ;
---Level: Public
---Purpose : General transformation of an Image with the default
-- PixelInterpolation method.
-- Warning:
-- Raised an exception if the matrix of the transformation
-- is not inversible.
Affine( me : mutable ;
anInterpolation : PixelInterpolation from Image;
Trsf : in Trsf from gp ) ;
---Level: Public
---Purpose : General transformation of an Image with the default
-- PixelInterpolation method.
-- Warning:
-- Raised an exception if the matrix of the transformation
-- is not inversible.
InternalDup( me : mutable ; anImage : immutable like me )
is redefined ;
---Level: Public
---Purpose : Duplicate an Image.
-- ******************* Deferred method from Image *******************
SetOrigin ( me : mutable ; x,y : in Integer from Standard ) ;
---Level: Public
---Purpose: Sets Image origin, for Rotation, copy between image ...
-- Image origin is on the TOP LEFT . Y axis goes TOP to
-- DOWN , X axis goes LEFT to RIGHT.
LowerX ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the lower X Image coordinate ( X Origin ).
UpperX ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the upper X Image coordinate
-- ( X Origin + Image width - 1 ).
Width ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the Image width.
LowerY ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the lower Y Image coordinate ( Y Origin ).
UpperY ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the upper Y Image coordinate
-- ( Y Origin + Image height - 1 ).
Height ( me : immutable ) returns Integer from Standard ;
---Level: Public
---Purpose: Return the Image height.
Resize( me : mutable ;
XOffset,XScale, YOffset,YScale : Real from Standard ) ;
---Level: Public
---Purpose: Resize an Image. Image Pixel are left unchanged at there
-- absolute positon. Resulting Image can be clipped.
-- newLowerX = LowerX()*XScale + XOffset
-- newLowerY = LowerY()*YScale + YOffset
-- newUpperX = UpperX()*XScale + XOffset
-- newUpperY = UpperY()*YScale + YOffset
-- newWidth = Width() *XScale
-- newHeight = Height()*YScale
Type ( me : immutable ) returns TypeOfImage from Image is deferred ;
---Level: Public
---Purpose: Return the ImageType TOI_ColorImage or TOI_PseudoColorImage
isSamePixel( me : immutable ;
X,Y : in Integer from Standard ;
anotherImage : immutable like me ;
anotherX,anotherY : in Integer from Standard )
returns Boolean from Standard ;
---Level: Public
---Purpose: Returns True if me->Pixel(X,Y) is equal to
-- anotherImage->Pixel(anotherX,anotherY)
Pixel ( me : immutable ; X,Y : in Integer from Standard ;
aPixel : in out Pixel from Aspect ) ;
---Level: Public
---Purpose: Store the Image Pixel Value at X,Y coordinate in aPixel.
-- Warning: aPixel must have the same type than Image Pixel.
SetPixel( me : mutable ; X,Y : in Integer from Standard ;
aPixel : in Pixel from Aspect ) ;
---Level: Public
---Purpose: Store aPixel in the Image at X,Y coordinate .
-- Warning: aPixel must have the same type than Image Pixel.
Pixel ( me : immutable ; X,Y : in Integer from Standard ;
aPixel : in out PixelAddress from Image ) ;
---Level: Public
---Purpose: Store the Image Pixel Value at X,Y coordinate in aPixel.
-- Warning: aPixel must have the same type than Image Pixel.
SetPixel( me : mutable ; X,Y : in Integer from Standard ;
aPixel : in PixelAddress from Image ) ;
---Level: Public
---Purpose: Store aPixel in the Image at X,Y coordinate .
-- Warning: aPixel must have the same type than Image Pixel.
Transpose( me : mutable ; aType : in FlipType from Image ) ;
---Level: Public
---Purpose: Transpose an Image( flipping across horizontal axis or
-- vertical axis, or acroos diagonal... )
-- This geometric transformation preserve all Image Pixels.
-- We don't need to interpolate pixel .
-- Warning : Image size change durring Transpose.
Clip ( me : mutable ; X,Y,Width,Height:in Integer from Standard);
---Level: Public
---Purpose: Extract a SubImage starting at coordinate X,Y
-- to (X+Width-1),(Y+Height-1).
-- Warning : the Image size and origin change, new origine
-- is X,Y ; new size is Width,Height.
Shift ( me : mutable ; XShifth,YShift :in Integer from Standard);
---Level: Public
---Purpose: Translate an Image XShifth pixel Right, YShift Down .
-- Shift parameter are Integer value.
Fill ( me : mutable ; SrcImage : immutable like me ) ;
---Level: Public
---Purpose: Fill me with SrcImage. SrcImage pixel are copied starting
-- at SrcImage->LowerX(),SrcImage->LowerY() in MyPixelField.
-- SrcImage Pixel are clipped outside <me>.
Fill ( me : mutable ; SrcImage : immutable like me ;
SrcX, SrcY, SrcWidth, SrcHeight,
X, Y : in Integer from Standard ) ;
---Level: Public
---Purpose: Fill me with a SubImage of SrcImage starting from
-- SrcX, SrcY to (SrcX+SrcWidth-1),(SrcY+SrcHeight-1) in
-- Src Image coordinate. SrcImage SubImage pixels are copied
-- starting at X,Y in MyPixelField.
-- SrcImage Pixel are clipped outside <me>.
FillRect ( me : mutable ; aPixel : anyPixel ;
X, Y, Width, Height : in Integer from Standard) ;
---Level: Public
---Purpose: Fill a Rectangle in me with a Pixel
-- starting at X,Y to (X+Width-1,Y+Height-1) .
DrawRect ( me : mutable ; aPixel : anyPixel ;
X, Y, Width, Height : in Integer from Standard) ;
---Level: Public
---Purpose: draw a Rectangle in me with a Pixel
-- starting at X,Y to (X+Width-1,Y+Height-1) .
DrawLine ( me : mutable ; aPixel : anyPixel ;
X1, Y1, X2, Y2 : in Integer from Standard) ;
---Level: Public
---Purpose: draw a line in me with a Pixel
-- starting at X1,Y1 to X2,Y2 .
--DrawCircle ( me : mutable ; aPixel : anyPixel ;
--X, Y, R : in Integer from Standard) ;
-- ---Level: Public
-- ---Purpose: draw a circle in me with a Pixel
Clear ( me : mutable ) ;
---Level: Public
---Purpose: Fill the entire Image with the BackgroundPixel.
Dump ( me : immutable ) ;
---Level: Public
---Purpose: Debug
-- ******************* Redefined method ***************************
-- ShallowCopy (me) returns mutable like me is redefined deferred ;
---Level: Public
-- ---Purpose: Returns a copy at the first level of <me>. The objects
-- -- referenced are not copied. Entities copied by
-- -- ShallowCopy are equal.
-- ---C++: function call
-- DeepCopy (me) returns mutable like me is redefined deferred ;
---Level: Public
-- ---Purpose: Returns a deep copy of <me>. The objects
-- -- referenced are copied. Entities copied by
-- -- DeepCopy are similar (c.f the Method IsSimilar).
-- ---C++: function call
-- ******************* Private Method *******************
FlipHorizontal ( me : mutable ) is private ;
FlipVertical ( me : mutable ) is private ;
FlipMainDiagonal( me : mutable ) is private ;
FlipAntiDiagonal( me : mutable ) is private ;
Rotate90 ( me : mutable ) is private ;
Rotate180 ( me : mutable ) is private ;
Rotate270 ( me : mutable ) is private ;
PixelField ( me : immutable )
returns PixelField from Image is private ;
---C++: return const &
PixelFieldCopyTo( me : immutable ;
Dst : in out PixelField from Image ;
LowR,LowC,UpR,UpC,
DstLowR, DstLowC :in Integer from Standard) is private;
PixelFieldCopyFrom( me : mutable ;
Dst : PixelField from Image ;
LowR,LowC,UpR,UpC,
DstLowR, DstLowC :in Integer from Standard) is private;
PixelFieldDestroy( me : mutable ) is private ;
CirclePixels( me : mutable ;
Pixel : anyPixel ;
XCenter, YCenter, x,y : Integer from Standard ;
LowX,LowY,UpX,UpY : Integer from Standard ) is private ;
fields
myX,myY : Integer from Standard ;
myPixelField : Address from Standard ;
myBackgroundPixel : anyPixel;
end GImage from Image;

1538
src/Image/Image_GImage.gxx Executable file

File diff suppressed because it is too large Load Diff

117
src/Image/Image_GPixelField.cdl Executable file
View File

@@ -0,0 +1,117 @@
-- File: Image_GPixelField.cdl
-- Created: Wed Dec 9 12:22:03 1993
-- Author: Bertand Lesecq
-- <bbl@sparc3>
---Copyright: Matra Datavision 1993
private generic class GPixelField from Image (Item as any)
---Purpose: The class GPixelField represents bi-dimensionnal arrays
-- The range of the index start from 0 .
raises
RangeError from Standard,
OutOfRange from Standard,
OutOfMemory from Standard,
DimensionMismatch from Standard
is
Create (Width, Height: Integer from Standard)
returns GPixelField from Image
---Level: Public
---Purpose: Creates an array of lower bound <0><0> and upper
-- bound <Width-1><Height-1>. Range from Standard error is
-- raised when <Width-1> is less than <0> or <Height-1> is less
-- than <0>.
raises
RangeError from Standard,
OutOfMemory from Standard;
Create (Width, Height: Integer from Standard; V : Item)
returns GPixelField from Image
---Level: Public
---Purpose: Creates an array of lower bound <0><0> and upper
-- bound <Width-1><Height-1>. Range from Standard error is
-- raised when <Width-1> is less than <0> or <Height-1> is less
-- than <0>. The array is initialized with <V>.
raises
RangeError from Standard,
OutOfMemory from Standard;
Destroy (me : in out )
---Level: Public
---Purpose: Frees the allocated area corresponding to the
-- array. If the array was constructed from a
-- DoubleArray the Destroy doesn't delete the area.
--
---C++: alias ~
is static;
Width (me) returns Integer from Standard
---Level: Public
---Purpose: Return the number of columns of <me>.
--
---C++: inline
is static ;
Height (me) returns Integer from Standard
---Level: Public
---Purpose: Returns the number of rows of <me>.
--
---C++: inline
is static;
UpperX (me) returns Integer from Standard
---Level: Public
---Purpose: Returns the upper column number of the array.
--
---C++: inline
is static ;
UpperY (me) returns Integer from Standard
---Level: Public
---Purpose: Returns the upper row number of the array.
--
---C++: inline
is static ;
SetValue (me : in out; X, Y: Integer from Standard; Value: Item)
---Level: Public
---Purpose: Sets the element of index <X><Y>
-- to <Value>.
---C++: inline
raises OutOfRange from Standard
is static ;
Value (me; X,Y: Integer from Standard) returns any Item
---Level: Public
---Purpose: Returns the value of the element of index
-- <X><Y>
--
---C++: inline
---C++: alias operator()
---C++: return const &
raises OutOfRange from Standard
is static;
ChangeValue (me: in out; X,Y: Integer from Standard) returns any Item
---Level: Public
---Purpose: Returns the value of the element of index
-- <X><Y>
--
---C++: inline
---C++: alias operator()
---C++: return &
raises OutOfRange from Standard
is static;
fields
myWidth : Integer from Standard ;
myHeight : Integer from Standard ;
myDeletable : Boolean;
myData : Address;
end GPixelField ;

79
src/Image/Image_GPixelField.gxx Executable file
View File

@@ -0,0 +1,79 @@
#include <Standard_OutOfRange.hxx>
#include <Standard_DimensionMismatch.hxx>
#include <Standard_RangeError.hxx>
#include <Standard_OutOfMemory.hxx>
#ifdef TRACE
static int GPixelFieldCount = 0 ;
#endif
//=======================================================================
//function : Image_GPixelField
//purpose :
//=======================================================================
Image_GPixelField::Image_GPixelField (const Standard_Integer Width,
const Standard_Integer Height) :
myWidth(Width),
myHeight(Height),
myDeletable(Standard_True)
{
Standard_Integer Size = myWidth * myHeight;
Standard_RangeError_Raise_if(( myWidth <= 0 || myHeight <= 0 ),
"Image_GPixelField::Create");
#ifdef TRACE
cout << form("\tCreate a new GPixelField ( Count : %d )\n",++GPixelFieldCount)
<< flush ;
#endif
myData = new Item [Size];
}
//=======================================================================
//function : Image_GPixelField
//purpose :
//=======================================================================
Image_GPixelField::Image_GPixelField (const Standard_Integer Width,
const Standard_Integer Height,
const Item& V) :
myWidth(Width),
myHeight(Height),
myDeletable(Standard_True)
{
Standard_Integer Size = myWidth * myHeight;
Standard_RangeError_Raise_if(( myWidth <= 0 || myHeight <= 0 ),
"Image_GPixelField::Create");
#ifdef TRACE
cout << form("\tCreate a new GPixelField ( Count : %d )\n",++GPixelFieldCount)
<< flush ;
#endif
myData = new Item [Size];
for (Standard_Integer I = 0; I < Size ; I++) ((Item *)myData)[I] = V;
}
//=======================================================================
//function : Destroy
//purpose :
//=======================================================================
void Image_GPixelField::Destroy ()
{
#ifdef TRACE
cout << form("\t\tDelete a GPixelField ( Count : %d )\n", --GPixelFieldCount )
<< flush ;
#endif
if(myDeletable) {
delete [] (Item *) myData;
}
}

70
src/Image/Image_GPixelField.lxx Executable file
View File

@@ -0,0 +1,70 @@
#include <Standard_DimensionMismatch.hxx>
#include <Standard_OutOfRange.hxx>
#include Item_hxx
#include <stdio.h>
# ifdef WNT
# include <InterfaceGraphic_wntio.hxx>
# endif // WNT
//static char *ErrorMessag, LocalMessag[255];
static char LocalMessag[255];
inline Standard_Integer Image_GPixelField::Width() const { return myWidth; }
inline Standard_Integer Image_GPixelField::Height() const { return myHeight; }
inline Standard_Integer Image_GPixelField::UpperX() const { return myWidth-1; }
inline Standard_Integer Image_GPixelField::UpperY() const { return myHeight-1; }
//=======================================================================
//function : SetValue
//purpose :
//=======================================================================
inline void Image_GPixelField::SetValue ( const Standard_Integer X,
const Standard_Integer Y,
const Item& Value )
{
if (X < 0 || X > (myWidth -1) || Y < 0 || Y > (myHeight -1)) {
sprintf(LocalMessag,
"Index out of range in PixelField::SetValue(%d,%d)",X,Y);
Standard_OutOfRange::Raise (LocalMessag);
}
((Item *)myData)[(Y)*(myWidth)+X] = Value ;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
inline const Item& Image_GPixelField::Value(const Standard_Integer X,
const Standard_Integer Y) const
{
if (X < 0 || X > (myWidth -1) || Y < 0 || Y > (myHeight -1)) {
sprintf(LocalMessag,
"Index out of range in PixelField::Value(%d,%d)",X,Y);
Standard_OutOfRange::Raise (LocalMessag);
}
return ((Item *)myData)[(Y)*(myWidth)+X] ;
}
//=======================================================================
//function : ChangeValue
//purpose :
//=======================================================================
inline Item& Image_GPixelField::ChangeValue(const Standard_Integer X,
const Standard_Integer Y)
{
if ((X < 0 || X > (myWidth -1) || Y < 0 || Y > (myHeight -1))) {
sprintf(LocalMessag,
"Index out of range in PixelField::ChangeValue(%d,%d)",X,Y);
Standard_OutOfRange::Raise (LocalMessag);
}
return ((Item *)myData)[(Y)*(myWidth)+X] ;
}

View File

@@ -0,0 +1,12 @@
#ifndef _Image_HPrivateImage_HeaderFile
#define _Image_HPrivateImage_HeaderFile
#include <NCollection_Handle.hxx>
// This typedef shadows the private image storage class
// Currently FreeImagePlus is used
class fipImage;
typedef NCollection_Handle<fipImage> Image_HPrivateImage;
#endif /*_Image_HPrivateImage_HeaderFile*/

202
src/Image/Image_Image.cdl Executable file
View File

@@ -0,0 +1,202 @@
-- File: Image_Image.cdl
-- Created: Tue Jul 27 18:45:26 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
deferred class Image from Image inherits TShared from MMgt
---Purpose: This class defined the general behavior of an Image from
-- Package Image .
uses
PlaneAngle from Quantity,
FlipType from Image,
Color from Quantity,
Array1OfColor from Quantity,
HArray1OfColor from Quantity,
Pixel from Aspect,
PixelAddress from Image,
TypeOfImage from Image,
Type from Standard
is
Initialize( aPixelType : Type from Standard );
---Level: Public
---Purpose: Image constructor ,initialise the Image PixelType.
Destroy( me : mutable )
is virtual ;
---C++: alias ~
---Level: Public
---Purpose: Image destructor.
isSamePixel( me : immutable ;
X,Y : in Integer from Standard ;
anotherImage : immutable like me ;
anotherX,anotherY : in Integer from Standard )
returns Boolean from Standard is deferred ;
---Level: Public
---Purpose: Returns True if me->Pixel(X,Y) is equal to
-- anotherImage->Pixel(anotherX,anotherY)
PixelColor( me : immutable ; X,Y : in Integer from Standard )
returns Color from Quantity is deferred ;
---C++: return const &
---Purpose: Returns the Color of an Image Pixel.
RowColor ( me : immutable ; Y : in Integer from Standard )
returns HArray1OfColor from Quantity is virtual ;
---Purpose: Returns the Color of an Image Pixel Row.
RowColor ( me : immutable ;
Y : in Integer from Standard ;
aArray1 : in out Array1OfColor from Quantity )
is virtual ;
---Purpose: Stores the Color of an Image Pixel Row in aArray1.
PixelType( me : immutable ) returns Type from Standard ;
---Level: Public
---Purpose: Returns the Image Pixel Type.
Size ( me : immutable ) returns Integer from Standard ;
---Purpose: Returns the Image size in Pixel unit ( width*height) .
InternalDup( me : mutable ; anImage : immutable like me )
is deferred ;
---Purpose : Duplicates an Image.
-- ******************* Deferred method of Image *******************
SetOrigin( me : mutable ; x,y : in Integer from Standard )
is deferred ;
---Purpose: Sets Image origin, for Rotation, copy between image ...
-- Image origin is on the TOP LEFT . Y axis goes TOP to
-- DOWN , X axis goes LEFT to RIGHT.
LowerX ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the lower X Image coordinate ( X Origin ).
UpperX ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the upper X Image coordinate
-- ( X Origin + Image width - 1 ).
Width ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the Image width.
LowerY ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the lower Y Image coordinate ( Y Origin ).
UpperY ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the upper Y Image coordinate
-- ( Y Origin + Image height - 1 ).
Height ( me : immutable ) returns Integer from Standard is deferred ;
---Level: Public
---Purpose: Returns the Image height.
Resize( me : mutable ;
XOffset,XScale, YOffset,YScale : Real from Standard ) is deferred ;
---Level: Public
---Purpose: Resize an Image. Image Pixel are left unchanged at there
-- absolute positon. Resulting Image can be clipped.
-- newLowerX = LowerX()*XScale + XOffset
-- newLowerY = LowerY()*YScale + YOffset
-- newUpperX = UpperX()*XScale + XOffset
-- newUpperY = UpperY()*YScale + YOffset
-- newWidth = Width() *XScale
-- newHeight = Height()*YScale
Type ( me : immutable ) returns TypeOfImage from Image is deferred ;
---Level: Public
---Purpose: Returns the ImageType TOI_ColorImage or TOI_PseudoColorImage
Pixel ( me : immutable ; X,Y : in Integer from Standard ;
aPixel : in out Pixel from Aspect )
is deferred ;
---Level: Public
---Purpose: Get the Image Pixel Value at X,Y coordinate in aPixel.
-- Warning: aPixel must have the same type than Image Pixel.
SetPixel( me : mutable ; X,Y : in Integer from Standard ;
aPixel : in Pixel from Aspect )
is deferred ;
---Level: Public
---Purpose: Store aPixel in the Image at X,Y coordinate .
-- Warning: aPixel must have the same type than Image Pixel.
Pixel ( me : immutable ; X,Y : in Integer from Standard ;
aPixel : in out PixelAddress from Image )
is deferred ;
---Level: Public
---Purpose: Get the Image Pixel Value at X,Y coordinate in aPixel.
-- Warning: aPixel must have the same type than Image Pixel.
SetPixel( me : mutable ; X,Y : in Integer from Standard ;
aPixel : in PixelAddress from Image )
is deferred ;
---Level: Public
---Purpose: Store aPixel in the Image at X,Y coordinate .
-- Warning: aPixel must have the same type than Image Pixel.
Transpose ( me : mutable ; aType : in FlipType from Image ) is deferred ;
---Level: Public
---Purpose: Transpose an Image( flipping across horizontal axis or
-- vertical axis, or across diagonal... )
-- This geometric transformation preserves all Image Pixels.
-- We don't need to interpolate pixels .
-- Warning : Image size change during Transpose.
Clip ( me : mutable ; X,Y,Width,Height:in Integer from Standard)
is deferred ;
---Level: Public
---Purpose: Extract a SubImage starting at coordinate X,Y
-- to (X+Width-1),(Y+Height-1).
-- Warning : the Image size and origin change, new origin
-- is X,Y ; new size is Width,Height.
Shift ( me : mutable ; XShift,YShift :in Integer from Standard)
is deferred ;
---Level: Public
---Purpose: Translate an Image XShift pixel Right, YShift Down .
-- Shift parameter are Integer value.
Fill ( me : mutable ; SrcImage : immutable like me ) is deferred ;
---Level: Public
---Purpose: Fill me with SrcImage. SrcImage pixel are copied starting
-- at SrcImage->LowerX(),SrcImage->LowerY() in MyPixelField.
-- SrcImage Pixel are clipped outside <me>.
Fill ( me : mutable ; SrcImage : immutable like me ;
SrcX, SrcY, SrcWidth, SrcHeight,
X, Y : in Integer from Standard ) is deferred ;
---Level: Public
---Purpose: Fill me with a SubImage of SrcImage starting from
-- SrcX, SrcY to (SrcX+SrcWidth-1),(SrcY+SrcHeight-1) in
-- Src Image coordinate. SrcImage SubImage pixels are copied
-- starting at X,Y in MyPixelField.
-- SrcImage Pixel are clipped outside <me>.
Clear ( me : mutable ) is deferred ;
---Level: Public
---Purpose: Fill the entire Image with the BackgroundPixel.
Dup ( me : immutable ) returns mutable Image from Image is deferred;
---Level: Public
---Purpose : Duplicate an Image.
Dump( me : immutable ) is deferred ;
---Level: Public
---Purpose: Debug
fields
myPixelType : Type from Standard ;
end Image from Image;

64
src/Image/Image_Image.cxx Executable file
View File

@@ -0,0 +1,64 @@
#include <Image_Image.ixx>
#ifdef TRACE
static int ImageCount = 0 ;
#endif
Image_Image::Image_Image ( const Handle(Standard_Type)& aPixelType )
{
#ifdef TRACE
cout << "\tCreate a new Image ( Count : " << ++ImageCount << " )" << endl
<< flush ;
#endif
myPixelType = aPixelType ;
}
Standard_Integer Image_Image::Size() const {
return ( Width() * Height() ) ;
}
void Image_Image::InternalDup( const Handle(Image_Image)& aImage )
{ // myPixelType is set in Image_Image Constructor
}
Handle(Standard_Type) Image_Image::PixelType() const { return myPixelType ; }
void Image_Image::Destroy ()
{
#ifdef TRACE
cout << "\tDelete an Image ( Count : " << --ImageCount << " )" << endl
<< flush ;
#endif
}
void Image_Image::RowColor( const Standard_Integer Y,
Quantity_Array1OfColor& PR) const {
Standard_Integer TheLength = Min (PR.Length(), Width() );
Standard_Integer L = PR.Lower() ;
Standard_Integer X = LowerX() ;
for (Standard_Integer i=0; i< TheLength; i++) {
PR(L+i) = PixelColor(X+i,Y);
}
}
Handle(Quantity_HArray1OfColor) Image_Image::RowColor(
const Standard_Integer Y ) const {
Standard_Integer TheLength = Width() ;
Standard_Integer X = LowerX() ;
Handle(Quantity_HArray1OfColor) PR =
new Quantity_HArray1OfColor( 0, TheLength-1) ;
for (Standard_Integer i=0; i< TheLength; i++) {
PR->SetValue(i,PixelColor(X+i,Y));
}
return PR ;
}

120
src/Image/Image_PixMap.cdl Normal file
View File

@@ -0,0 +1,120 @@
--
-- File: Image_PixMap.cdl
-- Created: 16 September 2010
-- Author: KGV
--
---Copyright: Open CASCADE S.A.S. 2010
class PixMap from Image
---Version:
---Purpose: This class defines a system-independent bitmap
---Keywords: Bitmap, Pixmap
inherits
PixMap from Aspect
uses
Handle from Aspect,
TypeOfImage from Image,
HPrivateImage from Image,
CRawBufferData from Image,
Color from Quantity
raises
PixmapDefinitionError from Aspect,
PixmapError from Aspect
is
Create ( theWidth, theHeight : Integer from Standard;
theType : TypeOfImage from Image )
returns mutable PixMap from Image
raises PixmapDefinitionError from Aspect;
---Level: Public
---Purpose:
-- Allocate the bitmap with requested dimensions.
-- Allowed image types:
-- - Image_TOI_RGB (color image, 1 byte per component);
-- - Image_TOI_RGBA (color image with alpha channel);
-- - Image_TOI_RGBF (color image, 1 float per component);
-- - Image_TOI_RGBAF (color image with alpha channel);
-- - Image_TOI_FLOAT (grey image, 1 float per pixel).
Create ( theDataPtr : PByte from Standard;
theWidth, theHeight : Integer from Standard;
thePitch : Integer from Standard;
theBitsPerPixel : Integer from Standard;
theIsTopDown : Boolean from Standard )
returns mutable PixMap from Image
raises PixmapDefinitionError from Aspect;
---Level: Public
---Purpose:
-- Create a bitmap by copying an existing buffer.
---------------------------------------------------
-- Category: Methods to modify the class definition
---------------------------------------------------
Destroy ( me : mutable )
---Level: Advanced
---Purpose:
-- Destroies the Bitmap
---C++: alias ~
---Trigger: Raises if Bitmap is not defined properly
raises PixmapError from Aspect is virtual;
Dump ( me;
theFilename : CString from Standard;
theGammaCorr : Real from Standard = 1.0 )
returns Boolean from Standard
---Level: Advanced
---Purpose:
-- Dumps the Bitmap to an image file with
-- an optional gamma correction value
-- and returns TRUE if the dump occurs normaly.
raises PixmapError from Aspect is virtual;
----------------------------
-- Category: Inquire methods
----------------------------
PixmapID ( me ) returns Handle from Aspect is virtual;
---Level: Advanced
---Purpose:
-- Returns NULL handle
---Category: Inquire methods
----------------------------
-- Category: Access methods
----------------------------
AccessBuffer ( me : in;
theBufferInfo : in out CRawBufferData from Image )
is static;
---Purpose:
-- Fill the structure for low-level access to the bitmap data.
-- It is up to you to interpret these bytes correctly!
-- Important notice: image stored upside-down in the memory,
-- first image row is an last scanline in
-- the memory buffer.
-- If image was created with type Image_TOI_FLOAT buffer
-- format will be set to TDepthComponent. You can override
-- this field with another one-channel buffer format because
-- it useless for bitmap definition.
PixelColor ( me : in;
theX, theY : in Integer from Standard )
returns Color from Quantity
is virtual;
---Purpose:
-- Returns the pixel color. This function is relatively slow,
-- use AccessBuffer() instead for stream operations.
-- Note that this function convert input theY coordinate
-- to count off from top of an image (while in memory it stored
-- upside-down).
fields
myImage : HPrivateImage from Image is protected;
end PixMap;

456
src/Image/Image_PixMap.cxx Normal file
View File

@@ -0,0 +1,456 @@
// File Image_PixMap.cxx
// Created 16 September 2010
// Author KGV
// Copyright OpenCASCADE 2010
#ifdef HAVE_FREEIMAGE
#include <FreeImagePlus.h>
#include <Image_PixMap.ixx>
/* OCC22216 NOTE: linker dependency can be switched off by undefining macro */
#ifdef _MSC_VER
#pragma comment( lib, "FreeImage.lib" )
#pragma comment( lib, "FreeImagePlus.lib" )
#endif
#else
#include <Image_PixMap.ixx>
#include <fstream>
#if (defined(BYTE_ORDER) && BYTE_ORDER==BIG_ENDIAN) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER==__BIG_ENDIAN) || \
defined(__BIG_ENDIAN__)
#define THE_BIGENDIAN
#endif
// dummy class which can only dump to PPM format
class fipImage
{
public:
typedef struct tagRGBQuad {
#ifndef THE_BIGENDIAN
Standard_Byte rgbBlue;
Standard_Byte rgbGreen;
Standard_Byte rgbRed;
#else
Standard_Byte rgbRed;
Standard_Byte rgbGreen;
Standard_Byte rgbBlue;
#endif
Standard_Byte rgbReserved;
} RGBQuad_t;
public:
fipImage()
: myDataPtr(NULL),
mySizeX(0),
mySizeY(0),
myBytesPerLine(0),
myBytesPerPixel(3)
{
//
}
fipImage (const Standard_Integer theSizeX, const Standard_Integer theSizeY,
const Standard_Integer theBytesPerLine = 0, const Standard_Integer theBytesPerPixel = 3)
: myDataPtr(NULL),
mySizeX (theSizeX),
mySizeY (theSizeY),
myBytesPerLine (theBytesPerLine),
myBytesPerPixel (theBytesPerPixel)
{
if (myBytesPerLine == 0)
{
myBytesPerLine = mySizeX * myBytesPerPixel;
}
myDataPtr = new Standard_Byte[myBytesPerLine * mySizeY];
}
~fipImage()
{
delete[] myDataPtr;
}
Standard_Integer getHeight() const
{
return mySizeY;
}
Standard_Integer getWidth() const
{
return mySizeX;
}
Standard_Integer getBytesPerPixel() const
{
return myBytesPerPixel;
}
Standard_Integer getBytesPerLine() const
{
return myBytesPerLine;
}
Standard_Byte* getData() const
{
return myDataPtr;
}
Standard_Byte* getScanLine (const Standard_Integer theRow) const
{
return &myDataPtr[theRow * myBytesPerLine];
}
Quantity_Color getPixelColor (const Standard_Integer theCol,
const Standard_Integer theRow) const
{
RGBQuad_t* aPixel = (RGBQuad_t* )&getScanLine (theRow)[theCol * myBytesPerPixel];
return Quantity_Color (Standard_Real (aPixel->rgbRed) / 255.0,
Standard_Real (aPixel->rgbGreen) / 255.0,
Standard_Real (aPixel->rgbBlue) / 255.0,
Quantity_TOC_RGB);
}
Standard_Boolean savePPM (const Standard_CString theFileName) const
{
// Open file
FILE* pFile = fopen (theFileName, "wb");
if (pFile == NULL)
{
return Standard_False;
}
// Write header
fprintf (pFile, "P6\n%d %d\n255\n", mySizeX, mySizeY);
// Write pixel data
Standard_Byte* aScanLine;
RGBQuad_t* aPixel;
// image stored upside-down
for (Standard_Integer aRow = mySizeY - 1; aRow >= 0; --aRow)
{
aScanLine = getScanLine (aRow);
for (Standard_Integer aCol = 0; aCol < mySizeX; ++aCol)
{
aPixel = (RGBQuad_t* )&aScanLine[aCol * myBytesPerPixel];
fwrite (&aPixel->rgbRed, 1, 1, pFile);
fwrite (&aPixel->rgbGreen, 1, 1, pFile);
fwrite (&aPixel->rgbBlue, 1, 1, pFile);
}
}
// Close file
fclose (pFile);
return Standard_True;
}
Standard_Integer getMaxRowAligmentBytes() const
{
Standard_Integer aDeltaBytes = myBytesPerLine - myBytesPerPixel * mySizeX;
for (Standard_Integer anAligment = 16; anAligment > 1; anAligment /= 2)
{
if (isRowAlignedTo (anAligment, aDeltaBytes))
{
return anAligment;
}
}
return 1;
}
private:
Standard_Boolean isRowAlignedTo (const Standard_Integer theAligmentBytes,
const Standard_Integer theDeltaBytes) const
{
return (theDeltaBytes < theAligmentBytes) &&
((myBytesPerLine % theAligmentBytes) == 0);
}
private:
Standard_Byte* myDataPtr;
Standard_Integer mySizeX;
Standard_Integer mySizeY;
Standard_Integer myBytesPerLine;
Standard_Integer myBytesPerPixel;
};
#endif
#include <gp.hxx>
#include <TCollection_AsciiString.hxx>
//=======================================================================
//function : Image_PixMap
//purpose :
//=======================================================================
Image_PixMap::Image_PixMap (const Standard_Integer theWidth,
const Standard_Integer theHeight,
const Image_TypeOfImage theType)
: Aspect_PixMap (theWidth, theHeight, 1),
myImage()
{
#ifdef HAVE_FREEIMAGE
FREE_IMAGE_TYPE aFIType = FIT_UNKNOWN;
int aBitsPerPixel = 0;
switch (theType)
{
case Image_TOI_RGBA:
aFIType = FIT_BITMAP;
aBitsPerPixel = 32;
break;
case Image_TOI_RGBF:
aFIType = FIT_RGBF;
aBitsPerPixel = 96;
break;
case Image_TOI_RGBAF:
aFIType = FIT_RGBAF;
aBitsPerPixel = 128;
break;
case Image_TOI_FLOAT:
aFIType = FIT_FLOAT;
aBitsPerPixel = 32;
break;
case Image_TOI_RGB:
default:
aFIType = FIT_BITMAP;
aBitsPerPixel = 24;
break;
}
myImage = new fipImage (aFIType, theWidth, theHeight, aBitsPerPixel);
#else
Standard_Integer aBytesPerPixel = 0;
switch (theType)
{
case Image_TOI_RGBAF:
std::cerr << "Float formats not supported\n";
case Image_TOI_RGBA:
aBytesPerPixel = 4;
break;
case Image_TOI_RGBF:
case Image_TOI_FLOAT:
std::cerr << "Float formats not supported\n";
case Image_TOI_RGB:
default:
aBytesPerPixel = 3;
break;
}
myImage = new fipImage (theWidth, theHeight, 0, aBytesPerPixel);
//
#endif
}
//=======================================================================
//function : Image_PixMap
//purpose :
//=======================================================================
Image_PixMap::Image_PixMap (const Standard_PByte theDataPtr,
const Standard_Integer theWidth, const Standard_Integer theHeight,
const Standard_Integer thePitch, const Standard_Integer theBitsPerPixel,
const Standard_Boolean theIsTopDown)
: Aspect_PixMap (theWidth, theHeight, 1),
myImage (new fipImage())
{
#ifdef HAVE_FREEIMAGE
*myImage = FreeImage_ConvertFromRawBits (theDataPtr,
theWidth, theHeight,
thePitch, theBitsPerPixel,
0, 0, 0,
theIsTopDown);
if (theBitsPerPixel != 24)
{
myImage->convertTo24Bits();
}
#else
myImage = new fipImage (theWidth, theHeight, thePitch, theBitsPerPixel / 8);
Standard_Integer aRowStart = !theIsTopDown ? 0 : (theHeight - 1);
Standard_Integer aRowDelta = !theIsTopDown ? 1 : -1;
for (Standard_Integer aRowFrom (aRowStart), aRowTo (0);
aRowFrom >= 0 && aRowFrom < theHeight;
aRowFrom += aRowDelta, ++aRowTo)
{
memcpy (myImage->getScanLine (aRowTo),
&theDataPtr[aRowFrom * thePitch],
myImage->getBytesPerLine());
}
#endif
}
//=======================================================================
//function : Destroy
//purpose :
//=======================================================================
void Image_PixMap::Destroy()
{
myImage = Image_HPrivateImage();
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_Boolean Image_PixMap::Dump (const Standard_CString theFilename,
const Standard_Real theGammaCorr) const
{
#ifdef HAVE_FREEIMAGE
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename (theFilename);
if (anImageFormat == FIF_UNKNOWN)
{
std::cerr << "Image_PixMap, image format doesn't supported!\n";
return Standard_False;
}
Standard_Boolean isCopied = Standard_False;
Image_HPrivateImage anImageToDump = myImage;
if (Abs (theGammaCorr - 1.0) > gp::Resolution())
{
if (!isCopied)
{
isCopied = Standard_True;
anImageToDump = new fipImage (*myImage);
}
anImageToDump->adjustGamma (theGammaCorr);
}
switch (anImageFormat)
{
case FIF_GIF:
if (!isCopied)
{
isCopied = Standard_True;
anImageToDump = new fipImage (*myImage);
}
// need convertion to image with pallete
anImageToDump->colorQuantize (FIQ_NNQUANT);
break;
case FIF_EXR:
if (myImage->getImageType() == FIT_BITMAP)
{
if (!isCopied)
{
isCopied = Standard_True;
anImageToDump = new fipImage (*myImage);
}
anImageToDump->convertToType (FIT_RGBF);
}
break;
default:
if (myImage->getImageType() != FIT_BITMAP)
{
if (!isCopied)
{
isCopied = Standard_True;
anImageToDump = new fipImage (*myImage);
}
anImageToDump->convertToType (FIT_BITMAP);
}
break;
}
return anImageToDump->save (theFilename);
#else
return myImage->savePPM (theFilename);
#endif
}
Aspect_Handle Image_PixMap::PixmapID() const
{
return Aspect_Handle();
}
void Image_PixMap::AccessBuffer (Image_CRawBufferData& theBuffer) const
{
theBuffer.widthPx = myImage->getWidth();
theBuffer.heightPx = myImage->getHeight();
#ifdef HAVE_FREEIMAGE
theBuffer.rowAligmentBytes = 4; // 32 bits according to FreeImage documentation
switch (myImage->getImageType())
{
case FIT_FLOAT:
theBuffer.format = TDepthComponent;
theBuffer.type = TFloat;
break;
case FIT_RGBF:
theBuffer.format = TRGB;
theBuffer.type = TFloat;
break;
case FIT_RGBAF:
theBuffer.format = TRGBA;
theBuffer.type = TFloat;
break;
case FIT_BITMAP:
default:
#if defined(FREEIMAGE_BIGENDIAN)
theBuffer.format = (myImage->getColorType() == FIC_RGBALPHA) ? TRGBA : TRGB;
#else
theBuffer.format = (myImage->getColorType() == FIC_RGBALPHA) ? TBGRA : TBGR;
#endif
theBuffer.type = TUByte;
break;
}
theBuffer.dataPtr = myImage->accessPixels();
#else
theBuffer.rowAligmentBytes = myImage->getMaxRowAligmentBytes();
theBuffer.format = (myImage->getBytesPerPixel() == 4) ? TBGRA : TBGR;
theBuffer.type = TUByte;
theBuffer.dataPtr = myImage->getData();
#endif
}
Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
const Standard_Integer theY) const
{
Standard_Integer aScanlineId = myImage->getHeight() - theY - 1;
if (theX < 0 || theX >= (unsigned int)myImage->getWidth() ||
theY < 0 || theY >= (unsigned int)myImage->getHeight())
{
return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
}
#ifdef HAVE_FREEIMAGE
else if (myImage->getImageType() == FIT_BITMAP)
{
RGBQUAD aValue; memset (&aValue, 0, sizeof(aValue));
myImage->getPixelColor (theX, aScanlineId, &aValue);
return Quantity_Color (Standard_Real (aValue.rgbRed) / 255.0,
Standard_Real (aValue.rgbGreen) / 255.0,
Standard_Real (aValue.rgbBlue) / 255.0,
Quantity_TOC_RGB);
}
else
{
switch (myImage->getImageType())
{
case FIT_FLOAT:
{
float* aScanLine = (float* )myImage->getScanLine (aScanlineId);
Quantity_Parameter aValue = Quantity_Parameter (aScanLine[theX]);
return Quantity_Color (aValue, aValue, aValue, Quantity_TOC_RGB);
}
case FIT_RGBF:
{
FIRGBF* aScanLine = (FIRGBF* )myImage->getScanLine (aScanlineId);
FIRGBF* aPixel = &aScanLine[theX];
return Quantity_Color (Quantity_Parameter (aPixel->red),
Quantity_Parameter (aPixel->green),
Quantity_Parameter (aPixel->blue),
Quantity_TOC_RGB);
}
case FIT_RGBAF:
{
FIRGBAF* aScanLine = (FIRGBAF* )myImage->getScanLine (aScanlineId);
FIRGBAF* aPixel = &aScanLine[theX];
return Quantity_Color (Quantity_Parameter (aPixel->red),
Quantity_Parameter (aPixel->green),
Quantity_Parameter (aPixel->blue),
Quantity_TOC_RGB);
}
default:
{
// not supported image type
return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
}
}
}
#else
return myImage->getPixelColor (theX, aScanlineId);
#endif
}

View File

@@ -0,0 +1,9 @@
#include <Image_PixelAddress.hxx>
const Handle(Standard_Type)& STANDARD_TYPE(Image_PixelAddress)
{
static Handle(Standard_Type) _atype =
new Standard_Type ("Image_PixelAddress", sizeof (Image_PixelAddress));
return _atype;
}

View File

@@ -0,0 +1,19 @@
//============================================================================
//==== Titre: Image_PixelAddress.hxx
//====
//==== Implementation: This is a primitive type implemented with typedef
//============================================================================
#ifndef _Image_PixelAddress_HeaderFile
#define _Image_PixelAddress_HeaderFile
//==== Definition de Type ====================================================
#include <Standard_Type.hxx>
const Handle(Standard_Type)& STANDARD_TYPE(Image_PixelAddress);
//============================================================================
#include <Aspect_Pixel.hxx>
typedef Aspect_Pixel *Image_PixelAddress ;
#endif

View File

@@ -0,0 +1,88 @@
--
-- File: Image_PixelInterpolation.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class PixelInterpolation from Image
---Purpose: The class PixelInterpolation is used to compute a Pixel
-- value on non-integer Image coordinate. This Pixel type
-- is called SubPixel .
-- PixelInterpolation is the default and is the simplest one,
-- SubPixel value on non-integer Image coordinate is the
-- value of the nearest Pixel at integer coordinate.
-- The user can create a new kind of PixelInterpolation with a
-- new algorithm by creating a new derived PixelInterpolation
-- class and redefined Interpolate() method.
-- If V1 is the value of the nearest Image Pixel
-- V = V1 is the Image SubPixel value on non-integer
-- coordinate (FX,FY)
uses
Pixel from Aspect,
Image from Image,
ColorPixel from Aspect,
IndexPixel from Aspect,
DColorImage from Image,
DIndexedImage from Image
is
Create returns PixelInterpolation from Image ;
---Level: Public
---Purpose: Create a PixelInterpolation object.
Interpolate( me ; aImage : Image from Image ;
X,Y : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard
is virtual ;
---Level: Public
---Purpose: Compute SubPixel's value on non-integer Image coordinate.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate X,Y is outside of image.
-- Return True if Interpolation Succes.
-- Retrun False if the SubPixel is out from Image.
Interpolate( me ; aImage : DColorImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out ColorPixel from Aspect )
returns Boolean from Standard
is virtual ;
---Level: Public
---Purpose: Compute SubPixel's value on non-integer Image coordinate for
-- DColorImage and ColorPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DIndexedImage from Image ;
FX,FY : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out IndexPixel from Aspect )
returns Boolean from Standard
is virtual ;
---Level: Public
---Purpose: Compute SubPixel's value on non-integer Image coordinate for
-- DIndexedImage and IndexPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's use
-- check if the SubPixel coordinate X,Y is outside of image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
DoInterpolate( me ; aImage : Image from Image ;
X,Y : Real from Standard ;
LowerX,LowerY,UpperX,UpperY: Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard is static private ;
end PixelInterpolation from Image;

View File

@@ -0,0 +1,65 @@
#include <Image_PixelInterpolation.ixx>
Image_PixelInterpolation::Image_PixelInterpolation() {}
Standard_Boolean Image_PixelInterpolation::DoInterpolate(
const Handle(Image_Image)& aImage,
const Standard_Real X, const Standard_Real Y,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{ Standard_Integer NX ;
Standard_Integer NY ;
if ( X < 0. ) NX = Standard_Integer(X-0.5) ;
else NX = Standard_Integer(X+0.5) ;
if ( Y < 0. ) NY = Standard_Integer(Y-0.5) ;
else NY = Standard_Integer(Y+0.5) ;
if ( NX < LowX || NX > UpX ||
NY < LowY || NY > UpY ) {
return Standard_False ;
}
else {
aImage->Pixel( NX, NY, aPixel );
return Standard_True ;
}
}
Standard_Boolean Image_PixelInterpolation::Interpolate(
const Handle(Image_Image)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{ return DoInterpolate( aImage, FX, FY, LowX, LowY, UpX, UpY, aPixel ) ; }
Standard_Boolean Image_PixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ return DoInterpolate( aImage, FX, FY, LowX, LowY, UpX, UpY, aPixel ) ; }
Standard_Boolean Image_PixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ return DoInterpolate( aImage, FX, FY, LowX, LowY, UpX, UpY, aPixel ) ; }

View File

@@ -0,0 +1,79 @@
-- File: Image_PlanarPixelInterpolation.cdl
-- Created: Tue Jul 27 18:47:06 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class PlanarPixelInterpolation from Image inherits PixelInterpolation from Image
---Purpose: The class PlanarPixelInterpolation is used to compute a
-- SubPixelvalue on non integer Image coordinate
-- PlanarPixelInterpolation redefined a new method to compute a
-- SubPixel value .
-- To compute the value of a Image SubPixel, first we look
-- for the three nearest Image Pixels .
-- Then we compute the plane definition in the 3D space
-- composed by the Image Pixel coordinate and Pixel value
-- on Z axis .
-- The SubPixel value is the Z value of ( FX,FY ) point in the
-- three nearest Image Pixel defined plane .
uses
Image from Image,
Pixel from Aspect,
ColorPixel from Aspect,
IndexPixel from Aspect,
DColorImage from Image,
DIndexedImage from Image
is
Create returns PlanarPixelInterpolation from Image ;
---Level: Public
---Purpose: Create a PlanarPixelInterpolation object.
Interpolate( me ; aImage : Image from Image ;
X,Y : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out Pixel from Aspect )
returns Boolean from Standard is redefined ;
---Level: Public
---Purpose: Redefined the method to compute SubPixel's value
-- on non integer Image coordinate.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DColorImage from Image ;
X,Y : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out ColorPixel from Aspect )
returns Boolean from Standard is redefined;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DColorImage and ColorPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate FX,FY is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
Interpolate( me ; aImage : DIndexedImage from Image ;
X,Y : Real from Standard ;
LowerX,LowerY,UpperX,UpperY : Integer from Standard ;
RetPixel : in out IndexPixel from Aspect )
returns Boolean from Standard is redefined ;
---Level: Public
---Purpose: Compute SubPixel's value on non integer Image coordinate for
-- DIndexedImage and IndexPixel.
-- LowerX,LowerY,UpperX,UpperY is the Image Min Max, it's used
-- to check if the SubPixel coordinate X,Y is outside of
-- image.
-- Return True if Interpolation Succes.
-- Return False if the SubPixel is out from Image.
end PlanarPixelInterpolation from Image;

View File

@@ -0,0 +1,265 @@
#include <Image_PlanarPixelInterpolation.ixx>
Image_PlanarPixelInterpolation::Image_PlanarPixelInterpolation() {}
Standard_Boolean Image_PlanarPixelInterpolation::Interpolate(
const Handle(Image_Image)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_Pixel& aPixel ) const
{
if ( aImage->IsKind(STANDARD_TYPE(Image_DIndexedImage))) {
return Interpolate( Handle(Image_DIndexedImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_IndexPixel &)aPixel ) ;
}
else if ( aImage->IsKind(STANDARD_TYPE(Image_DColorImage))) {
return Interpolate( Handle(Image_DColorImage)::DownCast( aImage ),
FX,FY,LowX,LowY,UpX,UpY,(Aspect_ColorPixel &)aPixel ) ;
}
else {
return Image_PixelInterpolation::Interpolate( aImage,
FX,FY,LowX,LowY,UpX,UpY,aPixel ) ;
}
}
static Standard_Real DoInterpolation( const Standard_Integer NX[3],
const Standard_Integer NY[3],
const Standard_Real NZ[3],
const Standard_Real FX,
const Standard_Real FY )
{ Standard_Real VX[3], VY[3], VZ[3] ;
Standard_Real Result ;
if ( NZ[0] == NZ[1] && NZ[0] == NZ[2] ) {
Result = NZ[0] ;
}
else {
VX[1] = NX[1] - NX[0] ;
VY[1] = NY[1] - NY[0] ;
VZ[1] = NZ[1] - NZ[0] ;
VX[2] = NX[2] - NX[0] ;
VY[2] = NY[2] - NY[0] ;
VZ[2] = NZ[2] - NZ[0] ;
if ( VZ[1] == 0. && VZ[2] == 0. ) {
Result = NZ[0] ;
}
else {
VX[0] = VY[1]*VZ[2] - VY[2]*VZ[1] ;
VY[0] = VZ[1]*VX[2] - VZ[2]*VX[1] ;
VZ[0] = VX[1]*VY[2] - VX[2]*VY[1] ;
if ( VZ[0] != 0. ) {
Result = NZ[0] -
( (FX-NX[0])*VX[0] + (FY-NY[0])*VY[0] ) / VZ[0];
}
else {
Result = NZ[0] ;
}
}
}
return Result ;
}
Standard_Boolean Image_PlanarPixelInterpolation::Interpolate(
const Handle(Image_DColorImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_ColorPixel& aPixel ) const
{ Standard_Integer NX[3], NY[3] ;
Standard_Real NZ[3] ;
Standard_Real R,G,B ;
static Quantity_Color Col ;
if ( FX < 0. ) NX[0] = Standard_Integer(FX-0.5) ;
else NX[0] = Standard_Integer(FX+0.5) ;
if ( FY < 0. ) NY[0] = Standard_Integer(FY-0.5) ;
else NY[0] = Standard_Integer(FY+0.5) ;
if ( NX[0] < LowX || NX[0] > UpX ||
NY[0] < LowY || NY[0] > UpY ) {
return Standard_False ;
}
else if ( ( FX-NX[0] ) == 0. && ( FY-NY[0] ) == 0. ) {
aImage->Pixel( NX[0], NY[0], aPixel );
return Standard_True ;
}
else {
if ( ( FX-NX[0] ) >= 0. ) { NX[1] = NX[0]+1 ; NY[1] = NY[0] ; }
else { NX[1] = NX[0]-1 ; NY[1] = NY[0] ; }
if ( ( FY-NY[0] ) >= 0. ) { NX[2] = NX[0] ; NY[2] = NY[0]+1 ; }
else { NX[2] = NX[0] ; NY[2] = NY[0]-1 ; }
if ( NX[1] < LowX || NX[1] > UpX || NY[1] < LowY || NY[1] > UpY ||
NX[2] < LowX || NX[2] > UpX || NY[2] < LowY || NY[2] > UpY ) {
aImage->Pixel( NX[0], NY[0], aPixel );
}
else {
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Red() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Red() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Red() ;
R = DoInterpolation( NX,NY,NZ, FX,FY ) ;
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Green() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Green() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Green() ;
G = DoInterpolation( NX,NY,NZ, FX,FY ) ;
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value().Blue() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value().Blue() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value().Blue() ;
B = DoInterpolation( NX,NY,NZ, FX,FY ) ;
Col.SetValues( R, G, B, Quantity_TOC_RGB ) ;
aPixel.SetValue( Col ) ;
}
return Standard_True ;
}
}
Standard_Boolean Image_PlanarPixelInterpolation::Interpolate(
const Handle(Image_DIndexedImage)& aImage,
const Standard_Real FX, const Standard_Real FY,
const Standard_Integer LowX,
const Standard_Integer LowY,
const Standard_Integer UpX,
const Standard_Integer UpY,
Aspect_IndexPixel& aPixel ) const
{ Standard_Integer NX[3], NY[3] ;
Standard_Real NZ[3] ;
if ( FX < 0. ) NX[0] = Standard_Integer(FX-0.5) ;
else NX[0] = Standard_Integer(FX+0.5) ;
if ( FY < 0. ) NY[0] = Standard_Integer(FY-0.5) ;
else NY[0] = Standard_Integer(FY+0.5) ;
if ( NX[0] < LowX || NX[0] > UpX ||
NY[0] < LowY || NY[0] > UpY ) {
return Standard_False ;
}
else if ( ( FX-NX[0] ) == 0. && ( FY-NY[0] ) == 0. ) {
aImage->Pixel( NX[0], NY[0], aPixel );
return Standard_True ;
}
else {
if ( ( FX-NX[0] ) >= 0. ) { NX[1] = NX[0]+1 ; NY[1] = NY[0] ; }
else { NX[1] = NX[0]-1 ; NY[1] = NY[0] ; }
if ( ( FY-NY[0] ) >= 0. ) { NX[2] = NX[0] ; NY[2] = NY[0]+1 ; }
else { NX[2] = NX[0] ; NY[2] = NY[0]-1 ; }
if ( NX[1] < LowX || NX[1] > UpX || NY[1] < LowY || NY[1] > UpY ||
NX[2] < LowX || NX[2] > UpX || NY[2] < LowY || NY[2] > UpY ) {
aImage->Pixel( NX[0], NY[0], aPixel );
}
else {
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value() ;
aPixel.SetValue(
Standard_Integer( DoInterpolation( NX,NY,NZ, FX,FY ) )
) ;
}
return Standard_True ;
}
}
//##############################################################################
#ifdef OLD
{ Standard_Integer NX[3], NY[3], NZ[3] ;
Standard_Integer Result ;
Standard_Real VX[3], VY[3], VZ[3], PVALUE ;
NX[0] = Standard_Integer(FX+0.5) ;
NY[0] = Standard_Integer(FY+0.5) ;
if ( NX[0] < LowX || NX[0] > UpX ||
NY[0] < LowY || NY[0] > UpY ) {
return Standard_False ;
}
else if ( ( FX-NX[0] ) == 0. && ( FY-NY[0] ) == 0. ) {
aImage->Pixel( NX[0], NY[0], aPixel );
return Standard_True ;
}
else {
if ( ( FX-NX[0] ) >= 0. ) { NX[1] = NX[0]+1 ; NY[1] = NY[0] ; }
else { NX[1] = NX[0]-1 ; NY[1] = NY[0] ; }
if ( ( FY-NY[0] ) >= 0. ) { NX[2] = NX[0] ; NY[2] = NY[0]+1 ; }
else { NX[2] = NX[0] ; NY[2] = NY[0]-1 ; }
if ( NX[1] < LowX || NX[1] > UpX || NY[1] < LowY || NY[1] > UpY ||
NX[2] < LowX || NX[2] > UpX || NY[2] < LowY || NY[2] > UpY ) {
aImage->Pixel( NX[0], NY[0], aPixel );
}
else {
NZ[0] = aImage->Pixel( NX[0],NY[0] ).Value() ;
NZ[1] = aImage->Pixel( NX[1],NY[1] ).Value() ;
NZ[2] = aImage->Pixel( NX[2],NY[2] ).Value() ;
VX[1] = NX[1] - NX[0] ;
VY[1] = NY[1] - NY[0] ;
VZ[1] = NZ[1] - NZ[0] ;
VX[2] = NX[2] - NX[0] ;
VY[2] = NY[2] - NY[0] ;
VZ[2] = NZ[2] - NZ[0] ;
if ( VZ[1] == 0. && VZ[2] == 0. ) {
Result = NZ[0] ;
}
else {
VX[0] = VY[1]*VZ[2] - VY[2]*VZ[1] ;
VY[0] = VZ[1]*VX[2] - VZ[2]*VX[1] ;
VZ[0] = VX[1]*VY[2] - VX[2]*VY[1] ;
if ( VZ[0] != 0. ) {
PVALUE = NZ[0] -
( (FX-NX[0])*VX[0] + (FY-NY[0])*VY[0] ) / VZ[0];
Result = Standard_Integer( PVALUE ) ;
}
else {
Result = NZ[0] ;
}
}
aPixel.SetValue( Result ) ;
}
return Standard_True ;
}
}
#endif

View File

@@ -0,0 +1,132 @@
-- File: Image_PseudoColorImage.cdl
-- Created: Tue Jul 27 18:53:48 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
class PseudoColorImage from Image inherits DIndexedImage from Image
---Purpose : A PseudoColorImage is a DIndexedImage associated with a
-- ColorMap . The ColoMap is set at Creation time and then
-- never be changed. Each Pixel in the Image ,as a IndexPixel
-- from Aspect, match a ColoMap Entry with the same value.
uses
ColorMap from Aspect,
Color from Quantity,
IndexPixel from Aspect ,
Array1OfColor from Quantity,
HArray1OfColor from Quantity,
LookupTable from Image,
Image from Image,
TypeOfImage from Image
is
Create( x,y,dx,dy : in Integer from Standard ;
aColorMap : ColorMap from Aspect )
returns mutable PseudoColorImage from Image;
---Level: Public
---Purpose : Creates a PseudoColorImage object.
-- The default Background Pixel is set to 0 .
-- All the Image is initialised with Background Pixel
Create( x,y,dx,dy : in Integer from Standard ;
aColorMap : ColorMap from Aspect ;
BackPixel : IndexPixel from Aspect )
returns mutable PseudoColorImage from Image;
---Level: Public
---Purpose : Creates a PseudoColorImage object and set the
-- Background Pixel.
-- All the Image is initialised with Background Pixel
Type ( me : immutable ) returns TypeOfImage from Image ;
---Level: Public
---Purpose : Returns the Image Type.
ColorMap( me ) returns immutable ColorMap from Aspect;
---Level: Public
---Purpose : returns the Image ColorMap .
PixelColor( me : immutable ; X,Y : in Integer from Standard )
returns Color from Quantity ;
---C++: return const &
---Level: Public
---Purpose : Returns the Pixel Color .
RowColor ( me : immutable ; Y : in Integer from Standard )
returns HArray1OfColor from Quantity is redefined ;
---Level: Public
---Purpose : Return the PixelRow Color in a HArray1 of Color.
RowColor ( me : immutable ;
Y : in Integer from Standard ;
aArray1 : in out Array1OfColor from Quantity ) is redefined ;
---Level: Public
---Purpose : Stores the PixelRow Color in a Array1 .
Squeeze( me : immutable ;
BasePixel : IndexPixel from Aspect )
returns PseudoColorImage from Image ;
---Level: Public
---Purpose : Creates a new Image with continuous Pixel and a continuous
-- ColorMap whith only used Image color starting from
-- BasePixel .
SqueezedLookupTable(
me : immutable ;
BasePixel : IndexPixel from Aspect ;
aLookup : in out LookupTable from Image ) ;
---Level: Public
---Purpose: Creates a LookupTable that can be used to create a
-- new Image with continuous Pixel and a continuous
-- ColorMap with only used Image color starting
-- from BasePixel .
Lookup( me : mutable ;
aLookup : in LookupTable from Image ) ;
---Level: Public
---Purpose : Pass a PseudoColorImage through a lookupTable
Extrema( me : immutable ; Min, Max : in out IndexPixel from Aspect );
---Level: Public
---Purpose: Find the maximum and minimum Pixel Value of an Image.
Threshold( me : mutable ; Min, Max : IndexPixel from Aspect ;
Map : IndexPixel from Aspect );
---Level: Public
---Purpose: This method changes the value of any Pixel beetwen the
-- range (Min->Max) to the Pixel Map value. All Pixel values
-- outside the range are passed through without changed .
Rescale( me : mutable ; Scale, Offset : Real from Standard ) ;
---Level: Public
---Purpose : Map the Image Pixel Value from one range to another range.
-- This method perform the mapping by multiplying each
-- Pixel Value by Scale and then adding Offset to the result.
Dup ( me : immutable ) returns mutable Image from Image;
---Level: Public
---Purpose : Duplicate a Image.
-- ******************* Redefined method ***************************
-- ShallowCopy (me) returns mutable like me ;
---Level: Public
-- ---Purpose: Returns a copy at the first level of <me>. The objects
-- -- referenced are not copied. Entities copied by
-- -- ShallowCopy are equal.
-- ---C++: function call
-- DeepCopy (me) returns mutable like me ;
---Level: Public
-- ---Purpose: Returns a deep copy of <me>. The objects
-- -- referenced are copied. Entities copied by
-- -- DeepCopy are similar (c.f the Method IsSimilar).
-- ---C++: function call
fields
myColorMap: ColorMap from Aspect;
end PseudoColorImage from Image;

View File

@@ -0,0 +1,304 @@
#include <Image_PseudoColorImage.ixx>
#include <Image_LookupTable.hxx>
#include <TColStd_SetIteratorOfSetOfInteger.hxx>
#include <TColStd_SetOfInteger.hxx>
#include <Aspect_GenericColorMap.hxx>
#include <Aspect_ColorMapEntry.hxx>
Image_PseudoColorImage::Image_PseudoColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy,
const Handle(Aspect_ColorMap)& aColorMap)
: Image_DIndexedImage( x, y, dx, dy, Aspect_IndexPixel( 0 ) ) ,
myColorMap (aColorMap)
{
}
Image_PseudoColorImage::Image_PseudoColorImage (
const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer dx,
const Standard_Integer dy,
const Handle(Aspect_ColorMap)& aColorMap,
const Aspect_IndexPixel& Back )
: Image_DIndexedImage( x, y, dx, dy, Back ) , myColorMap (aColorMap)
{
}
Handle(Image_Image) Image_PseudoColorImage::Dup() const {
Handle(Image_PseudoColorImage) aImage =
new Image_PseudoColorImage( LowerX(), LowerY(),
Width(), Height(),
myColorMap,
BackgroundPixel() ) ;
aImage->InternalDup( this ) ;
return aImage ;
}
Image_TypeOfImage Image_PseudoColorImage::Type () const {
return Image_TOI_PseudoColorImage ;
}
Handle(Aspect_ColorMap) Image_PseudoColorImage::ColorMap () const {
return myColorMap;
}
const Quantity_Color& Image_PseudoColorImage::PixelColor(
const Standard_Integer x,
const Standard_Integer y ) const
{ return( myColorMap->FindEntry ( Pixel( x, y ).Value()
).Color() ) ;
}
void Image_PseudoColorImage::RowColor( const Standard_Integer Y,
Quantity_Array1OfColor& PR) const {
Standard_Integer TheLength = Min (PR.Length(), Width() );
Standard_Integer L = PR.Lower() ;
Standard_Integer X = LowerX() ;
Standard_Integer NIndex ;
Standard_Integer PIndex = Pixel( X, Y ).Value() ;
Quantity_Color PColor = PixelColor( X, Y ) ;
for (Standard_Integer i=0; i< TheLength; i++) {
NIndex = Pixel(X+i,Y).Value() ;
if ( NIndex != PIndex ) {
PIndex = NIndex ;
PColor = myColorMap->FindEntry( PIndex ).Color() ;
}
PR(L+i) = PColor;
}
}
Handle(Quantity_HArray1OfColor) Image_PseudoColorImage::RowColor(
const Standard_Integer Y ) const {
Standard_Integer TheLength = Width() ;
Standard_Integer X = LowerX() ;
Standard_Integer NIndex ;
Standard_Integer PIndex = Pixel( X, Y ).Value() ;
Quantity_Color PColor = PixelColor( X, Y ) ;
Handle(Quantity_HArray1OfColor) PR =
new Quantity_HArray1OfColor( 0, TheLength-1) ;
for (Standard_Integer i=0; i< TheLength; i++) {
NIndex = Pixel(X+i,Y).Value() ;
if ( NIndex != PIndex ) {
PIndex = NIndex ;
PColor = myColorMap->FindEntry( PIndex ).Color() ;
}
PR->SetValue(i,PColor);
}
return PR ;
}
void Image_PseudoColorImage::SqueezedLookupTable(
const Aspect_IndexPixel& BasePixel,
Image_LookupTable& aLookup ) const
{ TColStd_SetOfInteger PixelSet ;
TColStd_SetIteratorOfSetOfInteger It;
Standard_Integer x, y, i, UpX, UpY ;
// Aspect_IndexPixel aPixel ;
//Image_LookupTable aLookup( 101 ) ;
// Aspect_ColorMapEntry aEntry;
UpX = UpperX() ;
UpY = UpperY() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
PixelSet.Add( Pixel( x, y ).Value() ) ;
}
}
#ifdef TRACE
cout << "Squeeze() PixelSet Extent :" << PixelSet.Extent() << endl ;
#endif
for (It.Initialize(PixelSet), i = BasePixel.Value() ;
It.More(); It.Next(), i++ ) {
aLookup.Bind( It.Value(), i ) ;
}
// Modif CAL 10/02/95: passage par argument car copie inaccessible.
// return( aLookup ) ;
}
Handle(Image_PseudoColorImage) Image_PseudoColorImage::Squeeze(
const Aspect_IndexPixel& BasePixel ) const
{ Handle(Image_PseudoColorImage) ret_image = NULL ;
Handle(Aspect_GenericColorMap) newcmap = NULL ;
Handle(Aspect_ColorMap) cmap = ColorMap() ;
TColStd_SetOfInteger PixelSet ;
TColStd_SetIteratorOfSetOfInteger It;
Standard_Integer x, y, i, UpX, UpY ;
// Aspect_IndexPixel aPixel ;
Image_LookupTable aLookup( 101 ) ;
Aspect_ColorMapEntry aEntry;
UpX = UpperX() ;
UpY = UpperY() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
PixelSet.Add( Pixel( x, y ).Value() ) ;
}
}
#ifdef TRACE
cout << "Squeeze() PixelSet Extent :" << PixelSet.Extent() << endl ;
#endif
if ( PixelSet.Extent() != 0 ) {
newcmap = new Aspect_GenericColorMap() ;
for (It.Initialize(PixelSet), i = BasePixel.Value() ;
It.More(); It.Next(), i++ ) {
aLookup.Bind( It.Value(), i ) ;
aEntry.SetValue( i, cmap->FindEntry( It.Value() ).Color() ) ;
newcmap->AddEntry( aEntry ) ;
}
ret_image = new Image_PseudoColorImage( LowerX(), LowerY(),
Width() , Height(),
newcmap );
ret_image->Fill( this ) ;
ret_image->Lookup( aLookup ) ;
}
return( ret_image ) ;
}
void Image_PseudoColorImage::Lookup( const Image_LookupTable& aLookup )
{ Standard_Integer x,y, UpX, UpY;
Aspect_IndexPixel val, lastval, newval;
UpX = UpperX() ;
UpY = UpperY() ;
val = Pixel( LowerX(), LowerY() ) ;
lastval = val ;
newval = aLookup.Find( lastval ) ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
val = Pixel( x, y ) ;
if ( !(val == lastval) ) {
lastval = val ;
newval = aLookup.Find( lastval ) ;
}
SetPixel( x, y , newval ) ;
}
}
}
void Image_PseudoColorImage::Rescale( const Standard_Real Scale,
const Standard_Real Offset )
{ Standard_Real S = Scale ;
Standard_Real O = Offset ;
Standard_Integer x,y, UpX, UpY, val;
UpX = UpperX() ;
UpY = UpperY() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
val = ( Standard_Integer ) ( Pixel(x, y).Value() * S + O ) ;
MutPixel( x, y ).SetValue( val ) ;
}
}
}
void Image_PseudoColorImage::Extrema( Aspect_IndexPixel& PMin,
Aspect_IndexPixel& PMax ) const
{ Standard_Integer x,y, UpX, UpY, min, max, val, lastval;
// Aspect_IndexPixel aPixel ;
UpX = UpperX() ;
UpY = UpperY() ;
max = IntegerFirst() ;
min = IntegerLast() ;
lastval = Pixel( LowerX(), LowerY() ).Value() ;
max = Max( max, lastval ) ;
min = Min( min, lastval ) ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
val = Pixel( x, y ).Value();
if ( val != lastval ) {
lastval = val ;
max = Max( max, lastval ) ;
min = Min( min, lastval ) ;
}
}
}
PMin.SetValue( min ) ;
PMax.SetValue( max ) ;
}
void Image_PseudoColorImage::Threshold( const Aspect_IndexPixel& PMin,
const Aspect_IndexPixel& PMax,
const Aspect_IndexPixel& PMap )
{ Standard_Integer x,y, UpX, UpY, min, max, val, map ;
Aspect_IndexPixel ThePixel ;
UpX = UpperX() ;
UpY = UpperY() ;
max = PMax.Value() ;
min = PMin.Value() ;
map = PMap.Value() ;
for ( y = LowerY() ; y <= UpY ; y++ ) {
for ( x = LowerX() ; x <= UpX ; x++ ) {
ThePixel = Pixel( x, y ) ;
val = Pixel( x, y ).Value();
if ( val >= min && val <= max ) {
MutPixel( x, y ).SetValue( map ) ;
}
}
}
}
#ifdef OLD
Handle(Standard_Transient) Image_PseudoColorImage::ShallowCopy() const {
return DeepCopy() ;
}
Handle(Standard_Transient) Image_PseudoColorImage::DeepCopy() const {
return Dup() ;
}
#endif