Merge with develop
This commit is contained in:
commit
f7894c58c7
45 changed files with 305 additions and 1885 deletions
|
@ -188,6 +188,7 @@ MACRO(NL_SETUP_DEFAULT_OPTIONS)
|
|||
OPTION(WITH_LOGGING "With Logging" ON )
|
||||
OPTION(WITH_COVERAGE "With Code Coverage Support" OFF)
|
||||
OPTION(WITH_PCH "With Precompiled Headers" ON )
|
||||
OPTION(WITH_LOW_MEMORY "With low memory (use the least of RAM)" OFF)
|
||||
OPTION(FINAL_VERSION "Build in Final Version mode" ON )
|
||||
|
||||
# Default to static building on Windows.
|
||||
|
@ -809,7 +810,11 @@ MACRO(NL_SETUP_BUILD)
|
|||
ENDIF(HOST_CPU STREQUAL "x86" AND TARGET_CPU STREQUAL "x86_64")
|
||||
ENDIF(APPLE)
|
||||
|
||||
ADD_PLATFORM_FLAGS("-D_REENTRANT -pipe -fno-strict-aliasing")
|
||||
ADD_PLATFORM_FLAGS("-D_REENTRANT -fno-strict-aliasing")
|
||||
|
||||
IF(NOT WITH_LOW_MEMORY)
|
||||
ADD_PLATFORM_FLAGS("-pipe")
|
||||
ENDIF()
|
||||
|
||||
IF(WITH_COVERAGE)
|
||||
ADD_PLATFORM_FLAGS("-fprofile-arcs -ftest-coverage")
|
||||
|
|
|
@ -212,6 +212,11 @@ enum TKey
|
|||
KeyRCONTROL =0xA3,
|
||||
KeyLMENU =0xA4,
|
||||
KeyRMENU =0xA5,
|
||||
KeyMUTE =0xAD,
|
||||
KeyPLAYPAUSE =0xB3,
|
||||
KeyVOLUMEDOWN =0xB4,
|
||||
KeyVOLUMEUP =0xB5,
|
||||
KeyCALC =0xB7,
|
||||
KeySEMICOLON =0xBA,
|
||||
KeyEQUALS =0xBB,
|
||||
KeyCOMMA =0xBC,
|
||||
|
|
|
@ -2607,8 +2607,8 @@ CPSLocatedBindable *CPSLocated::unbind(uint index)
|
|||
CPSLocatedBindable *lb = _LocatedBoundCont[index];
|
||||
lb->setOwner(NULL);
|
||||
_LocatedBoundCont.erase(_LocatedBoundCont.begin() + index);
|
||||
return lb;
|
||||
CHECK_PS_INTEGRITY
|
||||
return lb;
|
||||
}
|
||||
|
||||
/// ***************************************************************************************
|
||||
|
|
|
@ -2376,7 +2376,6 @@ uint8 CBitmap::readTGA( NLMISC::IStream &f)
|
|||
|
||||
if(!f.isReading()) return 0;
|
||||
|
||||
uint32 size;
|
||||
uint32 x,y;
|
||||
sint32 slsize;
|
||||
uint8 *scanline;
|
||||
|
@ -2452,7 +2451,6 @@ uint8 CBitmap::readTGA( NLMISC::IStream &f)
|
|||
|
||||
_Width = width;
|
||||
_Height = height;
|
||||
size = _Width * _Height * (imageDepth/8);
|
||||
|
||||
switch(imageType)
|
||||
{
|
||||
|
@ -2599,7 +2597,7 @@ uint8 CBitmap::readTGA( NLMISC::IStream &f)
|
|||
case 10:
|
||||
{
|
||||
uint8 packet;
|
||||
uint8 pixel[4];
|
||||
uint8 pixel[4] = {0};
|
||||
uint32 imageSize = width*height;
|
||||
uint32 readSize = 0;
|
||||
uint8 upSideDown = ((desc & (1 << 5))==0);
|
||||
|
@ -2616,22 +2614,12 @@ uint8 CBitmap::readTGA( NLMISC::IStream &f)
|
|||
f.serial(pixel[i]);
|
||||
}
|
||||
for (i=0; i < (packet & 0x7F) + 1; i++)
|
||||
{
|
||||
if(imageDepth==32)
|
||||
{
|
||||
_Data[0][dstId++]= pixel[2];
|
||||
_Data[0][dstId++]= pixel[1];
|
||||
_Data[0][dstId++]= pixel[0];
|
||||
_Data[0][dstId++]= pixel[3];
|
||||
}
|
||||
if(imageDepth==24)
|
||||
{
|
||||
_Data[0][dstId++]= pixel[2];
|
||||
_Data[0][dstId++]= pixel[1];
|
||||
_Data[0][dstId++]= pixel[0];
|
||||
_Data[0][dstId++]= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // packet Raw
|
||||
{
|
||||
|
@ -2641,21 +2629,11 @@ uint8 CBitmap::readTGA( NLMISC::IStream &f)
|
|||
{
|
||||
f.serial(pixel[j]);
|
||||
}
|
||||
if(imageDepth==32)
|
||||
{
|
||||
_Data[0][dstId++]= pixel[2];
|
||||
_Data[0][dstId++]= pixel[1];
|
||||
_Data[0][dstId++]= pixel[0];
|
||||
_Data[0][dstId++]= pixel[3];
|
||||
}
|
||||
if(imageDepth==24)
|
||||
{
|
||||
_Data[0][dstId++]= pixel[2];
|
||||
_Data[0][dstId++]= pixel[1];
|
||||
_Data[0][dstId++]= pixel[0];
|
||||
_Data[0][dstId++]= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
readSize += (packet & 0x7F) + 1;
|
||||
}
|
||||
|
|
|
@ -159,6 +159,11 @@ static const CStringConversion<TKey>::CPair stringTable [] =
|
|||
{ "KeyRCONTROL", KeyRCONTROL },
|
||||
{ "KeyLMENU", KeyLMENU },
|
||||
{ "KeyRMENU", KeyRMENU },
|
||||
{ "KeyMUTE", KeyMUTE },
|
||||
{ "KeyPLAYPAUSE", KeyPLAYPAUSE },
|
||||
{ "KeyVOLUMEDOWN", KeyVOLUMEDOWN },
|
||||
{ "KeyVOLUMEUP", KeyVOLUMEUP },
|
||||
{ "KeyCALC", KeyCALC },
|
||||
{ "KeySEMICOLON", KeySEMICOLON },
|
||||
{ "KeyEQUALS", KeyEQUALS },
|
||||
{ "KeyCOMMA", KeyCOMMA },
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
#include "stdmisc.h"
|
||||
#include "nel/misc/sstring.h"
|
||||
|
||||
#ifdef DEBUG_NEW
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
namespace NLMISC
|
||||
{
|
||||
|
||||
|
@ -225,14 +229,14 @@ namespace NLMISC
|
|||
return false;
|
||||
|
||||
// iterate from size-2 to 1
|
||||
for (uint32 i=(uint32)size()-1; --i;)
|
||||
for (uint i=(uint)size()-1; --i;)
|
||||
if (!isValidFileNameChar((*this)[i]) && (*this)[i]!=' ')
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// iterate from size-1 to 0
|
||||
for (uint32 i=(uint32)size(); i--;)
|
||||
for (uint i=(uint)size(); i--;)
|
||||
if (!isValidFileNameChar((*this)[i]))
|
||||
return false;
|
||||
}
|
||||
|
@ -253,7 +257,7 @@ namespace NLMISC
|
|||
return false;
|
||||
|
||||
// iterate from size-1 to 1
|
||||
for (uint32 i=(uint32)size(); --i;)
|
||||
for (uint i=(uint)size(); --i;)
|
||||
if (!isValidKeywordChar((*this)[i]))
|
||||
return false;
|
||||
|
||||
|
@ -489,9 +493,9 @@ namespace NLMISC
|
|||
CSString s=strip();
|
||||
while(!s.empty())
|
||||
{
|
||||
uint32 pre=(uint32)s.size();
|
||||
uint pre=(uint)s.size();
|
||||
result.push_back(s.firstWord(true));
|
||||
uint32 post=(uint32)s.size();
|
||||
uint post=(uint)s.size();
|
||||
if (post>=pre)
|
||||
return false;
|
||||
}
|
||||
|
@ -503,9 +507,9 @@ namespace NLMISC
|
|||
CSString s=*this;
|
||||
while(!s.empty())
|
||||
{
|
||||
uint32 pre=(uint32)s.size();
|
||||
uint pre=(uint)s.size();
|
||||
result.push_back(s.firstWordOrWords(true,useSlashStringEscape,useRepeatQuoteStringEscape));
|
||||
uint32 post=(uint32)s.size();
|
||||
uint post=(uint)s.size();
|
||||
if (post>=pre)
|
||||
return false;
|
||||
}
|
||||
|
@ -520,8 +524,8 @@ namespace NLMISC
|
|||
if (s.contains('\r'))
|
||||
s=s.replace("\r","");
|
||||
|
||||
uint32 it=0;
|
||||
uint32 len= (uint32)s.size();
|
||||
uint it=0;
|
||||
uint len= (uint)s.size();
|
||||
while(it<len)
|
||||
{
|
||||
// extract the text up to the next '\n'character
|
||||
|
@ -542,12 +546,12 @@ namespace NLMISC
|
|||
CSString s=*this;
|
||||
while(!s.empty())
|
||||
{
|
||||
uint32 pre=(uint32)s.size();
|
||||
uint pre=(uint)s.size();
|
||||
result.push_back(s.splitToSeparator(separator,true,useAngleBrace,useSlashStringEscape,
|
||||
useRepeatQuoteStringEscape,true));
|
||||
if (skipBlankEntries && result.back().empty())
|
||||
result.pop_back();
|
||||
uint32 post=(uint32)s.size();
|
||||
uint post=(uint)s.size();
|
||||
if (post>=pre)
|
||||
return false;
|
||||
}
|
||||
|
@ -568,7 +572,7 @@ namespace NLMISC
|
|||
|
||||
while(!s.empty())
|
||||
{
|
||||
uint32 pre=(uint32)s.size();
|
||||
uint pre=(uint)s.size();
|
||||
result.push_back(s.splitToOneOfSeparators( separators,true,useAngleBrace,useSlashStringEscape,
|
||||
useRepeatQuoteStringEscape,!retainSeparators ));
|
||||
|
||||
|
@ -586,7 +590,7 @@ namespace NLMISC
|
|||
}
|
||||
}
|
||||
|
||||
uint32 post=(uint32)s.size();
|
||||
uint post=(uint)s.size();
|
||||
if (post>=pre)
|
||||
return false;
|
||||
}
|
||||
|
@ -716,7 +720,7 @@ namespace NLMISC
|
|||
for (i=0;i<size();++i)
|
||||
{
|
||||
// perform a quick string compare
|
||||
int j;
|
||||
uint j;
|
||||
for (j=0;s[j]!=0 && s[j]==(&((*this)[i]))[j];++j)
|
||||
{
|
||||
}
|
||||
|
@ -1022,7 +1026,7 @@ namespace NLMISC
|
|||
}
|
||||
else if ((*this)[0]=='\"' && isDelimitedMonoBlock(false,useSlashStringEscape,useRepeatQuoteStringEscape))
|
||||
{
|
||||
i=(uint32)size();
|
||||
i=(uint)size();
|
||||
}
|
||||
if (i!=size())
|
||||
return quote(useSlashStringEscape,useRepeatQuoteStringEscape);
|
||||
|
@ -1224,7 +1228,7 @@ namespace NLMISC
|
|||
{
|
||||
bool foundToken= false;
|
||||
|
||||
for (uint32 i=(uint32)size();i--;)
|
||||
for (uint i=(uint)size();i--;)
|
||||
{
|
||||
switch((*this)[i])
|
||||
{
|
||||
|
@ -1274,7 +1278,7 @@ namespace NLMISC
|
|||
|
||||
bool CSString::isXMLCompatible(bool isParameter) const
|
||||
{
|
||||
for (uint32 i=(uint32)size();i--;)
|
||||
for (uint i=(uint)size();i--;)
|
||||
{
|
||||
switch((*this)[i])
|
||||
{
|
||||
|
|
|
@ -62,10 +62,10 @@ IF(WITH_NEL_TOOLS AND WITH_3D)
|
|||
ENDIF(MFC_FOUND)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF(WITH_QT)
|
||||
IF(WITH_QT OR WITH_QT5)
|
||||
ADD_SUBDIRECTORY(tile_edit_qt)
|
||||
ADD_SUBDIRECTORY(object_viewer_widget)
|
||||
ENDIF(WITH_QT)
|
||||
ENDIF()
|
||||
|
||||
IF(WITH_NEL_TOOLS)
|
||||
FIND_PACKAGE(Squish)
|
||||
|
|
|
@ -2,19 +2,33 @@ INCLUDE_DIRECTORIES(
|
|||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${LIBXML2_INCLUDE_DIR}
|
||||
${NEL_INCLUDE_DIR}
|
||||
${QT_INCLUDES})
|
||||
${NEL_INCLUDE_DIR})
|
||||
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
ADD_DEFINITIONS(${LIBXML2_DEFINITIONS})
|
||||
|
||||
FILE(GLOB OBJECT_VIEWER_WIDGET_SRC *.cpp *.h)
|
||||
SET(OBJECT_VIEWER_WIDGET_HDR object_viewer_widget.h)
|
||||
|
||||
IF(WITH_QT)
|
||||
INCLUDE_DIRECTORIES(${QT_INCLUDES})
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
|
||||
SET(QT_USE_QTGUI TRUE)
|
||||
SET(QT_USE_QTOPENGL TRUE)
|
||||
|
||||
QT4_WRAP_CPP(OBJECT_VIEWER_WIDGET_MOC_SRCS ${OBJECT_VIEWER_WIDGET_HDR})
|
||||
|
||||
ADD_DEFINITIONS(${QT_DEFINITIONS})
|
||||
ADD_DEFINITIONS(-DQT_NO_KEYWORDS)
|
||||
ADD_DEFINITIONS(-DQT_PLUGIN)
|
||||
ADD_DEFINITIONS(-DQT_SHARED)
|
||||
#ADD_DEFINITIONS(-DQT_NO_DEBUG)
|
||||
|
||||
SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTOPENGL_LIBRARY})
|
||||
ELSE()
|
||||
QT5_WRAP_CPP(OBJECT_VIEWER_WIDGET_MOC_SRCS ${OBJECT_VIEWER_WIDGET_HDR})
|
||||
ENDIF()
|
||||
|
||||
SOURCE_GROUP(QtGeneratedMocSrc FILES ${OBJECT_VIEWER_WIDGET_MOC_SRCS})
|
||||
|
||||
ADD_LIBRARY(object_viewer_widget_qt MODULE
|
||||
|
@ -24,19 +38,13 @@ ADD_LIBRARY(object_viewer_widget_qt MODULE
|
|||
TARGET_LINK_LIBRARIES(object_viewer_widget_qt
|
||||
nelmisc
|
||||
nel3d
|
||||
${QT_LIBRARIES}
|
||||
${QT_QTOPENGL_LIBRARY})
|
||||
|
||||
ADD_DEFINITIONS(-DQT_NO_KEYWORDS ${LIBXML2_DEFINITIONS} ${QT_DEFINITIONS})
|
||||
ADD_DEFINITIONS(-DQT_PLUGIN)
|
||||
ADD_DEFINITIONS(-DQT_SHARED)
|
||||
#ADD_DEFINITIONS(-DQT_NO_DEBUG)
|
||||
${QT_LIBRARIES})
|
||||
|
||||
NL_DEFAULT_PROPS(object_viewer_widget_qt "NeL, Tools, 3D: Object Viewer Qt Widget")
|
||||
NL_ADD_RUNTIME_FLAGS(object_viewer_widget_qt)
|
||||
|
||||
IF(WITH_PCH)
|
||||
ADD_NATIVE_PRECOMPILED_HEADER(object_viewer_widget_qt ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp)
|
||||
ENDIF(WITH_PCH)
|
||||
ENDIF()
|
||||
|
||||
#INSTALL(TARGETS object_viewer_widget_qt RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT runtime BUNDLE DESTINATION /Applications)
|
||||
|
|
|
@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stdpch.h"
|
||||
#include "object_viewer_widget.h"
|
||||
|
||||
// STL includes
|
||||
|
@ -46,7 +47,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
// Project includes
|
||||
|
||||
#ifndef USE_QT5
|
||||
Q_EXPORT_PLUGIN2(object_viewer_widget_qt, NLQT::CObjectViewerWidget)
|
||||
#endif
|
||||
|
||||
using namespace NLMISC;
|
||||
using namespace NL3D;
|
||||
|
|
|
@ -20,7 +20,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifndef NL_STDPCH_H
|
||||
#define NL_STDPCH_H
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
||||
#undef realloc
|
||||
#undef free
|
||||
#endif
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
#undef Q_COMPILER_RVALUE_REFS
|
||||
#endif
|
||||
|
||||
#include <QtCore/QtCore>
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#define USE_QT5
|
||||
#endif
|
||||
|
||||
#ifdef USE_QT5
|
||||
#include <QtWidgets/QtWidgets>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#endif
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
@ -28,6 +53,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include <nel/misc/common.h>
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,7 +65,7 @@ struct CBuildInfo
|
|||
TColorMaskVect ColorMasks;
|
||||
// how to shift right the size of the src Bitmap for the .hlsinfo
|
||||
uint LowDefShift;
|
||||
uint OptimizeTextures; // 0 = don't optimize, 1 = check, 2 = optimize
|
||||
uint OptimizeTextures; // 0 = don't check, 1 = check
|
||||
};
|
||||
|
||||
|
||||
|
@ -351,7 +351,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
catch (const NLMISC::EUnknownVar &)
|
||||
{
|
||||
// don't optimize files by default
|
||||
// don't check files by default
|
||||
bi.OptimizeTextures = 0;
|
||||
}
|
||||
}
|
||||
|
@ -667,55 +667,12 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
|||
throw NLMISC::Exception("Failed to load bitmap");
|
||||
}
|
||||
|
||||
// if bitmap is RGBA but has an alpha channel fully transparent,
|
||||
// if bitmap is RGBA but has an alpha channel fully opaque (255),
|
||||
// we can save it as RGB to optimize it
|
||||
if (bi.OptimizeTextures > 0 && depth == 32)
|
||||
{
|
||||
uint8 value = 0;
|
||||
|
||||
// texture can be converted if all alphas are 255
|
||||
if (srcBitmap.isAlphaUniform(&value) && value == 255)
|
||||
if (bi.OptimizeTextures > 0 && depth == 32 && srcBitmap.isAlphaUniform(&value) && value == 255)
|
||||
{
|
||||
if (bi.OptimizeTextures > 1)
|
||||
{
|
||||
// make bitmap opaque
|
||||
srcBitmap.makeOpaque();
|
||||
|
||||
// original depth is now 24 bits, since we discarded alpha channel
|
||||
depth = 24;
|
||||
|
||||
NLMISC::COFile os;
|
||||
|
||||
if (os.open(fullInputBitmapPath))
|
||||
{
|
||||
nlwarning("Optimizing texture %s...", fullInputBitmapPath.c_str());
|
||||
|
||||
std::string ext = CFile::getExtension(fullInputBitmapPath);
|
||||
|
||||
// resave the texture in optimized same format
|
||||
if (ext == "png")
|
||||
{
|
||||
srcBitmap.writePNG(os, 24);
|
||||
}
|
||||
else if (ext == "tga")
|
||||
{
|
||||
srcBitmap.writeTGA(os, 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Don't support %s format for texture, unable to save it", ext.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Unable to save texture %s", fullInputBitmapPath.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Texture %s can be optimized", fullInputBitmapPath.c_str());
|
||||
}
|
||||
}
|
||||
nlwarning("Texture %s can be optimized, run textures_optimizer", fullInputBitmapPath.c_str());
|
||||
}
|
||||
|
||||
if (srcBitmap.PixelFormat != NLMISC::CBitmap::RGBA)
|
||||
|
@ -794,36 +751,10 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
|||
throw NLMISC::Exception("Failed to load mask");
|
||||
}
|
||||
|
||||
// convert color mask to grayscale (red is the new gray value)
|
||||
if (li.Mask.getPixelFormat() == CBitmap::RGBA)
|
||||
{
|
||||
// display a warning if checks enabled
|
||||
if (bi.OptimizeTextures > 0 && !li.Mask.isGrayscale())
|
||||
if (li.Mask.getPixelFormat() == CBitmap::RGBA && bi.OptimizeTextures > 0 && !li.Mask.isGrayscale())
|
||||
{
|
||||
nlwarning("Mask %s is using colors, results may by incorrect! Use OptimizeTextures = 2 to fix it.", maskFileName.c_str());
|
||||
}
|
||||
|
||||
// get a pointer on original data
|
||||
uint32 size = li.Mask.getPixels().size();
|
||||
uint32 *data = (uint32*)li.Mask.getPixels().getPtr();
|
||||
uint32 *endData = (uint32*)((uint8*)data + size);
|
||||
|
||||
NLMISC::CRGBA *color = NULL;
|
||||
|
||||
// process all pixels
|
||||
while(data < endData)
|
||||
{
|
||||
color = (NLMISC::CRGBA*)data;
|
||||
|
||||
// copy red value to green and blue,
|
||||
// because only red is used for mask
|
||||
color->B = color->G = color->R;
|
||||
|
||||
// make opaque
|
||||
color->A = 255;
|
||||
|
||||
++data;
|
||||
}
|
||||
nlwarning("Mask %s is using colors, results may by incorrect! Run textures_optimizer to fix it.", maskFileName.c_str());
|
||||
}
|
||||
|
||||
// convert image to real grayscale
|
||||
|
@ -832,40 +763,6 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
|||
li.Mask.convertToType(NLMISC::CBitmap::Luminance);
|
||||
}
|
||||
|
||||
// masks can be converted to grayscale files
|
||||
if (bi.OptimizeTextures > 0 && maskDepth > 8)
|
||||
{
|
||||
if (bi.OptimizeTextures > 1)
|
||||
{
|
||||
NLMISC::COFile os;
|
||||
|
||||
if (os.open(maskFileName))
|
||||
{
|
||||
std::string ext = NLMISC::toLower(CFile::getExtension(maskFileName));
|
||||
|
||||
nlwarning("Optimizing mask %s...", maskFileName.c_str());
|
||||
|
||||
// resave the texture in optimized same format
|
||||
if (ext == "png")
|
||||
{
|
||||
li.Mask.writePNG(os, 8);
|
||||
}
|
||||
else if (ext == "tga")
|
||||
{
|
||||
li.Mask.writeTGA(os, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Don't support %s format for mask, unable to save it", ext.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Mask %s can be optimized", maskFileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/// make sure the mask has the same size
|
||||
if (li.Mask.getWidth() != srcBitmap.getWidth()
|
||||
|| li.Mask.getHeight() != srcBitmap.getHeight())
|
||||
|
|
|
@ -43,6 +43,7 @@ static void compressMipMap(uint8 *pixSrc, sint width, sint height, vector<uint8
|
|||
case DXT1A:
|
||||
flags |= squish::kDxt1;
|
||||
dest.ddpf.dwFourCC = MAKEFOURCC('D', 'X', 'T', '1');
|
||||
// TODO: add special headers flags for DXTC1a
|
||||
break;
|
||||
case DXT3:
|
||||
flags |= squish::kDxt3;
|
||||
|
|
|
@ -463,6 +463,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: if alpha channel is 0, use DXTC1a instead DXTC1
|
||||
if(imageDepth==24)
|
||||
algo = DXT1;
|
||||
else
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${QT_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/pic)
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
|
||||
FIND_PACKAGE(JPEG)
|
||||
INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
FILE(GLOB TILE_EDIT_SRC *.cpp *.h)
|
||||
FILE(GLOB PIC_SRC pic/*.c pic/*.cpp)
|
||||
|
@ -10,22 +6,35 @@ SET(TILE_EDIT_HDR items_edit_dlg.h tile_browser_dlg.h tile_edit_dlg.h tile_rotat
|
|||
SET(TILE_EDIT_UIS tile_widget_qt.ui tile_rotation_qt.ui tile_edit_qt.ui tile_browser_qt.ui items_edit_qt.ui)
|
||||
SET(TILE_EDIT_RCS tile_edit_qt.qrc)
|
||||
|
||||
IF(WITH_QT)
|
||||
INCLUDE_DIRECTORIES(${QT_INCLUDES})
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
|
||||
QT4_ADD_RESOURCES(TILE_EDIT_RC_SRCS ${TILE_EDIT_RCS})
|
||||
QT4_WRAP_UI(TILE_EDIT_UI_HDRS ${TILE_EDIT_UIS})
|
||||
QT4_WRAP_CPP(TILE_EDIT_MOC_SRCS ${TILE_EDIT_HDR})
|
||||
|
||||
ADD_DEFINITIONS(${QT_DEFINITIONS})
|
||||
ELSEIF(WITH_QT5)
|
||||
QT5_ADD_RESOURCES(TILE_EDIT_RC_SRCS ${TILE_EDIT_RCS})
|
||||
QT5_WRAP_UI(TILE_EDIT_UI_HDRS ${TILE_EDIT_UIS})
|
||||
QT5_WRAP_CPP(TILE_EDIT_MOC_SRCS ${TILE_EDIT_HDR})
|
||||
ENDIF()
|
||||
|
||||
|
||||
SOURCE_GROUP(QtResources FILES ${TILE_EDIT_UIS} ${TILE_EDIT_RCS})
|
||||
SOURCE_GROUP(QtGeneratedUiHdr FILES ${TILE_EDIT_UI_HDRS})
|
||||
SOURCE_GROUP(QtGeneratedMocSrc FILES ${TILE_EDIT_MOC_SRCS})
|
||||
SOURCE_GROUP(PICLibrary FILES ${PIC_SRC})
|
||||
|
||||
ADD_EXECUTABLE(tile_edit_qt ${TILE_EDIT_SRC} ${PIC_SRC} ${TILE_EDIT_MOC_SRCS} ${TILE_EDIT_RC_SRCS} ${TILE_EDIT_UI_HDRS})
|
||||
ADD_EXECUTABLE(tile_edit_qt WIN32 ${TILE_EDIT_SRC} ${TILE_EDIT_MOC_SRCS} ${TILE_EDIT_RC_SRCS} ${TILE_EDIT_UI_HDRS})
|
||||
|
||||
TARGET_LINK_LIBRARIES(tile_edit_qt ${QT_LIBRARIES} ${JPEG_LIBRARY} nelmisc nel3d)
|
||||
TARGET_LINK_LIBRARIES(tile_edit_qt ${QT_LIBRARIES} nelmisc nel3d)
|
||||
NL_DEFAULT_PROPS(tile_edit_qt "NeL, Tools, 3D: Qt Tile Editor")
|
||||
NL_ADD_RUNTIME_FLAGS(tile_edit_qt)
|
||||
|
||||
ADD_DEFINITIONS(${QT_DEFINITIONS})
|
||||
IF(WITH_PCH)
|
||||
ADD_NATIVE_PRECOMPILED_HEADER(tile_edit_qt ${CMAKE_CURRENT_SOURCE_DIR}/common.h ${CMAKE_CURRENT_SOURCE_DIR}/common.cpp)
|
||||
ENDIF()
|
||||
|
||||
INSTALL(TARGETS tile_edit_qt RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT tools3d)
|
||||
|
||||
|
|
|
@ -14,19 +14,9 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include "common.h"
|
||||
#include "browser_model.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <nel/3d/tile_bank.h>
|
||||
#include <nel/misc/stream.h>
|
||||
#include <nel/misc/file.h>
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
#include "pic/readpic.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NL3D;
|
||||
using namespace NLMISC;
|
||||
|
@ -34,6 +24,37 @@ using namespace NLMISC;
|
|||
extern CTileBank tileBankBrowser;
|
||||
static const char* comp[]={"Red", "Green", "Blue", "Alpha", ""};
|
||||
|
||||
static bool loadPic(const string &path, std::vector<NLMISC::CBGRA> &tampon, uint &width, uint &height)
|
||||
{
|
||||
try
|
||||
{
|
||||
NLMISC::CIFile file;
|
||||
if (file.open(path.c_str()))
|
||||
{
|
||||
NLMISC::CBitmap bitmap;
|
||||
bitmap.load(file);
|
||||
width = bitmap.getWidth();
|
||||
height = bitmap.getHeight();
|
||||
tampon.resize(width * height);
|
||||
bitmap.convertToType(NLMISC::CBitmap::RGBA);
|
||||
for (uint y = 0; y < height; ++y)
|
||||
{
|
||||
for (uint x = 0; x < width; ++x)
|
||||
{
|
||||
NLMISC::CRGBA c = bitmap.getPixelColor(x, y, 0);
|
||||
c.R = (c.R * c.A) / 255;
|
||||
c.G = (c.G * c.A) / 255;
|
||||
c.B = (c.B * c.A) / 255;
|
||||
tampon[(y * width) + x] = c;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NLMISC::Exception& ) { }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RemovePath (std::string& path, const char* absolutePathToRemplace);
|
||||
|
||||
// Rotate a buffer
|
||||
|
@ -65,7 +86,7 @@ int loadPixmapBuffer(const std::string& path, std::vector<NLMISC::CBGRA>& Buffer
|
|||
{
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (PIC_LoadPic(path, Buffer, Width, Height))
|
||||
if (loadPic(path, Buffer, Width, Height))
|
||||
{
|
||||
while (rot)
|
||||
{
|
||||
|
@ -278,7 +299,7 @@ bool TileList::setTile128 (int tile, const std::string& name, NL3D::CTile::TBitm
|
|||
vector<NLMISC::CBGRA> tampon;
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (!PIC_LoadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
if (!loadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
{
|
||||
return ( QMessageBox::Yes == QMessageBox::question( NULL, QObject::tr("Can't load bitmap."), QString( ((tileBankBrowser.getAbsPath ()+troncated)+"\nContinue ?").c_str() ), QMessageBox::Yes | QMessageBox::No));
|
||||
}
|
||||
|
@ -343,7 +364,7 @@ bool TileList::setTile256 (int tile, const std::string& name, NL3D::CTile::TBitm
|
|||
vector<NLMISC::CBGRA> tampon;
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (!PIC_LoadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
if (!loadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
{
|
||||
return ( QMessageBox::Yes == QMessageBox::question( NULL, QObject::tr("Can't load bitmap."), QString( ((tileBankBrowser.getAbsPath ()+troncated)+"\nContinue ?").c_str() ), QMessageBox::Yes | QMessageBox::No) );
|
||||
|
||||
|
@ -409,7 +430,7 @@ bool TileList::setTileTransition (int tile, const std::string& name, NL3D::CTile
|
|||
vector<NLMISC::CBGRA> tampon;
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (!PIC_LoadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
if (!loadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
{
|
||||
return ( QMessageBox::Yes == QMessageBox::question( NULL, QObject::tr("Can't load bitmap."), QString( ((tileBankBrowser.getAbsPath ()+troncated)+"\nContinue ?").c_str() ), QMessageBox::Yes | QMessageBox::No) );
|
||||
}
|
||||
|
@ -473,7 +494,7 @@ bool TileList::setDisplacement (int tile, const std::string& name, NL3D::CTile::
|
|||
vector<NLMISC::CBGRA> tampon;
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (!PIC_LoadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
if (!loadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
{
|
||||
return ( QMessageBox::Yes == QMessageBox::question( NULL, QObject::tr("Can't load bitmap"), QString( ((tileBankBrowser.getAbsPath ()+troncated)+"\nContinue ?").c_str() ), QMessageBox::Yes | QMessageBox::No) );
|
||||
}
|
||||
|
@ -516,7 +537,7 @@ bool TileList::setTileTransitionAlpha (int tile, const std::string& name, int ro
|
|||
vector<NLMISC::CBGRA> tampon;
|
||||
uint Width;
|
||||
uint Height;
|
||||
if (!PIC_LoadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
if (!loadPic(tileBankBrowser.getAbsPath ()+troncated, tampon, Width, Height))
|
||||
{
|
||||
return ( QMessageBox::Yes == QMessageBox::question( NULL, QObject::tr("Can't load bitmap"), QString( ((tileBankBrowser.getAbsPath ()+troncated)+"\nContinue ?").c_str() ), QMessageBox::Yes | QMessageBox::No) );
|
||||
}
|
||||
|
|
17
code/nel/tools/3d/tile_edit_qt/common.cpp
Normal file
17
code/nel/tools/3d/tile_edit_qt/common.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "common.h"
|
56
code/nel/tools/3d/tile_edit_qt/common.h
Normal file
56
code/nel/tools/3d/tile_edit_qt/common.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
||||
#undef realloc
|
||||
#undef free
|
||||
#endif
|
||||
|
||||
#include <qglobal.h>
|
||||
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
#undef Q_COMPILER_RVALUE_REFS
|
||||
#endif
|
||||
|
||||
#include <QtCore/QtCore>
|
||||
#include <QtGui/QtGui>
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#define USE_QT5
|
||||
#endif
|
||||
|
||||
#ifdef USE_QT5
|
||||
#include <QtWidgets/QtWidgets>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include <nel/3d/tile_bank.h>
|
||||
#include <nel/misc/stream.h>
|
||||
#include <nel/misc/file.h>
|
||||
#include <nel/misc/app_context.h>
|
||||
#include <nel/misc/bitmap.h>
|
||||
|
||||
#endif
|
|
@ -1,3 +1,4 @@
|
|||
#include "common.h"
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include "items_edit_dlg.h"
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef ITEMS_EDITDLG_H
|
||||
#define ITEMS_EDITDLG_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtGui/QDialog>
|
||||
#include "ui_items_edit_qt.h"
|
||||
|
||||
class CItems_edit_dlg : public QDialog
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
#include <QtGui/QApplication>
|
||||
#include "nel/misc/app_context.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "tile_edit_dlg.h"
|
||||
|
||||
#ifdef QT_STATICPLUGIN
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
||||
#elif defined(Q_OS_MAC)
|
||||
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
|
||||
#elif defined(Q_OS_UNIX)
|
||||
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if !defined(__APPLE__)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define PIC_ERRSIZE 256
|
||||
|
||||
static size_t PIC_Sys_MEM_Allocated;
|
||||
static size_t PIC_Sys_MEM_NbAllocs;
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define _msize malloc_size
|
||||
#elif defined(__GNUC__)
|
||||
#define _msize malloc_usable_size
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
void *Pic_malloc(unsigned long size)
|
||||
{
|
||||
void *mem;
|
||||
mem=malloc(size);
|
||||
if (mem)
|
||||
{
|
||||
PIC_Sys_MEM_Allocated+=size;
|
||||
PIC_Sys_MEM_NbAllocs++;
|
||||
}
|
||||
return(mem);
|
||||
}
|
||||
/* ----- */
|
||||
void *Pic_calloc(size_t count, size_t size)
|
||||
{
|
||||
void *mem;
|
||||
mem=calloc(count,size);
|
||||
if (mem)
|
||||
{
|
||||
PIC_Sys_MEM_Allocated+=(size*count);
|
||||
PIC_Sys_MEM_NbAllocs++;
|
||||
}
|
||||
return(mem);
|
||||
}
|
||||
/* ----- */
|
||||
void Pic_free(void *memblock)
|
||||
{
|
||||
size_t size;
|
||||
size=_msize(memblock);
|
||||
PIC_Sys_MEM_Allocated-=size;
|
||||
PIC_Sys_MEM_NbAllocs--;
|
||||
free(memblock);
|
||||
}
|
||||
/* ----- */
|
||||
size_t Pic__msize(void *memblock)
|
||||
{
|
||||
return(_msize(memblock));
|
||||
}
|
||||
/* ----- */
|
||||
size_t PIC_GetMemNbAllocs(void)
|
||||
{
|
||||
return(PIC_Sys_MEM_NbAllocs);
|
||||
}
|
||||
/* ----- */
|
||||
size_t PIC_GetMemAllocated(void)
|
||||
{
|
||||
return(PIC_Sys_MEM_Allocated);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static unsigned char PIC_ErrorFlag;
|
||||
static unsigned char PIC_ErrorString[PIC_ERRSIZE];
|
||||
static unsigned char PIC_Sys_FnctActive=0;
|
||||
static void (*PIC_Sys_Fnct)(void);
|
||||
|
||||
void Pic_SetError(const char *msg, ...)
|
||||
{
|
||||
unsigned char curerr[PIC_ERRSIZE],olderr[PIC_ERRSIZE];
|
||||
va_list args;
|
||||
|
||||
va_start(args,msg);
|
||||
vsprintf(curerr,msg,args);
|
||||
va_end(args);
|
||||
if ( (strlen(curerr)+strlen(PIC_ErrorString))>PIC_ERRSIZE ) return;
|
||||
|
||||
if (PIC_ErrorFlag)
|
||||
{
|
||||
strcpy(olderr,PIC_ErrorString);
|
||||
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
|
||||
strcat(PIC_ErrorString,"\n");
|
||||
strcat(PIC_ErrorString,olderr);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
|
||||
}
|
||||
PIC_ErrorFlag++;
|
||||
if (PIC_Sys_FnctActive) PIC_Sys_Fnct();
|
||||
return;
|
||||
}
|
||||
/* ----- */
|
||||
char* PIC_GetError(void)
|
||||
{
|
||||
return(PIC_ErrorString);
|
||||
}
|
||||
/* ----- */
|
||||
unsigned char PIC_Error(void)
|
||||
{
|
||||
return(PIC_ErrorFlag);
|
||||
}
|
||||
/* ----- */
|
||||
void PIC_ResetError(void)
|
||||
{
|
||||
strcpy(PIC_ErrorString,"");
|
||||
PIC_ErrorFlag=0;
|
||||
}
|
||||
/* ----- */
|
||||
unsigned char PIC_OnErrorCall( void pFnct(void) )
|
||||
{
|
||||
if (pFnct != NULL)
|
||||
{
|
||||
PIC_Sys_Fnct=pFnct;
|
||||
PIC_Sys_FnctActive=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
PIC_Sys_FnctActive=0;
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pic_private.h"
|
||||
#include "pic.h"
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct BMP_HEADER
|
||||
{
|
||||
unsigned short bfType;
|
||||
unsigned long bfSize;
|
||||
unsigned short Res1;
|
||||
unsigned short Res2;
|
||||
unsigned long bfOffBits;
|
||||
unsigned long biSize;
|
||||
unsigned long biWidth;
|
||||
unsigned long biHeight;
|
||||
unsigned short biPlanes;
|
||||
unsigned short biBitCount;
|
||||
unsigned long biCompression;
|
||||
unsigned long biSizeImage;
|
||||
unsigned long biXPelsPerMeter;
|
||||
unsigned long biYPelsPerMeter;
|
||||
unsigned long biClrUsed;
|
||||
unsigned long biClrImportant;
|
||||
} BMP_HEADER;
|
||||
#pragma pack()
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_BMP_Write( const char *FileName,
|
||||
unsigned char *pPal,unsigned char *pDatas,
|
||||
unsigned long w, unsigned long h, unsigned long d)
|
||||
|
||||
{
|
||||
FILE *file;
|
||||
BMP_HEADER bmph;
|
||||
unsigned long slsize;
|
||||
unsigned char *scanline;
|
||||
unsigned long i;
|
||||
long x,y,rest;
|
||||
unsigned char r,g,b;
|
||||
|
||||
file=fopen(FileName,"wb");
|
||||
if (!file)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
memset(&bmph,0,sizeof(BMP_HEADER));
|
||||
bmph.bfType=19778;
|
||||
bmph.bfSize=sizeof(BMP_HEADER);
|
||||
bmph.bfSize+=w*h*d/8;
|
||||
if (pPal)
|
||||
{
|
||||
bmph.bfSize+=(256*4);
|
||||
}
|
||||
bmph.bfOffBits=sizeof(BMP_HEADER);
|
||||
if (pPal)
|
||||
{
|
||||
bmph.bfOffBits+=(256*4);
|
||||
}
|
||||
bmph.biSize=40;/*sizeof(BMP_HEADER);*/
|
||||
bmph.biWidth=w;
|
||||
bmph.biHeight=h;
|
||||
bmph.biPlanes=1;
|
||||
bmph.biBitCount=(unsigned short)d;
|
||||
bmph.biCompression=0;
|
||||
bmph.biSizeImage=w*h*d/8;
|
||||
|
||||
fwrite(&bmph,1,sizeof(BMP_HEADER),file);
|
||||
if (pPal)
|
||||
{
|
||||
for(i=0 ; i<256 ; i++)
|
||||
{
|
||||
fwrite(&pPal[i*3+0],1,1,file);
|
||||
fwrite(&pPal[i*3+1],1,1,file);
|
||||
fwrite(&pPal[i*3+2],1,1,file);
|
||||
fwrite(&pPal[i*3+2],1,1,file);
|
||||
}
|
||||
}
|
||||
slsize=w*d/8;
|
||||
scanline=Pic_calloc(1,slsize);
|
||||
if (!scanline)
|
||||
{
|
||||
Pic_SetError("BMP_Write, not enough memory for scanline");
|
||||
return(0);
|
||||
}
|
||||
for(rest=0 ; ((w*d/8)+rest)%4!=0 ; rest++);
|
||||
for(y=0 ; y<(long)h ; y++)
|
||||
{
|
||||
memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize);
|
||||
if (d==24)
|
||||
{
|
||||
for(x=0 ; x<(long)w ; x++)
|
||||
{
|
||||
b=scanline[x*3+0];
|
||||
g=scanline[x*3+1];
|
||||
r=scanline[x*3+2];
|
||||
scanline[x*3+0]=b;
|
||||
scanline[x*3+1]=g;
|
||||
scanline[x*3+2]=r;
|
||||
}
|
||||
}
|
||||
fwrite(scanline,1,slsize,file);
|
||||
if (rest)
|
||||
{
|
||||
fwrite(scanline,1,rest,file);
|
||||
}
|
||||
}
|
||||
Pic_free(scanline);
|
||||
fclose(file);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_BMP_Read( const char *FileName,
|
||||
unsigned char **ppPal, unsigned char **ppDatas,
|
||||
unsigned long *pWidth, unsigned long *pHeight,
|
||||
unsigned long *pDepth)
|
||||
{
|
||||
FILE *file;
|
||||
BMP_HEADER bmph;
|
||||
unsigned char *pPal;
|
||||
unsigned char *pDatas;
|
||||
unsigned char *scanline;
|
||||
long w,h,d;
|
||||
long i,x,y,rest;
|
||||
unsigned char r,g,b;
|
||||
unsigned char pad[4];
|
||||
|
||||
pPal=NULL;
|
||||
pDatas=NULL;
|
||||
file=fopen(FileName,"rb");
|
||||
if (!file)
|
||||
{
|
||||
Pic_SetError("BMP_Read, unable to open %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
fread(&bmph,1,sizeof(BMP_HEADER),file);
|
||||
*pWidth=w=bmph.biWidth;
|
||||
*pHeight=h=bmph.biHeight;
|
||||
*pDepth=d=bmph.biBitCount;
|
||||
if (d!=8 && d!=24)
|
||||
{
|
||||
Pic_SetError("BMP_Read, number of bits per pixel unsupported");
|
||||
return(0);
|
||||
}
|
||||
if (*pDepth==8)
|
||||
{
|
||||
pPal=Pic_calloc(1,256*3);
|
||||
if (!pPal)
|
||||
{
|
||||
Pic_SetError("BMP_Read, not enough memory for palette");
|
||||
return(0);
|
||||
}
|
||||
for(i=0 ; i<256 ; i++)
|
||||
{
|
||||
fread(&pPal[i*3+2],1,1,file);
|
||||
fread(&pPal[i*3+1],1,1,file);
|
||||
fread(&pPal[i*3+0],1,1,file);
|
||||
fread(&pad[0],1,1,file);
|
||||
}
|
||||
}
|
||||
pDatas=Pic_calloc(1,w*h*d/8);
|
||||
if (!pDatas)
|
||||
{
|
||||
if (pPal)
|
||||
{
|
||||
Pic_free(pPal);
|
||||
}
|
||||
Pic_SetError("BMP_Read, not enough memory for datas");
|
||||
return(0);
|
||||
}
|
||||
scanline=Pic_calloc(1,w*h*d/8);
|
||||
if (!scanline)
|
||||
{
|
||||
if (pPal)
|
||||
{
|
||||
Pic_free(pPal);
|
||||
}
|
||||
Pic_free(pDatas);
|
||||
Pic_SetError("BMP_Read, not enough memory for scanline");
|
||||
return(0);
|
||||
}
|
||||
for(rest=0 ; (w+rest)%4!=0 ; rest++);
|
||||
for(y=0 ; y<h ; y++)
|
||||
{
|
||||
fread(scanline,w,d/8,file);
|
||||
if (d==24)
|
||||
{
|
||||
for(x=0 ; x<w ; x++)
|
||||
{
|
||||
r=scanline[x*3+0];
|
||||
g=scanline[x*3+1];
|
||||
b=scanline[x*3+2];
|
||||
scanline[x*3+0]=b;
|
||||
scanline[x*3+1]=g;
|
||||
scanline[x*3+2]=r;
|
||||
}
|
||||
}
|
||||
memcpy(&pDatas[(h-y-1)*w*d/8],scanline,w*d/8);
|
||||
fread(pad,rest,d/8,file);
|
||||
}
|
||||
fclose(file);
|
||||
Pic_free(scanline);
|
||||
*ppPal=pPal;
|
||||
*ppDatas=pDatas;
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
|
@ -1,160 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jpeglib.h"
|
||||
#include "pic_private.h"
|
||||
#include "pic.h"
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct my_error_mgr
|
||||
{
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buffer;
|
||||
};
|
||||
typedef struct my_error_mgr * my_error_ptr;
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static unsigned char error;
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
void my_error_exit(j_common_ptr cinfo)
|
||||
{
|
||||
my_error_ptr myerr = (my_error_ptr) cinfo->err;
|
||||
error=1;
|
||||
longjmp(myerr->setjmp_buffer, 1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_JPG_Read(const char *FileName, unsigned char **ppPal, unsigned char **ppDatas, unsigned long *w, unsigned long *h)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct my_error_mgr jerr;
|
||||
FILE *file;
|
||||
JSAMPARRAY buffer;
|
||||
int row_stride,i;
|
||||
unsigned char *pDatas,*pPal;
|
||||
unsigned long ptr;
|
||||
|
||||
error=0;
|
||||
ptr=0;
|
||||
file=fopen(FileName, "rb");
|
||||
if (!file)
|
||||
{
|
||||
Pic_SetError("JPG_Read, unable to open %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
setjmp(jerr.setjmp_buffer);
|
||||
if (error)
|
||||
{
|
||||
Pic_SetError("JPG_Read, internal decompression error");
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
return(0);
|
||||
}
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, file);
|
||||
(void) jpeg_read_header(&cinfo, TRUE);
|
||||
*w=cinfo.image_width;
|
||||
*h=cinfo.image_height;
|
||||
if (!ppPal)
|
||||
{
|
||||
pDatas=Pic_calloc(1,(*w)*(*h)*3);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDatas=Pic_calloc(1,(*w)*(*h));
|
||||
pPal=Pic_calloc(1,256*3);
|
||||
if (!pPal)
|
||||
{
|
||||
Pic_SetError("JPG_Read, not enough memory for palette");
|
||||
return(0);
|
||||
}
|
||||
cinfo.desired_number_of_colors = 256;
|
||||
cinfo.quantize_colors = TRUE;
|
||||
cinfo.dither_mode = JDITHER_ORDERED;
|
||||
}
|
||||
if (!pDatas)
|
||||
{
|
||||
Pic_SetError("JPG_Read, not enough memory for pic");
|
||||
return(0);
|
||||
}
|
||||
(void) jpeg_start_decompress(&cinfo);
|
||||
row_stride = cinfo.output_width * cinfo.output_components;
|
||||
buffer = (*cinfo.mem->alloc_sarray)
|
||||
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
|
||||
while (cinfo.output_scanline < cinfo.output_height)
|
||||
{
|
||||
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
|
||||
memcpy(&pDatas[ptr],buffer[0],row_stride);
|
||||
ptr+=row_stride;
|
||||
}
|
||||
*ppDatas=pDatas;
|
||||
if (ppPal)
|
||||
{
|
||||
for(i=0 ; i<256 ; i++)
|
||||
{
|
||||
pPal[i*3+0]=cinfo.colormap[2][i];
|
||||
pPal[i*3+1]=cinfo.colormap[1][i];
|
||||
pPal[i*3+2]=cinfo.colormap[0][i];
|
||||
}
|
||||
*ppPal=pPal;
|
||||
}
|
||||
(void) jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_JPG_Write(const char *FileName, unsigned long Qual, unsigned char *pDatas, unsigned long w, unsigned long h)
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
struct my_error_mgr jerr;
|
||||
FILE *file;
|
||||
JSAMPROW row_pointer[1];
|
||||
int row_stride;
|
||||
|
||||
error=0;
|
||||
file=fopen(FileName,"wb");
|
||||
if (!file)
|
||||
{
|
||||
Pic_SetError("JPG_Write, unable to open %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
jpeg_create_compress(&cinfo);
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = my_error_exit;
|
||||
setjmp(jerr.setjmp_buffer);
|
||||
if (error)
|
||||
{
|
||||
Pic_SetError("JPG_Write, internal compression error");
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return(0);
|
||||
}
|
||||
jpeg_stdio_dest(&cinfo, file);
|
||||
cinfo.image_width = w;
|
||||
cinfo.image_height = h;
|
||||
cinfo.input_components = 3;
|
||||
cinfo.in_color_space = JCS_RGB;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, Qual, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
row_stride = w * 3;
|
||||
while(cinfo.next_scanline<cinfo.image_height)
|
||||
{
|
||||
row_pointer[0] = & pDatas[cinfo.next_scanline * row_stride];
|
||||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||
}
|
||||
jpeg_finish_compress(&cinfo);
|
||||
fclose(file);
|
||||
jpeg_destroy_compress(&cinfo);
|
||||
return(1);
|
||||
}
|
|
@ -1,654 +0,0 @@
|
|||
#include <string.h>
|
||||
#include "pic_private.h"
|
||||
#include "pic.h"
|
||||
|
||||
static unsigned long NbPics=0;
|
||||
static PIC_PICTURE *HeadPic=NULL;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <ctype.h>
|
||||
|
||||
char *strupr(char *string)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (string)
|
||||
{
|
||||
for (s = string; *s; ++s)
|
||||
*s = toupper(*s);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static PIC_PICTURE *GetPic(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
|
||||
for(pic=HeadPic ; pic ; pic=pic->Next)
|
||||
{
|
||||
if (pic->ID==id)
|
||||
{
|
||||
return(pic);
|
||||
}
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long PIC_Load(char* FileName, unsigned char Quantize)
|
||||
{
|
||||
unsigned char ext[4];
|
||||
unsigned long type;
|
||||
unsigned long i,taken,id;
|
||||
PIC_PICTURE *pic;
|
||||
unsigned char *pDatas;
|
||||
unsigned char *pPal;
|
||||
unsigned long w,h,Depth;
|
||||
unsigned long ret;
|
||||
|
||||
/* --- Init */
|
||||
|
||||
ret=0;
|
||||
type=0;
|
||||
id=0;
|
||||
taken=0;
|
||||
w=0;
|
||||
h=0;
|
||||
Depth=0;
|
||||
pic=NULL;
|
||||
pDatas=NULL;
|
||||
pPal=NULL;
|
||||
/* --- Get 1st available ID */
|
||||
for(i=1 ; i<=NbPics+1 ; i++)
|
||||
{
|
||||
taken=0;
|
||||
for(pic=HeadPic ; pic ; pic=pic->Next)
|
||||
{
|
||||
if (pic->ID==i)
|
||||
{
|
||||
taken=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!taken)
|
||||
{
|
||||
id=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!id)
|
||||
{
|
||||
Pic_SetError("Load, unable to create ID");
|
||||
return(0);
|
||||
}
|
||||
/* --- Load pic */
|
||||
if (FileName)
|
||||
{
|
||||
ext[0]=FileName[strlen(FileName)-3];
|
||||
ext[1]=FileName[strlen(FileName)-2];
|
||||
ext[2]=FileName[strlen(FileName)-1];
|
||||
ext[3]=0;
|
||||
strupr(ext);
|
||||
if ( !strcmp(ext,"JPG") )
|
||||
{
|
||||
type=1;
|
||||
}
|
||||
else if ( !strcmp(ext,"TGA") )
|
||||
{
|
||||
type=2;
|
||||
}
|
||||
else if ( !strcmp(ext,"BMP") )
|
||||
{
|
||||
type=3;
|
||||
}
|
||||
|
||||
switch(type)
|
||||
{
|
||||
/* - JPG */
|
||||
case 1:
|
||||
if (!Quantize)
|
||||
{
|
||||
Depth=24;
|
||||
ret=Pic_JPG_Read(FileName,NULL,&pDatas,&w,&h);
|
||||
}
|
||||
else
|
||||
{
|
||||
Depth=8;
|
||||
ret=Pic_JPG_Read(FileName,&pPal,&pDatas,&w,&h);
|
||||
}
|
||||
if (!ret)
|
||||
{
|
||||
Pic_SetError("Load, unable to load JPG file %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
break;
|
||||
/* - TGA */
|
||||
case 2:
|
||||
ret=Pic_TGA_Read(FileName,&pPal,&pDatas,&w,&h,&Depth);
|
||||
if (!ret)
|
||||
{
|
||||
Pic_SetError("Load, unable to load TGA file %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
break;
|
||||
/* - BMP */
|
||||
case 3:
|
||||
ret=Pic_BMP_Read(FileName,&pPal,&pDatas,&w,&h,&Depth);
|
||||
if (!ret)
|
||||
{
|
||||
Pic_SetError("Load, unable to load BMP file %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
break;
|
||||
/* - Unknown */
|
||||
default:
|
||||
Pic_SetError("Load, unknown extension for %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Create and place new pic struct */
|
||||
pic=Pic_calloc(1,sizeof(PIC_PICTURE));
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Load, not enough memory for internal structure");
|
||||
return(0);
|
||||
}
|
||||
pic->Next=HeadPic;
|
||||
HeadPic=pic;
|
||||
NbPics++;
|
||||
pic->ID=id;
|
||||
pic->pDatas=pDatas;
|
||||
pic->pPal=pPal;
|
||||
pic->Width=w;
|
||||
pic->Height=h;
|
||||
pic->Depth=Depth;
|
||||
return(id);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long PIC_Create(unsigned char* pPal, unsigned char* pDatas, unsigned long w, unsigned long h, unsigned long d)
|
||||
{
|
||||
unsigned long i,taken,id;
|
||||
PIC_PICTURE *pic;
|
||||
|
||||
/* --- Init */
|
||||
id=0;
|
||||
taken=0;
|
||||
pic=NULL;
|
||||
/* --- Get 1st available ID */
|
||||
for(i=1 ; i<=NbPics+1 ; i++)
|
||||
{
|
||||
taken=0;
|
||||
for(pic=HeadPic ; pic ; pic=pic->Next)
|
||||
{
|
||||
if (pic->ID==i)
|
||||
{
|
||||
taken=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!taken)
|
||||
{
|
||||
id=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!id)
|
||||
{
|
||||
Pic_SetError("Create, unable to create ID");
|
||||
return(0);
|
||||
}
|
||||
/* --- Create pic */
|
||||
if (!pDatas)
|
||||
{
|
||||
pDatas=Pic_calloc(1,w*h*d/8);
|
||||
if (!pDatas)
|
||||
{
|
||||
Pic_SetError("Create, not enough memory for datas");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
if (d==8)
|
||||
{
|
||||
if (!pPal)
|
||||
{
|
||||
pPal=Pic_calloc(1,256*3);
|
||||
if (!pPal)
|
||||
{
|
||||
Pic_SetError("Create, not enough memory for palette");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pPal=NULL;
|
||||
}
|
||||
/* --- Create and place new pic struct */
|
||||
pic=Pic_calloc(1,sizeof(PIC_PICTURE));
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Create, not enough memory for internal structure");
|
||||
return(0);
|
||||
}
|
||||
pic->Next=HeadPic;
|
||||
HeadPic=pic;
|
||||
NbPics++;
|
||||
pic->ID=id;
|
||||
pic->pDatas=pDatas;
|
||||
pic->pPal=pPal;
|
||||
pic->Width=w;
|
||||
pic->Height=h;
|
||||
pic->Depth=d;
|
||||
return(id);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long PIC_GetInfos( unsigned long id,
|
||||
unsigned char* *ppPal, unsigned char* *ppDatas,
|
||||
unsigned long *pW, unsigned long *pH, unsigned long *pD)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("GetInfos, picture internal structure not found");
|
||||
return(0);
|
||||
}
|
||||
if (ppPal)
|
||||
{
|
||||
*ppPal=pic->pPal;
|
||||
}
|
||||
if (ppDatas)
|
||||
{
|
||||
*ppDatas=pic->pDatas;
|
||||
}
|
||||
if (pW)
|
||||
{
|
||||
*pW=pic->Width;
|
||||
}
|
||||
if (pH)
|
||||
{
|
||||
*pH=pic->Height;
|
||||
}
|
||||
if (pD)
|
||||
{
|
||||
*pD=pic->Depth;
|
||||
}
|
||||
return(id);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char* Conv8To24(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
unsigned char *buf;
|
||||
unsigned long i;
|
||||
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Conv8To24, picture internal structure not found");
|
||||
return(NULL);
|
||||
}
|
||||
buf=Pic_malloc(pic->Width*pic->Height*3);
|
||||
if (!buf)
|
||||
{
|
||||
Pic_SetError("Conv8To24, not enough memory for temporary buffer");
|
||||
return(NULL);
|
||||
}
|
||||
for(i=0 ; i<pic->Width*pic->Height ; i++)
|
||||
{
|
||||
buf[i*3+0]=pic->pPal[pic->pDatas[i]*3+0];
|
||||
buf[i*3+1]=pic->pPal[pic->pDatas[i]*3+1];
|
||||
buf[i*3+2]=pic->pPal[pic->pDatas[i]*3+2];
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
static char* Conv8To16(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
unsigned short *buf;
|
||||
unsigned long i;
|
||||
unsigned short r,g,b,pix16;
|
||||
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Conv8To24, picture internal structure not found");
|
||||
return(NULL);
|
||||
}
|
||||
buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2);
|
||||
if (!buf)
|
||||
{
|
||||
Pic_SetError("Conv8To24, not enough memory for temporary buffer");
|
||||
return(NULL);
|
||||
}
|
||||
for(i=0 ; i<pic->Width*pic->Height ; i++)
|
||||
{
|
||||
b=pic->pPal[pic->pDatas[i]*3+0];
|
||||
g=pic->pPal[pic->pDatas[i]*3+1];
|
||||
r=pic->pPal[pic->pDatas[i]*3+2];
|
||||
r>>=3;
|
||||
g>>=3; g&=0x3E;
|
||||
b>>=3;
|
||||
pix16=(r<<10)+(g<<5)+b;
|
||||
buf[i]=pix16;
|
||||
}
|
||||
return((unsigned char*)buf);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
static char* Conv16To24(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
unsigned short *pDatas;
|
||||
unsigned char *buf;
|
||||
unsigned long i;
|
||||
unsigned short r,g,b;
|
||||
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Conv16To24, picture internal structure not found");
|
||||
return(NULL);
|
||||
}
|
||||
buf=Pic_malloc(pic->Width*pic->Height*3);
|
||||
if (!buf)
|
||||
{
|
||||
Pic_SetError("Conv16To24, not enough memory for temporary buffer");
|
||||
return(NULL);
|
||||
}
|
||||
pDatas=(unsigned short*)pic->pDatas;
|
||||
for(i=0 ; i<pic->Width*pic->Height ; i++)
|
||||
{
|
||||
r=(pDatas[i] & 0x7C00)>>(10-3);
|
||||
g=(pDatas[i] & 0x03E0)>>(5-3);
|
||||
b=(pDatas[i] & 0x001F)<<3;
|
||||
buf[i*3+0]=(unsigned char)r;
|
||||
buf[i*3+1]=(unsigned char)g;
|
||||
buf[i*3+2]=(unsigned char)b;
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
static char* Conv24To16(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
unsigned short *buf;
|
||||
unsigned long i;
|
||||
unsigned short r,g,b;
|
||||
unsigned short pix16;
|
||||
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Conv24To16, picture internal structure not found");
|
||||
return(NULL);
|
||||
}
|
||||
buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2);
|
||||
if (!buf)
|
||||
{
|
||||
Pic_SetError("Conv24To16, not enough memory for temporary buffer");
|
||||
return(NULL);
|
||||
}
|
||||
for(i=0 ; i<pic->Width*pic->Height ; i++)
|
||||
{
|
||||
r=pic->pDatas[i*3+0];
|
||||
g=pic->pDatas[i*3+1];
|
||||
b=pic->pDatas[i*3+2];
|
||||
/* r : 5 bits forts (0x7C) */
|
||||
/* g : 5 bits (6e zapped) (0x3E) */
|
||||
/* b : 5 bits faibles (0x1F) */
|
||||
r>>=3;
|
||||
g>>=3; g&=0x3E;
|
||||
b>>=3;
|
||||
pix16=(r<<10)+(g<<5)+b;
|
||||
buf[i]=pix16;
|
||||
}
|
||||
return((unsigned char*)buf);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
static char* ConvPic(PIC_PICTURE *pic, unsigned long type, char* pErr)
|
||||
{
|
||||
unsigned char *buf;
|
||||
unsigned long src,dst;
|
||||
|
||||
*pErr=0;
|
||||
buf=NULL;
|
||||
src=pic->Depth;
|
||||
if (type==PIC_TYPE_TGA8 || type==PIC_TYPE_BMP8)
|
||||
{
|
||||
dst=8;
|
||||
}
|
||||
if (type==PIC_TYPE_TGA16)
|
||||
{
|
||||
dst=16;
|
||||
}
|
||||
if (type==PIC_TYPE_JPG || type==PIC_TYPE_TGA24 || type==PIC_TYPE_BMP24)
|
||||
{
|
||||
dst=24;
|
||||
}
|
||||
/* --- */
|
||||
if (src==dst)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
/* --- */
|
||||
if (src==8 && dst==24)
|
||||
{
|
||||
buf=Conv8To24(pic->ID);
|
||||
if (!buf)
|
||||
{
|
||||
*pErr=1;
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
if (src==8 && dst==16)
|
||||
{
|
||||
buf=Conv8To16(pic->ID);
|
||||
if (!buf)
|
||||
{
|
||||
*pErr=1;
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
/* --- */
|
||||
if (src==16 && dst==24)
|
||||
{
|
||||
buf=Conv16To24(pic->ID);
|
||||
if (!buf)
|
||||
{
|
||||
*pErr=1;
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
/* --- */
|
||||
if (src==24 && dst==16)
|
||||
{
|
||||
buf=Conv24To16(pic->ID);
|
||||
if (!buf)
|
||||
{
|
||||
*pErr=1;
|
||||
}
|
||||
return(buf);
|
||||
}
|
||||
/* --- */
|
||||
if (src==24 && dst==8)
|
||||
{
|
||||
Pic_SetError("ConvPic, downsampling 24 to 8 bits unsupported");
|
||||
*pErr=1;
|
||||
return(NULL);
|
||||
}
|
||||
Pic_SetError("ConvPic, conversion %d to %d unsupported",src,dst);
|
||||
*pErr=1;
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
unsigned long PIC_Save(unsigned long id, const char* FileName, unsigned long type, unsigned long qual)
|
||||
{
|
||||
PIC_PICTURE *pic;
|
||||
unsigned char err;
|
||||
unsigned char *buf;
|
||||
unsigned char *freeit;
|
||||
unsigned long depth;
|
||||
|
||||
freeit=NULL;
|
||||
pic=GetPic(id);
|
||||
if (!pic)
|
||||
{
|
||||
Pic_SetError("Save %s, picture internal structure not found",FileName);
|
||||
return(0);
|
||||
}
|
||||
freeit=ConvPic(pic,type,&err);
|
||||
if (err)
|
||||
{
|
||||
Pic_SetError("Save %s, error while converting picture",FileName);
|
||||
return(0);
|
||||
}
|
||||
if (!freeit)
|
||||
{
|
||||
buf=pic->pDatas;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf=freeit;
|
||||
}
|
||||
err=0;
|
||||
switch(type)
|
||||
{
|
||||
/* --- */
|
||||
case PIC_TYPE_JPG:
|
||||
if ( !Pic_JPG_Write(FileName,qual,buf,pic->Width,pic->Height) )
|
||||
{
|
||||
if (freeit)
|
||||
{
|
||||
Pic_free(buf);
|
||||
}
|
||||
Pic_SetError("Save %s, error while saving JPG file",FileName);
|
||||
err=1;
|
||||
}
|
||||
break;
|
||||
/* --- */
|
||||
case PIC_TYPE_TGA8:
|
||||
case PIC_TYPE_TGA16:
|
||||
case PIC_TYPE_TGA24:
|
||||
if (type==PIC_TYPE_TGA8)
|
||||
{
|
||||
depth=8;
|
||||
}
|
||||
if (type==PIC_TYPE_TGA16)
|
||||
{
|
||||
depth=16;
|
||||
}
|
||||
if (type==PIC_TYPE_TGA24)
|
||||
{
|
||||
depth=24;
|
||||
}
|
||||
if ( !Pic_TGA_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) )
|
||||
{
|
||||
if (freeit)
|
||||
{
|
||||
Pic_free(freeit);
|
||||
}
|
||||
Pic_SetError("Save %s, error while saving TGA file",FileName);
|
||||
err=1;
|
||||
}
|
||||
break;
|
||||
/* --- */
|
||||
case PIC_TYPE_BMP8:
|
||||
case PIC_TYPE_BMP24:
|
||||
if (type==PIC_TYPE_BMP8)
|
||||
{
|
||||
depth=8;
|
||||
}
|
||||
if (type==PIC_TYPE_BMP24)
|
||||
{
|
||||
depth=24;
|
||||
}
|
||||
if ( !Pic_BMP_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) )
|
||||
{
|
||||
if (freeit)
|
||||
{
|
||||
Pic_free(freeit);
|
||||
}
|
||||
Pic_SetError("Save %s, error while saving BMP file",FileName);
|
||||
err=1;
|
||||
}
|
||||
break;
|
||||
/* --- */
|
||||
default:
|
||||
Pic_SetError("Save %s, unknow save format/type",FileName);
|
||||
err=1;
|
||||
break;
|
||||
}
|
||||
if (freeit)
|
||||
{
|
||||
Pic_free(freeit);
|
||||
}
|
||||
return(err-1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long PIC_Destroy(unsigned long id)
|
||||
{
|
||||
PIC_PICTURE *prevpic,*pic;
|
||||
unsigned long found;
|
||||
|
||||
prevpic=NULL;
|
||||
found=0;
|
||||
for(pic=HeadPic ; pic ; pic=pic->Next)
|
||||
{
|
||||
if (pic->ID==id)
|
||||
{
|
||||
found=1;
|
||||
break;
|
||||
}
|
||||
prevpic=pic;
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
Pic_SetError("Destroy, picture internal structure not found");
|
||||
return(0);
|
||||
}
|
||||
if (prevpic)
|
||||
{
|
||||
prevpic->Next=pic->Next;
|
||||
}
|
||||
if (pic->pDatas)
|
||||
{
|
||||
Pic_free(pic->pDatas);
|
||||
}
|
||||
if (pic->pPal)
|
||||
{
|
||||
Pic_free(pic->pPal);
|
||||
}
|
||||
if (pic==HeadPic)
|
||||
{
|
||||
HeadPic=pic->Next;
|
||||
}
|
||||
Pic_free(pic);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
|
@ -1,215 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pic_private.h"
|
||||
#include "pic.h"
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct TGA_HEADER
|
||||
{
|
||||
unsigned char LengthID;
|
||||
unsigned char CMapType;
|
||||
unsigned char ImageType;
|
||||
unsigned short Origin;
|
||||
unsigned short Length;
|
||||
unsigned char Depth;
|
||||
unsigned short XOrg;
|
||||
unsigned short YOrg;
|
||||
unsigned short Width;
|
||||
unsigned short Height;
|
||||
unsigned char ImageDepth;
|
||||
unsigned char Desc;
|
||||
} TGA_HEADER;
|
||||
#pragma pack()
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_TGA_Read( const char *FileName,
|
||||
unsigned char **ppPal, unsigned char **ppDatas,
|
||||
unsigned long *pWidth, unsigned long *pHeight,
|
||||
unsigned long *pDepth)
|
||||
{
|
||||
FILE *file;
|
||||
TGA_HEADER tgah;
|
||||
long w,h,d;
|
||||
unsigned long size;
|
||||
unsigned char *pDatas;
|
||||
unsigned char *pPal;
|
||||
long x,y;
|
||||
long slsize;
|
||||
unsigned char *scanline;
|
||||
unsigned char r,g,b;
|
||||
long i;
|
||||
int upSideDown;
|
||||
|
||||
pDatas=NULL;
|
||||
pPal=NULL;
|
||||
file=fopen(FileName,"rb");
|
||||
if (!file)
|
||||
{
|
||||
Pic_SetError("TGA_Read, unable to open %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
fread(&tgah,1,sizeof(TGA_HEADER),file);
|
||||
if (tgah.ImageType>3)
|
||||
{
|
||||
Pic_SetError("TGA_Read, unsupported TGA format");
|
||||
return(0);
|
||||
}
|
||||
*pWidth=w=tgah.Width;
|
||||
*pHeight=h=tgah.Height;
|
||||
*pDepth=d=tgah.ImageDepth;
|
||||
upSideDown = ((tgah.Desc & (1 << 5))==0);
|
||||
|
||||
size=tgah.Width*tgah.Height*(tgah.ImageDepth/8);
|
||||
pDatas=Pic_malloc(size);
|
||||
if (!pDatas)
|
||||
{
|
||||
Pic_SetError("TGA_Read, not enough memory");
|
||||
return(0);
|
||||
}
|
||||
if (*pDepth==8)
|
||||
{
|
||||
if (!ppPal)
|
||||
{
|
||||
Pic_free(pDatas);
|
||||
Pic_SetError("TGA_Read, need a pointer to palette");
|
||||
return(0);
|
||||
}
|
||||
pPal=Pic_calloc(1,256*3);
|
||||
if (!pPal)
|
||||
{
|
||||
Pic_SetError("TGA_Read, not enough memory for palette");
|
||||
return(0);
|
||||
}
|
||||
if (tgah.ImageType==1)
|
||||
{
|
||||
for(i=0 ; i<256*3 ; i+=3)
|
||||
{
|
||||
fread(&pPal[i+2],1,1,file);
|
||||
fread(&pPal[i+1],1,1,file);
|
||||
fread(&pPal[i+0],1,1,file);
|
||||
}
|
||||
}
|
||||
*ppPal=pPal;
|
||||
}
|
||||
|
||||
slsize=w*d/8;
|
||||
scanline=Pic_calloc(1,slsize);
|
||||
if (!scanline)
|
||||
{
|
||||
if (pPal)
|
||||
{
|
||||
Pic_free(pPal);
|
||||
}
|
||||
Pic_free(pDatas);
|
||||
Pic_SetError("TGA_Read, not enough memory for scanline");
|
||||
return(0);
|
||||
}
|
||||
for(y=0 ; y<h ; y++)
|
||||
{
|
||||
fread(scanline,1,slsize,file);
|
||||
if (d==24 || d==32)
|
||||
{
|
||||
long mult=3;
|
||||
if(d==32) mult=4;
|
||||
for(x=0 ; x<w ; x++)
|
||||
{
|
||||
r=scanline[x*mult+0];
|
||||
g=scanline[x*mult+1];
|
||||
b=scanline[x*mult+2];
|
||||
scanline[x*mult+0]=b;
|
||||
scanline[x*mult+1]=g;
|
||||
scanline[x*mult+2]=r;
|
||||
}
|
||||
}
|
||||
if (upSideDown)
|
||||
memcpy(&pDatas[(h-y-1)*slsize], scanline, slsize);
|
||||
else
|
||||
memcpy(&pDatas[(y)*slsize], scanline, slsize);
|
||||
}
|
||||
Pic_free(scanline);
|
||||
fclose(file);
|
||||
*ppDatas=pDatas;
|
||||
return(1);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
unsigned long Pic_TGA_Write( const char *FileName,
|
||||
unsigned char *pPal,unsigned char *pDatas,
|
||||
unsigned long w, unsigned long h, unsigned long d)
|
||||
{
|
||||
FILE *file;
|
||||
TGA_HEADER tgah;
|
||||
long x,y;
|
||||
long slsize;
|
||||
unsigned char *scanline;
|
||||
unsigned char r,g,b;
|
||||
|
||||
file=fopen(FileName,"wb");
|
||||
if (!file)
|
||||
{
|
||||
Pic_SetError("TGA_Write, unable to open %s",FileName);
|
||||
return(0);
|
||||
}
|
||||
memset(&tgah,0,sizeof(TGA_HEADER));
|
||||
tgah.LengthID=0;
|
||||
if (d>8)
|
||||
{
|
||||
tgah.CMapType=0;
|
||||
tgah.ImageType=2;
|
||||
tgah.Length=0;
|
||||
tgah.Depth=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tgah.CMapType=1;
|
||||
tgah.ImageType=1;
|
||||
tgah.Length=256;
|
||||
tgah.Depth=24;
|
||||
}
|
||||
tgah.Origin=0;
|
||||
tgah.XOrg=0;
|
||||
tgah.YOrg=0;
|
||||
tgah.Width=(unsigned short)w;
|
||||
tgah.Height=(unsigned short)h;
|
||||
tgah.ImageDepth=(unsigned char)d;
|
||||
tgah.Desc=0;
|
||||
fwrite(&tgah,1,sizeof(TGA_HEADER),file);
|
||||
if (d==8)
|
||||
{
|
||||
fwrite(pPal,1,256*3,file);
|
||||
}
|
||||
slsize=w*d/8;
|
||||
scanline=Pic_calloc(1,slsize);
|
||||
if (!scanline)
|
||||
{
|
||||
Pic_SetError("TGA_Write, not enough memory for scanline");
|
||||
return(0);
|
||||
}
|
||||
for(y=0 ; y<(long)h ; y++)
|
||||
{
|
||||
memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize);
|
||||
if (d==24)
|
||||
{
|
||||
for(x=0 ; x<(long)w ; x++)
|
||||
{
|
||||
r=scanline[x*3+0];
|
||||
g=scanline[x*3+1];
|
||||
b=scanline[x*3+2];
|
||||
scanline[x*3+0]=b;
|
||||
scanline[x*3+1]=g;
|
||||
scanline[x*3+2]=r;
|
||||
}
|
||||
}
|
||||
fwrite(scanline,1,slsize,file);
|
||||
}
|
||||
Pic_free(scanline);
|
||||
fclose(file);
|
||||
return(1);
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef _PIC_H_
|
||||
#define _PIC_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#define PIC_TYPE_JPG 1
|
||||
#define PIC_TYPE_TGA8 2
|
||||
#define PIC_TYPE_TGA16 3
|
||||
#define PIC_TYPE_TGA24 4
|
||||
#define PIC_TYPE_BMP8 5
|
||||
#define PIC_TYPE_BMP24 6
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* Basic API
|
||||
*/
|
||||
extern unsigned long PIC_Load(char* FileName, unsigned char Quantize);
|
||||
|
||||
extern unsigned long PIC_Create(unsigned char* pPal, unsigned char* pDatas, unsigned long w, unsigned long h, unsigned long d);
|
||||
|
||||
extern unsigned long PIC_Save(unsigned long id, const char* FileName, unsigned long type, unsigned long qual);
|
||||
|
||||
extern unsigned long PIC_GetInfos( unsigned long id,
|
||||
unsigned char* *ppPal, unsigned char* *ppDatas,
|
||||
unsigned long *pW, unsigned long *pH, unsigned long *pD);
|
||||
|
||||
|
||||
extern unsigned long PIC_Destroy(unsigned long id);
|
||||
/*
|
||||
* System
|
||||
*/
|
||||
extern unsigned long PIC_GetMemNbAllocs(void);
|
||||
extern unsigned long PIC_GetMemAllocated(void);
|
||||
extern char* PIC_GetError(void);
|
||||
extern unsigned char PIC_Error(void);
|
||||
extern void PIC_ResetError(void);
|
||||
extern unsigned char PIC_OnErrorCall( void pFnct(void) );
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,71 +0,0 @@
|
|||
#ifndef _PIC_PRIVATE_H_
|
||||
#define _PIC_PRIVATE_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct PIC_PICTURE
|
||||
{
|
||||
unsigned long ID;
|
||||
unsigned long Width;
|
||||
unsigned long Height;
|
||||
unsigned long Depth;
|
||||
unsigned char *pDatas;
|
||||
unsigned char *pPal;
|
||||
struct PIC_PICTURE *Next;
|
||||
} PIC_PICTURE;
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/*
|
||||
* JPG
|
||||
*/
|
||||
|
||||
|
||||
extern unsigned long Pic_JPG_Read( const char *FileName,
|
||||
unsigned char **ppPal, unsigned char **ppDatas,
|
||||
unsigned long *w, unsigned long *h);
|
||||
|
||||
extern unsigned long Pic_JPG_Write( const char *FileName,
|
||||
unsigned long Qual,
|
||||
unsigned char *pDatas,
|
||||
unsigned long w, unsigned long h);
|
||||
/*
|
||||
* TGA
|
||||
*/
|
||||
extern unsigned long Pic_TGA_Read( const char *FileName,
|
||||
unsigned char **ppPal, unsigned char **ppDatas,
|
||||
unsigned long *pWidth, unsigned long *pHeight,
|
||||
unsigned long *pDepth);
|
||||
extern unsigned long Pic_TGA_Write( const char *FileName,
|
||||
unsigned char *pPal,unsigned char *pDatas,
|
||||
unsigned long w, unsigned long h, unsigned long d);
|
||||
/*
|
||||
* BMP
|
||||
*/
|
||||
extern unsigned long Pic_BMP_Read( const char *FileName,
|
||||
unsigned char **ppPal, unsigned char **ppDatas,
|
||||
unsigned long *pWidth, unsigned long *pHeight,
|
||||
unsigned long *pDepth);
|
||||
|
||||
extern unsigned long Pic_BMP_Write( const char *FileName,
|
||||
unsigned char *pPal,unsigned char *pDatas,
|
||||
unsigned long w, unsigned long h, unsigned long d);
|
||||
/*
|
||||
* System
|
||||
*/
|
||||
extern void* Pic_malloc(size_t size);
|
||||
extern void* Pic_calloc(size_t count, size_t size);
|
||||
extern void Pic_free(void *memblock);
|
||||
extern size_t Pic__msize(void *memblock);
|
||||
extern void Pic_SetError(const char *msg, ...);
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,68 +0,0 @@
|
|||
|
||||
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include "readpic.h"
|
||||
#include "pic.h"
|
||||
#include <nel/misc/rgba.h>
|
||||
|
||||
|
||||
//============================================================
|
||||
// Image API.
|
||||
//============================================================
|
||||
|
||||
|
||||
bool PIC_LoadPic(const std::string &path, std::vector<NLMISC::CBGRA> &tampon, uint &Width, uint &Height)
|
||||
{
|
||||
uint32 id;
|
||||
unsigned char *pal, *data;
|
||||
unsigned long w,h,depth;
|
||||
uint i;
|
||||
|
||||
|
||||
// Loadons l'image.
|
||||
id= PIC_Load((char*)path.c_str(), 0);
|
||||
if(id==0)
|
||||
return false;
|
||||
PIC_GetInfos( id, &pal, &data, &w, &h, &depth);
|
||||
Width=w;
|
||||
Height=h;
|
||||
|
||||
// On traduit en RGBA.
|
||||
tampon.resize(w*h);
|
||||
switch(depth)
|
||||
{
|
||||
case 8:
|
||||
for(i=0;i<w*h;i++)
|
||||
{
|
||||
tampon[i].R= data[i];
|
||||
tampon[i].G= data[i];
|
||||
tampon[i].B= data[i];
|
||||
tampon[i].A= data[i];
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
for(i=0;i<w*h;i++)
|
||||
{
|
||||
tampon[i].R= data[i*3+ 0];
|
||||
tampon[i].G= data[i*3+ 1];
|
||||
tampon[i].B= data[i*3+ 2];
|
||||
tampon[i].A= 255;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
for(i=0;i<w*h;i++)
|
||||
{
|
||||
tampon[i].R= data[i*4+ 0];
|
||||
tampon[i].G= data[i*4+ 1];
|
||||
tampon[i].B= data[i*4+ 2];
|
||||
tampon[i].A= data[i*4+ 3];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// On ferme.
|
||||
PIC_Destroy(id);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
|
||||
#ifndef _READPIC_H_
|
||||
#define _READPIC_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include <nel/misc/rgba.h>
|
||||
|
||||
//============================================================
|
||||
// API.
|
||||
//============================================================
|
||||
|
||||
|
||||
bool PIC_LoadPic(const std::string &Path, std::vector<NLMISC::CBGRA> &tampon, uint &Width, uint &Height);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -14,18 +14,8 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtGui/QListWidgetItem>
|
||||
#include <QtGui/QColor>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtCore/QSettings>
|
||||
#include "nel/3d/tile_bank.h"
|
||||
#include "nel/misc/bitmap.h"
|
||||
#include "nel/misc/file.h"
|
||||
#include "pic/readpic.h"
|
||||
#include "pic/pic.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "tile_browser_dlg.h"
|
||||
#include "tile_rotation_dlg.h"
|
||||
|
||||
|
@ -220,7 +210,7 @@ void CTile_browser_dlg::on_actionAddTile_triggered(bool checked)
|
|||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Bitmap", QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Bitmap", QString(tileBankBrowser.getAbsPath().c_str()) , "All supported files (*.png;*.tga);;PNG Bitmap (*.png);;Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
|
||||
qSort(fileNames.begin(), fileNames.end());
|
||||
|
||||
|
@ -294,7 +284,7 @@ void CTile_browser_dlg::on_actionReplaceImage_triggered(bool checked)
|
|||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Choose Bitmap", QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Choose Bitmap", QString(tileBankBrowser.getAbsPath().c_str()) , "All supported files (*.png;*.tga);;PNG Bitmap (*.png);;Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
|
@ -406,7 +396,7 @@ void CTile_browser_dlg::on_batchLoadPushButton_clicked()
|
|||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , tr("Targa Bitmap (*.tga);;PNG Image (*.png);;All Files (*.*);;"), &selectedFilter, options);
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , tr("All supported files (*.png;*.tga);;PNG Bitmap (*.png);;Targa Bitmap (*.tga);;All Files (*.*);;"), &selectedFilter, options);
|
||||
QFileInfo fi(fileName);
|
||||
QString baseName = fi.baseName() ;
|
||||
|
||||
|
@ -507,7 +497,7 @@ void CTile_browser_dlg::on_exportBorderPushButton_clicked()
|
|||
// Select a file
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "All supported files (*.png;*.tga);;PNG Bitmap (*.png);;Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
|
@ -578,7 +568,7 @@ void CTile_browser_dlg::on_importBorderPushButton_clicked()
|
|||
{
|
||||
QFileDialog::Options options;
|
||||
QString selectedFilter;
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "All supported files (*.png;*.tga);;PNG Bitmap (*.png);;Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
|
||||
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
|
|
|
@ -17,14 +17,10 @@
|
|||
#ifndef TILE_BROWSERDLG_H
|
||||
#define TILE_BROWSERDLG_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QButtonGroup>
|
||||
#include "ui_tile_browser_qt.h"
|
||||
#include "tiles_model.h"
|
||||
#include "browser_model.h"
|
||||
|
||||
|
||||
class CTile_browser_dlg : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -14,14 +14,7 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtGui/QListWidgetItem>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtCore/QDir>
|
||||
#include <string>
|
||||
#include <nel/3d/tile_bank.h>
|
||||
#include <nel/misc/stream.h>
|
||||
#include <nel/misc/file.h>
|
||||
#include "common.h"
|
||||
#include "tile_edit_dlg.h"
|
||||
#include "items_edit_dlg.h"
|
||||
#include "tile_browser_dlg.h"
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#ifndef TILE_EDITDLG_H
|
||||
#define TILE_EDITDLG_H
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include "ui_tile_edit_qt.h"
|
||||
|
||||
class QCheckBox;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "common.h"
|
||||
#include "tile_listwidgetitem.h"
|
||||
|
||||
//tile_listwidgetitem::tile_listwidgetitem(void)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "common.h"
|
||||
#include "tile_rotation_dlg.h"
|
||||
|
||||
CTile_rotation_dlg::CTile_rotation_dlg(QWidget *parent, Qt::WindowFlags flags)
|
||||
|
|
|
@ -17,10 +17,6 @@
|
|||
#ifndef TILE_ROTATIONDLG_H
|
||||
#define TILE_ROTATIONDLG_H
|
||||
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/QButtonGroup>
|
||||
#include "ui_tile_rotation_qt.h"
|
||||
|
||||
class CTile_rotation_dlg : public QDialog
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "common.h"
|
||||
#include <QtGui/QtGui>
|
||||
#include "tile_widget.h"
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef TILE_WIDGET_H
|
||||
#define TILE_WIDGET_H
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include "tiles_model.h"
|
||||
#include "ui_tile_widget_qt.h"
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "common.h"
|
||||
#include <QtGui/QtGui>
|
||||
#include "tiles_model.h"
|
||||
#include "tile_widget.h"
|
||||
|
@ -57,10 +58,9 @@ QVariant tiles_model::data(const QModelIndex &index, int role) const
|
|||
|
||||
if (role == Qt::DecorationRole || role == Qt::UserRole)
|
||||
{
|
||||
CTile_Widget* wiwi = new CTile_Widget;
|
||||
wiwi->initWidget( tiles.value(index.row()).getPixmap(), tiles.value(index.row()).getPixmapSide(), tiles.value(index.row()).getTileLabel() );
|
||||
QPixmap pixpix = QPixmap::grabWidget(wiwi, wiwi->contentsRect());
|
||||
delete wiwi;
|
||||
CTile_Widget wiwi;
|
||||
wiwi.initWidget(tiles.value(index.row()).getPixmap(), tiles.value(index.row()).getPixmapSide(), tiles.value(index.row()).getTileLabel());
|
||||
QPixmap pixpix = wiwi.grab(wiwi.contentsRect());
|
||||
return pixpix;
|
||||
}
|
||||
else if (role == Qt::UserRole + 1)
|
||||
|
|
|
@ -1,15 +1,6 @@
|
|||
#ifndef TILESMODEL_H
|
||||
#define TILESMODEL_H
|
||||
|
||||
#include <QtCore/QAbstractListModel>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtCore/QPoint>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QStackedWidget>
|
||||
#include <QtGui/QLabel>
|
||||
|
||||
class TileModel
|
||||
{
|
||||
|
||||
|
|
|
@ -1803,8 +1803,8 @@ void CClientConfig::setValues()
|
|||
|
||||
READ_BOOL_DEV(DamageShieldEnabled)
|
||||
|
||||
READ_BOOL_DEV(AllowDebugLua)
|
||||
READ_BOOL_DEV(DisplayLuaDebugInfo)
|
||||
READ_BOOL_FV(AllowDebugLua)
|
||||
READ_BOOL_FV(DisplayLuaDebugInfo)
|
||||
|
||||
READ_BOOL_DEV(LuaDebugInfoGotoButtonEnabled)
|
||||
READ_STRING_DEV(LuaDebugInfoGotoButtonTemplate)
|
||||
|
|
|
@ -1511,6 +1511,10 @@ bool CClientEditionModule::loadUserComponent(const std::string& filename, bool m
|
|||
nlwarning("Error while reading %s", filename.c_str());
|
||||
}
|
||||
|
||||
#ifdef NL_BIG_ENDIAN
|
||||
NLMISC_BSWAP32(uncompressedFileLength);
|
||||
#endif
|
||||
|
||||
fclose(file);
|
||||
|
||||
// Test if data are not too big
|
||||
|
|
|
@ -90,15 +90,15 @@ using namespace NLNET;
|
|||
|
||||
|
||||
|
||||
// Automatic SaveShardRoot path standardization
|
||||
// Automatic SaveShardRootGameShare path standardization
|
||||
void cbOnSaveShardRootModified( NLMISC::IVariable& var )
|
||||
{
|
||||
var.fromString( CPath::standardizePath( var.toString() ) );
|
||||
}
|
||||
|
||||
|
||||
// (SaveShardRoot from game_share/backup_service_interface.cpp is not instanciated because nothing is used from that file)
|
||||
extern NLMISC::CVariable<std::string> SaveShardRoot;
|
||||
// (SaveShardRootGameShare from game_share/backup_service_interface.cpp is not instanciated because nothing is used from that file)
|
||||
extern NLMISC::CVariable<std::string> SaveShardRootGameShare;
|
||||
CVariable<string> PdrFilename("ai", "PdrFilename", "Pdr file containing AIScript variables", string("ai_persistent_var.pdr"), 0, true);
|
||||
|
||||
|
||||
|
@ -174,7 +174,7 @@ CAIScriptDataManager::~CAIScriptDataManager()
|
|||
|
||||
std::string CAIScriptDataManager::dirname()
|
||||
{
|
||||
return SaveShardRoot.get()+"/"+IService::getInstance()->SaveFilesDirectory.toString()+"/ai_script_data";
|
||||
return SaveShardRootGameShare.get()+"/"+IService::getInstance()->SaveFilesDirectory.toString()+"/ai_script_data";
|
||||
}
|
||||
|
||||
//CConfigFile* CAIScriptDataManager::createFile(string name)
|
||||
|
|
|
@ -584,19 +584,17 @@ public:
|
|||
std::string op1;
|
||||
if (cond.Property == "name")
|
||||
{
|
||||
op1 = si.SheetName;
|
||||
op1 = NLMISC::toLower(si.SheetName);
|
||||
}
|
||||
else if (cond.Property == "gender")
|
||||
{
|
||||
op1 = si.Gender;
|
||||
op1 = NLMISC::toLower(GSGENDER::toString(si.Gender));
|
||||
}
|
||||
else
|
||||
{
|
||||
return CParameterTraitsEntity::eval(lang,charInfo, cond);
|
||||
}
|
||||
|
||||
NLMISC::strlwr(op1);
|
||||
|
||||
LOG("SM : (creature) eval condition for property %s [%s] %s [%s]", cond.Property.c_str(), op1.c_str(), OperatorNames[cond.Operator], cond.ReferenceStr.c_str());
|
||||
|
||||
switch(cond.Operator)
|
||||
|
@ -987,7 +985,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
const CStringManager::TSheetInfo &si = SM->getSheetInfo(sheetId);
|
||||
op1 = si.SheetName;
|
||||
op1 = NLMISC::toLower(si.SheetName);
|
||||
}
|
||||
else if (cond.Property == "gender")
|
||||
{
|
||||
|
@ -997,15 +995,13 @@ public:
|
|||
nlwarning("Could not find character info for EId %s to check property %s", EId.toString().c_str(), cond.Property.c_str());
|
||||
return false;
|
||||
}
|
||||
op1 = GSGENDER::toString(charInfo->getGender());
|
||||
op1 = NLMISC::toLower(GSGENDER::toString(charInfo->getGender()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return CParameterTraitsEntity::eval(lang,charInfo, cond);
|
||||
}
|
||||
|
||||
NLMISC::strlwr(op1);
|
||||
|
||||
LOG("SM : (player) eval condition for property %s [%s] %s [%s]", cond.Property.c_str(), op1.c_str(), OperatorNames[cond.Operator], cond.ReferenceStr.c_str());
|
||||
|
||||
switch(cond.Operator)
|
||||
|
@ -1085,14 +1081,14 @@ public:
|
|||
}
|
||||
else if (cond.Property == "role")
|
||||
{
|
||||
op1 = si.ChatProfile;
|
||||
op1 = NLMISC::toLower(si.ChatProfile);
|
||||
}
|
||||
else if (cond.Property == "title")
|
||||
{
|
||||
// we need to retrieve the charInfo
|
||||
CCharacterInfos *ci = IOS->getCharInfos(EId);
|
||||
if (ci != NULL)
|
||||
op1 = ci->Title;
|
||||
op1 = NLMISC::toLower(ci->Title);
|
||||
else
|
||||
{
|
||||
nlwarning("No character info for bot %s, can't test property 'title' !", EId.toString().c_str());
|
||||
|
@ -1104,8 +1100,6 @@ public:
|
|||
return CParameterTraitsEntity::eval(lang, charInfo, cond);
|
||||
}
|
||||
|
||||
NLMISC::strlwr(op1);
|
||||
|
||||
LOG("SM : (bot) eval condition for property %s [%s] %s [%s]", cond.Property.c_str(), op1.c_str(), OperatorNames[cond.Operator], cond.ReferenceStr.c_str());
|
||||
|
||||
switch(cond.Operator)
|
||||
|
@ -1460,18 +1454,17 @@ public:
|
|||
// check if checked property is gender or name
|
||||
if (cond.Property == "gender")
|
||||
{
|
||||
value = GSGENDER::toString(charInfo->getGender());
|
||||
value = NLMISC::toLower(GSGENDER::toString(charInfo->getGender()));
|
||||
}
|
||||
else if (cond.Property == "name")
|
||||
{
|
||||
value = charInfo->ShortName.toString();
|
||||
value = NLMISC::toLower(charInfo->ShortName.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return CParameterTraitsEntity::eval(lang,charInfo, cond);
|
||||
}
|
||||
|
||||
NLMISC::strlwr(value);
|
||||
LOG("SM : (self) eval condition for property %s [%s] %s [%s]", cond.Property.c_str(), value.c_str(), OperatorNames[cond.Operator], cond.ReferenceStr.c_str());
|
||||
|
||||
switch(cond.Operator)
|
||||
|
|
Loading…
Reference in a new issue