mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 07:16:15 +00:00
Changed: Added default checks for textures and masks (-t and -m)
This commit is contained in:
parent
d910feb086
commit
9a2d36f684
1 changed files with 72 additions and 17 deletions
|
@ -29,8 +29,10 @@ void writeInstructions()
|
||||||
std::cout << " By default, it only make checks and display if texture can optimized or not" << 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 << std::endl;
|
||||||
std::cout << "with" << std::endl;
|
std::cout << "with" << std::endl;
|
||||||
std::cout << "-a : Remove alpha channel if useless" << std::endl;
|
std::cout << "-a : Remove alpha channel if useless (255)" << std::endl;
|
||||||
std::cout << "-g : Convert to grayscale if all pixels are gray" << std::endl;
|
std::cout << "-g : Convert to grayscale if all pixels are gray" << std::endl;
|
||||||
|
std::cout << "-t : Apply texture optimizations (same as -a -g)" << std::endl;
|
||||||
|
std::cout << "-m : Apply mask optimizations (convert to grayscale using red value and remove alpha)" << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "-h or -? for this help" << std::endl;
|
std::cout << "-h or -? for this help" << std::endl;
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
@ -38,6 +40,8 @@ void writeInstructions()
|
||||||
|
|
||||||
bool FixAlpha = false;
|
bool FixAlpha = false;
|
||||||
bool FixGrayscale = false;
|
bool FixGrayscale = false;
|
||||||
|
bool TextureOptimizations = false;
|
||||||
|
bool MaskOptimizations = false;
|
||||||
|
|
||||||
std::vector<std::string> InputFilenames;
|
std::vector<std::string> InputFilenames;
|
||||||
|
|
||||||
|
@ -74,6 +78,18 @@ bool parseOptions(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FixGrayscale = true;
|
FixGrayscale = true;
|
||||||
}
|
}
|
||||||
|
// Texture optimizations
|
||||||
|
else if (option == "t")
|
||||||
|
{
|
||||||
|
TextureOptimizations = true;
|
||||||
|
FixAlpha = true;
|
||||||
|
FixGrayscale = true;
|
||||||
|
}
|
||||||
|
// Mask optimizations
|
||||||
|
else if (option == "m")
|
||||||
|
{
|
||||||
|
MaskOptimizations = true;
|
||||||
|
}
|
||||||
else if (option == "h" || option == "?")
|
else if (option == "h" || option == "?")
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -168,6 +184,44 @@ int main(int argc, char **argv)
|
||||||
isGrayscale = true;
|
isGrayscale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MaskOptimizations && (!isGrayscale || hasAlpha))
|
||||||
|
{
|
||||||
|
std::cout << InputFilenames[i] << " (mask with wrong format)" << std::endl;
|
||||||
|
|
||||||
|
if (!isGrayscale)
|
||||||
|
{
|
||||||
|
// get a pointer on original RGBA data
|
||||||
|
uint32 size = bitmap.getPixels().size();
|
||||||
|
uint32 *data = (uint32*)bitmap.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// already in grayscale, just remove alpha
|
||||||
|
bitmap.convertToType(NLMISC::CBitmap::Luminance);
|
||||||
|
|
||||||
|
isGrayscale = true;
|
||||||
|
hasAlpha = false;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (!isGrayscale && bitmap.isGrayscale())
|
if (!isGrayscale && bitmap.isGrayscale())
|
||||||
{
|
{
|
||||||
std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl;
|
std::cout << InputFilenames[i] << " (grayscale image with RGB colors)" << std::endl;
|
||||||
|
@ -199,6 +253,7 @@ int main(int argc, char **argv)
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!modified) continue;
|
if (!modified) continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue