Remove AlienImage package. Clean up Image package.
t TKXMesh
n InterfaceGraphic
p AIS
-p AlienImage
p Aspect
p DsgPrs
p Graphic3d
------------------------------------------------------------
- SetTextureFileName( me: mutable;
- TextureFileName: AsciiString from TCollection)
+ SetTextureFileName( me: mutable;
+ TextureFileName: AsciiString from TCollection)
is virtual;
-
-
- ---Purpose : Sets the name of the texture file to map. The accepted
- -- file types are those used in AlienImage with extensions
- -- such as xwd, bmp, gif, rgb, ras, rs and more.
+ ---Purpose : Sets the name of the texture file to map. The accepted
+ -- file types are those used in Image_AlienPixMap with extensions
+ -- such as rgb, png, jpg and more.
------------------------------------------------------------
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-package AlienImage
-
- ---Purpose: This package allows importation of images
- -- from some other format into CAS.CADE format.
-
-uses
- Image,
- TColStd,
- TCollection,
- Aspect,
- OSD,
- MMgt
-
-is
-
- ------------------------
- ---Category: The classes
- ------------------------
-
- deferred class AlienImage;
- ---Purpose: Define the general methods on AlienImage
-
- deferred class AlienImageData ;
- ---Purpose: Internal Definition of AlienImage.
-
- deferred class AlienUserImage ;
- ---Purpose: Public Definition of AlienImage.
-
--- class PSAlienImage;
- ---Purpose: Definition of PostScript AlienImage.
-
- class SunRFAlienData;
- ---Purpose: Private definition of Sun Raster File .rs AlienImage.
-
- class SunRFAlienImage;
- ---Purpose: Public definition of Sun Raster File .rs AlienImage.
-
- class EuclidAlienData;
- ---Purpose: Private definition of Euclid .pix AlienImage.
-
- class EuclidAlienImage;
- ---Purpose: Public definition of Euclid .pix AlienImage.
-
- class SGIRGBAlienData;
- ---Purpose: Private definition of SGI .rgb AlienImage.
-
- class SGIRGBAlienImage;
- ---Purpose: Public definition of SGI .rgb AlienImage.
-
- class X11XWDAlienData;
- ---Purpose: Private definition X11 .xwd AlienImage .
-
- class XAlienImage;
- ---Purpose: Public definition X11 .xwd AlienImage.
-
- class AidaAlienData;
- ---Purpose: Private definition of Aida .i AlienImage .
-
- class AidaAlienImage;
- ---Purpose: Public definition of Aida .i AlienImage.
-
- class MemoryOperations;
- ---Purpose: A set of function to swap byte in memory, used for
- -- comaptibility between LSBFirst and MSBFirst .
-
-
-
-
- private class BMPAlienData;
- ---Purpose: Private definition of windows .bmp AlienImage.
-
- private class GIFAlienData;
- ---Purpose: Private definition of windows .gif AlienImage.
-
- class BMPAlienImage;
- ---Purpose: Public definition of windows .bmp AlienImage.
-
- class GIFAlienImage;
- ---Purpose: Public definition of windows .gif AlienImage.
-
-
-
-
- ---Category: Imported types:
- imported GIFLZWDict;
- imported BMPHeader;
-
- imported X11XColor ;
- imported X11XWDFileHeader ;
- imported SGIRGBFileHeader ;
- imported SUNRFFileHeader ;
-
- enumeration SUNRFFormat is SUNRF_Old,
- SUNRF_Standard,
- SUNRF_ByteEncoded,
- SUNRF_RGB,
- SUNRF_Unknown
- end SUNRFFormat ;
----Purpose: Type of code for a SUNRF image.
-
- ----------------------------
- ---Category: Package methods
- ----------------------------
- CreateImage (theFileName : AsciiString from TCollection;
- theImage : out Image from Image)
- returns Boolean from Standard;
- ---Purpose:
-
- CreateImage (theFileName : CString from Standard;
- theImage : out Image from Image)
- returns Boolean from Standard;
- ---Purpose:
-
- CreateImage (theFile : in out File from OSD;
- theImage : out Image from Image)
- returns Boolean from Standard;
- ---Purpose:
-
- LoadImageFile (anImageFile : CString from Standard;
- anImage : out Image from Image;
- aWidth : out Integer from Standard;
- aHeight : out Integer from Standard
- ) returns Boolean from Standard;
- ---Purpose: Used by plotter drivers
-
-end AlienImage;
-
+++ /dev/null
-// Created on: 1998-10-21
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-#include <AlienImage.hxx>
-#include <OSD_Path.hxx>
-#include <OSD_File.hxx>
-#include <OSD_Protection.hxx>
-#include <OSD_Environment.hxx>
-
-#include <Image_Image.hxx>
-#include <AlienImage_AlienUserImage.hxx>
-#include <AlienImage_XAlienImage.hxx>
-#include <AlienImage_SGIRGBAlienImage.hxx>
-#include <AlienImage_EuclidAlienImage.hxx>
-#include <AlienImage_SunRFAlienImage.hxx>
-#include <AlienImage_GIFAlienImage.hxx>
-#include <AlienImage_BMPAlienImage.hxx>
-
-//====================================================================
-static OSD_Environment& _CSF_DefaultImageFormat() {
- static OSD_Environment CSF_DefaultImageFormat("CSF_DefaultImageFormat");
- return CSF_DefaultImageFormat;
-}
-#define CSF_DefaultImageFormat _CSF_DefaultImageFormat()
-
-//====================================================================
-Standard_Boolean AlienImage::CreateImage (const TCollection_AsciiString& theFileName,
- Handle(Image_Image)& theImage)
-{
- OSD_File file = OSD_File (OSD_Path (theFileName));
- return AlienImage::CreateImage (file, theImage);
-}
-
-//====================================================================
-Standard_Boolean AlienImage::CreateImage (const Standard_CString theFileName,
- Handle(Image_Image)& theImage)
-{
- OSD_File file = OSD_File (OSD_Path (TCollection_AsciiString (theFileName)));
- return AlienImage::CreateImage (file, theImage);
-}
-
-//====================================================================
-Standard_Boolean AlienImage::CreateImage (OSD_File& theFile,
- Handle(Image_Image)& theImage)
-{
- OSD_Protection theProtection (OSD_R, OSD_R, OSD_R, OSD_R);
- OSD_Path thePath;
- theFile.Path (thePath);
- TCollection_AsciiString theExtension = thePath.Extension();
- theExtension.UpperCase ();
-
- Handle(AlienImage_AlienUserImage) theAlienImage;
-
- theFile.Open (OSD_ReadOnly, theProtection);
- if (theFile.IsOpen()) {
- if (theExtension.IsEqual (".XWD"))
-_CreateXWD:
- theAlienImage = new AlienImage_XAlienImage ();
- else if (theExtension.IsEqual (".RGB"))
-_CreateRGB:
- theAlienImage = new AlienImage_SGIRGBAlienImage ();
- else if (theExtension.IsEqual (".RS"))
-_CreateRS:
- theAlienImage = new AlienImage_SunRFAlienImage ();
- else if (theExtension.IsEqual (".PIX"))
-_CreatePIX:
- theAlienImage = new AlienImage_EuclidAlienImage ();
- else if (theExtension.IsEqual (".GIF"))
-_CreateGIF:
- theAlienImage = new AlienImage_GIFAlienImage ();
- else if (theExtension.IsEqual (".BMP"))
-_CreateBMP:
- theAlienImage = new AlienImage_BMPAlienImage ();
-
- else if (theExtension.IsEmpty ()) {
- // Trye to read $CSF_DefaultImageFormat environment
- TCollection_AsciiString theDefExt = CSF_DefaultImageFormat.Value();
- theDefExt.Prepend (".");
- thePath.SetExtension (theDefExt);
- theExtension = theDefExt;
- theExtension.UpperCase ();
- if (theExtension.IsEqual (".XWD")) goto _CreateXWD;
- else if (theExtension.IsEqual (".RGB")) goto _CreateRGB;
- else if (theExtension.IsEqual (".RS")) goto _CreateRS;
- else if (theExtension.IsEqual (".PIX")) goto _CreatePIX;
- else if (theExtension.IsEqual (".GIF")) goto _CreateGIF;
- else if (theExtension.IsEqual (".BMP")) goto _CreateBMP;
- else return Standard_False;
- } else {
- return Standard_False;
- }
-
- if (!theAlienImage -> Read (theFile)) {
- theFile.Close ();
- return Standard_False;
- }
-
- theImage = theAlienImage -> ToImage ();
- theFile.Close ();
- return (!theImage.IsNull());
- }
- return Standard_False;
-}
-
-//====================================================================
-Standard_Boolean AlienImage::LoadImageFile(const Standard_CString anImageFile,
- Handle(Image_Image)& myImage,
- Standard_Integer& aWidth,
- Standard_Integer& aHeight)
-{
- // Try to load new image
- myImage.Nullify ();
- if (AlienImage::CreateImage (anImageFile, myImage)) {
- // New image loaded
-//_ExitOK:
- aWidth = myImage -> Width ();
- aHeight = myImage -> Height ();
- return Standard_True;
- } else {
- // Could not load new image
-//_ExitError:
- myImage.Nullify ();
- aWidth = aHeight = 0;
- return Standard_False;
- }
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class AidaAlienData from AlienImage inherits AlienImageData from AlienImage
-
- ---Version: 0.0
-
- ---Level: Public
- ---Purpose: This class defines an Aida Alien image.
-
-
-uses
- File from OSD,
- ColorImage from Image,
- PseudoColorImage from Image,
- ColorMap from Aspect,
- HArray2OfInteger from TColStd,
- DitheringMethod from Image,
- Image from Image
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable AidaAlienData from AlienImage ;
-
- Clear( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by AidaAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a AidaAlienData object from a file .
- -- Returns True if file is a Aida file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a AidaAlienData object to a file .
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Purpose : Converts a AidaAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Purpose : Converts a Image object to a AidaAlienData object.
-
- SetColorImageDitheringMethod( me : in out mutable ;
- aMethod : DitheringMethod from Image;
- aColorMap : ColorMap from Aspect ) ;
-
- ---Level: Public
- ---Purpose: Set the ImageDitheringMethod and the ColorMap when
- -- FromImage is called with a ColorImage .
- -- Aida BYTEMAPS file handle only PseudoColorImage .
- -- Default value is DM_NearestColor,
- -- ColorCubeColorMap( 40, 5,1, 8,6, 3,54 )
-
-
- AllocData( me : in out mutable ; DX,DY : in Integer from Standard )
- is private;
- ---Level: Internal
- ---Purpose : Allocate HArray2 to store Image data
-
- Pixel ( me : in immutable ; X,Y : in Integer from Standard )
- returns Integer from Standard
- raises OutOfRange from Standard is private ;
- ---Level: Internal
-
- SetPixel( me : in out mutable; X,Y : in Integer from Standard ;
- Value : in Integer from Standard )
- raises OutOfRange from Standard is private ;
- ---Level: Internal
-
- FromPseudoColorImage( me : in out mutable;
- anImage : in PseudoColorImage from Image )
- is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a AidaAlienData object.
-
- FromColorImage( me : in out mutable;
- anImage : in ColorImage from Image)
- is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a AidaAlienData object.
-
-fields
- myDitheringMethod : DitheringMethod from Image is protected ;
-
- myDitheringColorMap : ColorMap from Aspect is protected ;
-
- myColors : ColorMap from Aspect is protected ;
- myColorsIsDef : Boolean from Standard is protected ;
-
- -- AidaColors definition
- myData : HArray2OfInteger from TColStd ;
- myDataIsDef : Boolean from Standard is protected ;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#define TEST //GG_140699
-// Check file extension, must be ".aida".
-
-#include <TCollection_AsciiString.hxx>
-#include <Image_Convertor.hxx>
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_ColorCubeColorMap.hxx>
-#include <AlienImage_AidaAlienData.ixx>
-#include <Aspect_ColorMapEntry.hxx>
-
-# include <stdio.h>
-
-#ifdef TRACE
-static int Verbose = 0 ;
-#endif
-
-
-AlienImage_AidaAlienData::AlienImage_AidaAlienData()
-
-{
- myDataIsDef = Standard_False ;
- myColorsIsDef = Standard_False ;
- myDitheringColorMap = new Aspect_ColorCubeColorMap( 40, 5,1, 8,6, 3,54 ) ;
- myDitheringMethod = Image_DM_NearestColor ;
-}
-
-void AlienImage_AidaAlienData::Clear()
-
-{
- myDataIsDef = Standard_False ;
- myColorsIsDef = Standard_False ;
-}
-
-Standard_Boolean AlienImage_AidaAlienData::Write( OSD_File& file ) const
-
-{ Standard_Integer r,c ;
- TCollection_AsciiString out ;
- char hexa[3] ;
- unsigned char p ;
- unsigned long int rc,gc,bc ;
- TCollection_AsciiString Space = " " ;
-
- if ( ! myDataIsDef ) return( Standard_False ) ;
- if ( ! myColorsIsDef ) return( Standard_False ) ;
-
- out = TCollection_AsciiString( "#BC(" ) +
- TCollection_AsciiString( myData->RowLength() ) +
- Space +
- TCollection_AsciiString( myData->ColLength() ) +
- TCollection_AsciiString( " #[\n" ) ;
-
- file.Write( out, out.Length() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- for ( r = myData->LowerRow() ; r <= myData->UpperRow() ; r++ ) {
- out = TCollection_AsciiString( "#*" ) ;
- for ( c = myData->LowerCol() ; c <= myData->UpperCol() ; c++ ) {
- p = ( unsigned char ) myData->Value( r, c ) ;
- sprintf( hexa , "%.2x", p ) ;
- out += TCollection_AsciiString( hexa ) ;
- }
- out += TCollection_AsciiString( "\n" ) ;
-
- file.Write( out, out.Length() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
-
- out = TCollection_AsciiString( "](\n" ) ;
-
- file.Write( out, out.Length() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- // write out the color map buffer
- for ( c = 1 ; c <= myColors->Size() ; c++ ) {
- rc = (long unsigned int )( myColors->Entry(c).Color().Red() * 32767 + 0.5 );
- gc = (long unsigned int )( myColors->Entry(c).Color().Green() * 32767 + 0.5 );
- bc = (long unsigned int )( myColors->Entry(c).Color().Blue() * 32767 + 0.5 );
-
- out = TCollection_AsciiString( "#[" ) +
- TCollection_AsciiString( myColors->Entry(c).Index() ) + Space +
- TCollection_AsciiString( Standard_Integer(rc) ) + Space +
- TCollection_AsciiString( Standard_Integer(gc) ) + Space +
- TCollection_AsciiString( Standard_Integer(bc) ) + Space +
- TCollection_AsciiString( "()]\n" ) ;
-
- file.Write( out, out.Length() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- }
-
- out = TCollection_AsciiString( "))" ) ;
-
- file.Write( out, out.Length() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- return( Standard_True ) ;
-
-}
-
-
-Standard_Boolean AlienImage_AidaAlienData::Read( OSD_File& file )
-
-{ TCollection_AsciiString tmp, in ;
- Standard_Integer loc1, loc2, width, height, i, bblcount, l ,value ;
- TCollection_AsciiString HexaSet = "0123456789ABCDEFabcdef" ;
- int r,g,b,pixel,status ;
- Handle(Aspect_GenericColorMap) GenCmap = NULL ;
-
-#ifdef TEST
- OSD_Path path; file.Path(path);
- TCollection_AsciiString ext = path.Extension(); ext.LowerCase();
- if( ext != ".aida" ) {
- TCollection_AsciiString sysname; path.SystemName(sysname);
-#ifdef TRACE
- cout << " *** AlienImage_AidaAlienData::Read('" << sysname << "'). must have an '.aida' extension" << endl;
-#endif
- return Standard_False;
- }
-#endif
-
- Clear() ;
-
- // Extract AidaBYTEMAPS type "#BC"
-
- // Get "#"
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "#" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get "BC"
- file.Read( tmp, 2 ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- if ( tmp != TCollection_AsciiString( "BC" ) ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get "(" Start of AidaBYTEMAPS size definition
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "(" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- // Get "#" Start of AidaBYTEMAPS Pixel definition
- in.Clear() ;
-
- do {
- file.Read( tmp, 1) ;
-
- if ( tmp.IsAscii() ) {
- in += tmp ;
- }
- } while( !file.Failed() && tmp != TCollection_AsciiString( "#" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- // Extract Image size in "Width Height #"
-
- loc1 = 1 ;
-
- if ( ( loc2 = in.Location( 1, ' ', loc1, in.Length() ) ) == 0 ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( ( loc1 ) > ( loc2-1 ) ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- tmp = in.SubString( loc1, loc2-1 ) ;
-
- if ( !tmp.IsIntegerValue() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( ( width = tmp.IntegerValue() ) <= 0 ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- tmp = in.SubString( loc2, in.Length()-1 ) ;
-
- if ( !tmp.IsIntegerValue() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- if ( ( height = tmp.IntegerValue() ) <= 0 ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
-#ifdef TRACE
- if ( Verbose )
- cout << "Width,Height :" << width << "," << height << endl << flush ;
-#endif
-
- AllocData( width, height ) ;
-
- // Get "[" start of AidaBYTEMAPS Pixel definition
-
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "[" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- // Extract Pixel lines "#*................."
- in.Clear() ;
-
- for ( i = 0 ; i < height ; i++ ) {
-
- // Get "#"
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "#" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get "*"
- file.Read( tmp, 1) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( tmp != TCollection_AsciiString( "*" ) ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get Pixel line
- bblcount = 0 ;
- in.Clear() ;
-
- while ( bblcount < (2*width) ) {// Two byte per PIXEL
- file.Read( tmp, 1) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( tmp.IsAscii() ) {
- if ( tmp.FirstLocationInSet( HexaSet, 1, 1 ) ) {
- in += tmp ; bblcount++ ;
- }
- else {
- // Get Next line character before end of current line
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
- }
- }
-
-#ifdef TRACE
- if ( Verbose )
- cout << "Get one line :\"" << in << "\"\n" << flush ;
-#endif
-
- for ( l = 0 ; l < in.Length() ; l += 2 ) {
- tmp = in.SubString( l+1, l+2 ) ;
-
- value = ( Standard_Integer )strtol( tmp.ToCString(), NULL, 16 );
-
- SetPixel( l/2 , i, value ) ;
-#ifdef TRACE
- if ( Verbose > 1 )
- cout << "SetPixel(" << l/2 << "," << i << "," << value << ")\n" <<flush;
-#endif
- }
- }
-
- // Get "]" end of Aida image data
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "]" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get "(" start of Aida colors definition or ")" end of Aida ByteMaps
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() &&
- tmp != TCollection_AsciiString( "(" ) &&
- tmp != TCollection_AsciiString( ")" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( tmp == TCollection_AsciiString( ")" ) ) {
- return( Standard_True ) ; // No Color definition ERROR ??
- }
-
- // Find Color definition "#[ Red Green Blue ... ]" color is from 0->32767
-
- myColors = GenCmap = new Aspect_GenericColorMap() ;
- myColorsIsDef = Standard_True ;
-
- do {
- // Get "#" start of a Aida color definition or
- // Get ")" end of Aida colors definition
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() &&
- tmp != TCollection_AsciiString( "#" ) &&
- tmp != TCollection_AsciiString( ")" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- if ( tmp == TCollection_AsciiString( "#" ) ) {
-
- // Get "[" start of a Aida color definition
- do {
- file.Read( tmp, 1) ;
- } while( !file.Failed() && tmp != TCollection_AsciiString( "[" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- // Get "]" end of a Aida color definition
- in.Clear() ;
-
- do {
- file.Read( tmp, 1) ;
- if ( tmp.IsAscii() && tmp != TCollection_AsciiString( "]" ) ) {
- in += tmp ;
- }
- } while( !file.Failed() && tmp != TCollection_AsciiString( "]" ) ) ;
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
- status = sscanf( in.ToCString(), "%d %d %d %d", &pixel,&r,&g,&b ) ;
-
- if ( status == 4 ) {
- GenCmap->AddEntry(
- Aspect_ColorMapEntry( pixel,
- Quantity_Color( r/32767.,g/32767.,b/32767.,
- Quantity_TOC_RGB ) ) ) ;
-
- }
-
-#ifdef TRACE
- if ( Verbose )
- cout << in << endl << flush ;
-#endif
- }
-
- } while ( !file.Failed() && tmp != TCollection_AsciiString( ")" ) ) ;
-
-
- if ( file.Failed() ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ; // ERROR
- }
-
-
- return( Standard_True ) ;
-
-}
-
-Handle_Image_Image AlienImage_AidaAlienData::ToImage() const
-
-{ Standard_Integer x,y ;
- Handle(Image_PseudoColorImage) aPImage =
- new Image_PseudoColorImage( 0, 0,
- myData->RowLength(), myData->ColLength(),
- myColors );
-
- for( y = 0 ; y < aPImage->Height() ; y++ ) {
- for( x = 0 ; x < aPImage->Width() ; x++ ) {
- aPImage->SetPixel( aPImage->LowerX()+x,
- aPImage->LowerY()+y, Pixel( x, y ) ) ;
- }
- }
-
- return aPImage ;
-}
-
-void AlienImage_AidaAlienData::FromImage( const Handle_Image_Image& anImage )
-
-{ if ( anImage->IsInstance(STANDARD_TYPE(Image_PseudoColorImage)) ) {
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage) ;
-
- FromPseudoColorImage( aPImage ) ;
- }
- else if ( anImage->IsInstance(STANDARD_TYPE(Image_ColorImage)) ) {
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage) ;
-
- FromColorImage( aCImage ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a unknown Image_Image type to a AidaAlienData");
- }
-}
-
-void AlienImage_AidaAlienData::SetColorImageDitheringMethod(
- const Image_DitheringMethod aMethod ,
- const Handle(Aspect_ColorMap)& aColorMap )
-
-{ myDitheringMethod = aMethod ; myDitheringColorMap = aColorMap ; }
-
-//------------------------------------------------------------------------------
-// Private Method
-//------------------------------------------------------------------------------
-
-
-void AlienImage_AidaAlienData::FromPseudoColorImage(
- const Handle_Image_PseudoColorImage& anImage)
-
-{ Standard_Integer x,y ;
-
- AllocData( anImage->Width(), anImage->Height() ) ;
-
- myColors = anImage->ColorMap() ;
- myColorsIsDef = Standard_True ;
-
- for ( y = 0 ; y < anImage->Height() ; y++ ) {
- for ( x = 0 ; x < anImage->Width() ; x++ ) {
- SetPixel( x,
- y,
- anImage->Pixel( anImage->LowerX()+x,
- anImage->LowerY()+y ).Value() ) ;
- }
- }
-}
-
-void AlienImage_AidaAlienData::FromColorImage(
- const Handle_Image_ColorImage& anImage)
-
-{ Image_Convertor Convertor ;
-
- Handle(Image_PseudoColorImage) aPImage =
- new Image_PseudoColorImage( anImage->LowerX(), anImage->LowerY(),
- anImage->Width(), anImage->Height(),
- myDitheringColorMap ) ;
-
- Convertor.SetDitheringMethod( myDitheringMethod ) ;
-
- aPImage = Convertor.Convert( anImage, myDitheringColorMap ) ;
-
- FromPseudoColorImage( aPImage ) ;
-}
-
-void AlienImage_AidaAlienData::AllocData(
- const Standard_Integer dx,
- const Standard_Integer dy )
-{
- myData = new TColStd_HArray2OfInteger( 0, dy-1 , 0, dx-1 ) ;
- myDataIsDef = Standard_True ;
-}
-
-void AlienImage_AidaAlienData::SetPixel(
- const Standard_Integer x,
- const Standard_Integer y,
- const Standard_Integer value )
-{
- myData->SetValue( y, x, value ) ;
-}
-
-Standard_Integer AlienImage_AidaAlienData::Pixel(
- const Standard_Integer x, const Standard_Integer y ) const
-
-{ return myData->Value( y, x ) ; }
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
-
-class AidaAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines an Aida Alien image ( BYTEMAPS ).
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- ColorMap from Aspect,
- Image from Image,
- DitheringMethod from Image,
- AidaAlienData from AlienImage
-
-is
- Create returns mutable AidaAlienImage from AlienImage;
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by AidaAlienImage
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : convert a AidaAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : convert a Image object to a AidaAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a AidaAlienImage object from a file .
- -- Returns True if file is a Aida file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a AidaAlienImage object to a file .
-
- SetColorImageDitheringMethod( me : in out mutable ;
- aMethod : DitheringMethod from Image;
- aColorMap : ColorMap from Aspect ) ;
-
- ---Level: Public
- ---Purpose: Set the ImageDitheringMethod and the ColorMap when
- -- FromImage is called with a ColorImage .
- -- Aida BYTEMAPS file handle only PseudoColorImage .
- -- Default value is DM_NearestColor,
- -- ColorCubeColorMap( 40, 5,1, 8,6, 3,54 )
-
-fields
- myData : AidaAlienData from AlienImage;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-#include <stdio.h>
-
-#include <AlienImage_XAlienImage.hxx>
-#include <OSD_Protection.hxx>
-#include <OSD_File.hxx>
-#include <AlienImage_AidaAlienImage.ixx>
-
-AlienImage_AidaAlienImage::AlienImage_AidaAlienImage()
-
-{ // il faut faire un new si mydata est du type HANDLE
- myData = new AlienImage_AidaAlienData() ;
-}
-
-void AlienImage_AidaAlienImage::Clear()
-
-{ myData->Clear() ; }
-
-Standard_Boolean AlienImage_AidaAlienImage::Write( OSD_File& file ) const
-
-{ return( myData->Write( file ) ) ; }
-
-Standard_Boolean AlienImage_AidaAlienImage::Read( OSD_File& file )
-
-{ return( myData->Read( file ) ) ; }
-
-Handle(Image_Image) AlienImage_AidaAlienImage::ToImage() const
-
-{ return( myData->ToImage() ) ; }
-
-void AlienImage_AidaAlienImage::FromImage( const Handle(Image_Image)& anImage )
-
-{ myData->FromImage( anImage ) ; }
-
-
-void AlienImage_AidaAlienImage::SetColorImageDitheringMethod(
- const Image_DitheringMethod aMethod ,
- const Handle(Aspect_ColorMap)& aColorMap )
-
-{ myData->SetColorImageDitheringMethod( aMethod, aColorMap ) ; }
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL,JLF
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-deferred class AlienImage from AlienImage inherits TShared from MMgt
-
- ---Purpose: This class defines an Alien image.
- -- Alien Image is X11 .xwd image or SGI .rgb image for example
-
-uses
- File from OSD,
- Image from Image
-
-raises
- TypeMismatch from Standard
-
-is
- Initialize ;
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard is deferred;
- ---Level: Public
- ---Purpose: Reads content of a AlienImage object from a file .
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable ; afile : in out File from OSD )
- returns Boolean from Standard is deferred ;
- ---Level: Public
- ---Purpose: Writes content of a AlienImage object to a file .
-
- ToImage ( me : in immutable )
- returns mutable Image from Image
- raises TypeMismatch from Standard is deferred ;
- ---Level: Public
- ---Purpose : Converts a AlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard is deferred ;
- ---Level: Public
- ---Purpose : Converts a Image object to a AlienImage object.
-
-end AlienImage;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_AlienImage.ixx>
-
-AlienImage_AlienImage::AlienImage_AlienImage()
-{
-#ifdef TRACE
- cout << "AlienImage_AlienImage constructor \n" ;
-#endif
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL,JLF
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: DCB (20-OCT-98)
--- Define Name()/SetName() as deferred.
-
-deferred class AlienImageData from AlienImage inherits AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines an Alien image.
- -- Alien Image is X11 . xwd image or SGI .rgb image for examples
-
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- AsciiString from TCollection
-
-is
- Initialize ;
-
- SetName( me : in out mutable;
- aName : in AsciiString from TCollection)
- is virtual;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection
- is virtual;
- ---C++: return const &
- ---Level: Public
- ---Purpose: get Image name .
-
-fields
- myName: AsciiString from TCollection is protected;
-
-end AlienImageData;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_AlienImageData.ixx>
-
-AlienImage_AlienImageData::AlienImage_AlienImageData()
-{
-#ifdef TRACE
- cout << "AlienImage_AlienImageData constructor \n" ;
-#endif
-}
-
-void AlienImage_AlienImageData::SetName (const TCollection_AsciiString& aName)
-{
- myName = aName + TCollection_AsciiString ("\0");
-}
-
-const TCollection_AsciiString& AlienImage_AlienImageData::Name () const
-{
- return myName;
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL,JLF
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: DCB (20-OCT-98)
--- Define ToImage()/FromName() as deferred.
-
-deferred class AlienUserImage from AlienImage inherits AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines an Alien user image.
- -- Alien Image is X11 .xwd image or SGI .rgb image for examples
-
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- Image from Image,
- File from OSD
-
-raises
- TypeMismatch from Standard
-
-is
- Initialize ;
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard is deferred;
- ---Level: Public
- ---Purpose: Read content of a UserAlienImage object from a file .
- -- Returns True if sucess .
-
- Read ( me : in out mutable ; afile : in CString from Standard )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a UserAlienImage object from a file .
- -- Returns True if file is a AlienImage file .
-
- Write ( me : in immutable ; afile : in out File from OSD )
- returns Boolean from Standard is deferred ;
- ---Level: Public
- ---Purpose: Write content of a UserAlienImage object to a file .
-
- Write ( me : in immutable ; afile : in CString from Standard )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a UserAlienImage object to a file .
-
- ToImage ( me : in immutable )
- returns mutable Image from Image
- raises TypeMismatch from Standard
- is deferred;
- ---Level: Public
- ---Purpose : convert a AidaAlienData object to a Image object.
-
- FromImage ( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard
- is deferred;
- ---Level: Public
- ---Purpose : convert a Image object to a AidaAlienData object.
-
-end AlienUserImage;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <OSD_Process.hxx>
-#include <OSD_Protection.hxx>
-#include <AlienImage_XAlienImage.hxx>
-#include <AlienImage_AlienUserImage.ixx>
-#include <OSD_File.hxx>
-#include <OSD_Path.hxx>
-
-AlienImage_AlienUserImage::AlienImage_AlienUserImage()
-{
-#ifdef TRACE
- cout << "AlienImage_AlienUserImage constructor \n" ;
-#endif
-}
-
-#ifdef IMPLEMENTED
-AlienImage_AlienUserImage::AlienImage_AlienUserImage(
- const Standard_CString afile,
- Standard_Boolean& Success )
-{
-#ifdef TRACE
- cout << "AlienImage_AlienUserImage constructor \n" ;
-#endif
-
- Success = Read( afile ) ;
-}
-
-AlienImage_AlienUserImage::AlienImage_AlienUserImage(
- const Handle(Image_Image)& anImage)
-{
-#ifdef TRACE
- cout << "AlienImage_AlienUserImage constructor \n" ;
-#endif
-
- FromImage( anImage ) ;
-}
-#endif
-
-Standard_Boolean AlienImage_AlienUserImage::Read( const Standard_CString file )
-{ OSD_File File ;
- OSD_Protection Protection ;
- OSD_Path Path;
- Standard_Boolean Ret ;
-
- Protection.SetValues( OSD_R, OSD_R, OSD_R, OSD_R ) ;
- Path = OSD_Path( TCollection_AsciiString( file ),OSD_Default);
- File.SetPath ( Path ); // Instanciate
- File.Open ( OSD_ReadOnly, Protection ) ;
-
- Ret = Read( File ) ;
-
- File.Close() ;
-
- return( Ret ) ;
-}
-
-Standard_Boolean AlienImage_AlienUserImage::Write(
- const Standard_CString file)const
-
-{ OSD_File File ;
- OSD_Protection Protection ;
- OSD_Path Path;
- Standard_Boolean Ret ;
-
- Protection.SetValues( OSD_RW, OSD_RW, OSD_RW, OSD_RW ) ;
- Path = OSD_Path( TCollection_AsciiString( file ),OSD_Default);
- File.SetPath ( Path ); // Instanciate
- File.Build ( OSD_WriteOnly, Protection ) ;
-
- Ret = Write( File ) ;
-
- File.Close() ;
-
- return( Ret ) ;
-}
-
+++ /dev/null
--- Created on: 1998-10-20
--- Created by: DCB
--- Copyright (c) 1998-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-private class BMPAlienData from AlienImage inherits AlienImageData from AlienImage
-
-uses
- File from OSD,
- GenericColorMap from Aspect,
- PseudoColorImage from Image,
- ColorImage from Image,
- Image from Image
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable BMPAlienData from AlienImage ;
-
- Clear( me : in out mutable );
- ---Level: Public
- ---Purpose: Frees memory allocated by BMPAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard;
- ---Level: Public
- ---Purpose: Read content of a BMPAlienData object from a file
- -- Returns True if file is a BMP file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard;
- ---Level: Public
- ---Purpose: Write content of a BMPAlienData object to a file
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a BMPAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a BMPAlienData object.
-
- ------------------------------------------------------
- --- Private methods
- ------------------------------------------------------
- FromPseudoColorImage (me : in out mutable;
- anImage : in PseudoColorImage from Image )
- is private;
- ---Level: Internal
- ---Purpose : convert a Image object to a GIFAlienData object.
-
- FromColorImage (me : in out mutable;
- anImage : in ColorImage from Image)
- is private;
- ---Level: Internal
- ---Purpose : convert a Image object to a GIFAlienData object.
-
-fields
- myColorMap : GenericColorMap from Aspect;
- myData : Address from Standard; --BYTE* or DWORD*
- myWidth : Integer from Standard;
- myHeight : Integer from Standard;
-
-end;
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Notes:
-// Read()/Write() code is taken from ZOV's sources from Xw package.
-
-// include windows.h first to ensure that it is loaded completely
-#ifdef WNT
-#include <windows.h>
-#endif
-
-#include <AlienImage_BMPAlienData.ixx>
-#include <AlienImage_BMPHeader.hxx>
-#include <Aspect_ColorMap.hxx>
-#include <Aspect_ColorMapEntry.hxx>
-#include <Quantity_Color.hxx>
-#include <Image_PseudoColorImage.hxx>
-#include <Image_ColorImage.hxx>
-#include <OSD_FromWhere.hxx>
-#include <Standard.hxx>
-
-static unsigned long __swaptest = 1;
-
-WORD static _TestSwapWORD (WORD __w)
-{
- return LOW_VAL_AT_LOW_ADDR ? __w:
- ((__w&0xFF) << 8) | ((__w&0xFF00) >> 8);
-}
-
-DWORD static _TestSwapDWORD (DWORD __dw)
-{
- return LOW_VAL_AT_LOW_ADDR ? __dw:
- ((__dw&0x000000FF) << 24) | ((__dw&0x0000FF00) << 8)
- | ((__dw&0xFF0000) >> 8) | ((__dw&0xFF000000) >> 24);
-}
-
-#define STGMGR_ALLOC(size) Standard::Allocate(size)
-#define STGMGR_FREE(buf,size) Standard::Free((void*&)buf)
-#define BPIXEL ((BYTE *) myData)
-#define DWPIXEL ((DWORD*) myData)
-
-//================================================================
-AlienImage_BMPAlienData::AlienImage_BMPAlienData ()
- : AlienImage_AlienImageData ()
-{
- myData = NULL;
- myWidth = 0;
- myHeight = 0;
- myColorMap.Nullify ();
-}
-
-//================================================================
-void AlienImage_BMPAlienData::Clear ()
-{
- if (myData) {
- STGMGR_FREE (myData, (!myColorMap.IsNull() ? myWidth*myHeight :
- myWidth*myHeight*4));
- myData = NULL;
- }
- myWidth = 0;
- myHeight = 0;
- myColorMap.Nullify ();
-}
-
-//================================================================
-Standard_Boolean AlienImage_BMPAlienData::Read (OSD_File& file)
-{
- BYTE *pData = NULL, *pbData=NULL; // pointer to bitmap pixels
- BYTE *ptrByte;
- int i, isize, ncolors, bytes_per_line, x, y, width, height;
- DWORD dwRMask, dwGMask, dwBMask, dwSize;
- int nRMult, nGMult, nBMult;
- int isInsideOut, hasMask, nBitCount;
- int iCompression, isOS2Format, hasColormap;
- int nBytes, iDataSize;
- char bmpSign[2];
- AlienImage_BMPHeader bmfh; // Standard BMP file header
- BITMAPINFOHEADER bmih; // Windows BMP header
- BITMAPCOREHEADER bmch; // OS/2 BMP header
- Standard_Address lpVoid;
- Quantity_Color color;
- Standard_Real r, g, b;
- Aspect_ColorMapEntry entry;
-
- RGBQUAD* pColors256 = (RGBQUAD*) STGMGR_ALLOC (sizeof(RGBQUAD)*256);
-
- // Check 'BM' signature
- file.Seek (0, OSD_FromBeginning);
- lpVoid = Standard_Address(&bmpSign[0]);
- file.Read ((void*&)lpVoid, 2, nBytes);
- if (file.Failed () || strncmp (bmpSign, "BM", 2) || nBytes != 2) {
-// cout << "AlienImage_BMPAlienData::Read() : 'BM' signature not found."
-// << endl << flush;
- goto _ExitReadError;
- }
-
- lpVoid = Standard_Address(&bmfh);
- file.Read ((void*&)lpVoid, sizeof(AlienImage_BMPHeader), nBytes);
- if (file.Failed () || nBytes != sizeof(AlienImage_BMPHeader)) {
- cout << "AlienImage_BMPAlienData::Read() : Reading AlienImage_BMPHeader."
- << endl << flush;
- goto _ExitReadError;
- }
-
- lpVoid = Standard_Address (&dwSize);
- file.Read ((void*&)lpVoid, sizeof (DWORD), nBytes);
- if (file.Failed() || nBytes != sizeof (DWORD)) {
- cout << "AlienImage_BMPAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
- file.Seek (-(int)sizeof(DWORD), OSD_FromHere);
-
- isOS2Format = _TestSwapDWORD(dwSize) == sizeof (BITMAPCOREHEADER);
- if (isOS2Format) {
- lpVoid = Standard_Address(&bmch);
- file.Read ((void*&)lpVoid, sizeof(BITMAPCOREHEADER), nBytes);
- if (file.Failed() || nBytes != sizeof(BITMAPCOREHEADER)) {
- cout << "AlienImage_BMPAlienData::Read() : Reading BITMAPCOREHEADER."
- << endl << flush;
- goto _ExitReadError;
- }
- } else {
- lpVoid = Standard_Address(&bmih);
- file.Read ((void*&)lpVoid, sizeof(BITMAPINFOHEADER), nBytes);
- if (file.Failed() || nBytes != sizeof(BITMAPINFOHEADER)) {
- cout << "AlienImage_BMPAlienData::Read() : Reading BITMAPINFOHEADER."
- << endl << flush;
- goto _ExitReadError;
- }
- }
-
- nBitCount = _TestSwapWORD (isOS2Format ? bmch.bcBitCount: bmih.biBitCount);
- if ((nBitCount != 1 && nBitCount != 4 && nBitCount != 8 &&
- nBitCount != 16 && nBitCount != 24 && nBitCount != 32) ||
- isOS2Format && (nBitCount == 16 || nBitCount == 32)) {
- cout << "AlienImage_BMPAlienData::Read() : Bad <nBitCount> value :"
- << nBitCount << " " << isOS2Format << endl << flush;
- goto _ExitReadError;
- }
-
- iCompression = isOS2Format ? BI_RGB: _TestSwapDWORD (bmih.biCompression);
- hasColormap = nBitCount <= 8;
- hasMask = iCompression == BI_BITFIELDS;
- ncolors = hasColormap ? 1 << nBitCount: 0;
- width = isOS2Format ? _TestSwapWORD (bmch.bcWidth)
- : _TestSwapDWORD (bmih.biWidth);
- height = isOS2Format ? _TestSwapWORD (bmch.bcHeight)
- : _TestSwapDWORD (bmih.biHeight);
- isInsideOut = !isOS2Format && height < 0;
- height = isInsideOut ? -height: height;
- bytes_per_line = width * nBitCount;
- bytes_per_line = (bytes_per_line>>3) + (bytes_per_line&0x7 ? 1: 0);
- bytes_per_line += (bytes_per_line&0x3)? (4-(bytes_per_line&0x3)): 0;
-
- myWidth = width;
- myHeight = height;
-
- if (hasColormap) {
- // Retreive array of colors (as RGBQUAD sequence).
- // Note, that there can be less then ncolors colors.
- isize = ncolors * sizeof (RGBQUAD);
-
- file.Read ((void*&)pColors256, isize, nBytes);
- if (file.Failed() || nBytes != isize) {
- cout << "AlienImage_BMPAlienData::Read() : Reading ColorMap."
- << endl << flush;
- goto _ExitReadError;
- }
- // Build colormap
- myColorMap = new Aspect_GenericColorMap ();
- for (i=0; i<ncolors; i++) {
- r = ((float)pColors256[i].rgbRed / 255.);
- g = ((float)pColors256[i].rgbGreen / 255.);
- b = ((float)pColors256[i].rgbBlue / 255.);
- color.SetValues (r, g, b, Quantity_TOC_RGB);
- entry.SetValue (i, color);
- myColorMap -> AddEntry (entry);
- }
- }
-
- if (hasMask) {
- PDWORD pdw;
- // Retrieve three DWORD's that contain the masks for R, G and B respectively
- file.Read ((void*&)(pdw = &dwRMask), sizeof (DWORD), nBytes);
- if (file.Failed() || nBytes != sizeof(DWORD)) {
- cout << "AlienImage_BMPAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
-
- file.Read ((void*&)(pdw = &dwGMask), sizeof (DWORD), nBytes);
- if (file.Failed() || nBytes != sizeof(DWORD)) {
- cout << "AlienImage_BMPAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
-
- file.Read ((void*&)(pdw = &dwBMask), sizeof (DWORD), nBytes);
- if (file.Failed() || nBytes != sizeof(DWORD)) {
- cout << "AlienImage_BMPAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
-
- if (hasColormap || !dwRMask || !dwGMask || !dwBMask) {
- cout << "AlienImage_BMPAlienData::Read() : BAD image colormap." << endl << flush;
- goto _ExitReadError;
- }
-
- dwRMask = _TestSwapDWORD (dwRMask);
- dwGMask = _TestSwapDWORD (dwGMask);
- dwBMask = _TestSwapDWORD (dwBMask);
-
- nRMult = nGMult = nBMult = 0;
-
- for (i=dwRMask; (i&1)^1; i >>= 1)
- nRMult++;
- for (i=dwGMask; (i&1)^1; i >>= 1)
- nGMult++;
- for (i=dwBMask; (i&1)^1; i >>= 1)
- nBMult++;
- } else {
- dwBMask = 0x000000ff, dwGMask = 0x0000ff00, dwRMask = 0x00ff0000,
- nBMult = 0, nGMult = 8, nRMult = 16;
- }
-
- // Allocate the pixel buffer and load raw data from file
- i = _TestSwapDWORD (bmfh.bfOffBits);
- iDataSize = _TestSwapDWORD (bmfh.bfSize) - i;
- pData = (BYTE *) STGMGR_ALLOC (iDataSize);
- pbData = pData;
-
- file.Seek (i, OSD_FromBeginning);
- file.Read ((void*&)pData, iDataSize, nBytes);
- if (file.Failed () || nBytes != iDataSize) {
- cout << "AlienImage_BMPAlienData::Read() : Image data."
- << endl << flush;
- goto _ExitReadError;
- }
-
- if (iCompression == BI_RLE4 || iCompression == BI_RLE8) {
- pbData = (BYTE*) STGMGR_ALLOC (width*height);
- // Note, that it is possible that "spots" could appear
- // after decompressing the data encoded using RLE algorith.
- // The method assumes that the image is drawn to an already
- // defined background. That's why I have to fill in these
- // probable spots with some color (I have chosen 0-indexed one).
- memset (pbData, 0, iDataSize);
- // Decompress the data to array of 8-bit color indices
- x = 0;
- y = 0;
- ptrByte = pData;
- for (;;) {
- BYTE bPixCount = *ptrByte++;
- BYTE bCode, bColor;
- if (bPixCount) {
- bColor = *ptrByte++;
- //fprintf (stderr, "[%02x S]", (int)bPixCount);
- if (iCompression == BI_RLE8) {
- while (bPixCount--)
- pbData [width*y + x++] = bColor;
- } else {
- BYTE bColor0 = (bColor & 0xf0) >> 4;
- BYTE bColor1 = bColor & 0x0f;
- i = 0;
- while (bPixCount--)
- pbData [width*y + x++] = i++ & 1 ? bColor1: bColor0;
- }
- continue;
- }
- // Zero code has been reached.
- // Do the command specified in the second byte.
- bCode = *ptrByte++;
-
- if (!bCode) { // EOL
- x = 0, y++; //,fprintf (stderr, "\r\n");
- } else if (bCode == 1) { // EOF
- break;
- } else if (bCode == 2) { // Delta
- x += (unsigned) *ptrByte++;
- y += (unsigned) *ptrByte++;
- //fprintf (stderr, "[POS=%d,%d]", x, y);
- } else { // Absolute mode
- bPixCount = bCode;
- //fprintf (stderr, "[%02x D]", (int)bPixCount);
- if (iCompression == BI_RLE8) {
- while (bPixCount--)
- pbData [width*y + x++] = *ptrByte++;
- } else {
- i = 0;
- while (bPixCount--)
- pbData [width*y + x++] = i++ & 1 ? *ptrByte & 0x0f
- : (*ptrByte++ & 0xf0) >> 4;
- }
- // each run must aligned on a word boundary
- if (iCompression == BI_RLE8 && (bCode & 1) ||
- iCompression == BI_RLE4 && (bCode & 3))
- ptrByte ++;
- }
- }
-
- bytes_per_line = width;
- nBitCount = 8;
- STGMGR_FREE (pData, iDataSize);
- iDataSize = width*height;
- }
-
- // Data isn't comressed. Can just use the raw data
- // Alloc image data (pidata) and fill in the buffer with RGBQUAD's
- isize = width*height;
- myData = STGMGR_ALLOC (!myColorMap.IsNull() ? myWidth*myHeight : myWidth*myHeight*4);
- x = 0;
- y = isInsideOut? 0: height-1;
- for (i = 0; i < isize; i++) {
- DWORD dwValue=0;
- BYTE* pbLine = pbData + y*bytes_per_line;
- switch (nBitCount) {
- case 32:
- dwValue = *(((DWORD *) pbLine) + x); break; // next double word value
- case 16:
- dwValue = *(((WORD *) pbLine) + x); break; // next word
- case 8:
- dwValue = *(((BYTE *) pbLine) + x); break; // next byte
- case 24: {
- BYTE* pbTripple = pbLine + x+(x<<1);
- dwValue = *pbTripple + (*(pbTripple +1) <<8) + (*(pbTripple +2) <<16);
- } break;
- case 4:
- dwValue = (x&1) ? *(pbLine+(x>>1))&0x0f: (*(pbLine+(x>>1))&0xf0) >> 4; break;
- case 1: {
- int iBit = 7 - (x&7);
- dwValue = (*(pbLine+(x>>3)) & (1 <<iBit)) >>iBit;
- } break; // next bit
- }
- if (hasColormap) {
- BPIXEL [i] = (BYTE) dwValue; // put index in colormap
- } else {
- DWPIXEL[i] = (DWORD) dwValue; // put RGB
- }
- if (++x == width) {
- x = 0;
- y += isInsideOut? 1: -1;
- }
- }
-
- STGMGR_FREE (pColors256, sizeof(RGBQUAD)*256);
- STGMGR_FREE (pbData, iDataSize);
- return Standard_True;
-
-_ExitReadError:
-// cout << "AlienImage_BMPAlienData::Read() : Read file error." << endl << flush;
- STGMGR_FREE (pColors256, sizeof(RGBQUAD)*256);
- if (pbData) STGMGR_FREE (pbData, iDataSize);
- Clear ();
- return Standard_False;
-}
-
-//================================================================
-Standard_Boolean AlienImage_BMPAlienData::Write (OSD_File& file) const
-{
- AlienImage_BMPHeader bfh;
- BITMAPINFOHEADER bih;
- int isize, x, y;
- BYTE *pbData = NULL, *pbCell = NULL;
- WORD sign = _TestSwapWORD(0x4D42); // BMP file signature: SWAP('MB')
- DWORD dwPixel;
- RGBQUAD* prgbColor = (RGBQUAD*)&dwPixel;
- Quantity_Color color;
- Standard_Real r, g, b;
-
- if (myData == NULL || myWidth == 0 || myHeight == 0 )
- return Standard_False;
- // Get the size of array of pixels
- isize = myWidth*3; // actual size of data in each scan line
- isize += (isize & 3 ? 4 - (isize & 3): 0); // plus pad size
- isize *= myHeight;
- pbData = (BYTE*) STGMGR_ALLOC (isize);
-
- // Build and write File Header.
- bfh.bfSize = _TestSwapDWORD(2+sizeof (AlienImage_BMPHeader) +
- sizeof (BITMAPINFOHEADER) +
- sizeof (RGBQUAD)*0 +
- isize);
- bfh.bfReserved = 0;
- bfh.bfOffBits = _TestSwapDWORD(2+sizeof (AlienImage_BMPHeader) +
- sizeof (BITMAPINFOHEADER) +
- sizeof (RGBQUAD)*0);
-
- // Write file signature
- file.Write (&sign, 2);
- if (file.Failed ())
- goto _ExitWriteError;
-
- // Write file header
- file.Write (&bfh, sizeof (bfh));
- if (file.Failed ())
- goto _ExitWriteError;
-
- // Build and write Info Header.
- bih.biSize = _TestSwapDWORD(sizeof (BITMAPINFOHEADER));
- bih.biWidth = _TestSwapDWORD(myWidth );
- bih.biHeight = _TestSwapDWORD(myHeight);
- bih.biPlanes = _TestSwapWORD (1);
- bih.biBitCount = _TestSwapWORD (24); // 8 bits per each of R,G and B value
- bih.biCompression = 0; // BI_RGB
- bih.biSizeImage = 0; // can be zero for BI_RGB
- bih.biXPelsPerMeter = 0;
- bih.biYPelsPerMeter = 0;
- bih.biClrUsed = 0; // all colors used
- bih.biClrImportant = 0; // all colors imortant
-
- file.Write (&bih, sizeof (bih));
- if (file.Failed ())
- goto _ExitWriteError;
-
- // Fill in array of pixels and write out the buffer.
- pbCell = pbData;
- for (y = myHeight-1; y >= 0; y--) {
- for (x = 0; x < myWidth; x++) {
- if (!myColorMap.IsNull ()) {
- color = myColorMap -> FindEntry (BPIXEL[y*myWidth + x]).Color ();
- color.Values (r, g, b, Quantity_TOC_RGB);
- *pbCell++ = (BYTE)(b*255.);
- *pbCell++ = (BYTE)(g*255.);
- *pbCell++ = (BYTE)(r*255.);
- } else {
- dwPixel = _TestSwapDWORD (DWPIXEL[y*myWidth + x]);
- *pbCell++ = prgbColor -> rgbBlue;
- *pbCell++ = prgbColor -> rgbGreen;
- *pbCell++ = prgbColor -> rgbRed;
- }
- }
- x *= 3;
- // Pad each scan line with zeroes to end on a LONG data-type boundary
- while (x++ & 0x03) // i.e. until 4 devides x
- *pbCell++ = 0;
- }
-
- file.Write (pbData, isize);
- if (file.Failed ())
- goto _ExitWriteError;
-
- STGMGR_FREE (pbData, isize);
- return Standard_True;
-
-_ExitWriteError:
- cout << "AlienImage_BMPAlienData::Write() : Write file error." << endl << flush;
- STGMGR_FREE (pbData, isize);
- return Standard_False;
-}
-
-//================================================================
-Handle_Image_Image AlienImage_BMPAlienData::ToImage () const
-{
- Standard_Integer x, y, LowX, LowY;
- Handle(Image_Image) theImage;
- if (!myColorMap.IsNull()) {
- Aspect_IndexPixel iPixel;
- theImage = new Image_PseudoColorImage (0, 0, myWidth, myHeight, myColorMap);
- LowX = theImage -> LowerX ();
- LowY = theImage -> LowerY ();
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- iPixel.SetValue (BPIXEL[y*myWidth + x]);
- theImage -> SetPixel (LowX + x, LowY + y, iPixel);
- }
- }
- } else {
- DWORD dwPixel;
- RGBQUAD* pRgb = (RGBQUAD*)&dwPixel;
- Standard_Real r, g, b;
- Quantity_Color color;
- Aspect_ColorPixel cPixel;
- theImage = new Image_ColorImage (0, 0, myWidth, myHeight);
- LowX = theImage -> LowerX ();
- LowY = theImage -> LowerY ();
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- dwPixel = _TestSwapDWORD (DWPIXEL[y*myWidth + x]);
- r = ((float)pRgb -> rgbRed / 255.);
- g = ((float)pRgb -> rgbGreen / 255.);
- b = ((float)pRgb -> rgbBlue / 255.);
- color.SetValues (r, g, b, Quantity_TOC_RGB);
- cPixel.SetValue (color);
- theImage -> SetPixel (LowX + x, LowY + y, cPixel);
- }
- }
- }
- return theImage;
-}
-
-//================================================================
-void AlienImage_BMPAlienData::FromImage (const Handle_Image_Image& anImage)
-{
- if (anImage -> Type() == Image_TOI_PseudoColorImage) {
- // Build from PseudoColorImage
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage);
- FromPseudoColorImage (aPImage);
- } else if (anImage -> Type() == Image_TOI_ColorImage) {
- // Build from ColorImage
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage);
- FromColorImage (aCImage);
- } else {
- // Unknown type of image
- Standard_TypeMismatch_Raise_if (Standard_True,
- "Attempt to convert a unknown Image_Image type to a BMPAlienData");
- }
-}
-
-//================================================================
-void AlienImage_BMPAlienData::FromPseudoColorImage (
- const Handle(Image_PseudoColorImage)& anImage)
-{
- int width = anImage -> Width ();
- int height = anImage -> Height ();
- int x, y, LowX = anImage -> LowerX(), LowY = anImage -> LowerY();
- Aspect_IndexPixel iPixel;
- BYTE index;
-
- if (width*height > 0) {
- Handle(Aspect_ColorMap) aColorMap = anImage -> ColorMap ();
- // Clear old data if any
- Clear ();
- // Fill colormap
- myColorMap = new Aspect_GenericColorMap ();
- for (int i = 1; i <= aColorMap -> Size (); i++)
- myColorMap -> AddEntry (aColorMap -> Entry (i));
- // Fill image's data
- myWidth = width;
- myHeight = height;
- myData = STGMGR_ALLOC (myWidth*myHeight);
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- iPixel = anImage -> Pixel (LowX + x, LowY + y);
- index = aColorMap -> FindEntry (iPixel.Value ()).Index ();
- BPIXEL[y*myWidth + x] = index;
- }
- }
- }
-}
-
-//================================================================
-void AlienImage_BMPAlienData::FromColorImage (
- const Handle(Image_ColorImage)& anImage)
-{
- int width = anImage -> Width ();
- int height = anImage -> Height ();
- int x, y, LowX = anImage -> LowerX(), LowY = anImage -> LowerY();
- Standard_Real r, g, b;
- Quantity_Color color;
- RGBQUAD rgbColor;
- DWORD* pdwPixel = (DWORD*)&rgbColor;
-
- if (width*height > 0) {
- // Clear old data if any
- Clear ();
- // Fill image's data
- myWidth = width;
- myHeight = height;
- myData = STGMGR_ALLOC (myWidth*myHeight*4);
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- color = anImage -> PixelColor (LowX + x, LowY + y);
- color.Values (r, g, b, Quantity_TOC_RGB);
- rgbColor.rgbRed = (int)(r*255.);
- rgbColor.rgbGreen = (int)(g*255.);
- rgbColor.rgbBlue = (int)(b*255.);
- rgbColor.rgbReserved = 0;
- DWPIXEL[y*myWidth + x] = _TestSwapDWORD (*pdwPixel);
- }
- }
- }
-}
-
+++ /dev/null
--- Created on: 1998-10-20
--- Created by: DCB
--- Copyright (c) 1998-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class BMPAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
-uses
- BMPAlienData from AlienImage,
- File from OSD,
- AsciiString from TCollection,
- Image from Image
-
-is
- Create
- returns mutable BMPAlienImage from AlienImage;
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by BMPAlienImage
- ---C++: alias ~
-
- SetName( me : in out mutable;
- aName : in AsciiString from TCollection) ;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection ;
- ---C++: return const &
- ---Level: Public
- ---Purpose: get Image name .
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : convert a BMPAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : convert a Image object to a BMPAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a BMPAlienImage object from a file .
- -- Returns True if file is a BMP file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a BMPAlienImage object to a file .
-
-fields
- myData : BMPAlienData from AlienImage;
-
-end;
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-#include <AlienImage_BMPAlienImage.ixx>
-
-//================================================================
-AlienImage_BMPAlienImage::AlienImage_BMPAlienImage ()
-{
- myData = new AlienImage_BMPAlienData() ;
-}
-
-//================================================================
-void AlienImage_BMPAlienImage::Clear ()
-{
- myData->Clear();
-}
-
-//================================================================
-void AlienImage_BMPAlienImage::SetName (const TCollection_AsciiString& aName)
-{
- myData->SetName (aName);
-}
-
-//================================================================
-const TCollection_AsciiString& AlienImage_BMPAlienImage::Name () const
-{
- return (myData->Name());
-}
-
-//================================================================
-Standard_Boolean AlienImage_BMPAlienImage::Write (OSD_File& file) const
-{
- return myData->Write(file);
-}
-
-//================================================================
-Standard_Boolean AlienImage_BMPAlienImage::Read (OSD_File& file)
-{
- return myData->Read(file);
-}
-
-//================================================================
-Handle_Image_Image AlienImage_BMPAlienImage::ToImage () const
-{
- return myData->ToImage();
-}
-
-//================================================================
-void AlienImage_BMPAlienImage::FromImage (const Handle_Image_Image& anImage)
-{
- myData->FromImage(anImage);
-}
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Notes: Most of code is taken from Xw_load_bmp_image.c file (ZOV)
-
-#include <AlienImage_BMPHeader.hxx>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_BMPHeader)
-{
- static Handle(Standard_Type) _atype =
- new Standard_Type ("AlienImage_BMPHeader", sizeof (AlienImage_BMPHeader));
- return _atype;
-}
-
+++ /dev/null
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_BMPHeader.hxx
-//============================================================================
-
-#ifndef _AlienImage_BMPHeader_HeaderFile
-#define _AlienImage_BMPHeader_HeaderFile
-
-//==== Definition de Type ====================================================
-#include <Standard_Type.hxx>
-
-#ifdef WNT
-# include <windows.h>
-#else
-typedef unsigned int DWORD; // 32-bit signed
-typedef unsigned int* PDWORD;
-typedef int LONG; // 32-bit unsigned
-typedef unsigned short WORD; // 16-bit unsigned
-typedef unsigned char BYTE; // 8-bit unsigned
-#endif // WNT
-
-typedef struct {
-// WORD bfType;
- DWORD bfSize;
- DWORD bfReserved;
- DWORD bfOffBits;
-} AlienImage_BMPHeader;
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_BMPHeader);
-
-//============================================================================
-#ifndef WNT
-
-typedef struct tagBITMAPINFOHEADER {
- DWORD biSize;
- LONG biWidth;
- LONG biHeight;
- WORD biPlanes;
- WORD biBitCount;
- DWORD biCompression;
- DWORD biSizeImage;
- LONG biXPelsPerMeter;
- LONG biYPelsPerMeter;
- DWORD biClrUsed;
- DWORD biClrImportant;
-} BITMAPINFOHEADER;
-
-typedef struct tagBITMAPCOREHEADER {
- DWORD bcSize;
- WORD bcWidth;
- WORD bcHeight;
- WORD bcPlanes; // 1
- WORD bcBitCount; // 1,4,8 or 24
-} BITMAPCOREHEADER;
-
-// constants for the biCompression field
-#define BI_RGB 0
-#define BI_RLE8 1
-#define BI_RLE4 2
-#define BI_BITFIELDS 3
-
-typedef struct tagRGBQUAD {
- BYTE rgbBlue;
- BYTE rgbGreen;
- BYTE rgbRed;
- BYTE rgbReserved;
-} RGBQUAD;
-
-#endif // WNT
-
-#define LOW_VAL_AT_LOW_ADDR (*(char*)&__swaptest)
-
-#endif // _AlienImage_BMPHeader_HeaderFile
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class EuclidAlienData from AlienImage inherits AlienImageData from AlienImage
-
- ---Version: 0.0
-
- ---Level: Public
- ---Purpose: This class defines an Euclid .PIX Alien image.
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- HArray2OfInteger from TColStd
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable EuclidAlienData from AlienImage ;
-
- Clear( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by EuclidAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a EuclidAlienData object from a file .
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a EuclidAlienData object to a file .
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a EuclidAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a EuclidAlienData object.
-
- --
- -- Private Method
- --
-
-
- FromPseudoColorImage( me : in out mutable ;
- anImage : in PseudoColorImage from Image );
- ---Level: Internal
- ---Purpose : convert a Image object to a EuclidAlienData object.
-
- FromColorImage( me : in out mutable ;
- anImage : in ColorImage from Image );
- ---Level: Internal
- ---Purpose : convert a Image object to a EuclidAlienData object.
-
-fields
-
- myX1, myY1, myX2, myY2 : Integer from Standard ;
- myNumberOfColor : Integer from Standard ;
- myColors : Address from Standard ;
- myPixels : HArray2OfInteger from TColStd ;
- myPixelsIsDef : Boolean from Standard ;
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#define TEST //GG_140699
-// Check file extension, must be ".PIX".
-
-#include <Aspect_GenericColorMap.hxx>
-#include <Image_Convertor.hxx>
-#include <Image_PseudoColorImage.hxx>
-#include <AlienImage_EuclidAlienData.ixx>
-#include <Aspect_ColorMapEntry.hxx>
-#include <Standard.hxx>
-
-#define xTRACE
-
-#ifdef TRACE
-static int Verbose = 1 ;
-#endif
-
-static const unsigned int EndOfPixelLine = 65535 ;
-static const unsigned int EndOfPixelField = 65534 ;
-
-#ifdef PAGESIZE // HPUX COMPATIBILLITY
-#undef PAGESIZE
-#endif
-#define MAXCOUL 896
-#define PAGESIZE 512
-
-#define FIRST_EUCLID_IMAGE_COLOR 37
-#define LAST_EUCLID_IMAGE_COLOR 180
-
-#define ColorsSize() ( MAXCOUL*sizeof(int) )
-#define COLOR(i) ( (( int * )myColors)[i-1] ) // Fortran Array Binding
-
-//------------------------------------------------------------------------------
-// Public Method
-//------------------------------------------------------------------------------
-
-AlienImage_EuclidAlienData::AlienImage_EuclidAlienData()
-
-{
- myX1 = myY1 = myX2 = myY2 = myNumberOfColor = 0 ;
- myColors = NULL ;
- myPixelsIsDef = Standard_False ;
-}
-
-void AlienImage_EuclidAlienData::Clear()
-
-{
- if ( myColors ) {
- // Free memory
- Standard::Free(myColors) ;
- myColors = NULL ;
- }
-
- myPixelsIsDef = Standard_False ;
-
- myX1 = myY1 = myX2 = myY2 = myNumberOfColor = 0 ;
-}
-
-
-Standard_Boolean AlienImage_EuclidAlienData::Read( OSD_File& file )
-
-{ Standard_Integer bblcount, i ;
-
-#ifdef TEST
- OSD_Path path; file.Path(path);
- TCollection_AsciiString ext = path.Extension(); ext.LowerCase();
- if( ext != ".pix" ) {
- TCollection_AsciiString sysname; path.SystemName(sysname);
-#ifdef TRACE
- cout << " *** AlienImage_EuclidAlienData::Read('" << sysname << "'). must have an '.PIX' extension" << endl;
-#endif
- return Standard_False;
- }
-#endif
-
- if ( myColors == NULL )
- myColors = Standard::Allocate( ColorsSize() ) ;
-
- // Read in Header information
-
- file.Read( myColors, ColorsSize(), bblcount ) ;
-
- if ( file.Failed() || ( bblcount != ColorsSize() ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- myNumberOfColor = COLOR(1)+1 ;
- myX1 = COLOR(2) ;
- myY1 = COLOR(3) ;
- myX2 = COLOR(4) ;
- myY2 = COLOR(5) ;
-
-#ifdef TRACE
- if ( Verbose ) {
- cout << "EuclidAlienData::Read(" << myNumberOfColor-1 << "," <<
- myX1 << "," <<
- myY1 << "," <<
- myX2 << "," <<
- myY2 << ")\n" << flush ;
- }
-#endif
-
- myPixels = new TColStd_HArray2OfInteger( myX1, myX2, myY1, myY2, 0 ) ;
- myPixelsIsDef = Standard_True ;
-
- Standard_Boolean K_FLAG, K_LIGNE;
- Standard_Integer INCRE, JNCRE, ILIGNE, NUMBLK, NMOT, NPIX, IPIXCR;
- int LINPIX[(PAGESIZE*128)/sizeof(int)] ;
- Standard_Address pLINPIX = ( Standard_Address ) LINPIX ;
-
- K_FLAG = Standard_True ;
- K_LIGNE = Standard_False ;
-
- INCRE = myX1 ;
- JNCRE = 1 ;
- ILIGNE = myY1 ;
-
- NUMBLK = 8 ;
- NMOT = (PAGESIZE*128) ;
-
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Read( pLINPIX, NMOT*sizeof(int), bblcount ) ;
-
- NUMBLK += 128 ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- while( K_FLAG ) {
- while( !K_LIGNE ) {
- NPIX = LINPIX[JNCRE-1] & 0xffff ;
- IPIXCR = ( LINPIX[JNCRE-1] >> 16 ) & 0xffff ;
- if ( IPIXCR == (Standard_Integer ) EndOfPixelLine ) {
- K_LIGNE = Standard_True ;
- }
- else if ( IPIXCR < 512 ) {
- for( i = 0 ; i < NPIX ; i++ ) {
- myPixels->SetValue(INCRE,ILIGNE,IPIXCR & 0xff);
- INCRE++ ;
- }
-
- JNCRE++ ;
-
- if ( JNCRE >= NMOT ) {
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Read( pLINPIX, NMOT*sizeof(int),bblcount );
-
- NUMBLK += 128 ;
- JNCRE = 1 ;
-
- if ( file.Failed() ){ // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
- }
- else {
- K_LIGNE = Standard_True ;
- }
- }
- // Next Line
- K_LIGNE = Standard_False ;
- ILIGNE++ ;
- INCRE = myX1 ;
-
- JNCRE++ ;
- IPIXCR = ( LINPIX[JNCRE-1] >> 16 ) & 0xffff ;
- if ( IPIXCR == (Standard_Integer ) EndOfPixelField )
- K_FLAG = Standard_False ; // End of Image
- }
-
- return Standard_True ;
-
-}
-
-Standard_Boolean AlienImage_EuclidAlienData::Write( OSD_File& file ) const
-
-{ Standard_Integer x, y ;
- Standard_Integer NUMBLK, NMOT, NPIX, MAXMOT ;
- Standard_Integer ITSTPIX ;
- int LINPIX[(PAGESIZE*128)/sizeof(int)] ;
-
- if ( myNumberOfColor == 0 || myColors == NULL || ! myPixelsIsDef )
- return Standard_False ;
-
- MAXMOT = (PAGESIZE*128) / sizeof(int) ;
-
- // Write in Header information
-
- file.Write( myColors, ColorsSize() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- NUMBLK = 8 ;
- NMOT = 0 ;
-
- for ( y = myY1 ; y <= myY2 ; y++ ) {
- x = myX1 ;
- ITSTPIX = myPixels->Value( x, y ) ;
- x++ ;
-
- while( x <= myX2 ) {
- NPIX = 1 ;
-
- while ( myPixels->Value( x, y ) == ITSTPIX ) {
- NPIX++ ;
- x++ ;
- if ( x > myX2 ) break ;// End of Pixel Line
- }
-
- LINPIX[NMOT] = ( ( ( ITSTPIX&0xff ) << 16 ) & 0xffff0000 ) |
- ( NPIX & 0xffff );
- NMOT++ ;
-
- if ( NMOT >= MAXMOT ) {
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Write( ( void *)LINPIX, NMOT*sizeof(int) );
-
- NMOT = 0 ;
- NUMBLK += 128 ;
- }
-
- if ( x <= myX2 ) {
- ITSTPIX = myPixels->Value( x, y ) ;
- x++ ;
-
- if ( x == myX2 ) {// Last Pixel
- LINPIX[NMOT] = ( ( (ITSTPIX&0xff)<<16 ) & 0xffff0000 ) |
- ( 1 & 0xffff );
- NMOT++ ;
-
- if ( NMOT >= MAXMOT ) {
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Write( ( void *)LINPIX, NMOT*sizeof(int) );
-
- NMOT = 0 ;
- NUMBLK += 128 ;
- }
- }
- }
- }
-
- // End of Pixel Line
- LINPIX[NMOT] = ( ( EndOfPixelLine<<16 ) & 0xffff0000 ) |
- ( 0 & 0xffff );
- NMOT++ ;
-
- if ( NMOT >= MAXMOT ) {
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Write( ( void *)LINPIX, NMOT*sizeof(int) );
-
- NMOT = 0 ;
- NUMBLK += 128 ;
- }
- }
-
- // End of Pixel Field
- LINPIX[NMOT] = ( ( EndOfPixelField<<16 ) & 0xffff0000 ) |
- ( 0 & 0xffff );
- NMOT++ ;
-
- file.Seek( PAGESIZE*(NUMBLK-1), OSD_FromBeginning ) ;
- file.Write( ( void *)LINPIX, NMOT*sizeof(int) );
-
- return Standard_False ;
-
-}
-
-Handle_Image_Image AlienImage_EuclidAlienData::ToImage() const
-
-{ Standard_Real r,g,b ;
- Standard_Integer x, y, i ;
- Aspect_IndexPixel IPixel ;
- Aspect_ColorMapEntry Centry ;
- Quantity_Color color ;
-
- if ( myNumberOfColor == 0 || myColors == NULL || ! myPixelsIsDef )
- return NULL ;
-
- Handle(Aspect_GenericColorMap) colormap = new Aspect_GenericColorMap() ;
- Handle(Image_PseudoColorImage) PImage =
- new Image_PseudoColorImage( myX1, myY1,
- (myX2-myX1)+1, (myY2-myY1)+1, colormap ) ;
- Handle(Image_Image) RetImage = PImage ;
-
- // Get Colors
-
- for ( i = 0 ; i < myNumberOfColor ; i++ ) {
- r = ( Standard_Real ) COLOR(129+3*i) / 255. ;
- g = ( Standard_Real ) COLOR(130+3*i) / 255. ;
- b = ( Standard_Real ) COLOR(131+3*i) / 255. ;
-
- color.SetValues( r,g,b, Quantity_TOC_RGB );
-
- Centry.SetValue( i, color ) ;
-
- colormap->AddEntry( Centry ) ;
- }
-
- for ( y = myY1 ; y <= myY2 ; y++ ) {
- for ( x = myX1 ; x <= myX2 ; x++ ) {
- IPixel.SetValue( myPixels->Value( x, y ) ) ;
- PImage->SetPixel( x,myY2+myY1-y, IPixel ) ;
- }
- }
-
-
- return RetImage ;
-
-}
-
-
-void AlienImage_EuclidAlienData::FromImage( const Handle_Image_Image& anImage )
-
-{
- if ( anImage->Type() == Image_TOI_PseudoColorImage ) {
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage) ;
-
- FromPseudoColorImage( aPImage ) ;
- }
- else if ( anImage->Type() == Image_TOI_ColorImage ) {
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage) ;
-
- FromColorImage( aCImage ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a unknown Image_Image type to a EuclidAlienImage");
- }
-}
-
-//------------------------------------------------------------------------------
-// Private Method
-//------------------------------------------------------------------------------
-
-void AlienImage_EuclidAlienData::FromColorImage(
- const Handle_Image_ColorImage& anImage)
-
-{ Image_Convertor Convertor ;
- Handle(Aspect_ColorMap) aCmap =
- anImage->ChooseColorMap(LAST_EUCLID_IMAGE_COLOR-FIRST_EUCLID_IMAGE_COLOR+1);
- Handle(Image_PseudoColorImage) aPImage = Convertor.Convert( anImage, aCmap ) ;
-
- FromPseudoColorImage( aPImage ) ;
-}
-
-void AlienImage_EuclidAlienData::FromPseudoColorImage(
- const Handle_Image_PseudoColorImage& PImage)
-
-
-{
- if ( myColors == NULL )
- myColors = Standard::Allocate( ColorsSize() ) ;
-
- //
- // Euclid ColorMap goes from 0 to 255
- // We must define all colors form 0 to 255 in a EUCLID .PIX file
- //
-
- Standard_Real r,g,b ;
- Standard_Integer x, y, i, index ;
- Aspect_IndexPixel IPixel ;
- Aspect_ColorMapEntry Centry ;
-
- Handle(Aspect_ColorMap) colormap = PImage->ColorMap() ;
-
- for ( i = 1 ; i <= MAXCOUL ; i++ ) {
- COLOR(i) = 0 ;
- }
-
- myX1 = PImage->LowerX() ; myX2 = PImage->UpperX() ;
- myY1 = PImage->LowerY() ; myY2 = PImage->UpperY() ;
-
- myPixels = new TColStd_HArray2OfInteger( myX1, myX2, myY1, myY2, 0 ) ;
- myPixelsIsDef = Standard_True ;
-
- myNumberOfColor = 0 ;
-
- // Get Colors
-
- for ( i = 1 ; i <= colormap->Size() ; i++ ) {
- Centry = colormap->Entry( i ) ;
- index = Centry.Index() ;
- if ( index >= 0 && index <= 255 ) {
- myNumberOfColor = Max( myNumberOfColor, index ) ;
- Centry.Color().Values( r,g,b, Quantity_TOC_RGB ) ;
-
- COLOR(129+3*index) = ( int ) ( r * 255. + 0.5 ) ;
- COLOR(130+3*index) = ( int ) ( g * 255. + 0.5 ) ;
- COLOR(131+3*index) = ( int ) ( b * 255. + 0.5 ) ;
- }
- }
-
- COLOR(1) = myNumberOfColor ;
- COLOR(2) = myX1;
- COLOR(3) = myY1 ;
- COLOR(4) = myX2 ;
- COLOR(5) = myY2 ;
-
- for ( y = myY1 ; y <= myY2 ; y++ ) {
- for ( x = myX1 ; x <= myX2 ; x++ ) {
- PImage->Pixel( x,myY2+myY1-y, IPixel ) ;
- myPixels->SetValue( x, y, IPixel.Value() ) ;
- }
- }
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
-
-class EuclidAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines an Euclid Alien image.
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- EuclidAlienData from AlienImage
-
-is
- Create returns mutable EuclidAlienImage from AlienImage;
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by EuclidAlienImage
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : Converts a EuclidAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : converts a Image object to a EuclidAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Purpose: Reads content of a EuclidAlienImage object
- -- from a file .
- -- Returns True if file is a Euclid file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Purpose: Writes content of a EuclidAlienImage object
- -- to a file .
-
-fields
- myData : EuclidAlienData from AlienImage ;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_EuclidAlienImage.ixx>
-
-AlienImage_EuclidAlienImage::AlienImage_EuclidAlienImage()
-
-{ // il faut faire un new si mydata est du type HANDLE
- myData = new AlienImage_EuclidAlienData() ;
-}
-
-void AlienImage_EuclidAlienImage::Clear()
-
-{ myData->Clear() ; }
-
-Standard_Boolean AlienImage_EuclidAlienImage::Write( OSD_File& file ) const
-
-{ return( myData->Write( file ) ) ; }
-
-Standard_Boolean AlienImage_EuclidAlienImage::Read( OSD_File& file )
-
-{ return( myData->Read( file ) ) ; }
-
-Handle_Image_Image AlienImage_EuclidAlienImage::ToImage() const
-
-{ return( myData->ToImage() ) ; }
-
-void AlienImage_EuclidAlienImage::FromImage( const Handle_Image_Image& anImage )
-
-{ myData->FromImage( anImage ) ; }
-
+++ /dev/null
--- Created on: 1998-10-20
--- Created by: DCB
--- Copyright (c) 1998-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-private class GIFAlienData from AlienImage inherits AlienImageData from AlienImage
-
-uses
- File from OSD,
- AsciiString from TCollection,
- PseudoColorImage from Image,
- ColorImage from Image,
- Image from Image
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable GIFAlienData from AlienImage ;
-
- Clear( me : in out mutable );
- ---Level: Public
- ---Purpose: Frees memory allocated by GIFAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard;
- ---Level: Public
- ---Purpose: Read content of a GIFAlienData object from a file
- -- Returns True if file is a GIF file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard;
- ---Level: Public
- ---Purpose: Write content of a GIFAlienData object to a file
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a GIFAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a GIFAlienData object.
-
- ------------------------------------------------------
- --- Private methods
- ------------------------------------------------------
- FromPseudoColorImage (me : in out mutable;
- anImage : in PseudoColorImage from Image )
- is private;
- ---Level: Internal
- ---Purpose : convert a Image object to a GIFAlienData object.
-
- FromColorImage (me : in out mutable;
- anImage : in ColorImage from Image)
- is private;
- ---Level: Internal
- ---Purpose : convert a Image object to a GIFAlienData object.
-
-
-fields
- myRedColors : Address from Standard;
- myGreenColors : Address from Standard;
- myBlueColors : Address from Standard;
-
- myData : Address from Standard;
- myWidth : Integer from Standard;
- myHeight : Integer from Standard;
-
-end;
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Notes:
-// Read()/Write() code is taken from ZOV's sources from Xw package.
-// _convert24to8() sources and all concerned code is taken from
-// EUG's code of WNT_ImageProcessor.
-
-#define TEST //GG_140699
-// Check GIF format first.
-
-#ifdef WNT
-//it is important to undefine NOGDI and enforce including <windows.h> before
-//Standard_Macro.hxx defines it and includes <windows.h> making GDI-related
-//stuff unavailable and causing compilation errors
-#undef NOGDI
-#include <windows.h>
-#endif
-
-#include <AlienImage_GIFAlienData.ixx>
-#include <AlienImage_GIFLZWDict.hxx>
-
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_ColorMapEntry.hxx>
-#include <Image_Convertor.hxx>
-#include <Image_DitheringMethod.hxx>
-
-#ifdef _DEBUG
-//# define TRACE
-#endif
-
-#ifdef TRACE
-# include <OSD_Timer.hxx>
-#endif
-
-#define STGMGR_ALLOC(size) Standard::Allocate(size)
-#define STGMGR_FREE(buf,size) Standard::Free((void*&)buf)
-#define COLORS_SIZE 256*sizeof(BYTE)
-#define RED ((PBYTE)myRedColors)
-#define GREEN ((PBYTE)myGreenColors)
-#define BLUE ((PBYTE)myBlueColors)
-#define PIXEL ((PBYTE)myData)
-
-#define ZERO_COLORS() \
- memset (myRedColors, 0, COLORS_SIZE); \
- memset (myGreenColors, 0, COLORS_SIZE); \
- memset (myBlueColors, 0, COLORS_SIZE);
-
-#define _ADD_PIXEL(idx) \
-{ \
- if (y < height) \
- *((PBYTE)myData + y*width + x) = ((BYTE)(idx)); \
- if (++x == width) { \
- x = 0; \
- if (!isInterlace) ++y; \
- else switch (pass) { \
- case 0: y += 8; if (y >= height) ++pass, y = 4; break; \
- case 1: y += 8; if (y >= height) ++pass, y = 2; break; \
- case 2: y += 4; if (y >= height) ++pass, y = 1; break; \
- default: y += 2; \
- } \
- } \
-}
-
-//================================================================
-AlienImage_GIFAlienData::AlienImage_GIFAlienData()
- : AlienImage_AlienImageData ()
-{
- myRedColors = NULL;
- myGreenColors = NULL;
- myBlueColors = NULL;
-
- myData = NULL;
- myWidth = 0;
- myHeight = 0;
-}
-
-//================================================================
-void AlienImage_GIFAlienData::Clear ()
-{
- if (myRedColors) {
- STGMGR_FREE (myRedColors, COLORS_SIZE);
- myRedColors = NULL;
- }
- if (myGreenColors) {
- STGMGR_FREE (myGreenColors, COLORS_SIZE);
- myGreenColors = NULL;
- }
- if (myBlueColors) {
- STGMGR_FREE (myBlueColors, COLORS_SIZE);
- myBlueColors = NULL;
- }
-
- if (myData) {
- STGMGR_FREE (myData, myWidth*myHeight);
- myData = NULL;
- myWidth = myHeight = 0;
- }
-}
-
-//================================================================
-Standard_Boolean AlienImage_GIFAlienData::Read (OSD_File& file)
-{
- Standard_Integer nFileSize = file.Size(), nReadCount;
- unsigned *OutCode=NULL, *Prefix=NULL, *Suffix=NULL,
- BitMask, CodeSize, ClearCode, EOFCode, FreeCode, x, y, pass, width, height,
- InitCodeSize, MaxCode, ReadMask, FirstFree, OutCount, BitOffset,
- ByteOffset, Code, CurCode, OldCode=0, FinChar=0, InCode;
- int isInterlace, hasColormap;
- int i, ncolors;
- BYTE byte, byte1;
- PBYTE pFileStream = NULL;
- // Allocate memory to read the file
- PBYTE pFileBuffer =
- (PBYTE) STGMGR_ALLOC (nFileSize);
- PBYTE rasterPtr = NULL, ptr1;
- pFileStream = pFileBuffer + 10;
-
-#ifdef TRACE
- OSD_Timer timer;
- cout << "AlienImage_GIFAlienData::Read () starts" << endl << flush;
- timer.Start ();
-#endif
-
- // Read file into memory
- file.Read ((void*&)pFileBuffer, nFileSize, nReadCount);
- if (nFileSize != nReadCount) {
- cout << "GIFAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
-
-#ifdef TEST
- if( strncmp ((char*)pFileBuffer, "GIF87a", 6) &&
- strncmp ((char*)pFileBuffer, "GIF89a", 6) )
- goto _ExitReadError;
-#endif
-
- // Determine if the image has colormap
- byte = *pFileStream++; // Color descriptor byte (M#CR0#BP)
- hasColormap = byte & 0x80;
- ncolors = hasColormap ? 1<<((byte & 0x07) + 1): 1<<8;
- BitMask = ncolors - 1;
-
- pFileStream += 2; // Skip background byte and following zero byte
- if (ncolors > 0 && ncolors <= 256) { // Allocate Color Table entries
- myRedColors = STGMGR_ALLOC (COLORS_SIZE);
- myGreenColors = STGMGR_ALLOC (COLORS_SIZE);
- myBlueColors = STGMGR_ALLOC (COLORS_SIZE);
- ZERO_COLORS ();
-
- for (i=0; i<ncolors; i++) {
- // Fill in array of XColor's used
- // Note, that if there's no colormap specified then I use gray scale
- RED [i] = ((BYTE)(hasColormap ? *pFileStream++: i));
- GREEN[i] = ((BYTE)(hasColormap ? *pFileStream++: i));
- BLUE [i] = ((BYTE)(hasColormap ? *pFileStream++: i));
- }
- } else {
- cout << "GIFAlienData::Read() : There's no colormap"
- << " in the image (or too big): " << ncolors << endl << flush;
- goto _ExitReadError;
- }
-
- // Skip extension blocks if any.
- // Format: <'!'><size><...><size><...><0>
- while (*pFileStream == '!') {
- pFileStream += 2; // skip code byte followed '!' sign
- while (*pFileStream)
- pFileStream += (unsigned)(1 + *(PBYTE)pFileStream);
- pFileStream ++;
- }
-
- if (*pFileStream++ != ',') { // must be an image descriptor
- cout << "GIFAlienData::Read() : There's no separator"
- << " following the colormap" << endl << flush;
- goto _ExitReadError;
- }
-
- pFileStream += 2*2; // Skip image left & top offsets
- width = (unsigned) *pFileStream++;
- width += ((unsigned)*pFileStream++) << 8;
- height = (unsigned) *pFileStream++;
- height += ((unsigned)*pFileStream++) << 8;
-
- byte = *pFileStream++;
- isInterlace = byte & 0x40;
- if (byte & 0x80) {
- cout << "GIFAlienData::Read() : Can't read GIF image"
- << " with locally defined colormap" << endl << flush;
- goto _ExitReadError;
- }
-
- // Allocate the pixel buffer
- rasterPtr = (PBYTE) STGMGR_ALLOC (nFileSize);
-
- OutCode = (unsigned *) STGMGR_ALLOC (1025 * sizeof (unsigned int));
- Prefix = (unsigned *) STGMGR_ALLOC (4096 * sizeof (unsigned int));
- Suffix = (unsigned *) STGMGR_ALLOC (4096 * sizeof (unsigned int));
-
- // Decode compressed raster data.
- CodeSize = *pFileStream++;
- ClearCode = 1 << CodeSize;
- EOFCode = ClearCode + 1;
- FreeCode = FirstFree = EOFCode + 1;
-
- ++CodeSize;
- InitCodeSize = CodeSize;
- MaxCode = 1 << CodeSize;
- ReadMask = MaxCode - 1;
- ptr1 = rasterPtr;
-
- // Read encoded data to a continuous array pointed to by rasterPtr
- do {
- byte = byte1 = *pFileStream++;
- while (byte--)
- *ptr1++ = *pFileStream++;
- if ((long) (ptr1 - rasterPtr) > nFileSize) {// Currupt file
- cout << "GIFAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
- } while (byte1);
- // The file data has been already read
- STGMGR_FREE (pFileBuffer, nFileSize);
- pFileBuffer = NULL;
-
- // Allocate image data
- myWidth = width;
- myHeight = height;
- myData = STGMGR_ALLOC (myWidth*myHeight);
-
- x = y = pass = OutCount = BitOffset = ByteOffset = 0;
- // Fetch the next code (3 to 12 bits) from the raster data stream
- Code = rasterPtr[0] + (((unsigned) rasterPtr[1]) << 8);
- if (CodeSize >= 8)
- Code += ((unsigned) rasterPtr[2]) << 16;
-
- Code >>= BitOffset & 0x7;
- BitOffset += CodeSize;
- Code &= ReadMask;
-
- while (Code != EOFCode) {
- if (Code == ClearCode) {
- // Read the next code
- CodeSize = InitCodeSize;
- MaxCode = 1 << CodeSize;
- ReadMask = MaxCode - 1;
- FreeCode = FirstFree;
- ByteOffset = BitOffset >> 3;
- Code = rasterPtr[ByteOffset]
- + (((unsigned) rasterPtr[ByteOffset + 1]) << 8);
-
- if (CodeSize >= 8)
- Code += ((unsigned) rasterPtr[ByteOffset + 2]) << 16;
-
- Code >>= BitOffset & 0x7;
- BitOffset += CodeSize;
- Code &= ReadMask;
-
- CurCode = OldCode = Code;
- FinChar = CurCode & BitMask;
-
- _ADD_PIXEL (FinChar);
- } else {
- CurCode = InCode = Code;
- if (CurCode >= FreeCode) {
- CurCode = OldCode;
- OutCode[OutCount++] = FinChar;
- }
- while (CurCode > BitMask) {
- if (OutCount > 1024) {
- cout << "GIFAlienData::Read() : BAD file size." << endl << flush;
- goto _ExitReadError;
- }
- OutCode [OutCount++] = Suffix [CurCode];
- CurCode = Prefix [CurCode];
- }
- FinChar = CurCode & BitMask;
- OutCode [OutCount++] = FinChar;
- for (i = OutCount - 1; i >= 0; --i)
- _ADD_PIXEL (OutCode [i]);
-
- OutCount = 0;
- Prefix [FreeCode] = OldCode;
- Suffix [FreeCode] = FinChar;
- OldCode = InCode;
- ++FreeCode;
- if (FreeCode >= MaxCode) {
- if (CodeSize < 12) {
- ++CodeSize;
- MaxCode <<= 1;
- ReadMask = (1 << CodeSize) - 1;
- }
- }
- }
-
- ByteOffset = BitOffset >> 3;
- Code = (unsigned) rasterPtr[ByteOffset]
- + (((unsigned) rasterPtr[ByteOffset + 1]) << 8);
-
- if (CodeSize >= 8)
- Code += ((unsigned) rasterPtr[ByteOffset + 2]) << 16;
-
- Code >>= (BitOffset & 0x7);
- BitOffset += CodeSize;
- Code &= ReadMask;
- } // while (Code != EOFCode)
-
- // Free allocated memory
- STGMGR_FREE (rasterPtr, nFileSize);
- STGMGR_FREE (OutCode, 1025 * sizeof (unsigned int));
- STGMGR_FREE (Prefix, 4096 * sizeof (unsigned int));
- STGMGR_FREE (Suffix, 4096 * sizeof (unsigned int));
-#ifdef TRACE
- timer.Stop ();
- timer.Show (cout);
- cout << "AlienImage_GIFAlienData::Read () finished\n" << endl << flush;
-#endif
- return Standard_True;
-
-_ExitReadError:
-// cout << "GIFAlienData::Read() : Read file error." << endl << flush;
- if (pFileBuffer) STGMGR_FREE (pFileBuffer, nFileSize);
- if (OutCode) STGMGR_FREE (OutCode, 1025 * sizeof (unsigned int));
- if (Prefix) STGMGR_FREE (Prefix, 4096 * sizeof (unsigned int));
- if (Suffix) STGMGR_FREE (Suffix, 4096 * sizeof (unsigned int));
- if (myRedColors) {
- STGMGR_FREE (myRedColors, COLORS_SIZE);
- myRedColors = NULL;
- }
- if (myGreenColors) {
- STGMGR_FREE (myGreenColors, COLORS_SIZE);
- myGreenColors = NULL;
- }
- if (myBlueColors) {
- STGMGR_FREE (myBlueColors, COLORS_SIZE);
- myBlueColors = NULL;
- }
- if (myData) {
- STGMGR_FREE (myData, myWidth*myHeight);
- myData = NULL;
- myWidth = myHeight = 0;
- }
-
- return Standard_False;
-}
-
-//================================================================
-Standard_Boolean AlienImage_GIFAlienData::Write (OSD_File& file) const
-{
- SCREEN_DESCR sd;
- IMAGE_DESCR id;
- BYTE image_sep = 0x2C; // gif colormap delimiter
- WORD wZero = 0x00;
- BYTE colors256 [256][3];
- BYTE bEnd = 0x3B;
- int i;
-
-#ifdef TRACE
- OSD_Timer timer;
- cout << "AlienImage_GIFAlienData::Write () starts" << endl << flush;
- timer.Start ();
-#endif
- // Check if image is loaded
- if (myData == NULL || myRedColors == NULL ||
- myGreenColors == NULL || myBlueColors == NULL ||
- myWidth == 0 || myHeight == 0)
- goto _ExitWriteError;
-
- // Build file header
- memcpy (sd.gifID, "GIF87a", 6);
- sd.scrnWidth = SWAP_WORD ((WORD) myWidth );
- sd.scrnHeight = SWAP_WORD ((WORD) myHeight);
- sd.scrnFlag = 0x80 | ( ( 7/*[=depth-1]*/ << 4 ) & 0x70 ) | 0x07;
- id.imgX = 0;
- id.imgY = 0;
- id.imgWidth = SWAP_WORD ((WORD) myWidth );
- id.imgHeight = SWAP_WORD ((WORD) myHeight);
-// imgFlag
-// +-+-+-+-+-+-----+ M=0 - Use global color map, ignore 'pixel'
-// |M|I|0|0|0|pixel| 10 M=1 - Local color map follows, use 'pixel'
-// +-+-+-+-+-+-----+ I=0 - Image formatted in Sequential order
-// I=1 - Image formatted in Interlaced order
-// pixel+1 - # bits per pixel for this image
- id.imgFlag = 0x07; // Global color map, Sequential order, 8 bits per pixel
-
- for (i = 0; i < 256; i++) {
- colors256[i] [0/*R*/] = RED [i];
- colors256[i] [1/*G*/] = GREEN [i];
- colors256[i] [2/*B*/] = BLUE [i];
- }
-
- // Write off the buffers
- file.Write (&sd, 11); // Screen descriptor
- if (file.Failed())
- goto _ExitWriteError;
-
- file.Write (&wZero, 2); // Zero word
- if (file.Failed())
- goto _ExitWriteError;
-
- file.Write (colors256, 256*3); // Colormap
- if (file.Failed())
- goto _ExitWriteError;
-
- file.Write (&image_sep, 1); // Separator
- if (file.Failed())
- goto _ExitWriteError;
-
- file.Write (&id, 9); // Image descriptor
- if (file.Failed())
- goto _ExitWriteError;
-
- // Write off the image data
- if (!_lzw_encode (file, (PBYTE) myData, myWidth, myHeight, myWidth))
- goto _ExitWriteError;
-
- file.Write (&bEnd, 1); // End of image
- if (file.Failed())
- goto _ExitWriteError;
-
- // Return SUCCESS status if there were no errors.
-#ifdef TRACE
- timer.Stop ();
- timer.Show (cout);
- cout << "AlienImage_GIFAlienData::Write () finished\n" << endl << flush;
-#endif
- return Standard_True;
-
- // Exit on error
-_ExitWriteError:
- file.Seek (0, OSD_FromBeginning);
- return Standard_False;
-}
-
-//================================================================
-Handle_Image_Image AlienImage_GIFAlienData::ToImage () const
-{
-#ifdef TRACE
- OSD_Timer timer;
- cout << "AlienImage_GIFAlienData::ToImage () starts" << endl << flush;
- timer.Start ();
-#endif
- Standard_Integer i, x, y, LowX, LowY;
- Standard_Real r, g, b;
- Aspect_ColorMapEntry entry;
- Aspect_IndexPixel index;
- Quantity_Color color;
-
- // Build colormap
- Handle(Aspect_GenericColorMap) aColorMap =
- new Aspect_GenericColorMap ();
- for (i = 0; i < 256; i++) {
- r = ((float)RED [i] / 255.);
- g = ((float)GREEN [i] / 255.);
- b = ((float)BLUE [i] / 255.);
- color.SetValues (r, g, b, Quantity_TOC_RGB);
- entry.SetValue (i, color);
- aColorMap -> AddEntry (entry);
- }
-
- // Fill image data
- Handle(Image_Image) theImage =
- new Image_PseudoColorImage (0, 0, myWidth, myHeight, aColorMap);
- LowX = theImage -> LowerX ();
- LowY = theImage -> LowerY ();
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- index.SetValue (PIXEL[y*myWidth + x]);
- theImage -> SetPixel (LowX + x, LowY + y, index);
- }
- }
-#ifdef TRACE
- timer.Stop ();
- timer.Show (cout);
- cout << "AlienImage_GIFAlienData::ToImage () finished\n" << endl << flush;
-#endif
- return theImage;
-}
-
-//================================================================
-void AlienImage_GIFAlienData::FromImage (const Handle_Image_Image& anImage)
-{
- if (anImage -> Type() == Image_TOI_PseudoColorImage) {
- // Build from PseudoColorImage
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage);
- FromPseudoColorImage (aPImage);
- } else if (anImage -> Type() == Image_TOI_ColorImage) {
- // Build from ColorImage
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage);
- FromColorImage (aCImage);
- } else {
- // Unknown type of image
- Standard_TypeMismatch_Raise_if (Standard_True,
- "Attempt to convert a unknown Image_Image type to a GIFAlienData");
- }
-}
-
-//================================================================
-void AlienImage_GIFAlienData::FromPseudoColorImage (
- const Handle(Image_PseudoColorImage)& anImage)
-{
- int width = anImage -> Width ();
- int height = anImage -> Height ();
- unsigned short x, y, i;
- Standard_Real r, g, b;
- Aspect_ColorMapEntry entry;
- Aspect_IndexPixel index;
- Quantity_Color color;
- Standard_Integer LowX = anImage -> LowerX();
- Standard_Integer LowY = anImage -> LowerY();
- BYTE ei;
-
-#ifdef TRACE
- OSD_Timer timer;
- cout << "AlienImage_GIFAlienData::FromPseudoColorImage () starts" << endl << flush;
- timer.Start ();
-#endif
- if (width*height > 0) {
- Handle(Aspect_ColorMap) aColorMap = anImage -> ColorMap ();
- // Clear old values if any
- Clear ();
-
- myRedColors = STGMGR_ALLOC (COLORS_SIZE);
- myGreenColors = STGMGR_ALLOC (COLORS_SIZE);
- myBlueColors = STGMGR_ALLOC (COLORS_SIZE);
- ZERO_COLORS ();
-
- // Build colors from colormap
- for (i = 1; i <= aColorMap -> Size (); i++) {
- entry = aColorMap -> Entry (i);
- ei = entry.Index ();
- color = entry.Color ();
- color.Values (r, g, b, Quantity_TOC_RGB);
- RED [ei] = (BYTE)(r*255.);
- GREEN[ei] = (BYTE)(g*255.);
- BLUE [ei] = (BYTE)(b*255.);
- }
-
- // Build imagedata from Image_PseudoColorImage
- myWidth = width;
- myHeight = height;
- myData = STGMGR_ALLOC (myWidth*myHeight);
- for (y = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- index = anImage -> Pixel (LowX + x, LowY + y);
- PIXEL[y*myWidth + x] = (BYTE)index.Value ();
- }
- }
- }
-#ifdef TRACE
- timer.Stop ();
- timer.Show (cout);
- cout << "AlienImage_GIFAlienData::FromPseudoColorImage () finished\n" << endl << flush;
-#endif
-}
-
-//================================================================
-void AlienImage_GIFAlienData::FromColorImage (
- const Handle(Image_ColorImage)& anImage)
-{
-#ifdef TRACE
- OSD_Timer timer;
- cout << "AlienImage_GIFAlienData::FromColorImage () starts" << endl << flush;
- timer.Start ();
-#endif // TRACE
-
- int width = anImage -> Width ();
- int height = anImage -> Height ();
- int i, x, y, LowX = anImage -> LowerX(), LowY = anImage -> LowerY();
- Quantity_Color color;
- Standard_Real r, g, b;
-
- if (width*height > 0) {
- Aspect_ColorMapEntry entry;
- // Clear old values if any
- Clear ();
- myWidth = width;
- myHeight = height;
- LPRGBQUAD pColors = (LPRGBQUAD) STGMGR_ALLOC (256*sizeof(RGBQUAD));
- PBYTE pBits24 = (PBYTE) STGMGR_ALLOC (width*height*3);
- memset (pColors, 0, 256*sizeof(RGBQUAD));
-
- myData = STGMGR_ALLOC (width*height);
- myRedColors = STGMGR_ALLOC (COLORS_SIZE);
- myGreenColors = STGMGR_ALLOC (COLORS_SIZE);
- myBlueColors = STGMGR_ALLOC (COLORS_SIZE);
-
- for (y = 0, i = 0; y < myHeight; y++) {
- for (x = 0; x < myWidth; x++) {
- color = anImage -> PixelColor (LowX + x, LowY + y);
- color.Values (r, g, b, Quantity_TOC_RGB);
- pBits24 [i + 0] = (BYTE)(b*255.);
- pBits24 [i + 1] = (BYTE)(g*255.);
- pBits24 [i + 2] = (BYTE)(r*255.);
- i += 3;
- }
- }
-
- if (_convert24to8 (pColors, pBits24, (PBYTE)myData, myWidth, myHeight)) {
- Handle(Aspect_GenericColorMap) aColorMap = new Aspect_GenericColorMap ();
- for (i = 0; i < 256; i++) {
- r = ((float)pColors[i].rgbRed / 255.);
- g = ((float)pColors[i].rgbGreen / 255.);
- b = ((float)pColors[i].rgbBlue / 255.);
- color.SetValues (r, g, b, Quantity_TOC_RGB);
- entry.SetValue (i, color);
- aColorMap -> AddEntry (entry);
- RED [i] = pColors[i].rgbRed;
- GREEN[i] = pColors[i].rgbGreen;
- BLUE [i] = pColors[i].rgbBlue;
- }
- } else {
- Image_Convertor aConvertor;
- aConvertor.SetDitheringMethod (Image_DM_ErrorDiffusion);
- Handle(Aspect_ColorMap) aColorMap = anImage -> ChooseColorMap (256);
- Handle(Image_PseudoColorImage) aPImage =
- aConvertor.Convert (anImage, aColorMap);
- FromPseudoColorImage (aPImage);
- }
-
- STGMGR_FREE (pColors, 256*sizeof(RGBQUAD));
- STGMGR_FREE (pBits24, width*height*3);
- }
-
-#ifdef TRACE
- timer.Stop ();
- timer.Show (cout);
- cout << "AlienImage_GIFAlienData::FromColorImage () finished\n" << endl << flush;
-#endif // TRACE
-}
-
+++ /dev/null
--- Created on: 1998-10-20
--- Created by: DCB
--- Copyright (c) 1998-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class GIFAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
-uses
- GIFAlienData from AlienImage,
- File from OSD,
- AsciiString from TCollection,
- Image from Image
-
-is
- Create
- returns mutable GIFAlienImage from AlienImage;
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by GIFAlienImage
- ---C++: alias ~
-
- SetName( me : in out mutable;
- aName : in AsciiString from TCollection) ;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection ;
- ---C++: return const &
- ---Level: Public
- ---Purpose: get Image name .
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : convert a GIFAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : convert a Image object to a GIFAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a GIFAlienImage object from a file .
- -- Returns True if file is a GIF file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a GIFAlienImage object to a file .
-
-fields
- myData : GIFAlienData from AlienImage;
-
-end;
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-#include <AlienImage_GIFAlienImage.ixx>
-
-//================================================================
-AlienImage_GIFAlienImage::AlienImage_GIFAlienImage ()
-{
- myData = new AlienImage_GIFAlienData() ;
-}
-
-//================================================================
-void AlienImage_GIFAlienImage::Clear ()
-{
- myData->Clear();
-}
-
-//================================================================
-void AlienImage_GIFAlienImage::SetName (const TCollection_AsciiString& aName)
-{
- myData->SetName (aName);
-}
-
-//================================================================
-const TCollection_AsciiString& AlienImage_GIFAlienImage::Name () const
-{
- return (myData->Name());
-}
-
-//================================================================
-Standard_Boolean AlienImage_GIFAlienImage::Write (OSD_File& file) const
-{
- return myData->Write(file);
-}
-
-//================================================================
-Standard_Boolean AlienImage_GIFAlienImage::Read (OSD_File& file)
-{
- return myData->Read(file);
-}
-
-//================================================================
-Handle_Image_Image AlienImage_GIFAlienImage::ToImage () const
-{
- return myData->ToImage();
-}
-
-//================================================================
-void AlienImage_GIFAlienImage::FromImage (const Handle_Image_Image& anImage)
-{
- myData->FromImage(anImage);
-}
-
+++ /dev/null
-// Created by: DCB
-// Copyright (c) 1998-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Notes: Most of code is taken from Xw_save_gif_image.c file (ZOV)
-
-#include <AlienImage_GIFLZWDict.hxx>
-#include <stdio.h>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_GIFLZWDict)
-{
- static Handle(Standard_Type) _atype =
- new Standard_Type ("AlienImage_GIFLZWDict", sizeof (AlienImage_GIFLZWDict));
- return _atype;
-}
-
-//=============================================================================
-// Functions to write GIF image to file.
-//=============================================================================
-
-//===================== Static definitions ===================
-static AlienImage_GIFLZWDict* dict;
-static int startBits, codeBits, nextCode, bumpCode, rack, mask, putIdx,
- ClearCode, EOFCode, FreeCode;
-
-static void _init_dict (void);
-static int _find_child (int, int);
-static BOOL _put_bits (BYTE *, ULONG, UINT, OSD_File&);
-static BOOL _flush_bits (BYTE *, OSD_File&);
-
-
-//=============================================================================
-int _lzw_encode (OSD_File& file, const BYTE* pData, int width, int height, int inc)
-{
- int i, x, y;
- BYTE byte, OutBuff [BUFF_SIZE];
- const BYTE *pLine;
- int strCode, chr;
-
- dict = (AlienImage_GIFLZWDict*) malloc (sizeof (AlienImage_GIFLZWDict)*TBL_SIZE);
- if (dict == NULL)
- goto _ExitError;
-
- x = y = 0;
- pLine = pData;
-
- OutBuff[ 0 ] = 0;
- putIdx = 1;
- mask = 0x01;
- rack = 0;
- startBits = 8;
- ClearCode = 1 << startBits;
- EOFCode = ClearCode + 1;
- FreeCode = EOFCode + 1;
-
- _init_dict ();
-
- byte = startBits;
-
- file.Write (&byte, sizeof(byte));
- if (file.Failed ())
- goto _ExitError;
-
- strCode = pLine[ x++ ];
-
- if (!_put_bits (OutBuff, (ULONG) ClearCode, codeBits, file))
- goto _ExitError;
-
- while (y < height) {
-
- chr = pLine[ x++ ];
-
- i = _find_child ( strCode, chr );
-
- if ( dict[ i ].code != UNUSED )
- strCode = dict[ i ].code;
-
- else {
- dict[ i ].code = nextCode++;
- dict[ i ].prnt = strCode;
- dict[ i ].byte = chr;
-
- if (!_put_bits (OutBuff, (ULONG) strCode, codeBits, file))
- goto _ExitError;
-
- strCode = chr;
-
- if (nextCode > MAX_CODE) {
- if (!_put_bits (OutBuff, (ULONG) ClearCode, codeBits, file))
- goto _ExitError;
-
- _init_dict ();
- }
- else if (nextCode > bumpCode) {
- ++codeBits;
- bumpCode <<= 1;
- }
- }
-
- if (x == width) {
- x = 0;
- ++y;
- pLine += inc;
- }
- }
-
- if (!_put_bits (OutBuff, (ULONG) strCode, codeBits, file)) goto _ExitError;
- if (!_put_bits (OutBuff, (ULONG) EOFCode, codeBits, file)) goto _ExitError;
- if (!_flush_bits (OutBuff, file)) goto _ExitError;
-
- if (dict)
- free (dict);
- return TRUE;
-
-
-_ExitError:
- if (dict)
- free (dict);
- return FALSE;
-}
-
-//====================================================================
-static void _init_dict ()
-{
- memset (dict, UNUSED, sizeof (AlienImage_GIFLZWDict)*TBL_SIZE);
- nextCode = FreeCode;
- codeBits = startBits + 1;
- bumpCode = 1 << codeBits;
-}
-
-//====================================================================
-static int _find_child (int prntCode, int chr)
-{
- int idx, offset;
-
- idx = ( chr << ( NBITS - 8 ) ) ^ prntCode;
- offset = idx ? TBL_SIZE - idx : 1;
-
- for (;;) {
-
- if (dict[ idx ].code == UNUSED ||
- dict[ idx ].prnt == prntCode && dict[ idx ].byte == ( BYTE )chr)
- return idx;
-
- idx = ( idx >= offset ) ? idx - offset : idx + TBL_SIZE - offset;
- }
-}
-
-//====================================================================
-static BOOL _put_bits (BYTE *OutBuff, ULONG code, UINT nBits, OSD_File& file)
-{
- BOOL retVal = TRUE;
- ULONG msk;
-
- msk = 1;
-
- while (msk != (ULONG) (1 << nBits)) {
- if ( msk & code )
- rack |= mask;
- mask <<= 1;
-
- if ((mask & 0xFF) == 0) {
- OutBuff[ putIdx++ ] = rack;
- ++OutBuff[ 0 ];
-
- if (putIdx == BUFF_SIZE) {
- file.Write (OutBuff, BUFF_SIZE);
- if (file.Failed ()) {
- retVal = FALSE;
- break;
- }
- putIdx = 1;
- OutBuff[ 0 ] = 0;
- }
- rack = 0;
- mask = 0x01;
- }
- msk <<= 1;
- }
- return retVal;
-}
-
-//====================================================================
-static BOOL _flush_bits (BYTE* OutBuff, OSD_File& file)
-{
- BOOL retVal = TRUE;
- BYTE byte;
-
- if ( mask != 0x01 ) {
- OutBuff[ putIdx++ ] = rack;
- ++OutBuff[ 0 ];
- }
-
- if (putIdx != 1) {
- file.Write (OutBuff, putIdx);
- if (file.Failed ())
- retVal = FALSE;
- }
-
- if (retVal) {
- byte = 0;
- file.Write (&byte, 1);
- if (file.Failed ())
- retVal = FALSE;
- }
- return retVal;
-}
-
-//=============================================================================
-// Functions to convert from 24 to 8 color image
-//=============================================================================
-static int __fastcall quick_check ( PBYTE, int, int, PBYTE, LPRGBQUAD );
-//static int __fastcall quick_quant ( PBYTE, int, int, PBYTE, LPRGBQUAD );
-static int __fastcall ppm_quant ( PBYTE, int, int, PBYTE, LPRGBQUAD );
-
-BOOL __fastcall _convert24to8 (
- LPRGBQUAD cTable, PBYTE pData24, PBYTE pData8,
- int w, int h
- )
-{
- BOOL retVal = FALSE;
- while ( 1 ) {
- if ( quick_check ( pData24, w, h, pData8, cTable ) ) {
-okRet:
- retVal = TRUE;
- break;
- } else if ( ppm_quant ( pData24, w, h, pData8, cTable ) != -1 ) {
-////////////////////
- for ( int i = 0; i < 256; ++i ) {
- BYTE b = cTable[ i ].rgbRed;
- cTable[ i ].rgbRed = cTable[ i ].rgbBlue;
- cTable[ i ].rgbBlue = b;
- } // end for
-////////////////////
- goto okRet;
- } // end if
- break;
- } // end while
- return retVal;
-} // end _convert24to8
-
-//*************************************************************************//
-//* The following code based on code from the 'pbmplus' package written by //
-//* Jef Poskanzer //
-//*************************************************************************//
-//***//
-#define MAXCOLORS 32767
-
-#define PPM_GETR( p ) ( ( p ).r )
-#define PPM_GETG( p ) ( ( p ).g )
-#define PPM_GETB( p ) ( ( p ).b )
-
-#define PPM_ASSIGN( p, red, grn, blu ) \
- { ( p ).r = ( red ); ( p ).g = ( grn ); ( p ).b = ( blu ); }
-
-#define PPM_EQUAL( p, q ) \
- ( ( p ).r == ( q ).r && ( p ).g == ( q ).g && ( p ).b == ( q ).b )
-
-
-#define PPM_DEPTH( newp, p, oldmaxval, newmaxval ) \
- PPM_ASSIGN( \
- ( newp ), \
- ( ( int )PPM_GETR( p ) ) * ( ( int )newmaxval ) / ( ( int )oldmaxval ), \
- ( ( int )PPM_GETG( p ) ) * ( ( int )newmaxval ) / ( ( int )oldmaxval ), \
- ( ( int )PPM_GETB( p ) ) * ( ( int )newmaxval ) / ( ( int )oldmaxval ) \
- )
-
-
-#define HASH_SIZE 6553
-
-#define ppm_hashpixel( p ) \
- ( ( ( ( int )PPM_GETR( p ) * 33023 + \
- ( int )PPM_GETG( p ) * 30013 + \
- ( int )PPM_GETB( p ) * 27011 \
- ) & 0x7fffffff \
- ) % HASH_SIZE \
- )
-
-#define PPM_LUMIN( p ) \
- ( 77 * PPM_GETR( p ) + 150 * PPM_GETG( p ) + 29 * PPM_GETB( p ) )
-
-typedef struct { BYTE r, g, b; } pixel;
-
-struct chist_item {
- pixel color;
- int value;
- };
-
-typedef struct chist_item* chist_vec;
-
-typedef struct chist_list_item* chist_list;
-typedef chist_list* chash_table;
-
-struct chist_list_item {
- struct chist_item ch;
- chist_list next;
- };
-
-struct box {
- int index;
- int colors;
- int sum;
- };
-
-typedef struct box* box_vector;
-
-static chist_vec __fastcall ppm_computechist ( pixel**, int, int, int, PINT );
-static void __fastcall ppm_freechist ( chist_vec );
-static chist_vec __fastcall mediancut ( chist_vec, int, int, int, int );
-static chash_table ppm_allocchash ( void );
-static void __fastcall ppm_freechash ( chash_table );
-static chash_table __fastcall ppm_computechash ( pixel**, int, int, int, PINT );
-static chist_vec __fastcall ppm_chashtochist ( chash_table, int );
-
-static int redcompare ( const void*, const void* );
-static int greencompare ( const void*, const void* );
-static int bluecompare ( const void*, const void* );
-static int sumcompare ( const void*, const void* );
-
-static int __fastcall ppm_quant (
- PBYTE pic24, int cols, int rows, PBYTE pic8, LPRGBQUAD rgbmap
- ) {
-
-
- pixel** pixels;
- pixel* pP;
- int row;
- int col, limitcol;
- BYTE maxval, newmaxval;
- int colors;
- int index;
- chist_vec chv, colormap;
- chash_table cht;
- int i;
- PBYTE picptr;
- LPRGBQUAD pRGB;
- int pad;
-
- index = 0;
- maxval = 255;
-// pad = PAD( cols * 3 );
- pad = 0;
-
- pixels = ( pixel** )MALLOC( rows * sizeof ( pixel* ) );
-
- if ( pixels == NULL ) return -1;
-
- for ( row = 0; row < rows; ++row ) {
-
- pixels[ row ] = ( pixel* )MALLOC( cols * sizeof ( pixel ) );
-
- if ( pixels[ row ] == NULL ) {
-freeMemory:
- while ( --row >= 0 ) FREE( pixels[ row ] );
-
- FREE( pixels );
-
- return -1;
-
- } // end if
-
- for ( col = 0, pP = pixels[ row ]; col < cols; ++col, ++pP ) {
-
- pP -> r = *pic24++;
- pP -> g = *pic24++;
- pP -> b = *pic24++;
-
- } // end for
-
- pic24 += pad;
-
- } // end for
-
- for ( ;; ) {
-
- chv = ppm_computechist ( pixels, cols, rows, MAXCOLORS, &colors );
-
- if ( chv != ( chist_vec )0 ) break;
-
- newmaxval = maxval / 2;
-
- for ( row = 0; row < rows; ++row )
-
- for ( col = 0, pP = pixels[ row ]; col < cols; ++col, ++pP )
-
- PPM_DEPTH( *pP, *pP, maxval, newmaxval );
-
- maxval = newmaxval;
-
- } // end for
-
- colormap = mediancut ( chv, colors, rows * cols, maxval, 256 );
-
- if ( colormap == ( chist_vec )NULL ) {
-freeMemory_1:
- ppm_freechist ( chv );
- row = rows;
- goto freeMemory;
-
- } // end if
-
- ppm_freechist ( chv );
-
- cht = ppm_allocchash ();
-
- picptr = pic8;
-
- for ( row = 0; row < rows; ++row ) {
-
- col = 0;
- limitcol = cols;
- pP = pixels[ row ];
-
- do {
-
- int hash;
- chist_list chl;
-
- hash = ppm_hashpixel ( *pP );
-
- for ( chl = cht[ hash ]; chl; chl = chl -> next )
-
- if ( PPM_EQUAL( chl -> ch.color, *pP ) ) {
-
- index = chl -> ch.value;
- break;
-
- } // end if
-
- if ( !chl ) {
-
- int i, r1, g1, b1, r2, g2, b2;
- long dist, newdist;
-
- r1 = PPM_GETR( *pP );
- g1 = PPM_GETG( *pP );
- b1 = PPM_GETB( *pP );
- dist = 2000000000;
-
- for ( i = 0; i < 256; ++i ) {
-
- r2 = PPM_GETR( colormap[ i ].color );
- g2 = PPM_GETG( colormap[ i ].color );
- b2 = PPM_GETB( colormap[ i ].color );
-
- newdist = ( r1 - r2 ) * ( r1 - r2 ) +
- ( g1 - g2 ) * ( g1 - g2 ) +
- ( b1 - b2 ) * ( b1 - b2 );
-
- if ( newdist < dist ) {
-
- index = i;
- dist = newdist;
-
- } // end if
-
- } // end for
-
- hash = ppm_hashpixel( *pP );
- chl = ( chist_list )MALLOC( sizeof ( struct chist_list_item ) );
-
- if ( chl == NULL ) {
-
- ppm_freechash ( cht );
- goto freeMemory_1;
-
- } // end if
-
- chl -> ch.color = *pP;
- chl -> ch.value = index;
- chl -> next = cht[ hash ];
- cht[ hash ] = chl;
-
- } // end if
-
- *picptr++ = index;
- ++col;
- ++pP;
-
- } while ( col != limitcol );
-
- } // end for
-
- for ( i = 0, pRGB = rgbmap; i < 256; ++i, ++pRGB ) {
-
- PPM_DEPTH( colormap[ i ].color, colormap[ i ].color, maxval, 255 );
-
- pRGB -> rgbRed = PPM_GETR( colormap[ i ].color );
- pRGB -> rgbGreen = PPM_GETG( colormap[ i ].color );
- pRGB -> rgbBlue = PPM_GETB( colormap[ i ].color );
-
- } // end for
-
- for ( i = 0; i < rows; ++i ) FREE( pixels[ i ] );
-
- FREE( pixels );
-
- ppm_freechist ( colormap );
- ppm_freechash ( cht );
-
- return 0;
-
-} // end ppm_quant
-
-static void __fastcall ppm_freechist ( chist_vec chv ) {
-
- FREE( ( LPVOID )chv );
-
-} // end ppm_freechist
-
-static chist_vec __fastcall mediancut (
- chist_vec chv, int colors, int sum,
- int maxval, int newcolors
- ) {
-
- chist_vec colormap;
- box_vector bv;
- int bi, i;
- int boxes;
-
- bv = ( box_vector )MALLOC( sizeof( struct box ) * newcolors );
-
- if ( bv == NULL ) return ( chist_vec )NULL;
-
- colormap = ( chist_vec )MALLOC( sizeof( struct chist_item ) * newcolors );
-
- if ( colormap == NULL ) {
-
- FREE( bv );
- return ( chist_vec )NULL;
-
- } // end if
-
- for ( i = 0; i < newcolors; ++i ) PPM_ASSIGN( colormap[ i ].color, 0, 0, 0 );
-
- bv[ 0 ].index = 0;
- bv[ 0 ].colors = colors;
- bv[ 0 ].sum = sum;
- boxes = 1;
-
- while ( boxes < newcolors ) {
-
- int indx, clrs;
- int sm;
- int minr, maxr, ming, maxg, minb, maxb, v;
- int halfsum, lowersum;
-
- for ( bi = 0; bv[ bi ].colors < 2 && bi < boxes; ++bi );
-
- if ( bi == boxes ) break;
-
- indx = bv[ bi ].index;
- clrs = bv[ bi ].colors;
- sm = bv[ bi ].sum;
-
- minr = maxr = PPM_GETR( chv[ indx ].color );
- ming = maxg = PPM_GETG( chv[ indx ].color );
- minb = maxb = PPM_GETB( chv[ indx ].color );
-
- for ( i = 1; i < clrs; ++i ) {
-
- v = PPM_GETR( chv[ indx + i ].color );
-
- if ( v < minr ) minr = v;
- if ( v > maxr ) maxr = v;
-
- v = PPM_GETG( chv[ indx + i ].color );
-
- if ( v < ming ) ming = v;
- if ( v > maxg ) maxg = v;
-
- v = PPM_GETB( chv[ indx + i ].color );
-
- if ( v < minb ) minb = v;
- if ( v > maxb ) maxb = v;
-
- } // end for
-
- { // begin local block
-
- pixel p;
- int rl, gl, bl;
-
- PPM_ASSIGN( p, maxr - minr, 0, 0 );
- rl = PPM_LUMIN( p );
-
- PPM_ASSIGN( p, 0, maxg - ming, 0 );
- gl = PPM_LUMIN( p );
-
- PPM_ASSIGN( p, 0, 0, maxb - minb );
- bl = PPM_LUMIN( p );
-
- if ( rl >= gl && rl >= bl )
-
- qsort (
- ( char* )&chv[ indx ], ( size_t )clrs,
- sizeof ( struct chist_item ), redcompare
- );
-
- else if ( gl >= bl )
-
- qsort (
- ( char* )&chv[ indx ], ( size_t )clrs,
- sizeof ( struct chist_item ), greencompare
- );
-
- else
-
- qsort (
- ( char* )&chv[ indx ], ( size_t )clrs,
- sizeof ( struct chist_item ), bluecompare
- );
-
- } // end local block
-
- lowersum = chv[ indx ].value;
- halfsum = sm / 2;
-
- for ( i = 1; i < clrs - 1; ++i) {
-
- if ( lowersum >= halfsum ) break;
-
- lowersum += chv[ indx + i ].value;
-
- } // end for
-
- bv[ bi ].colors = i;
- bv[ bi ].sum = lowersum;
-
- bv[ boxes ].index = indx + i;
- bv[ boxes ].colors = clrs - i;
- bv[ boxes++ ].sum = sm - lowersum;
-
- qsort (
- ( char* )bv, ( size_t )boxes, sizeof ( struct box ), sumcompare
- );
-
- } // end while
-
- for ( bi = 0; bi < boxes; ++bi ) {
-
- int indx = bv[ bi ].index;
- int clrs = bv[ bi ].colors;
- long r = 0, g = 0, b = 0, sum = 0;
-
- for ( i = 0; i < clrs; ++i ) {
-
- r += PPM_GETR( chv[ indx + i ].color ) * chv[ indx + i ].value;
- g += PPM_GETG( chv[ indx + i ].color ) * chv[ indx + i ].value;
- b += PPM_GETB( chv[ indx + i ].color ) * chv[ indx + i ].value;
-
- sum += chv[ indx + i ].value;
-
- } // end for ( i . . . )
-
- r = r / sum; if ( r > maxval ) r = maxval;
- g = g / sum; if ( g > maxval ) g = maxval;
- b = b / sum; if ( b > maxval ) b = maxval;
-
- PPM_ASSIGN( colormap[ bi ].color, ( BYTE )r, ( BYTE )g, ( BYTE )b );
-
- } // end for ( bi . . . )
-
- FREE( bv );
-
- return colormap;
-
-} // end mediancut
-
-static int redcompare ( const void* p1, const void* p2 ) {
-
- return ( int )PPM_GETR( ( ( chist_vec )p1 ) -> color ) -
- ( int )PPM_GETR( ( ( chist_vec )p2 ) -> color );
-
-} // end redcompare
-
-static int greencompare ( const void* p1, const void* p2 ) {
-
- return ( int )PPM_GETG( ( ( chist_vec )p1 ) -> color ) -
- ( int )PPM_GETG( ( ( chist_vec )p2 ) -> color );
-
-} // end greencompare
-
-static int bluecompare ( const void* p1, const void* p2 ) {
-
- return ( int )PPM_GETB( ( ( chist_vec )p1 ) -> color ) -
- ( int )PPM_GETB( ( ( chist_vec )p2 ) -> color );
-
-} // end bluecompare
-
-static int sumcompare ( const void* p1, const void* p2 ) {
-
- return ( ( box_vector )p2 ) -> sum - ( ( box_vector )p1 ) -> sum;
-
-} // end sumcompare
-
-static chash_table ppm_allocchash ( void ) {
-
- chash_table cht;
-
- cht = ( chash_table )MALLOC( HASH_SIZE * sizeof ( chist_list ) );
-
- return cht;
-
-} // end ppm_allocchash
-
-static chist_vec __fastcall ppm_computechist (
- pixel** pixels, int cols, int rows, int maxcolors,
- PINT colorsP
- ) {
-
- chash_table cht;
- chist_vec chv;
-
- cht = ppm_computechash ( pixels, cols, rows, maxcolors, colorsP );
-
- if ( cht == NULL ) return ( chist_vec )NULL;
-
- chv = ppm_chashtochist ( cht, maxcolors );
-
- ppm_freechash ( cht );
-
- return chv;
-
-} // end ppm_computechist
-
-static chash_table __fastcall ppm_computechash (
- pixel** pixels, int cols, int rows, int maxcolors,
- PINT colorsP
- ) {
-
- chash_table cht;
- register pixel* pP;
- chist_list chl;
- int col, row, hash;
-
- cht = ppm_allocchash ();
- *colorsP = 0;
-
- for ( row = 0; row < rows; ++row )
-
- for ( col = 0, pP = pixels[ row ]; col < cols; ++col, ++pP ) {
-
- hash = ppm_hashpixel ( *pP );
-
- for ( chl = cht[ hash ]; chl != ( chist_list )0; chl = chl -> next )
-
- if ( PPM_EQUAL( chl -> ch.color, *pP ) ) break;
-
- if ( chl != ( chist_list)0 )
-
- ++( chl->ch.value );
-
- else {
-
- if ( ( *colorsP )++ > maxcolors ) {
-
- ppm_freechash ( cht );
-
- return ( chash_table )NULL;
-
- } // end if
-
- chl = ( chist_list )MALLOC( sizeof( struct chist_list_item ) );
-
- if ( chl == NULL ) return ( chash_table )NULL;
-
- chl -> ch.color = *pP;
- chl -> ch.value = 1;
- chl -> next = cht[ hash ];
- cht[ hash ] = chl;
-
- } // end else
-
- } // end for
-
- return cht;
-
-} // end ppm_computechash
-
-static chist_vec __fastcall ppm_chashtochist ( chash_table cht, int maxcolors ) {
-
- chist_vec chv;
- chist_list chl;
- int i, j;
-
- chv = ( chist_vec )MALLOC( maxcolors * sizeof ( struct chist_item ) );
-
- if ( chv == NULL) return chv;
-
- j = 0;
-
- for ( i = 0; i < HASH_SIZE; ++i )
-
- for ( chl = cht[ i ]; chl != ( chist_list )0; chl = chl -> next ) {
-
- chv[ j ] = chl -> ch;
- ++j;
-
- } // end for
-
- return chv;
-
-} // end ppm_chashtochist
-
-static void __fastcall ppm_freechash ( chash_table cht ) {
-
- int i;
- chist_list chl, chlnext;
-
- for ( i = 0; i < HASH_SIZE; ++i )
-
- for ( chl = cht[ i ]; chl != ( chist_list )0; chl = chlnext ) {
-
- chlnext = chl -> next;
- FREE( chl );
-
- } // end for
-
- FREE( cht );
-
-} // end ppm_freechash
-
-static int __fastcall quick_check (
- PBYTE pic24, int w, int h, PBYTE pic8, LPRGBQUAD rgbmap
- ) {
-
- unsigned long colors[ 256 ], col;
- int i, j, nc, low, high, mid, pad;
- PBYTE p, pix;
-
- nc = 0;
- mid = 0;
-// pad = PAD( w * 3 );
- pad = 0;
-
- for ( i = 0, p = pic24; i < h; ++i ) {
-
- for ( j = 0; j < w; ++j ) {
-
- col = ( ( ( unsigned long )*p++ ) << 16 );
- col += ( ( ( unsigned long )*p++ ) << 8 );
- col += ( ( ( unsigned long )*p++ ) << 0 );
-
- low = 0; high = nc - 1;
-
- while ( low <= high ) {
-
- mid = ( low + high ) / 2;
-
- if ( col < colors[ mid ] )
-
- high = mid - 1;
-
- else if ( col > colors[ mid ] )
-
- low = mid + 1;
-
- else break;
-
- } // end while
-
- if ( high < low ) {
-
- if ( nc >= 256 ) return FALSE;
-
- memcpy (
- ( char* )&colors[ low + 1 ], ( char* )&colors[ low ],
- ( nc - low ) * sizeof ( unsigned long )
- );
-
- colors[ low ] = col;
- ++nc;
-
- } // end if
-
- } // end for ( j . . . )
-
- p += pad;
-
- } // end for ( i . . . )
-
- for ( i = 0, p = pic24, pix = pic8; i < h; ++i ) {
-
- for ( j = 0; j < w; ++j ) {
-
- col = ( ( ( unsigned long )*p++ ) << 16 );
- col += ( ( ( unsigned long )*p++ ) << 8 );
- col += *p++;
-
- low = 0; high = nc - 1;
-
- while ( low <= high ) {
-
- mid = ( low + high ) / 2;
-
- if ( col < colors[ mid ] )
-
- high = mid - 1;
-
- else if ( col > colors[ mid ] )
-
- low = mid + 1;
-
- else break;
-
- } // end while
-
- *pix++ = mid;
-
- } // end for ( j . . . )
-
- p += pad;
-
- } // end for ( i . . . )
-
- for ( i = 0; i < nc; ++i, ++rgbmap ) {
-
- rgbmap -> rgbRed = ( BYTE )( colors[ i ] >> 0 ) & 0xFF;
- rgbmap -> rgbGreen = ( BYTE )( colors[ i ] >> 8 ) & 0xFF;
- rgbmap -> rgbBlue = ( BYTE )( colors[ i ] >> 16 ) & 0xFF;
-
- } // end for
-
- return nc;
-
-} // end quick_check
-
-#ifdef BSHIFT //HPUX COMPATIBILLITY
-#undef BSHIFT
-#endif
-#define RMASK 0xE0
-#define RSHIFT 0
-#define GMASK 0xE0
-#define GSHIFT 3
-#define BMASK 0xC0
-#define BSHIFT 6
-#define RANGE( a, b, c ) { if ( a < b ) a = b; if ( a > c ) a = c; }
-
-//static int __fastcall quick_quant (
-// PBYTE p24, int w, int h, PBYTE p8, LPRGBQUAD rgbmap
-// ) {
-
-// PBYTE pp;
-// int r1, g1, b1;
-// PINT thisline, nextline, thisptr, nextptr, tmpptr;
-// int i, j, val, pwide3;
-// int imax, jmax;
-// int pad;
-
-//// pad = PAD( w * 3 );
-// pad = 0;
-
-// pp = p8;
-// pwide3 = w * 3;
-// imax = h - 1;
-// jmax = w - 1;
-
-// for ( i = 0; i < 256; ++i ) {
-
-// rgbmap[ i ].rgbRed = ( ( ( i << RSHIFT ) & RMASK ) * 255 + RMASK / 2 ) / RMASK;
-// rgbmap[ i ].rgbGreen = ( ( ( i << GSHIFT ) & GMASK ) * 255 + GMASK / 2 ) / GMASK;
-// rgbmap[ i ].rgbBlue = ( ( ( i << BSHIFT ) & BMASK ) * 255 + BMASK / 2 ) / BMASK;
-
-// } // end for
-
-// thisline = ( PINT )MALLOC( pwide3 * sizeof ( int ) );
-
-// if ( thisline == NULL ) return 1;
-
-// nextline = ( PINT )MALLOC( pwide3 * sizeof ( int ) );
-
-// if ( nextline == NULL ) {
-
-// FREE( thisline );
-// return 1;
-
-// } // end if
-
-// for ( j = pwide3, tmpptr = nextline; j; --j ) *tmpptr++ = ( int )*p24++;
-
-// p24 += pad;
-
-// for ( i = 0; i < h; ++i ) {
-
-// tmpptr = thisline;
-// thisline = nextline;
-// nextline = tmpptr;
-//
-// if ( i != imax ) {
-
-// for ( j = pwide3, tmpptr = nextline; j; --j ) *tmpptr++ = ( int )*p24++;
-//
-// p24 += pad;
-
-// } // end if
-
-// for ( j = 0, thisptr = thisline, nextptr = nextline; j < w; ++j, ++pp ) {
-
-// r1 = *thisptr++;
-// RANGE( r1, 0, 255 );
-
-// g1 = *thisptr++;
-// RANGE(g1,0,255);
-
-// b1 = *thisptr++;
-// RANGE(b1,0,255);
-
-// val = ( ( ( r1 & RMASK ) >> RSHIFT ) |
-// ( ( g1 & GMASK ) >> GSHIFT ) |
-// ( ( b1 & BMASK ) >> BSHIFT ) );
-// *pp = val;
-
-// r1 -= rgbmap[ val ].rgbRed;
-// g1 -= rgbmap[ val ].rgbGreen;
-// b1 -= rgbmap[ val ].rgbBlue;
-
-// if ( j != jmax ) {
-
-// thisptr[ 0 ] += ( r1 * 7 ) / 16;
-// thisptr[ 1 ] += ( g1 * 7 ) / 16;
-// thisptr[ 2 ] += ( b1 * 7 ) / 16;
-
-// } // end if
-
-// if ( i != imax ) {
-
-// nextptr[ 0 ] += ( r1 * 5 ) / 16;
-// nextptr[ 1 ] += ( g1 * 5 ) / 16;
-// nextptr[ 2 ] += ( b1 * 5 ) / 16;
-
-// if ( j > 0 ) {
-
-// nextptr[ -3 ] += ( r1 * 3 ) / 16;
-// nextptr[ -2 ] += ( g1 * 3 ) / 16;
-// nextptr[ -1 ] += ( b1 * 3 ) / 16;
-
-// } // end if
-
-// if ( j != jmax ) {
-
-// nextptr[ 3 ] += ( r1 ) / 16;
-// nextptr[ 4 ] += ( g1 ) / 16;
-// nextptr[ 5 ] += ( b1 ) / 16;
-
-// } // end if
-
-// nextptr += 3;
-
-// } // end if
-
-// } // end for ( j . . . )
-
-// } // end for ( i . . . )
-
-// FREE( thisline );
-// FREE( nextline );
-
-// return 0;
-
-//} // end quick_quant
-//***//
-//*************************************************************************//
-
+++ /dev/null
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_GIFLZWDict.hxx
-//============================================================================
-
-#ifndef _AlienImage_GIFLZWDict_HeaderFile
-#define _AlienImage_GIFLZWDict_HeaderFile
-
-//==== Definition de Type ====================================================
-#include <Standard_Type.hxx>
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_GIFLZWDict);
-
-//============================================================================
-#include <OSD_File.hxx>
-
-#ifndef WNT
-typedef unsigned int DWORD; // 32-bit signed
-typedef int LONG; // 32-bit unsigned
-typedef unsigned int ULONG, UINT; // 32-bit signed
-typedef unsigned short WORD; // 16-bit unsigned
-typedef unsigned char BYTE; // 8-bit unsigned
-typedef unsigned int BOOL;
-typedef int* PINT;
-typedef unsigned char* PBYTE;
-typedef void* LPVOID;
-#else
-#ifdef NOGDI
-#undef NOGDI /* we need GDI definitions here... */
-#endif
-# include <windows.h>
-#endif
-
-#if defined(__alpha) || defined(DECOSF1) || defined(WNT)
-# define SWAP_WORD(__w) (__w)
-# define SWAP_DWORD(__w) (__w)
-#else
-# define SWAP_WORD(__w) ((((__w)&0xFF) << 8) | (((__w)&0xFF00) >> 8))
-# define SWAP_DWORD(__w) ((((__w)&0x000000FF) << 24) | (((__w)&0x0000FF00) << 8) \
- | (((__w)&0xFF0000) >> 8) | (((__w)&0xFF000000) >> 24) )
-#endif
-
-#define NBITS 12
-#define TBL_SIZE 5021
-#define MAX_CODE ( ( 1 << NBITS ) - 1 )
-#define BUFF_SIZE 255
-#define UNUSED -1
-#define TRUE 1
-#define FALSE 0
-
-//=============================================================================
-// Functions and structs to write GIF image to file.
-//=============================================================================
-extern int _lzw_encode (OSD_File&, const BYTE*, int, int, int);
-
-typedef struct {
- char gifID[ 6 ];
- WORD scrnWidth;
- WORD scrnHeight;
- BYTE scrnFlag;
-} SCREEN_DESCR;
-
-typedef struct {
- WORD imgX;
- WORD imgY;
- WORD imgWidth;
- WORD imgHeight;
- BYTE imgFlag;
-} IMAGE_DESCR;
-
-typedef struct {
- int code;
- int prnt;
- BYTE byte;
-} AlienImage_GIFLZWDict;
-
-//=============================================================================
-// Functions to convert from 24 to 8 color image
-//=============================================================================
-#define PAD(a) ( ( a ) % sizeof ( LONG ) ? \
- sizeof ( LONG ) - ( ( a ) % sizeof ( LONG ) ) : 0 )
-#define MALLOC(s) calloc ( ( s ), 1 )
-#define FREE(p) free ( ( p ) )
-
-#ifndef WNT
-typedef struct {
- BYTE rgbBlue;
- BYTE rgbGreen;
- BYTE rgbRed;
- BYTE rgbReserved;
-} RGBQUAD, *LPRGBQUAD;
-
-#define __fastcall
-#endif // WNT
-
-BOOL __fastcall _convert24to8 (LPRGBQUAD, PBYTE, PBYTE, int, int);
-
-#endif // _AlienImage_GIFLZWDict_HeaderFile
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL,JLF
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class MemoryOperations from AlienImage
-
- ---Version: 0.0
-
- ---Level: Public
- ---Purpose: This class defines class method for
- -- memory mangement .
- ---Keywords:
- ---Warning:
- ---References:
---uses
-
-raises
- NullObject
-
-is
- SwapLong ( myclass ; Data : in Address from Standard
- ; Size : in Integer from Standard )
- ---Level: Internal
- ---Purpose: Swap byte in a long word ( 32 Bit )
- -- Size is the number of long word to swap
- -- ex : SwapLong( "abcd". 1 ) gives "dcba"
- --
- raises NullObject;
-
- SwapShort( myclass ; Data : in Address from Standard
- ; Size : in Integer from Standard )
- ---Level: Internal
- ---Purpose: Swap byte in a short word ( 16 Bit )
- -- Size is the number of short word to swap
- -- ex : SwapShort( "ab". 1 ) gives "ba"
- --
- raises NullObject;
-
-end MemoryOperations;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <Standard_NullObject.hxx>
-
-#include <AlienImage_MemoryOperations.ixx>
-
-
-void AlienImage_MemoryOperations::SwapLong( const Standard_Address Data,
- const Standard_Integer Size )
-
-{
- register char c;
- register char *bp = ( char * )Data ;
- register char *ep = ( char * )Data + Size ;
- register char *sp;
-
- if ( Data == NULL)
- Standard_NullObject::Raise("AlienImage_MemoryOperations : SwapLong");
-
- while (bp < ep) {
- sp = bp + 3;
- c = *sp;
- *sp = *bp;
- *bp++ = c;
- sp = bp + 1;
- c = *sp;
- *sp = *bp;
- *bp++ = c;
- bp += 2;
- }
-}
-
-void AlienImage_MemoryOperations::SwapShort( const Standard_Address Data,
- const Standard_Integer Size )
-
-{
- register char c;
- register char *ep = ( char * )Data + Size ;
- register char *bp = ( char * )Data ;
-
- if ( Data == NULL)
- Standard_NullObject::Raise("AlienImage_MemoryOperations : SwapLong");
-
- while (bp < ep) {
- c = *bp;
- *bp = *(bp + 1);
- bp++;
- *bp++ = c;
- }
-}
-
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class SGIRGBAlienData from AlienImage inherits AlienImageData from AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines a SGI .rgb Alien image.
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- X11XColor from AlienImage,
- SGIRGBFileHeader from AlienImage
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable SGIRGBAlienData from AlienImage ;
-
- Clear( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by SGIRGBAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a SGIRGBAlienData object from a file .
- -- Returns True if file is a SGI .rgb file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a SGIRGBAlienData object to a file .
-
- SetName( me : in out mutable ;
- aName : in AsciiString from TCollection)
- is redefined;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection
- is redefined;
- ---C++: return const &
- ---Level: Public
- ---Purpose: Get Image name .
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a SGIRGBAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a SGIRGBAlienData object.
-
- --
- -- Private Method
- --
-
- ToPseudoColorImage( me : in immutable)
- returns PseudoColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a AlienImage object to a Image object.
-
- ToColorImage( me : in immutable)
- returns ColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a AlienImage object to a Image object.
-
-fields
-
- myHeader : SGIRGBFileHeader from AlienImage is protected ;
- myRedData, myGreenData, myBlueData : Address from Standard is protected;
- -- ( unsigned short * )
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// Modified 27/12/97 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
-// Modified 08/12/98 : FMN ; SGI : Changement option de compilation
-
-#include <Aspect_ColorRampColorMap.hxx>
-#include <Image_PseudoColorImage.hxx>
-#include <AlienImage_SGIRGBFileHeader.hxx>
-#include <AlienImage_SGIRGBAlienData.ixx>
-#include <Standard.hxx>
-
-#define TRACE
-
-#include <stdio.h>
-#if !defined(_IOERR)
-# define _IOERR 0040 /* I/O error from system */
-#endif
-#if !defined(_IOREAD)
-# define _IOREAD 0001 /* currently reading */
-#endif
-#if !defined(_IOWRT)
-# define _IOWRT 0002 /* currently writing */
-#endif
-#if !defined(_IORW)
-# define _IORW 0200 /* opened for reading and writing */
-#endif
-
-#ifdef TRACE
-static int Verbose = 0 ;
-#endif
-
-#define LOPTIM
-#ifndef LOPTIM
-static Handle(Aspect_ColorRampColorMap) GrayScaleColorMap =
- new Aspect_ColorRampColorMap( 0,256, Quantity_Color(1.,1.,1.,Quantity_TOC_RGB));
-#else
-static Handle(Aspect_ColorRampColorMap)& _GrayScaleColorMap() {
-static Handle(Aspect_ColorRampColorMap) GrayScaleColorMap =
- new Aspect_ColorRampColorMap( 0,256, Quantity_Color(1.,1.,1.,Quantity_TOC_RGB));
-return GrayScaleColorMap;
-}
-#define GrayScaleColorMap _GrayScaleColorMap()
-#endif // LOPTIM
-
-
-//============================================================================
-//==== C Class Method.
-//============================================================================
-static Standard_Boolean iopen( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- char ,
- unsigned int ,
- unsigned int ,
- unsigned int ,
- unsigned int ,
- unsigned int );
-static void iclose( OSD_File &File,AlienImage_SGIRGBFileHeader *);
-int iflush( OSD_File &File,AlienImage_SGIRGBFileHeader *);
-static void isetname( AlienImage_SGIRGBFileHeader *, const char * );
-#ifdef DEB
-static void isetcolormap( AlienImage_SGIRGBFileHeader *, int );
-#endif
-static int putrow( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- unsigned short *,
- unsigned int ,
- unsigned int );
-static int getrow( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- unsigned short *,
- unsigned int ,
- unsigned int );
-
-
-//------------------------------------------------------------------------------
-// Private Method
-//------------------------------------------------------------------------------
-
-#define DataSize() (myHeader.ysize*myHeader.xsize*sizeof(short))
-
-Handle(Image_ColorImage) AlienImage_SGIRGBAlienData::ToColorImage() const
-
-{ Handle(Image_ColorImage) ret_image =
- new Image_ColorImage( 0,0,
- (Standard_Integer)myHeader.xsize,
- (Standard_Integer)myHeader.ysize ) ;
- unsigned short *rbuf, *gbuf, *bbuf ;
- Aspect_ColorPixel CPixel ;
- Quantity_Color acolor ;
- Standard_Real r,g,b ;
- unsigned short x,y ;
- Standard_Integer LowX = ret_image->LowerX() ;
- Standard_Integer LowY = ret_image->LowerY() ;
-
- rbuf = ( unsigned short * ) myRedData ;
- gbuf = ( unsigned short * ) myGreenData ;
- bbuf = ( unsigned short * ) myBlueData ;
-
- for(y=0; y<myHeader.ysize; y++) {
- for(x=0; x<myHeader.xsize; x++) {
- r = Standard_Real( rbuf[x] ) ;
- r /= 255. ;
- g = Standard_Real( gbuf[x] ) ;
- g /= 255. ;
- b = Standard_Real( bbuf[x] ) ;
- b /= 255. ;
- acolor.SetValues( r,g,b, Quantity_TOC_RGB ) ;
- CPixel.SetValue ( acolor ) ;
-
- ret_image->SetPixel( LowX+x , LowY+y, CPixel ) ;
- }
- rbuf += myHeader.xsize ;
- gbuf += myHeader.xsize ;
- bbuf += myHeader.xsize ;
- }
-
- return( ret_image ) ;
-}
-
-Handle_Image_PseudoColorImage AlienImage_SGIRGBAlienData::ToPseudoColorImage()
- const
-
-{ Handle(Image_PseudoColorImage) ret_image =
- new Image_PseudoColorImage( 0,0,
- (Standard_Integer)myHeader.xsize,
- (Standard_Integer)myHeader.ysize,
- GrayScaleColorMap ) ;
-
- unsigned short *rbuf ;
- Aspect_IndexPixel CPixel ;
- unsigned short x,y ;
- Standard_Integer LowX = ret_image->LowerX() ;
- Standard_Integer LowY = ret_image->LowerY() ;
-
- rbuf = ( unsigned short * ) myRedData ;
-
- for(y=0; y<myHeader.ysize; y++) {
- for(x=0; x<myHeader.xsize; x++) {
- CPixel.SetValue ( Standard_Integer( rbuf[x] ) ) ;
-
- ret_image->SetPixel( LowX+x , LowY+y, CPixel ) ;
- }
- rbuf += myHeader.xsize ;
- }
-
- return ret_image ;
-
-}
-
-#include <stdlib.h>
-#include <string.h>
-
-
-//============================================================================
-//==== C Class Method.
-static unsigned short *ibufalloc(AlienImage_SGIRGBFileHeader *);
-#ifdef DEB
-static unsigned int reverse(unsigned int ) ;
-#endif
-static void cvtshorts( unsigned short [], int );
-static void cvtlongs( int [], int ) ;
-static void cvtimage(int [] );
-static int img_seek( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- unsigned int , unsigned int );
-static int img_badrow( AlienImage_SGIRGBFileHeader *,
- int , int );
-static int img_write( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- char *, int );
-static int img_read( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- char *, int );
-static int img_optseek( OSD_File &File,
- AlienImage_SGIRGBFileHeader *,
- unsigned int );
-static int img_getrowsize( AlienImage_SGIRGBFileHeader * );
-static void img_setrowsize( AlienImage_SGIRGBFileHeader *,
- int , int , int );
-static int img_rle_compact( unsigned short *,
- int ,
- unsigned short *,
- int , int );
-static void img_rle_expand( unsigned short *,
- int ,
- unsigned short *,
- int );
-
-void i_errhdlr(const char *fmt)
-{
- printf("%s",fmt);
- return;
-}
-
-/*
- * iclose and iflush -
- *
- */
-
-static void iclose( OSD_File& File, AlienImage_SGIRGBFileHeader *image)
-{
- int tablesize;
-
- iflush( File, image);
- img_optseek( File, image, 0);
- if (image->flags&_IOWRT) {
- if(image->dorev)
- cvtimage((int *)image);
- if ( img_write( File, image,
- (char *)image,sizeof(AlienImage_SGIRGBFileHeader)) !=
- sizeof(AlienImage_SGIRGBFileHeader)) {
- i_errhdlr("iclose: error on write of image header\n");
- return ;
- }
- if(image->dorev)
- cvtimage((int *)image);
- if(ISRLE(image->type)) {
- img_optseek( File, image, 512);
- tablesize = image->ysize*image->zsize*sizeof(int);
- if(image->dorev)
- cvtlongs((int *)image->rowstart,tablesize);
- if (img_write( File, image,(char *)image->rowstart,tablesize) != tablesize) {
- i_errhdlr("iclose: error on write of rowstart\n");
- return ;
- }
- if(image->dorev)
- cvtlongs((int *)image->rowsize,tablesize);
- if (img_write( File, image,(char *)image->rowsize,tablesize) != tablesize) {
- i_errhdlr("iclose: error on write of rowsize\n");
- return ;
- }
- }
- }
- if(image->base) {
- free(image->base);
- image->base = 0;
- }
- if(image->tmpbuf) {
- free(image->tmpbuf);
- image->tmpbuf = 0;
- }
- if(ISRLE(image->type)) {
- free(image->rowstart);
- image->rowstart = 0;
- free(image->rowsize);
- image->rowsize = 0;
- }
-
-// return(close(image->file));
-}
-
-int iflush( OSD_File& File, AlienImage_SGIRGBFileHeader *image)
-{
- unsigned short *base;
-
- if ( (image->flags&_IOWRT)
- && (base=image->base)!=NULL && (image->ptr-base)>0) {
- if (putrow(File,image, base, image->y,image->z)!=image->xsize) {
- image->flags |= _IOERR;
- return(EOF);
- }
- }
- return 0 ;
-}
-/*
- * isetname and isetcolormap -
- *
- */
-
-static void isetname( AlienImage_SGIRGBFileHeader *image, const char *name )
-{
- strncpy(image->name,name,80);
-}
-
-// Unused :
-#ifdef DEB
-static void isetcolormap(AlienImage_SGIRGBFileHeader *image, int colormap)
-{
- image->colormap = colormap;
-}
-#endif
-/*
- * iopen -
- *
- */
-static Standard_Boolean iopen( OSD_File &File,
- AlienImage_SGIRGBFileHeader *image,
- char mode,
- unsigned int type,
- unsigned int dim,
- unsigned int xsize,
- unsigned int ysize,
- unsigned int zsize )
-{
-
- int tablesize;
- register int i, max;
-
- Standard_Integer bblcount ;
-
- int calsize = sizeof( AlienImage_SGIRGBFileHeader ) ;
- if (mode=='w') { //------------------WRITE------------------
- image->imagic = IMAGIC;
- image->type = type;
- image->xsize = xsize;
- image->ysize = 1;
- image->zsize = 1;
- if (dim>1)
- image->ysize = ysize;
- if (dim>2)
- image->zsize = zsize;
- if(image->zsize == 1) {
- image->dim = 2;
- if(image->ysize == 1)
- image->dim = 1;
- } else {
- image->dim = 3;
- }
- image->min = 10000000;
- image->max = 0;
- isetname(image,"no name");
- image->wastebytes = 0;
- image->dorev = 0;
-
- File.Write( ( Standard_Address ) image, calsize ) ;
- if ( File.Failed() ) {
- // ERROR
- i_errhdlr("iopen: error on write of image header\n");
- return( Standard_False ) ;
- }
- } else {//--------------------------READ------------------------
- File.Read( ( Standard_Address& )image, calsize, bblcount ) ;
- if ( File.Failed() ||
- ( bblcount != calsize ) ) {
-#ifdef TRACE
- // ERROR
- i_errhdlr("iopen: error on read of image header\n");
-#endif
- return( Standard_False ) ;
- }
-
- if( ((image->imagic>>8) | ((image->imagic&0xff)<<8))
- == IMAGIC ) {
- image->dorev = 1;
- cvtimage((int *)image);
- } else
- image->dorev = 0;
- if (image->imagic != IMAGIC) {
-#ifdef TRACE
- i_errhdlr("iopen: bad magic in image file \n");
-#endif
- return Standard_False ;
- }
- }
- if (mode != 'r')
- image->flags = _IOWRT;
- else
- image->flags = _IOREAD;
- if(ISRLE(image->type)) {
- tablesize = image->ysize*image->zsize*sizeof(int);
- image->rowstart = (unsigned int *)malloc(tablesize);
- image->rowsize = (int *)malloc(tablesize);
- if( image->rowstart == 0 || image->rowsize == 0 ) {
- i_errhdlr("iopen: error on table alloc\n");
- return Standard_False ;
- }
- image->rleend = 512+2*tablesize;
- if (mode=='w') {
- max = image->ysize*image->zsize;
- for(i=0; i<max; i++) {
- image->rowstart[i] = 0;
- image->rowsize[i] = -1;
- }
- } else {
- tablesize = image->ysize*image->zsize*sizeof(int);
- File.Seek( 512, OSD_FromBeginning ) ;
- File.Read( (Standard_Address&) image->rowstart,tablesize, bblcount);
- if ( File.Failed() || ( bblcount != tablesize ) ) {
- // ERROR
- i_errhdlr("iopen: error on read of rowstart\n");
- return( Standard_False ) ;
- }
-
- if(image->dorev)
- cvtlongs((int *)image->rowstart,tablesize);
- File.Read( (Standard_Address&) image->rowsize,tablesize, bblcount);
- if ( File.Failed() || ( bblcount != tablesize ) ) {
- // ERROR
- i_errhdlr("iopen: error on read of rowsize\n");
- return( Standard_False ) ;
- }
-
- if(image->dorev)
- cvtlongs((int *)image->rowsize,tablesize);
- }
- }
- image->cnt = 0;
- image->ptr = 0;
- image->base = 0;
- if( (image->tmpbuf = ibufalloc(image)) == 0 ) {
- i_errhdlr("iopen: error on tmpbuf alloc\n");
- return Standard_False ;
- }
- image->x = image->y = image->z = 0;
- image->file = 0;
- image->offset = 512; /* set up for img_optseek */
-
- File.Seek( 512, OSD_FromBeginning ) ;
-
- return(Standard_True);
-}
-
-
-static unsigned short *ibufalloc(AlienImage_SGIRGBFileHeader *image)
-{
- return (unsigned short *)malloc(IBUFSIZE(image->xsize));
-}
-
-// Unused :
-#ifdef DEB
-static unsigned int reverse(unsigned int lwrd)
-{
- return ((lwrd>>24) |
- (lwrd>>8 & 0xff00) |
- (lwrd<<8 & 0xff0000) |
- (lwrd<<24) );
-}
-#endif
-
-static void cvtshorts( unsigned short buffer[], int n)
-{
- register short i;
- register int nshorts = n>>1;
- register unsigned short swrd;
-
- for(i=0; i<nshorts; i++) {
- swrd = *buffer;
- *buffer++ = (swrd>>8) | (swrd<<8);
- }
-}
-
-static void cvtlongs( int buffer[], int n )
-{
- register short i;
- register int nlongs = n>>2;
- register unsigned int lwrd;
-
- for(i=0; i<nlongs; i++) {
- lwrd = buffer[i];
- buffer[i] = ((lwrd>>24) |
- (lwrd>>8 & 0xff00) |
- (lwrd<<8 & 0xff0000) |
- (lwrd<<24) );
- }
-}
-
-static void cvtimage(int buffer[] )
-{
- cvtshorts((unsigned short *)buffer,12);
- cvtlongs(buffer+3,12);
- cvtlongs(buffer+26,4);
-}
-
-/*
- * img_seek, img_write, img_read, img_optseek -
- *
- *
- */
-
-static int img_seek( OSD_File &File,
- AlienImage_SGIRGBFileHeader *image,
- unsigned int y, unsigned int z )
-{
- if(img_badrow(image,y,z)) {
- i_errhdlr("img_seek: row number out of range\n");
- return EOF;
- }
- image->x = 0;
- image->y = y;
- image->z = z;
- if(ISVERBATIM(image->type)) {
- switch(image->dim) {
- case 1:
- return img_optseek(File,image, 512);
- case 2:
- return img_optseek(File,image,
- 512+(y*image->xsize)*BPP(image->type));
- case 3:
- return img_optseek(File,image,
- 512+(y*image->xsize+z*image->xsize*image->ysize)*
- BPP(image->type));
- default:
- i_errhdlr("img_seek: weird dim\n");
- break;
- }
- } else if(ISRLE(image->type)) {
- switch(image->dim) {
- case 1:
- return img_optseek(File, image, image->rowstart[0]);
- case 2:
- return img_optseek(File, image, image->rowstart[y]);
- case 3:
- return img_optseek(File, image,
- image->rowstart[y+z*image->ysize]);
- default:
- i_errhdlr("img_seek: weird dim\n");
- break;
- }
- } else
- i_errhdlr("img_seek: weird image type\n");
- return -1;
-}
-
-static int img_badrow(AlienImage_SGIRGBFileHeader *image, int y, int z )
-{
- if(y>=(int)image->ysize || z>=(int)image->zsize)
- return 1;
-// else
- return 0;
-}
-
-static int img_write( OSD_File &File,
- AlienImage_SGIRGBFileHeader *image,char *buffer,
- int bblcount )
-{
- int retval;
-
- File.Write( (Standard_Address) buffer,bblcount ) ;
-
- if ( File.Failed() ) retval = 0 ;
- else retval = bblcount ;
-
- if(retval == bblcount)
- image->offset += bblcount;
- else
- image->offset = (unsigned int ) -1;
- return retval;
-}
-
-static int img_read( OSD_File &File,
- AlienImage_SGIRGBFileHeader *image, char *buffer,
- int bblcount )
-{
- int retval;
- File.Read( (Standard_Address&)buffer,bblcount, retval ) ;
- if(retval == bblcount && !File.Failed() )
- image->offset += bblcount;
- else
- image->offset = (unsigned int ) -1;
- return retval;
-}
-
-static int img_optseek( OSD_File &File,
- AlienImage_SGIRGBFileHeader *image,
- unsigned int offset)
-{
-
- if(image->offset != offset) {
- image->offset = offset;
- File.Seek( offset, OSD_FromBeginning ) ;
-
- return( offset ) ;
- //return lseek(image->file,offset,0);
- }
- return offset;
-}
-
-/*
- * img_getrowsize, img_setrowsize, img_rle_compact, img_rle_expand -
- *
- *
- */
-
-static int img_getrowsize( AlienImage_SGIRGBFileHeader *image )
-{
- switch(image->dim) {
- case 1:
- return image->rowsize[0];
- case 2:
- return image->rowsize[image->y];
- case 3:
- return image->rowsize[image->y+image->z*image->ysize];
- }
- return -1;
-}
-
-static void img_setrowsize( AlienImage_SGIRGBFileHeader *image,
- int cnt, int y, int z )
-{
- int *sizeptr=NULL;
-
- if(img_badrow(image,y,z))
- return;
- switch(image->dim) {
- case 1:
- sizeptr = &image->rowsize[0];
- image->rowstart[0] = image->rleend;
- break;
- case 2:
- sizeptr = &image->rowsize[y];
- image->rowstart[y] = image->rleend;
- break;
- case 3:
- sizeptr = &image->rowsize[y+z*image->ysize];
- image->rowstart[y+z*image->ysize] = image->rleend;
- }
- if(*sizeptr != -1)
- image->wastebytes += *sizeptr;
- *sizeptr = cnt;
- image->rleend += cnt;
-}
-
-#define docompact \
- while(iptr<ibufend) { \
- sptr = iptr; \
- iptr += 2; \
- while((iptr<ibufend)&&((iptr[-2]!=iptr[-1])||(iptr[-1]!=iptr[0])))\
- iptr++; \
- iptr -= 2; \
- bblcount = iptr-sptr; \
- while(bblcount) { \
- todo = bblcount>126 ? 126:bblcount; \
- bblcount -= todo; \
- *optr++ = 0x80|todo; \
- while(todo--) \
- *optr++ = (unsigned char)*sptr++; \
- } \
- sptr = iptr; \
- cc = *iptr++; \
- while( (iptr<ibufend) && (*iptr == cc) ) \
- iptr++; \
- bblcount = iptr-sptr; \
- while(bblcount) { \
- todo = bblcount>126 ? 126:bblcount; \
- bblcount -= todo; \
- *optr++ = (unsigned char)todo; \
- *optr++ = (unsigned char)cc; \
- } \
- } \
- *optr++ = 0;
-
-static int img_rle_compact( unsigned short *expbuf,
- int ibpp,
- unsigned short *rlebuf,
- int obpp, int cnt)
-{
- if(ibpp == 1 && obpp == 1) {
- register unsigned char *iptr = (unsigned char *)expbuf;
- register unsigned char *ibufend = iptr+cnt;
- register unsigned char *sptr;
- register unsigned char *optr = (unsigned char *)rlebuf;
- register short todo, cc;
- register int bblcount;
-
- docompact;
- return (int)(optr - (unsigned char *)rlebuf);
- } else if(ibpp == 1 && obpp == 2) {
- register unsigned char *iptr = (unsigned char *)expbuf;
- register unsigned char *ibufend = iptr+cnt;
- register unsigned char *sptr;
- register unsigned short *optr = rlebuf;
- register short todo, cc;
- register int bblcount;
-
- docompact;
- return optr - rlebuf;
- } else if(ibpp == 2 && obpp == 1) {
- register unsigned short *iptr = expbuf;
- register unsigned short *ibufend = iptr+cnt;
- register unsigned short *sptr;
- register unsigned char *optr = (unsigned char *)rlebuf;
- register short todo, cc;
- register int bblcount;
-
-
- docompact;
- return (int)(optr - (unsigned char *)rlebuf);
- } else if(ibpp == 2 && obpp == 2) {
- register unsigned short *iptr = expbuf;
- register unsigned short *ibufend = iptr+cnt;
- register unsigned short *sptr;
- register unsigned short *optr = rlebuf;
- register short todo, cc;
- register int bblcount;
-
- docompact;
- return optr - rlebuf;
- } else {
- i_errhdlr("rle_compact: bad bpp\n");
- return 0;
- }
-}
-
-#define doexpand \
- while(1) { \
- pixel = *iptr++; \
- if ( !(bblcount = (pixel & 0x7f)) ) \
- return; \
- if(pixel & 0x80) { \
- while(bblcount--) \
- *optr++ = (unsigned char)*iptr++; \
- } else { \
- pixel = *iptr++; \
- while(bblcount--) \
- *optr++ = (unsigned char)pixel; \
- } \
- }
-
-static void img_rle_expand( unsigned short *rlebuf,
- int ibpp,
- unsigned short *expbuf,
- int obpp )
-
-{
- if(ibpp == 1 && obpp == 1) {
- register unsigned char *iptr = (unsigned char *)rlebuf;
- register unsigned char *optr = (unsigned char *)expbuf;
- register unsigned short pixel,bblcount;
-
- doexpand;
- } else if(ibpp == 1 && obpp == 2) {
- register unsigned char *iptr = (unsigned char *)rlebuf;
- register unsigned short *optr = expbuf;
- register unsigned short pixel,bblcount;
-
- doexpand;
- } else if(ibpp == 2 && obpp == 1) {
- register unsigned short *iptr = rlebuf;
- register unsigned char *optr = (unsigned char *)expbuf;
- register unsigned short pixel,bblcount;
-
- doexpand;
- } else if(ibpp == 2 && obpp == 2) {
- register unsigned short *iptr = rlebuf;
- register unsigned short *optr = expbuf;
- register unsigned short pixel,bblcount;
-
- doexpand;
- } else
- i_errhdlr("rle_expand: bad bpp\n");
-}
-/*
- * putrow, getrow -
- *
- */
-
-static int putrow( OSD_File& File,
- AlienImage_SGIRGBFileHeader *image,
- unsigned short *buffer,
- unsigned int y, unsigned int z )
-{
- register unsigned short *sptr;
- register unsigned char *cptr;
- register unsigned int x;
- register unsigned int min, max;
- register int cnt;
-
- if( !(image->flags & (_IORW|_IOWRT)) )
- return -1;
- if(image->dim<3)
- z = 0;
- if(image->dim<2)
- y = 0;
- if(ISVERBATIM(image->type)) {
- switch(BPP(image->type)) {
- case 1:
- min = image->min;
- max = image->max;
- cptr = (unsigned char *)image->tmpbuf;
- sptr = buffer;
- for(x=image->xsize; x--;) {
- *cptr = (unsigned char )*sptr++;
- if (*cptr > max) max = *cptr;
- if (*cptr < min) min = *cptr;
- cptr++;
- }
- image->min = min;
- image->max = max;
- img_seek( File, image,y,z);
- cnt = image->xsize;
- if (img_write( File, image,(char *)image->tmpbuf,cnt) != cnt)
- return -1;
- else
- return cnt;
- /* NOTREACHED */
-
- case 2:
- min = image->min;
- max = image->max;
- sptr = buffer;
- for(x=image->xsize; x--;) {
- if (*sptr > max) max = *sptr;
- if (*sptr < min) min = *sptr;
- sptr++;
- }
- image->min = min;
- image->max = max;
- img_seek( File, image,y,z);
- cnt = image->xsize<<1;
- if(image->dorev)
- cvtshorts(buffer,cnt);
- if (img_write( File, image,(char *)buffer,cnt) != cnt) {
- if(image->dorev)
- cvtshorts(buffer,cnt);
- return -1;
- } else {
- if(image->dorev)
- cvtshorts(buffer,cnt);
- return image->xsize;
- }
- /* NOTREACHED */
-
- default:
- i_errhdlr("putrow: weird bpp\n");
- }
- } else if(ISRLE(image->type)) {
- switch(BPP(image->type)) {
- case 1:
- min = image->min;
- max = image->max;
- sptr = buffer;
- for(x=image->xsize; x--;) {
- if (*sptr > max) max = *sptr;
- if (*sptr < min) min = *sptr;
- sptr++;
- }
- image->min = min;
- image->max = max;
- cnt = img_rle_compact(buffer,2,image->tmpbuf,1,image->xsize);
- img_setrowsize(image,cnt,y,z);
- img_seek( File, image,y,z);
- if (img_write( File, image,(char *)image->tmpbuf,cnt) != cnt)
- return -1;
- else
- return image->xsize;
- /* NOTREACHED */
-
- case 2:
- min = image->min;
- max = image->max;
- sptr = buffer;
- for(x=image->xsize; x--;) {
- if (*sptr > max) max = *sptr;
- if (*sptr < min) min = *sptr;
- sptr++;
- }
- image->min = min;
- image->max = max;
- cnt = img_rle_compact(buffer,2,image->tmpbuf,2,image->xsize);
- cnt <<= 1;
- img_setrowsize(image,cnt,y,z);
- img_seek( File, image,y,z);
- if(image->dorev)
- cvtshorts(image->tmpbuf,cnt);
- if (img_write( File, image,(char *)image->tmpbuf,cnt) != cnt) {
- if(image->dorev)
- cvtshorts(image->tmpbuf,cnt);
- return -1;
- } else {
- if(image->dorev)
- cvtshorts(image->tmpbuf,cnt);
- return image->xsize;
- }
- /* NOTREACHED */
-
- default:
- i_errhdlr("putrow: weird bpp\n");
- }
- } else
- i_errhdlr("putrow: weird image type\n");
-return -1;
-}
-
-static int getrow( OSD_File& File,
- AlienImage_SGIRGBFileHeader *image,
- unsigned short *buffer,
- unsigned int y, unsigned int z)
-{
- register short i;
- register unsigned char *cptr;
- register unsigned short *sptr;
- register short cnt;
-
- if( !(image->flags & (_IORW|_IOREAD)) )
- return -1;
- if(image->dim<3)
- z = 0;
- if(image->dim<2)
- y = 0;
- img_seek( File, image, y, z);
- if(ISVERBATIM(image->type)) {
- switch(BPP(image->type)) {
- case 1:
- if (img_read( File, image,(char *)image->tmpbuf,image->xsize)
- != image->xsize)
- return -1;
- else {
- cptr = (unsigned char *)image->tmpbuf;
- sptr = buffer;
- for(i=image->xsize; i--;)
- *sptr++ = *cptr++;
- }
- return image->xsize;
- /* NOTREACHED */
-
- case 2:
- cnt = image->xsize<<1;
- if (img_read( File, image,(char *)buffer,cnt) != cnt)
- return -1;
- else {
- if(image->dorev)
- cvtshorts(buffer,cnt);
- return image->xsize;
- }
- /* NOTREACHED */
-
- default:
- i_errhdlr("getrow: weird bpp\n");
- break;
- }
- } else if(ISRLE(image->type)) {
- switch(BPP(image->type)) {
- case 1:
- if( (cnt = img_getrowsize(image)) == -1 )
- return -1;
- if( img_read( File, image,(char *)image->tmpbuf,cnt) != cnt )
- return -1;
- else {
- img_rle_expand(image->tmpbuf,1,buffer,2);
- return image->xsize;
- }
- /* NOTREACHED */
-
- case 2:
- if( (cnt = img_getrowsize(image)) == -1 )
- return -1;
- if( cnt != img_read( File, image,(char *)image->tmpbuf,cnt) )
- return -1;
- else {
- if(image->dorev)
- cvtshorts(image->tmpbuf,cnt);
- img_rle_expand(image->tmpbuf,2,buffer,2);
- return image->xsize;
- }
- /* NOTREACHED */
-
- default:
- i_errhdlr("getrow: weird bpp\n");
- break;
- }
- } else
- i_errhdlr("getrow: weird image type\n");
-return -1;
-}
-
-#ifdef PIX
-/*
- * ifilbuf -
- *
- */
-static int ifilbuf( AlienImage_SGIRGBFileHeader *);
-
-static int ifilbuf( AlienImage_SGIRGBFileHeader *image )
-{
- int size;
-
- if ((image->flags&_IOREAD) == 0)
- return(EOF);
- if (image->base==NULL) {
- size = IBUFSIZE(image->xsize);
- if ((image->base = ibufalloc(image)) == NULL) {
- i_errhdlr("can't alloc image buffer\n");
- return EOF;
- }
- }
- image->cnt = getrow( File, image,image->base,image->y,image->z);
- image->ptr = image->base;
- if (--image->cnt < 0) {
- if (image->cnt == -1) {
- image->flags |= _IOEOF;
- if (image->flags & _IORW)
- image->flags &= ~_IOREAD;
- } else
- image->flags |= _IOERR;
- image->cnt = 0;
- return -1;
- }
- if(++image->y >= (short)image->ysize) {
- image->y = 0;
- if(++image->z >= (short)image->zsize) {
- image->z = image->zsize-1;
- image->flags |= _IOEOF;
- return -1;
- }
- }
- return *image->ptr++ & 0xffff;
-}
-/*
- * iflsbuf -
- *
- *
- */
-static int iflsbuf( OSD_File&,
- AlienImage_SGIRGBFileHeader *,unsigned int );
-
-static int iflsbuf( OSD_File& File,
- AlienImage_SGIRGBFileHeader *image,unsigned int c )
-{
- register unsigned short *base;
- register n, rn;
- int size;
-
- if ((image->flags&_IOWRT)==0)
- return(EOF);
- if ((base=image->base)==NULL) {
- size = IBUFSIZE(image->xsize);
- if ((image->base=base=ibufalloc(image)) == NULL) {
- i_errhdlr("flsbuf: error on buf alloc\n");
- return EOF;
- }
- rn = n = 0;
- } else if ((rn = n = image->ptr - base) > 0) {
- n = putrow( File, image,base,image->y,image->z);
- if(++image->y >= ( short )image->ysize) {
- image->y = 0;
- if(++image->z >= ( short )image->zsize) {
- image->z = image->zsize-1;
- image->flags |= _IOEOF;
- return -1;
- }
- }
- }
- image->cnt = image->xsize-1;
- *base++ = c;
- image->ptr = base;
- if (rn != n) {
- image->flags |= _IOERR;
- return(EOF);
- }
- return(c);
-}
-/*
- * getpix and putpix -
- *
- *
- */
-
-#undef getpix
-#undef putpix
-
-int getpix( AlienImage_SGIRGBFileHeader *image )
-{
- if(--(image)->cnt>=0)
- return *(image)->ptr++;
- else
- return ifilbuf(image);
-}
-
-int putpix( AlienImage_SGIRGBFileHeader *image,
- unsigned int pix )
-{
- if(--(image)->cnt>=0)
- return *(image)->ptr++ = pix;
- else
- return iflsbuf( File, (image,pix);
-}
-#endif
-//------------------------------------------------------------------------------
-// Public Method
-//------------------------------------------------------------------------------
-
-AlienImage_SGIRGBAlienData::AlienImage_SGIRGBAlienData()
-
-{
- myRedData = myGreenData = myBlueData = NULL ;
-}
-
-void AlienImage_SGIRGBAlienData::SetName( const TCollection_AsciiString& aName)
-
-{ myName = aName + TCollection_AsciiString( "\0" ) ;
-}
-
-const TCollection_AsciiString& AlienImage_SGIRGBAlienData::Name() const
-
-{ return ( myName ) ; }
-
-void AlienImage_SGIRGBAlienData::Clear()
-
-{ myName.Clear() ;
-
- if ( myRedData ) {
- //Free all allocated memory
- Standard::Free( myRedData) ;
- myRedData = NULL ;
- }
- if ( myGreenData ) {
- //Free all allocated memory
- Standard::Free( myGreenData) ;
- myRedData = NULL ;
- }
- if ( myBlueData ) {
- //Free all allocated memory
- Standard::Free( myBlueData) ;
- myRedData = NULL ;
- }
-
- myHeader.xsize = myHeader.ysize = myHeader.zsize = 0 ;
-}
-
-
-Standard_Boolean AlienImage_SGIRGBAlienData::Read( OSD_File& file )
-
-{ Standard_Boolean Success = iopen( file,
- &myHeader,
- 'r' ,
- 0 ,
- 0 ,
- 0 ,
- 0 ,
- 0 );
-
- unsigned short *rbuf, *gbuf, *bbuf ;
- unsigned short y ;
-
- if ( Success ) {
-#ifdef TRACE
- if ( Verbose ) {
- /* print a little info about the image */
- printf("Image x and y size in pixels: %d %d\n",
- myHeader.xsize,myHeader.ysize);
- printf("Image zsize in channels: %d\n",myHeader.zsize);
- printf("Image pixel min and max: %d %d\n",myHeader.min,myHeader.max);
- }
-#endif
-
- myName = TCollection_AsciiString( myHeader.name ) ;
-
- /* allocate buffers for image data */
- if ( DataSize() ) {
- myRedData = Standard::Allocate( DataSize() ) ;
- }
-
- if(myHeader.zsize >= 3 && DataSize()) {/*if the image has alpha zsize is 4*/
- myGreenData = Standard::Allocate( DataSize() ) ;
- myBlueData = Standard::Allocate( DataSize() ) ;
- }
-
- rbuf = ( unsigned short * ) myRedData ;
- gbuf = ( unsigned short * ) myGreenData ;
- bbuf = ( unsigned short * ) myBlueData ;
-
- /* check to see if the image is B/W or RGB */
- if(myHeader.zsize == 1) {
-#ifdef TRACE
- if ( Verbose ) printf("This is a black and write image\n");
-#endif
- for(y=0; y<myHeader.ysize; y++) {
- getrow(file, &myHeader,rbuf,y,0); rbuf += myHeader.xsize ;
- }
- } else if(myHeader.zsize >= 3) { /* if the image has alpha zsize is 4 */
-#ifdef TRACE
- if ( Verbose ) printf("This is a rgb image\n");
-#endif
- for(y=0; y<myHeader.ysize; y++) {
- getrow(file, &myHeader,rbuf,myHeader.ysize-1-y,0);
- rbuf += myHeader.xsize ;
- getrow(file, &myHeader,gbuf,myHeader.ysize-1-y,1);
- gbuf += myHeader.xsize ;
- getrow(file, &myHeader,bbuf,myHeader.ysize-1-y,2);
- bbuf += myHeader.xsize ;
- }
- }
- }
-
- return Success ;
-
-
-}
-
-Standard_Boolean AlienImage_SGIRGBAlienData::Write( OSD_File& file ) const
-
-{ unsigned short *rbuf, *gbuf, *bbuf ;
- unsigned short y;
- unsigned int xsize,ysize,zsize ;
-
- AlienImage_SGIRGBFileHeader WritedHeader ;
-
- xsize = myHeader.xsize ;
- ysize = myHeader.ysize ;
- zsize = myHeader.zsize ;
-
- Standard_Boolean Success = iopen( file,
- &WritedHeader,
- 'w' ,
- RLE(1),
- 3,
- xsize,
- ysize,
- zsize);
-
- if ( Success ) {
-#ifdef TRACE
- if ( Verbose ) {
- /* print a little info about the image */
- printf("Image x and y size in pixels: %d %d\n",
- WritedHeader.xsize,WritedHeader.ysize);
- printf("Image zsize in channels: %d\n",WritedHeader.zsize);
- printf("Image pixel min and max: %d %d\n",
- WritedHeader.min,WritedHeader.max);
- }
-#endif
-
- isetname( &WritedHeader, (Standard_PCharacter)myName.ToCString() ) ;
-
- rbuf = ( unsigned short * ) myRedData ;
- gbuf = ( unsigned short * ) myGreenData ;
- bbuf = ( unsigned short * ) myBlueData ;
-
- /* check to see if the image is B/W or RGB */
- if(WritedHeader.zsize == 1) {
- for(y=0; y<WritedHeader.ysize; y++) {
- putrow(file, &WritedHeader,rbuf,WritedHeader.ysize-1-y,0);
- rbuf += WritedHeader.xsize ;
- }
- } else if(WritedHeader.zsize >= 3) { /* if the image has alpha zsize is 4 */
- for(y=0; y<WritedHeader.ysize; y++) {
- putrow(file, &WritedHeader,rbuf,WritedHeader.ysize-1-y,0);
- rbuf += WritedHeader.xsize ;
- putrow(file, &WritedHeader,gbuf,WritedHeader.ysize-1-y,1);
- gbuf += WritedHeader.xsize ;
- putrow(file, &WritedHeader,bbuf,WritedHeader.ysize-1-y,2);
- bbuf += WritedHeader.xsize ;
- }
- }
- }
-
- iclose( file, &WritedHeader ) ;
-
- return Success ;
-
-}
-
-Handle_Image_Image AlienImage_SGIRGBAlienData::ToImage() const
-
-{ if ( myHeader.zsize == 1 ) {
-#ifdef TRACE
- if ( Verbose ) printf("This is a gray scale image\n");
-#endif
- return( ToPseudoColorImage() ) ;
- }
- else if ( myHeader.zsize >= 3 ) {
-#ifdef TRACE
- if ( Verbose ) printf("This is a rgb image\n");
-#endif
- return( ToColorImage() ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a SGIRGBAlienData to a unknown Image_Image type");
-
- return( NULL ) ;
- }
-}
-
-
-void AlienImage_SGIRGBAlienData::FromImage(const Handle(Image_Image)& anImage )
-
-{ unsigned short x,y ;
- unsigned short *rbuf, *gbuf, *bbuf ;
- Standard_Real r,g,b ;
- Standard_Integer LowX = anImage->LowerX() ;
- Standard_Integer LowY = anImage->LowerY() ;
-
- myHeader.xsize = anImage->Width();
- myHeader.ysize = anImage->Height();
- myHeader.zsize = 3;
-
- /* allocate buffers for image data */
- if ( DataSize() ) {
- myRedData = Standard::Allocate( DataSize() ) ;
- myGreenData = Standard::Allocate( DataSize() ) ;
- myBlueData = Standard::Allocate( DataSize() ) ;
- }
-
- rbuf = ( unsigned short * ) myRedData ;
- gbuf = ( unsigned short * ) myGreenData ;
- bbuf = ( unsigned short * ) myBlueData ;
-
- for(y=0; y<myHeader.ysize; y++) {
- for(x=0; x<myHeader.xsize; x++, rbuf++, gbuf++, bbuf++) {
- (anImage->PixelColor( LowX+x,LowY+y )).Values(r,g,b,Quantity_TOC_RGB);
- *rbuf = (unsigned short) (r*255.+0.5) ;
- *gbuf = (unsigned short) (g*255.+0.5) ;
- *bbuf = (unsigned short) (b*255.+0.5) ;
- }
- }
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
-
-class SGIRGBAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
- ---Purpose: Defines an SGI .rgb Alien image, i.e. an image using
- -- the image format for Silicon Graphics workstations.
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- SGIRGBAlienData from AlienImage
-
-is
- Create returns mutable SGIRGBAlienImage from AlienImage;
- ---Purpose: Constructs an empty SGI .rgb Alien image.
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by SGIRGBAlienImage
-
- SetName( me : in out mutable;
- aName : in AsciiString from TCollection) ;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection ;
- ---C++: return const &
- ---Purpose: Reads the Image name .
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : Converts a SGIRGBAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : Converts a Image object to a SGIRGBAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Purpose: Reads content of a SGIRGBAlienImage object from a file
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Purpose: Writes content of a SGIRGBAlienImage object to a file
-
-fields
- myData : SGIRGBAlienData from AlienImage;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_SGIRGBAlienImage.ixx>
-
-AlienImage_SGIRGBAlienImage::AlienImage_SGIRGBAlienImage()
-
-{ // il faut faire un new si mydata est du type HANDLE
- myData = new AlienImage_SGIRGBAlienData() ;
-}
-
-void AlienImage_SGIRGBAlienImage::SetName( const TCollection_AsciiString& aName)
-
-{ myData->SetName( aName ) ; }
-
-const TCollection_AsciiString& AlienImage_SGIRGBAlienImage::Name() const
-{ return( myData->Name() ) ; }
-
-void AlienImage_SGIRGBAlienImage::Clear()
-
-{ myData->Clear() ; }
-
-Standard_Boolean AlienImage_SGIRGBAlienImage::Write( OSD_File& file ) const
-
-{ return( myData->Write( file ) ) ; }
-
-Standard_Boolean AlienImage_SGIRGBAlienImage::Read( OSD_File& file )
-
-{ return( myData->Read( file ) ) ; }
-
-Handle_Image_Image AlienImage_SGIRGBAlienImage::ToImage() const
-
-{ return( myData->ToImage() ) ; }
-
-void AlienImage_SGIRGBAlienImage::FromImage( const Handle_Image_Image& anImage )
-
-{ myData->FromImage( anImage ) ; }
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_SGIRGBFileHeader.hxx>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_SGIRGBFileHeader)
-{
- static Handle(Standard_Type) _atype =
- new Standard_Type ("AlienImage_SGIRGBFileHeader", sizeof (AlienImage_SGIRGBFileHeader));
- return _atype;
-}
-
-Standard_Boolean operator == ( const AlienImage_SGIRGBFileHeader& AnObject,
- const AlienImage_SGIRGBFileHeader& AnotherObject )
-
-{ Standard_Boolean _result = Standard_True;
-
- return _result;
-}
-
-//============================================================================
-//==== ShallowDump : Writes a CString value.
-//============================================================================
-void ShallowDump (const AlienImage_SGIRGBFileHeader& AnObject, Standard_OStream& s)
-
-{
- s << "AlienImage_SGIRGBFileHeader\n" ;
-}
-
-ostream& operator << ( ostream& s, const AlienImage_SGIRGBFileHeader& c )
-
-{
- return( s << "AlienImage_SGIRGBFileHeader " );
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_SGIRGBFileHeader.hxx
-//==== Role : The header file of primitve type "SGIRGBFileHeader"
-//==== Implementation: This is a primitive type implemented with typedef
-//==== typedef SGIRGBSGIRGBFileHeader AlienImage_SGIRGBFileHeader;
-//============================================================================
-
-#ifndef _AlienImage_SGIRGBFileHeader_HeaderFile
-#define _AlienImage_SGIRGBFileHeader_HeaderFile
-
-//==== Definition de Type ====================================================
-#include <Standard_Type.hxx>
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_SGIRGBFileHeader);
-//============================================================================
-
-#define IMAGIC 0732
-
-/* colormap of images */
-#define CM_NORMAL 0 /* file contains rows of values which
- * are either RGB values (zsize == 3)
- * or greyramp values (zsize == 1) */
-#define CM_DITHERED 1
-#define CM_SCREEN 2 /* file contains data which is a screen
- * image; getrow returns buffer which
- * can be displayed directly with
- * writepixels */
-#define CM_COLORMAP 3 /* a colormap file */
-
-#define TYPEMASK 0xff00
-#define BPPMASK 0x00ff
-#define ITYPE_VERBATIM 0x0000
-#define ITYPE_RLE 0x0100
-#define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE)
-#define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM)
-#define BPP(type) ((type) & BPPMASK)
-#define RLE(bpp) (ITYPE_RLE | (bpp))
-#define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp))
-#define IBUFSIZE(pixels) ((pixels+(pixels>>6))<<2)
-#define RLE_NOP 0x00
-
-#define ierror(p) (((p)->flags&_IOERR)!=0)
-#define ifileno(p) ((p)->file)
-#define getpix(p) (--(p)->cnt>=0 ? *(p)->ptr++ : ifilbuf(p))
-#define putpix(p,x) (--(p)->cnt>=0 \
- ? ((int)(*(p)->ptr++=(unsigned)(x))) \
- : iflsbuf(p,(unsigned)(x)))
-
-typedef struct {
- unsigned short imagic; /* stuff saved on disk . . */
- unsigned short type;
- unsigned short dim;
- unsigned short xsize;
- unsigned short ysize;
- unsigned short zsize;
- unsigned int min;
- unsigned int max;
- unsigned int wastebytes;
- char name[80];
- unsigned int colormap;
-
- int file; /* stuff used in core only */
- unsigned short flags;
- short dorev;
- short x;
- short y;
- short z;
- short cnt;
- unsigned short *ptr;
- unsigned short *base;
- unsigned short *tmpbuf;
- unsigned int offset;
- unsigned int rleend; /* for rle images */
- unsigned int *rowstart; /* for rle images */
- int *rowsize; /* for rle images */
-} AlienImage_SGIRGBFileHeader;
-
-AlienImage_SGIRGBFileHeader *iopen();
-AlienImage_SGIRGBFileHeader *icreate();
-
-ostream& operator << ( ostream& s, const AlienImage_SGIRGBFileHeader& h );
-
-Standard_Boolean operator==(const AlienImage_SGIRGBFileHeader& AnObject,
- const AlienImage_SGIRGBFileHeader& AnotherObject) ;
-void ShallowDump (const AlienImage_SGIRGBFileHeader& AnObject,Standard_OStream& S) ;
-#endif
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_SUNRFFileHeader.hxx>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_SUNRFFileHeader)
-{
- static Handle(Standard_Type) _atype =
- new Standard_Type ("AlienImage_SUNRFFileHeader", sizeof (AlienImage_SUNRFFileHeader));
- return _atype;
-}
-
-Standard_Boolean operator == ( const AlienImage_SUNRFFileHeader& AnObject,
- const AlienImage_SUNRFFileHeader& AnotherObject )
-
-{ Standard_Boolean _result = Standard_True;
-
- return _result;
-}
-
-//============================================================================
-//==== ShallowDump : Writes a CString value.
-//============================================================================
-void ShallowDump (const AlienImage_SUNRFFileHeader& AnObject, Standard_OStream& s)
-
-{
- s << AnObject ;
-}
-
-ostream& operator << ( ostream& s, const AlienImage_SUNRFFileHeader& c )
-
-{
- return( s << "AlienImage_SUNRFFileHeader :"
- << "\n\tmagic :" << c.ras_magic
- << "\n\twidth :" << c.ras_width
- << "\n\theight :" << c.ras_height
- << "\n\tdepth :" << c.ras_depth
- << "\n\tlength :" << c.ras_length
- << "\n\tmaptype :" << c.ras_maptype
- << "\n\tmaplength:" << c.ras_maplength << endl << flush );
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_SUNRFFileHeader.hxx
-//==== Role : The header file of primitve type "SUNRFFileHeader"
-//==== Implementation: This is a primitive type implemented with typedef
-//==== typedef SUNRFSUNRFFileHeader AlienImage_SUNRFFileHeader;
-//============================================================================
-
-#ifndef _AlienImage_SUNRFFileHeader_HeaderFile
-#define _AlienImage_SUNRFFileHeader_HeaderFile
-
-//==== Definition de Type ====================================================
-#include <Standard_Type.hxx>
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_SUNRFFileHeader);
-//============================================================================
-
-#define RAS_MAGIC 0x59a66a95
-
- /* Sun supported ras_type's */
-#define RT_OLD 0 /* Raw pixrect image in 68000 byte order */
-#define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */
-#define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */
-#define RT_FORMAT_RGB 3 /* XRGB or RGB instead of XBGR or BGR */
-#define RT_FORMAT_TIFF 4 /* tiff <-> standard rasterfile */
-#define RT_FORMAT_IFF 5 /* iff (TAAC format) <-> standard rasterfile */
-#define RT_EXPERIMENTAL 0xffff /* Reserved for testing */
-
- /* Sun registered ras_maptype's */
-#define RMT_RAW 2
- /* Sun supported ras_maptype's */
-#define RMT_NONE 0 /* ras_maplength is expected to be 0 */
-#define RMT_EQUAL_RGB 1 /* red[ras_maplength/3],green[],blue[] */
-
-/*
- * NOTES:
- * Each line of the image is rounded out to a multiple of 16 bits.
- * This corresponds to the rounding convention used by the memory pixrect
- * package (/usr/include/pixrect/memvar.h) of the SunWindows system.
- * The ras_encoding field (always set to 0 by Sun's supported software)
- * was renamed to ras_length in release 2.0. As a result, rasterfiles
- * of type 0 generated by the old software claim to have 0 length; for
- * compatibility, code reading rasterfiles must be prepared to compute the
- * true length from the width, height, and depth fields.
- */
-
-
-typedef struct {
- int ras_magic; /* magic number */
- int ras_width; /* width (pixels) of image */
- int ras_height; /* height (pixels) of image */
- int ras_depth; /* depth (1, 8, or 24 bits) of pixel */
- int ras_length; /* length (bytes) of image */
- int ras_type; /* type of file; see RT_* below */
- int ras_maptype; /* type of colormap; see RMT_* below */
- int ras_maplength; /* length (bytes) of following map */
- /* color map follows for ras_maplength bytes, followed by image */
-} AlienImage_SUNRFFileHeader;
-
-ostream& operator << ( ostream& s, const AlienImage_SUNRFFileHeader& h );
-
-Standard_Boolean operator==(const AlienImage_SUNRFFileHeader& Obj1,
- const AlienImage_SUNRFFileHeader& Obj2) ;
-void ShallowDump (const AlienImage_SUNRFFileHeader& AnObject,Standard_OStream& S) ;
-
-#endif
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class SunRFAlienData from AlienImage inherits AlienImageData from AlienImage
-
- ---Version: 0.0
-
- ---Level: Public
- ---Purpose: This class defines a SUN Raster File .rs Alien image.
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- SUNRFFileHeader from AlienImage,
- SUNRFFormat from AlienImage
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable SunRFAlienData from AlienImage ;
-
- Clear( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by SunRFAlienData and
- -- reset Object fields.
- ---C++: alias ~
-
- FreeData( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by SunRFAlienData
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a SunRFAlienData object from a file .
- -- Returns True if file is a Sun Raster file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a SunRFAlienData object to a file .
-
- SetFormat( me : in out mutable ;
- aFormat : SUNRFFormat from AlienImage);
- ---Level: Public
- ---Purpose: Set SUN Raster File Format for Write method.
-
- Format( me : in immutable )
- returns SUNRFFormat from AlienImage ;
- ---Level: Public
- ---Purpose: Get SUN Raster File Format .
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a SunRFAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a SunRFAlienData object.
-
- --
- -- Private Method
- --
-
- ToPseudoColorImage( me : in immutable)
- returns PseudoColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a AlienImage object to a Image object.
-
- ToColorImage( me : in immutable)
- returns ColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a AlienImage object to a Image object.
-
- FromPseudoColorImage( me : in out mutable ;
- anImage : in PseudoColorImage from Image );
- ---Level: Internal
- ---Purpose : convert a Image object to a SunRFAlienData object.
-
- FromColorImage( me : in out mutable ;
- anImage : in ColorImage from Image );
- ---Level: Internal
- ---Purpose : convert a Image object to a SunRFAlienData object.
-
- ReadPixelRow( me : in out mutable ;
- afile : in out File from OSD ;
- aAddress : in Address from Standard ;
- TheRowSize : in Integer from Standard )
- returns Boolean from Standard;
- ---Level: Internal
- ---Purpose : Read a Image row from a file and store
- -- TheRowSize byte at aAddress
- -- returns True if Success.
-
- WritePixelRow( me : in immutable ;
- afile : in out File from OSD ;
- aAddress : in Address from Standard ;
- TheRowSize : in Integer from Standard )
- returns Boolean from Standard;
- ---Level: Internal
- ---Purpose : Write a Image row to a file from TheRowSize byte at
- -- aAddress
- -- returns True if Success.
-
-fields
- myHeader : SUNRFFileHeader from AlienImage is protected ;
- myDataSize : Integer from Standard ;
- myData : Address from Standard is protected;
- myRedData, myGreenData, myBlueData : Address from Standard is protected;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <Aspect_GenericColorMap.hxx>
-#include <Image_PseudoColorImage.hxx>
-
-#include <AlienImage_MemoryOperations.hxx>
-#include <AlienImage_SUNRFFormat.hxx>
-#include <Image_Convertor.hxx>
-#include <AlienImage_SunRFAlienData.ixx>
-#include <Aspect_ColorMapEntry.hxx>
-
-#include <Standard_Byte.hxx>
-#include <Standard.hxx>
-
-#ifdef TRACE
-static int Verbose = 1 ;
-#endif
-
-#define RUN_FLAG 0x80
-
-// Each line of the image is rounded out to a multiple of 16 bits
-#define ROWBYTES() (((myHeader.ras_width*myHeader.ras_depth + 7 )/8 + 1 ) & ~1 )
-
-
-
-AlienImage_SunRFAlienData::AlienImage_SunRFAlienData()
-
-{ Clear() ; }
-
-void AlienImage_SunRFAlienData::SetFormat(
- const AlienImage_SUNRFFormat aFormat )
-
-{ switch ( aFormat ) {
- case AlienImage_SUNRF_Old :
- myHeader.ras_type = RT_OLD ; break ;
- case AlienImage_SUNRF_Standard :
- myHeader.ras_type = RT_STANDARD ; break ;
- case AlienImage_SUNRF_ByteEncoded :
- myHeader.ras_type = RT_BYTE_ENCODED ; break ;
- case AlienImage_SUNRF_RGB :
- myHeader.ras_type = RT_FORMAT_RGB ; break ;
- default :
- cout << "SunRFAlienData : Unknown or Unsuported Format\n" ;
- break ;
- }
-}
-
-AlienImage_SUNRFFormat AlienImage_SunRFAlienData::Format() const
-
-{ AlienImage_SUNRFFormat ret = AlienImage_SUNRF_Unknown ;
-
- switch ( myHeader.ras_type ) {
- case RT_OLD :
- ret = AlienImage_SUNRF_Old ; break ;
- case RT_STANDARD :
- ret = AlienImage_SUNRF_Standard ; break ;
- case RT_BYTE_ENCODED :
- ret = AlienImage_SUNRF_ByteEncoded ; break ;
- case RT_FORMAT_RGB :
- ret = AlienImage_SUNRF_RGB ; break ;
- }
-
- return ret ;
-
-}
-
-void AlienImage_SunRFAlienData::FreeData()
-
-{
- if ( myData && myDataSize ) {
- //Free all allocated memory
- Standard::Free(myData) ;
- myData = NULL ;
- myDataSize = 0 ;
- }
-
- if ( myRedData && myHeader.ras_maplength ) {
- //Free all allocated memory
- Standard::Free( myRedData) ;
- myRedData = NULL ;
- }
-
- if ( myGreenData && myHeader.ras_maplength ) {
- //Free all allocated memory
- Standard::Free(myGreenData) ;
- myRedData = NULL ;
- }
-
- if ( myBlueData && myHeader.ras_maplength ) {
- //Free all allocated memory
- Standard::Free(myBlueData) ;
- myRedData = NULL ;
- }
-
-}
-
-void AlienImage_SunRFAlienData::Clear()
-
-{ FreeData() ;
-
-
- myHeader.ras_magic = RAS_MAGIC ;
- myHeader.ras_width = 0 ;
- myHeader.ras_height = 0 ;
- myHeader.ras_length = 0 ;
- myHeader.ras_type = RT_STANDARD ;
- myHeader.ras_maptype = RMT_NONE ;
- myHeader.ras_maplength = 0 ;
-
-}
-
-Standard_Boolean AlienImage_SunRFAlienData::Write( OSD_File& file ) const
-
-{ Standard_Integer size;
- AlienImage_SUNRFFileHeader TheHeader = myHeader ;
-
- // Write out TheHeader information
-
- if ( myData && myDataSize &&
- myHeader.ras_type == RT_FORMAT_RGB &&
- myHeader.ras_depth == 8 ) {
- // Convert PseudoColorImage to TrueColor
-
- Handle(Image_Image) aImage = ToImage() ;
-
- if ( aImage->IsKind( STANDARD_TYPE(Image_PseudoColorImage) ) ) {
- Image_Convertor Convertor;
-
- Handle(Image_ColorImage) aCImage =
- Convertor.Convert(Handle(Image_PseudoColorImage)::DownCast(aImage));
-
- Handle(AlienImage_SunRFAlienData) newThis =
- new AlienImage_SunRFAlienData() ;
-
- newThis->FromImage( aCImage ) ;
- newThis->SetFormat( AlienImage_SUNRF_RGB ) ;
- return newThis->Write( file ) ;
- }
- }
-
- size = ( Standard_Integer ) sizeof( TheHeader ) ;
-
- const Standard_Address pHeader = ( Standard_Address ) &TheHeader ;
-
- file.Write( pHeader, sizeof( TheHeader ) ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- // write out the color map buffer
-
- if ( TheHeader.ras_maplength ) {
- file.Write( myRedData, myHeader.ras_maplength/3 ) ;
- file.Write( myGreenData, myHeader.ras_maplength/3 ) ;
- file.Write( myBlueData, myHeader.ras_maplength/3 ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
-
- Standard_Integer rwbytes ;
-
- rwbytes = ROWBYTES() ;
-
- if ( myData && myDataSize ) {
- if ( myHeader.ras_type == RT_OLD ||
- myHeader.ras_type == RT_STANDARD ||
- myHeader.ras_type == RT_FORMAT_RGB ) {
- if ( myHeader.ras_type == RT_FORMAT_RGB ) {
- // Swap Sun Default BGR Format to RGB
- Standard_Byte *p = ( Standard_Byte * )myData ;
- Standard_Byte tmp, *pix ;
- Standard_Integer j, i ;
-
- if ( myHeader.ras_depth == 24 || myHeader.ras_depth == 32 ) {
- for ( i = 0 ;i < myHeader.ras_height ; i++, p += rwbytes ) {
- for ( j = 0, pix=p; j < myHeader.ras_width ; j++,pix+=3) {
- if ( myHeader.ras_depth == 32 ) pix++ ;
- tmp = *pix ;
- *pix = *(pix+2) ;
- *(pix+2) = tmp ;
- }
- }
- }
- else if ( myHeader.ras_depth == 8 ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
-
- file.Write( myData, myDataSize ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if ( myHeader.ras_type == RT_FORMAT_RGB &&
- ( myHeader.ras_depth == 24 || myHeader.ras_depth == 32 ) ) {
- // Swap RGB Format to Sun Default
- Standard_Byte *p = ( Standard_Byte * )myData ;
- Standard_Byte tmp, *pix ;
- Standard_Integer j, i ;
-
- for ( i = 0 ;i < myHeader.ras_height ; i++, p += rwbytes ) {
- for ( j = 0, pix=p; j < myHeader.ras_width ; j++,pix+=3) {
- if ( myHeader.ras_depth == 32 ) pix++ ;
- tmp = *pix ;
- *pix = *(pix+2) ;
- *(pix+2) = tmp ;
- }
- }
- }
- }
- else if ( myHeader.ras_type == RT_BYTE_ENCODED ) {
- Standard_Byte *p = ( Standard_Byte * )myData ;
- Standard_Integer i ;
-
- for ( i = 0 ; i < myHeader.ras_height ; i++, p += rwbytes ) {
- if ( WritePixelRow( file, ( Standard_Address) p, rwbytes ) ==
- Standard_False ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- }
- }
-
- }
-
- return( Standard_True ) ;
-
-}
-
-
-Standard_Boolean AlienImage_SunRFAlienData::Read( OSD_File& file )
-
-{ Standard_Integer bblcount, size ;
- Standard_Address pheader = ( Standard_Address ) &myHeader ;
-
- // Read in myHeader information
-
- file.Read( pheader, sizeof( myHeader ), bblcount ) ;
-
- if ( file.Failed() || ( bblcount != sizeof( myHeader ) ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- // check to see if the dump file is in the proper format */
- if (myHeader.ras_magic != RAS_MAGIC) {
- // ERROR "XWD file format version mismatch."
-
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
-#ifdef TRACE
- if ( Verbose ) cout << myHeader << endl << flush ;
-#endif
-
- // read in the color map buffer
-
- if ( myHeader.ras_maplength ) {
- size = myHeader.ras_maplength / 3 ;
-
- myRedData = Standard::Allocate( size ) ;
- myGreenData = Standard::Allocate( size ) ;
- myBlueData = Standard::Allocate( size ) ;
-
- file.Read( myRedData, size, bblcount ) ;
- file.Read( myGreenData, size, bblcount ) ;
- file.Read( myBlueData, size, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != size ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
-#ifdef TRACE
- if ( Verbose ) {
- Standard_Byte *r = ( Standard_Byte * )myRedData ;
- Standard_Byte *g = ( Standard_Byte * )myGreenData ;
- Standard_Byte *b = ( Standard_Byte * )myBlueData ;
-
- for (i = 0 ; i < myHeader.ncolors; i++,p++) {
- cout << "(" << r << "," << g << "," << b << ")\n" << flush ;
- }
-
- }
-#endif
- }
-
- if ( myHeader.ras_width && myHeader.ras_height && myHeader.ras_depth ) {
- Standard_Integer rwbytes ;
-
- rwbytes = ROWBYTES() ;
-
- myDataSize = rwbytes * myHeader.ras_height ;
-
- myData = Standard::Allocate( myDataSize ) ;
-
- if ( myHeader.ras_type == RT_OLD ||
- myHeader.ras_type == RT_STANDARD ||
- myHeader.ras_type == RT_FORMAT_RGB ) {
- file.Read( myData, myDataSize, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != myDataSize ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if ( myHeader.ras_type == RT_FORMAT_RGB &&
- ( myHeader.ras_depth == 24 || myHeader.ras_depth == 32 )) {
- // Swap RGB to Sun Default BGR Format
- Standard_Byte *p = ( Standard_Byte * )myData ;
- Standard_Byte tmp, *pix ;
- Standard_Integer i, j ;
-
- for ( i = 0 ; i < myHeader.ras_height ; i++, p += rwbytes ) {
- for ( j = 0, pix = p; j < myHeader.ras_width ; j++,pix+=3) {
- if ( myHeader.ras_depth == 32 ) pix++ ;
- tmp = *pix ;
- *pix = *(pix+2) ;
- *(pix+2) = tmp ;
- }
- }
- }
- }
- else if ( myHeader.ras_type == RT_BYTE_ENCODED ) {
- Standard_Byte *p = ( Standard_Byte * )myData ;
- Standard_Integer i ;
-
- for ( i = 0 ; i < myHeader.ras_height ; i++, p += rwbytes ) {
- if ( ReadPixelRow( file, ( Standard_Address) p, rwbytes ) ==
- Standard_False ) {
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
- }
-
- }
-
- return( Standard_True ) ;
-
-}
-
-Handle_Image_Image AlienImage_SunRFAlienData::ToImage() const
-
-{ if ( myHeader.ras_depth <= 8 &&
- myHeader.ras_maplength ) {
- return( ToPseudoColorImage() ) ;
- }
- else if ( myHeader.ras_depth == 24 || myHeader.ras_depth == 32 ) {
- return( ToColorImage() ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a SunRFAlienData to a unknown Image_Image type");
-
- return( NULL ) ;
- }
-}
-
-void AlienImage_SunRFAlienData::FromImage( const Handle_Image_Image& anImage )
-
-{ if ( anImage->Type() == Image_TOI_PseudoColorImage ) {
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage) ;
-
- FromPseudoColorImage( aPImage ) ;
- }
- else if ( anImage->Type() == Image_TOI_ColorImage ) {
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage) ;
-
- FromColorImage( aCImage ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a unknown Image_Image type to a SunRFAlienData");
- }
-}
-
-//------------------------------------------------------------------------------
-// Private Method
-//------------------------------------------------------------------------------
-
-Standard_Boolean AlienImage_SunRFAlienData::ReadPixelRow(
- OSD_File& file,
- const Standard_Address pdata,
- const Standard_Integer rwbytes)
-
-{ Standard_Byte *p = ( Standard_Byte * )pdata ;
- Standard_Byte byte, val ;
- Standard_Integer RLEcnt, PixelCount, i, bblcount ;
- Standard_Address pb = ( Standard_Address ) &byte ;
-
- PixelCount = 0 ;
-
- while ( PixelCount < myHeader.ras_width ) {
- file.Read( pb, 1, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != 1 ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if ( byte != RUN_FLAG ) {
- // Get a single pixel byte
- RLEcnt = 1 , val = byte ;
- }
- else { // RLE Flag
- file.Read( pb, 1, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != 1 ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if ( byte == 0 ) {
- RLEcnt = 1 , val = RUN_FLAG ;
- }
- else {
- RLEcnt = byte ;
-
- file.Read( pb, 1, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != 1 ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- val = byte ;
- }
-
- for ( i = 0 ; i < RLEcnt ; i++, PixelCount++, p++ ) *p = val ;
- }
- }
-
- return( Standard_True ) ;
-
-}
-
-Standard_Boolean AlienImage_SunRFAlienData::WritePixelRow(
- OSD_File& file,
- const Standard_Address pdata,
- const Standard_Integer rwbytes ) const
-{ Standard_Integer n, n1, n2 = 0;
- Standard_Byte *scanln = ( Standard_Byte * ) pdata ;
- Standard_Byte b ;
-
- while ( n2 < rwbytes ) {
- n1 = n2 ;
- n2 = n1 + 1 ;
-
- while( ( n2 < rwbytes ) && ( scanln[n1] == scanln[n2] ) ) n2++ ;
-
- n = n2 - n1 ;
-
- if ( n == 1 ) {
- b = scanln[n1]; file.Write( ( Standard_Address ) &b, 1 ) ;
-
- if ( scanln[n1] == RUN_FLAG ) {
- b = 0 ; file.Write( ( Standard_Address ) &b, 1 ) ;
- }
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- }
- else {
- while ( n > 256 ) {
- b = RUN_FLAG ; file.Write( ( Standard_Address ) &b, 1) ;
- b = 255 ; file.Write( ( Standard_Address ) &b, 1) ;
- b = scanln[n1];file.Write( ( Standard_Address ) &b, 1) ;
- n -= 256 ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
-
- b = RUN_FLAG ; file.Write( ( Standard_Address ) &b, 1 ) ;
- b = n-1 ; file.Write( ( Standard_Address ) &b, 1 ) ;
- b = scanln[n1];file.Write( ( Standard_Address ) &b, 1 ) ;
-
- }
- }
-
- return( Standard_True ) ;
-
-}
-
-void AlienImage_SunRFAlienData::FromPseudoColorImage(
- const Handle(Image_PseudoColorImage)& TheImage)
-
-{ Standard_Integer rowbytes,i ;
- Standard_Integer x, y, pix;
- Handle(Image_PseudoColorImage)anImage =
- TheImage->Squeeze(Aspect_IndexPixel( 0 )) ;
- Handle(Aspect_ColorMap) Cmap = anImage->ColorMap() ;
- Aspect_ColorMapEntry aEntry ;
-
- FreeData() ;
- myHeader.ras_magic = RAS_MAGIC ;
- myHeader.ras_width = anImage->Width() ;
- myHeader.ras_height = anImage->Height() ;
- myHeader.ras_depth = 8 ;
-
- rowbytes = ROWBYTES() ;
-
- myDataSize = myHeader.ras_height * rowbytes ;
- myData = Standard::Allocate( myDataSize ) ;
- myHeader.ras_length = myDataSize ;
-
- myHeader.ras_maptype = RMT_EQUAL_RGB ;
- myHeader.ras_maplength = Cmap->Size() ;
-
- myRedData = Standard::Allocate( myHeader.ras_maplength ) ;
- myGreenData = Standard::Allocate( myHeader.ras_maplength ) ;
- myBlueData = Standard::Allocate( myHeader.ras_maplength ) ;
-
- Standard_Byte *pr = ( Standard_Byte * ) myRedData ;
- Standard_Byte *pg = ( Standard_Byte * ) myGreenData ;
- Standard_Byte *pb = ( Standard_Byte * ) myBlueData ;
-
- for ( i = 0 ; i < myHeader.ras_maplength ; i++, pr++, pg++, pb++ ) {
- aEntry = Cmap->FindEntry( i ) ;
- *pr = ( Standard_Byte ) ( aEntry.Color().Red() * 255. + 0.5 ) ;
- *pg = ( Standard_Byte ) ( aEntry.Color().Green() * 255. + 0.5 ) ;
- *pb = ( Standard_Byte ) ( aEntry.Color().Blue() * 255. + 0.5 ) ;
- }
-
- myHeader.ras_maplength *= 3 ;
-
- if ( myData != NULL ) {
- Standard_Byte *pr = ( Standard_Byte * ) myData ;
- Standard_Byte *p ;
-
- for ( y = 0 ; y < myHeader.ras_height ; y++, pr += rowbytes ) {
- for ( x = 0, p = pr ; x < myHeader.ras_width ; x++ ) {
-
- pix = anImage->Pixel( anImage->LowerX()+x ,
- anImage->LowerY()+y ).Value() ;
-
- *p = ( Standard_Byte ) pix ; p++ ;
- }
- }
- }
-}
-
-void AlienImage_SunRFAlienData::FromColorImage(
- const Handle_Image_ColorImage& anImage)
-
-{ Standard_Integer rowbytes ;
- Standard_Integer x, y;
- Quantity_Color col ;
- Standard_Real r,g,b ;
-
- FreeData() ;
-
- myHeader.ras_magic = RAS_MAGIC ;
- myHeader.ras_width = anImage->Width() ;
- myHeader.ras_height = anImage->Height() ;
- myHeader.ras_depth = 24 ;
-
- rowbytes = ROWBYTES() ;
-
- myDataSize = myHeader.ras_height * rowbytes ;
- myData = Standard::Allocate( myDataSize ) ;
- myHeader.ras_length = myDataSize ;
-
- myHeader.ras_maptype = RMT_NONE ;
- myHeader.ras_maplength = 0 ;
-
- if ( myData != NULL ) {
- Standard_Byte *pr = ( Standard_Byte * ) myData ;
- Standard_Byte *p ;
-
- for ( y = 0 ; y < myHeader.ras_height ; y++, pr += rowbytes ) {
- for ( x = 0, p = pr ; x < myHeader.ras_width ; x++ ) {
-
- col = anImage->Pixel( anImage->LowerX()+x ,
- anImage->LowerY()+y ).Value() ;
-
- r = ( Standard_Integer ) ( col.Red() * 255. + 0.5 );
- g = ( Standard_Integer ) ( col.Green() * 255. + 0.5 );
- b = ( Standard_Integer ) ( col.Blue() * 255. + 0.5 );
-
- *p = ( Standard_Byte ) b ; p++ ;
- *p = ( Standard_Byte ) g ; p++ ;
- *p = ( Standard_Byte ) r ; p++ ;
- }
- }
- }
-}
-
-Handle_Image_ColorImage AlienImage_SunRFAlienData::ToColorImage() const
-
-{ Aspect_ColorPixel CPixel ;
- Quantity_Color acolor ;
- Handle(Image_ColorImage) ret_image = NULL ;
- Standard_Integer x,y, rowbytes ;
- Standard_Real r,g,b ;
- Standard_Byte *pr = ( Standard_Byte * ) myData ;
- Standard_Byte *p ;
-
- if ( myHeader.ras_depth == 24 || myHeader.ras_depth == 32 ) {
- ret_image = new Image_ColorImage( 0,0,
- (Standard_Integer)myHeader.ras_width,
- (Standard_Integer)myHeader.ras_height ) ;
-
- rowbytes = ROWBYTES() ;
-
- for ( y = 0 ; y < myHeader.ras_height ; y++, pr += rowbytes ) {
- for ( x = 0, p = pr ; x < myHeader.ras_width ; x++ ) {
- if ( myHeader.ras_depth == 32 ) p++ ; // Skeep Alpha
- b = ( Standard_Real ) *p / 255. ; p++ ;
- g = ( Standard_Real ) *p / 255. ; p++ ;
- r = ( Standard_Real ) *p / 255. ; p++ ;
-
- acolor.SetValues( r,g,b, Quantity_TOC_RGB ) ;
-
- CPixel.SetValue ( acolor ) ;
-
- ret_image->SetPixel( ret_image->LowerX()+x ,
- ret_image->LowerY()+y, CPixel ) ;
- }
- }
-
- }
-
- return( ret_image ) ;
-}
-
-Handle_Image_PseudoColorImage AlienImage_SunRFAlienData::ToPseudoColorImage()
- const
-
-{ Standard_Real r,g,b ;
- Standard_Integer x, y ;
- Handle(Image_PseudoColorImage) ret_image = NULL ;
-
- if ( myHeader.ras_depth <= 8 &&
- myHeader.ras_maplength ) {
- Standard_Integer i,rowbytes ;
- Aspect_ColorMapEntry Centry ;
- Quantity_Color color ;
- Aspect_IndexPixel IPixel ;
- Standard_Byte *red = ( Standard_Byte * ) myRedData ;
- Standard_Byte *green = ( Standard_Byte * ) myGreenData ;
- Standard_Byte *blue = ( Standard_Byte * ) myBlueData ;
- Standard_Byte *p ;
- Standard_Byte *pr = ( Standard_Byte * ) myData ;
- Handle(Aspect_GenericColorMap) colormap =
- new Aspect_GenericColorMap();
-
- for ( i = 0 ; i < myHeader.ras_maplength/3 ; i++, red++, green++, blue++ ) {
- r = ( Standard_Real ) *red / 255. ;
- g = ( Standard_Real ) *green / 255. ;
- b = ( Standard_Real ) *blue / 255. ;
- color.SetValues( r,g,b, Quantity_TOC_RGB );
- Centry.SetValue( i, color ) ;
- colormap->AddEntry( Centry ) ;
- }
-
- ret_image = new Image_PseudoColorImage( 0,0,
- Standard_Integer(myHeader.ras_width),
- Standard_Integer(myHeader.ras_height),
- colormap ) ;
-
- rowbytes = ROWBYTES() ;
-
- for ( y = 0 ; y < myHeader.ras_height ; y++, pr += rowbytes ) {
- for ( x = 0, p = pr ; x < myHeader.ras_width ; x++, p++ ) {
-
- IPixel.SetValue( Standard_Integer( *p ) ) ;
- ret_image->SetPixel( ret_image->LowerX()+x ,
- ret_image->LowerY()+y, IPixel ) ;
- }
- }
- }
-
- return ret_image ;
-}
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
--- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
-
-class SunRFAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
-
- ---Purpose: Defines a SunRF Alien image, i.e. an image using the
--- image format for SUN workstations.
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- SunRFAlienData from AlienImage,
- SUNRFFormat from AlienImage
-
-is
- Create returns mutable SunRFAlienImage from AlienImage;
----Purpose: Constructs an empty SunRF alien image.
-
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by SunRFAlienImage
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : Converts a SunRFAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : Converts an Image object to a SunRFAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Reads the content of a SunRFAlienImage object from a file
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Purpose: Writes content of a SunRFAlienImage object to a file
-
- SetFormat( me : in out mutable ;
- aFormat : SUNRFFormat from AlienImage);
- ---Purpose: Sets the SUN Raster File Format for Write method.
-
- Format( me : in immutable )
- returns SUNRFFormat from AlienImage ;
- ---Purpose: Returns the SUN Raster File Format .
-
-fields
- myData : SunRFAlienData from AlienImage ;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_SunRFAlienImage.ixx>
-
-AlienImage_SunRFAlienImage::AlienImage_SunRFAlienImage()
-
-{ // il faut faire un new si mydata est du type HANDLE
- myData = new AlienImage_SunRFAlienData() ;
-}
-
-void AlienImage_SunRFAlienImage::Clear()
-
-{ myData->Clear() ; }
-
-Standard_Boolean AlienImage_SunRFAlienImage::Write( OSD_File& file ) const
-
-{ return( myData->Write( file ) ) ; }
-
-Standard_Boolean AlienImage_SunRFAlienImage::Read( OSD_File& file )
-
-{ return( myData->Read( file ) ) ; }
-
-Handle_Image_Image AlienImage_SunRFAlienImage::ToImage() const
-
-{ return( myData->ToImage() ) ; }
-
-void AlienImage_SunRFAlienImage::FromImage( const Handle_Image_Image& anImage )
-
-{ myData->FromImage( anImage ) ; }
-
-void AlienImage_SunRFAlienImage::SetFormat(
- const AlienImage_SUNRFFormat aFormat )
-
-{ myData->SetFormat( aFormat ) ; }
-
-AlienImage_SUNRFFormat AlienImage_SunRFAlienImage::Format() const
-
-{ return myData->Format( ) ; }
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_X11XColor.hxx>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_X11XColor)
-{
- static Handle(Standard_Type) _atype = new Standard_Type ("AlienImage_X11XColor", sizeof (AlienImage_X11XColor));
- return _atype;
-}
-
-Standard_Boolean operator == ( const AlienImage_X11XColor& AnObject,
- const AlienImage_X11XColor& AnotherObject )
-
-{ Standard_Boolean _result = Standard_True;
-
- _result = _result && (AnObject.pixel==AnotherObject.pixel) ;
- _result = _result && (AnObject.red ==AnotherObject.red) ;
- _result = _result && (AnObject.green==AnotherObject.green) ;
- _result = _result && (AnObject.blue ==AnotherObject.blue) ;
- _result = _result && (AnObject.flags==AnotherObject.flags) ;
-
- return _result;
-}
-
-//============================================================================
-//==== ShallowDump : Writes a CString value.
-//============================================================================
-void ShallowDump (const AlienImage_X11XColor& AnObject, Standard_OStream& s)
-
-{
- s << "AlienImage_X11XColor\n" ;
- s << "\tpixel :" << AnObject.pixel << "\n";
- s << "\tred/green/blue :" << AnObject.red << "/"
- << AnObject.green << "/"
- << AnObject.blue<< "\n";
- s << "\tflags :" << AnObject.flags << "\n" << flush ;
-}
-
-ostream& operator << ( ostream& s, const AlienImage_X11XColor& c )
-
-{
- return( s << "(" << c.pixel
- << ",(" << c.red << ","
- << c.green <<","
- << c.blue
- << "),"
- << hex << c.flags
- << ")" ) ;
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_X11XColor.hxx
-//==== Role : The header file of primitve type "X11XColor" from package
-//==== "AlienImage"
-//====
-//==== Implementation: This is a primitive type implemented with typedef
-//==== typedef XColor AlienImage_X11XColor;
-//============================================================================
-
-#ifndef AlienImage_X11XColor_HeaderFile
-#define AlienImage_X11XColor_HeaderFile
-
-/*
- * Data structure used by color operations from <X11/Xlib.h>
- */
-//==== Definition de Type ====================================================
-#include <Standard_Type.hxx>
-extern const Handle_Standard_Type AlienImage_X11XColorType;
-inline Handle(Standard_Type) AlienImage_X11XColorType_Type_() {return 0;}
-//============================================================================
-
-/*
-invalide car unsigned long = 32 ou 64 !
-#include <X11/Xlib.h>
-typedef XColor AlienImage_X11XColor ;
-*/
-
-/*
- * Data structure used by color operations
- */
-typedef struct {
- unsigned int pixel;
- unsigned short red, green, blue;
- char flags; /* do_red, do_green, do_blue */
- char pad;
-} AlienImage_X11XColor;
-
-ostream& operator << ( ostream& s, const AlienImage_X11XColor& color );
-
-Standard_Boolean operator == (const AlienImage_X11XColor& AnObject,
- const AlienImage_X11XColor& AnotherObject);
-void ShallowDump (const AlienImage_X11XColor& AnObject, Standard_OStream& S);
-
-#endif
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class X11XWDAlienData from AlienImage inherits AlienImageData from AlienImage
-
- ---Version: 0.0
-
- ---Purpose: This class defines a X11 Alien image.
- ---Keywords:
- ---Warning:
- ---References:
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- X11XColor from AlienImage,
- X11XWDFileHeader from AlienImage
-
-raises
- OutOfRange from Standard,
- TypeMismatch from Standard
-
-is
- Create returns mutable X11XWDAlienData from AlienImage ;
-
- Clear( me : in out mutable ) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by X11XWDAlienData
- ---C++: alias ~
-
- Read ( me : in out mutable ; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Read content of a X11XWDAlienData object from a file
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Write content of a X11XWDAlienData object to a file
-
- SetName( me : in out mutable ;
- aName : in AsciiString from TCollection)
- is redefined;
- ---Level: Public
- ---Purpose: Set Image name .
-
- Name( me : in immutable ) returns AsciiString from TCollection
- is redefined;
- ---C++: return const &
- ---Level: Public
- ---Purpose: Get Image name .
-
- ToImage( me : in immutable)
- returns mutable Image from Image
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a X11XWDAlienData object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image )
- raises TypeMismatch from Standard ;
- ---Level: Public
- ---Purpose : convert a Image object to a X11XWDAlienData object.
-
- --
- -- Private Method
- --
-
- Pixel ( me : in immutable ; X,Y : in Integer from Standard )
- returns Integer from Standard
- raises OutOfRange from Standard is private ;
- ---Level: Internal
-
- SetPixel( me : in out mutable; X,Y : in Integer from Standard ;
- Value : in Integer from Standard )
- raises OutOfRange from Standard is private ;
- ---Level: Internal
-
- DataSize( me : in immutable)
- returns Integer from Standard is private ;
- ---Level: Internal
- ---Purpose: Compute the imaga data size in byte
- -- from header information
-
- RedShift( me : in immutable) returns Integer from Standard
- raises TypeMismatch from Standard is private ;
- ---Purpose: Compute the red shift for TrueColor X11XWDImage
-
- GreenShift( me : in immutable) returns Integer from Standard
- raises TypeMismatch from Standard is private ;
- ---Level: Internal
- ---Purpose: Compute the red shift for TrueColor X11XWDImage
-
- BlueShift( me : in immutable) returns Integer from Standard
- raises TypeMismatch from Standard is private ;
- ---Level: Internal
- ---Purpose: Compute the red shift for TrueColor X11XWDImage
-
- ToPseudoColorImage( me : in immutable)
- returns PseudoColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a AlienImage object.
-
- ToColorImage( me : in immutable)
- returns ColorImage from Image is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a AlienImage object.
-
- FromPseudoColorImage( me : in out mutable;
- anImage : in PseudoColorImage from Image )
- is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a X11XWDAlienData object.
-
- FromColorImage( me : in out mutable;
- anImage : in ColorImage from Image)
- is private ;
- ---Level: Internal
- ---Purpose : convert a Image object to a X11XWDAlienData object.
-
-fields
-
- myHeader : X11XWDFileHeader from AlienImage is protected ;
-
- myColors : Address from Standard is protected ;
- -- XColors definition
-
- myData : Address from Standard is protected ;
- -- my is a ( unsigned char * ) for 8 bit image ,
- -- ( unsigned int * ) for 24 bit image .
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#define PRO9517 //GG_010997
-// 1) Le swap ne fonctionne pas correctement sur DEC
-// car X11XColor.pixel est int et non long (::Read(),::Write()).
-// 2) Initialiser la table des couleurs avant d'ecrire
-// le fichier temporaire (::Write())
-
-#define K4 //GG_110398
-// Ne pas initialiser una AsciiString avec '\0' dans le
-// constructeur de AlienImage_X11XWDAlienData sinon RAISE !
-
-#define TEST //GG_140699
-// Check file extension, must be ".xwd".
-
-#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
-# include <X11/Xlib.h>
-#endif // WNT
-#include <Aspect_GenericColorMap.hxx>
-#include <Image_PseudoColorImage.hxx>
-#include <AlienImage_MemoryOperations.hxx>
-#include <AlienImage_X11XColor.hxx>
-#include <AlienImage_X11XWDAlienData.ixx>
-#include <Aspect_ColorMapEntry.hxx>
-#include <Standard.hxx>
-
-#ifdef TRACE
-static int Verbose = 0 ;
-#endif
-
-
-
-AlienImage_X11XWDAlienData::AlienImage_X11XWDAlienData()
-
-{ myData = NULL ;
- myColors = NULL ;
-}
-
-void AlienImage_X11XWDAlienData::SetName( const TCollection_AsciiString& aName)
-
-{ myName = aName + TCollection_AsciiString( "\0" ) ;
- myHeader.header_size = sizeof( myHeader ) + myName.Length() ;
-}
-
-const TCollection_AsciiString& AlienImage_X11XWDAlienData::Name() const
-
-{ return ( myName ) ; }
-
-void AlienImage_X11XWDAlienData::Clear()
-
-{ Standard_Integer size ;
-
- myHeader.header_size = sizeof( myHeader ) ;
- /* Size of the entire file header (bytes).*/
- myHeader.file_version = 0 ; /* XWD_FILE_VERSION */
- myHeader.pixmap_format= 0; /* Pixmap format */
- myHeader.pixmap_depth = 0 ; /* Pixmap depth */
- myHeader.pixmap_width = 0 ; /* Pixmap width */
- myHeader.pixmap_height= 0 ; /* Pixmap height */
- myHeader.xoffset = 0 ; /* Bitmap x offset */
- myHeader.byte_order = 0; /* MSBFirst, LSBFirst */
- myHeader.bitmap_unit = 0 ; /* Bitmap unit */
- myHeader.bitmap_bit_order = 0; /* MSBFirst, LSBFirst */
- myHeader.bitmap_pad = 0 ; /* Bitmap scanline pad */
- myHeader.bits_per_pixel = 0 ; /* Bits per pixel */
- myHeader.bytes_per_line =0 ; /* Bytes per scanline */
- myHeader.visual_class = 0 ; /* Class of colormap */
- myHeader.red_mask = 0 ; /* Z red mask */
- myHeader.green_mask = 0 ; /* Z green mask */
- myHeader.blue_mask = 0 ; /* Z blue mask */
- myHeader.bits_per_rgb = 0 ; /* Log2 of distinct color values */
- myHeader.colormap_entries = 0 ; /* Number of entries in colormap */
- myHeader.ncolors = 0 ; /* Number of Color structures */
- myHeader.window_width = 0 ; /* Window width */
- myHeader.window_height= 0 ; /* Window height */
- myHeader.window_x = 0 ; /* Window upper left X coordinate */
- myHeader.window_y = 0 ; /* Window upper left Y coordinate */
- myHeader.window_bdrwidth =0 ; /* Window border width */
-
- myName.Clear() ;
-
- if ( myData ) {
- //Free all allocated memory
- Standard::Free(myData) ;
- myData = NULL ;
- }
-
- if ( myColors ) {
- size = ( Standard_Integer )
- myHeader.ncolors * sizeof( AlienImage_X11XColor ) ;
- //Free all allocated memory
- Standard::Free(myColors);
- myColors = NULL ;
- }
-
-}
-
-Standard_Boolean AlienImage_X11XWDAlienData::Write( OSD_File& file ) const
-
-{ Standard_Integer size, i ;
- unsigned long swaptest = 1;
- AlienImage_X11XWDFileHeader TheHeader = myHeader ;
-
- if ( myData == NULL ) return( Standard_False ) ;
- if ( TheHeader.ncolors &&
- myColors == NULL ) return( Standard_False ) ;
-
-
- // Write out TheHeader information
-
- size = ( Standard_Integer ) TheHeader.header_size - sizeof( TheHeader ) ;
-
- if ( size ) {
- // Add '\0' at the end of name
- TheHeader.header_size++ ;
- }
-
- if (*(char *) &swaptest) {
- AlienImage_X11XWDFileHeader SwapHeader = TheHeader ;
-
- AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &SwapHeader,
- sizeof(SwapHeader));
- file.Write( &SwapHeader , sizeof( SwapHeader ) ) ;
- }
- else {
- const Standard_Address pHeader = ( Standard_Address ) &TheHeader ;
-
- file.Write( pHeader, sizeof( TheHeader ) ) ;
- }
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- size = ( Standard_Integer ) TheHeader.header_size - sizeof( TheHeader ) ;
-
- if ( size ) {
- char end = '\0' ;
- Standard_Address pend = Standard_Address( &end ) ;
-
- file.Write( myName, myName.Length() ) ;
-
- file.Write( pend, 1 ) ;
- }
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- // write out the color map buffer
-
- if ( TheHeader.ncolors ) {
- size = ( Standard_Integer ) TheHeader.ncolors
- * sizeof( AlienImage_X11XColor ) ;
-
- if (*(char *) &swaptest) {
- Standard_Address palloc =
- Standard::Allocate( size ) ;
-#ifdef PRO9517
- const AlienImage_X11XColor *p = ( AlienImage_X11XColor * ) myColors ;
- AlienImage_X11XColor *pp = ( AlienImage_X11XColor * ) palloc ;
-
- for (i = 0 ; (unsigned int ) i < TheHeader.ncolors; i++,p++,pp++) {
- pp->pixel = p->pixel;
- pp->red = p->red;
- pp->green = p->green;
- pp->blue = p->blue;
- pp->flags = p->flags;
- AlienImage_MemoryOperations::SwapLong (
- (Standard_Address) &(pp->pixel), sizeof(int));
- AlienImage_MemoryOperations::SwapShort(
- (Standard_Address) &(pp->red) , 3 * sizeof(short));
- }
-#else
- const AlienImage_X11XColor *p = ( AlienImage_X11XColor * ) palloc ;
-
- for (i = 0 ; i < TheHeader.ncolors; i++,p++) {
- AlienImage_MemoryOperations::SwapLong (
- (Standard_Address) &(p->pixel), sizeof(long));
- AlienImage_MemoryOperations::SwapShort(
- (Standard_Address) &(p->red) , 3 * sizeof(short));
- }
-#endif
-
- file.Write( palloc, size ) ;
-
- //Free all allocated memory
- Standard::Free(palloc) ;
- }
- else {
- file.Write( myColors, size ) ;
- }
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- }
-
- if ( DataSize() ) {
- file.Write( myData, DataSize() ) ;
-
- if ( file.Failed() ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- }
-
- return( Standard_True ) ;
-
-}
-
-
-Standard_Boolean AlienImage_X11XWDAlienData::Read( OSD_File& file )
-
-{ Standard_Integer bblcount, i, size ;
- unsigned long swaptest = 1;
- Standard_Address pheader = ( Standard_Address ) &myHeader ;
-
-#ifdef TEST
- OSD_Path path; file.Path(path);
- TCollection_AsciiString ext = path.Extension(); ext.LowerCase();
- if( ext != ".xwd" ) {
- TCollection_AsciiString sysname; path.SystemName(sysname);
-#ifdef TRACE
- cout << " *** AlienImage_X11XWDAlienData::Read('" << sysname << "'). must have an '.xwd' extension" << endl;
-#endif
- return Standard_False;
- }
-#endif
-
- // Read in myHeader information
-
- file.Read( pheader, sizeof( myHeader ), bblcount ) ;
-
- if ( file.Failed() || ( bblcount != sizeof( myHeader ) ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if (*(char *) &swaptest)
- AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &myHeader,
- sizeof(myHeader));
-
- // check to see if the dump file is in the proper format */
- if (myHeader.file_version != XWD_FILE_VERSION) {
- // ERROR "XWD file format version mismatch."
-
- if (*(char *) &swaptest)
- AlienImage_MemoryOperations::SwapLong( ( Standard_Address ) &myHeader,
- sizeof(myHeader));
-
- if (myHeader.file_version != XWD_FILE_VERSION) {
- // ERROR "XWD file format version mismatch."
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- else {
- // Data come from a swaped computer ??
- swaptest = 0 ;
- }
- }
-
- if (myHeader.header_size < sizeof(myHeader)) {
- // ERROR "XWD header size is too small."
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
-#ifdef TRACE
- if ( Verbose ) cout << myHeader << endl << flush ;
-#endif
-
- // read in window name
-
- size = ( Standard_Integer ) myHeader.header_size - sizeof( myHeader ) ;
-
- if ( size > 0 ) {
-#ifdef K4
- TCollection_AsciiString name( bblcount ) ;
-#else
- TCollection_AsciiString name( bblcount , '\0') ;
-#endif
-
- file.Read( name, size ) ; bblcount = name.Length() ;
-#ifdef WNT
- --size;
-#endif // WNT
-
- if ( file.Failed() || ( bblcount != size ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- myName = name ;
-
-#ifdef TRACE
- if ( Verbose ) cout << myName << endl << flush ;
-#endif
-
- }
-
- // read in the color map buffer
-
- if ( myHeader.ncolors ) {
- size = ( Standard_Integer ) myHeader.ncolors
- * sizeof( AlienImage_X11XColor ) ;
-
- myColors = Standard::Allocate( size ) ;
-
- file.Read( myColors, size, bblcount ) ;
-
- if ( file.Failed() || ( bblcount != size ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
-
- if ( *(char *) &swaptest ) {
- AlienImage_X11XColor *p
- = ( AlienImage_X11XColor * )myColors ;
- for (i = 0 ; (unsigned int ) i < myHeader.ncolors; i++,p++) {
-#ifdef PRO9517
- AlienImage_MemoryOperations::SwapLong (
- (Standard_Address) &(p->pixel), sizeof(int));
-#else
- AlienImage_MemoryOperations::SwapLong (
- (Standard_Address) &(p->pixel), sizeof(long));
-#endif
- AlienImage_MemoryOperations::SwapShort(
- (Standard_Address) &(p->red) , 3 * sizeof(short));
- }
- }
-
-#ifdef TRACE
- if ( Verbose ) {
- AlienImage_X11XColor *p = ( AlienImage_X11XColor * )myColors;
-
- for (i = 0 ; i < myHeader.ncolors; i++,p++) {
- cout << *p << endl << flush ;
- }
-
- }
-#endif
- }
-
- if ( DataSize() ) {
- myData = Standard::Allocate( DataSize() ) ;
-
- file.Read( myData, DataSize(), bblcount ) ;
-
- if ( file.Failed() || ( bblcount != DataSize() ) ) {
- // ERROR
- file.Seek( 0, OSD_FromBeginning ) ;
- return( Standard_False ) ;
- }
- }
-
- return( Standard_True ) ;
-
-}
-
-Handle_Image_Image AlienImage_X11XWDAlienData::ToImage() const
-
-{ if ( myHeader.pixmap_depth <= 8 &&
- myHeader.ncolors &&
- myHeader.pixmap_format == ZPixmap) {
- return( ToPseudoColorImage() ) ;
- }
- else if ( myHeader.visual_class == TrueColor &&
- myHeader.pixmap_format == ZPixmap) {
- return( ToColorImage() ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a X11XWDAlienData to a unknown Image_Image type");
-
- return( NULL ) ;
- }
-}
-
-void AlienImage_X11XWDAlienData::FromImage( const Handle_Image_Image& anImage )
-
-{ if ( anImage->Type() == Image_TOI_PseudoColorImage ) {
- Handle(Image_PseudoColorImage) aPImage =
- Handle(Image_PseudoColorImage)::DownCast(anImage) ;
-
- FromPseudoColorImage( aPImage ) ;
- }
- else if ( anImage->Type() == Image_TOI_ColorImage ) {
- Handle(Image_ColorImage) aCImage =
- Handle(Image_ColorImage)::DownCast(anImage) ;
-
- FromColorImage( aCImage ) ;
- }
- else {
- Standard_TypeMismatch_Raise_if( Standard_True,
- "Attempt to convert a unknown Image_Image type to a X11XWDAlienData");
- }
-}
-
-//------------------------------------------------------------------------------
-// Private Method
-//------------------------------------------------------------------------------
-
-
-void AlienImage_X11XWDAlienData::FromPseudoColorImage(
- const Handle_Image_PseudoColorImage& anImage)
-
-{ Standard_Integer size, i ;
-
- /* Size of the entire file header (bytes).*/
- myHeader.header_size = sizeof(myHeader) + myName.Length() ;
- myHeader.file_version = XWD_FILE_VERSION ; /* XWD_FILE_VERSION */
- myHeader.pixmap_format = ZPixmap ; /* Pixmap format */
- myHeader.pixmap_depth = 8 ; /* Pixmap depth */
- myHeader.pixmap_width = anImage->Width() ;/* Pixmap width */
- myHeader.pixmap_height = anImage->Height() ;/* Pixmap height */
- myHeader.xoffset = 0 ; /* Bitmap x offset */
- myHeader.byte_order = MSBFirst; /* MSBFirst, LSBFirst */
- myHeader.bitmap_unit = 32 ; /* Bitmap unit */
- myHeader.bitmap_bit_order = MSBFirst; /* MSBFirst, LSBFirst */
- myHeader.bitmap_pad = 32 ; /* Bitmap scanline pad */
- myHeader.bits_per_pixel = 8 ; /* Bits per pixel */
- /* Bytes per scanline */
- size = ( Standard_Integer ) ( anImage->Width() * myHeader.bits_per_pixel );
-
- myHeader.bytes_per_line = size / myHeader.bitmap_unit ;
- if ( size % myHeader.bitmap_pad ) myHeader.bytes_per_line += 1 ;
-
- myHeader.bytes_per_line *= ( myHeader.bitmap_unit / 8 ) ;
-
- myHeader.visual_class = PseudoColor ; /* Class of colormap */
- myHeader.red_mask = 0 ; /* Z red mask */
- myHeader.green_mask = 0 ; /* Z green mask */
- myHeader.blue_mask = 0 ; /* Z blue mask */
- myHeader.bits_per_rgb = 8 ; /* Log2 of distinct color values */
- myHeader.colormap_entries = 256 ; /* Number of entries in colormap */
- myHeader.ncolors = (anImage->ColorMap())->Size() ;
- /* Number of Color structures */
- myHeader.window_width = anImage->Width() ; /* Window width */
- myHeader.window_height = anImage->Height() ; /* Window height */
- myHeader.window_x = 0 ; /* Window upper left X coordinate */
- myHeader.window_y = 0 ; /* Window upper left Y coordinate */
- myHeader.window_bdrwidth = 0 ; /* Window border width */
-
- size = ( Standard_Integer ) myHeader.ncolors
- * sizeof( AlienImage_X11XColor ) ;
-
- myColors = Standard::Allocate( size ) ;
-
- AlienImage_X11XColor *p = ( AlienImage_X11XColor * )myColors ;
- Aspect_ColorMapEntry aCentry ;
-
- for ( i = 1 ; (unsigned int ) i <= myHeader.ncolors ; i++, p++ ) {
- p->pixel = 0 ;
- p->red = p->green = p->blue = 0 ;
- p->flags = 0 ;
-
- aCentry = (anImage->ColorMap())->Entry( i ) ;
-
- if ( aCentry.IsAllocated() == Standard_True ) {
- p->flags = DoRed | DoGreen | DoBlue ;
- p->pixel = aCentry.Index() ;
- p->red = ( unsigned short )
- ( (aCentry.Color()).Red() * 0xffff + 0.5 ) ;
- p->green = ( unsigned short )
- ( (aCentry.Color()).Green() * 0xffff + 0.5 ) ;
- p->blue = ( unsigned short )
- ( (aCentry.Color()).Blue() * 0xffff + 0.5 ) ;
- }
- }
-
- if ( anImage->Size() ) {
- Standard_Integer x, y ;
-
- myData = Standard::Allocate( DataSize() ) ;
-
- for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
- for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
- SetPixel( x, y,
- ( anImage->Pixel( anImage->LowerX()+x ,
- anImage->LowerY()+y )).Value() ) ;
- }
- }
-
- }
-}
-
-void AlienImage_X11XWDAlienData::FromColorImage(
- const Handle_Image_ColorImage& anImage)
-
-{ long int size ;;
-
- /* Size of the entire file header (bytes).*/
- myHeader.header_size = sizeof(myHeader) + myName.Length() ;
- myHeader.file_version = XWD_FILE_VERSION ; /* XWD_FILE_VERSION */
- myHeader.pixmap_format = ZPixmap ; /* Pixmap format */
- myHeader.pixmap_depth = 24 ; /* Pixmap depth */
- myHeader.pixmap_width = anImage->Width() ;/* Pixmap width */
- myHeader.pixmap_height = anImage->Height() ;/* Pixmap height */
- myHeader.xoffset = 0 ; /* Bitmap x offset */
- myHeader.byte_order = MSBFirst; /* MSBFirst, LSBFirst */
- myHeader.bitmap_unit = 32 ; /* Bitmap unit */
- myHeader.bitmap_bit_order = MSBFirst; /* MSBFirst, LSBFirst */
- myHeader.bitmap_pad = 32 ; /* Bitmap scanline pad */
- myHeader.bits_per_pixel = 32 ; /* Bits per pixel */
- /* Bytes per scanline */
- size = anImage->Width() * myHeader.bits_per_pixel ;
-
- myHeader.bytes_per_line = size / myHeader.bitmap_unit ;
- if ( size % myHeader.bitmap_pad ) myHeader.bytes_per_line += 1 ;
-
- myHeader.bytes_per_line *= ( myHeader.bitmap_unit / 8 ) ;
-
- myHeader.visual_class = TrueColor ; /* Class of colormap */
- myHeader.red_mask = 0xff ; /* Z red mask */
- myHeader.green_mask = 0xff00 ; /* Z green mask */
- myHeader.blue_mask = 0xff0000 ; /* Z blue mask */
- myHeader.bits_per_rgb = 8 ; /* Log2 of distinct color values */
- myHeader.colormap_entries = 256 ; /* Number of entries in colormap */
- myHeader.ncolors = 0 ; /* Number of Color structures */
- myHeader.window_width = anImage->Width() ; /* Window width */
- myHeader.window_height = anImage->Height() ; /* Window height */
- myHeader.window_x = 0 ; /* Window upper left X coordinate */
- myHeader.window_y = 0 ; /* Window upper left Y coordinate */
- myHeader.window_bdrwidth = 0 ; /* Window border width */
-
-
- myColors = NULL ;
-
- if ( anImage->Size() ) {
- Standard_Integer x, y, pix, c ;
- const Standard_Integer rs = RedShift() ;
- const Standard_Integer gs = GreenShift() ;
- const Standard_Integer bs = BlueShift() ;
- const Standard_Integer ColorRange =
- Standard_Integer( ( 1 << myHeader.bits_per_rgb ) - 1 );
- Quantity_Color col ;
-
- myData = Standard::Allocate( DataSize() ) ;
-
- for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
- for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
- col = anImage->Pixel( anImage->LowerX()+x ,
- anImage->LowerY()+y ).Value() ;
-
- pix = 0 ;
-
- c = ( Standard_Integer ) ( col.Red() * ColorRange + 0.5 );
- c = ( Standard_Integer ) (( c << rs ) & myHeader.red_mask) ;
- pix |= c ;
-
- c = ( Standard_Integer ) ( col.Green() * ColorRange + 0.5 );
- c = ( Standard_Integer ) (( c << gs ) & myHeader.green_mask) ;
- pix |= c ;
-
- c = ( Standard_Integer ) ( col.Blue() * ColorRange + 0.5 );
- c = ( Standard_Integer ) (( c << bs ) & myHeader.blue_mask) ;
- pix |= c ;
-
- SetPixel( x, y, pix ) ;
- }
- }
-
- }
-}
-
-Handle_Image_ColorImage AlienImage_X11XWDAlienData::ToColorImage() const
-
-{ Aspect_ColorPixel CPixel ;
- Quantity_Color acolor ;
- Handle(Image_ColorImage) ret_image = NULL ;
- Standard_Integer pix,x,y ;
- Standard_Real r,g,b, maxcol ;
-
- if ( myHeader.visual_class == TrueColor &&
- myHeader.pixmap_format == ZPixmap) {
- ret_image = new Image_ColorImage( 0,0,
- (Standard_Integer)myHeader.pixmap_width,
- (Standard_Integer)myHeader.pixmap_height ) ;
-
- maxcol = ( 1 << myHeader.bits_per_rgb ) - 1 ;
-
- for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
- for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
- pix = Pixel( x, y ) ;
-
- r = ( ( pix & myHeader.red_mask ) >> RedShift() ) / maxcol ;
- g = ( ( pix & myHeader.green_mask ) >> GreenShift() ) / maxcol ;
- b = ( ( pix & myHeader.blue_mask ) >> BlueShift() ) / maxcol ;
-
- acolor.SetValues( r,g,b, Quantity_TOC_RGB ) ;
- CPixel.SetValue ( acolor ) ;
-
- ret_image->SetPixel( ret_image->LowerX()+x ,
- ret_image->LowerY()+y, CPixel ) ;
- }
- }
-
- }
-
- return( ret_image ) ;
-}
-
-Handle_Image_PseudoColorImage AlienImage_X11XWDAlienData::ToPseudoColorImage()
- const
-
-{ Standard_Real r,g,b ;
- Standard_Integer x, y ;
- const Standard_Real XRange = Standard_Real( Standard_Integer(0xffff) );
- const Standard_Integer newColorSize =
- Standard_Integer(myHeader.colormap_entries*sizeof(AlienImage_X11XColor));
- Handle(Image_PseudoColorImage) ret_image = NULL ;
-
- if ( myHeader.pixmap_depth <= 8 &&
- myHeader.ncolors &&
- myHeader.pixmap_format == ZPixmap) {
-// unsigned long int i, j, ncol ;
- unsigned long int i, ncol ;
- Aspect_ColorMapEntry Centry ;
- Quantity_Color color ;
- AlienImage_X11XColor *p ;
- AlienImage_X11XColor *newColor ;
- Standard_Address palloc ;
- Aspect_IndexPixel IPixel ;
-
- palloc = Standard::Allocate( newColorSize ) ;
-
- newColor = ( AlienImage_X11XColor * ) palloc ;
-
- p = ( AlienImage_X11XColor * )myColors;
-
- for ( i = 0 ; i < myHeader.ncolors ; i++, p++ ) newColor[p->pixel] = *p;
- for ( i = 0 ; i < myHeader.colormap_entries ; i++ ) newColor[i].flags = 0 ;
-
- for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
- for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
- newColor[ Pixel( x, y ) ].flags = DoRed | DoGreen | DoBlue ;
- }
- }
-
- for ( i = ncol = 0 ; i < myHeader.colormap_entries ; i++ ) {
- if ( newColor[i].flags ) ncol++ ;
- }
-
- Handle(Aspect_GenericColorMap) colormap =
- new Aspect_GenericColorMap();
-
- for ( i = 0 ; i < myHeader.colormap_entries ; i++ ) {
- if ( newColor[i].flags ) {
- r = ( Standard_Real ) newColor[i].red / XRange ;
- g = ( Standard_Real ) newColor[i].green / XRange ;
- b = ( Standard_Real ) newColor[i].blue / XRange ;
- color.SetValues( r,g,b, Quantity_TOC_RGB );
- Centry.SetValue( Standard_Integer(newColor[i].pixel), color ) ;
- colormap->AddEntry( Centry ) ;
- }
- }
-
- ret_image = new Image_PseudoColorImage( 0,0,
- Standard_Integer(myHeader.pixmap_width),
- Standard_Integer(myHeader.pixmap_height),
- colormap ) ;
-
- for ( y = 0 ; (unsigned int ) y < myHeader.pixmap_height ; y++ ) {
- for ( x = 0 ; (unsigned int ) x < myHeader.pixmap_width ; x++ ) {
- IPixel.SetValue( Pixel( x, y ) ) ;
- ret_image->SetPixel( ret_image->LowerX()+x ,
- ret_image->LowerY()+y, IPixel ) ;
- }
- }
-
-
- //Free all allocated memory
- Standard::Free(palloc);
- }
-
- return ret_image ;
-
-}
-
-Standard_Integer AlienImage_X11XWDAlienData::DataSize() const
-
-{
- if ( myHeader.pixmap_format != ZPixmap)
- return( myHeader.bytes_per_line * myHeader.pixmap_height
- * myHeader.pixmap_depth );
-
- return( myHeader.bytes_per_line * myHeader.pixmap_height);
-}
-
-void AlienImage_X11XWDAlienData::SetPixel(
- const Standard_Integer x,
- const Standard_Integer y,
- const Standard_Integer value )
-
-{ unsigned char *p ;
- unsigned long int pixel_size ;
-
- Standard_OutOfRange_Raise_if(
- ( x < 0 || (unsigned int ) x >= myHeader.pixmap_width ||
- y < 0 || (unsigned int ) y >= myHeader.pixmap_height ),
- "Index out of range in X11XWDAlienData::Pixel");
-
- pixel_size = ( unsigned long int ) myHeader.bytes_per_line /
- myHeader.pixmap_width;
-
- p = ( unsigned char * ) myData ;
- p += y * myHeader.bytes_per_line + x * pixel_size ;
-
- if ( pixel_size == 1 ) {
- *p = ( unsigned char ) value ;
- }
- else if ( pixel_size == 2 ) {
- *( ( unsigned short int * ) p ) = ( unsigned short int ) value ;
- }
- else if ( pixel_size == 4 ) {
- *( ( unsigned long int * ) p ) = ( unsigned long int ) value ;
- }
-}
-
-Standard_Integer AlienImage_X11XWDAlienData::Pixel(
- const Standard_Integer x, const Standard_Integer y ) const
-
-{ unsigned char *p ;
- unsigned long int pixel_size ;
- unsigned long int pix ;
- Standard_Integer ret ;
-
- Standard_OutOfRange_Raise_if(
- ( x < 0 || (unsigned int ) x >= myHeader.pixmap_width ||
- y < 0 || (unsigned int ) y >= myHeader.pixmap_height ),
- "Index out of range in X11XWDAlienData::Pixel");
-
- pixel_size = ( unsigned long int ) myHeader.bytes_per_line /
- myHeader.pixmap_width;
-
- p = ( unsigned char * ) myData ;
- p += y * myHeader.bytes_per_line + x * pixel_size ;
-
- if ( pixel_size == 1 ) {
- pix = ( unsigned long int ) *p ;
- }
- else if ( pixel_size == 2 ) {
- pix = *( ( unsigned short int * ) p ) ;
- }
- else {
- pix = *( ( unsigned long int * ) p ) ;
- }
-
- ret = Standard_Integer ( pix );
-
- return( ret ) ;
-
-}
-
-Standard_Integer AlienImage_X11XWDAlienData::RedShift() const
-
-{ Standard_Integer shift = 0 ;
-
- Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
- "Attempt to get RedShift from a non TrueColor X11XWDImage" ) ;
-
- if ( ( myHeader.red_mask >> myHeader.bits_per_rgb ) == 0 ) {
- shift = 0 ;
- }
- else if ( ( myHeader.red_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
- shift = Standard_Integer( myHeader.bits_per_rgb ) ;
- }
- else {
- shift = Standard_Integer( 2 * myHeader.bits_per_rgb );
- }
- return shift ;
-}
-
-Standard_Integer AlienImage_X11XWDAlienData::GreenShift() const
-
-{ Standard_Integer shift = 0 ;
-
- Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
- "Attempt to get GreenShift from a non TrueColor X11XWDImage" ) ;
-
- if ( ( myHeader.green_mask >> myHeader.bits_per_rgb ) == 0 ) {
- shift = 0 ;
- }
- else if ( ( myHeader.green_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
- shift = Standard_Integer( myHeader.bits_per_rgb ) ;
- }
- else {
- shift = Standard_Integer( 2 * myHeader.bits_per_rgb ) ;
- }
- return shift ;
-}
-
-Standard_Integer AlienImage_X11XWDAlienData::BlueShift() const
-
-{ Standard_Integer shift = 0 ;
-
- Standard_TypeMismatch_Raise_if( myHeader.visual_class != TrueColor ,
- "Attempt to get BlueShift from a non TrueColor X11XWDImage" ) ;
-
- if ( ( myHeader.blue_mask >> myHeader.bits_per_rgb ) == 0 ) {
- shift = 0 ;
- }
- else if ( ( myHeader.blue_mask >> ( 2 * myHeader.bits_per_rgb ) ) == 0 ) {
- shift = Standard_Integer( myHeader.bits_per_rgb ) ;
- }
- else {
- shift = Standard_Integer( 2 * myHeader.bits_per_rgb ) ;
- }
-
- return shift ;
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
-# include <X11/Xlib.h>
-#endif // WNT
-#include <AlienImage_X11XWDFileHeader.hxx>
-
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_X11XWDFileHeader)
-{
- static Handle(Standard_Type) _atype =
- new Standard_Type ("AlienImage_X11XWDFileHeader", sizeof (AlienImage_X11XWDFileHeader));
- return _atype;
-}
-
-Standard_Boolean operator == (
- const AlienImage_X11XWDFileHeader& AnObject,
- const AlienImage_X11XWDFileHeader& AnotherObject)
-
-{ Standard_Boolean _result = Standard_True;
-
- _result = _result && (AnObject.header_size==
- AnotherObject.header_size) ;
- _result = _result && (AnObject.file_version==
- AnotherObject.file_version) ;
- _result = _result && (AnObject.pixmap_format==
- AnotherObject.pixmap_format) ;
- _result = _result && (AnObject.pixmap_depth==
- AnotherObject.pixmap_depth) ;
- _result = _result && (AnObject.pixmap_width==
- AnotherObject.pixmap_width) ;
- _result = _result && (AnObject.pixmap_height==
- AnotherObject.pixmap_height) ;
- _result = _result && (AnObject.xoffset==
- AnotherObject.xoffset) ;
- _result = _result && (AnObject.byte_order==
- AnotherObject.byte_order) ;
- _result = _result && (AnObject.bitmap_unit==
- AnotherObject.bitmap_unit) ;
- _result = _result && (AnObject.bitmap_bit_order==
- AnotherObject.bitmap_bit_order) ;
- _result = _result && (AnObject.bitmap_pad==
- AnotherObject.bitmap_pad) ;
- _result = _result && (AnObject.bits_per_pixel==
- AnotherObject.bits_per_pixel) ;
- _result = _result && (AnObject.bytes_per_line==
- AnotherObject.bytes_per_line) ;
- _result = _result && (AnObject.visual_class==
- AnotherObject.visual_class) ;
- _result = _result && (AnObject.red_mask==
- AnotherObject.red_mask) ;
- _result = _result && (AnObject.green_mask==
- AnotherObject.green_mask) ;
- _result = _result && (AnObject.blue_mask==
- AnotherObject.blue_mask) ;
- _result = _result && (AnObject.bits_per_rgb==
- AnotherObject.bits_per_rgb) ;
- _result = _result && (AnObject.colormap_entries==
- AnotherObject.colormap_entries) ;
- _result = _result && (AnObject.ncolors==
- AnotherObject.ncolors) ;
- _result = _result && (AnObject.window_width==
- AnotherObject.window_width) ;
- _result = _result && (AnObject.window_height==
- AnotherObject.window_height) ;
- _result = _result && (AnObject.window_x==
- AnotherObject.window_x) ;
- _result = _result && (AnObject.window_y==
- AnotherObject.window_y) ;
- _result = _result && (AnObject.window_bdrwidth==
- AnotherObject.window_bdrwidth) ;
-
- return _result;
-}
-
-//============================================================================
-//==== ShallowDump : Writes a CString value.
-//============================================================================
-void ShallowDump (
- const AlienImage_X11XWDFileHeader& AnObject,Standard_OStream& s) {
- s << "AlienImage_X11XWDFileHeader" << "\n";
- s << "\theader_size\t:" << AnObject.header_size << "\n" ;
- s << "\tfile_version\t:" << AnObject.file_version << "\n" ;
- s << "\tpixmap_format\t:" ; switch( AnObject.pixmap_format ) {
- case XYBitmap :
- s << "XYBitmap" ; break ;
- case XYPixmap :
- s << "XYPixmap" ; break ;
- case ZPixmap :
- s << "ZPixmap" ; break ;
- default :
- s << AnObject.pixmap_format ; break ;
- } ; s << "\n" ;
- s << "\tpixmap_depth\t:" << AnObject.pixmap_depth << "\n" ;
- s << "\tpixmap_width\t:" << AnObject.pixmap_width << "\n" ;
- s << "\tpixmap_height\t:" << AnObject.pixmap_height << "\n" ;
- s << "\txoffset\t:" << AnObject.xoffset << "\n" ;
- s << "\tbyte_order\t:" ;
- if ( AnObject.byte_order == LSBFirst ) s << "LSBFirst" ;
- else s << "MSBFirst" ;
- s << "\n" ;
- s << "\tbitmap_unit\t:" << AnObject.bitmap_unit << "\n" ;
- s << "\tbitmap_bit_order\t:" ;
- if ( AnObject.bitmap_bit_order == LSBFirst ) s << "LSBFirst" ;
- else s << "MSBFirst" ;
- s << "\n" ;
- s << "\tbitmap_pad\t:" << AnObject.bitmap_pad << "\n" ;
- s << "\tbits_per_pixel\t:" << AnObject.bits_per_pixel << "\n" ;
- s << "\tbytes_per_line\t:" << AnObject.bytes_per_line << "\n" ;
- s << "\tvisual_class\t:" ; switch( AnObject.visual_class ) {
- case StaticGray : s << "StaticGray" ; break ;
- case GrayScale : s << "GrayScale" ; break ;
- case StaticColor : s << "StaticColor" ; break ;
- case PseudoColor : s << "PseudoColor" ; break ;
- case TrueColor : s << "TrueColor" ; break ;
- case DirectColor : s << "DirectColor" ; break ;
- default : s << AnObject.visual_class ; break ;
- } ; s << "\n" ;
- s << "\tred_mask\t:" << AnObject.red_mask << "\n" ;
- s << "\tgreen_mask\t:" << AnObject.green_mask << "\n" ;
- s << "\tblue_mask\t:" << AnObject.blue_mask << "\n" ;
- s << "\tbits_per_rgb\t:" << AnObject.bits_per_rgb << "\n" ;
- s << "\tcolormap_entries\t:" << AnObject.colormap_entries << "\n" ;
- s << "\tncolors\t:" << AnObject.ncolors << "\n" ;
- s << "\twindow_width\t:" << AnObject.window_width << "\n" ;
- s << "\twindow_height\t:" << AnObject.window_height << "\n" ;
- s << "\twindow_x\t:" << AnObject.window_x << "\n" ;
- s << "\twindow_y\t:" << AnObject.window_y << "\n" ;
- s << "\twindow_bdrwidth\t:" << AnObject.window_bdrwidth << "\n" << flush ;
-}
-
-ostream& operator << ( ostream& s, const AlienImage_X11XWDFileHeader& h )
-
-{ ::ShallowDump( h, s ) ;
- return( s ) ;
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== Titre: AlienImage_X11XWDFileHeader.hxx
-//==== Role : The header file of primitve type "XWDFileHeader" from package //==== "X11"
-//====
-//==== Implementation: This is a primitive type implemented with typedef
-//==== typedef XColor AlienImage_X11XWDFileHeader;
-//============================================================================
-
-#ifndef _AlienImage_X11XWDFileHeader_HeaderFile
-#define _AlienImage_X11XWDFileHeader_HeaderFile
-
-/*
- * Data structure used by color operations from <X11/XWDFile.h>
- */
-//==== Definition de Type ====================================================
-
-#include <Standard_Type.hxx>
-const Handle(Standard_Type)& STANDARD_TYPE(AlienImage_X11XWDFileHeader);
-//============================================================================
-
-#include <Aspect_XWD.hxx>
-
-typedef XWDFileHeader AlienImage_X11XWDFileHeader ;
-
-ostream& operator << ( ostream& s, const AlienImage_X11XWDFileHeader& h );
-
-Standard_Boolean operator==(const AlienImage_X11XWDFileHeader& AnObject,
- const AlienImage_X11XWDFileHeader& AnotherObject);
-void ShallowDump (const AlienImage_X11XWDFileHeader& AnObject,Standard_OStream& S) ;
-#endif
-
+++ /dev/null
--- Created on: 1993-03-23
--- Created by: BBL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-class XAlienImage from AlienImage inherits AlienUserImage from AlienImage
-
- ---Purpose: Defines an X11 Alien image, i.e. an image file to be
- -- used with X11 xwd utility.
-
-uses
- File from OSD,
- AsciiString from TCollection,
- ColorImage from Image,
- PseudoColorImage from Image,
- Image from Image,
- X11XWDAlienData from AlienImage
-
-is
- Create returns mutable XAlienImage from AlienImage;
- ---Purpose: Constructs an empty X11 alien image.
- Clear( me : in out mutable) ;
- ---Level: Public
- ---Purpose: Frees memory allocated by XAlienImage
- ---C++: alias ~
-
- SetName( me : in out mutable;
- aName : in AsciiString from TCollection) ;
- ---Purpose: Sets the Image name for the Name function.
-
- Name( me : in immutable ) returns AsciiString from TCollection ;
- ---C++: return const &
- ---Purpose: Returns the Image name.
-
- ToImage( me : in immutable )
- returns mutable Image from Image ;
- ---Level: Public
- ---Purpose : Converts an XAlienImage object to a Image object.
-
- FromImage( me : in out mutable ; anImage : in Image from Image ) ;
- ---Level: Public
- ---Purpose : Converts an Image object to a XAlienImage object.
-
- Read ( me : in out mutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Reads the content of a XAlienImage object from a file .
- -- Returns True if file is a XWD file .
-
- Write( me : in immutable; afile : in out File from OSD )
- returns Boolean from Standard ;
- ---Level: Public
- ---Purpose: Writes the content of a XAlienImage object to a file .
-
-fields
- myData : X11XWDAlienData from AlienImage;
-
-end ;
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include <AlienImage_XAlienImage.ixx>
-
-AlienImage_XAlienImage::AlienImage_XAlienImage()
-
-{ // il faut faire un new si mydata est du type HANDLE
- myData = new AlienImage_X11XWDAlienData() ;
-}
-
-void AlienImage_XAlienImage::SetName( const TCollection_AsciiString& aName)
-
-{ myData->SetName( aName ) ; }
-
-const TCollection_AsciiString& AlienImage_XAlienImage::Name() const
-{ return( myData->Name() ) ; }
-
-void AlienImage_XAlienImage::Clear()
-
-{ myData->Clear() ; }
-
-Standard_Boolean AlienImage_XAlienImage::Write( OSD_File& file ) const
-
-{ return( myData->Write( file ) ) ; }
-
-Standard_Boolean AlienImage_XAlienImage::Read( OSD_File& file )
-
-{ return( myData->Read( file ) ) ; }
-
-Handle_Image_Image AlienImage_XAlienImage::ToImage() const
-
-{ return( myData->ToImage() ) ; }
-
-void AlienImage_XAlienImage::FromImage( const Handle_Image_Image& anImage )
-
-{ myData->FromImage( anImage ) ; }
-
+++ /dev/null
-AlienImage_X11XColor.hxx
-AlienImage_X11XColor.cxx
-AlienImage_X11XWDFileHeader.hxx
-AlienImage_X11XWDFileHeader.cxx
-AlienImage_SGIRGBFileHeader.hxx
-AlienImage_SGIRGBFileHeader.cxx
-AlienImage_SUNRFFileHeader.hxx
-AlienImage_SUNRFFileHeader.cxx
-AlienImage_GIFLZWDict.hxx
-AlienImage_GIFLZWDict.cxx
-AlienImage_BMPHeader.hxx
-AlienImage_BMPHeader.cxx
-
MMgt,
WNT,
Image,
- AlienImage,
gp,
Font
is
PlaneAngle from Quantity,
- AlienImage from AlienImage,
PixMap from Image,
Array1OfEdge from Aspect,
EXTERNLIB
-Image_GImage.gxx
-Image_GPixelField.gxx
-Image_GPixelField.lxx
-Image_PixelAddress.cxx
-Image_PixelAddress.hxx
-Image.edl
-Image_CMPLRS.edl
Image_PixMap.hxx
Image_PixMap.cxx
Image_PixMap_Handle.hxx
-- purpose or non-infringement. Please see the License for the specific terms
-- and conditions governing the rights and limitations under the License.
-
package Image
- ---Purpose: The package Image provide PseudoColorImage and ColorImage
- -- definition and a set of key functions from the fields
- -- of image.
+ ---Purpose: The package Image provides image manipulation classes.
uses
- TCollection,
- TColStd,
- Aspect,
- Quantity,
- gp,
- MMgt
+ 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 );
-
- -----------------------------
- ---Category: Imported types:
- -----------------------------
-
- imported PixelAddress;
- imported PixMap;
- imported AlienPixMap;
- imported PixMap_Handle;
- imported AlienPixMap_Handle;
- imported Diff;
-
- -----------------------------
- ---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
- 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.
+ -----------------------------
+ ---Category: Imported types:
+ -----------------------------
- 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.
+ imported PixMap;
+ imported AlienPixMap;
+ imported PixMap_Handle;
+ imported AlienPixMap_Handle;
+ imported Diff;
end Image;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-// 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 ) ;
- }
-}
+++ /dev/null
--- Created on: 1996-10-03
--- Created by: Jean GAUTIER
--- Copyright (c) 1996-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-@ifnotdefined ( %Image_EDL) then
- @set %Image_EDL = "";
-@endif;
#define _Image_AlienPixMap_H__
#include <Image_PixMap.hxx>
-#include <Image_TypeOfImage.hxx>
class TCollection_AsciiString;
struct FIBITMAP;
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-/***********************************************************************
-
- 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 ;
- }
-}
-
+++ /dev/null
--- Created on: 1996-10-03
--- Created by: Jean GAUTIER
--- Copyright (c) 1996-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-@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;
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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
+++ /dev/null
--- Created on: 1993-07-28
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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 ) ;
-
-}
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#include anyPixel_hxx
-#include <Image_FlipType.hxx>
-#include <gp_Dir.hxx>
-#include <gp_Pln.hxx>
-
-#ifdef TRACE
-static int Verbose = 0 ;
-#endif
-
-#define MYPIXELFIELD ((Image_PixelField *)myPixelField)
-
-Image_GImage::Image_GImage ( const Standard_Integer x,
- const Standard_Integer y,
- const Standard_Integer dx,
- const Standard_Integer dy,
- const anyPixel& Back)
- : Image_Image( STANDARD_TYPE(Aspect_Pixel) )
-{
- myX = x ; myY = y ;
-
- myBackgroundPixel = Back ;
-
- myPixelField = ( Standard_Address ) new Image_PixelField( dx, dy, Back ) ;
-
-}
-
-void Image_GImage::PixelFieldDestroy()
-
-{ if ( myPixelField ) {
- MYPIXELFIELD->Destroy() ;
-
- myPixelField = NULL ;
- }
-}
-
-void Image_GImage::Destroy()
-{
-#ifdef TRACE
- cout << "Image_GImage::Destroy()\n" ;
-#endif
- Image_Image::Destroy() ;
- PixelFieldDestroy() ;
-}
-
-Standard_Boolean Image_GImage::isSamePixel(
- const Standard_Integer X,
- const Standard_Integer Y,
- const Handle(Image_Image)& anotherImage,
- const Standard_Integer anotherX,
- const Standard_Integer anotherY ) const
-{ Handle(Image_GImage) aImage =
- Handle(Image_GImage)::DownCast( anotherImage ) ;
-
- return ( Pixel( X,Y ) == aImage->Pixel( anotherX,anotherY ) ) ;
-}
-
-const Image_PixelField& Image_GImage::PixelField() const
-
-{
- return ( *((Image_PixelField *)myPixelField) ) ;
-}
-
-Standard_Integer Image_GImage::Height() const {
-
- return ( MYPIXELFIELD->Height() ) ;
-
-}
-
-Standard_Integer Image_GImage::Width() const {
-
- return ( MYPIXELFIELD->Width() ) ;
-
-}
-
-Standard_Integer Image_GImage::LowerX() const {
-
- return ( myX ) ;
-
-}
-
-Standard_Integer Image_GImage::LowerY() const {
-
- return ( myY ) ;
-
-}
-
-Standard_Integer Image_GImage::UpperX() const {
-
- return ( myX+Width()-1 ) ;
-
-}
-
-Standard_Integer Image_GImage::UpperY() const {
-
- return ( myY+Height()-1 ) ;
-
-}
-
-void Image_GImage::Clear () {
- Standard_Integer x,y ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- for ( y = LowerY() ; y <= UpY ; y++ ) {
- for ( x = LowerX() ; x <= UpX ; x++ ) {
- SetPixel( x, y , myBackgroundPixel ) ;
- }
- }
-
-}
-
-void Image_GImage::SetOrigin (const Standard_Integer X,
- const Standard_Integer Y ) {
- myX = X ; myY = Y ;
-}
-
-void Image_GImage::Row( const Standard_Integer X,
- const Standard_Integer Y,
- Image_PixelRow& PR) const {
-
- Standard_Integer TheLength = Min (PR.Length(), UpperX()-X+1);
- Standard_Integer L = PR.Lower() ;
-
- for (Standard_Integer i=0; i< TheLength; i++) {
- PR(L+i) = Pixel(X+i,Y);
- }
-
-}
-
-void Image_GImage::SetRow( const Standard_Integer X,
- const Standard_Integer Y,
- const Image_PixelRow& PR) {
-
- Standard_Integer TheLength = Min (PR.Length(), UpperX()-X+1);
- Standard_Integer L = PR.Lower() ;
-
- for (Standard_Integer i=0; i< TheLength; i++) {
- MutPixel(X+i,Y) = PR(L+i) ;
- }
-
-}
-
-void Image_GImage::Dump() const
-
-{ Standard_Integer x, y ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
-
- cout << "Image Origin :" << myX << "," << myY << endl ;
- cout << "Back Pixel :" << myBackgroundPixel << endl ;
- cout << "Pixel Field :" << endl ;
-
- for ( y = LowerY() ; y <= UpY ; y++ ) {
- for ( x = LowerX() ; x <= UpX ; x++ ) {
- cout << Pixel(x,y) << " " ;
- }
- cout << "\n" << flush ;
- }
-}
-
-void Image_GImage::SwapRow (const Standard_Integer I,
- const Standard_Integer J)
-
-{ anyPixel P ;
- Standard_Integer Up = UpperX() ;
-
- for (Standard_Integer i = LowerX(); i <= Up; i++) {
- P = Pixel(i,I);
- MutPixel(i,I) = Pixel(i,J);
- MutPixel(i,J) = P;
- }
-}
-
-void Image_GImage::SwapCol (const Standard_Integer I,
- const Standard_Integer J)
-
-{ anyPixel P ;
- Standard_Integer Up = UpperY() ;
-
- for (Standard_Integer i = LowerY(); i <= Up; i ++) {
- P = Pixel(I,i);
- MutPixel(I,i) = Pixel(J,i);
- MutPixel(J,i) = P;
- }
-}
-
-
-void Image_GImage::Rotate90()
-
-{ Standard_Integer x,y ;
- Standard_Integer UpY = MYPIXELFIELD->UpperY() ;
- Standard_Integer UpX = MYPIXELFIELD->UpperX() ;
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Height(),
- MYPIXELFIELD->Width(),
- myBackgroundPixel ) ;
-
- for ( y = 0 ; y <= UpY ; y++ )
- for ( x = 0 ; x <= UpX ; x++ )
- NewPixelField->SetValue( UpY-y , x ,MYPIXELFIELD->Value( x , y ) );
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
-}
-
-void Image_GImage::FlipMainDiagonal()
-
-{ Standard_Integer x,y ;
- Standard_Integer UpY = MYPIXELFIELD->UpperY() ;
- Standard_Integer UpX = MYPIXELFIELD->UpperX() ;
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Height(),
- MYPIXELFIELD->Width(),
- myBackgroundPixel ) ;
-
- for ( y = 0 ; y <= UpY ; y++ )
- for ( x = 0 ; x <= UpX ; x++ )
- NewPixelField->SetValue( y , x , MYPIXELFIELD->Value( x , y ) );
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
-}
-
-void Image_GImage::Rotate270()
-
-{ Standard_Integer x,y ;
- Standard_Integer UpY = MYPIXELFIELD->UpperY() ;
- Standard_Integer UpX = MYPIXELFIELD->UpperX() ;
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Height(),
- MYPIXELFIELD->Width(),
- myBackgroundPixel ) ;
-
- for ( y = 0 ; y <= UpY ; y++ )
- for ( x = 0 ; x <= UpX ; x++ )
- NewPixelField->SetValue( y , UpX-x ,MYPIXELFIELD->Value( x,y ));
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
-}
-
-void Image_GImage::FlipAntiDiagonal()
-
-{ Standard_Integer x,y ;
- Standard_Integer Height = MYPIXELFIELD->Height() ;
- Standard_Integer Width = MYPIXELFIELD->Width() ;
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Height(),
- MYPIXELFIELD->Width(),
- myBackgroundPixel ) ;
-
- Standard_Integer NewUpY = NewPixelField->UpperY() ;
- Standard_Integer NewUpX = NewPixelField->UpperX() ;
-
- for ( y = 0 ; y < Height ; y++ )
- for ( x = 0 ; x < Width ; x++ )
- NewPixelField->SetValue( NewUpX-y, NewUpY-x,
- MYPIXELFIELD->Value( x,y ) ) ;
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
-}
-
-void Image_GImage::Rotate180()
-
-{ anyPixel P ;
- Standard_Integer x, y, HalfX, HalfY, W ;
-
- HalfX = Width() / 2 ;
- HalfY = Height() / 2 ;
- W = Width() ;
-
- for ( y = 0 ; y < HalfY ; y++ ){
- for ( x = 0 ; x < W ; x++ ) {
- P =Pixel( LowerX()+x , LowerY()+y);
- MutPixel( LowerX()+x , LowerY()+y )=Pixel( UpperX()-x , UpperY()-y);
- MutPixel( UpperX()-x , UpperY()-y )=P ;
- }
- }
-
- if ( Height() % 2 ) {
- // Swap Half of the center ROW
- for ( x = 0 , y = HalfY ; x <= HalfX ; x++ ) {
- P =Pixel( LowerX()+x , LowerY()+y);
- MutPixel( LowerX()+x , LowerY()+y )=Pixel( UpperX()-x , LowerY()+y);
- MutPixel( UpperX()-x , LowerY()+y )= P ;
- }
- }
-}
-
-void Image_GImage::FlipHorizontal()
-
-{ anyPixel P ;
- Standard_Integer x, y, HalfX, HalfY ;
- Standard_Integer UpX = UpperX() ;
-
- HalfX = Width() / 2 ;
- HalfY = Height() / 2 ;
-
- for ( x = LowerX() ; x <= UpX ; x++ ){
- for ( y = 0 ; y < HalfY ; y++ ) {
- P = Pixel( x , LowerY()+y ) ;
- MutPixel( x , LowerY()+y ) = Pixel( x , UpperY()-y ) ;
- MutPixel( x , UpperY()-y ) = P ;
- }
- }
-}
-
-void Image_GImage::FlipVertical()
-
-{ anyPixel P ;
- Standard_Integer x, y, HalfX, HalfY ;
- Standard_Integer UpY = UpperY() ;
-
- HalfX = Width() / 2 ;
- HalfY = Height() / 2 ;
-
- for ( y = LowerY() ; y <= UpY ; y++ ){
- for ( x = 0 ; x < HalfX ; x++ ) {
- P = Pixel( LowerX()+x , y ) ;
- MutPixel( LowerX()+x , y ) = Pixel( UpperX()-x , y ) ;
- MutPixel( UpperX()-x , y ) = P ;
- }
- }
-}
-
-void Image_GImage::Transpose(const Image_FlipType aType)
-
-{ switch (aType) {
- case Image_FT_VERTICAL:
- FlipVertical() ;
- break;
- case Image_FT_HORIZONTAL:
- FlipHorizontal() ;
- break;
- case Image_FT_MAINDIAGONAL:
- FlipMainDiagonal() ;
- break;
- case Image_FT_ANTIDIAGONAL:
- FlipAntiDiagonal() ;
- break;
- case Image_FT_CENTER:
- case Image_FT_180:
- Rotate180() ;
- break;
- case Image_FT_90:
- Rotate90() ;
- break;
- case Image_FT_270:
- Rotate270() ;
- break;
- default :
- cout << "Unknown ImageFlipType\n" ;
- }
-}
-
-void Image_GImage::PixelFieldCopyTo( Image_PixelField& Dst,
- const Standard_Integer Lowx ,
- const Standard_Integer Lowy ,
- const Standard_Integer Upx ,
- const Standard_Integer Upy ,
- const Standard_Integer DstLowx ,
- const Standard_Integer DstLowy ) const
-
-{ Standard_Integer x,y,nx,ny ;
-
- if ( Lowy < DstLowy ) {
- if ( Lowx < DstLowx ) {
- y = Lowy ; ny = DstLowy ;
-
- while( y <= Upy ) {
- x = Lowx ; nx = DstLowx ;
- while( x <= Upx ) {
-#ifdef TRACE
- if ( Verbose ) {
- cout << "PixelFieldCopy( (" << x << "," << y << "," <<
- MYPIXELFIELD->Value( x , y ) <<
- ") to (" << nx << "," << ny << ")" << endl << flush ;
- }
-#endif
- Dst.SetValue( nx, ny ,MYPIXELFIELD->Value( x , y ) );
- x++ ; nx++ ;
- }
- y++ ; ny++ ;
- }
- }
- else {
- y = Lowy ; ny = DstLowy ;
-
- while( y <= Upy ) {
- x = Upx ; nx = DstLowx + ( Upx - Lowx ) ;
- while( x >= Lowx ) {
-#ifdef TRACE
- if ( Verbose ) {
- cout << "PixelFieldCopy( (" << x << "," << y << "," <<
- MYPIXELFIELD->Value( x , y ) <<
- ") to (" << nx << "," << ny << ")" << endl << flush ;
- }
-#endif
- Dst.SetValue( nx, ny ,MYPIXELFIELD->Value( x , y ) );
- x-- ; nx-- ;
- }
- y++ ; ny++ ;
- }
- }
- }
- else {
- if ( Lowx < DstLowx ) {
- y = Upy ; ny = DstLowy + ( Upy - Lowy ) ;
-
- while( y >= Lowy ) {
- x = Lowx ; nx = DstLowx ;
- while( x <= Upx ) {
-#ifdef TRACE
- if ( Verbose ) {
- cout << "PixelFieldCopy( (" << x << "," << y << "," <<
- MYPIXELFIELD->Value( x , y ) <<
- ") to (" << nx << "," << ny << ")" << endl << flush ;
- }
-#endif
- Dst.SetValue( nx, ny ,MYPIXELFIELD->Value( x , y ) );
- x++ ; nx++ ;
- }
- y-- ; ny-- ;
- }
- }
- else {
- y = Upy ; ny = DstLowy + ( Upy - Lowy ) ;
-
- while( y >= Lowy ) {
- x = Upx ; nx = DstLowx + ( Upx - Lowx ) ;
- while( x >= Lowx ) {
-#ifdef TRACE
- if ( Verbose ) {
- cout << "PixelFieldCopy( (" << x << "," << y << "," <<
- MYPIXELFIELD->Value( x , y ) <<
- ") to (" << nx << "," << ny << ")" << endl << flush ;
- }
-#endif
- Dst.SetValue( nx, ny ,MYPIXELFIELD->Value( x , y ) );
- x-- ; nx-- ;
- }
- y-- ; ny-- ;
- }
- }
- }
-}
-
-void Image_GImage::PixelFieldCopyFrom(const Image_PixelField& Src,
- const Standard_Integer Lowx ,
- const Standard_Integer Lowy ,
- const Standard_Integer Upx ,
- const Standard_Integer Upy ,
- const Standard_Integer DstLowx ,
- const Standard_Integer DstLowy )
-
-{ Standard_Integer x,y,nx,ny ;
-
- if ( Lowy < DstLowy ) {
- if ( Lowx < DstLowx ) {
- y = Lowy ; ny = DstLowy ;
-
- while( y <= Upy ) {
- x = Lowx ; nx = DstLowx ;
- while( x <= Upx ) {
- MYPIXELFIELD->SetValue( nx, ny ,Src.Value( x , y ) );
- x++ ; nx++ ;
- }
- y++ ; ny++ ;
- }
- }
- else {
- y = Lowy ; ny = DstLowy ;
-
- while( y <= Upy ) {
- x = Upx ; nx = DstLowx + ( Upx - Lowx ) ;
- while( x >= Lowx ) {
- MYPIXELFIELD->SetValue( nx, ny ,Src.Value( x , y ) );
- x-- ; nx-- ;
- }
- y++ ; ny++ ;
- }
- }
- }
- else {
- if ( Lowx < DstLowx ) {
- y = Upy ; ny = DstLowy + ( Upy - Lowy ) ;
-
- while( y >= Lowy ) {
- x = Lowx ; nx = DstLowx ;
- while( x <= Upx ) {
- MYPIXELFIELD->SetValue( nx, ny ,Src.Value( x , y ) );
- x++ ; nx++ ;
- }
- y-- ; ny-- ;
- }
- }
- else {
- y = Upy ; ny = DstLowy + ( Upy - Lowy ) ;
-
- while( y >= Lowy ) {
- x = Upx ; nx = DstLowx + ( Upx - Lowx ) ;
- while( x >= Lowx ) {
- MYPIXELFIELD->SetValue( nx, ny ,Src.Value( x , y ) );
- x-- ; nx-- ;
- }
- y-- ; ny-- ;
- }
- }
- }
-}
-
-
-void Image_GImage::Shift(const Standard_Integer XShift,
- const Standard_Integer YShift )
-{ Standard_Integer x, y, nx, ny, Upy, Upx ;
- Standard_Integer LowX, LowY, UpX, UpY ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Width(),
- MYPIXELFIELD->Height(),
- myBackgroundPixel) ;
-
- LowX = Max( LowerX(), LowerX()-XShift ) ;
- UpX = Min( UpperX(), LowX+Width()-Abs(XShift)-1 ) ;
-
- LowY = Max( LowerY(), LowerY()-YShift ) ;
- UpY = Min( UpperY(), LowY+Height()-Abs(YShift)-1 ) ;
-
- y = ( LowY - myY ) ;
- Upy = ( UpY - myY ) ;
- ny = y + YShift ;
-
- x = ( LowX - myX ) ;
- Upx = ( UpX - myX ) ;
- nx = x + XShift ;
-
- if ( LowX <= UpX && LowY <= UpY ) {
- PixelFieldCopyTo( *NewPixelField, x,y ,Upx,Upy, nx,ny ) ;
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-}
-
-void Image_GImage::Fill(const Handle(Image_Image)& aImage )
-
-{ Standard_Integer x, y, nx, ny, Upx, Upy ;
- Standard_Integer LowX, LowY, UpX, UpY ;
- Handle(Image_GImage) SrcImage = Handle(Image_GImage)::DownCast( aImage ) ;
-
- LowX = Max( LowerX(), SrcImage->LowerX() ) ;
- UpX = Min( UpperX(), SrcImage->UpperX() ) ;
-
- LowY = Max( LowerY(), SrcImage->LowerY() ) ;
- UpY = Min( UpperY(), SrcImage->UpperY() ) ;
-
- y = ( LowY - SrcImage->LowerY() ) ;
- Upy = ( UpY - SrcImage->LowerY() ) ;
- ny = ( LowY - LowerY() ) ;
-
- x = ( LowX - SrcImage->LowerX() ) ;
- Upx = ( UpX - SrcImage->LowerX() ) ;
- nx = ( LowX - LowerX() ) ;
-
- if ( LowX <= UpX && LowY <= UpY ) {
- PixelFieldCopyFrom( SrcImage->PixelField(), x,y, Upx,Upy, nx,ny ) ;
- }
-}
-
-void Image_GImage::Fill(const Handle(Image_Image)& aImage ,
- const Standard_Integer SrcX ,
- const Standard_Integer SrcY,
- const Standard_Integer SrcWidth,
- const Standard_Integer SrcHeight,
- const Standard_Integer DstX,
- const Standard_Integer DstY )
-{ Standard_Integer x, y, nx, ny, Upx, Upy ;
- Standard_Integer LowX, LowY, UpX, UpY ;
- Standard_Integer nLowX, nLowY, nUpX, nUpY ;
- Handle(Image_GImage) SrcImage = Handle(Image_GImage)::DownCast( aImage ) ;
-
- // Clipped PixelField in SrcImage
- LowX = Max( SrcX, SrcImage->LowerX() ) ;
- UpX = Min( SrcImage->UpperX(), SrcX+SrcWidth-1 ) ;
-
- LowY = Max( SrcY, SrcImage->LowerY() ) ;
- UpY = Min( SrcImage->UpperY(), SrcY+SrcHeight-1 ) ;
-
- // UnClipped PixelField in DstImage from Clipped PixelField of SrcImage
- nLowX = DstX ;
- nUpX = DstX+(UpX-LowX)+1 ;
-
- nLowY = DstY ;
- nUpY = DstY+(UpY-LowY)+1 ;
-
- // Clipped PixelField in DstImage and recompute Clipped PixelField in SrcImage
- if ( nLowX > UpperX() ) {
- return ;
- }
- else if ( nLowX < LowerX() ) {
- LowX += ( LowerX()-nLowX ) ;
- nLowX = LowerX() ;
- }
-
- if ( nLowY > UpperY() ) {
- return ;
- }
- else if ( nLowY < LowerY() ) {
- LowY += ( LowerY()-nLowY ) ;
- nLowY = LowerY() ;
- }
-
- if ( nUpX < LowerX() ) {
- return ;
- }
- else if ( nUpX > UpperX() ) {
- UpX -= ( nUpX - UpperX() ) ;
- nUpX = UpperX() ;
- }
-
- if ( nUpY < LowerY() ) {
- return ;
- }
- else if ( nUpY > UpperY() ) {
- UpY -= ( nUpY - UpperY() ) ;
- nUpY = UpperY() ;
- }
-
- // Translate to PixelField Coordinate
-
- y = ( LowY - SrcImage->LowerY() ) ;
- Upy = ( UpY - SrcImage->LowerY() ) ;
-
- x = ( LowX - SrcImage->LowerX() ) ;
- Upx = ( UpX - SrcImage->LowerX() ) ;
-
- ny = ( nLowY - LowerY() ) ;
- nx = ( nLowX - LowerX() ) ;
-
- if ( LowX <= UpX && LowY <= UpY ) {
- PixelFieldCopyFrom( SrcImage->PixelField(), x,y, Upx,Upy, nx,ny ) ;
- }
-}
-
-void Image_GImage::FillRect(const anyPixel& aPixel ,
- const Standard_Integer SrcX ,
- const Standard_Integer SrcY,
- const Standard_Integer SrcWidth,
- const Standard_Integer SrcHeight )
-{ Standard_Integer ux, lx, uy, ly, x, y ;
- Standard_Integer LowX, LowY, UpX, UpY ;
-
- LowX = Max( SrcX, LowerX() ) ;
- UpX = Min( UpperX(), SrcX+SrcWidth-1 ) ;
-
- LowY = Max( SrcY, LowerY() ) ;
- UpY = Min( UpperY(), SrcY+SrcHeight-1 ) ;
-
- ly = ( LowY - myY ) ;
- uy = ( UpY - myY ) ;
-
- lx = ( LowX - myX ) ;
- ux = ( UpX - myX ) ;
-
- if ( LowX <= UpX && LowY <= UpY ) {
-
- for ( y = ly ; y <= uy ; y++ ) {
- for ( x = lx ; x <= ux ; x++ ) {
- MYPIXELFIELD->SetValue( x, y, aPixel ) ;
- }
- }
- }
-}
-
-static int w_compute_clip(
- Standard_Integer LowX,
- Standard_Integer LowY,
- Standard_Integer UpX,
- Standard_Integer UpY ,
- Standard_Integer *x1,
- Standard_Integer *y1,
- Standard_Integer *x2,
- Standard_Integer *y2)
-
-{ Standard_Integer *c,c1,c2 ;
- Standard_Integer *x,*y;
- register Standard_Integer flag = 0 ;
-#ifdef TRACE
-Standard_Integer Tclip = 0 ;
-#endif
-
- if ( *x1 < LowX ) c1 = 1 ;
- else if( *x1 > UpX ) c1 = 2 ;
- else c1 = 0;
-
- if ( *y1 < LowY ) c1 = c1 | 4 ;
- else if( *y1 > UpY ) c1 = c1 | 8 ;
-
- if ( *x2 < LowX ) c2 = 1 ;
- else if( *x2 > UpX ) c2 = 2 ;
- else c2 = 0;
-
- if ( *y2 < LowY ) c2 = c2 | 4 ;
- else if( *y2 > UpY ) c2 = c2 | 8 ;
-
- flag = 0;
- if ( c1 ) flag = 1 ;
- if ( c2 ) flag = flag | 2;
-
-#ifdef TRACE
- if ( Tclip )
- printf("w_clip( %d,%d %d,%d 0x%2x,0x%2x)\n", *x1,*y1,*x2,*y2,c1,c2);
-#endif
-
- while ( c1 || c2 ) {
- flag ++ ;
- if ( c1 & c2 ) return (-1); /* Les 2 points sont du meme cote */
-
- if ( c1 ) {
- c = &c1 ;
- x = x1 ;
- y = y1 ;
- }
- else {
- c = &c2 ;
- x = x2 ;
- y = y2 ;
- }
-
- if ( *c & 1 ){
- *y = *y1 + Standard_Integer(
- (float)(*y2)*(0-*x1)/(float)(*x2-*x1) -
- (float)(*y1)*(0-*x1)/(float)(*x2-*x1) ) ;
- *x = 0 ;
-#ifdef TRACE
- if ( Tclip )
- printf("clip left x,y,c %d %d %x\n",*x,*y,*c);
-#endif
- }
- else if ( *c & 2 ){
- *y = *y1 + Standard_Integer(
- (float)(*y2)*(UpX-*x1)/(float)(*x2-*x1) -
- (float)(*y1)*(UpX-*x1)/(float)(*x2-*x1) ) ;
- *x = UpX ;
-#ifdef TRACE
- if ( Tclip )
- printf("clip right x,y,c %d %d %x\n",*x,*y,*c);
-#endif
- }
- else if ( *c & 4 ) {
- *x = *x1 + Standard_Integer(
- (float)(*x2)*(0-*y1)/(float)(*y2-*y1) -
- (float)(*x1)*(0-*y1)/(float)(*y2-*y1) ) ;
- *y = 0 ;
-#ifdef TRACE
- if ( Tclip )
- printf("clip bottom x,y,c %d %d %x\n",*x,*y,*c);
-#endif
- }
- else if ( *c & 8 ) {
- *x = *x1 + Standard_Integer(
- (float)(*x2)*(UpY-*y1)/(float)(*y2-*y1) -
- (float)(*x1)*(UpY-*y1)/(float)(*y2-*y1) ) ;
- *y = UpY ;
-#ifdef TRACE
- if ( Tclip )
- printf("clip top x,y,c %d %d %x\n",*x,*y,*c);
-#endif
- }
-
- if ( *x < 0 ) *c = 1 ;
- else if( *x > UpX ) *c = 2 ;
- else *c = 0 ;
-
- if ( *y < 0 ) *c = *c | 4 ;
- else if( *y > UpY ) *c = *c | 8 ;
-
-#ifdef TRACE
- if ( Tclip ) {
- printf("recomputed code,c1,c2 %x %x,%x\n ",*c,c1,c2);
- }
-#endif
-
- }
-
- return (flag);
-}
-
-void Image_GImage::DrawLine(const anyPixel& aPixel ,
- const Standard_Integer X1 ,
- const Standard_Integer Y1,
- const Standard_Integer X2,
- const Standard_Integer Y2 )
-{ Standard_Integer x0,y0,x1,y1,x,y,dx,dy,d, incrE, incrNE ;
- Standard_Integer i, tmp ;
- Standard_Real m ;
- Standard_Boolean SwapXY = 0 ;
- Standard_Boolean XAxisMirror = 0 ;
- Standard_Boolean YAxisMirror = 0 ;
- // From : "Computer Graphics , Principles and Practice, Foley & Van Dam"
-
- //Clip
- x0 = X1 ;
- y0 = Y1 ;
- x1 = X2 ;
- y1 = Y2 ;
-
- i = w_compute_clip( LowerX(), LowerY(), UpperX(), UpperY(), &x0,&y0,&x1,&y1 );
-
-#ifdef TRACE
- if ( Verbose )
- cout << form("DrawLine( clip : %d )\n", i ) << flush ;
-#endif
-
- if ( i == -1 ) return ; // Clipped Line
-
- //Draw
- dy = y1 - y0 ;
- dx = x1 - x0 ;
-
- if ( dx == 0 ) {
- // Vertical line
- Standard_Integer inc = ( dy > 0 )? 1 : -1 ;
-
- for ( i = y0 ; i != y1 ; i+= inc ) SetPixel( x0,i, aPixel );
- }
- else if ( dy == 0 ) {
- // Horizontal line
- Standard_Integer inc = ( dx > 0 )? 1 : -1 ;
-
- for ( i = x0 ; i != x1 ; i+= inc ) SetPixel( i, y0, aPixel ) ;
-
- SetPixel( x1,y1, aPixel ) ;
- }
- else if ( Abs(dy) == Abs(dx) ) {
- Standard_Integer incx = ( dx > 0 )? 1 : -1 ;
- Standard_Integer incy = ( dy > 0 )? 1 : -1 ;
-
- for ( x=x0,y=y0 ; x != x1 ; x+=incx , y+=incy ) SetPixel(x,y,aPixel);
-
- SetPixel( x1,y1, aPixel ) ;
- }
- else {
- dy = y1 - y0 ;
- dx = x1 - x0 ;
-
- m = Standard_Real(dy) / Standard_Real(dx) ;
-
-#ifdef TRACE
- if ( Verbose )
- cout << form("DrawLine( m = %.2f )\n", m ) ;
-#endif
- if ( m < -1. || m > 1. ) {
-
- SwapXY = 1 ;
-
- tmp = x0 ; x0 = y0 ; y0 = tmp ;
- tmp = x1 ; x1 = y1 ; y1 = tmp ;
-
- dy = y1 - y0 ;
- dx = x1 - x0 ;
-
- m = Standard_Real(dy) / Standard_Real(dx) ;
- }
-
- if ( m >= -1. && m <= 1. ) {
- if ( ( m > 0. && ( dy < 0 ) ) ||
- ( m < 0. && ( dy > 0 ) ) ) {
- // Draw line from ( x0,y0 ) to ( x0-dx ,y0-dy ) and make
- // a Mirror on X and Y Axis
-
-#ifdef TRACE
- if ( Verbose )
- cout << "DrawLine( X and Y Axis Symetrie )\n" << flush ;
-#endif
-
- YAxisMirror++ ;
-
- x1 = x0 - dx ;
-
- XAxisMirror++ ;
-
- y1 = y0 - dy ;
-
- dy = y1 - y0 ;
- dx = x1 - x0 ;
-
- m = Standard_Real(dy) / Standard_Real(dx) ;
- }
-
- if ( m < 0. ) {
- // Draw line from ( x0,y0 ) to ( x1, y0-dy and make
- // a Mirror on X Axis
-
-#ifdef TRACE
- if ( Verbose )
- cout << "DrawLine( X Axis Symetrie )\n" << flush ;
-#endif
-
- XAxisMirror++ ;
-
- y1 = y0 - dy ;
-
- dy = y1 - y0 ;
- dx = x1 - x0 ;
-
- m = Standard_Real(dy) / Standard_Real(dx) ;
- }
-
- dy = y1 - y0 ;
- dx = x1 - x0 ;
- d = 2 * dy - dx ; // Initial value for d
- incrE = 2 * dy ; // Increment used for move to E
- incrNE = 2 * (dy-dx) ; // Increment used for move to NE
- x = x0 ;
- y = y0 ;
-
- Standard_Integer xp,yp ;
-
- xp = x ;
- yp = y ;
-
- if ( SwapXY ) {
- tmp = xp ; xp = yp ; yp = tmp ;
- }
-
- SetPixel( xp,yp, aPixel ) ; // Start Pixel
-
- while ( x < x1 ) {
- if ( d <= 0 ) {
- d += incrE ; // Choose E
- x += 1 ;
- }
- else {
- d += incrNE ; // Choose NE
- x += 1 ;
- y += 1 ;
- }
-
- xp = (YAxisMirror==1)? (x0 - (x-x0)) : x ;
- yp = (XAxisMirror==1)? (y0 - (y-y0)) : y ;
-
- if ( SwapXY == 1 ) {
- tmp = xp ; xp = yp ; yp = tmp ;
- }
-
- SetPixel( xp,yp, aPixel ) ;
- }
- }
- }
-}
-
-void Image_GImage::CirclePixels( const anyPixel& aPixel ,
- const Standard_Integer X ,
- const Standard_Integer Y,
- const Standard_Integer x,
- const Standard_Integer y,
- const Standard_Integer LowX,
- const Standard_Integer LowY,
- const Standard_Integer UpX,
- const Standard_Integer UpY)
-
-{ Standard_Integer NX, NY ;
-
- NX = X+x , NY = Y+y ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NY = Y-y ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NX = X-x ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NY = Y+y ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- if ( x != y ) {
- NX = X+y , NY = Y+x ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NY = Y-x ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NX = X-y ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
-
- NY = Y+x ;
- if ( NX >= LowX && NX <= UpX && NY >= LowY && NY <= UpY )
- SetPixel( NX, NY,aPixel ) ;
- }
-}
-
-
-#ifdef IMPLEMENTED
-void Image_GImage::DrawCircle(const anyPixel& aPixel ,
- const Standard_Integer X ,
- const Standard_Integer Y,
- const Standard_Integer R )
-{ Standard_Integer x, y, d, deltaE, deltaSE ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- // From : "Computer Graphics , Principles and Practice, Foley & Van Dam"
-
- x = 0 ;
- y = R ;
-
- d = 1 - R ;
-
- deltaE = 3 ;
- deltaSE = -2 * R + 5 ;
-
- CirclePixels ( aPixel, X, Y, x, y, LowX,LowY,UpX,UpY ) ;
-
- while ( y > x ) {
- if ( d < 0 ) { // Select E
- d += deltaE ;
- deltaE += 2 ;
- deltaSE += 2 ;
- x++ ;
- }
- else {
- d += deltaSE ;
- deltaE += 2 ;
- deltaSE += 4 ;
- x++ ;
- y-- ;
- }
- CirclePixels ( aPixel, X, Y, x, y, LowX,LowY,UpX,UpY ) ;
- }
-
-}
-#endif
-
-
-void Image_GImage::DrawRect(const anyPixel& aPixel ,
- const Standard_Integer SrcX ,
- const Standard_Integer SrcY,
- const Standard_Integer SrcWidth,
- const Standard_Integer SrcHeight )
-{ Standard_Integer ux, lx, uy, ly, x, y ;
- Standard_Integer LowX, LowY, UpX, UpY ;
-
- LowX = Max( SrcX, LowerX() ) ;
- UpX = Min( UpperX(), SrcX+SrcWidth-1 ) ;
-
- if ( LowX <= UpX ) {
- lx = ( LowX - myX ) ;
- ux = ( UpX - myX ) ;
- y = SrcY ;
-
- if ( y >= LowerY() && y <= UpperY() ) {
- y -= myY ;
- for ( x = lx ; x <= ux ; x++ ) MYPIXELFIELD->SetValue(x,y,aPixel) ;
- }
-
- y = SrcY + SrcHeight - 1;
-
- if ( y >= LowerY() && y <= UpperY() ) {
- y -= myY ;
- for ( x = lx ; x <= ux ; x++ ) MYPIXELFIELD->SetValue(x,y,aPixel) ;
- }
- }
-
- LowY = Max( SrcY, LowerY() ) ;
- UpY = Min( UpperY(), SrcY+SrcHeight-1 ) ;
-
- if ( LowY <= UpY ) {
- ly = ( LowY - myY ) ;
- uy = ( UpY - myY ) ;
-
- x = SrcX ;
-
- if ( x >= LowerX() && x <= UpperX() ) {
- x -= myX ;
- for ( y = ly ; y <= uy ; y++ ) MYPIXELFIELD->SetValue(x,y,aPixel) ;
- }
-
- x = SrcX + SrcWidth - 1;
-
- if ( x >= LowerX() && x <= UpperX() ) {
- x -= myX ;
- for ( y = ly ; y <= uy ; y++ ) MYPIXELFIELD->SetValue(x,y,aPixel) ;
- }
- }
-}
-
-
-void Image_GImage::Resize(const Standard_Real XOffset,
- const Standard_Real aCoefX,
- const Standard_Real YOffset,
- const Standard_Real aCoefY)
-
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY ;
- anyPixel aPixel ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- if ( aCoefX == 0. || aCoefY == 0. ) {
- cout << "Image_GImage::Resize() singular transformation\n" ;
- }
-
- nLowX = Standard_Integer( IntegerPart( LowX * aCoefX + XOffset ) ) ;
- nLowY = Standard_Integer( IntegerPart( LowY * aCoefY + YOffset ) ) ;
-
- nUpX = Standard_Integer( IntegerPart( UpX * aCoefX + XOffset ) ) ;
- nUpY = Standard_Integer( IntegerPart( UpY * aCoefY + YOffset ) ) ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( nUpX-nLowX+1,
- nUpY-nLowY+1,
- myBackgroundPixel) ;
-
- for( Y = LowY ; Y <= UpY ; Y++ ) {
- for( X = LowX ; X <= UpX ; X++ ) {
- aPixel = Pixel( X, Y ) ;
- if ( X >= nLowX && X <= nUpX && Y >= nLowY && Y <= nUpY )
- NewPixelField->SetValue(X-nLowX,Y-nLowY,aPixel);
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = nLowX ; myY = nLowY ;
-
-}
-
-void Image_GImage::Clip(const Standard_Integer X,
- const Standard_Integer Y,
- const Standard_Integer Width,
- const Standard_Integer Height )
-{ Standard_Integer nx, x, ny, y, Upx, Upy ;
- Standard_Integer LowX, LowY, UpY, UpX ;
- Image_PixelField* NewPixelField =
- new Image_PixelField( Width ,
- Height ,
- myBackgroundPixel) ;
-
- LowX = Max( X, myX );
- UpX = Min( UpperX(), X+Width-1 ) ;
-
- LowY = Max( Y, myY );
- UpY = Min( UpperY(), Y+Height-1 ) ;
-
- y = ( LowY - myY ) ;
- Upy = ( UpY - myY ) ;
- ny = ( LowY - Y ) ;
-
- x = ( LowX - myX ) ;
- Upx = ( UpX - myX ) ;
- nx = ( LowX - X ) ;
-
- if ( LowX <= UpX && LowY <= UpY ) {
- PixelFieldCopyTo( *NewPixelField, x, y, Upx, Upy, nx, ny ) ;
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = X ; myY = Y ;
-}
-
-void Image_GImage::Affine(
- const Image_PixelInterpolation& aInterpolation,
- const gp_GTrsf2d& aTrsf )
-
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY;
- Standard_Real SX, SY ;
- anyPixel aPixel ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
-
- if ( aTrsf.Form() == gp_Identity ) return ;
- else if ( aTrsf.Form() == gp_Translation ) {
- Translate( aInterpolation, aTrsf.Value( 1, 3 ), aTrsf.Value( 2, 3 ) ) ;
- return ;
- }
- else if ( aTrsf.Form() == gp_Rotation ) {
- }
- else if ( aTrsf.Form() == gp_Scale ) {
- Zoom( aInterpolation, aTrsf.Value( 1, 1 ), aTrsf.Value( 2, 2 ) ) ;
- return ;
- }
-
- if ( aTrsf.IsSingular() ) {
- cout << "Image_GImage::Affine() singular transformation\n" ;
- }
-
- gp_GTrsf2d InvTrsf( aTrsf ) ; InvTrsf.Invert() ;
-
- nLowX = myX ;
- nLowY = myY ;
- nUpX = UpperX() ;
- nUpY = UpperY() ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Width(),
- MYPIXELFIELD->Height(),
- myBackgroundPixel) ;
-
- for( Y = nLowY ; Y <= nUpY ; Y++ ) {
- for( X = nLowX ; X <= nUpX ; X++ ) {
- SX = X ; SY = Y ;
- InvTrsf.Transforms( SX, SY ) ;
- if ( aInterpolation.Interpolate( this, SX, SY,
- LowX, LowY, UpX, UpY, aPixel ) ) {
- NewPixelField->SetValue( X-nLowX, Y-nLowY, aPixel ) ;
- }
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = nLowX ; myY = nLowY ;
-
-}
-
-void Image_GImage::Affine(
- const Image_PixelInterpolation& aInterpolation,
- const gp_Trsf& aTrsf )
-
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY;
- Standard_Real SX, SY, SZ ;
- anyPixel aPixel ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
-
- if ( aTrsf.Form() == gp_Identity ) return ;
- else if ( aTrsf.Form() == gp_Translation ) {
- Translate( aInterpolation, aTrsf.Value( 1, 4 ), aTrsf.Value( 2, 4 ) ) ;
- return ;
- }
- else if ( aTrsf.Form() == gp_Rotation ) {
- }
- else if ( aTrsf.Form() == gp_Scale ) {
- Zoom( aInterpolation, aTrsf.Value( 1, 1 ), aTrsf.Value( 2, 2 ) ) ;
- return ;
- }
-
- gp_Trsf InvTrsf = aTrsf.Inverted() ;
-
- Standard_Real RmyX = Standard_Real(myX) ;
- Standard_Real RmyY = Standard_Real(myY) ;
-
- gp_Pln Pln( gp_Pnt( RmyX, RmyY, 0. ),
- gp_Dir( 0., 0., 1. )
- ) ;
-
- Pln.Transform( aTrsf ) ;
-
- Standard_Real a,b,c,d ;
-
- Pln.Coefficients( a,b,c,d ) ;
-
- if ( c == 0. ) {
- cout << "Image_GImage::Affine() singular transformation\n" ;
- return ;
- }
-
- nLowX = myX ;
- nLowY = myY ;
- nUpX = UpperX() ;
- nUpY = UpperY() ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Width(),
- MYPIXELFIELD->Height(),
- myBackgroundPixel) ;
-
- for( Y = nLowY ; Y <= nUpY ; Y++ ) {
- for( X = nLowX ; X <= nUpX ; X++ ) {
- SX = X ; SY = Y ; SZ = - ( d + a*SX + b*SY ) / c ;
- InvTrsf.Transforms( SX, SY, SZ ) ;
- if ( aInterpolation.Interpolate( this, SX, SY,
- LowX, LowY, UpX, UpY, aPixel ) ) {
- NewPixelField->SetValue( X-nLowX, Y-nLowY, aPixel ) ;
- }
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = nLowX ; myY = nLowY ;
-
-}
-
-void Image_GImage::Rotate(
- const Image_PixelInterpolation& aInterpolation,
- const Quantity_PlaneAngle aAngle )
-
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY;
- Standard_Real SX, SY ;
- anyPixel aPixel ;
-#ifdef USE_GP
- gp_Pnt2d Pnt( 0, 0 ) ;
- pg_GTrsf2d Trsf ;
-#endif
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- nLowX = myX ;
- nLowY = myY ;
- nUpX = UpperX() ;
- nUpY = UpperY() ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Width(),
- MYPIXELFIELD->Height(),
- myBackgroundPixel) ;
-
-#ifdef USE_GP
- Trsf.SetRotation( Pnt, -aAngle ) ;
-#endif
-
- for( Y = nLowY ; Y <= nUpY ; Y++ ) {
- for( X = nLowX ; X <= nUpX ; X++ ) {
-#ifdef USE_GP
- SX = X ; SY = Y ;
- Trsf.Transforms( SX, SY ) ;
-#else
- SX = X*Cos(-aAngle) + Y*Sin(-aAngle) ;
- SY = -X*Sin(-aAngle) + Y*Cos(-aAngle) ;
-#endif
- if ( aInterpolation.Interpolate( this, SX, SY,
- LowX, LowY, UpX, UpY, aPixel ) ) {
- NewPixelField->SetValue( X-nLowX, Y-nLowY, aPixel ) ;
- }
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = nLowX ; myY = nLowY ;
-
-}
-
-void Image_GImage::Zoom(const Image_PixelInterpolation& aInterpolation,
- const Standard_Real aCoefX,
- const Standard_Real aCoefY )
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY ;
- anyPixel aPixel ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- if ( aCoefX == 0. || aCoefY == 0. ) {
- cout << "Image_GImage::Zoom() singular transformation\n" ;
- }
-
- nLowX = Standard_Integer( IntegerPart( LowX * aCoefX ) ) ;
- nLowY = Standard_Integer( IntegerPart( LowY * aCoefY ) ) ;
-
-#ifdef OLD
- nUpX = nLowX + ( Width() * aCoefX + 0.5 ) - 1 ;
- nUpY = nLowY + ( Height() * aCoefY + 0.5 ) - 1 ;
-#else
- nUpX = Standard_Integer( IntegerPart( UpX * aCoefX ) ) ;
- nUpY = Standard_Integer( IntegerPart( UpY * aCoefY ) ) ;
-#endif
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( nUpX-nLowX+1,
- nUpY-nLowY+1,
- myBackgroundPixel) ;
-
- for( Y = nLowY ; Y <= nUpY ; Y++ ) {
- for( X = nLowX ; X <= nUpX ; X++ ) {
- if ( aInterpolation.Interpolate( this, X/aCoefX, Y/aCoefY,
- LowX, LowY, UpX, UpY, aPixel ) ) {
- NewPixelField->SetValue( X-nLowX, Y-nLowY, aPixel ) ;
- }
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-
- myX = nLowX ; myY = nLowY ;
-
-}
-
-void Image_GImage::Translate(
- const Image_PixelInterpolation& aInterpolation,
- const Standard_Real DX,
- const Standard_Real DY )
-{ Standard_Integer X, Y, nLowX, nLowY, nUpX, nUpY ;
- anyPixel aPixel ;
- Standard_Integer LowX = LowerX() ;
- Standard_Integer LowY = LowerY() ;
- Standard_Integer UpX = UpperX() ;
- Standard_Integer UpY = UpperY() ;
-
- Image_PixelField *NewPixelField =
- new Image_PixelField( MYPIXELFIELD->Width(),
- MYPIXELFIELD->Height(),
- myBackgroundPixel) ;
-
- nLowX = myX ;
- nLowY = myY ;
- nUpX = UpperX() ;
- nUpY = UpperY() ;
-
- for( Y = nLowY ; Y <= nUpY ; Y++ ) {
- for( X = nLowX ; X <= nUpX ; X++ ) {
- if ( aInterpolation.Interpolate( this, X-DX, Y-DY,
- LowX, LowY, UpX, UpY, aPixel ) ) {
- NewPixelField->SetValue( X-nLowX, Y-nLowY, aPixel ) ;
- }
- }
- }
-
- PixelFieldDestroy() ;
-
- myPixelField = ( Standard_Address ) NewPixelField ;
-}
-
-void Image_GImage::InternalDup( const Handle(Image_Image)& aImage ) {
-
- Handle(Image_GImage) GImage = Handle(Image_GImage)::DownCast(aImage) ;
-
-// Image Origin is set in Image_Gimage constructor
-
- PixelFieldCopyFrom( GImage->PixelField(),
- 0, 0,
- (GImage->PixelField()).UpperX(),
- (GImage->PixelField()).UpperY(),
- 0, 0 ) ;
-
- Image_Image::InternalDup( aImage ) ;
-}
-
-void Image_GImage::SetBackgroundPixel ( const anyPixel& aPixel ) {
- myBackgroundPixel = aPixel ;
-}
-
-const anyPixel& Image_GImage::BackgroundPixel () const {
- return myBackgroundPixel;
-}
-
-void Image_GImage::SetPixel(const Standard_Integer X,
- const Standard_Integer Y,
- const Aspect_Pixel& aPixel) {
- //Assume that aPixel has similar type than Pixel from Image PixelField
-
- MYPIXELFIELD->SetValue(X-myX,Y-myY,(( anyPixel& )aPixel)) ;
-
-}
-
-void Image_GImage::SetPixel(const Standard_Integer X,
- const Standard_Integer Y,
- const Image_PixelAddress& aPixel) {
- //Assume that aPixel has similar type than Pixel from Image PixelField
-
- MYPIXELFIELD->SetValue(X-myX,Y-myY,*(( anyPixel* )aPixel)) ;
-
-}
-
-const anyPixel& Image_GImage::Pixel(const Standard_Integer X,
- const Standard_Integer Y) const {
-
- return ( MYPIXELFIELD->Value(X-myX,Y-myY) ) ;
-
-}
-
-void Image_GImage::Pixel(const Standard_Integer X,
- const Standard_Integer Y,
- Image_PixelAddress& aPixel) const {
-
- //Assume that aPixel has similar type than Pixel from Image PixelField
- aPixel = ( Image_PixelAddress )
- &( MYPIXELFIELD->Value(X-myX,Y-myY ) );
-
-}
-
-void Image_GImage::Pixel(const Standard_Integer X,
- const Standard_Integer Y,
- Aspect_Pixel& aPixel) const {
-
- //Assume that aPixel has similar type than Pixel from Image PixelField
- ( anyPixel& )aPixel = MYPIXELFIELD->Value(X-myX,Y-myY ) ;
-
-}
-
-anyPixel& Image_GImage::MutPixel(const Standard_Integer X,
- const Standard_Integer Y) {
-
- return ( MYPIXELFIELD->ChangeValue(X-myX,Y-myY) ) ;
-
-}
-
-void Image_GImage::SetPixel (const Standard_Integer X,
- const Standard_Integer Y,
- const anyPixel & aPixel) {
- MYPIXELFIELD->SetValue(X-myX,Y-myY,aPixel);
-
-}
-
+++ /dev/null
--- Created on: 1993-12-09
--- Created by: Bertand Lesecq
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-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 ;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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;
- }
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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] ;
-}
-
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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 ;
-}
-
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-//============================================================================
-//==== 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
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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 ) ; }
-
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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
+++ /dev/null
--- Created on: 1993-07-27
--- Created by: Jean Louis FRENKEL
--- Copyright (c) 1993-1999 Matra Datavision
--- Copyright (c) 1999-2012 OPEN CASCADE SAS
---
--- The content of this file is subject to the Open CASCADE Technology Public
--- License Version 6.5 (the "License"). You may not use the content of this file
--- except in compliance with the License. Please obtain a copy of the License
--- at http://www.opencascade.org and read it completely before using this file.
---
--- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
--- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
---
--- The Original Code and all software distributed under the License is
--- distributed on an "AS IS" basis, without warranty of any kind, and the
--- Initial Developer hereby disclaims all such warranties, including without
--- limitation, any warranties of merchantability, fitness for a particular
--- purpose or non-infringement. Please see the License for the specific terms
--- and conditions governing the rights and limitations under the License.
-
-
-
-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;
+++ /dev/null
-// Copyright (c) 1995-1999 Matra Datavision
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-#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
uses
Quantity, AIS, PrsMgr, Prs3d, SelectMgr, TColStd, SelectBasics,
- Graphic3d, gp, TCollection, Bnd, TColgp, Select3D, TopLoc, Aspect, AlienImage
+ Graphic3d, gp, TCollection, Bnd, TColgp, Select3D, TopLoc, Aspect
is
---Purpose: The integer keys for most useful constants attuning mesh presentation appearence
#include <Handle_TColStd_HArray1OfReal.hxx>
#include <Quantity_PlaneAngle.hxx>
#include <Quantity_NameOfColor.hxx>
-#include <Handle_AlienImage_AlienImage.hxx>
#include <Handle_OpenGl_View.hxx>
#include <Handle_OpenGl_Workspace.hxx>
class Graphic3d_Vertex;
class Aspect_Array1OfEdge;
class TCollection_ExtendedString;
-class AlienImage_AlienImage;
class Image_PixMap;
class TColStd_HArray1OfReal;
class Handle(OpenGl_Workspace);
InterfaceGraphic
SelectBasics
Xw
-AlienImage
Image
WNT
Cocoa
TransientManager from Visual3d,
TypeOfTriedronEcho from Aspect,
TypeOfTriedronPosition from Aspect,
- FormatOfSheetPaper from Aspect,
RenderingContext from Aspect,
GraphicCallbackProc from Aspect,
FillMethod from Aspect,