0030182: Visualization, Image_AlienPixMap - support reading encoded image from memory... IR-2019-03-01
authorkgv <kgv@opencascade.com>
Thu, 28 Feb 2019 22:26:20 +0000 (01:26 +0300)
committerapn <apn@opencascade.com>
Sun, 3 Mar 2019 17:59:18 +0000 (20:59 +0300)
Added two new Image_AlienPixMap::Load() methods, taking std::istream
and memory buffer (pointer, length) arguments.
This allows reading image from application memory or from file with non-zero offset.

Added Image_AlienPixMap::IsTopDownDefault() static property allowing to query rows order used by linked image library,
so that application might generate UV texture coordinates accordingly.

Added missing Release() to IWICImagingFactory instance.

src/Image/Image_AlienPixMap.cxx
src/Image/Image_AlienPixMap.hxx
src/QABugs/QABugs_1.cxx
src/QABugs/QABugs_17.cxx
tests/bugs/vis/bug1188
tests/bugs/vis/bug25475
tests/bugs/vis/bug30182 [new file with mode: 0644]

index f7ed44a..ba166a5 100644 (file)
@@ -34,6 +34,8 @@
 #include <gp.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
+#include <NCollection_Array1.hxx>
+#include <Standard_ArrayStreamBuffer.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 #include <OSD_OpenFile.hxx>
@@ -110,6 +112,109 @@ namespace
         return FIT_UNKNOWN;
     }
   }
+
+  //! Wrapper for accessing C++ stream from FreeImage.
+  class Image_FreeImageStream
+  {
+  public:
+    //! Construct wrapper over input stream.
+    Image_FreeImageStream (std::istream& theStream)
+    : myIStream (&theStream), myOStream (NULL), myInitPos (theStream.tellg()) {}
+
+    //! Get io object.
+    FreeImageIO GetFiIO() const
+    {
+      FreeImageIO anIo;
+      memset (&anIo, 0, sizeof(anIo));
+      if (myIStream != NULL)
+      {
+        anIo.read_proc = readProc;
+        anIo.seek_proc = seekProc;
+        anIo.tell_proc = tellProc;
+      }
+      if (myOStream != NULL)
+      {
+        anIo.write_proc = writeProc;
+      }
+      return anIo;
+    }
+  public:
+    //! Simulate fread().
+    static unsigned int DLL_CALLCONV readProc (void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
+    {
+      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      if (aThis->myIStream == NULL)
+      {
+        return 0;
+      }
+
+      if (!aThis->myIStream->read ((char* )theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
+      {
+        //aThis->myIStream->clear();
+      }
+      const std::streamsize aNbRead = aThis->myIStream->gcount();
+      return (unsigned int )(aNbRead / theSize);
+    }
+
+    //! Simulate fwrite().
+    static unsigned int DLL_CALLCONV writeProc (void* theBuffer, unsigned int theSize, unsigned int theCount, fi_handle theHandle)
+    {
+      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      if (aThis->myOStream != NULL
+       && aThis->myOStream->write ((const char* )theBuffer, std::streamsize(theSize) * std::streamsize(theCount)))
+      {
+        return theCount;
+      }
+      return 0;
+    }
+
+    //! Simulate fseek().
+    static int DLL_CALLCONV seekProc (fi_handle theHandle, long theOffset, int theOrigin)
+    {
+      Image_FreeImageStream* aThis = (Image_FreeImageStream* )theHandle;
+      if (aThis->myIStream == NULL)
+      {
+        return -1;
+      }
+
+      bool isSeekDone = false;
+      switch (theOrigin)
+      {
+        case SEEK_SET:
+          if (aThis->myIStream->seekg ((std::streamoff )aThis->myInitPos + theOffset, std::ios::beg))
+          {
+            isSeekDone = true;
+          }
+          break;
+        case SEEK_CUR:
+          if (aThis->myIStream->seekg (theOffset, std::ios::cur))
+          {
+            isSeekDone = true;
+          }
+          break;
+        case SEEK_END:
+          if (aThis->myIStream->seekg (theOffset, std::ios::end))
+          {
+            isSeekDone = true;
+          }
+          break;
+      }
+      return isSeekDone ? 0 : -1;
+    }
+
+    //! Simulate ftell().
+    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;
+    }
+  private:
+    std::istream*  myIStream;
+    std::ostream*  myOStream;
+    std::streampos myInitPos;
+  };
+
 #elif defined(HAVE_WINCODEC)
 
   //! Return a zero GUID
@@ -385,20 +490,49 @@ void Image_AlienPixMap::Clear()
 }
 
 // =======================================================================
+// function : IsTopDownDefault
+// purpose  :
+// =======================================================================
+bool Image_AlienPixMap::IsTopDownDefault()
+{
+#ifdef HAVE_FREEIMAGE
+  return false;
+#elif defined(HAVE_WINCODEC)
+  return true;
+#else
+  return false;
+#endif
+}
+
+// =======================================================================
 // function : Load
 // purpose  :
 // =======================================================================
 #ifdef HAVE_FREEIMAGE
-bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
+bool Image_AlienPixMap::Load (const Standard_Byte* theData,
+                              Standard_Size theLength,
+                              const TCollection_AsciiString& theImagePath)
 {
   Clear();
 
 #ifdef _WIN32
   const TCollection_ExtendedString aFileNameW (theImagePath);
-  FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileTypeU (aFileNameW.ToWideString(), 0);
-#else
-  FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileType (theImagePath.ToCString(), 0);
 #endif
+  FREE_IMAGE_FORMAT aFIF = FIF_UNKNOWN;
+  FIMEMORY* aFiMem = NULL;
+  if (theData != NULL)
+  {
+    aFiMem = FreeImage_OpenMemory ((BYTE* )theData, (DWORD )theLength);
+    aFIF = FreeImage_GetFileTypeFromMemory (aFiMem, 0);
+  }
+  else
+  {
+  #ifdef _WIN32
+    aFIF = FreeImage_GetFileTypeU (aFileNameW.ToWideString(), 0);
+  #else
+    aFIF = FreeImage_GetFileType (theImagePath.ToCString(), 0);
+  #endif
+  }
   if (aFIF == FIF_UNKNOWN)
   {
     // no signature? try to guess the file format from the file extension
@@ -406,10 +540,12 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
   }
   if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading (aFIF))
   {
-    TCollection_AsciiString aMessage = "Error: image file '";
-    aMessage.AssignCat (theImagePath);
-    aMessage.AssignCat ("' has unsupported file format.");
-    ::Message::DefaultMessenger()->Send (aMessage, Message_Fail);
+    ::Message::DefaultMessenger()->Send (TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported file format.",
+                                         Message_Fail);
+    if (aFiMem != NULL)
+    {
+      FreeImage_CloseMemory (aFiMem);
+    }
     return false;
   }
 
@@ -425,11 +561,21 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
     aLoadFlags = ICO_MAKEALPHA;
   }
 
-#ifdef _WIN32
-  FIBITMAP* anImage = FreeImage_LoadU (aFIF, aFileNameW.ToWideString(), aLoadFlags);
-#else
-  FIBITMAP* anImage = FreeImage_Load  (aFIF, theImagePath.ToCString(), aLoadFlags);
-#endif
+  FIBITMAP* anImage = NULL;
+  if (theData != NULL)
+  {
+    anImage = FreeImage_LoadFromMemory (aFIF, aFiMem, aLoadFlags);
+    FreeImage_CloseMemory (aFiMem);
+    aFiMem = NULL;
+  }
+  else
+  {
+  #ifdef _WIN32
+    anImage = FreeImage_LoadU (aFIF, aFileNameW.ToWideString(), aLoadFlags);
+  #else
+    anImage = FreeImage_Load  (aFIF, theImagePath.ToCString(), aLoadFlags);
+  #endif
+  }
   if (anImage == NULL)
   {
     TCollection_AsciiString aMessage = "Error: image file '";
@@ -445,10 +591,8 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
   if (aFormat == Image_Format_UNKNOWN)
   {
     //anImage = FreeImage_ConvertTo24Bits (anImage);
-    TCollection_AsciiString aMessage = "Error: image file '";
-    aMessage.AssignCat (theImagePath);
-    aMessage.AssignCat ("' has unsupported pixel format.");
-    ::Message::DefaultMessenger()->Send (aMessage, Message_Fail);
+    ::Message::DefaultMessenger()->Send (    TCollection_AsciiString ("Error: image '") + theImagePath + "' has unsupported pixel format.",
+                                         Message_Fail);
     return false;
   }
 
@@ -460,25 +604,106 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
   myLibImage = anImage;
   return true;
 }
+
+bool Image_AlienPixMap::Load (std::istream& theStream,
+                              const TCollection_AsciiString& theFileName)
+{
+  Clear();
+
+  Image_FreeImageStream aStream (theStream);
+  FreeImageIO aFiIO = aStream.GetFiIO();
+
+  FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileTypeFromHandle (&aFiIO, &aStream, 0);
+  if (aFIF == FIF_UNKNOWN)
+  {
+    // no signature? try to guess the file format from the file extension
+    aFIF = FreeImage_GetFIFFromFilename (theFileName.ToCString());
+  }
+  if ((aFIF == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading (aFIF))
+  {
+    ::Message::DefaultMessenger()->Send (TCollection_AsciiString ("Error: image stream '") + theFileName + "' has unsupported file format.",
+                                         Message_Fail);
+    return false;
+  }
+
+  int aLoadFlags = 0;
+  if (aFIF == FIF_GIF)
+  {
+    // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading
+    aLoadFlags = GIF_PLAYBACK;
+  }
+  else if (aFIF == FIF_ICO)
+  {
+    // convert to 32bpp and create an alpha channel from the AND-mask when loading
+    aLoadFlags = ICO_MAKEALPHA;
+  }
+
+  FIBITMAP* anImage = FreeImage_LoadFromHandle (aFIF, &aFiIO, &aStream, aLoadFlags);
+  if (anImage == NULL)
+  {
+    ::Message::DefaultMessenger()->Send (TCollection_AsciiString ("Error: image stream '") + theFileName + "' is missing or invalid.",
+                                         Message_Fail);
+    return false;
+  }
+
+  Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
+                                                FreeImage_GetColorType(anImage),
+                                                FreeImage_GetBPP      (anImage));
+  if (aFormat == Image_Format_UNKNOWN)
+  {
+    ::Message::DefaultMessenger()->Send (TCollection_AsciiString ("Error: image stream '") + theFileName + "' has unsupported pixel format.",
+                                         Message_Fail);
+    return false;
+  }
+
+  Image_PixMap::InitWrapper (aFormat, FreeImage_GetBits (anImage),
+                             FreeImage_GetWidth (anImage), FreeImage_GetHeight (anImage), FreeImage_GetPitch (anImage));
+  SetTopDown (false);
+
+  // assign image after wrapper initialization (virtual Clear() called inside)
+  myLibImage = anImage;
+  return true;
+}
+
 #elif defined(HAVE_WINCODEC)
-bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
+bool Image_AlienPixMap::Load (const Standard_Byte* theData,
+                              Standard_Size theLength,
+                              const TCollection_AsciiString& theFileName)
 {
   Clear();
 
-  IWICImagingFactory* aWicImgFactory = NULL;
+  Image_ComPtr<IWICImagingFactory> aWicImgFactory;
   CoInitializeEx (NULL, COINIT_MULTITHREADED);
-  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory)) != S_OK)
+  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
   {
     Message::DefaultMessenger()->Send ("Error: cannot initialize WIC Imaging Factory", Message_Fail);
     return false;
   }
 
   Image_ComPtr<IWICBitmapDecoder> aWicDecoder;
-  const TCollection_ExtendedString aFileNameW (theImagePath);
-  if (aWicImgFactory->CreateDecoderFromFilename (aFileNameW.ToWideString(), NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
+  Image_ComPtr<IWICStream> aWicStream;
+  if (theData != NULL)
   {
-    Message::DefaultMessenger()->Send ("Error: cannot create WIC Image Decoder", Message_Fail);
-    return false;
+    if (aWicImgFactory->CreateStream (&aWicStream.ChangePtr()) != S_OK
+     || aWicStream->InitializeFromMemory ((BYTE* )theData, (DWORD )theLength) != S_OK)
+    {
+      Message::DefaultMessenger()->Send ("Error: cannot initialize WIC Stream", Message_Fail);
+      return false;
+    }
+    if (aWicImgFactory->CreateDecoderFromStream (aWicStream.get(), NULL, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
+    {
+      Message::DefaultMessenger()->Send ("Error: cannot create WIC Image Decoder", Message_Fail);
+      return false;
+    }
+  }
+  else
+  {
+    const TCollection_ExtendedString aFileNameW (theFileName);
+    if (aWicImgFactory->CreateDecoderFromFilename (aFileNameW.ToWideString(), NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &aWicDecoder.ChangePtr()) != S_OK)
+    {
+      Message::DefaultMessenger()->Send ("Error: cannot create WIC Image Decoder", Message_Fail);
+      return false;
+    }
   }
 
   UINT aFrameCount = 0, aFrameSizeX = 0, aFrameSizeY = 0;
@@ -527,10 +752,45 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
   SetTopDown (true);
   return true;
 }
+bool Image_AlienPixMap::Load (std::istream& theStream,
+                              const TCollection_AsciiString& theFilePath)
+{
+  Clear();
+
+  // fallback copying stream data into transient buffer
+  const std::streamoff aStart = theStream.tellg();
+  theStream.seekg (0, std::ios::end);
+  const Standard_Integer aLen = Standard_Integer(theStream.tellg() - aStart);
+  theStream.seekg (aStart);
+  if (aLen <= 0)
+  {
+    Message::DefaultMessenger()->Send ("Error: empty stream", Message_Fail);
+    return false;
+  }
+
+  NCollection_Array1<Standard_Byte> aBuff (1, aLen);
+  if (!theStream.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
+  {
+    Message::DefaultMessenger()->Send ("Error: unable to read stream", Message_Fail);
+    return false;
+  }
+
+  return Load (&aBuff.ChangeFirst(), aBuff.Size(), theFilePath);
+}
 #else
-bool Image_AlienPixMap::Load (const TCollection_AsciiString&)
+bool Image_AlienPixMap::Load (std::istream& ,
+                              const TCollection_AsciiString& )
+{
+  Clear();
+  Message::DefaultMessenger()->Send ("Error: no image library available", Message_Fail);
+  return false;
+}
+bool Image_AlienPixMap::Load (const Standard_Byte* ,
+                              Standard_Size ,
+                              const TCollection_AsciiString& )
 {
   Clear();
+  Message::DefaultMessenger()->Send ("Error: no image library available", Message_Fail);
   return false;
 }
 #endif
@@ -774,9 +1034,9 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
     return false;
   }
 
-  IWICImagingFactory* aWicImgFactory = NULL;
+  Image_ComPtr<IWICImagingFactory> aWicImgFactory;
   CoInitializeEx (NULL, COINIT_MULTITHREADED);
-  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory)) != S_OK)
+  if (CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&aWicImgFactory.ChangePtr())) != S_OK)
   {
     Message::DefaultMessenger()->Send ("Error: cannot initialize WIC Imaging Factory", Message_Fail);
     return false;
index 1e8a179..14b1f40 100644 (file)
@@ -36,6 +36,10 @@ class Image_AlienPixMap : public Image_PixMap
   DEFINE_STANDARD_RTTIEXT(Image_AlienPixMap, Image_PixMap)
 public:
 
+  //! Return default rows order used by underlying image library.
+  Standard_EXPORT static bool IsTopDownDefault();
+public:
+
   //! Empty constructor.
   Standard_EXPORT Image_AlienPixMap();
 
@@ -43,7 +47,23 @@ public:
   Standard_EXPORT virtual ~Image_AlienPixMap();
 
   //! Read image data from file.
-  Standard_EXPORT bool Load (const TCollection_AsciiString& theFileName);
+  bool Load (const TCollection_AsciiString& theFileName)
+  {
+    return Load (NULL, 0, theFileName);
+  }
+
+  //! Read image data from stream.
+  Standard_EXPORT bool Load (std::istream& theStream,
+                             const TCollection_AsciiString& theFileName);
+
+  //! Read image data from memory buffer.
+  //! @param theData     memory pointer to read from;
+  //!                    when NULL, function will attempt to open theFileName file
+  //! @param theLength   memory buffer length
+  //! @param theFileName optional file name
+  Standard_EXPORT bool Load (const Standard_Byte* theData,
+                             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);
index d0a6dd0..3f8b3b0 100644 (file)
@@ -386,6 +386,139 @@ static Standard_Integer OCC361bug (Draw_Interpretor& di, Standard_Integer nb, co
   return 0;
 }
 
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <OSD_OpenFile.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+#include <Standard_ArrayStreamBuffer.hxx>
+//=======================================================================
+//function : OCC30182
+//purpose  : Testing different interfaces of Image_AlienPixMap::Load()
+//=======================================================================
+static Standard_Integer OCC30182 (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
+{
+  if (ViewerTest::CurrentView().IsNull())
+  {
+    std::cout << "Error: no active view\n";
+    return 1;
+  }
+
+  TCollection_AsciiString aPrsName, anImgPath;
+  Standard_Integer anOffset = 0;
+  Standard_Integer aSrc = 0; // 0 - file name, 1 - file stream, 2 - memory buffer
+  for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-offset"
+     && anArgIter + 1 < theNbArgs)
+    {
+      anOffset = Draw::Atoi (theArgVec[++anArgIter]);
+    }
+    else if (anArg == "-filename")
+    {
+      aSrc = 0;
+    }
+    else if (anArg == "-stream")
+    {
+      aSrc = 1;
+    }
+    else if (anArg == "-mem"
+          || anArg == "-memory")
+    {
+      aSrc = 2;
+    }
+    else if (aPrsName.IsEmpty())
+    {
+      aPrsName = theArgVec[anArgIter];
+    }
+    else if (anImgPath.IsEmpty())
+    {
+      anImgPath = theArgVec[anArgIter];
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << anArg << "'\n";
+      return 1;
+    }
+  }
+  if (anImgPath.IsEmpty())
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
+  if (aSrc == 0)
+  {
+    if (!anImage->Load (anImgPath))
+    {
+      return 0;
+    }
+  }
+  else
+  {
+    std::ifstream aFile;
+    OSD_OpenStream (aFile, anImgPath.ToCString(), std::ios::in | std::ios::binary);
+    if (!aFile.is_open())
+    {
+      std::cout << "Syntax error: image file '" << anImgPath << "' cannot be found\n";
+      return 1;
+    }
+    if (anOffset != 0)
+    {
+      aFile.seekg (anOffset);
+    }
+
+    if (aSrc == 2)
+    {
+      aFile.seekg (0, std::ios::end);
+      Standard_Integer aLen = (Standard_Integer )aFile.tellg() - anOffset;
+      aFile.seekg (anOffset);
+      if (aLen <= 0)
+      {
+        std::cout << "Syntax error: wrong offset\n";
+        return 1;
+      }
+      NCollection_Array1<Standard_Byte> aBuff (1, aLen);
+      if (!aFile.read ((char* )&aBuff.ChangeFirst(), aBuff.Size()))
+      {
+        std::cout << "Error: unable to read file\n";
+        return 1;
+      }
+      aFile.close();
+      if (!anImage->Load (&aBuff.ChangeFirst(), aBuff.Size(), anImgPath))
+      {
+        return 0;
+      }
+    }
+    else
+    {
+      if (!anImage->Load (aFile, anImgPath))
+      {
+        return 0;
+      }
+    }
+  }
+
+  TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100.0 * anImage->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_Texture2Dmanual (anImage));
+  if (anImage->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";
 
@@ -399,7 +532,9 @@ void QABugs::Commands_1(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC74_set", "OCC74_set shape mode;   set selection mode", __FILE__, OCC74bug_set, group);
   theCommands.Add ("OCC74_get", "OCC74_get shape;   get selection mode", __FILE__, OCC74bug_get, group);
 
-  theCommands.Add("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
-
+  theCommands.Add ("OCC361", "OCC361 Doc ", __FILE__, OCC361bug, group);
+  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);
   return;
 }
index f0e1a8a..86ed992 100644 (file)
@@ -1078,48 +1078,6 @@ static Standard_Integer OCC884 (Draw_Interpretor& di, Standard_Integer argc, con
   return 0;
 }
 
-#include <Aspect_FillMethod.hxx>
-//=======================================================================
-//function : OCC1188
-//purpose  : 
-//=======================================================================
-static Standard_Integer OCC1188 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
-{
-  if (argc < 2 || argc > 3)
-  {
-    di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background\n";
-    return 1;
-  }
-
-  Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
-  if(AISContext.IsNull()) 
-  {
-    di << "use 'vinit' command before " << argv[0] << "\n";
-    return 1;
-  }
-
-  Aspect_FillMethod aFillType = Aspect_FM_CENTERED;
-  if (argc == 3)
-  {
-    const char* szType = argv[2];
-    if      (strcmp(szType, "NONE"    ) == 0) aFillType = Aspect_FM_NONE;
-    else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
-    else if (strcmp(szType, "TILED"   ) == 0) aFillType = Aspect_FM_TILED;
-    else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
-    else
-    {
-      di << "Wrong fill type : " << szType << "\n";
-      di << "Must be one of CENTERED, TILED, STRETCH, NONE\n";
-      return 1;
-    }
-  }
-
-  Handle(V3d_View) V3dView = ViewerTest::CurrentView();
-  V3dView->SetBackgroundImage(argv[1], aFillType, Standard_True);
-
-  return 0;
-}
-
 #include <Graphic3d_MaterialAspect.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_ShadingAspect.hxx>
@@ -1590,7 +1548,6 @@ void QABugs::Commands_17(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC813", "OCC813 U V", __FILE__, OCC813, group);
   theCommands.Add ("OCC814", "OCC814", __FILE__, OCC814, group);
   theCommands.Add ("OCC884", "OCC884 result shape [toler [maxtoler]]", __FILE__, OCC884, group);
-  theCommands.Add ("OCC1188", "OCC1188 imagefile [filltype] : Load image as background", __FILE__, OCC1188, group);
 
   theCommands.Add ("OCC1174_1", "OCC1174_1 shape", __FILE__, OCC1174_1, group);
   theCommands.Add ("OCC1174_2", "OCC1174_2 shape", __FILE__, OCC1174_2, group);
index 1f584dc..53af177 100755 (executable)
@@ -1,19 +1,11 @@
 puts "================"
-puts "OCC1188"
-puts "Impossible to set background image for V3d_View"
+puts "0001188: Impossible to set background image for V3d_View"
 puts "================"
 puts ""
 
-set x 200
-set y 200
+vinit View1
 
-vinit
+vsetbg [locate_data_file OCC1188.gif]
+if { [vreadpixel 200 200 rgb name] != "WHITE" } { puts "Error: image background is not set" }
 
-OCC1188 [locate_data_file OCC1188.gif]
-
-checkcolor $x $y 0.99 0.99 0.99
-if { ${stat} != 1} {
-    puts "OCC1188: Error"
-}
-
-checkview -screenshot -3d -path ${imagedir}/${test_image}.png
+vdump $imagedir/${casename}.png
index 2169acd..1ba94b0 100644 (file)
@@ -1,30 +1,24 @@
 puts "============"
-puts "OCC25475"
+puts "0025475: Visualization, TKOpenGl - draw background using primitive arrays"
+puts "Tests textured background"
 puts "============"
 puts ""
-#######################################################################
-puts "Tests textured background"
-#######################################################################
 
 set aTextureFile [locate_data_file hatch_1.png]
-set anImage1 $imagedir/${casename}_1.png
-set anImage2 $imagedir/${casename}_2.png
-set anImage3 $imagedir/${casename}_3.png
-set anImage4 $imagedir/${casename}_4.png
 
 pload VISUALIZATION
-vinit
+vinit View1
 
 vsetbg $aTextureFile STRETCH
-vdump $anImage1
+vdump $imagedir/${casename}_1.png
 
 vsetbg $aTextureFile NONE
 vsetbg $aTextureFile TILED
-vdump $anImage2
+vdump $imagedir/${casename}_2.png
 
 vsetgradientbg 255 0 0 0 0 255 1
 vsetbg $aTextureFile CENTERED
-vdump $anImage3
+vdump $imagedir/${casename}_3.png
 
 vsetbg $aTextureFile NONE
-vdump $anImage4
+vdump $imagedir/${casename}_4.png
diff --git a/tests/bugs/vis/bug30182 b/tests/bugs/vis/bug30182
new file mode 100644 (file)
index 0000000..9b8978e
--- /dev/null
@@ -0,0 +1,64 @@
+puts "============"
+puts "0030182: Visualization, Image_AlienPixMap - support reading encoded image from memory buffer"
+puts "============"
+puts ""
+
+set anImg1 [locate_data_file hatch_1.png]
+set anImg2 [locate_data_file OCC1188.gif]
+set anImgTmp "$imagedir/${casename}_img.bin"
+
+set aTmpOut [open "$anImgTmp" w]
+fconfigure $aTmpOut -translation binary
+foreach aFileIter {anImg1 anImg2} {
+  set aFileName [set $aFileIter]
+  set aFileIn [open $aFileName]
+  fconfigure $aFileIn -translation binary
+  fcopy $aFileIn $aTmpOut
+  close $aFileIn
+}
+close $aTmpOut
+
+pload VISUALIZATION QAcommands
+vclear
+vinit View1
+vtop
+
+OCC30182 t $anImg1 -fileName; vfit
+vdump $imagedir/${casename}_1.png
+
+OCC30182 t $anImg1 -stream; vfit
+vdump $imagedir/${casename}_1s1.png
+
+OCC30182 t $anImg1 -memory; vfit
+vdump $imagedir/${casename}_1m1.png
+
+OCC30182 t $anImg2 -fileName; vfit
+vdump $imagedir/${casename}_2.png
+
+OCC30182 t $anImg2 -stream; vfit
+vdump $imagedir/${casename}_2s1.png
+
+OCC30182 t $anImg2 -memory; vfit
+vdump $imagedir/${casename}_2m1.png
+
+OCC30182 t $anImgTmp -stream -offset 0; vfit
+vdump $imagedir/${casename}_1s2.png
+
+OCC30182 t $anImgTmp -memory -offset 0; vfit
+vdump $imagedir/${casename}_1m2.png
+
+OCC30182 t $anImgTmp -stream -offset [file size $anImg1]; vfit
+vdump $imagedir/${casename}_2s2.png
+
+OCC30182 t $anImgTmp -memory -offset [file size $anImg1]; vfit
+vdump $imagedir/${casename}_2m2.png
+
+if { [diffimage $imagedir/${casename}_1s1.png $imagedir/${casename}_1.png] != 0 } { puts "Error 1s1" }
+if { [diffimage $imagedir/${casename}_1m1.png $imagedir/${casename}_1.png] != 0 } { puts "Error 1m1" }
+if { [diffimage $imagedir/${casename}_1s2.png $imagedir/${casename}_1.png] != 0 } { puts "Error 1s2" }
+if { [diffimage $imagedir/${casename}_1m2.png $imagedir/${casename}_1.png] != 0 } { puts "Error 1m2" }
+
+if { [diffimage $imagedir/${casename}_2s1.png $imagedir/${casename}_2.png] != 0 } { puts "Error 2s1" }
+if { [diffimage $imagedir/${casename}_2m1.png $imagedir/${casename}_2.png] != 0 } { puts "Error 2m1" }
+if { [diffimage $imagedir/${casename}_2s2.png $imagedir/${casename}_2.png] != 0 } { puts "Error 2s2" }
+if { [diffimage $imagedir/${casename}_2m2.png $imagedir/${casename}_2.png] != 0 } { puts "Error 2m2" }