EgtGraphics 1.8b2 :

- aggiunta in interfaccia funzione GetImage.
This commit is contained in:
Dario Sassi
2017-02-13 08:20:31 +00:00
parent 2cf0a63522
commit 5be1bf8dc7
7 changed files with 141 additions and 3 deletions
BIN
View File
Binary file not shown.
+1
View File
@@ -250,6 +250,7 @@ copy $(TargetPath) \EgtProg\Dll64</Command>
<ClCompile Include="SceneDirect.cpp" />
<ClCompile Include="SceneGlobFrame.cpp" />
<ClCompile Include="SceneGrid.cpp" />
<ClCompile Include="SceneImage.cpp" />
<ClCompile Include="SceneSelect.cpp" />
<ClCompile Include="SceneSnap.cpp" />
<ClCompile Include="SceneTexture.cpp" />
+3
View File
@@ -134,6 +134,9 @@
<ClCompile Include="ObjMultiGraphics.cpp">
<Filter>File di origine</Filter>
</ClCompile>
<ClCompile Include="SceneImage.cpp">
<Filter>File di origine</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EgtGraphics.rc">
+4
View File
@@ -178,6 +178,9 @@ class Scene : public IEGrScene
bool GetTexturePixels( const std::string& sName, int& nWidth, int& nHeight) const override ;
bool GetTextureDimensions( const std::string& sName, double& dDimX, double& dDimY) const override ;
bool ChangeTextureDimensions( const std::string& sName, double dDimX, double dDimY) override ;
// Image
bool GetImage( int nShowMode, bool bShowGrid, bool bShowFrame, Color colBackTop, Color colBackBottom,
int nDestWidth, int nDestHeight, const std::string& sFile) override ;
public :
// Basic
@@ -202,6 +205,7 @@ class Scene : public IEGrScene
bool CalcDimViewFromExtView( void) ;
bool AdjustDimView( double dHalfWidth, double dHalfHeight) ;
bool CalcClippingPlanesFromExtView( void) ;
bool MyDraw( bool bSwapBF) ;
bool Background( void) ;
bool Prepare( void) ;
// Camera
+9 -2
View File
@@ -683,6 +683,13 @@ Scene::Prepare( void)
//----------------------------------------------------------------------------
bool
Scene::Draw( void)
{
return MyDraw( true) ;
}
//----------------------------------------------------------------------------
bool
Scene::MyDraw( bool bSwapBF)
{
// sistemo lo sfondo e lo Zbuffer
if ( ! Background())
@@ -811,7 +818,7 @@ Scene::Draw( void)
}
// scambio i buffer back e front ( eseguita solo se previsti)
if ( ! SwapBuffers( m_hDC))
if ( bSwapBF && ! SwapBuffers( m_hDC))
LOG_INFO( GetEGrLogger(), "Draw SwapBuffers error")
return true ;
@@ -877,7 +884,7 @@ Scene::Destroy( void)
// cancellazione textures
if ( ! m_TextMgr.Clear())
LOG_ERROR( GetEGrLogger(), "Error uloading textures from OpenGl") ;
LOG_ERROR( GetEGrLogger(), "Error unloading textures from OpenGl") ;
// cancellazione rendering context
wglMakeCurrent( nullptr, nullptr) ;
+123
View File
@@ -0,0 +1,123 @@
//----------------------------------------------------------------------------
// EgalTech 2017-2017
//----------------------------------------------------------------------------
// File : SceneImage.cpp Data : 11.02.17 Versione : 1.8b2
// Contenuto : Implementazione della gestione immagini della classe scena.
//
//
//
// Modifiche : 11.02.17 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "Scene.h"
#include "\EgtDev\Include\EgtStringConverter.h"
#include "\EgtDev\Extern\FreeImage\Include\FreeImage.h"
using namespace std ;
//----------------------------------------------------------------------------
bool
Scene::GetImage( int nShowMode, bool bShowGrid, bool bShowFrame, Color colBackTop, Color colBackBottom,
int nDestWidth, int nDestHeight, const string& sFile)
{
// Cerco e verifico il formato del file da scrivere a partire dall'estensione
FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilenameU( stringtoW( sFile)) ;
if ( fif == FIF_UNKNOWN || ! FreeImage_FIFSupportsWriting( fif))
return false ;
// Dimensioni della vista
int nWidth = m_nViewportW ;
int nHeight = m_nViewportH ;
if ( nWidth == 0 || nHeight == 0)
return false ;
// Coefficienti di scalatura
if ( nDestWidth == 0 || nDestHeight == 0)
return false ;
double dCoeffW = double( nDestWidth) / nWidth ;
double dCoeffH = double( nDestHeight) / nHeight ;
// Alloco il buffer di lettura dei pixel della vista OpenGL ( fattore 4 perché RGBA)
BYTE* pBuffer = new BYTE[ 4 * nWidth * nHeight] ;
if ( pBuffer == nullptr)
return false ;
// Imposto attributi di visualizzazione
int nCurrShowMode = m_nShowMode ;
m_nShowMode = nShowMode ;
bool bCurrShowGrid = m_bShowGrid ;
m_bShowGrid = bShowGrid ;
bool bCurrShowFrame = m_bShowFrame ;
m_bShowFrame = bShowFrame ;
Color colCurrBackTop = m_colBackTop ;
Color colCurrBackBottom = m_colBackBottom ;
m_colBackTop = colBackTop ;
m_colBackBottom = colBackBottom ;
// Imposto zoom
double dCurrHalfWidth = m_dHalfWidth ;
double dCurrHalfHeight = m_dHalfHeight ;
double dCoeff = max( dCoeffW, dCoeffH) / min( dCoeffW, dCoeffH) ;
m_dHalfWidth *= dCoeff ;
m_dHalfHeight *= dCoeff ;
// Eseguo disegno sul back buffer
if ( ! MyDraw( false))
return false ;
// Ripristino attributi di visualizzazione originali
m_nShowMode = nCurrShowMode ;
m_bShowGrid = bCurrShowGrid ;
m_bShowFrame = bCurrShowFrame ;
m_colBackBottom = colCurrBackBottom ;
m_colBackTop = colCurrBackTop ;
// Ripristino zoom
m_dHalfWidth = dCurrHalfWidth ;
m_dHalfHeight = dCurrHalfHeight ;
// Leggo l'immagine nel buffer
glReadBuffer( GL_BACK) ;
glReadPixels( 0, 0, nWidth, nHeight, GL_BGRA, GL_UNSIGNED_BYTE, pBuffer) ;
// Converto al formato di FreeImage
FIBITMAP* pDib = FreeImage_ConvertFromRawBits( pBuffer, nWidth, nHeight, 4 * nWidth, 32,
0x0000FF00, 0xFF000000, 0x00FF0000, false) ;
// converto l'immagine a 24 bit per pixel
FIBITMAP* pTmpDib = pDib ;
pDib = FreeImage_ConvertTo24Bits( pTmpDib) ;
FreeImage_Unload( pTmpDib) ;
// Eseguo scalatura della bitmap
int nLeft ; int nTop ;
int nRight ; int nBottom ;
if ( dCoeffW >= dCoeffH) {
nLeft = 0 ;
nRight = nWidth - 1 ;
int nDeltaH = nHeight - int( nDestHeight / dCoeffW) ;
nTop = nDeltaH / 2 ;
nBottom = nHeight - nTop ;
}
else {
nTop = 0 ;
nBottom = nHeight ;
int nDeltaW = nWidth - int( nDestWidth / dCoeffH) ;
nLeft = nDeltaW / 2 ;
nRight = nWidth - nLeft ;
}
FIBITMAP* pTmp2Dib = pDib ;
pDib = FreeImage_RescaleRect( pTmp2Dib, nDestWidth, nDestHeight, nLeft, nTop, nRight, nBottom, FILTER_BSPLINE) ;
FreeImage_Unload( pTmp2Dib) ;
// Salvataggio
int nFlag = 0 ;
bool bOk = ( FreeImage_SaveU( fif, pDib, stringtoW( sFile), nFlag) != FALSE) ;
// Libero le risorse
FreeImage_Unload( pDib) ;
delete pBuffer ;
return bOk ;
}
+1 -1
View File
@@ -2,7 +2,7 @@
// EgalTech 2015-2015
//----------------------------------------------------------------------------
// File : SceneTexture.cpp Data : 27.09.15 Versione : 1.6i8
// Contenuto : Implementazione della gestione texturesa della classe scena.
// Contenuto : Implementazione della gestione textures della classe scena.
//
//
//