mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-06 18:26:22 +03:00
0025369: Visualization, Image_AlienPixMap - handle UTF-8 names in image read/save operations on Windows
Test-case for issue #25369
This commit is contained in:
parent
54a16ee447
commit
7aa1b65c2a
@ -24,6 +24,7 @@
|
|||||||
#include <Image_AlienPixMap.hxx>
|
#include <Image_AlienPixMap.hxx>
|
||||||
#include <gp.hxx>
|
#include <gp.hxx>
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
#include <TCollection_ExtendedString.hxx>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -244,7 +245,13 @@ void Image_AlienPixMap::Clear()
|
|||||||
bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
|
bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
const TCollection_ExtendedString aFileNameW (theImagePath.ToCString(), Standard_True);
|
||||||
|
FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileTypeU ((const wchar_t* )aFileNameW.ToExtString(), 0);
|
||||||
|
#else
|
||||||
FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileType (theImagePath.ToCString(), 0);
|
FREE_IMAGE_FORMAT aFIF = FreeImage_GetFileType (theImagePath.ToCString(), 0);
|
||||||
|
#endif
|
||||||
if (aFIF == FIF_UNKNOWN)
|
if (aFIF == FIF_UNKNOWN)
|
||||||
{
|
{
|
||||||
// no signature? try to guess the file format from the file extension
|
// no signature? try to guess the file format from the file extension
|
||||||
@ -268,7 +275,11 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
|
|||||||
aLoadFlags = ICO_MAKEALPHA;
|
aLoadFlags = ICO_MAKEALPHA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
FIBITMAP* anImage = FreeImage_LoadU (aFIF, (const wchar_t* )aFileNameW.ToExtString(), aLoadFlags);
|
||||||
|
#else
|
||||||
FIBITMAP* anImage = FreeImage_Load (aFIF, theImagePath.ToCString(), aLoadFlags);
|
FIBITMAP* anImage = FreeImage_Load (aFIF, theImagePath.ToCString(), aLoadFlags);
|
||||||
|
#endif
|
||||||
if (anImage == NULL)
|
if (anImage == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -311,7 +322,12 @@ bool Image_AlienPixMap::savePPM (const TCollection_AsciiString& theFileName) con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
|
#ifdef _WIN32
|
||||||
|
const TCollection_ExtendedString aFileNameW (theFileName.ToCString(), Standard_True);
|
||||||
|
FILE* aFile = _wfopen ((const wchar_t* )aFileNameW.ToExtString(), L"wb");
|
||||||
|
#else
|
||||||
FILE* aFile = fopen (theFileName.ToCString(), "wb");
|
FILE* aFile = fopen (theFileName.ToCString(), "wb");
|
||||||
|
#endif
|
||||||
if (aFile == NULL)
|
if (aFile == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -354,7 +370,12 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
const TCollection_ExtendedString aFileNameW (theFileName.ToCString(), Standard_True);
|
||||||
|
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilenameU ((const wchar_t* )aFileNameW.ToExtString());
|
||||||
|
#else
|
||||||
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename (theFileName.ToCString());
|
FREE_IMAGE_FORMAT anImageFormat = FreeImage_GetFIFFromFilename (theFileName.ToCString());
|
||||||
|
#endif
|
||||||
if (anImageFormat == FIF_UNKNOWN)
|
if (anImageFormat == FIF_UNKNOWN)
|
||||||
{
|
{
|
||||||
std::cerr << "Image_PixMap, image format doesn't supported!\n";
|
std::cerr << "Image_PixMap, image format doesn't supported!\n";
|
||||||
@ -483,7 +504,11 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
bool isSaved = (FreeImage_SaveU (anImageFormat, anImageToDump, (const wchar_t* )aFileNameW.ToExtString()) != FALSE);
|
||||||
|
#else
|
||||||
bool isSaved = (FreeImage_Save (anImageFormat, anImageToDump, theFileName.ToCString()) != FALSE);
|
bool isSaved = (FreeImage_Save (anImageFormat, anImageToDump, theFileName.ToCString()) != FALSE);
|
||||||
|
#endif
|
||||||
if (anImageToDump != myLibImage)
|
if (anImageToDump != myLibImage)
|
||||||
{
|
{
|
||||||
FreeImage_Unload (anImageToDump);
|
FreeImage_Unload (anImageToDump);
|
||||||
@ -505,14 +530,12 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
|||||||
// function : AdjustGamma
|
// function : AdjustGamma
|
||||||
// purpose :
|
// purpose :
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
bool Image_AlienPixMap::AdjustGamma (const Standard_Real theGammaCorr)
|
||||||
|
{
|
||||||
#ifdef HAVE_FREEIMAGE
|
#ifdef HAVE_FREEIMAGE
|
||||||
Standard_EXPORT bool Image_AlienPixMap::AdjustGamma (const Standard_Real theGammaCorr)
|
|
||||||
{
|
|
||||||
return FreeImage_AdjustGamma (myLibImage, theGammaCorr) != FALSE;
|
return FreeImage_AdjustGamma (myLibImage, theGammaCorr) != FALSE;
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
Standard_EXPORT bool Image_AlienPixMap::AdjustGamma (const Standard_Real)
|
(void )theGammaCorr;
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
21
tests/bugs/vis/bug25369
Normal file
21
tests/bugs/vis/bug25369
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
puts "========"
|
||||||
|
puts "OCC25369"
|
||||||
|
puts "========"
|
||||||
|
puts ""
|
||||||
|
###################################################################################################
|
||||||
|
# Visualization, Image_AlienPixMap - handle UTF-8 names in image read/save operations on Windows
|
||||||
|
###################################################################################################
|
||||||
|
|
||||||
|
box b 1 2 3
|
||||||
|
vinit View1
|
||||||
|
vclear
|
||||||
|
vsetdispmode 0
|
||||||
|
vdisplay b
|
||||||
|
vfit
|
||||||
|
set s [encoding convertfrom unicode "\x3A\x04\x30\x04\x40\x04\x2E\x00\x70\x00\x6E\x00\x67\x00"]
|
||||||
|
|
||||||
|
vdrawtext $s 0 0 0 255 255 255 0 0 0 0 50 0 Times 1
|
||||||
|
vdump $::imagedir/$s
|
||||||
|
vtexture b $::imagedir/$s
|
||||||
|
|
||||||
|
set only_screen 1
|
Loading…
x
Reference in New Issue
Block a user