Skip to content

Commit

Permalink
Merge pull request #513 from Mignari/master
Browse files Browse the repository at this point in the history
Per-pixel transparency, fix image blit.
  • Loading branch information
hrsantiago committed Apr 4, 2014
2 parents a02c091 + 41b2f9b commit 50d3f83
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/gamelib/const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ GameNewOutfitProtocol = 49
GamePVPMode = 50
GameWritableDate = 51
GameAdditionalVipInfo = 52
GameSpritesAlphaChannel = 56

TextColors = {
red = '#f55e5e', --'#c83200'
Expand Down
1 change: 1 addition & 0 deletions src/client/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ namespace Otc
GameBaseSkillU16 = 53,
GameCreatureIcons = 54,
GameHideNpcNames = 55,
GameSpritesAlphaChannel = 56,

LastGameFeature = 101
};
Expand Down
8 changes: 6 additions & 2 deletions src/client/spritemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void SpriteManager::saveSpr(std::string fileName)
else
fin->addU16(m_spritesCount);

bool useAlpha = g_game.getFeature(Otc::GameSpritesAlphaChannel);
uint32 offset = fin->tell();
uint32 spriteAddress = offset + 4 * m_spritesCount;
for(int i = 1; i <= m_spritesCount; i++)
Expand All @@ -98,6 +99,7 @@ void SpriteManager::saveSpr(std::string fileName)
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
fin->addU8(m_spritesFile->getU8());
if (useAlpha) fin->addU8(m_spritesFile->getU8());

uint16 dataSize = m_spritesFile->getU16();
fin->addU16(dataSize);
Expand Down Expand Up @@ -153,6 +155,8 @@ ImagePtr SpriteManager::getSpriteImage(int id)
uint8 *pixels = image->getPixelData();
int writePos = 0;
int read = 0;
bool useAlpha = g_game.getFeature(Otc::GameSpritesAlphaChannel);
uint8 channels = useAlpha ? 4 : 3;

// decompress pixels
while(read < pixelDataSize && writePos < SPRITE_DATA_SIZE) {
Expand All @@ -171,11 +175,11 @@ ImagePtr SpriteManager::getSpriteImage(int id)
pixels[writePos + 0] = m_spritesFile->getU8();
pixels[writePos + 1] = m_spritesFile->getU8();
pixels[writePos + 2] = m_spritesFile->getU8();
pixels[writePos + 3] = 0xFF;
pixels[writePos + 3] = useAlpha ? m_spritesFile->getU8() : 0xFF;
writePos += 4;
}

read += 4 + (3 * coloredPixels);
read += 4 + (channels * coloredPixels);
}

// fill remaining pixels with alpha
Expand Down
2 changes: 1 addition & 1 deletion src/framework/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void Image::blit(const Point& dest, const ImagePtr& other)
int y = p / other->getWidth();
int pos = ((dest.y + y) * m_size.width() + (dest.x + x)) * 4;

if(otherPixels[p*4+3] == 0xFF) {
if (otherPixels[p*4+3] != 0) {
m_pixels[pos+0] = otherPixels[p*4+0];
m_pixels[pos+1] = otherPixels[p*4+1];
m_pixels[pos+2] = otherPixels[p*4+2];
Expand Down

0 comments on commit 50d3f83

Please sign in to comment.