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

Integration of OCCT 6.5.0 from SVN

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

133
src/AlienImage/AlienImage.cdl Executable file
View File

@@ -0,0 +1,133 @@
-- File: AlienImage.cdl
-- Created: Tue Jul 27 18:51:28 1993
-- Author: Jean Louis FRENKEL
-- <jlf@sparc3>
---Copyright: Matra Datavision 1993
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;

129
src/AlienImage/AlienImage.cxx Executable file
View File

@@ -0,0 +1,129 @@
// File: AlienImage.cxx
// Created: 21-OCT-1998
// Author: DCB
// Copyright: Matra Datavision 1998
#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;
}
}

View File

@@ -0,0 +1,110 @@
--
-- File: AlienImage_AidaAlienData.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,539 @@
#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 ) ; }

View File

@@ -0,0 +1,68 @@
--
-- File: AlienImage_AidaAlienImage.cdl
-- Created: 23/03/93
-- Author: BBL
-- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,41 @@
#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 ) ; }

View File

@@ -0,0 +1,47 @@
--
-- File: AlienImage_AlienImage.cdl
-- Created: 23/03/93
-- Author: BBL,JLF
--
---Copyright: Matravision 1993
--
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;

View File

@@ -0,0 +1,9 @@
#include <AlienImage_AlienImage.ixx>
AlienImage_AlienImage::AlienImage_AlienImage()
{
#ifdef TRACE
cout << "AlienImage_AlienImage constructor \n" ;
#endif
}

View File

@@ -0,0 +1,43 @@
-- File: AlienImage_AlienImage.cdl
-- Created: 23/03/93
-- Author: BBL,JLF
--
-- Modified: DCB (20-OCT-98)
-- Define Name()/SetName() as deferred.
--
---Copyright: Matravision 1993
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;

View File

@@ -0,0 +1,19 @@
#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;
}

View File

@@ -0,0 +1,67 @@
-- File: AlienImage_AlienUserImage.cdl
-- Created: 23/03/93
-- Author: BBL,JLF
--
-- Modified: DCB (20-OCT-98)
-- Define ToImage()/FromName() as deferred.
--
---Copyright: Matravision 1993
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;

View File

@@ -0,0 +1,75 @@
#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 ) ;
}

View File

@@ -0,0 +1,71 @@
-- File: AlienImage_BMPAlienData.cdl
-- Created: 20/10/98
-- Author: DCB
---Copyright: Matravision 1998
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;

View File

@@ -0,0 +1,574 @@
// File: AlienImage_BMPAlienData.cxx
// Created: Quebex 20 October 1998
// Author: DCB
// Notes:
// Read()/Write() code is taken from ZOV's sources from Xw package.
// Copyright: MatraDatavision 1998
// 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);
}
}
}
}

View File

@@ -0,0 +1,57 @@
-- File: AlienImage_BMPAlienImage.cdl
-- Created: 20/10/98
-- Author: DCB
---Copyright: Matravision 1993
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;

View File

@@ -0,0 +1,55 @@
// File: AlienImage_BMPAlienImage.cxx
// Created: Quebex 20 October 1998
// Author: DCB
// Copyright: MatraDatavision 1998
#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);
}

View File

@@ -0,0 +1,16 @@
// File: AlienImage_BMPHeader.cxx
// Created: Quebex 26 October 1998
// Author: DCB
// Notes: Most of code is taken from Xw_load_bmp_image.c file (ZOV)
//
// Copyright: MatraDatavision 1998
#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;
}

View File

@@ -0,0 +1,73 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,84 @@
--
-- File: AlienImage_EuclidAlienData.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,417 @@
#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() ) ;
}
}
}

View File

@@ -0,0 +1,58 @@
--
-- File: AlienImage_EuclidAlienImage.cdl
-- Created: 23/03/93
-- Author: BBL
-- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,28 @@
#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 ) ; }

View File

@@ -0,0 +1,75 @@
-- File: AlienImage_GIFAlienData.cdl
-- Created: 20/10/98
-- Author: DCB
---Copyright: Matravision 1998
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;

View File

@@ -0,0 +1,634 @@
// File: AlienImage_GIFAlienData.cxx
// Created: Quebex 20 October 1998
// Author: DCB
// 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.
// Copyright: MatraDatavision 1998
#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
}

View File

@@ -0,0 +1,57 @@
-- File: AlienImage_GIFAlienImage.cdl
-- Created: 20/10/98
-- Author: DCB
---Copyright: Matravision 1993
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;

View File

@@ -0,0 +1,55 @@
// File: AlienImage_GIFAlienImage.cxx
// Created: Quebex 20 October 1998
// Author: DCB
// Copyright: MatraDatavision 1998
#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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,44 @@
--
-- File: AlienImage_MemoryOperations.cdl
-- Created: 23/03/93
-- Author: BBL,JLF
--
---Copyright: Matravision 1993
--
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;

View File

@@ -0,0 +1,50 @@
#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;
}
}

View File

@@ -0,0 +1,94 @@
--
-- File: AlienImage_SGIRGBAlienData.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
--
-- File: AlienImage_SGIRGBAlienImage.cdl
-- Created: 23/03/93
-- Author: BBL
-- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,35 @@
#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 ) ; }

View File

@@ -0,0 +1,32 @@
#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 " );
}

View File

@@ -0,0 +1,86 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,39 @@
#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 );
}

View File

@@ -0,0 +1,65 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,128 @@
--
-- File: AlienImage_SunRFAlienData.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,704 @@
#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 ;
}

View File

@@ -0,0 +1,64 @@
--
-- File: AlienImage_SunRFAlienImage.cdl
-- Created: 23/03/93
-- Author: BBL
-- Modified: 02-06-98 : FMN ; Suppression appel Clear (deja fait dans ALienData)
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,37 @@
#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( ) ; }

View File

@@ -0,0 +1,48 @@
#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
<< ")" ) ;
}

View File

@@ -0,0 +1,45 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,141 @@
--
-- File: AlienImage_X11XWDAlienData.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,827 @@
#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".
#ifndef WNT
# 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 DEB
AlienImage_X11XColor *p = ( AlienImage_X11XColor * )myColors ;
#endif
#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 ;
}

View File

@@ -0,0 +1,134 @@
#ifndef WNT
# 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 ) ;
}

View File

@@ -0,0 +1,31 @@
//============================================================================
//==== 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

View File

@@ -0,0 +1,62 @@
--
-- File: AlienImage_XAlienImage.cdl
-- Created: 23/03/93
-- Author: BBL
--
---Copyright: Matravision 1993
--
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 ;

View File

@@ -0,0 +1,35 @@
#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 ) ; }

13
src/AlienImage/FILES Executable file
View File

@@ -0,0 +1,13 @@
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