From 77f8498295bf31bfa5f5206592f2bf1cda0d91eb Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Sat, 22 Apr 2017 02:38:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B0=D0=BA,=20=D0=B2=D0=BE=D1=82=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=20=D1=83=D0=B6=D0=B5=20=D0=BF=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=D1=81=D1=82=D1=80=D0=B5=D0=B5=20=D0=B1=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/image.lua | 52 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/image.lua b/lib/image.lua index aa707c7e..06398e5c 100755 --- a/lib/image.lua +++ b/lib/image.lua @@ -57,29 +57,49 @@ end function image.draw(x, y, picture) local groupedPicture = image.group(picture) + local _, _, currentBackground, currentForeground, gpuGetBackground, imageX, imageY for alpha in pairs(groupedPicture) do for symbol in pairs(groupedPicture[alpha]) do - for background in pairs(groupedPicture[alpha][symbol]) do - gpu.setBackground(background) - for foreground in pairs(groupedPicture[alpha][symbol][background]) do - gpu.setForeground(foreground) - for yPos in pairs(groupedPicture[alpha][symbol][background][foreground]) do - for xPos = 1, #groupedPicture[alpha][symbol][background][foreground][yPos] do - if alpha > 0x0 then - local oldBackground = background - local _, _, gpuGetBackground = gpu.get(x, y) - - gpu.setBackground(colorlib.alphaBlend(gpuGetBackground, background, alpha / 0xFF)) - gpu.set(x + groupedPicture[alpha][symbol][background][foreground][yPos][xPos] - 1, y + yPos - 1, symbol) - gpu.setBackground(oldBackground) - else - gpu.set(x + groupedPicture[alpha][symbol][background][foreground][yPos][xPos] - 1, y + yPos - 1, symbol) + + if not (symbol == " " and alpha == 0xFF) then + for background in pairs(groupedPicture[alpha][symbol]) do + + if background ~= currentBackground then + currentBackground = background + gpu.setBackground(background) + end + + for foreground in pairs(groupedPicture[alpha][symbol][background]) do + + if foreground ~= currentForeground and symbol ~= " " then + currentForeground = foreground + gpu.setForeground(foreground) + end + + for yPos in pairs(groupedPicture[alpha][symbol][background][foreground]) do + for xPos = 1, #groupedPicture[alpha][symbol][background][foreground][yPos] do + imageX, imageY = x + groupedPicture[alpha][symbol][background][foreground][yPos][xPos] - 1, y + yPos - 1 + + if alpha > 0x0 then + _, _, gpuGetBackground = gpu.get(imageX, imageY) + + if alpha == 0xFF then + currentBackground = gpuGetBackground + gpu.setBackground(currentBackground) + else + currentBackground = colorlib.alphaBlend(gpuGetBackground, background, alpha / 0xFF) + gpu.setBackground(currentBackground) + end + end + + gpu.set(imageX, imageY, symbol) end end end end end + end end end @@ -357,7 +377,7 @@ image.loadFormatModule("/lib/ImageFormatModules/OCIF.lua", ".pic") -- image.draw(1, 1, picture) -- end --- clearAndDraw(image.load("/MineOS/System/OS/Icons/Love.pic")) +-- clearAndDraw(image.load("/MineOS/Pictures/Ciri.pic")) -- local w, h = 2, 2 -- local picture = image.create(w, h, 0xFF0000, 0xFFFFFF, 0x0, "Q")