mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c975787c6c |
@@ -86,9 +86,7 @@ int ec_error ( const std::string& s, const std::string& text )
|
||||
|
||||
%top{
|
||||
// Pre-include stdlib.h to avoid redefinition of integer type macros (INT8_MIN and similar in generated code)
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1600) // Visual Studio 2010+
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include <Standard_TypeDef.hxx>
|
||||
}
|
||||
|
||||
%{
|
||||
|
@@ -1,7 +1,5 @@
|
||||
// Pre-include stdlib.h to avoid redefinition of integer type macros (INT8_MIN and similar in generated code)
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1600) // Visual Studio 2010+
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include <Standard_TypeDef.hxx>
|
||||
|
||||
#define YY_INT_ALIGNED short int
|
||||
|
||||
|
@@ -226,265 +226,299 @@ TopoDS_Shape IGESToBRep_CurveAndSurface::TransferCurveAndSurface
|
||||
//function : TransferGeometry
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TopoDS_Shape IGESToBRep_CurveAndSurface::TransferGeometry
|
||||
(const Handle(IGESData_IGESEntity)& theStart,
|
||||
(const Handle(IGESData_IGESEntity)& start,
|
||||
const Message_ProgressRange& theProgress)
|
||||
{
|
||||
// Declaration of messages//
|
||||
// DCE 22/12/98
|
||||
//Message_Msg aMsg1005("IGES_1001"); // The type of the Start is not recognized
|
||||
//Message_Msg aMsg1005("IGES_1005"); // Software error : the Start IsNull.
|
||||
//Message_Msg aMsg1015("IGES_1015"); // invalid type or exception raising (software error).
|
||||
//Message_Msg aMsg1010("IGES_1010"); // Not sameparameter.
|
||||
//Message_Msg aMsg1015("IGES_1020"); // Associated entity IsNull
|
||||
//Message_Msg aMsg1015("IGES_1025"); // No shape is found for the associated entity for the type 308
|
||||
//Message_Msg aMsg1015("IGES_1030"); // No shape is found for the associated entity for the type 402
|
||||
//Message_Msg aMsg1015("IGES_1035"); // The conversion of a Location is not possible
|
||||
//Message_Msg aMsg210 ("XSTEP_210"); // No associated entities for the type 308
|
||||
//Message_Msg aMsg202 ("XSTEP_202"); // No associated entities for the type 402
|
||||
//Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
|
||||
//Message_Msg msg1015("IGES_1015"); // invalid type or exception raising (software error).
|
||||
//Message_Msg msg1010("IGES_1010"); // Not sameparameter.
|
||||
// Message_Msg msg1015("IGES_1015");
|
||||
//Message_Msg msg210 ("XSTEP_210");
|
||||
//Message_Msg msg202 ("XSTEP_202");
|
||||
////////////////////////////
|
||||
TopoDS_Shape res;
|
||||
gp_Trsf T408;
|
||||
if (theStart.IsNull())
|
||||
{
|
||||
if (start.IsNull()) {
|
||||
Message_Msg msg1005("IGES_1005"); // Software error : start IsNull.
|
||||
SendFail(theStart, msg1005);
|
||||
SendFail(start, msg1005);
|
||||
return res;
|
||||
}
|
||||
|
||||
// Read of the DE number and the type number of the entity
|
||||
Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(start);
|
||||
//Standard_Integer typeNumber = start->TypeNumber();
|
||||
|
||||
// sln 13.06.2002 OCC448: Avoid transferring invisible sub entities which
|
||||
// logically depend on the one
|
||||
const Standard_Integer anOnlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
|
||||
Standard_Integer onlyvisible = Interface_Static::IVal("read.iges.onlyvisible");
|
||||
|
||||
if (IGESToBRep::IsCurveAndSurface(theStart))
|
||||
{
|
||||
if(anOnlyvisible && theStart->BlankStatus() == 1)
|
||||
if (IGESToBRep::IsCurveAndSurface(start)) {
|
||||
if(onlyvisible && start->BlankStatus() == 1)
|
||||
return res;
|
||||
try
|
||||
{
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
res = TransferCurveAndSurface(theStart, theProgress);
|
||||
res = TransferCurveAndSurface(start, theProgress);
|
||||
}
|
||||
catch(Standard_Failure const&)
|
||||
{
|
||||
catch(Standard_Failure const&) {
|
||||
Message_Msg msg1015("IGES_1015");
|
||||
SendFail(theStart, msg1015);
|
||||
SendFail(start, msg1015);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
//408 : SingularSubfigure
|
||||
if (theStart->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
|
||||
if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
|
||||
{
|
||||
if(anOnlyvisible && theStart->BlankStatus() == 1)
|
||||
if(onlyvisible && start->BlankStatus() == 1)
|
||||
return res;
|
||||
|
||||
DeclareAndCast(IGESBasic_SingularSubfigure, st408, theStart);
|
||||
DeclareAndCast(IGESBasic_SingularSubfigure, st408, start);
|
||||
Handle (IGESBasic_SubfigureDef) stsub = st408->Subfigure();
|
||||
const gp_XYZ trans = st408->Translation();
|
||||
gp_XYZ trans = st408->Translation();
|
||||
gp_Vec vectr(trans);
|
||||
const Standard_Real scunit = GetUnitFactor();
|
||||
Standard_Real scunit = GetUnitFactor();
|
||||
vectr.Multiply(scunit);
|
||||
T408.SetTranslation(vectr);
|
||||
if (st408->HasScaleFactor())
|
||||
{
|
||||
const Standard_Real scalef = st408->ScaleFactor();
|
||||
if (st408->HasScaleFactor()) {
|
||||
Standard_Real scalef = st408->ScaleFactor();
|
||||
T408.SetScaleFactor(scalef);
|
||||
}
|
||||
if (HasShapeResult(stsub))
|
||||
{
|
||||
if (HasShapeResult(stsub)) {
|
||||
res = GetShapeResult(stsub);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
else {
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
res = TransferGeometry(stsub, theProgress);
|
||||
}
|
||||
catch(Standard_Failure const&)
|
||||
{
|
||||
catch(Standard_Failure const&) {
|
||||
res.Nullify();
|
||||
const Message_Msg msg1015("IGES_1015");
|
||||
SendFail(st408, msg1015);
|
||||
Message_Msg msg1015("IGES_1015");
|
||||
SendFail( st408, msg1015);
|
||||
}
|
||||
if (!res.IsNull())
|
||||
{
|
||||
SetShapeResult(stsub, res);
|
||||
if (!res.IsNull()) {
|
||||
SetShapeResult(stsub,res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 308 : SubfigureDefinition
|
||||
else if (theStart->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef)))
|
||||
{
|
||||
DeclareAndCast(IGESBasic_SubfigureDef, st308, theStart);
|
||||
TopoDS_Compound aGroup;
|
||||
BRep_Builder aBuilder;
|
||||
aBuilder.MakeCompound (aGroup);
|
||||
if (st308->NbEntities() < 1)
|
||||
{
|
||||
const Message_Msg msg210 ("XSTEP_210");
|
||||
SendFail(st308, msg210);
|
||||
else if (start->IsKind(STANDARD_TYPE(IGESBasic_SubfigureDef))) {
|
||||
DeclareAndCast(IGESBasic_SubfigureDef, st308, start);
|
||||
TopoDS_Compound group;
|
||||
BRep_Builder B;
|
||||
B.MakeCompound (group);
|
||||
if (st308->NbEntities() < 1) {
|
||||
Message_Msg msg210 ("XSTEP_210");
|
||||
SendFail( st308, msg210);
|
||||
return res;
|
||||
}
|
||||
Message_ProgressScope aPS (theProgress, "Subfigure item", st308->NbEntities());
|
||||
for (Standard_Integer anIndx =1; anIndx <= st308->NbEntities() && aPS.More(); anIndx++)
|
||||
{
|
||||
Message_ProgressRange aRange = aPS.Next();
|
||||
TopoDS_Shape anItem;
|
||||
if (st308->AssociatedEntity(anIndx).IsNull())
|
||||
Message_ProgressScope PS (theProgress, "Subfigure item", st308->NbEntities());
|
||||
for (Standard_Integer i=1; i <= st308->NbEntities() && PS.More(); i++)
|
||||
{
|
||||
Message_ProgressRange aRange = PS.Next();
|
||||
TopoDS_Shape item;
|
||||
if (st308->AssociatedEntity(i).IsNull()) {
|
||||
Message_Msg msg1020("IGES_1020");
|
||||
msg1020.Arg(anIndx);
|
||||
SendWarning(st308, msg1020);
|
||||
msg1020.Arg(i);
|
||||
SendWarning( st308, msg1020);
|
||||
continue;
|
||||
}
|
||||
if(anOnlyvisible && st308->AssociatedEntity(anIndx)->BlankStatus() == 1)
|
||||
if(onlyvisible && st308->AssociatedEntity(i)->BlankStatus() == 1 )
|
||||
continue;
|
||||
|
||||
if (HasShapeResult(st308->AssociatedEntity(anIndx)))
|
||||
if (HasShapeResult(st308->AssociatedEntity(i)))
|
||||
{
|
||||
anItem = GetShapeResult(st308->AssociatedEntity(anIndx));
|
||||
item = GetShapeResult(st308->AssociatedEntity(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
else {
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
anItem = TransferGeometry (st308->AssociatedEntity(anIndx), aRange);
|
||||
item = TransferGeometry (st308->AssociatedEntity(i), aRange);
|
||||
}
|
||||
catch(Standard_Failure const&)
|
||||
{
|
||||
anItem.Nullify();
|
||||
const Message_Msg msg1015("IGES_1015");
|
||||
SendFail(st308->AssociatedEntity(anIndx), msg1015);
|
||||
catch(Standard_Failure const&) {
|
||||
item.Nullify();
|
||||
Message_Msg msg1015("IGES_1015");
|
||||
SendFail( st308->AssociatedEntity(i), msg1015);
|
||||
}
|
||||
}
|
||||
if (anItem.IsNull())
|
||||
{
|
||||
if (item.IsNull()) {
|
||||
Message_Msg msg1025("IGES_1025");
|
||||
msg1025.Arg(anIndx);
|
||||
SendWarning (theStart, msg1025);
|
||||
msg1025.Arg(i);
|
||||
SendWarning (start,msg1025);
|
||||
}
|
||||
else
|
||||
{
|
||||
aBuilder.Add(aGroup, anItem);
|
||||
SetShapeResult (st308->AssociatedEntity(anIndx), anItem);
|
||||
else {
|
||||
B.Add(group, item);
|
||||
SetShapeResult (st308->AssociatedEntity(i),item);
|
||||
}
|
||||
}
|
||||
res = aGroup;
|
||||
res = group;
|
||||
}
|
||||
// 402 : Group Associativity
|
||||
else if (theStart->IsKind(STANDARD_TYPE(IGESBasic_Group)))
|
||||
{
|
||||
if(anOnlyvisible && theStart->BlankStatus() == 1)
|
||||
else if (start->IsKind(STANDARD_TYPE(IGESBasic_Group))) {
|
||||
if(onlyvisible && start->BlankStatus() == 1)
|
||||
return res;
|
||||
|
||||
DeclareAndCast(IGESBasic_Group, st402f1, theStart);
|
||||
TopoDS_Compound aGroup;
|
||||
BRep_Builder aBuilder;
|
||||
aBuilder.MakeCompound (aGroup);
|
||||
const Standard_Integer aNbEnt = st402f1->NbEntities();
|
||||
if (aNbEnt < 1)
|
||||
{
|
||||
DeclareAndCast(IGESBasic_Group, st402f1, start);
|
||||
TopoDS_Compound group;
|
||||
BRep_Builder B;
|
||||
B.MakeCompound (group);
|
||||
if (st402f1->NbEntities() < 1) {
|
||||
Message_Msg msg202 ("XSTEP_202");
|
||||
msg202.Arg(st402f1->FormNumber());
|
||||
SendFail(st402f1, msg202);
|
||||
return res;
|
||||
}
|
||||
Message_ProgressScope aPS (theProgress, "Group item", aNbEnt);
|
||||
Message_ProgressScope PS (theProgress, "Group item", st402f1->NbEntities());
|
||||
Standard_Boolean ProblemInGroup = Standard_False;
|
||||
for (Standard_Integer anIndx=1; anIndx <= aNbEnt && aPS.More(); anIndx++)
|
||||
{
|
||||
Message_ProgressRange aRange = aPS.Next();
|
||||
TopoDS_Shape anItem;
|
||||
if (st402f1->Entity(anIndx).IsNull())
|
||||
for (Standard_Integer i=1; i <= st402f1->NbEntities() && PS.More(); i++)
|
||||
{
|
||||
Message_ProgressRange aRange = PS.Next();
|
||||
TopoDS_Shape item;
|
||||
if (st402f1->Entity(i).IsNull()) {
|
||||
Message_Msg msg1020("IGES_1020");
|
||||
msg1020.Arg(anIndx);
|
||||
SendFail(st402f1, msg1020);
|
||||
msg1020.Arg(i);
|
||||
SendFail( st402f1, msg1020);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(anOnlyvisible && st402f1->Entity(anIndx)->BlankStatus() == 1)
|
||||
if(onlyvisible && st402f1->Entity(i)->BlankStatus() == 1)
|
||||
continue;
|
||||
|
||||
if (HasShapeResult(st402f1->Entity(anIndx)))
|
||||
{
|
||||
anItem = GetShapeResult(st402f1->Entity(anIndx));
|
||||
if (HasShapeResult(st402f1->Entity(i))) {
|
||||
item = GetShapeResult(st402f1->Entity(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
else {
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
anItem = TransferGeometry (st402f1->Entity(anIndx), aRange);
|
||||
item = TransferGeometry (st402f1->Entity(i), aRange);
|
||||
}
|
||||
catch(Standard_Failure const&)
|
||||
{
|
||||
anItem.Nullify();
|
||||
catch(Standard_Failure const&) {
|
||||
item.Nullify();
|
||||
Message_Msg msg1015("IGES_1015");
|
||||
SendFail(st402f1->Entity(anIndx), msg1015);
|
||||
SendFail(st402f1->Entity(i),msg1015);
|
||||
}
|
||||
}
|
||||
if (anItem.IsNull())
|
||||
{
|
||||
if (item.IsNull()) {
|
||||
//Message_Msg msg1030("IGES_1030");
|
||||
//msg1030.Arg(st402f1->FormNumber());
|
||||
//msg1030.Arg(i);
|
||||
//SendWarning (st402f1,msg1030);
|
||||
ProblemInGroup = Standard_True;
|
||||
}
|
||||
else
|
||||
{
|
||||
aBuilder.Add(aGroup, anItem);
|
||||
SetShapeResult (st402f1->Entity(anIndx), anItem);
|
||||
else {
|
||||
B.Add(group, item);
|
||||
SetShapeResult (st402f1->Entity(i),item);
|
||||
}
|
||||
}
|
||||
res = aGroup;
|
||||
if(ProblemInGroup)
|
||||
{
|
||||
res = group;
|
||||
if(ProblemInGroup) {
|
||||
Message_Msg msg1030("IGES_1030");
|
||||
msg1030.Arg(st402f1->FormNumber());
|
||||
SendWarning (st402f1, msg1030);
|
||||
SendWarning (st402f1,msg1030);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (start->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
|
||||
|
||||
if(onlyvisible && start->BlankStatus() == 1)
|
||||
return res;
|
||||
|
||||
DeclareAndCast(IGESBasic_GroupWithoutBackP, st402f7, start);
|
||||
TopoDS_Compound group;
|
||||
//unused Handle(TCollection_HAsciiString) label = GetModel()->StringLabel(st402f7);
|
||||
BRep_Builder B;
|
||||
B.MakeCompound (group);
|
||||
if (st402f7->NbEntities() < 1) {
|
||||
Message_Msg msg202 ("XSTEP_202");
|
||||
msg202.Arg(st402f7->FormNumber());
|
||||
SendFail(st402f7, msg202);
|
||||
return res;
|
||||
}
|
||||
Message_ProgressScope PS (theProgress, "Group item", st402f7->NbEntities());
|
||||
Standard_Boolean ProblemInGroup = Standard_False;
|
||||
for (Standard_Integer i=1; i <= st402f7->NbEntities() && PS.More(); i++)
|
||||
{
|
||||
Message_ProgressRange aRange = PS.Next();
|
||||
TopoDS_Shape item;
|
||||
if (st402f7->Entity(i).IsNull()) {
|
||||
Message_Msg msg1020("IGES_1020");
|
||||
msg1020.Arg(i);
|
||||
SendFail( st402f7, msg1020);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(onlyvisible && st402f7->Entity(i)->BlankStatus() == 1 )
|
||||
continue;
|
||||
|
||||
if (HasShapeResult(st402f7->Entity(i))) {
|
||||
item = GetShapeResult(st402f7->Entity(i));
|
||||
}
|
||||
else {
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
item = TransferGeometry (st402f7->Entity(i), aRange);
|
||||
}
|
||||
catch(Standard_Failure const&) {
|
||||
item.Nullify();
|
||||
Message_Msg msg1015("IGES_1015");
|
||||
SendFail(st402f7->Entity(i),msg1015);
|
||||
}
|
||||
}
|
||||
if (item.IsNull()) {
|
||||
//Message_Msg msg1030("IGES_1030");
|
||||
//msg1030.Arg(st402f7->FormNumber());
|
||||
//msg1030.Arg(i);
|
||||
//SendWarning (st402f7,msg1030);
|
||||
ProblemInGroup = Standard_True;
|
||||
}
|
||||
else {
|
||||
B.Add(group, item);
|
||||
SetShapeResult (st402f7->Entity(i),item);
|
||||
}
|
||||
}
|
||||
res = group;
|
||||
if(ProblemInGroup) {
|
||||
Message_Msg msg1030("IGES_1030");
|
||||
msg1030.Arg(st402f7->FormNumber());
|
||||
SendWarning (st402f7,msg1030);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Message_Msg msg1001("IGES_1001");
|
||||
msg1001.Arg(theStart->FormNumber());
|
||||
SendFail (theStart, msg1001);
|
||||
msg1001.Arg(start->FormNumber());
|
||||
SendFail (start,msg1001);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (theStart->HasTransf())
|
||||
{
|
||||
if (start->HasTransf()) {
|
||||
gp_Trsf T;
|
||||
SetEpsilon(1.E-04);
|
||||
if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(), theStart->CompoundLocation(),
|
||||
T, GetUnitFactor()))
|
||||
{
|
||||
if (theStart->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
|
||||
if (IGESData_ToolLocation::ConvertLocation(GetEpsilon(),start->CompoundLocation(),
|
||||
T,GetUnitFactor())) {
|
||||
if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
|
||||
{
|
||||
gp_XYZ tra = T.TranslationPart();
|
||||
const gp_XYZ trans = T408.TranslationPart();
|
||||
gp_XYZ trans = T408.TranslationPart();
|
||||
tra.Add(trans);
|
||||
T.SetTranslationPart(tra);
|
||||
Standard_Real sc = T.ScaleFactor();
|
||||
const Standard_Real scalef = T408.ScaleFactor();
|
||||
Standard_Real scalef = T408.ScaleFactor();
|
||||
sc = sc*scalef;
|
||||
T.SetScaleFactor(sc);
|
||||
}
|
||||
TopLoc_Location L(T);
|
||||
res.Move(L, Standard_False);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
Message_Msg msg1035("IGES_1035");
|
||||
SendWarning (theStart, msg1035);
|
||||
SendWarning (start,msg1035);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (theStart->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure)))
|
||||
{
|
||||
else {
|
||||
if (start->IsKind(STANDARD_TYPE(IGESBasic_SingularSubfigure))) {
|
||||
TopLoc_Location L(T408);
|
||||
res.Move(L);
|
||||
}
|
||||
|
@@ -135,10 +135,6 @@ namespace
|
||||
Image_FreeImageStream (std::istream& theStream)
|
||||
: myIStream (&theStream), myOStream (NULL), myInitPos (theStream.tellg()) {}
|
||||
|
||||
//! Construct wrapper over output stream.
|
||||
Image_FreeImageStream (std::ostream& theStream)
|
||||
: myIStream (NULL), myOStream (&theStream), myInitPos (theStream.tellp()) {}
|
||||
|
||||
//! Get io object.
|
||||
FreeImageIO GetFiIO() const
|
||||
{
|
||||
@@ -147,15 +143,12 @@ namespace
|
||||
if (myIStream != NULL)
|
||||
{
|
||||
anIo.read_proc = readProc;
|
||||
anIo.seek_proc = seekProcIn;
|
||||
anIo.tell_proc = tellProcIn;
|
||||
anIo.seek_proc = seekProc;
|
||||
anIo.tell_proc = tellProc;
|
||||
}
|
||||
if (myOStream != NULL)
|
||||
{
|
||||
anIo.write_proc = writeProc;
|
||||
// seek and tell are also used for saving in some formats (.tif for example)
|
||||
anIo.seek_proc = seekProcOut;
|
||||
anIo.tell_proc = tellProcOut;
|
||||
}
|
||||
return anIo;
|
||||
}
|
||||
@@ -190,7 +183,7 @@ namespace
|
||||
}
|
||||
|
||||
//! Simulate fseek().
|
||||
static int DLL_CALLCONV seekProcIn (fi_handle theHandle, long theOffset, int theOrigin)
|
||||
static int DLL_CALLCONV seekProc (fi_handle theHandle, long theOffset, int theOrigin)
|
||||
{
|
||||
Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
|
||||
if (aThis->myIStream == NULL)
|
||||
@@ -223,53 +216,13 @@ namespace
|
||||
return isSeekDone ? 0 : -1;
|
||||
}
|
||||
|
||||
static int DLL_CALLCONV seekProcOut (fi_handle theHandle, long theOffset, int theOrigin)
|
||||
{
|
||||
Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
|
||||
if (aThis->myOStream == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool isSeekDone = false;
|
||||
switch (theOrigin)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (aThis->myOStream->seekp ((std::streamoff )aThis->myInitPos + theOffset, std::ios::beg))
|
||||
{
|
||||
isSeekDone = true;
|
||||
}
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
if (aThis->myOStream->seekp (theOffset, std::ios::cur))
|
||||
{
|
||||
isSeekDone = true;
|
||||
}
|
||||
break;
|
||||
case SEEK_END:
|
||||
if (aThis->myOStream->seekp (theOffset, std::ios::end))
|
||||
{
|
||||
isSeekDone = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return isSeekDone ? 0 : -1;
|
||||
}
|
||||
|
||||
//! Simulate ftell().
|
||||
static long DLL_CALLCONV tellProcIn (fi_handle theHandle)
|
||||
static long DLL_CALLCONV tellProc (fi_handle theHandle)
|
||||
{
|
||||
Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
|
||||
const long aPos = aThis->myIStream != NULL ? (long )(aThis->myIStream->tellg() - aThis->myInitPos) : 0;
|
||||
return aPos;
|
||||
}
|
||||
|
||||
static long DLL_CALLCONV tellProcOut (fi_handle theHandle)
|
||||
{
|
||||
Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
|
||||
const long aPos = aThis->myOStream != NULL ? (long )(aThis->myOStream->tellp() - aThis->myInitPos) : 0;
|
||||
return aPos;
|
||||
}
|
||||
private:
|
||||
std::istream* myIStream;
|
||||
std::ostream* myOStream;
|
||||
@@ -285,37 +238,6 @@ namespace
|
||||
return aGuid;
|
||||
}
|
||||
|
||||
//! Returns GUID of image format from file name
|
||||
static GUID getFileFormatFromName (const TCollection_AsciiString& theFileName)
|
||||
{
|
||||
TCollection_AsciiString aFileNameLower = theFileName;
|
||||
aFileNameLower.LowerCase();
|
||||
GUID aFileFormat = getNullGuid();
|
||||
if (aFileNameLower.EndsWith (".bmp"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatBmp;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".png"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatPng;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".jpg")
|
||||
|| aFileNameLower.EndsWith (".jpeg"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatJpeg;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".tiff")
|
||||
|| aFileNameLower.EndsWith (".tif"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatTiff;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".gif"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatGif;
|
||||
}
|
||||
return aFileFormat;
|
||||
}
|
||||
|
||||
//! Sentry over IUnknown pointer.
|
||||
template<class T> class Image_ComPtr
|
||||
{
|
||||
@@ -424,11 +346,7 @@ namespace
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Image_AlienPixMap::Image_AlienPixMap()
|
||||
#ifdef HAVE_WINCODEC
|
||||
: myPalette (NULL)
|
||||
#else
|
||||
: myLibImage (NULL)
|
||||
#endif
|
||||
{
|
||||
SetTopDown (false);
|
||||
}
|
||||
@@ -587,12 +505,6 @@ void Image_AlienPixMap::Clear()
|
||||
FreeImage_Unload (myLibImage);
|
||||
myLibImage = NULL;
|
||||
}
|
||||
#elif defined(HAVE_WINCODEC)
|
||||
if (myPalette != NULL)
|
||||
{
|
||||
myPalette->Release();
|
||||
myPalette = NULL;
|
||||
}
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
if (myLibImage != NULL)
|
||||
{
|
||||
@@ -623,7 +535,7 @@ bool Image_AlienPixMap::IsTopDownDefault()
|
||||
// =======================================================================
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
const Standard_Size theLength,
|
||||
Standard_Size theLength,
|
||||
const TCollection_AsciiString& theImagePath)
|
||||
{
|
||||
Clear();
|
||||
@@ -793,7 +705,7 @@ bool Image_AlienPixMap::Load (std::istream& theStream,
|
||||
|
||||
#elif defined(HAVE_WINCODEC)
|
||||
bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
const Standard_Size theLength,
|
||||
Standard_Size theLength,
|
||||
const TCollection_AsciiString& theFileName)
|
||||
{
|
||||
Clear();
|
||||
@@ -839,7 +751,7 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
|| aFrameCount < 1
|
||||
|| aWicDecoder->GetFrame (0, &aWicFrameDecode.ChangePtr()) != S_OK
|
||||
|| aWicFrameDecode->GetSize (&aFrameSizeX, &aFrameSizeY) != S_OK
|
||||
|| aWicFrameDecode->GetPixelFormat (&aWicPixelFormat) != S_OK)
|
||||
|| aWicFrameDecode->GetPixelFormat (&aWicPixelFormat))
|
||||
{
|
||||
Message::SendFail ("Error: cannot get WIC Image Frame");
|
||||
return false;
|
||||
@@ -856,6 +768,7 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
Message::SendFail ("Error: cannot convert WIC Image Frame to RGB format");
|
||||
return false;
|
||||
}
|
||||
aWicFrameDecode.Nullify();
|
||||
}
|
||||
|
||||
if (!Image_PixMap::InitTrash (aPixelFormat, aFrameSizeX, aFrameSizeY))
|
||||
@@ -864,37 +777,17 @@ bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
return false;
|
||||
}
|
||||
|
||||
TCollection_AsciiString aFileNameLower = theFileName;
|
||||
aFileNameLower.LowerCase();
|
||||
if (aFileNameLower.EndsWith (".gif")
|
||||
&& (aWicImgFactory->CreatePalette (&myPalette) != S_OK
|
||||
|| aWicFrameDecode->CopyPalette (myPalette) != S_OK))
|
||||
{
|
||||
Message::SendFail ("Error: cannot get palette for GIF image");
|
||||
return false;
|
||||
}
|
||||
|
||||
IWICBitmapSource* aWicSrc = aWicFrameDecode.get();
|
||||
if(!aWicConvertedFrame.IsNull())
|
||||
{
|
||||
aWicSrc = aWicConvertedFrame.get();
|
||||
}
|
||||
|
||||
IWICBitmapFlipRotator* aRotator;
|
||||
bool isTopDown = true;
|
||||
if (aWicImgFactory->CreateBitmapFlipRotator (&aRotator) == S_OK
|
||||
&& aRotator->Initialize (aWicSrc, WICBitmapTransformFlipVertical) == S_OK)
|
||||
{
|
||||
isTopDown = false;
|
||||
aWicSrc = aRotator;
|
||||
}
|
||||
|
||||
if (aWicSrc->CopyPixels (NULL, (UINT )SizeRowBytes(), (UINT )SizeBytes(), ChangeData()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot copy pixels from WIC Image");
|
||||
return false;
|
||||
}
|
||||
SetTopDown (isTopDown);
|
||||
SetTopDown (true);
|
||||
return true;
|
||||
}
|
||||
bool Image_AlienPixMap::Load (std::istream& theStream,
|
||||
@@ -931,7 +824,7 @@ bool Image_AlienPixMap::Load (std::istream& ,
|
||||
return false;
|
||||
}
|
||||
bool Image_AlienPixMap::Load (const Standard_Byte* theData,
|
||||
const Standard_Size theLength,
|
||||
Standard_Size theLength,
|
||||
const TCollection_AsciiString& theImagePath)
|
||||
{
|
||||
Clear();
|
||||
@@ -964,7 +857,7 @@ bool Image_AlienPixMap::Load (std::istream& ,
|
||||
return false;
|
||||
}
|
||||
bool Image_AlienPixMap::Load (const Standard_Byte* ,
|
||||
const Standard_Size ,
|
||||
Standard_Size ,
|
||||
const TCollection_AsciiString& )
|
||||
{
|
||||
Clear();
|
||||
@@ -1014,52 +907,11 @@ bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) con
|
||||
return true;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : convertData
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
#ifdef HAVE_WINCODEC
|
||||
static bool convertData (const Image_AlienPixMap& theSrcPixMapData,
|
||||
const WICPixelFormatGUID& theFormat,
|
||||
IWICImagingFactory& theWicImgFactory,
|
||||
Image_PixMapData& theDstPixMapData)
|
||||
{
|
||||
const UINT aSizeRowBytes = (UINT)theSrcPixMapData.SizeRowBytes();
|
||||
const UINT aSizeBytes = (UINT)theSrcPixMapData.SizeBytes();
|
||||
|
||||
Image_ComPtr<IWICBitmap> anSrcImg;
|
||||
Image_ComPtr<IWICFormatConverter> aWicFormatConverter;
|
||||
HRESULT anHResult = theWicImgFactory.CreateBitmapFromMemory ((UINT)theSrcPixMapData.SizeX(), (UINT)theSrcPixMapData.SizeY(),
|
||||
convertToWicFormat (theSrcPixMapData.Format()),
|
||||
aSizeRowBytes, aSizeBytes,
|
||||
(BYTE*)theSrcPixMapData.Data(), &anSrcImg.ChangePtr());
|
||||
if (anHResult != S_OK
|
||||
|| theWicImgFactory.CreateFormatConverter (&aWicFormatConverter.ChangePtr()) != S_OK
|
||||
|| aWicFormatConverter->Initialize (anSrcImg.get(), theFormat, WICBitmapDitherTypeNone, theSrcPixMapData.GetPalette(), 0.0f, WICBitmapPaletteTypeCustom) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot convert WIC Image Frame to required format");
|
||||
return false;
|
||||
}
|
||||
|
||||
theDstPixMapData.Init (Image_PixMap::DefaultAllocator(), 1, theSrcPixMapData.SizeXYZ(), aSizeRowBytes, NULL);
|
||||
|
||||
if (aWicFormatConverter->CopyPixels (NULL, aSizeRowBytes, aSizeBytes, theDstPixMapData.ChangeData()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot copy pixels from WIC Image");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// =======================================================================
|
||||
// function : Save
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Image_AlienPixMap::Save (Standard_Byte* theBuffer,
|
||||
const Standard_Size theLength,
|
||||
const TCollection_AsciiString& theFileName)
|
||||
bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
||||
{
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
if (myLibImage == NULL)
|
||||
@@ -1087,399 +939,10 @@ bool Image_AlienPixMap::Save (Standard_Byte* theBuffer,
|
||||
SetTopDown (false);
|
||||
}
|
||||
|
||||
FIBITMAP* anImageToDump = getImageToDump (anImageFormat);
|
||||
|
||||
if (anImageToDump == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSaved = false;
|
||||
if (theBuffer != NULL)
|
||||
{
|
||||
// a memory buffer wrapped by FreeImage is read only (images can be loaded but not be saved)
|
||||
// so we call FreeImage_OpenMemory() with default arguments and just memcpy in requsted buffer.
|
||||
FIMEMORY* aFiMem = FreeImage_OpenMemory();
|
||||
isSaved = (FreeImage_SaveToMemory (anImageFormat, anImageToDump, aFiMem) != FALSE);
|
||||
BYTE* aData = NULL;
|
||||
DWORD aSize;
|
||||
FreeImage_AcquireMemory (aFiMem, &aData, &aSize);
|
||||
if (aSize > theLength)
|
||||
{
|
||||
Message::SendFail ("Error: memory buffer too small for storing image");
|
||||
return false;
|
||||
}
|
||||
memcpy (theBuffer, aData, aSize);
|
||||
FreeImage_CloseMemory (aFiMem);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _WIN32
|
||||
isSaved = (FreeImage_SaveU (anImageFormat, anImageToDump, aFileNameW.ToWideString ()) != FALSE);
|
||||
#else
|
||||
isSaved = (FreeImage_Save (anImageFormat, anImageToDump, theFileName.ToCString ()) != FALSE);
|
||||
#endif
|
||||
}
|
||||
if (anImageToDump != myLibImage)
|
||||
{
|
||||
FreeImage_Unload (anImageToDump);
|
||||
}
|
||||
return isSaved;
|
||||
|
||||
#elif defined(HAVE_WINCODEC)
|
||||
|
||||
TCollection_AsciiString aFileNameLower = theFileName;
|
||||
aFileNameLower.LowerCase();
|
||||
if (aFileNameLower.EndsWith (".ppm"))
|
||||
{
|
||||
return savePPM (theFileName);
|
||||
}
|
||||
|
||||
GUID aFileFormat = getFileFormatFromName (theFileName);
|
||||
if (aFileFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_ComPtr<IWICImagingFactory> aWicImgFactory;
|
||||
CoInitializeEx (NULL, COINIT_MULTITHREADED);
|
||||
if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot initialize WIC Imaging Factory");
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID aWicPixelFormat = convertToWicFormat (myImgFormat);
|
||||
if (aWicPixelFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_PixMapData* aPixMapData = &myData;
|
||||
Image_PixMapData aConvertedData;
|
||||
if (aFileFormat == GUID_ContainerFormatGif)
|
||||
{
|
||||
aWicPixelFormat = GUID_WICPixelFormat8bppIndexed;
|
||||
convertData (*this, aWicPixelFormat, *aWicImgFactory, aConvertedData);
|
||||
aPixMapData = &aConvertedData;
|
||||
}
|
||||
|
||||
Image_ComPtr<IWICStream> aWicStream;
|
||||
Image_ComPtr<IWICBitmapEncoder> aWicEncoder;
|
||||
const TCollection_ExtendedString aFileNameW (theFileName);
|
||||
if (theBuffer != NULL)
|
||||
{
|
||||
if (aWicImgFactory->CreateStream (&aWicStream.ChangePtr()) != S_OK
|
||||
|| aWicStream->InitializeFromMemory (theBuffer,(DWORD )theLength) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Memory Stream");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (aWicImgFactory->CreateStream (&aWicStream.ChangePtr()) != S_OK
|
||||
|| aWicStream->InitializeFromFilename (aFileNameW.ToWideString(), GENERIC_WRITE) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC File Stream");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (aWicImgFactory->CreateEncoder (aFileFormat, NULL, &aWicEncoder.ChangePtr()) != S_OK
|
||||
|| aWicEncoder->Initialize (aWicStream.get(), WICBitmapEncoderNoCache) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Encoder");
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID aWicPixelFormatRes = aWicPixelFormat;
|
||||
Image_ComPtr<IWICBitmapFrameEncode> aWicFrameEncode;
|
||||
if (aWicEncoder->CreateNewFrame (&aWicFrameEncode.ChangePtr(), NULL) != S_OK
|
||||
|| aWicFrameEncode->Initialize (NULL) != S_OK
|
||||
|| aWicFrameEncode->SetSize ((UINT )SizeX(), (UINT )SizeY()) != S_OK
|
||||
|| aWicFrameEncode->SetPixelFormat (&aWicPixelFormatRes) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Frame");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aFileFormat == GUID_ContainerFormatGif
|
||||
&& (myPalette == NULL
|
||||
|| aWicFrameEncode->SetPalette (myPalette) != S_OK))
|
||||
{
|
||||
Message::SendFail ("Error: cannot set palette");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aWicPixelFormatRes != aWicPixelFormat)
|
||||
{
|
||||
Message::SendFail ("Error: pixel format is unsupported by image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsTopDown())
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels ((UINT )SizeY(), (UINT )SizeRowBytes(), (UINT )SizeBytes(), (BYTE* )aPixMapData->Data()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels (1, (UINT )SizeRowBytes(), (UINT )SizeRowBytes(), (BYTE* )aPixMapData->Row (aRow)) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aWicFrameEncode->Commit() != S_OK
|
||||
|| aWicEncoder->Commit() != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot commit data to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
if (aWicStream->Commit (STGC_DEFAULT) != S_OK)
|
||||
{
|
||||
//Message::Send ("Error: cannot commit data to WIC File Stream", Message_Fail);
|
||||
//return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if (theBuffer != NULL)
|
||||
{
|
||||
Message::SendFail ("Error: no image library available");
|
||||
return false;
|
||||
}
|
||||
const Standard_Integer aLen = theFileName.Length();
|
||||
if ((aLen >= 4) && (theFileName.Value (aLen - 3) == '.')
|
||||
&& strcasecmp( theFileName.ToCString() + aLen - 3, "ppm") == 0 )
|
||||
{
|
||||
return savePPM (theFileName);
|
||||
}
|
||||
Message::SendTrace ("Image_PixMap, no image library available! Image saved in PPM format");
|
||||
return savePPM (theFileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Image_AlienPixMap::Save (std::ostream& theStream, const TCollection_AsciiString& theExtension)
|
||||
{
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
if (myLibImage == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const TCollection_ExtendedString anExtW (theExtension.ToCString(), Standard_True);
|
||||
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilenameU (anExtW.ToWideString());
|
||||
#else
|
||||
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename (theExtension.ToCString());
|
||||
#endif
|
||||
if (anImageFormat == FIF_UNKNOWN)
|
||||
{
|
||||
#ifdef OCCT_DEBUG
|
||||
std::cerr << "Image_PixMap, image format doesn't supported!\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsTopDown())
|
||||
{
|
||||
FreeImage_FlipVertical (myLibImage);
|
||||
SetTopDown (false);
|
||||
}
|
||||
|
||||
FIBITMAP* anImageToDump = getImageToDump (anImageFormat);
|
||||
|
||||
if (anImageToDump == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSaved = false;
|
||||
Image_FreeImageStream aStream (theStream);
|
||||
FreeImageIO anIO = aStream.GetFiIO();
|
||||
|
||||
isSaved = (FreeImage_SaveToHandle(anImageFormat, anImageToDump, &anIO, &aStream) != FALSE);
|
||||
|
||||
if (anImageToDump != myLibImage)
|
||||
{
|
||||
FreeImage_Unload (anImageToDump);
|
||||
}
|
||||
return isSaved;
|
||||
#elif defined(HAVE_WINCODEC)
|
||||
GUID aFileFormat = getFileFormatFromName (theExtension);
|
||||
if (aFileFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_ComPtr<IWICImagingFactory> aWicImgFactory;
|
||||
CoInitializeEx (NULL, COINIT_MULTITHREADED);
|
||||
if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot initialize WIC Imaging Factory");
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID aWicPixelFormat = convertToWicFormat (myImgFormat);
|
||||
if (aWicPixelFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_PixMapData* aPixMapData = &myData;
|
||||
Image_PixMapData aConvertedData;
|
||||
if (aFileFormat == GUID_ContainerFormatGif)
|
||||
{
|
||||
aWicPixelFormat = GUID_WICPixelFormat8bppIndexed;
|
||||
convertData (*this, aWicPixelFormat, *aWicImgFactory, aConvertedData);
|
||||
aPixMapData = &aConvertedData;
|
||||
}
|
||||
|
||||
Image_ComPtr<IStream> aStream;
|
||||
Image_ComPtr<IWICBitmapEncoder> aWicEncoder;
|
||||
|
||||
if (CreateStreamOnHGlobal (NULL, Standard_True, &aStream.ChangePtr()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create Stream on global");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aWicImgFactory->CreateEncoder (aFileFormat, NULL, &aWicEncoder.ChangePtr()) != S_OK
|
||||
|| aWicEncoder->Initialize (aStream.get(), WICBitmapEncoderNoCache) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Encoder");
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID aWicPixelFormatRes = aWicPixelFormat;
|
||||
Image_ComPtr<IWICBitmapFrameEncode> aWicFrameEncode;
|
||||
if (aWicEncoder->CreateNewFrame (&aWicFrameEncode.ChangePtr(), NULL) != S_OK
|
||||
|| aWicFrameEncode->Initialize (NULL) != S_OK
|
||||
|| aWicFrameEncode->SetSize ((UINT )SizeX(), (UINT )SizeY()) != S_OK
|
||||
|| aWicFrameEncode->SetPixelFormat (&aWicPixelFormatRes) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Frame");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aFileFormat == GUID_ContainerFormatGif
|
||||
&& (myPalette == NULL
|
||||
|| aWicFrameEncode->SetPalette (myPalette) != S_OK))
|
||||
{
|
||||
Message::SendFail ("Error: cannot set palette");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aWicPixelFormatRes != aWicPixelFormat)
|
||||
{
|
||||
Message::SendFail ("Error: pixel format is unsupported by image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsTopDown())
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels ((UINT )SizeY(), (UINT )SizeRowBytes(), (UINT )SizeBytes(), (BYTE* )aPixMapData->Data()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels (1, (UINT )SizeRowBytes(), (UINT )SizeRowBytes(), (BYTE* )aPixMapData->Row (aRow)) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (aWicFrameEncode->Commit() != S_OK
|
||||
|| aWicEncoder->Commit() != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot commit data to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
if (aStream->Commit (STGC_DEFAULT) != S_OK)
|
||||
{
|
||||
//Message::Send ("Error: cannot commit data to Stream", Message_Fail);
|
||||
//return false;
|
||||
}
|
||||
|
||||
// WIC doesn't have the way to encode image directly in std::ostream
|
||||
// so we use a workaround to transfer data from IStream to std::ostream
|
||||
STATSTG aStat;
|
||||
if (aStream->Stat (&aStat, STATFLAG_NONAME) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot get stat from stream");
|
||||
return false;
|
||||
}
|
||||
HGLOBAL aMem;
|
||||
if (GetHGlobalFromStream (aStream.get(), &aMem) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot get global from stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
LPVOID aData = GlobalLock (aMem);
|
||||
if (aData == NULL)
|
||||
{
|
||||
Message::SendFail ("Error: cannot lock global");
|
||||
return false;
|
||||
}
|
||||
if (!theStream.write ((const char* )aData, aStat.cbSize.QuadPart))
|
||||
{
|
||||
Message::SendFail ("Error: cannot write data to ostream");
|
||||
return false;
|
||||
}
|
||||
if (GlobalUnlock (aMem) == 0 && GetLastError() != NO_ERROR)
|
||||
{
|
||||
Message::SendFail ("Error: cannot unlock global");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
Message::SendFail ("Error: no image library available");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AdjustGamma
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Image_AlienPixMap::AdjustGamma (const Standard_Real theGammaCorr)
|
||||
{
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
return FreeImage_AdjustGamma (myLibImage, theGammaCorr) != FALSE;
|
||||
#else
|
||||
(void )theGammaCorr;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
// =======================================================================
|
||||
// function : GetImageToDump
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
FIBITMAP* Image_AlienPixMap::getImageToDump (const Standard_Integer theFormat)
|
||||
{
|
||||
FIBITMAP* anImageToDump = myLibImage;
|
||||
// FreeImage doesn't provide flexible format conversion API
|
||||
// so we should perform multiple conversions in some cases!
|
||||
switch (theFormat)
|
||||
FIBITMAP* anImageToDump = myLibImage;
|
||||
switch (anImageFormat)
|
||||
{
|
||||
case FIF_PNG:
|
||||
case FIF_BMP:
|
||||
@@ -1510,7 +973,7 @@ FIBITMAP* Image_AlienPixMap::getImageToDump (const Standard_Integer theFormat)
|
||||
aTmpBitmap = FreeImage_ConvertToType (myLibImage, FIT_BITMAP);
|
||||
if (aTmpBitmap == NULL)
|
||||
{
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1523,7 +986,7 @@ FIBITMAP* Image_AlienPixMap::getImageToDump (const Standard_Integer theFormat)
|
||||
}
|
||||
if (aTmpBitmap24 == NULL)
|
||||
{
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
aTmpBitmap = aTmpBitmap24;
|
||||
}
|
||||
@@ -1568,7 +1031,7 @@ FIBITMAP* Image_AlienPixMap::getImageToDump (const Standard_Integer theFormat)
|
||||
anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_BITMAP);
|
||||
if (anImageToDump == NULL)
|
||||
{
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1581,13 +1044,170 @@ FIBITMAP* Image_AlienPixMap::getImageToDump (const Standard_Integer theFormat)
|
||||
}
|
||||
if (aTmpBitmap24 == NULL)
|
||||
{
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
anImageToDump = aTmpBitmap24;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return anImageToDump;
|
||||
}
|
||||
|
||||
if (anImageToDump == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool isSaved = (FreeImage_SaveU (anImageFormat, anImageToDump, aFileNameW.ToWideString()) != FALSE);
|
||||
#else
|
||||
bool isSaved = (FreeImage_Save (anImageFormat, anImageToDump, theFileName.ToCString()) != FALSE);
|
||||
#endif
|
||||
if (anImageToDump != myLibImage)
|
||||
{
|
||||
FreeImage_Unload (anImageToDump);
|
||||
}
|
||||
return isSaved;
|
||||
|
||||
#elif defined(HAVE_WINCODEC)
|
||||
|
||||
TCollection_AsciiString aFileNameLower = theFileName;
|
||||
aFileNameLower.LowerCase();
|
||||
GUID aFileFormat = getNullGuid();
|
||||
if (aFileNameLower.EndsWith (".ppm"))
|
||||
{
|
||||
return savePPM (theFileName);
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".bmp"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatBmp;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".png"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatPng;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".jpg")
|
||||
|| aFileNameLower.EndsWith (".jpeg"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatJpeg;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".tiff")
|
||||
|| aFileNameLower.EndsWith (".tif"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatTiff;
|
||||
}
|
||||
else if (aFileNameLower.EndsWith (".gif"))
|
||||
{
|
||||
aFileFormat = GUID_ContainerFormatGif;
|
||||
}
|
||||
|
||||
if (aFileFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_ComPtr<IWICImagingFactory> aWicImgFactory;
|
||||
CoInitializeEx (NULL, COINIT_MULTITHREADED);
|
||||
if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot initialize WIC Imaging Factory");
|
||||
return false;
|
||||
}
|
||||
|
||||
Image_ComPtr<IWICStream> aWicFileStream;
|
||||
Image_ComPtr<IWICBitmapEncoder> aWicEncoder;
|
||||
const TCollection_ExtendedString aFileNameW (theFileName);
|
||||
if (aWicImgFactory->CreateStream (&aWicFileStream.ChangePtr()) != S_OK
|
||||
|| aWicFileStream->InitializeFromFilename (aFileNameW.ToWideString(), GENERIC_WRITE) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC File Stream");
|
||||
return false;
|
||||
}
|
||||
if (aWicImgFactory->CreateEncoder (aFileFormat, NULL, &aWicEncoder.ChangePtr()) != S_OK
|
||||
|| aWicEncoder->Initialize (aWicFileStream.get(), WICBitmapEncoderNoCache) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Encoder");
|
||||
return false;
|
||||
}
|
||||
|
||||
const WICPixelFormatGUID aWicPixelFormat = convertToWicFormat (myImgFormat);
|
||||
if (aWicPixelFormat == getNullGuid())
|
||||
{
|
||||
Message::SendFail ("Error: unsupported pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID aWicPixelFormatRes = aWicPixelFormat;
|
||||
Image_ComPtr<IWICBitmapFrameEncode> aWicFrameEncode;
|
||||
if (aWicEncoder->CreateNewFrame (&aWicFrameEncode.ChangePtr(), NULL) != S_OK
|
||||
|| aWicFrameEncode->Initialize (NULL) != S_OK
|
||||
|| aWicFrameEncode->SetSize ((UINT )SizeX(), (UINT )SizeY()) != S_OK
|
||||
|| aWicFrameEncode->SetPixelFormat (&aWicPixelFormatRes) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot create WIC Frame");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aWicPixelFormatRes != aWicPixelFormat)
|
||||
{
|
||||
Message::SendFail ("Error: pixel format is unsupported by image format");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsTopDown())
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels ((UINT )SizeY(), (UINT )SizeRowBytes(), (UINT )SizeBytes(), (BYTE* )Data()) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
|
||||
{
|
||||
if (aWicFrameEncode->WritePixels (1, (UINT )SizeRowBytes(), (UINT )SizeRowBytes(), (BYTE* )Row (aRow)) != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot write pixels to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aWicFrameEncode->Commit() != S_OK
|
||||
|| aWicEncoder->Commit() != S_OK)
|
||||
{
|
||||
Message::SendFail ("Error: cannot commit data to WIC Frame");
|
||||
return false;
|
||||
}
|
||||
if (aWicFileStream->Commit (STGC_DEFAULT) != S_OK)
|
||||
{
|
||||
//Message::Send ("Error: cannot commit data to WIC File Stream", Message_Fail);
|
||||
//return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
const Standard_Integer aLen = theFileName.Length();
|
||||
if ((aLen >= 4) && (theFileName.Value (aLen - 3) == '.')
|
||||
&& strcasecmp( theFileName.ToCString() + aLen - 3, "ppm") == 0 )
|
||||
{
|
||||
return savePPM (theFileName);
|
||||
}
|
||||
Message::SendTrace ("Image_PixMap, no image library available! Image saved in PPM format");
|
||||
return savePPM (theFileName);
|
||||
#endif
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : AdjustGamma
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
bool Image_AlienPixMap::AdjustGamma (const Standard_Real theGammaCorr)
|
||||
{
|
||||
#ifdef HAVE_FREEIMAGE
|
||||
return FreeImage_AdjustGamma (myLibImage, theGammaCorr) != FALSE;
|
||||
#else
|
||||
(void )theGammaCorr;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@
|
||||
#include <Image_PixMap.hxx>
|
||||
|
||||
class TCollection_AsciiString;
|
||||
struct IWICPalette;
|
||||
struct FIBITMAP;
|
||||
|
||||
//! Image class that support file reading/writing operations using auxiliary image library.
|
||||
@@ -58,41 +57,21 @@ public:
|
||||
const TCollection_AsciiString& theFileName);
|
||||
|
||||
//! Read image data from memory buffer.
|
||||
//! @param[in] theData memory pointer to read from;
|
||||
//! @param theData memory pointer to read from;
|
||||
//! when NULL, function will attempt to open theFileName file
|
||||
//! @param[in] theLength memory buffer length
|
||||
//! @param[in] theFileName optional file name
|
||||
//! @param theLength memory buffer length
|
||||
//! @param theFileName optional file name
|
||||
Standard_EXPORT bool Load (const Standard_Byte* theData,
|
||||
const Standard_Size theLength,
|
||||
Standard_Size theLength,
|
||||
const TCollection_AsciiString& theFileName);
|
||||
|
||||
//! Write image data to file.
|
||||
//! @param[in] theFileName file name to save
|
||||
bool Save (const TCollection_AsciiString& theFileName)
|
||||
{
|
||||
return Save (NULL, 0, theFileName);
|
||||
}
|
||||
|
||||
//! Write image data to stream.
|
||||
//! @param[out] theStream stream where to write
|
||||
//! @param[in] theExtension image format
|
||||
Standard_EXPORT bool Save (std::ostream& theStream,
|
||||
const TCollection_AsciiString& theExtension);
|
||||
|
||||
//! Write image data to file or memory buffer using file extension to determine format.
|
||||
//! @param[out] theBuffer buffer pointer where to write
|
||||
//! when NULL, function write image data to theFileName file
|
||||
//! @param[in] theLength memory buffer length
|
||||
//! @param[in] theFileName file name to save;
|
||||
//! when theBuffer isn't NULL used only to determine format
|
||||
Standard_EXPORT bool Save (Standard_Byte* theBuffer,
|
||||
const Standard_Size theLength,
|
||||
const TCollection_AsciiString& theFileName);
|
||||
//! Write image data to file using file extension to determine compression format.
|
||||
Standard_EXPORT bool Save (const TCollection_AsciiString& theFileName);
|
||||
|
||||
//! Initialize image plane with required dimensions.
|
||||
//! @param[in] thePixelFormat if specified pixel format doesn't supported by image library
|
||||
//! thePixelFormat - if specified pixel format doesn't supported by image library
|
||||
//! than nearest supported will be used instead!
|
||||
//! @param[in] theSizeRowBytes may be ignored by this class and required alignment will be used instead!
|
||||
//! theSizeRowBytes - may be ignored by this class and required alignment will be used instead!
|
||||
Standard_EXPORT virtual bool InitTrash (Image_Format thePixelFormat,
|
||||
const Standard_Size theSizeX,
|
||||
const Standard_Size theSizeY,
|
||||
@@ -105,13 +84,12 @@ public:
|
||||
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
|
||||
|
||||
//! Performs gamma correction on image.
|
||||
//! @param[in] theGamma - gamma value to use; a value of 1.0 leaves the image alone
|
||||
//! theGamma - gamma value to use; a value of 1.0 leaves the image alone
|
||||
Standard_EXPORT bool AdjustGamma (const Standard_Real theGammaCorr);
|
||||
|
||||
#if !defined(HAVE_FREEIMAGE) && defined(_WIN32)
|
||||
//! Returns image palette.
|
||||
IWICPalette* GetPalette() const { return myPalette; }
|
||||
#endif
|
||||
private:
|
||||
|
||||
FIBITMAP* myLibImage;
|
||||
|
||||
private:
|
||||
|
||||
@@ -130,13 +108,6 @@ private:
|
||||
//! Built-in PPM export
|
||||
Standard_EXPORT bool savePPM (const TCollection_AsciiString& theFileName) const;
|
||||
|
||||
FIBITMAP* getImageToDump (const Standard_Integer theFormat);
|
||||
|
||||
private:
|
||||
|
||||
FIBITMAP* myLibImage;
|
||||
IWICPalette* myPalette;
|
||||
|
||||
};
|
||||
|
||||
DEFINE_STANDARD_HANDLE(Image_AlienPixMap, Image_PixMap)
|
||||
|
@@ -224,7 +224,7 @@ const gp_Pnt &IntTools_SurfaceRangeLocalizeData::GetPointInFrame
|
||||
Standard_Integer aFrmUInd = theUIndex + myUIndMin - 1;
|
||||
Standard_Integer aFrmVInd = theVIndex + myVIndMin - 1;
|
||||
|
||||
if (myGridPoints.IsNull() || aFrmUInd > myUIndMax || aFrmVInd > myVIndMax)
|
||||
if (aFrmUInd > myUIndMax || aFrmVInd > myVIndMax)
|
||||
return gp::Origin();
|
||||
|
||||
return myGridPoints->Value(aFrmUInd, aFrmVInd);
|
||||
@@ -235,7 +235,7 @@ Standard_Real IntTools_SurfaceRangeLocalizeData::GetUParamInFrame
|
||||
{
|
||||
Standard_Integer aFrmInd = theIndex + myUIndMin - 1;
|
||||
|
||||
if (myUParams.IsNull() || aFrmInd > myUIndMax)
|
||||
if (aFrmInd > myUIndMax)
|
||||
return Precision::Infinite();
|
||||
|
||||
return myUParams->Value(aFrmInd);
|
||||
@@ -246,7 +246,7 @@ Standard_Real IntTools_SurfaceRangeLocalizeData::GetVParamInFrame
|
||||
{
|
||||
Standard_Integer aFrmInd = theIndex + myVIndMin - 1;
|
||||
|
||||
if (myVParams.IsNull() || aFrmInd > myVIndMax)
|
||||
if (aFrmInd > myVIndMax)
|
||||
return Precision::Infinite();
|
||||
|
||||
return myVParams->Value(aFrmInd);
|
||||
|
@@ -387,11 +387,11 @@ static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, co
|
||||
//function : OCC30182
|
||||
//purpose : Testing different interfaces of Image_AlienPixMap::Load()
|
||||
//=======================================================================
|
||||
static Standard_Integer OCC30182 (Draw_Interpretor& di, Standard_Integer theNbArgs, const char** theArgVec)
|
||||
static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
|
||||
{
|
||||
if (ViewerTest::CurrentView().IsNull())
|
||||
{
|
||||
di << "Error: no active view\n";
|
||||
std::cout << "Error: no active view\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -430,13 +430,13 @@ static Standard_Integer OCC30182 (Draw_Interpretor& di, Standard_Integer theNbAr
|
||||
}
|
||||
else
|
||||
{
|
||||
di << "Syntax error at '" << anArg << "'\n";
|
||||
std::cout << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (anImgPath.IsEmpty())
|
||||
{
|
||||
di << "Syntax error: wrong number of arguments\n";
|
||||
std::cout << "Syntax error: wrong number of arguments\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ static Standard_Integer OCC30182 (Draw_Interpretor& di, Standard_Integer theNbAr
|
||||
std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (anImgPath, std::ios::in | std::ios::binary);
|
||||
if (aFile.get() == NULL)
|
||||
{
|
||||
di << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
|
||||
std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
|
||||
return 1;
|
||||
}
|
||||
if (anOffset != 0)
|
||||
@@ -469,13 +469,13 @@ static Standard_Integer OCC30182 (Draw_Interpretor& di, Standard_Integer theNbAr
|
||||
aFile->seekg (anOffset);
|
||||
if (aLen <= 0)
|
||||
{
|
||||
di << "Syntax error: wrong offset\n";
|
||||
std::cout << "Syntax error: wrong offset\n";
|
||||
return 1;
|
||||
}
|
||||
NCollection_Array1<Standard_Byte> aBuff (1, aLen);
|
||||
if (!aFile->read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
|
||||
{
|
||||
di << "Error: unable to read file\n";
|
||||
std::cout << "Error: unable to read file\n";
|
||||
return 1;
|
||||
}
|
||||
if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
|
||||
@@ -510,107 +510,6 @@ static Standard_Integer OCC30182 (Draw_Interpretor& di, Standard_Integer theNbAr
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : OCC31956
|
||||
//purpose : Testing Image_AlienPixMap::Save() overload for saving into a memory buffer or stream
|
||||
//=======================================================================
|
||||
static Standard_Integer OCC31956 (Draw_Interpretor& di, Standard_Integer theNbArgs, const char** theArgVec)
|
||||
{
|
||||
if (ViewerTest::CurrentView().IsNull())
|
||||
{
|
||||
di << "Error: no active view\n";
|
||||
return 1;
|
||||
}
|
||||
if (theNbArgs != 3 && theNbArgs != 5)
|
||||
{
|
||||
di << "Syntax error: wrong number of arguments\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool useStream = false;
|
||||
TCollection_AsciiString aTempImgPath;
|
||||
if (theNbArgs == 5)
|
||||
{
|
||||
TCollection_AsciiString anArg (theArgVec[3]);
|
||||
anArg.LowerCase();
|
||||
if (anArg == "-stream")
|
||||
{
|
||||
useStream = true;
|
||||
aTempImgPath = theArgVec[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
di << "Syntax error at '" << anArg << "'\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
TCollection_AsciiString aPrsName, anImgPath;
|
||||
aPrsName = theArgVec[1];
|
||||
anImgPath = theArgVec[2];
|
||||
Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
|
||||
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
|
||||
opencascade::std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (anImgPath, std::ios::in | std::ios::binary);
|
||||
if (aFile.get() == NULL)
|
||||
{
|
||||
di << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
aFile->seekg (0, std::ios::end);
|
||||
Standard_Integer aLen = (Standard_Integer )aFile->tellg();
|
||||
aFile->seekg (0);
|
||||
if (!anImage->Load (*aFile, anImgPath))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Handle(Image_AlienPixMap) aControlImg = new Image_AlienPixMap();
|
||||
if (useStream)
|
||||
{
|
||||
opencascade::std::shared_ptr<std::ostream> aTempFile = aFileSystem->OpenOStream (aTempImgPath, std::ios::out | std::ios::binary);
|
||||
if (aTempFile.get() == NULL)
|
||||
{
|
||||
di << "Error: image file '" << aTempImgPath << "' cannot be open\n";
|
||||
return 0;
|
||||
}
|
||||
if (!anImage->Save (*aTempFile, aTempImgPath))
|
||||
{
|
||||
di << "Error: failed saving file using stream '" << aTempImgPath << "'\n";
|
||||
return 0;
|
||||
}
|
||||
aTempFile.reset();
|
||||
aControlImg->Load (aTempImgPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
NCollection_Array1<Standard_Byte> aBuff (1, aLen + 2048);
|
||||
if (!anImage->Save (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
|
||||
{
|
||||
di << "Error: failed saving file using buffer'" << anImgPath << "'\n";
|
||||
return 0;
|
||||
}
|
||||
aControlImg->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath);
|
||||
}
|
||||
|
||||
TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100.0 * aControlImg->Ratio(), 100.0, 1.0).Shape();
|
||||
Handle(AIS_Shape) aPrs = new AIS_Shape (aShape);
|
||||
aPrs->SetDisplayMode (AIS_Shaded);
|
||||
aPrs->Attributes()->SetupOwnShadingAspect();
|
||||
const Handle(Graphic3d_AspectFillArea3d)& anAspect = aPrs->Attributes()->ShadingAspect()->Aspect();
|
||||
anAspect->SetShadingModel (Graphic3d_TOSM_UNLIT);
|
||||
anAspect->SetTextureMapOn (true);
|
||||
anAspect->SetTextureMap (new Graphic3d_Texture2D(aControlImg));
|
||||
if (aControlImg->IsTopDown())
|
||||
{
|
||||
anAspect->TextureMap()->GetParams()->SetTranslation (Graphic3d_Vec2 (0.0f, -1.0f));
|
||||
anAspect->TextureMap()->GetParams()->SetScale (Graphic3d_Vec2 (1.0f, -1.0f));
|
||||
}
|
||||
|
||||
ViewerTest::Display (aPrsName, aPrs, true, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QABugs::Commands_1(Draw_Interpretor& theCommands) {
|
||||
const char *group = "QABugs";
|
||||
|
||||
@@ -628,7 +527,5 @@ void QABugs::Commands_1(Draw_Interpretor& theCommands) {
|
||||
theCommands.Add ("OCC30182",
|
||||
"OCC30182 name image [-offset Start] [-fileName] [-stream] [-memory]\n"
|
||||
"Decodes image either by passing file name, file stream or memory stream", __FILE__, OCC30182, group);
|
||||
theCommands.Add ("OCC31956", "OCC31956 name image [-stream tempImage]\n"
|
||||
"Loads image and saves it into memory buffer or stream then loads it back", __FILE__, OCC31956, group);
|
||||
return;
|
||||
}
|
||||
|
@@ -17,41 +17,8 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if(defined(_MSC_VER) && (_MSC_VER < 1800))
|
||||
// only Visual Studio 2013 (vc12) provides <cinttypes> header
|
||||
// we do not defined all macros here - only used by OCCT framework
|
||||
#define PRIx64 "I64x"
|
||||
#define PRIX64 "I64X"
|
||||
#define PRId64 "I64d"
|
||||
#define PRIu64 "I64u"
|
||||
#define SCNd64 "I64d"
|
||||
#define SCNu64 "I64u"
|
||||
#ifdef _WIN64
|
||||
#define PRIxPTR "I64x"
|
||||
#define PRIXPTR "I64X"
|
||||
#define PRIdPTR "I64d"
|
||||
#define PRIuPTR "I64u"
|
||||
#define SCNdPTR "I64d"
|
||||
#define SCNuPTR "I64u"
|
||||
#else
|
||||
#define PRIxPTR "Ix"
|
||||
#define PRIXPTR "IX"
|
||||
#define PRIdPTR "d"
|
||||
#define PRIuPTR "u"
|
||||
#define SCNdPTR "d"
|
||||
#define SCNuPTR "u"
|
||||
#endif
|
||||
#else
|
||||
// should be just <cinttypes> since C++11
|
||||
// however we use this code for compatibility with old C99 compilers
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
|
||||
#define Standard_False false
|
||||
#define Standard_True true
|
||||
|
@@ -2,9 +2,7 @@
|
||||
// This file is generated, do not modify it directly; edit source file step.lex instead.
|
||||
|
||||
// Pre-include stdlib.h to avoid redefinition of integer type macros (INT8_MIN and similar in generated code)
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1600) // Visual Studio 2010+
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include <Standard_TypeDef.hxx>
|
||||
|
||||
#define YY_INT_ALIGNED short int
|
||||
|
||||
|
@@ -33,9 +33,7 @@
|
||||
// This file is generated, do not modify it directly; edit source file step.lex instead.
|
||||
|
||||
// Pre-include stdlib.h to avoid redefinition of integer type macros (INT8_MIN and similar in generated code)
|
||||
#if !defined(_MSC_VER) || (_MSC_VER >= 1600) // Visual Studio 2010+
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
#include <Standard_TypeDef.hxx>
|
||||
}
|
||||
|
||||
%{
|
||||
|
@@ -1,10 +0,0 @@
|
||||
puts "========================"
|
||||
puts "0033414: Modeling Algorithms - Access violation during executing BRepAlgoAPI_Section::Build()"
|
||||
puts "========================"
|
||||
|
||||
set filepath1 [locate_data_file "CR33414_1.brep"]
|
||||
set filepath2 [locate_data_file "CR33414_2.brep"]
|
||||
restore ${filepath1} shape1
|
||||
restore ${filepath2} shape2
|
||||
bsection res shape1 shape2
|
||||
# If bsection didn't cause a crash - everything is OK.
|
@@ -1,41 +0,0 @@
|
||||
puts "============"
|
||||
puts "0031956: Visualization - provide Image_AlienPixMap::Save() writing into a memory buffer instead of a file"
|
||||
puts "============"
|
||||
puts ""
|
||||
|
||||
set anImg1 [locate_data_file chataignier.gif]
|
||||
set anImg2 [locate_data_file hatch_1.png]
|
||||
|
||||
pload VISUALIZATION QAcommands
|
||||
vclear
|
||||
vinit View1
|
||||
vtop
|
||||
|
||||
OCC30182 t $anImg1 -fileName; vfit
|
||||
vdump $imagedir/${casename}_1.png
|
||||
|
||||
OCC30182 t $anImg2 -fileName; vfit
|
||||
vdump $imagedir/${casename}_2.png
|
||||
|
||||
vclear
|
||||
|
||||
OCC31956 t $anImg1; vfit
|
||||
vdump $imagedir/${casename}_test_1.png
|
||||
|
||||
OCC31956 t $anImg2; vfit
|
||||
vdump $imagedir/${casename}_test_2.png
|
||||
|
||||
vclear
|
||||
|
||||
OCC31956 t $anImg1 -stream $imagedir/${casename}_temp_1.gif; vfit
|
||||
vdump $imagedir/${casename}_test_1s.png
|
||||
|
||||
OCC31956 t $anImg2 -stream $imagedir/${casename}_temp_2.png; vfit
|
||||
vdump $imagedir/${casename}_test_2s.png
|
||||
|
||||
if { [diffimage $imagedir/${casename}_test_1.png $imagedir/${casename}_1.png -toleranceOfColor 0.1] != 0 } { puts "Error difference in 1st image" }
|
||||
if { [diffimage $imagedir/${casename}_test_2.png $imagedir/${casename}_2.png -toleranceOfColor 0.1] != 0 } { puts "Error difference in 2nd image" }
|
||||
|
||||
if { [diffimage $imagedir/${casename}_test_1s.png $imagedir/${casename}_1.png -toleranceOfColor 0.1] != 0 } { puts "Error difference in 1st image (using stream)" }
|
||||
if { [diffimage $imagedir/${casename}_test_2s.png $imagedir/${casename}_2.png -toleranceOfColor 0.1] != 0 } { puts "Error difference in 2nd image (using stream)" }
|
||||
|
Reference in New Issue
Block a user