1 // Modified 27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
4 #include <Aspect_ColorRampColorMap.hxx>
5 #include <Standard_TypeMismatch.hxx>
6 #include <ImageUtility.ixx>
11 static Handle(Aspect_ColorRampColorMap) TheBWColorMap =
12 new Aspect_ColorRampColorMap(0,2,Quantity_Color(1.,1.,1.,Quantity_TOC_RGB));
14 static Handle(Aspect_ColorRampColorMap)& _TheBWColorMap() {
15 static Handle(Aspect_ColorRampColorMap) TheBWColorMap =
16 new Aspect_ColorRampColorMap(0,2,Quantity_Color(1.,1.,1.,Quantity_TOC_RGB));
19 #define TheBWColorMap _TheBWColorMap()
23 static void Rescale( const Handle(Image_PseudoColorImage) aPImage )
25 { Aspect_IndexPixel PMin, PMax ;
26 Standard_Integer dim, base ;
27 Quantity_Color aColor ;
28 Standard_Real scale, offset ; ;
30 Handle(Aspect_ColorRampColorMap)::
31 DownCast(aPImage->ColorMap())->ColorRampDefinition( base, dim, aColor );
33 aPImage->Extrema( PMin, PMax ) ;
35 if ( PMax.Value() == PMin.Value() ) return ;
37 scale = Standard_Real( dim-1 ) / Standard_Real( PMax.Value() - PMin.Value()) ;
38 offset = Standard_Real( base ) - Standard_Real( PMin.Value() ) * scale ;
40 aPImage->Rescale( scale, offset ) ;
44 Handle(Image_PseudoColorImage) ImageUtility::PixelColorDiff(
45 const Handle(Image_Image)& Image1,
46 const Handle(Image_Image)& Image2 )
48 return PixelColorDiff( Image1, Image2, TheBWColorMap ) ;
51 Handle(Image_PseudoColorImage) ImageUtility::PixelColorDiff(
52 const Handle(Image_Image)& Image1,
53 const Handle(Image_Image)& Image2,
54 const Handle(Aspect_ColorRampColorMap)& TheColorMap )
56 { Handle(Image_PseudoColorImage) RetImage = NULL ;
57 Standard_Integer x,y, Error, BasePixel, RampLength ;
58 Standard_Integer LX, LY, UX, UY ;
59 Standard_Integer LX1, LY1, UX1, UY1 ;
60 Standard_Integer LX2, LY2, UX2, UY2 ;
61 Aspect_IndexPixel aPixel;
62 Standard_Real r1,g1,b1, r2,g2,b2 ;
63 Quantity_Color aColor ;
65 TheColorMap->ColorRampDefinition( BasePixel, RampLength, aColor ) ;
67 Aspect_IndexPixel Pixel0(BasePixel);
68 Aspect_IndexPixel Pixel1(BasePixel+RampLength-1);
70 LX1 = Image1->LowerX() ;
71 LY1 = Image1->LowerY() ;
73 UX1 = Image1->UpperX() ;
74 UY1 = Image1->UpperY() ;
76 LX2 = Image2->LowerX() ;
77 LY2 = Image2->LowerY() ;
79 UX2 = Image2->UpperX() ;
80 UY2 = Image2->UpperY() ;
82 LX = Image1->LowerX() ; LX = Min( LX, Image2->LowerX() ) ;
83 LY = Image1->LowerY() ; LY = Min( LY, Image2->LowerY() ) ;
85 UX = Image1->UpperX() ; UX = Max( UX, Image2->UpperX() ) ;
86 UY = Image1->UpperY() ; UY = Max( UY, Image2->UpperY() ) ;
88 RetImage = new Image_PseudoColorImage( LX, LY,
93 if ( RampLength == 2 ) { //B&W ColorMap
94 for ( y = LY ; y <= UY ; y++ ) {
95 for ( x = LX ; x <= UX ; x++ ) {
96 if ( ( x >= LX1 && x >= LX2 ) && ( x <= UX1 && x <= UX2 ) &&
97 ( y >= LY1 && y >= LY2 ) && ( y <= UY1 && y <= UY2 ) ) {
98 if ( Image1->PixelColor(x,y) == Image2->PixelColor(x,y) ) {
99 RetImage->SetPixel( x,y, Pixel0 ) ;
106 for ( y = LY ; y <= UY ; y++ ) {
107 for ( x = LX ; x <= UX ; x++ ) {
108 if ( ( x >= LX1 && x >= LX2 ) && ( x <= UX1 && x <= UX2 ) &&
109 ( y >= LY1 && y >= LY2 ) && ( y <= UY1 && y <= UY2 ) ) {
110 Image1->PixelColor(x,y).Values( r1,g1,b1, Quantity_TOC_RGB ) ;
111 Image2->PixelColor(x,y).Values( r2,g2,b2, Quantity_TOC_RGB ) ;
116 Standard_Integer( (Abs(r1-r2)+Abs(g1-g2)+Abs(b1-b2))/3.
120 aPixel.SetValue( Error ) ;
122 RetImage->SetPixel( x,y, aPixel ) ;
126 Rescale( RetImage ) ;
132 void ImageUtility::PixelColorDiff(
133 const Handle(Image_Image)& Image1,
134 const Handle(Image_Image)& Image2,
135 const Handle(Aspect_ColorRampColorMap)& TheColorMap,
136 Handle(Image_PseudoColorImage)& RedDiff,
137 Handle(Image_PseudoColorImage)& GreenDiff,
138 Handle(Image_PseudoColorImage)& BlueDiff )
140 { Standard_Integer x,y, Error, BasePixel, RampLength ;
141 Standard_Integer LX, LY, UX, UY ;
142 Standard_Integer LX1, LY1, UX1, UY1 ;
143 Standard_Integer LX2, LY2, UX2, UY2 ;
144 Aspect_IndexPixel aPixel;
145 Standard_Real r1,g1,b1, r2,g2,b2 ;
146 Quantity_Color aColor ;
148 TheColorMap->ColorRampDefinition( BasePixel, RampLength, aColor ) ;
150 Aspect_IndexPixel Pixel0(BasePixel);
151 Aspect_IndexPixel Pixel1(BasePixel+RampLength-1);
153 LX1 = Image1->LowerX() ;
154 LY1 = Image1->LowerY() ;
156 UX1 = Image1->UpperX() ;
157 UY1 = Image1->UpperY() ;
159 LX2 = Image2->LowerX() ;
160 LY2 = Image2->LowerY() ;
162 UX2 = Image2->UpperX() ;
163 UY2 = Image2->UpperY() ;
165 LX = Image1->LowerX() ; LX = Min( LX, Image2->LowerX() ) ;
166 LY = Image1->LowerY() ; LY = Min( LY, Image2->LowerY() ) ;
168 UX = Image1->UpperX() ; UX = Max( UX, Image2->UpperX() ) ;
169 UY = Image1->UpperY() ; UY = Max( UY, Image2->UpperY() ) ;
171 RedDiff = new Image_PseudoColorImage( LX, LY,
172 (UX-LX)+1, (UY-LY)+1,
176 GreenDiff = new Image_PseudoColorImage( LX, LY,
177 (UX-LX)+1, (UY-LY)+1,
181 BlueDiff = new Image_PseudoColorImage( LX, LY,
182 (UX-LX)+1, (UY-LY)+1,
186 if ( RampLength == 2 ) { //B&W ColorMap
187 for ( y = LY ; y <= UY ; y++ ) {
188 for ( x = LX ; x <= UX ; x++ ) {
189 if ( ( x >= LX1 && x >= LX2 ) && ( x <= UX1 && x <= UX2 ) &&
190 ( y >= LY1 && y >= LY2 ) && ( y <= UY1 && y <= UY2 ) ) {
191 Image1->PixelColor(x,y).Values( r1,g1,b1, Quantity_TOC_RGB ) ;
192 Image2->PixelColor(x,y).Values( r2,g2,b2, Quantity_TOC_RGB ) ;
194 if ( r1 == r2 ) RedDiff->SetPixel ( x,y, Pixel0 ) ;
195 if ( g1 == g2 ) GreenDiff->SetPixel( x,y, Pixel0 ) ;
196 if ( b1 == b2 ) BlueDiff->SetPixel ( x,y, Pixel0 ) ;
202 for ( y = LY ; y <= UY ; y++ ) {
203 for ( x = LX ; x <= UX ; x++ ) {
204 if ( ( x >= LX1 && x >= LX2 ) && ( x <= UX1 && x <= UX2 ) &&
205 ( y >= LY1 && y >= LY2 ) && ( y <= UY1 && y <= UY2 ) ) {
206 Image1->PixelColor(x,y).Values( r1,g1,b1, Quantity_TOC_RGB ) ;
207 Image2->PixelColor(x,y).Values( r2,g2,b2, Quantity_TOC_RGB ) ;
209 Error = BasePixel + Standard_Integer( Abs(r1-r2)*(RampLength-1) );
211 aPixel.SetValue( Error ) ; RedDiff->SetPixel( x,y, aPixel ) ;
213 Error = BasePixel + Standard_Integer( Abs(g1-g2)*(RampLength-1) );
215 aPixel.SetValue( Error ) ; GreenDiff->SetPixel( x,y, aPixel ) ;
217 Error = BasePixel + Standard_Integer( Abs(b1-b2)*(RampLength-1) );
219 aPixel.SetValue( Error ) ; BlueDiff->SetPixel( x,y, aPixel ) ;
224 Rescale( GreenDiff ) ;
225 Rescale( BlueDiff ) ;