From 9c8a8059014229a95eb31f3368abc26292f3ca5b Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Tue, 27 Oct 2015 14:42:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20Image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/doubleBuffering.lua | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/doubleBuffering.lua b/lib/doubleBuffering.lua index 7f1bc7c8..41f02612 100644 --- a/lib/doubleBuffering.lua +++ b/lib/doubleBuffering.lua @@ -1,11 +1,12 @@ local component = require("component") local colorlib = require("colorlib") local unicode = require("unicode") +local image local gpu = component.gpu local buffer = {} local countOfGPUOperations = 0 -local debug = false +local debug = true local sizeOfPixelData = 3 ------------------------------------------------------------------------------------------------------ @@ -264,9 +265,33 @@ function buffer.text(x, y, color, text) local index local sText = unicode.len(text) for i = 1, sText do - index = convertCoordsToIndex(x + i - 1, y) - buffer.screen.new[index + 1] = color - buffer.screen.new[index + 2] = unicode.sub(text, i, i) + if (x + i - 1) >= 1 and y >= 1 and (x + i - 1) <= buffer.screen.width and y <= buffer.screen.height then + index = convertCoordsToIndex(x + i - 1, y) + buffer.screen.new[index + 1] = color + buffer.screen.new[index + 2] = unicode.sub(text, i, i) + end + end +end + +function buffer.image(x, y, picture) + if not image then image = require("image") end + local index, imageIndex + for j = y, (y + picture.height - 1) do + for i = x, (x + picture.width - 1) do + if i >= 1 and j >= 1 and i <= buffer.screen.width and j <= buffer.screen.height then + index = convertCoordsToIndex(i, j) + --Копипаст формулы! + imageIndex = (picture.width * ((j - y + 1) - 1) + (i - x + 1)) * 4 - 4 + 1 + + if picture[imageIndex + 2] ~= 0x00 then + buffer.screen.new[index] = colorlib.alphaBlend(buffer.screen.new[index], picture[imageIndex], picture[imageIndex + 2]) + else + buffer.screen.new[index] = picture[imageIndex] + end + buffer.screen.new[index + 1] = picture[imageIndex + 1] + buffer.screen.new[index + 2] = picture[imageIndex + 3] + end + end end end