Skip to content

Commit

Permalink
scars & tracks: only construct the final image via red:=brightness & …
Browse files Browse the repository at this point in the history
…green:=alpha, if the image is a bitmap (only those don't have an alpha channel themselves). NOTE: this can give strange results if a mod already use png's etc. for scars & tracks
  • Loading branch information
-jk- committed May 16, 2009
1 parent 2015e36 commit 163b8af
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions rts/Rendering/GroundDecalHandler.cpp
Expand Up @@ -810,19 +810,24 @@ unsigned int CGroundDecalHandler::LoadTexture(const std::string& name)
(fullName.find_first_of('/') == string::npos)) {
fullName = string("bitmaps/tracks/") + fullName;
}
bool isBitmap = (StringToLower(fullName).find(string(".bmp")) != string::npos);

CBitmap bm;
if (!bm.Load(fullName)) {
throw content_error("Could not load ground decal from file " + fullName);
}
for (int y = 0; y < bm.ysize; ++y) {
for (int x = 0; x < bm.xsize; ++x) {
const int index = ((y * bm.xsize) + x) * 4;
bm.mem[index + 3] = bm.mem[index + 1];
const int brightness = bm.mem[index + 0];
bm.mem[index + 0] = (brightness * 90) / 255;
bm.mem[index + 1] = (brightness * 60) / 255;
bm.mem[index + 2] = (brightness * 30) / 255;
if (isBitmap) {
//! bitmaps don't have an alpha channel
//! so use: red := brightness & green := alpha
for (int y = 0; y < bm.ysize; ++y) {
for (int x = 0; x < bm.xsize; ++x) {
const int index = ((y * bm.xsize) + x) * 4;
bm.mem[index + 3] = bm.mem[index + 1];
const int brightness = bm.mem[index + 0];
bm.mem[index + 0] = (brightness * 90) / 255;
bm.mem[index + 1] = (brightness * 60) / 255;
bm.mem[index + 2] = (brightness * 30) / 255;
}
}
}

Expand Down Expand Up @@ -890,15 +895,31 @@ void CGroundDecalHandler::LoadScar(const std::string& file, unsigned char* buf,
if (!bm.Load(file)) {
throw content_error("Could not load scar from file " + file);
}
for (int y = 0; y < bm.ysize; ++y) {
for (int x = 0; x < bm.xsize; ++x) {
const int memIndex = ((y * bm.xsize) + x) * 4;
const int bufIndex = (((y + yoffset) * 512) + x + xoffset) * 4;
buf[bufIndex + 3] = bm.mem[memIndex + 1];
const int brightness = bm.mem[memIndex + 0];
buf[bufIndex + 0] = (brightness * 90) / 255;
buf[bufIndex + 1] = (brightness * 60) / 255;
buf[bufIndex + 2] = (brightness * 30) / 255;
bool isBitmap = (StringToLower(file).find(string("bmp")) != string::npos);
if (isBitmap) {
//! bitmaps don't have an alpha channel
//! so use: red := brightness & green := alpha
for (int y = 0; y < bm.ysize; ++y) {
for (int x = 0; x < bm.xsize; ++x) {
const int memIndex = ((y * bm.xsize) + x) * 4;
const int bufIndex = (((y + yoffset) * 512) + x + xoffset) * 4;
buf[bufIndex + 3] = bm.mem[memIndex + 1];
const int brightness = bm.mem[memIndex + 0];
buf[bufIndex + 0] = (brightness * 90) / 255;
buf[bufIndex + 1] = (brightness * 60) / 255;
buf[bufIndex + 2] = (brightness * 30) / 255;
}
}
} else {
for (int y = 0; y < bm.ysize; ++y) {
for (int x = 0; x < bm.xsize; ++x) {
const int memIndex = ((y * bm.xsize) + x) * 4;
const int bufIndex = (((y + yoffset) * 512) + x + xoffset) * 4;
buf[bufIndex + 0] = bm.mem[memIndex + 0];
buf[bufIndex + 1] = bm.mem[memIndex + 1];
buf[bufIndex + 2] = bm.mem[memIndex + 2];
buf[bufIndex + 3] = bm.mem[memIndex + 3];
}
}
}
}
Expand Down

0 comments on commit 163b8af

Please sign in to comment.