Skip to content

Commit

Permalink
fix bug for "adding" color values
Browse files Browse the repository at this point in the history
This is used for blitting with a per-blit alpha value. In 4bpp
mode, there was an error caused by improper use of the full byte
rather than just a nibble.
  • Loading branch information
hwhw committed Sep 28, 2014
1 parent 624348c commit 26003b1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ffi/blitbuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,14 @@ function ColorRGB32_mt.__index:set(color)
end
-- adding two colors:
function Color4L_mt.__index:add(color, intensity)
local value = tonumber(self.a) * (1-intensity) + tonumber(color:getColor4L().a) * intensity
local value = tonumber(band(self.a, 0x0F)) * (1-intensity) + tonumber(color:getColor4L().a) * intensity
if value > 0x0F then value = 0x0F end
self:set(Color4L(value))
end
function Color4U_mt.__index:add(color, intensity)
local orig = band(self.a, 0xF0)
local value = tonumber(orig) * (1-intensity) + tonumber(color:getColor4U().a) * intensity
local value = tonumber(band(self.a, 0xF0)) * (1-intensity) + tonumber(color:getColor4U().a) * intensity
if value > 0xF0 then value = 0xF0 end
self:set(Color4U(band(0xF0, value)))
self:set(Color4U(value))
end
function Color8_mt.__index:add(color, intensity)
local value = tonumber(self.a) * (1-intensity) + tonumber(color:getColor8().a) * intensity
Expand Down

0 comments on commit 26003b1

Please sign in to comment.