From c3aa197047bec198c2da51bc7c254b82d596674a Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Mon, 24 Apr 2017 04:34:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D1=86=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=B8=20=D0=BE=D0=BF=D1=82=D0=B8=D0=BC=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0=20=D1=81=D0=B6=D0=B0=D1=82=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications.cfg | 34 ++-- Applications/3DPrint/3DPrint.lua | 9 +- Applications/3DTest/3DTest.lua | 6 +- Applications/GeoScan2/GeoScan2.lua | 4 +- Applications/Photoshop/Photoshop.lua | 6 +- Applications/PrintImage/PrintImage.lua | 6 +- Installer/installer2.lua | 6 +- MineOS/OS.lua | 2 +- lib/ECSAPI.lua | 2 +- lib/ImageFormatModules/JPEG.lua | 263 +++++++++++++++++++++++++ lib/ImageFormatModules/OCIF.lua | 18 +- lib/MineOSCore.lua | 2 +- lib/OpenComputersGL/Main.lua | 8 +- lib/OpenComputersGL/Materials.lua | 5 +- lib/color.lua | 133 +++++++++++++ lib/doubleBuffering.lua | 12 +- lib/image.lua | 26 +-- lib/palette.lua | 27 +-- lib/rayEngine.lua | 6 +- 19 files changed, 481 insertions(+), 94 deletions(-) create mode 100644 lib/ImageFormatModules/JPEG.lua create mode 100755 lib/color.lua diff --git a/Applications.cfg b/Applications.cfg index b3a33698..26e5e6d6 100644 --- a/Applications.cfg +++ b/Applications.cfg @@ -5,7 +5,7 @@ about="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/MineOS/About/", type="Script", forceDownload=true, - version=3.51, + version=3.52, }, { path="/MineOS/Pictures/Raspberry.pic", @@ -198,14 +198,14 @@ path="/lib/MineOSCore.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/MineOSCore.lua", type="Library", - version=1.54, + version=1.55, }, { path="/lib/advancedLua.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/advancedLua.lua", type="Library", preloadFile=true, - version=1.09, + version=1.10, }, { path="/lib/web.lua", @@ -227,25 +227,25 @@ version=1.14, }, { - path="/lib/colorlib.lua", - url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/colorlib.lua", + path="/lib/color.lua", + url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/color.lua", type="Library", preloadFile=true, - version=1.05, + version=1.00, }, { path="/lib/ImageFormatModules/OCIF.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/ImageFormatModules/OCIF.lua", type="Library", preloadFile=true, - version=1.00, + version=1.01, }, { path="/lib/image.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/image.lua", type="Library", preloadFile=true, - version=1.24, + version=1.25, }, { path="/lib/serialization.lua", @@ -258,13 +258,13 @@ url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/GUI.lua", type="Library", preloadFile=true, - version=1.49, + version=1.50, }, { path="/lib/rayEngine.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/rayEngine.lua", type="Library", - version=1.39, + version=1.40, }, { path="/lib/json.lua", @@ -318,14 +318,14 @@ path="/lib/palette.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/palette.lua", type="Library", - version=1.11, + version=1.12, }, { path="/lib/doubleBuffering.lua", url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/doubleBuffering.lua", type="Library", preloadFile=true, - version=1.21, + version=1.22, }, { path="/lib/compressor.lua", @@ -456,7 +456,7 @@ icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/3DTest/Icon.pic", createShortcut="desktop", forceDownload=true, - version=1.16, + version=1.17, }, { path="/MineOS/Applications/GeoScan2", @@ -464,7 +464,7 @@ type="Application", icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/GeoScan2/Icon.pic", createShortcut="desktop", - version=1.05, + version=1.06, resources={ { path="/Earth.pic", @@ -627,7 +627,7 @@ type="Application", icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/3DPrint/Icon.pic", createShortcut="desktop", - version=1.11, + version=1.12, }, { path="/MineOS/Applications/FlappyBird", @@ -774,7 +774,7 @@ type="Application", icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/PrintImage/Icon.pic", createShortcut="desktop", - version=1.08, + version=1.09, }, { path="/MineOS/Applications/Palette", @@ -890,7 +890,7 @@ icon="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Photoshop/Icon.pic", createShortcut="dock", forceDownload=true, - version=1.04, + version=1.05, resources={ { path="/Localization/Russian.lang", diff --git a/Applications/3DPrint/3DPrint.lua b/Applications/3DPrint/3DPrint.lua index 760bff5a..ba4400af 100755 --- a/Applications/3DPrint/3DPrint.lua +++ b/Applications/3DPrint/3DPrint.lua @@ -5,8 +5,7 @@ local unicode = require("unicode") local serialization = require("serialization") local fs = require("filesystem") ---image -local colorlib = require("colorlib") +local color = require("color") local buffer = require("doubleBuffering") local context = require("context") local bigLetters = require("bigLetters") @@ -83,7 +82,7 @@ local shapeColors = {} local HUE = 0 local HUEAdder = math.floor(360 / maxShapeCount) for i = 1, maxShapeCount do - shapeColors[i] = colorlib.HSBtoHEX(HUE, 100, 100) + shapeColors[i] = color.HSBToHEX(HUE, 100, 100) HUE = HUE + HUEAdder end HUE, HUEAdder = nil, nil @@ -375,10 +374,10 @@ local function drawDrawingZone() if currentLayer >= selectionStartPoint.z and currentLayer <= selectionEndPoint.z then if shape ~= currentShape then - local h, s, b = colorlib.HEXtoHSB(shapeColors[shape]) + local h, s, b = color.HEXToHSB(shapeColors[shape]) s = 30 -- ecs.error("РИСУЮ") - drawPixel(selectionStartPoint.x, 18 - selectionStartPoint.y - yDifference, selectionEndPoint.x - selectionStartPoint.x + 1, yDifference, colorlib.HSBtoHEX(h, s, b)) + drawPixel(selectionStartPoint.x, 18 - selectionStartPoint.y - yDifference, selectionEndPoint.x - selectionStartPoint.x + 1, yDifference, color.HSBToHEX(h, s, b)) -- drawPixel(selectionStartPoint.x, selectionStartPoint.z, selectionEndPoint.x - selectionStartPoint.x + 1, selectionEndPoint.z - selectionStartPoint.z + 1, shapeColors[shape], trasparency) else drawPixel(selectionStartPoint.x, 18 - selectionStartPoint.y - yDifference, selectionEndPoint.x - selectionStartPoint.x + 1, yDifference, shapeColors[shape]) diff --git a/Applications/3DTest/3DTest.lua b/Applications/3DTest/3DTest.lua index ad823fad..bbe71275 100644 --- a/Applications/3DTest/3DTest.lua +++ b/Applications/3DTest/3DTest.lua @@ -9,7 +9,7 @@ -- package.loaded["OpenComputersGL/Renderer"] = nil -- package.loaded["MeowEngine/Main"] = nil -local colorlib = require("colorlib") +local color = require("color") local computer = require("computer") local buffer = require("doubleBuffering") local event = require("event") @@ -141,7 +141,7 @@ local hue, hueStep = 0, 360 / 9 for z = -1, 1 do for x = -1, 1 do if not (x == 0 and z == 0) then - setBlock(x, 0, z, colorlib.HSBtoHEX(hue, 100, 100)) + setBlock(x, 0, z, color.HSBToHEX(hue, 100, 100)) hue = hue + hueStep end end @@ -232,7 +232,7 @@ end -- elseif mesh.triangles[triangleIndex].brightness < minimumBrightness then -- mesh.triangles[triangleIndex].brightness = minimumBrightness -- end --- mesh.triangles[triangleIndex][4] = materials.newSolidMaterial(colorlib.HSBtoHEX(mesh.hue, 100, mesh.triangles[triangleIndex].brightness)) +-- mesh.triangles[triangleIndex][4] = materials.newSolidMaterial(color.HSBToHEX(mesh.hue, 100, mesh.triangles[triangleIndex].brightness)) -- end -- end diff --git a/Applications/GeoScan2/GeoScan2.lua b/Applications/GeoScan2/GeoScan2.lua index bd72d698..9c4fde5b 100644 --- a/Applications/GeoScan2/GeoScan2.lua +++ b/Applications/GeoScan2/GeoScan2.lua @@ -1,6 +1,6 @@ local component = require("component") -local colorlib = require("colorlib") +local color = require("color") local image = require("image") local buffer = require("doubleBuffering") local GUI = require("GUI") @@ -30,7 +30,7 @@ local window = GUI.fullScreenWindow() -------------------------------------------------------------------------------------------------------------------- local function getOpenGLValidColorChannels(color) - local r, g, b = colorlib.HEXtoRGB(color) + local r, g, b = color.HEXToRGB(color) return r / 255, g / 255, b / 255 end diff --git a/Applications/Photoshop/Photoshop.lua b/Applications/Photoshop/Photoshop.lua index dd4de4b6..694ffa29 100755 --- a/Applications/Photoshop/Photoshop.lua +++ b/Applications/Photoshop/Photoshop.lua @@ -68,7 +68,7 @@ local image = require("image") local component = require("component") local keyboard = require("keyboard") local buffer = require("doubleBuffering") -local colorlib = require("colorlib") +local color = require("color") local palette = require("palette") local event = require("event") @@ -308,7 +308,7 @@ local function drawPixel(x, y, xPixel, yPixel, iterator) end end - buffer.set(x, y, colorlib.alphaBlend(blendColor, background, alpha / 0xFF), foreground, symbol) + buffer.set(x, y, color.blend(blendColor, background, alpha / 0xFF), foreground, symbol) end background, foreground, alpha, symbol = nil, nil, nil, nil end @@ -843,7 +843,7 @@ local function brush(x, y, background, foreground, alpha, symbol) elseif alpha < 0xFF and alpha > 0x00 then --Если пиксель в массиве ни хуя не прозрачный, то оставляем его таким же, разве что цвет меняем на сблендированный if masterPixels[newIterator + 2] == 0x00 then - local gettedBackground = colorlib.alphaBlend(masterPixels[newIterator], background, alpha / 0xFF) + local gettedBackground = color.blend(masterPixels[newIterator], background, alpha / 0xFF) setPixel(newIterator, gettedBackground, foreground, 0x00, symbol) --А если прозрачный, то смешиваем прозрачности --Пиздануться вообще, сук diff --git a/Applications/PrintImage/PrintImage.lua b/Applications/PrintImage/PrintImage.lua index c2bde01b..0de8114c 100755 --- a/Applications/PrintImage/PrintImage.lua +++ b/Applications/PrintImage/PrintImage.lua @@ -6,7 +6,7 @@ local computer = require("computer") local unicode = require("unicode") local fs = require("filesystem") local advancedLua = require("advancedLua") -local colorlib = require("colorlib") +local color = require("color") local image = require("image") local buffer = require("doubleBuffering") local GUI = require("GUI") @@ -157,14 +157,14 @@ end local function verticalLine(x, y, height, transparency) for i = y, y + height - 1 do local background = buffer.get(x, i) - buffer.set(x, i, background, colorlib.alphaBlend(background, 0xFFFFFF, transparency), "│") + buffer.set(x, i, background, color.blend(background, 0xFFFFFF, transparency), "│") end end local function horizontalLine(x, y, width, transparency) for i = x, x + width - 1 do local background, foreground, symbol = buffer.get(i, y) - buffer.set(i, y, background, colorlib.alphaBlend(background, 0xFFFFFF, transparency), symbol == "│" and "┼" or "─") + buffer.set(i, y, background, color.blend(background, 0xFFFFFF, transparency), symbol == "│" and "┼" or "─") end end diff --git a/Installer/installer2.lua b/Installer/installer2.lua index ebda92fc..73b0e254 100644 --- a/Installer/installer2.lua +++ b/Installer/installer2.lua @@ -1,6 +1,6 @@ -package.loaded.web = nil -package.loaded.GUI = nil +-- package.loaded.web = nil +-- package.loaded.GUI = nil local fs = require("filesystem") local component = require("component") @@ -310,6 +310,8 @@ stages[5] = function() file:write("dofile(\"/OS.lua\")") file:close() + fs.makeDirectory("/MineOS/Trash/") + require("computer").shutdown(true) end end diff --git a/MineOS/OS.lua b/MineOS/OS.lua index 9acf5aba..f0ce3422 100755 --- a/MineOS/OS.lua +++ b/MineOS/OS.lua @@ -22,7 +22,7 @@ local copyright = [[ ---------------------------------------------- Адаптивная загрузка библиотек ------------------------------------------------------------------------ -package.loaded.MineOSCore = nil +-- package.loaded.MineOSCore = nil local component = require("component") local unicode = require("unicode") diff --git a/lib/ECSAPI.lua b/lib/ECSAPI.lua index d7253ced..2f011cb4 100755 --- a/lib/ECSAPI.lua +++ b/lib/ECSAPI.lua @@ -1884,7 +1884,7 @@ function ecs.universalWindow(x, y, width, background, closeWindowAfter, ...) elseif objectType == "color" then local xPos, yPos = x + 1, objects[number].y - local blendedColor = require("colorlib").alphaBlend(objects[number][3], 0xFFFFFF, 0.705882) + local blendedColor = require("color").blend(objects[number][3], 0xFFFFFF, 0.705882) local w = width - 2 ecs.colorTextWithBack(xPos, yPos + 2, blendedColor, background, string.rep("▀", w)) diff --git a/lib/ImageFormatModules/JPEG.lua b/lib/ImageFormatModules/JPEG.lua new file mode 100644 index 00000000..4fa194c4 --- /dev/null +++ b/lib/ImageFormatModules/JPEG.lua @@ -0,0 +1,263 @@ +local cmp = require("component") +local com = require("computer") +local gpu = cmp.gpu +local trm = require("term") +local shl = require("shell") +local args = shl.parse(...) + +HEX = "0123456789ABCDEF" +--[[ MARKER ]] + +function R(ind) + return STR:byte(ind) % 16 +end + +function L(ind) + return math.floor( STR:byte(ind) / 16 ) +end + +function getB(ind) local right, left = R(ind) + 1, L(ind) + 1 + return HEX:sub(left, left)..HEX:sub(right, right) +end + +function Common() + i = len +end + +function DB() local IDI, x, y = R(i) + 1, 1, 1 + i = i + 1 + while i < len do + while y > 1 and x < 8 do + masDB[IDI][y][x] = STR:byte(i) i = i + 1 + y, x = y - 1, x + 1 + end + if y <= 8 and x <= 8 then + masDB[IDI][y][x] = STR:byte(i) i = i + 1 + end + if x == 8 then y = y + 1 + else x = x + 1 end + while y < 8 and x > 1 do + masDB[IDI][y][x] = STR:byte(i) i = i + 1 + y, x = y + 1, x - 1 + end + if y <= 8 and x <= 8 then + masDB[IDI][y][x] = STR:byte(i) i = i + 1 + end + if y == 8 then x = x + 1 + else y = y + 1 end + end +end + +function DA() local YCbCr, BYTECODE, BYTEpos, comp = {}, "", 1, STR:byte(i) + local function DrawFrame(coordX, coordY) local Y, Cb_avr, Cr_avr, value + local function getTable(INDEX) local DC_ind, AC_ind, x, y, TABLE = YCbCr[INDEX][1], YCbCr[INDEX][2], 1, 1, {{}, {}, {}, {}, {}, {}, {}, {}} + local CODE + local function getKEY(ACDC_TABLE) local key = "" + while ACDC_TABLE[key] == nil do + key = key..BYTECODE:sub(BYTEpos, BYTEpos) + BYTEpos = BYTEpos + 1 + end + return ACDC_TABLE[key] + end + + local function getCOEF(VALUE) local COEF = 0 + + CODE = BYTECODE:sub(BYTEpos, BYTEpos + VALUE - 1) + BYTEpos = BYTEpos + VALUE + for j=1, #CODE do + COEF = COEF * 2 + tonumber(CODE:sub(j, j)) + end + if #CODE ~= 0 and CODE:sub(1, 1) == "0" then + COEF = COEF - 2 ^ #CODE + 1 + end + return COEF + end + + local function step(n) + TABLE[y][x] = n * masDB[QUAT[INDEX] + 1][y][x] + if (x + y) % 2 == 1 then + if y == 8 then x = x + 1 + elseif x == 1 then y = y + 1 + else x, y = x - 1, y + 1 + end + else + if x == 8 then y = y + 1 + elseif y == 1 then x = x + 1 + else x, y = x + 1, y - 1 + end + end + end + --[[ DC Coeficient ]] + value = getKEY(AC_DC[0][DC_ind]) + step(getCOEF(value) + YCbCr[INDEX][3]) + YCbCr[INDEX][3] = TABLE[1][1] / masDB[QUAT[INDEX] + 1][1][1] + --[[ AC Coeficient ]] + if AC_DC[1][AC_ind] ~= nil then + while TABLE[8][8] == nil do + value = getKEY(AC_DC[1][AC_ind]) + if value == 0 then break + end + for j=1, math.floor(value / 16) do + step(0) + end + step(getCOEF(value % 16) or 0) + end + end + while TABLE[8][8] == nil do + step(0) + end + return TABLE + end + + local function getPIXEL(l, j) + local function RGB(Yval, Cbval, Crval) + local function SSS(val) + local ost + val, ost = math.modf(val) + if ost > 0.5 then + val = val + 1 + end + return math.max(0, math.min(255, val)) + end + return SSS(Yval + 1.402 * Crval + 128) * 2 ^ 16 + SSS(Yval - 0.34414 * Cbval - 0.71414 * Crval + 128) * 2 ^ 8 + SSS(Yval + 1.772 * Cbval + 128) + end + return RGB(Y[DCT[1][1] * math.floor((l - 1) / 8) + math.ceil(j / 8)][(l - 1) % 8 + 1][(j - 1) % 8 + 1], Cb_avr[math.ceil(l / DCT[1][2])][math.ceil(j / DCT[1][1])], Cr_avr[math.ceil(l / DCT[1][2])][math.ceil(j / DCT[1][1])]) + end + + local function ODCP(arr) local arr1 = {{}, {}, {}, {}, {}, {}, {}, {}} + local function getC(var) + if var == 0 then return 1 / math.sqrt(2) end + return 1 + end + local function getSyx(x, y) local Syx = 0 + for u = 0, 7 do + local COSU = getC(u) * math.cos(((2 * x + 1) * u * math.pi) / 16) + for v = 0, 7 do + Syx = Syx + COSU * getC(v) * math.cos(((2 * y + 1) * v * math.pi) / 16) * arr[u+1][v+1] + end + end + return Syx / 4 + end + + for l=1, 8 do + for j=1, 8 do + arr1[l][j] = getSyx(l - 1, j - 1) + end + end + return arr1 + end + + Y = {} + for l=1, DCT[1][1] * DCT[1][2] do + Y[l] = ODCP(getTable(1)) + end + Cb_avr = ODCP(getTable(2)) + Cr_avr = ODCP(getTable(3)) + for l=1, 4 * DCT[1][2] do + for j=1, 8 * DCT[1][1] do + gpu.setBackground(getPIXEL(l*2-1, j)) + gpu.setForeground(getPIXEL(l*2, j)) + gpu.set(j + coordX - 1,l + coordY - 1,"▄") + end + end + end + + local function getBITCODE(value) local tmp = "" + for j=1, 8 do + tmp = tostring(value % 2)..tmp + value = math.floor(value / 2) + end + return tmp + end + + i = i + 1 + if comp ~= 3 then + print("ERROR in FF DA") os.exit() + end + YCbCr = {{L(i + 1), R(i + 1), 0}, {L(i + 3), R(i + 3), 0}, {L(i + 5), R(i + 5), 0}} + i = len + local j = i + while j < #STR - 1 do + if STR:byte(j) == 255 then BYTECODE, j = BYTECODE.."11111111", j + 1 + else BYTECODE = BYTECODE..getBITCODE(STR:byte(j)) + end + j = j + 1 + end + for I = 1, math.ceil(HEIGHT / (8 * DCT[1][2])) do + for J = 1, math.ceil(WIDTH / (8 * DCT[1][1])) do + DrawFrame((J - 1) * 8 * DCT[1][1] + 1, (I - 1) * 4 * DCT[1][2] + 1) + end + end +end + +function C0() + QUAT, i = {}, i + 1 + HEIGHT = STR:byte(i) * 256 + STR:byte(i + 1) i = i + 2 + WIDTH = STR:byte(i) * 256 + STR:byte(i + 1) i = i + 3 + -- gpu.setResolution(WIDTH, math.floor(HEIGHT / 2)) + DCT = {} + for j=1, STR:byte(i-1) do + i = i + 3 + DCT[j] = {L(i - 2), R(i - 2)} + QUAT[j] = STR:byte(i-1) + end + i = len +end + +function C4() local TREE, TREEpos, TREElevel, TREEpath, class, index, HAFF = {[0] = -1}, 0, 0, "", L(i), R(i), {} + i, AC_DC[class][index] = i + 1, {} + local function AddTree(VAL) + local function ADD(VALUE) + if TREElevel ~= VAL - 1 then + TREEpath = TREEpath..tostring(VALUE) + TREElevel = TREElevel + 1 + TREEpos = TREEpos * 2 + 1 + VALUE + TREE[TREEpos] = -1 + return AddTree(VAL) + else + TREE[TREEpos * 2 + 1 + VALUE] = 0 + AC_DC[class][index][TREEpath..tostring(VALUE)] = STR:byte(i) + i = i + 1 + end + end + if TREE[TREEpos * 2 + 1] == nil then ADD(0) + elseif TREE[TREEpos * 2 + 2] == nil then ADD(1) + else + TREElevel = TREElevel - 1 + TREEpath = TREEpath:sub(1, -2) + TREEpos = math.floor((TREEpos - 1) / 2) + return AddTree(VAL) + end + end + + for j=1, 16 do + HAFF[j], i = STR:byte(i), i + 1 + end + for j=1, 16 do + for k=1, HAFF[j] do + AddTree(j) + end + end + i = len +end + + +AC_DC = {[0] = {}, [1] = {}} +MF = {["DB"] = DB, ["C0"] = C0, ["C1"] = C0, ["C2"] = C0, ["C3"] = C0, ["C4"] = C4, ["DA"] = DA, ["FE"] = FE} +masDB = {{{}, {}, {}, {}, {}, {}, {}, {}}, {{}, {}, {}, {}, {}, {}, {}, {}}} +i = 3 + +file = io.open(args[1], "rb") +STR = file:read("*a") +file:close() +if getB(1) ~= "FF" or getB(2) ~= "D8" then + print("Error: incorrect contents of the file.") + os.exit() +end +while i < #STR - 1 do + idin = getB(i+1) + i = i + 2 + len = i + STR:byte(i) * 256 + STR:byte(i + 1) + i = i + 2 + (MF[idin] or Common)() +end \ No newline at end of file diff --git a/lib/ImageFormatModules/OCIF.lua b/lib/ImageFormatModules/OCIF.lua index 689559b9..8c5c9a24 100755 --- a/lib/ImageFormatModules/OCIF.lua +++ b/lib/ImageFormatModules/OCIF.lua @@ -8,7 +8,7 @@ local bit32 = require("bit32") local advancedLua = require("advancedLua") local unicode = require("unicode") local fs = require("filesystem") -local colorlib = require("colorlib") +local color = require("color") ------------------------------------------------------------------------------------------------------------ @@ -40,8 +40,8 @@ end encodingMethods.save[1] = function(file, picture) for i = 3, #picture, 4 do - writeByteArrayToFile(file, {colorlib.HEXtoRGB(picture[i])}) - writeByteArrayToFile(file, {colorlib.HEXtoRGB(picture[i + 1])}) + writeByteArrayToFile(file, {color.HEXToRGB(picture[i])}) + writeByteArrayToFile(file, {color.HEXToRGB(picture[i + 1])}) file:write(string.char(picture[i + 2])) writeByteArrayToFile(file, {string.byte(picture[i + 3], 1, 6)}) end @@ -49,8 +49,8 @@ end encodingMethods.load[1] = function(file, picture) for i = 1, image.getWidth(picture) * image.getHeight(picture) do - table.insert(picture, colorlib.RGBtoHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1)))) - table.insert(picture, colorlib.RGBtoHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1)))) + table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1)))) + table.insert(picture, color.RGBToHEX(string.byte(file:read(1)), string.byte(file:read(1)), string.byte(file:read(1)))) table.insert(picture, string.byte(file:read(1))) table.insert(picture, string.readUnicodeChar(file)) end @@ -77,13 +77,13 @@ encodingMethods.save[6] = function(file, picture) file:write(string.char(table.size(groupedPicture[alpha][symbol]))) for background in pairs(groupedPicture[alpha][symbol]) do - -- Writing 1 byte for background color value (compressed by colorlib) + -- Writing 1 byte for background color value (compressed by color) file:write(string.char(background)) -- Writing 1 byte for foregrounds array size file:write(string.char(table.size(groupedPicture[alpha][symbol][background]))) for foreground in pairs(groupedPicture[alpha][symbol][background]) do - -- Writing 1 byte for foreground color value (compressed by colorlib) + -- Writing 1 byte for foreground color value (compressed by color) file:write(string.char(foreground)) -- Writing 1 byte for y array size file:write(string.char(table.size(groupedPicture[alpha][symbol][background][foreground]))) @@ -119,11 +119,11 @@ encodingMethods.load[6] = function(file, picture) backgroundSize = string.byte(file:read(1)) for background = 1, backgroundSize do - currentBackground = colorlib.convert8BitTo24Bit(string.byte(file:read(1))) + currentBackground = color.to24Bit(string.byte(file:read(1))) foregroundSize = string.byte(file:read(1)) for foreground = 1, foregroundSize do - currentForeground = colorlib.convert8BitTo24Bit(string.byte(file:read(1))) + currentForeground = color.to24Bit(string.byte(file:read(1))) ySize = string.byte(file:read(1)) for y = 1, ySize do diff --git a/lib/MineOSCore.lua b/lib/MineOSCore.lua index 7deb41c3..922be6b0 100755 --- a/lib/MineOSCore.lua +++ b/lib/MineOSCore.lua @@ -177,6 +177,7 @@ function MineOSCore.loadStandartIcons() end function MineOSCore.init() + fs.makeDirectory(MineOSCore.paths.trash) MineOSCore.loadOSSettings() MineOSCore.localization = table.fromFile(MineOSCore.paths.localizationFiles .. _G.OSSettings.language .. ".lang") MineOSCore.loadStandartIcons() @@ -705,7 +706,6 @@ function MineOSCore.iconRightClick(icon, eventData) while fs.exists(newName) do newName, repeats = MineOSCore.paths.trash .. clearName .. string.rep("-copy", repeats) .. icon.format, repeats + 1 end - fs.rename(icon.path, newName) end computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuRename then diff --git a/lib/OpenComputersGL/Main.lua b/lib/OpenComputersGL/Main.lua index 08ea1251..e5f6eb21 100644 --- a/lib/OpenComputersGL/Main.lua +++ b/lib/OpenComputersGL/Main.lua @@ -1,7 +1,7 @@ -------------------------------------------------------- Libraries -------------------------------------------------------- -local colorlib = require("colorlib") +local color = require("color") local vector = require("vector") local buffer = require("doubleBuffering") local materials = require("OpenComputersGL/Materials") @@ -210,18 +210,18 @@ function OCGL.render() renderer.renderFilledTriangle({ vertex1, vertex2, vertex3 }, material.color) elseif OCGL.renderMode == OCGL.renderModes.flatShading then -- local finalColor = 0x0 - -- finalColor = colorlib.alphaBlend(material.color, 0x0, OCGL.triangles[triangleIndex][5]) + -- finalColor = color.blend(material.color, 0x0, OCGL.triangles[triangleIndex][5]) -- OCGL.triangles[triangleIndex][5] = nil -- renderer.renderFilledTriangle({ vertex1, vertex2, vertex3 }, finalColor) - local r, g, b = colorlib.HEXtoRGB(material.color) + local r, g, b = color.HEXToRGB(material.color) r, g, b = r * OCGL.triangles[triangleIndex][5], g * OCGL.triangles[triangleIndex][5], b * OCGL.triangles[triangleIndex][5] if r > 255 then r = 255 end if g > 255 then g = 255 end if b > 255 then b = 255 end OCGL.triangles[triangleIndex][5] = nil - renderer.renderFilledTriangle({ vertex1, vertex2, vertex3 }, colorlib.RGBtoHEX(r, g, b)) + renderer.renderFilledTriangle({ vertex1, vertex2, vertex3 }, color.RGBToHEX(r, g, b)) end elseif material.type == materials.types.textured then vertex1[4], vertex1[5] = OCGL.vertices[OCGL.triangles[triangleIndex][1]][4], OCGL.vertices[OCGL.triangles[triangleIndex][1]][5] diff --git a/lib/OpenComputersGL/Materials.lua b/lib/OpenComputersGL/Materials.lua index 6b90a003..9498be7f 100644 --- a/lib/OpenComputersGL/Materials.lua +++ b/lib/OpenComputersGL/Materials.lua @@ -1,5 +1,5 @@ - +local color = require("color") local materials = {} ------------------------------------------------------------------------------------------------------------------------ @@ -10,7 +10,6 @@ materials.types = { } function materials.newDebugTexture(width, height, h) - local colorlib = require("colorlib") local texture = {width = width, height = height} local bStep = 100 / height @@ -21,7 +20,7 @@ function materials.newDebugTexture(width, height, h) for y = 1, height do texture[y] = {} for x = 1, width do - texture[y][x] = blackSquare == true and 0x0 or colorlib.HSBtoHEX(h, s, b) + texture[y][x] = blackSquare == true and 0x0 or color.HSBToHEX(h, s, b) blackSquare = not blackSquare b = b + bStep end diff --git a/lib/color.lua b/lib/color.lua new file mode 100755 index 00000000..282bf023 --- /dev/null +++ b/lib/color.lua @@ -0,0 +1,133 @@ + +local bit32 = require("bit32") +local color = {} + +----------------------------------------------------------------------------------------------------------------------- + +local function isNan(x) + return x ~= x +end + +function color.HEXToRGB(color) + return bit32.rshift(color, 16), bit32.band(bit32.rshift(color, 8), 0xFF), bit32.band(color, 0xFF) +end + +function color.RGBToHEX(r, g, b) + return bit32.lshift(r, 16) + bit32.lshift(g, 8) + b +end + +function color.RGBToHSB(rr, gg, bb) + local max = math.max(rr, math.max(gg, bb)) + local min = math.min(rr, math.min(gg, bb)) + local delta = max - min + + local h = 0 + if ( max == rr and gg >= bb) then h = 60*(gg-bb)/delta end + if ( max == rr and gg <= bb ) then h = 60*(gg-bb)/delta + 360 end + if ( max == gg ) then h = 60*(bb-rr)/delta + 120 end + if ( max == bb ) then h = 60*(rr-gg)/delta + 240 end + + local s = 0 + if ( max ~= 0 ) then s = 1 - (min / max) end + + local b = max * 100 / 255 + + if isNan(h) then h = 0 end + + return h, s * 100, b +end + +function color.HSBToRGB(h, s, v) + if h > 359 then h = 0 end + local rr, gg, bb = 0, 0, 0 + local const = 255 + + s = s/100 + v = v/100 + + local i = math.floor(h/60) + local f = h/60 - i + + local p = v*(1-s) + local q = v*(1-s*f) + local t = v*(1-(1-f)*s) + + if ( i == 0 ) then rr, gg, bb = v, t, p end + if ( i == 1 ) then rr, gg, bb = q, v, p end + if ( i == 2 ) then rr, gg, bb = p, v, t end + if ( i == 3 ) then rr, gg, bb = p, q, v end + if ( i == 4 ) then rr, gg, bb = t, p, v end + if ( i == 5 ) then rr, gg, bb = v, p, q end + + return math.floor(rr * const), math.floor(gg * const), math.floor(bb * const) +end + +function color.HEXToHSB(color) + local rr, gg, bb = color.HEXToRGB(color) + local h, s, b = color.RGBToHSB( rr, gg, bb ) + + return h, s, b +end + +function color.HSBToHEX(h, s, b) + local rr, gg, bb = color.HSBToRGB(h, s, b) + local color = color.RGBToHEX(rr, gg, bb) + + return color +end + +function color.blend(firstColor, secondColor, secondColorTransparency) + local invertedTransparency, firstColorR, firstColorG, firstColorB = 1 - secondColorTransparency, color.HEXToRGB(firstColor) + local secondColorR, secondColorG, secondColorB = color.HEXToRGB(secondColor) + + return color.RGBToHEX( + secondColorR * invertedTransparency + firstColorR * secondColorTransparency, + secondColorG * invertedTransparency + firstColorG * secondColorTransparency, + secondColorB * invertedTransparency + firstColorB * secondColorTransparency + ) +end + +function color.average(colors) + local sColors, averageRed, averageGreen, averageBlue, r, g, b = #colors, 0, 0, 0 + + for i = 1, sColors do + r, g, b = color.HEXToRGB(colors[i]) + averageRed, averageGreen, averageBlue = averageRed + r, averageGreen + g, averageBlue + b + end + + return color.RGBToHEX(math.floor(averageRed / sColors), math.floor(averageGreen / sColors), math.floor(averageBlue / sColors)) +end + +----------------------------------------------------------------------------------------------------------------------- + +local openComputersPalette = { 0x000000, 0x000040, 0x000080, 0x0000BF, 0x0000FF, 0x002400, 0x002440, 0x002480, 0x0024BF, 0x0024FF, 0x004900, 0x004940, 0x004980, 0x0049BF, 0x0049FF, 0x006D00, 0x006D40, 0x006D80, 0x006DBF, 0x006DFF, 0x009200, 0x009240, 0x009280, 0x0092BF, 0x0092FF, 0x00B600, 0x00B640, 0x00B680, 0x00B6BF, 0x00B6FF, 0x00DB00, 0x00DB40, 0x00DB80, 0x00DBBF, 0x00DBFF, 0x00FF00, 0x00FF40, 0x00FF80, 0x00FFBF, 0x00FFFF, 0x0F0F0F, 0x1E1E1E, 0x2D2D2D, 0x330000, 0x330040, 0x330080, 0x3300BF, 0x3300FF, 0x332400, 0x332440, 0x332480, 0x3324BF, 0x3324FF, 0x334900, 0x334940, 0x334980, 0x3349BF, 0x3349FF, 0x336D00, 0x336D40, 0x336D80, 0x336DBF, 0x336DFF, 0x339200, 0x339240, 0x339280, 0x3392BF, 0x3392FF, 0x33B600, 0x33B640, 0x33B680, 0x33B6BF, 0x33B6FF, 0x33DB00, 0x33DB40, 0x33DB80, 0x33DBBF, 0x33DBFF, 0x33FF00, 0x33FF40, 0x33FF80, 0x33FFBF, 0x33FFFF, 0x3C3C3C, 0x4B4B4B, 0x5A5A5A, 0x660000, 0x660040, 0x660080, 0x6600BF, 0x6600FF, 0x662400, 0x662440, 0x662480, 0x6624BF, 0x6624FF, 0x664900, 0x664940, 0x664980, 0x6649BF, 0x6649FF, 0x666D00, 0x666D40, 0x666D80, 0x666DBF, 0x666DFF, 0x669200, 0x669240, 0x669280, 0x6692BF, 0x6692FF, 0x66B600, 0x66B640, 0x66B680, 0x66B6BF, 0x66B6FF, 0x66DB00, 0x66DB40, 0x66DB80, 0x66DBBF, 0x66DBFF, 0x66FF00, 0x66FF40, 0x66FF80, 0x66FFBF, 0x66FFFF, 0x696969, 0x787878, 0x878787, 0x969696, 0x990000, 0x990040, 0x990080, 0x9900BF, 0x9900FF, 0x992400, 0x992440, 0x992480, 0x9924BF, 0x9924FF, 0x994900, 0x994940, 0x994980, 0x9949BF, 0x9949FF, 0x996D00, 0x996D40, 0x996D80, 0x996DBF, 0x996DFF, 0x999200, 0x999240, 0x999280, 0x9992BF, 0x9992FF, 0x99B600, 0x99B640, 0x99B680, 0x99B6BF, 0x99B6FF, 0x99DB00, 0x99DB40, 0x99DB80, 0x99DBBF, 0x99DBFF, 0x99FF00, 0x99FF40, 0x99FF80, 0x99FFBF, 0x99FFFF, 0xA5A5A5, 0xB4B4B4, 0xC3C3C3, 0xCC0000, 0xCC0040, 0xCC0080, 0xCC00BF, 0xCC00FF, 0xCC2400, 0xCC2440, 0xCC2480, 0xCC24BF, 0xCC24FF, 0xCC4900, 0xCC4940, 0xCC4980, 0xCC49BF, 0xCC49FF, 0xCC6D00, 0xCC6D40, 0xCC6D80, 0xCC6DBF, 0xCC6DFF, 0xCC9200, 0xCC9240, 0xCC9280, 0xCC92BF, 0xCC92FF, 0xCCB600, 0xCCB640, 0xCCB680, 0xCCB6BF, 0xCCB6FF, 0xCCDB00, 0xCCDB40, 0xCCDB80, 0xCCDBBF, 0xCCDBFF, 0xCCFF00, 0xCCFF40, 0xCCFF80, 0xCCFFBF, 0xCCFFFF, 0xD2D2D2, 0xE1E1E1, 0xF0F0F0, 0xFF0000, 0xFF0040, 0xFF0080, 0xFF00BF, 0xFF00FF, 0xFF2400, 0xFF2440, 0xFF2480, 0xFF24BF, 0xFF24FF, 0xFF4900, 0xFF4940, 0xFF4980, 0xFF49BF, 0xFF49FF, 0xFF6D00, 0xFF6D40, 0xFF6D80, 0xFF6DBF, 0xFF6DFF, 0xFF9200, 0xFF9240, 0xFF9280, 0xFF92BF, 0xFF92FF, 0xFFB600, 0xFFB640, 0xFFB680, 0xFFB6BF, 0xFFB6FF, 0xFFDB00, 0xFFDB40, 0xFFDB80, 0xFFDBBF, 0xFFDBFF, 0xFFFF00, 0xFFFF40, 0xFFFF80, 0xFFFFBF, 0xFFFFFF } + +function color.to8Bit(color24Bit) + local closestDelta, r, g, b, closestIndex, delta, openComputersPaletteR, openComputersPaletteG, openComputersPaletteB = math.huge, color.HEXToRGB(color24Bit) + + for index = 1, #openComputersPalette do + if color24Bit == openComputersPalette[index] then + return index - 1 + else + openComputersPaletteR, openComputersPaletteG, openComputersPaletteB = color.HEXToRGB(openComputersPalette[index]) + delta = (openComputersPaletteR - r) ^ 2 + (openComputersPaletteG - g) ^ 2 + (openComputersPaletteB - b) ^ 2 + + if delta < closestDelta then + closestDelta, closestIndex = delta, index + end + end + end + + return closestIndex - 1 +end + +function color.to24Bit(color8Bit) + return openComputersPalette[color8Bit + 1] +end + +----------------------------------------------------------------------------------------------------------------------- + +return color + + + diff --git a/lib/doubleBuffering.lua b/lib/doubleBuffering.lua index 0104c1e0..32c62017 100755 --- a/lib/doubleBuffering.lua +++ b/lib/doubleBuffering.lua @@ -3,7 +3,7 @@ local component = require("component") local unicode = require("unicode") -local colorlib = require("colorlib") +local color = require("color") local image = require("image") ------------------------------------------------- Constants ------------------------------------------------- @@ -126,8 +126,8 @@ function buffer.square(x, y, width, height, background, foreground, symbol, tran if i >= buffer.drawLimit.x and j >= buffer.drawLimit.y and i <= buffer.drawLimit.x2 and j <= buffer.drawLimit.y2 then indexPlus1 = index + 1 if transparency then - buffer.screen.new[index] = colorlib.alphaBlend(buffer.screen.new[index], background, transparency) - buffer.screen.new[indexPlus1] = colorlib.alphaBlend(buffer.screen.new[indexPlus1], background, transparency) + buffer.screen.new[index] = color.blend(buffer.screen.new[index], background, transparency) + buffer.screen.new[indexPlus1] = color.blend(buffer.screen.new[indexPlus1], background, transparency) else buffer.screen.new[index] = background buffer.screen.new[indexPlus1] = foreground @@ -222,7 +222,7 @@ function buffer.line(x1, y1, x2, y2, background, foreground, symbol) end -- Отрисовка текста, подстраивающегося под текущий фон -function buffer.text(x, y, color, text, transparency) +function buffer.text(x, y, textColor, text, transparency) if transparency then if transparency == 0 then transparency = nil @@ -234,7 +234,7 @@ function buffer.text(x, y, color, text, transparency) local index, sText = buffer.getBufferIndexByCoordinates(x, y), unicode.len(text) for i = 1, sText do if x >= buffer.drawLimit.x and y >= buffer.drawLimit.y and x <= buffer.drawLimit.x2 and y <= buffer.drawLimit.y2 then - buffer.screen.new[index + 1] = not transparency and color or colorlib.alphaBlend(buffer.screen.new[index], color, transparency) + buffer.screen.new[index + 1] = not transparency and textColor or color.blend(buffer.screen.new[index], textColor, transparency) buffer.screen.new[index + 2] = unicode.sub(text, i, i) end index = index + 3 @@ -257,7 +257,7 @@ function buffer.image(x, y, picture) buffer.screen.new[bufferIndex + 1] = picture[imageIndex + 1] buffer.screen.new[bufferIndex + 2] = picture[imageIndexPlus3] elseif picture[imageIndexPlus2] > 0x00 and picture[imageIndexPlus2] < 0xFF then - buffer.screen.new[bufferIndex] = colorlib.alphaBlend(buffer.screen.new[bufferIndex], picture[imageIndex], picture[imageIndexPlus2]) + buffer.screen.new[bufferIndex] = color.blend(buffer.screen.new[bufferIndex], picture[imageIndex], picture[imageIndexPlus2]) buffer.screen.new[bufferIndex + 1] = picture[imageIndex + 1] buffer.screen.new[bufferIndex + 2] = picture[imageIndexPlus3] elseif picture[imageIndexPlus2] == 0xFF and picture[imageIndexPlus3] ~= " " then diff --git a/lib/image.lua b/lib/image.lua index d9daa3e7..52714ff6 100755 --- a/lib/image.lua +++ b/lib/image.lua @@ -1,7 +1,7 @@ -------------------------------------------------- Libraries -------------------------------------------------- -local colorlib = require("colorlib") +local color = require("color") local unicode = require("unicode") local gpu = require("component").gpu @@ -32,7 +32,7 @@ function image.group(picture, compressColors) iPlus2, iPlus3 = i + 2, i + 3 if compressColors then - background, foreground = colorlib.convert24BitTo8Bit(picture[i]), colorlib.convert24BitTo8Bit(picture[i + 1]) + background, foreground = color.to8Bit(picture[i]), color.to8Bit(picture[i + 1]) compressionYield(i) else background, foreground = picture[i], picture[i + 1] @@ -88,7 +88,7 @@ function image.draw(x, y, picture) currentBackground = gpuGetBackground gpu.setBackground(currentBackground) else - currentBackground = colorlib.alphaBlend(gpuGetBackground, background, alpha / 0xFF) + currentBackground = color.blend(gpuGetBackground, background, alpha / 0xFF) gpu.setBackground(currentBackground) end end @@ -189,8 +189,8 @@ function image.toString(picture) } for i = 3, #picture, 4 do - table.insert(charArray, string.format("%02X", colorlib.convert24BitTo8Bit(picture[i]))) - table.insert(charArray, string.format("%02X", colorlib.convert24BitTo8Bit(picture[i + 1]))) + table.insert(charArray, string.format("%02X", color.to8Bit(picture[i]))) + table.insert(charArray, string.format("%02X", color.to8Bit(picture[i + 1]))) table.insert(charArray, string.format("%02X", picture[i + 2])) table.insert(charArray, picture[i + 3]) @@ -207,20 +207,8 @@ function image.fromString(pictureString) } for i = 5, unicode.len(pictureString), 7 do - if type(colorlib.convert8BitTo24Bit(tonumber("0x" .. unicode.sub(pictureString, i, i + 1)))) ~= "number" then - print(unicode.sub(pictureString, i, i + 1)) - end - - if type(colorlib.convert8BitTo24Bit(tonumber("0x" .. unicode.sub(pictureString, i + 2, i + 3)))) ~= "number" then - print(unicode.sub(pictureString, i + 2, i + 3)) - end - - if type(tonumber("0x" .. unicode.sub(pictureString, i + 4, i + 5))) ~= "number" then - print("0x" .. unicode.sub(pictureString, i + 4, i + 5)) - end - - table.insert(picture, colorlib.convert8BitTo24Bit(tonumber("0x" .. unicode.sub(pictureString, i, i + 1)))) - table.insert(picture, colorlib.convert8BitTo24Bit(tonumber("0x" .. unicode.sub(pictureString, i + 2, i + 3)))) + table.insert(picture, color.to24Bit(tonumber("0x" .. unicode.sub(pictureString, i, i + 1)))) + table.insert(picture, color.to24Bit(tonumber("0x" .. unicode.sub(pictureString, i + 2, i + 3)))) table.insert(picture, tonumber("0x" .. unicode.sub(pictureString, i + 4, i + 5))) table.insert(picture, unicode.sub(pictureString, i + 6, i + 6)) end diff --git a/lib/palette.lua b/lib/palette.lua index fb3f6e71..74836788 100755 --- a/lib/palette.lua +++ b/lib/palette.lua @@ -4,7 +4,7 @@ local advancedLua = require("advancedLua") local component = require("component") local fs = require("filesystem") -local colorlib = require("colorlib") +local color = require("color") local image = require("image") local buffer = require("doubleBuffering") local GUI = require("GUI") @@ -23,20 +23,20 @@ local inputs local function switchColorFromHex(hex) currentColor = {hsb = {}, rgb = {}, hex = hex} - currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue = colorlib.HEXtoRGB(hex) - currentColor.hsb.hue, currentColor.hsb.saturation, currentColor.hsb.brightness = colorlib.RGBtoHSB(currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue) + currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue = color.HEXToRGB(hex) + currentColor.hsb.hue, currentColor.hsb.saturation, currentColor.hsb.brightness = color.RGBToHSB(currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue) end local function switchColorFromHsb(hue, saturation, brightness) currentColor = {hsb = {hue = hue, saturation = saturation, brightness = brightness}, rgb = {}, hex = nil} - currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue = colorlib.HSBtoRGB(hue, saturation, brightness) - currentColor.hex = colorlib.RGBtoHEX(currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue) + currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue = color.HSBToRGB(hue, saturation, brightness) + currentColor.hex = color.RGBToHEX(currentColor.rgb.red, currentColor.rgb.green, currentColor.rgb.blue) end local function switchColorFromRgb(red, green, blue) currentColor = {hsb = {}, rgb = {red = red, green = green, blue = blue}, hex = nil} - currentColor.hsb.hue, currentColor.hsb.saturation, currentColor.hsb.brightness = colorlib.RGBtoHSB(red, green, blue) - currentColor.hex = colorlib.RGBtoHEX(red, green, blue) + currentColor.hsb.hue, currentColor.hsb.saturation, currentColor.hsb.brightness = color.RGBToHSB(red, green, blue) + currentColor.hex = color.RGBToHEX(red, green, blue) end -------------------------------------------------------------------------------------------------------------- @@ -76,8 +76,8 @@ local function refreshBigRainbow(width, height) local saturationStep, brightnessStep, saturation, brightness = 100 / width, 100 / (height * 2), 0, 100 for j = 1, height do for i = 1, width do - local background = colorlib.HSBtoHEX(currentColor.hsb.hue, saturation, brightness) - local foreground = colorlib.HSBtoHEX(currentColor.hsb.hue, saturation, brightness - brightnessStep) + local background = color.HSBToHEX(currentColor.hsb.hue, saturation, brightness) + local foreground = color.HSBToHEX(currentColor.hsb.hue, saturation, brightness - brightnessStep) image.set(bigRainbow.image, i, j, background, foreground, 0x0, "▄") saturation = saturation + saturationStep end @@ -89,8 +89,8 @@ local function refreshMiniRainbow(width, height) local hueStep, hue = 360 / (height * 2), 0 for j = 1, height do for i = 1, width do - local background = colorlib.HSBtoHEX(hue, 100, 100) - local foreground = colorlib.HSBtoHEX(hue + hueStep, 100, 100) + local background = color.HSBToHEX(hue, 100, 100) + local foreground = color.HSBToHEX(hue + hueStep, 100, 100) image.set(miniRainbow.image, i, j, background, foreground, 0x0, "▄") end hue = hue + hueStep + hueStep @@ -275,7 +275,10 @@ function palette.show(x, y, startColor) drawAll() window.drawShadow = false - return window:handleEvents() + local selectedColor = window:handleEvents() + window = nil + + return selectedColor end -- Поддержим олдфагов! diff --git a/lib/rayEngine.lua b/lib/rayEngine.lua index d0cddb54..df472cdf 100755 --- a/lib/rayEngine.lua +++ b/lib/rayEngine.lua @@ -2,7 +2,7 @@ local component = require("component") local computer = require("computer") local advancedLua = require("advancedLua") -local colorlib = require("colorlib") +local color = require("color") local image = require("image") local buffer = require("doubleBuffering") local GUI = require("GUI") @@ -85,13 +85,13 @@ local function getTileColor(basecolor, distance) local limitedDistance = math.floor(distance * rayEngine.properties.shadingCascades / rayEngine.properties.shadingDistance) local transparency = rayEngine.currentShadingTransparencyMapValue - limitedDistance / rayEngine.properties.shadingCascades transparency = (transparency >= rayEngine.properties.shadingTransparencyMap[1] and transparency <= 1) and transparency or rayEngine.properties.shadingTransparencyMap[1] - return colorlib.alphaBlend(basecolor, 0x000000, transparency) + return color.blend(basecolor, 0x000000, transparency) end function rayEngine.refreshTimeDependentColors() rayEngine.world.colors.sky.current = getSkyColorByTime() rayEngine.currentShadingTransparencyMapValue = getBrightnessByTime() - rayEngine.world.colors.groundByTime = colorlib.alphaBlend(rayEngine.world.colors.ground, 0x000000, rayEngine.currentShadingTransparencyMapValue) + rayEngine.world.colors.groundByTime = color.blend(rayEngine.world.colors.ground, 0x000000, rayEngine.currentShadingTransparencyMapValue) end local function doDayNightCycle()