mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
Merge with develop
This commit is contained in:
parent
7a44693ec2
commit
83f8502b51
14 changed files with 644 additions and 160 deletions
|
@ -348,6 +348,27 @@ public:
|
|||
*/
|
||||
void makeNonPowerOf2Dummy();
|
||||
|
||||
|
||||
/**
|
||||
* Make a bitmap fully opaque (set alpha to 255).
|
||||
*/
|
||||
void makeOpaque();
|
||||
|
||||
|
||||
/**
|
||||
* Return if the bitmap has uniform alpha values for all pixels.
|
||||
* \param alpha return the uniform value if return is true
|
||||
* \return uniform or not
|
||||
*/
|
||||
bool isAlphaUniform(uint8 *alpha = NULL) const;
|
||||
|
||||
|
||||
/**
|
||||
* Return if the bitmap is a real grayscale.
|
||||
* \return grayscale or not
|
||||
*/
|
||||
bool isGrayscale() const;
|
||||
|
||||
/**
|
||||
* Return the pixels buffer of the image, or of one of its mipmap.
|
||||
* Return a reference of an array in pixel format get with getPixelFormat().
|
||||
|
|
|
@ -146,6 +146,14 @@ public:
|
|||
*/
|
||||
uint8 toGray() const;
|
||||
|
||||
/**
|
||||
* Color is gray
|
||||
*/
|
||||
bool isGray() const
|
||||
{
|
||||
return R == G && G == B;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a 16 bits 565 pixel.
|
||||
*/
|
||||
|
@ -169,6 +177,17 @@ public:
|
|||
B= (B<<3) + (B>>2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the RGBA fields with a 32 bits 8888 pixel.
|
||||
*/
|
||||
void set8888(uint32 col)
|
||||
{
|
||||
R = col & 255;
|
||||
G = (col >> 8) & 255;
|
||||
B = (col >> 16) & 255;
|
||||
A = (col >> 24) & 255;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute in this the average of 2 RGBA.
|
||||
|
|
|
@ -65,9 +65,9 @@ const uint32 CBitmap::bitPerPixels[ModeCount]=
|
|||
16 // DsDt
|
||||
};
|
||||
|
||||
const uint32 CBitmap::DXTC1HEADER = NL_MAKEFOURCC('D','X', 'T', '1');
|
||||
const uint32 CBitmap::DXTC3HEADER = NL_MAKEFOURCC('D','X', 'T', '3');
|
||||
const uint32 CBitmap::DXTC5HEADER = NL_MAKEFOURCC('D','X', 'T', '5');
|
||||
const uint32 CBitmap::DXTC1HEADER = NL_MAKEFOURCC('D', 'X', 'T', '1');
|
||||
const uint32 CBitmap::DXTC3HEADER = NL_MAKEFOURCC('D', 'X', 'T', '3');
|
||||
const uint32 CBitmap::DXTC5HEADER = NL_MAKEFOURCC('D', 'X', 'T', '5');
|
||||
|
||||
|
||||
#ifdef NEL_ALL_BITMAP_WHITE
|
||||
|
@ -309,6 +309,155 @@ void CBitmap::makeDummyFromBitField(const uint8 bitmap[1024])
|
|||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------*\
|
||||
makeOpaque
|
||||
\*-------------------------------------------------------------------*/
|
||||
void CBitmap::makeOpaque()
|
||||
{
|
||||
if (_Width*_Height == 0) return;
|
||||
|
||||
uint pixelSize;
|
||||
|
||||
switch(PixelFormat)
|
||||
{
|
||||
case RGBA: pixelSize = 4; break;
|
||||
case AlphaLuminance: pixelSize = 2; break;
|
||||
case Alpha: pixelSize = 1; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
for(uint8 m = 0; m < _MipMapCount; ++m)
|
||||
{
|
||||
// get a pointer on original data
|
||||
uint8 *data = _Data[m].getPtr();
|
||||
|
||||
// special case for only alpha values
|
||||
if (pixelSize == 1)
|
||||
{
|
||||
memset(data, 255, _Data[m].size());
|
||||
}
|
||||
else
|
||||
{
|
||||
// end of data
|
||||
uint8 *endData = data + _Data[m].size();
|
||||
|
||||
// first alpha
|
||||
data += pixelSize - 1;
|
||||
|
||||
// replace all alpha values by 255
|
||||
while(data < endData)
|
||||
{
|
||||
*data = 255;
|
||||
data += pixelSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------*\
|
||||
isAlphaUniform
|
||||
\*-------------------------------------------------------------------*/
|
||||
bool CBitmap::isAlphaUniform(uint8 *alpha) const
|
||||
{
|
||||
uint32 size = _Data[0].size();
|
||||
|
||||
if (size == 0) return false;
|
||||
|
||||
uint pixelSize;
|
||||
|
||||
switch(PixelFormat)
|
||||
{
|
||||
// formats with alpha channel
|
||||
case RGBA:
|
||||
pixelSize = 4;
|
||||
break;
|
||||
|
||||
case AlphaLuminance:
|
||||
pixelSize = 2;
|
||||
break;
|
||||
|
||||
case Alpha:
|
||||
pixelSize = 1;
|
||||
break;
|
||||
|
||||
// formats without alpha channel
|
||||
case Luminance:
|
||||
if (alpha) *alpha = 255;
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// get a pointer on original data
|
||||
uint8 *data = (uint8*)_Data[0].getPtr();
|
||||
uint8 *endData = data + size;
|
||||
|
||||
// first alpha
|
||||
data += pixelSize - 1;
|
||||
|
||||
// first alpha value
|
||||
uint8 value = *data;
|
||||
|
||||
// check if all alphas have the same value
|
||||
while(data < endData && *data == value) data += pixelSize;
|
||||
|
||||
// texture can be converted if all alphas are 0 or 255
|
||||
if (data >= endData)
|
||||
{
|
||||
// return the uniform value
|
||||
if (alpha) *alpha = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------*\
|
||||
isGrayscale
|
||||
\*-------------------------------------------------------------------*/
|
||||
bool CBitmap::isGrayscale() const
|
||||
{
|
||||
// all grayscale formats or, al least, without color information
|
||||
switch(PixelFormat)
|
||||
{
|
||||
case Luminance:
|
||||
case AlphaLuminance:
|
||||
case Alpha:
|
||||
return true;
|
||||
|
||||
case RGBA:
|
||||
break;
|
||||
|
||||
default:
|
||||
// DXTC formats won't be managed at the moment
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 size = _Data[0].size();
|
||||
if (size == 0) return false;
|
||||
|
||||
// get a pointer on original data
|
||||
uint32 *data = (uint32*)_Data[0].getPtr();
|
||||
uint32 *endData = (uint32*)((uint8*)data + size);
|
||||
|
||||
NLMISC::CRGBA color;
|
||||
|
||||
// check if all alphas have the same value
|
||||
while(data < endData)
|
||||
{
|
||||
color.set8888(*data);
|
||||
|
||||
if (!color.isGray()) return false;
|
||||
|
||||
++data;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -601,78 +601,157 @@ sint CSystemUtils::getTotalVideoMemory()
|
|||
#elif defined(NL_OS_MAC)
|
||||
// the right method is using OpenGL
|
||||
#else
|
||||
// under Linux, no method is really reliable...
|
||||
NLMISC::CIFile file;
|
||||
|
||||
std::string logFile = "/var/log/Xorg.0.log";
|
||||
|
||||
// parse last Xorg.0.log
|
||||
if (file.open(logFile, true))
|
||||
if (res == -1)
|
||||
{
|
||||
char buffer[256];
|
||||
// use nvidia-smi
|
||||
std::string command = "nvidia-smi -q -d MEMORY";
|
||||
|
||||
while(!file.eof())
|
||||
std::string out = getCommandOutput(command);
|
||||
|
||||
if (out.empty())
|
||||
{
|
||||
file.getline(buffer, 256);
|
||||
|
||||
if (buffer[0] == '\0') break;
|
||||
|
||||
std::string line(buffer);
|
||||
|
||||
// nvidia driver
|
||||
std::string::size_type pos = line.find(") NVIDIA(");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
// [ 20.883] (--) NVIDIA(0): Memory: 2097152 kBytes
|
||||
pos = line.find("Memory: ", pos);
|
||||
|
||||
// found memory line
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 8;
|
||||
|
||||
std::string::size_type posUnits = line.find(" kBytes", pos);
|
||||
|
||||
// found units in KiB
|
||||
if (posUnits == std::string::npos) continue;
|
||||
|
||||
std::string videoMemory = line.substr(pos, posUnits-pos);
|
||||
|
||||
if (!NLMISC::fromString(videoMemory, res)) continue;
|
||||
|
||||
nlinfo("Xorg NVIDIA driver reported %d KiB of video memory", res);
|
||||
break;
|
||||
}
|
||||
|
||||
// intel driver
|
||||
pos = line.find(") intel(");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
// (**) intel(0): VideoRam: 131072 KB
|
||||
pos = line.find("VideoRam: ", pos);
|
||||
|
||||
// found memory line
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 10;
|
||||
|
||||
std::string::size_type posUnits = line.find(" KB", pos);
|
||||
|
||||
// found units in KiB
|
||||
if (posUnits == std::string::npos) continue;
|
||||
|
||||
std::string videoMemory = line.substr(pos, posUnits-pos);
|
||||
|
||||
if (!NLMISC::fromString(videoMemory, res)) continue;
|
||||
|
||||
nlinfo("Xorg Intel driver reported %d KiB of video memory", res);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: other drivers: nv, fglrx (ATI), radeon (ATI)
|
||||
nlwarning("Unable to launch %s", command.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> lines;
|
||||
explode(out, std::string("\n"), lines, true);
|
||||
|
||||
// process each line
|
||||
for(uint i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
// Total : 62 MB
|
||||
|
||||
file.close();
|
||||
std::string line = lines[i];
|
||||
|
||||
// find Total line
|
||||
std::string::size_type pos = line.find("Total");
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 6;
|
||||
|
||||
// find separator
|
||||
pos = line.find(':', pos);
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 2;
|
||||
|
||||
// find units
|
||||
std::string::size_type posUnits = line.find(' ', pos);
|
||||
if (posUnits == std::string::npos) continue;
|
||||
++posUnits;
|
||||
|
||||
// found device ID
|
||||
std::string memory = line.substr(pos, posUnits-pos-1);
|
||||
std::string units = line.substr(posUnits);
|
||||
|
||||
// convert video memory to sint
|
||||
if (NLMISC::fromString(memory, res))
|
||||
{
|
||||
if (units == "MB")
|
||||
{
|
||||
res *= 1024;
|
||||
}
|
||||
else if (units == "GB")
|
||||
{
|
||||
res *= 1024 * 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset to use other methods
|
||||
res = -1;
|
||||
|
||||
nlwarning("nvidia-smi reported %d %s as wrong video memory units", res, units.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
nlinfo("nvidia-smi reported %d KiB of video memory", res);
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset to use other methods
|
||||
res = -1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (res == -1)
|
||||
{
|
||||
// under Linux, no method is really reliable...
|
||||
NLMISC::CIFile file;
|
||||
|
||||
std::string logFile = "/var/log/Xorg.0.log";
|
||||
|
||||
// parse last Xorg.0.log
|
||||
if (file.open(logFile, true))
|
||||
{
|
||||
char buffer[256];
|
||||
|
||||
while(!file.eof())
|
||||
{
|
||||
file.getline(buffer, 256);
|
||||
|
||||
if (buffer[0] == '\0') break;
|
||||
|
||||
std::string line(buffer);
|
||||
|
||||
// nvidia driver
|
||||
std::string::size_type pos = line.find(") NVIDIA(");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
// [ 20.883] (--) NVIDIA(0): Memory: 2097152 kBytes
|
||||
// [ 28.515] (--) NVIDIA(0): Memory: 262144 kBytes
|
||||
pos = line.find("Memory: ", pos);
|
||||
|
||||
// found memory line
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 8;
|
||||
|
||||
std::string::size_type posUnits = line.find(" kBytes", pos);
|
||||
|
||||
// found units in KiB
|
||||
if (posUnits == std::string::npos) continue;
|
||||
|
||||
std::string videoMemory = line.substr(pos, posUnits-pos);
|
||||
|
||||
if (!NLMISC::fromString(videoMemory, res)) continue;
|
||||
|
||||
nlinfo("Xorg NVIDIA driver reported %d KiB of video memory", res);
|
||||
break;
|
||||
}
|
||||
|
||||
// intel driver
|
||||
pos = line.find(") intel(");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
// (**) intel(0): VideoRam: 131072 KB
|
||||
pos = line.find("VideoRam: ", pos);
|
||||
|
||||
// found memory line
|
||||
if (pos == std::string::npos) continue;
|
||||
pos += 10;
|
||||
|
||||
std::string::size_type posUnits = line.find(" KB", pos);
|
||||
|
||||
// found units in KiB
|
||||
if (posUnits == std::string::npos) continue;
|
||||
|
||||
std::string videoMemory = line.substr(pos, posUnits-pos);
|
||||
|
||||
if (!NLMISC::fromString(videoMemory, res)) continue;
|
||||
|
||||
nlinfo("Xorg Intel driver reported %d KiB of video memory", res);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: other drivers: fglrx (ATI), radeon (ATI)
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (res == -1)
|
||||
|
|
|
@ -35,6 +35,7 @@ IF(WITH_NEL_TOOLS)
|
|||
SUBDIRS(
|
||||
build_interface
|
||||
get_neighbors
|
||||
textures_optimizer
|
||||
tga_cut
|
||||
tga_resize)
|
||||
ENDIF()
|
||||
|
@ -54,22 +55,22 @@ ENDIF()
|
|||
|
||||
IF(WITH_NEL_TOOLS AND WITH_3D)
|
||||
IF(WIN32)
|
||||
# ADD_SUBDIRECTORY(lightmap_optimizer)
|
||||
# ADD_SUBDIRECTORY(lightmap_optimizer)
|
||||
IF(MFC_FOUND)
|
||||
ADD_SUBDIRECTORY(object_viewer_exe)
|
||||
ADD_SUBDIRECTORY(tile_edit)
|
||||
ENDIF(MFC_FOUND)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
IF(WITH_QT)
|
||||
ADD_SUBDIRECTORY(tile_edit_qt)
|
||||
ADD_SUBDIRECTORY(object_viewer_widget)
|
||||
ENDIF(WITH_QT)
|
||||
|
||||
|
||||
IF(WITH_NEL_TOOLS)
|
||||
FIND_PACKAGE(Squish)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF(SQUISH_FOUND)
|
||||
ADD_SUBDIRECTORY(s3tc_compressor_lib)
|
||||
ADD_SUBDIRECTORY(panoply_maker)
|
||||
|
|
|
@ -669,69 +669,50 @@ static void BuildColoredVersionForOneBitmap(const CBuildInfo &bi, const std::str
|
|||
// we can save it as RGB to optimize it
|
||||
if (bi.OptimizeTextures > 0 && depth == 32)
|
||||
{
|
||||
uint32 size = srcBitmap.getPixels().size();
|
||||
uint8 value = 0;
|
||||
|
||||
if (size > 0)
|
||||
// texture can be converted if all alphas are 0 or 255
|
||||
if (srcBitmap.isAlphaUniform(&value) && (value == 255 || value == 0))
|
||||
{
|
||||
// get a pointer on original data
|
||||
uint8 *data = srcBitmap.getPixels().getPtr();
|
||||
|
||||
// pointer on first alpha value
|
||||
uint8 *tmp = data + 3;
|
||||
uint8 *endData = data + size;
|
||||
uint8 value = *tmp;
|
||||
|
||||
// check if all alphas have the same value
|
||||
while(tmp < endData && *tmp == value) tmp += 4;
|
||||
|
||||
// texture can be converted if all alphas are 0 or 255
|
||||
if (tmp >= endData && (value == 255 || value == 0))
|
||||
if (bi.OptimizeTextures > 1)
|
||||
{
|
||||
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))
|
||||
{
|
||||
// original depth is now 24 bits, since we discarded alpha channel
|
||||
depth = 24;
|
||||
nlwarning("Optimizing texture %s...", fullInputBitmapPath.c_str());
|
||||
|
||||
// if texture is fully transparent, make it fully opaque
|
||||
if (value == 0)
|
||||
std::string ext = CFile::getExtension(fullInputBitmapPath);
|
||||
|
||||
// resave the texture in optimized same format
|
||||
if (ext == "png")
|
||||
{
|
||||
tmp = data + 3;
|
||||
|
||||
while(tmp < endData)
|
||||
{
|
||||
*tmp = 255;
|
||||
tmp += 4;
|
||||
}
|
||||
srcBitmap.writePNG(os, 24);
|
||||
}
|
||||
|
||||
NLMISC::COFile os;
|
||||
|
||||
if (os.open(fullInputBitmapPath))
|
||||
else if (ext == "tga")
|
||||
{
|
||||
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());
|
||||
}
|
||||
srcBitmap.writeTGA(os, 24);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Don't support %s format for texture, unable to save it", ext.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Texture %s can be optimized", fullInputBitmapPath.c_str());
|
||||
nlwarning("Unable to save texture %s", fullInputBitmapPath.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Texture %s can be optimized", fullInputBitmapPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
code/nel/tools/3d/textures_optimizer/CMakeLists.txt
Normal file
9
code/nel/tools/3d/textures_optimizer/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
FILE(GLOB SRC *.cpp *.h)
|
||||
|
||||
ADD_EXECUTABLE(textures_optimizer ${SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(textures_optimizer nelmisc)
|
||||
NL_DEFAULT_PROPS(textures_optimizer "NeL, Tools, 3D: Textures optimizer")
|
||||
NL_ADD_RUNTIME_FLAGS(textures_optimizer)
|
||||
|
||||
INSTALL(TARGETS textures_optimizer RUNTIME DESTINATION ${NL_BIN_PREFIX} COMPONENT tools3d)
|
233
code/nel/tools/3d/textures_optimizer/main.cpp
Normal file
233
code/nel/tools/3d/textures_optimizer/main.cpp
Normal file
|
@ -0,0 +1,233 @@
|
|||
// 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 "nel/misc/file.h"
|
||||
#include "nel/misc/bitmap.h"
|
||||
#include "nel/misc/path.h"
|
||||
#include "nel/misc/debug.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void writeInstructions()
|
||||
{
|
||||
std::cout << "Syntax: textures_optimizer [-a] [-g] <input>" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " Try to optimize TGA or PNG textures by removing useless alpha channel or converting a RGB with black and white values to grayscale" << std::endl;
|
||||
std::cout << " By default, it only make checks and display if texture can optimized or not" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "with" << std::endl;
|
||||
std::cout << "-a : Remove alpha channel if useless" << std::endl;
|
||||
std::cout << "-g : Convert to grayscale if all pixels are gray" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "-h or -? for this help" << std::endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
bool FixAlpha = false;
|
||||
bool FixGrayscale = false;
|
||||
|
||||
std::vector<std::string> InputFilenames;
|
||||
|
||||
bool parseOptions(int argc, char **argv)
|
||||
{
|
||||
// process each argument
|
||||
for(sint i = 1; i < argc; ++i)
|
||||
{
|
||||
std::string option = argv[i];
|
||||
|
||||
if (option.length() > 0)
|
||||
{
|
||||
bool isOption = option[0] == '-';
|
||||
|
||||
#ifdef NL_OS_WINDOWS
|
||||
// authorize / for options only under Windows,
|
||||
// because under Linux it could be a full path
|
||||
if (!isOption) isOption = (option[0] == '/');
|
||||
#endif
|
||||
|
||||
// Option
|
||||
if (isOption)
|
||||
{
|
||||
// remove option prefix
|
||||
option = option.substr(1);
|
||||
|
||||
// Fix alpha
|
||||
if (option == "a")
|
||||
{
|
||||
FixAlpha = true;
|
||||
}
|
||||
// Fix grayscale
|
||||
else if (option == "g")
|
||||
{
|
||||
FixGrayscale = true;
|
||||
}
|
||||
else if (option == "h" || option == "?")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Unknown option -%s", option.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Filename
|
||||
else
|
||||
{
|
||||
std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(option));
|
||||
|
||||
if (ext == "png" || ext == "tga")
|
||||
{
|
||||
InputFilenames.push_back(option);
|
||||
}
|
||||
else
|
||||
{
|
||||
nlwarning("Only PNG and TGA files supported, %s won't be processed", option.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !InputFilenames.empty();
|
||||
}
|
||||
|
||||
#include "nel/misc/system_utils.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NLMISC::CApplicationContext applicationContext;
|
||||
|
||||
if (!parseOptions(argc, argv))
|
||||
{
|
||||
writeInstructions();
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(uint i = 0; i < InputFilenames.size(); ++i)
|
||||
{
|
||||
std::string ext = NLMISC::toLower(NLMISC::CFile::getExtension(InputFilenames[i]));
|
||||
|
||||
NLMISC::CIFile input;
|
||||
|
||||
if (!input.open(InputFilenames[i]))
|
||||
{
|
||||
std::cerr << "Unable to open " << InputFilenames[i] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
NLMISC::CBitmap bitmap;
|
||||
|
||||
uint8 depth = bitmap.load(input);
|
||||
|
||||
// don't need file so close it
|
||||
input.close();
|
||||
|
||||
if (depth == 0)
|
||||
{
|
||||
std::cerr << "Unable to decode " << InputFilenames[i] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool modified = false;
|
||||
bool hasAlpha = false;
|
||||
bool isGrayscale = false;
|
||||
|
||||
if (bitmap.getPixelFormat() == NLMISC::CBitmap::RGBA && depth == 32)
|
||||
{
|
||||
hasAlpha = true;
|
||||
}
|
||||
else if (bitmap.getPixelFormat() == NLMISC::CBitmap::AlphaLuminance)
|
||||
{
|
||||
hasAlpha = true;
|
||||
isGrayscale = true;
|
||||
}
|
||||
else if (bitmap.getPixelFormat() == NLMISC::CBitmap::Luminance)
|
||||
{
|
||||
isGrayscale = true;
|
||||
}
|
||||
else if (bitmap.getPixelFormat() == NLMISC::CBitmap::Alpha)
|
||||
{
|
||||
hasAlpha = true;
|
||||
isGrayscale = true;
|
||||
}
|
||||
|
||||
if (!isGrayscale && bitmap.isGrayscale())
|
||||
{
|
||||
std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl;
|
||||
|
||||
if (FixGrayscale)
|
||||
{
|
||||
if (!bitmap.convertToType(hasAlpha ? NLMISC::CBitmap::AlphaLuminance:NLMISC::CBitmap::Luminance))
|
||||
{
|
||||
std::cerr << "Unable to convert to Luminance" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
isGrayscale = true;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
uint8 alpha = 0;
|
||||
|
||||
if (hasAlpha && bitmap.isAlphaUniform(&alpha))
|
||||
{
|
||||
std::cout << InputFilenames[i] << " (image with uniform alpha channel " << alpha << ")" << std::endl;
|
||||
|
||||
if (FixAlpha && (alpha == 0 || alpha == 255))
|
||||
{
|
||||
bitmap.makeOpaque();
|
||||
|
||||
hasAlpha = false;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!modified) continue;
|
||||
|
||||
NLMISC::COFile output;
|
||||
|
||||
if (!output.open(InputFilenames[i]))
|
||||
{
|
||||
std::cerr << "Unable to open" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32 newDepth = isGrayscale ? 8:24;
|
||||
|
||||
if (hasAlpha) newDepth += 8;
|
||||
|
||||
bool res = false;
|
||||
|
||||
if (ext == "png")
|
||||
{
|
||||
res = bitmap.writePNG(output, newDepth);
|
||||
}
|
||||
else if (ext == "tga")
|
||||
{
|
||||
res = bitmap.writePNG(output, newDepth);
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
std::cerr << "Unable to encode" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -843,7 +843,7 @@ void CPatchManager::createBatchFile(CProductDescriptionForClient &descFile, bool
|
|||
for (uint32 fff = 0; fff < vFilenames.size (); fff++)
|
||||
{
|
||||
string SrcPath = ClientPatchPath;
|
||||
string DstPath = rCat.getUnpackTo();
|
||||
string DstPath = CPath::standardizePath(rCat.getUnpackTo()); // to be sure there is a / at the end
|
||||
NLMISC::CFile::createDirectoryTree(DstPath);
|
||||
|
||||
// this file must be moved
|
||||
|
@ -2400,19 +2400,6 @@ void CCheckThread::run ()
|
|||
fromString(sServerVersion, nServerVersion);
|
||||
fromString(sClientVersion, nClientVersion);
|
||||
|
||||
#ifdef NL_OS_UNIX
|
||||
string sClientNewVersion = ClientCfg.BuildName;
|
||||
|
||||
sint32 nClientNewVersion;
|
||||
fromString(sClientNewVersion, nClientNewVersion);
|
||||
|
||||
// servers files are not compatible with current client, use last client version
|
||||
if (nClientNewVersion && nServerVersion > nClientNewVersion)
|
||||
{
|
||||
nServerVersion = nClientNewVersion;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nClientVersion != nServerVersion)
|
||||
{
|
||||
// first, try in the version subdirectory
|
||||
|
|
|
@ -47,7 +47,7 @@ NL_INSTANCE_COUNTER_IMPL(CGuildMemberModule);
|
|||
CGuildMemberModule * CGuildMemberModule::createModule( CGuildCharProxy& proxy, CGuildMember* guildMember )
|
||||
{
|
||||
nlassert( guildMember );
|
||||
switch( guildMember->getGrade() )
|
||||
switch( guildMember->getGrade() )
|
||||
{
|
||||
case EGSPD::CGuildGrade::Member:
|
||||
return new CGuildMemberModule(proxy,guildMember);
|
||||
|
@ -103,7 +103,7 @@ void CGuildMemberModule::quitGuild()
|
|||
EGS_PD_AST( guild );
|
||||
SM_STATIC_PARAMS_1( params,STRING_MANAGER::player );
|
||||
params[0].setEIdAIAlias( _GuildMemberCore->getIngameEId(), CAIAliasTranslator::getInstance()->getAIAlias(_GuildMemberCore->getIngameEId()) );
|
||||
|
||||
|
||||
CFameManager::getInstance().clearPlayerGuild( _GuildMemberCore->getIngameEId() );
|
||||
|
||||
CGuildCharProxy proxy;
|
||||
|
@ -134,7 +134,7 @@ void CGuildMemberModule::setGrade( uint16 index,uint8 session, EGSPD::CGuildGrad
|
|||
CGuildCharProxy proxy;
|
||||
getProxy(proxy);
|
||||
proxy.cancelAFK();
|
||||
|
||||
|
||||
if ( guild->getMembersSession() != session )
|
||||
{
|
||||
proxy.sendSystemMessage( "GUILD_BAD_SESSION" );
|
||||
|
@ -165,17 +165,17 @@ void CGuildMemberModule::setGrade( uint16 index,uint8 session, EGSPD::CGuildGrad
|
|||
proxy.sendSystemMessage("GUILD_GRADE_FULL",paramFull);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
member->setMemberGrade(grade);
|
||||
guild->incGradeCount( grade );
|
||||
guild->decGradeCount( oldGrade );
|
||||
|
||||
|
||||
// send system message
|
||||
SM_STATIC_PARAMS_3(params,STRING_MANAGER::player,STRING_MANAGER::player,STRING_MANAGER::string_id);
|
||||
params[0].setEIdAIAlias( proxy.getId(), CAIAliasTranslator::getInstance()->getAIAlias(proxy.getId()) );
|
||||
params[1].setEIdAIAlias( member->getIngameEId(), CAIAliasTranslator::getInstance()->getAIAlias(member->getIngameEId()) );
|
||||
params[2].StringId = guild->getNameId();
|
||||
|
||||
|
||||
// If the player is online, the module must be recreated. Do as the reference was destroyed
|
||||
CGuildMemberModule * module = NULL;
|
||||
if ( member->getReferencingModule(module) )
|
||||
|
@ -266,7 +266,7 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil
|
|||
if ( target.getModule(inviteModule) )
|
||||
{
|
||||
CCharacter::sendDynamicSystemMessage( invitor.getRowId(), "GUILD_ALREADY_HAS_JOIN_PROPOSAL",params1 );
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/// the invitor must not be in the ignore list of the target
|
||||
|
@ -323,16 +323,18 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil
|
|||
SM_STATIC_PARAMS_1(params,STRING_MANAGER::integer);
|
||||
params[0].Int = GuildMaxMemberCount;
|
||||
CCharacter::sendDynamicSystemMessage( invitor.getRowId(), "GUILD_MAX_MEMBER_COUNT", params);
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
/// check guild and invited member allegiances compatibilities
|
||||
CGuild::TAllegiances guildAllegiance, invitedAllegiance;
|
||||
guildAllegiance = guild->getAllegiance();
|
||||
|
||||
CCharacter * invitedChar = PlayerManager.getChar(target.getId());
|
||||
if( invitedChar == 0 ) return;
|
||||
if (invitedChar == NULL) return;
|
||||
invitedAllegiance = invitedChar->getAllegiance();
|
||||
if( invitedAllegiance.first != guildAllegiance.first && invitedAllegiance.first != PVP_CLAN::Neutral )
|
||||
|
||||
if (invitedAllegiance.first != guildAllegiance.first && invitedAllegiance.first != PVP_CLAN::Neutral)
|
||||
{
|
||||
SM_STATIC_PARAMS_2( params, STRING_MANAGER::player, STRING_MANAGER::faction );
|
||||
params[0].setEIdAIAlias( target.getId(), CAIAliasTranslator::getInstance()->getAIAlias( target.getId()) );
|
||||
|
@ -340,7 +342,8 @@ void CGuildMemberModule::_inviteCharacterInGuild(CGuildCharProxy& invitor, CGuil
|
|||
invitor.sendSystemMessage("GUILD_ICOMPATIBLE_ALLEGIANCE",params);
|
||||
return;
|
||||
}
|
||||
if( invitedAllegiance.second != guildAllegiance.second && invitedAllegiance.second != PVP_CLAN::Neutral )
|
||||
|
||||
if (invitedAllegiance.second != guildAllegiance.second && invitedAllegiance.second != PVP_CLAN::Neutral)
|
||||
{
|
||||
SM_STATIC_PARAMS_2( params, STRING_MANAGER::player, STRING_MANAGER::faction );
|
||||
params[0].setEIdAIAlias( target.getId(), CAIAliasTranslator::getInstance()->getAIAlias( target.getId()) );
|
||||
|
@ -504,11 +507,11 @@ void CGuildMemberModule::clearOnlineGuildProperties()
|
|||
getProxy(targetProxy);
|
||||
targetProxy.setGuildId(0);
|
||||
targetProxy.updateTargetingChars();
|
||||
|
||||
|
||||
CMirrorPropValueRO<TYPE_CELL> mirrorCell( TheDataset, targetProxy.getEntityRowId(), DSPropertyCELL );
|
||||
sint32 cell = mirrorCell;
|
||||
sint32 cell = mirrorCell;
|
||||
if ( CBuildingManager::getInstance()->isRoomCell(cell) )
|
||||
{
|
||||
{
|
||||
CRoomInstanceGuild * room = dynamic_cast<CRoomInstanceGuild *>( CBuildingManager::getInstance()->getRoomInstanceFromCell( cell ) );
|
||||
if ( room && room->getGuildId() && room->getBuilding() )
|
||||
{
|
||||
|
@ -533,7 +536,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const
|
|||
CGuildCharProxy proxy;
|
||||
getProxy(proxy);
|
||||
proxy.cancelAFK();
|
||||
|
||||
|
||||
if ( guild->getMembersSession() != session )
|
||||
{
|
||||
proxy.sendSystemMessage( "GUILD_BAD_SESSION" );
|
||||
|
@ -544,7 +547,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const
|
|||
nlwarning("<GUILD>%s tries to kick himself",proxy.getId().toString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CGuildMember * member = guild->getMemberByIndex( index );
|
||||
if ( member == NULL )
|
||||
{
|
||||
|
@ -570,7 +573,7 @@ void CGuildMemberModule::kickMember( uint16 index,uint8 session )const
|
|||
params[1].StringId = CEntityIdTranslator::getInstance()->getEntityNameStringId(member->getIngameEId());
|
||||
sendMessageToGuildMembers("GUILD_KICK_MEMBER",params);
|
||||
|
||||
guild->deleteMember( member );
|
||||
guild->deleteMember( member );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -104,7 +104,7 @@ uint32 IMissionStepTemplate::sendRpStepText(CCharacter * user,const std::vector<
|
|||
|
||||
_User = user;
|
||||
|
||||
if (_RoleplayText.substr(0, 6) == "WEBIG_")
|
||||
if (_RoleplayText.compare(0, 6, "WEBIG_") == 0)
|
||||
{
|
||||
TVectorParamCheck params;
|
||||
string name = _RoleplayText;
|
||||
|
@ -174,7 +174,7 @@ uint32 IMissionStepTemplate::sendStepText(CCharacter * user,const std::vector<ui
|
|||
// If the text is overriden, add the overide parameters
|
||||
if ( !_OverridenText.empty() )
|
||||
{
|
||||
if (_OverridenText.substr(0, 6) == "WEBIG_")
|
||||
if (_OverridenText.compare(0, 6, "WEBIG_") == 0)
|
||||
{
|
||||
string text = _OverridenText;
|
||||
if (user)
|
||||
|
|
|
@ -2441,7 +2441,7 @@ uint32 CMissionTemplate::testPrerequisits( CCharacter * user, CPrerequisitInfos
|
|||
|
||||
uint32 CMissionTemplate::sendTitleText( const TDataSetRow & userRow, const TDataSetRow & giver ) const
|
||||
{
|
||||
if (TitleText.substr(0, 6) == "WEBIG_")
|
||||
if (TitleText.compare(0, 6, "WEBIG_") == 0)
|
||||
{
|
||||
string text = TitleText;
|
||||
CCharacter *user = PlayerManager.getChar(getEntityIdFromRow(userRow));
|
||||
|
@ -2469,7 +2469,7 @@ uint32 CMissionTemplate::sendTitleText( const TDataSetRow & userRow, const TData
|
|||
|
||||
uint32 CMissionTemplate::sendAutoText( const TDataSetRow & userRow,const NLMISC::CEntityId & giver) const
|
||||
{
|
||||
if (AutoText.substr(0, 6) == "WEBIG_")
|
||||
if (AutoText.compare(0, 6, "WEBIG_") == 0)
|
||||
{
|
||||
string text = AutoText;
|
||||
CCharacter *user = PlayerManager.getChar(getEntityIdFromRow(userRow));
|
||||
|
@ -2494,7 +2494,7 @@ uint32 CMissionTemplate::sendAutoText( const TDataSetRow & userRow,const NLMISC:
|
|||
|
||||
uint32 CMissionTemplate::sendDescText( const TDataSetRow & userRow, const TDataSetRow & giver, uint32 descIndex) const
|
||||
{
|
||||
if (DescText.substr(0, 6) == "WEBIG_")
|
||||
if (DescText.compare(0, 6, "WEBIG_") == 0)
|
||||
{
|
||||
string text = DescText;
|
||||
CCharacter *user = PlayerManager.getChar(getEntityIdFromRow(userRow));
|
||||
|
|
|
@ -8,6 +8,9 @@ FILE(GLOB SRC main.cpp
|
|||
${CMAKE_SOURCE_DIR}/ryzom/client/src/stdpch.h
|
||||
)
|
||||
|
||||
# always enable custom patch server
|
||||
ADD_DEFINITIONS(-DRZ_USE_CUSTOM_PATCH_SERVER)
|
||||
|
||||
ADD_EXECUTABLE(ryzom_client_patcher ${SRC})
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -397,4 +397,3 @@ int main(int argc, char *argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue