Skip to content

Commit

Permalink
Per-pixel transparency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mignari committed Apr 4, 2014
1 parent a02c091 commit 41b2f9b
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
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
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
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());

This comment has been minimized.

Copy link
@hrsantiago

hrsantiago Apr 4, 2014

Collaborator

This is not correct. To fix, just remove this line.
Those 3 bytes are part of colorkey.
Color key makes no sense if you are using alpha channel.

This comment has been minimized.

Copy link
@Mignari

Mignari Apr 4, 2014

Author Contributor

This comment has been minimized.

Copy link
@asamy

asamy Apr 4, 2014

Collaborator

Why do you add this? This simply completely broke the sprite parser, have you even tested it with a regular SPR file? This is logically broken, we don't even skip 1 byte after reading the RGB, so that you'd remove the skip and assign the value as the alpha channel.

This comment has been minimized.

Copy link
@hrsantiago

hrsantiago Apr 4, 2014

Collaborator

Don't get your comment, decltype. All of his changes depends on a GameFeature.
Btw, I don't get this sprSave function. You're not able to make any changes to a sprite.
You simple read from a file and write to another. The only changeable thing is the number of sprites copied.

This comment has been minimized.

Copy link
@Mignari

Mignari Apr 4, 2014

Author Contributor

If you have not enabled the feature nothing is changed. Don't skip 1 byte after reading the RGB.

Feature not enabled and regular spr
disabled

Feature enabled and edited spr
enabled

This comment has been minimized.

Copy link
@asamy

asamy Apr 4, 2014

Collaborator

Ah, didn't take into account that it all depends on a game feature, my bad.

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
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 41b2f9b

Please sign in to comment.