mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 11:09:21 +01:00
Новый формат изображений OCIF4
Теперь идет группировка по пикселям, а не только лишь по цветам, символам и альфа-каналу. К примеру, при кодировании картинки 4х4 пикселя ранее использовалось 32 байта информации для данных о координатах, а теперь лишь 14. Магия?
This commit is contained in:
parent
088beaa4f3
commit
4c4ea4d92e
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -724,21 +724,19 @@ while true do
|
|||||||
new()
|
new()
|
||||||
|
|
||||||
elseif action == "Сохранить как" then
|
elseif action == "Сохранить как" then
|
||||||
local data = ecs.universalWindow("auto", "auto", 30, ecs.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x262626, "Сохранить как"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, "Путь"}, {"Selector", 0x262626, 0x880000, "OCIF3", "OCIF2", "OCIF1", "RAW"}, {"CenterText", 0x262626, "Рекомендуется использовать"}, {"CenterText", 0x262626, "метод кодирования OCIF3"}, {"EmptyLine"}, {"Button", {0x888888, 0xffffff, "OK"}, {0xaaaaaa, 0xffffff, "Отмена"}})
|
local data = ecs.universalWindow("auto", "auto", 30, ecs.windowColors.background, true, {"EmptyLine"}, {"CenterText", 0x262626, "Сохранить как"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, "Путь"}, {"Selector", 0x262626, 0x880000, "OCIF4", "OCIF1", "RAW"}, {"CenterText", 0x262626, "Рекомендуется использовать"}, {"CenterText", 0x262626, "метод кодирования OCIF4"}, {"EmptyLine"}, {"Button", {0x888888, 0xffffff, "OK"}, {0xaaaaaa, 0xffffff, "Отмена"}})
|
||||||
if data[3] == "OK" then
|
if data[3] == "OK" then
|
||||||
data[1] = data[1] or "Untitled"
|
data[1] = data[1] or "Untitled"
|
||||||
data[2] = data[2] or "OCIF3"
|
data[2] = data[2] or "OCIF4"
|
||||||
|
|
||||||
if data[2] == "RAW" then
|
if data[2] == "RAW" then
|
||||||
data[2] = 0
|
data[2] = 0
|
||||||
elseif data[2] == "OCIF1" then
|
elseif data[2] == "OCIF1" then
|
||||||
data[2] = 1
|
data[2] = 1
|
||||||
elseif data[2] == "OCIF1" then
|
elseif data[2] == "OCIF4" then
|
||||||
data[2] = 2
|
data[2] = 4
|
||||||
elseif data[2] == "OCIF1" then
|
|
||||||
data[2] = 3
|
|
||||||
else
|
else
|
||||||
data[2] = 3
|
data[2] = 4
|
||||||
end
|
end
|
||||||
|
|
||||||
local filename = data[1] .. ".pic"
|
local filename = data[1] .. ".pic"
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@ -437,12 +437,19 @@ local function saveOCIF2(file, picture, compressColors)
|
|||||||
file:write(convertBytesToString(extractBytesFromNumber(background, 3)))
|
file:write(convertBytesToString(extractBytesFromNumber(background, 3)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--Записываем координаты
|
--Перебираем координаты
|
||||||
for i = 1, #grouppedPucture[alpha][symbol][foreground][background], 2 do
|
for y in pairs(grouppedPucture[alpha][symbol][foreground][background]) do
|
||||||
|
--Записываем заголовок координат, размер массива y и само значение y
|
||||||
file:write(
|
file:write(
|
||||||
string.char(grouppedPucture[alpha][symbol][foreground][background][i]),
|
"Y",
|
||||||
string.char(grouppedPucture[alpha][symbol][foreground][background][i + 1])
|
string.char(getArraySize(grouppedPucture[alpha][symbol][foreground][background][y])),
|
||||||
|
string.char(y)
|
||||||
)
|
)
|
||||||
|
--Записываем ИКСЫЫЫ
|
||||||
|
--Ы
|
||||||
|
for i = 1, #grouppedPucture[alpha][symbol][foreground][background][y] do
|
||||||
|
file:write(string.char(grouppedPucture[alpha][symbol][foreground][background][y][i]))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -452,7 +459,7 @@ local function saveOCIF2(file, picture, compressColors)
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function loadOCIF2(file, decompressColors)
|
local function loadOCIF2(file, decompressColors, useOCIF4)
|
||||||
local picture = {}
|
local picture = {}
|
||||||
|
|
||||||
--Читаем размер изображения
|
--Читаем размер изображения
|
||||||
@ -461,7 +468,7 @@ local function loadOCIF2(file, decompressColors)
|
|||||||
picture.width = readedWidth
|
picture.width = readedWidth
|
||||||
picture.height = readedHeight
|
picture.height = readedHeight
|
||||||
|
|
||||||
local header, alpha, symbol, foreground, background, alphaSize, symbolSize, foregroundSize, backgroundSize = ""
|
local header, alpha, symbol, foreground, background, y, alphaSize, symbolSize, foregroundSize, backgroundSize, ySize = ""
|
||||||
while true do
|
while true do
|
||||||
header = file:read(1)
|
header = file:read(1)
|
||||||
if not header then break end
|
if not header then break end
|
||||||
@ -507,6 +514,8 @@ local function loadOCIF2(file, decompressColors)
|
|||||||
-- print("Размер массива координат: " .. backgroundSize)
|
-- print("Размер массива координат: " .. backgroundSize)
|
||||||
-- print("Цвет фона: " .. background)
|
-- print("Цвет фона: " .. background)
|
||||||
|
|
||||||
|
--Поддержка загрузки формата OCIF3
|
||||||
|
if not useOCIF4 then
|
||||||
--Читаем координаты
|
--Читаем координаты
|
||||||
for i = 1, backgroundSize, 2 do
|
for i = 1, backgroundSize, 2 do
|
||||||
local x = string.byte(file:read(1))
|
local x = string.byte(file:read(1))
|
||||||
@ -514,13 +523,32 @@ local function loadOCIF2(file, decompressColors)
|
|||||||
local index = convertCoordsToIndex(x, y, readedWidth)
|
local index = convertCoordsToIndex(x, y, readedWidth)
|
||||||
-- print("Координата: " .. x .. "x" .. y .. ", индекс: "..index)
|
-- print("Координата: " .. x .. "x" .. y .. ", индекс: "..index)
|
||||||
|
|
||||||
|
picture[index] = background
|
||||||
|
picture[index + 1] = foreground
|
||||||
|
picture[index + 2] = alpha
|
||||||
|
picture[index + 3] = symbol
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--Новый формат OCIF4
|
||||||
|
elseif header == "Y" and useOCIF4 then
|
||||||
|
ySize = string.byte(file:read(1))
|
||||||
|
y = string.byte(file:read(1))
|
||||||
|
-- print("Размер массива Y: " .. ySize)
|
||||||
|
-- print("Текущий Y: " .. y)
|
||||||
|
|
||||||
|
for i = 1, ySize do
|
||||||
|
local x = string.byte(file:read(1))
|
||||||
|
local index = convertCoordsToIndex(x, y, readedWidth)
|
||||||
|
-- print("Координата: " .. x .. "x" .. y .. ", индекс: "..index)
|
||||||
|
|
||||||
picture[index] = background
|
picture[index] = background
|
||||||
picture[index + 1] = foreground
|
picture[index + 1] = foreground
|
||||||
picture[index + 2] = alpha
|
picture[index + 2] = alpha
|
||||||
picture[index + 3] = symbol
|
picture[index + 3] = symbol
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error("Ошибка чтения формата OCIF: неизвестный тип заголовка (" .. header .. ")")
|
error("Error while reading OCIF format: unknown Header type (" .. header .. ")")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -637,9 +665,9 @@ function image.convertToGroupedImage(picture)
|
|||||||
optimizedPicture[alpha][symbol] = optimizedPicture[alpha][symbol] or {}
|
optimizedPicture[alpha][symbol] = optimizedPicture[alpha][symbol] or {}
|
||||||
optimizedPicture[alpha][symbol][foreground] = optimizedPicture[alpha][symbol][foreground] or {}
|
optimizedPicture[alpha][symbol][foreground] = optimizedPicture[alpha][symbol][foreground] or {}
|
||||||
optimizedPicture[alpha][symbol][foreground][background] = optimizedPicture[alpha][symbol][foreground][background] or {}
|
optimizedPicture[alpha][symbol][foreground][background] = optimizedPicture[alpha][symbol][foreground][background] or {}
|
||||||
|
optimizedPicture[alpha][symbol][foreground][background][yPos] = optimizedPicture[alpha][symbol][foreground][background][yPos] or {}
|
||||||
|
|
||||||
table.insert(optimizedPicture[alpha][symbol][foreground][background], xPos)
|
table.insert(optimizedPicture[alpha][symbol][foreground][background][yPos], xPos)
|
||||||
table.insert(optimizedPicture[alpha][symbol][foreground][background], yPos)
|
|
||||||
--Если xPos достигает width изображения, то сбросить на 1, иначе xPos++
|
--Если xPos достигает width изображения, то сбросить на 1, иначе xPos++
|
||||||
xPos = (xPos == picture.width) and 1 or xPos + 1
|
xPos = (xPos == picture.width) and 1 or xPos + 1
|
||||||
--Если xPos равняется 1, то yPos++, а если нет, то похуй
|
--Если xPos равняется 1, то yPos++, а если нет, то похуй
|
||||||
@ -939,7 +967,7 @@ end
|
|||||||
|
|
||||||
--Сохранить изображение любого поддерживаемого формата
|
--Сохранить изображение любого поддерживаемого формата
|
||||||
function image.save(path, picture, encodingMethod)
|
function image.save(path, picture, encodingMethod)
|
||||||
encodingMethod = encodingMethod or 3
|
encodingMethod = encodingMethod or 4
|
||||||
--Создать папку под файл, если ее нет
|
--Создать папку под файл, если ее нет
|
||||||
fs.makeDirectory(fs.path(path))
|
fs.makeDirectory(fs.path(path))
|
||||||
--Получаем формат указанного файла
|
--Получаем формат указанного файла
|
||||||
@ -962,6 +990,8 @@ function image.save(path, picture, encodingMethod)
|
|||||||
file:write(string.char(encodingMethod))
|
file:write(string.char(encodingMethod))
|
||||||
saveOCIF2(file, picture)
|
saveOCIF2(file, picture)
|
||||||
elseif encodingMethod == 3 or string.lower(encodingMethod) == "ocif3" then
|
elseif encodingMethod == 3 or string.lower(encodingMethod) == "ocif3" then
|
||||||
|
error("Encoding method 3 is deprecated and no longer supported. Use method 4 instead of it.")
|
||||||
|
elseif encodingMethod == 4 or string.lower(encodingMethod) == "ocif4" then
|
||||||
file:write(string.char(encodingMethod))
|
file:write(string.char(encodingMethod))
|
||||||
picture = convertImageColorsTo8Bit(picture)
|
picture = convertImageColorsTo8Bit(picture)
|
||||||
saveOCIF2(file, picture, true)
|
saveOCIF2(file, picture, true)
|
||||||
@ -999,15 +1029,17 @@ function image.load(path)
|
|||||||
return loadOCIF2(file)
|
return loadOCIF2(file)
|
||||||
elseif encodingMethod == 3 then
|
elseif encodingMethod == 3 then
|
||||||
return loadOCIF2(file, true)
|
return loadOCIF2(file, true)
|
||||||
|
elseif encodingMethod == 4 then
|
||||||
|
return loadOCIF2(file, true, true)
|
||||||
else
|
else
|
||||||
file:close()
|
file:close()
|
||||||
error("Unsupported encoding method.\n")
|
error("Unsupported encoding method: " .. encodingMethod .. "\n")
|
||||||
end
|
end
|
||||||
--Поддержка ПНГ-формата
|
--Поддержка ПНГ-формата
|
||||||
elseif fileFormat == constants.pngFileFormat then
|
elseif fileFormat == constants.pngFileFormat then
|
||||||
return image.loadPng(path)
|
return image.loadPng(path)
|
||||||
else
|
else
|
||||||
error("Unsupported file format.\n")
|
error("Unsupported file format: " .. fileFormat .. "\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1026,8 +1058,10 @@ function image.draw(x, y, picture)
|
|||||||
for background in pairs(picture[alpha][symbol][foreground]) do
|
for background in pairs(picture[alpha][symbol][foreground]) do
|
||||||
if gpu.getBackground ~= background then gpu.setBackground(background) end
|
if gpu.getBackground ~= background then gpu.setBackground(background) end
|
||||||
currentBackground = background
|
currentBackground = background
|
||||||
for i = 1, #picture[alpha][symbol][foreground][background], 2 do
|
|
||||||
xPos, yPos = x + picture[alpha][symbol][foreground][background][i], y + picture[alpha][symbol][foreground][background][i + 1]
|
for yArray in pairs(picture[alpha][symbol][foreground][background]) do
|
||||||
|
for xArray = 1, #picture[alpha][symbol][foreground][background][yArray] do
|
||||||
|
xPos, yPos = x + picture[alpha][symbol][foreground][background][yArray][xArray], y + yArray
|
||||||
|
|
||||||
--Если альфа имеется, но она не совсем прозрачна
|
--Если альфа имеется, но она не совсем прозрачна
|
||||||
if (alpha > 0x00 and alpha < 0xFF) or (alpha == 0xFF and symbol ~= " ")then
|
if (alpha > 0x00 and alpha < 0xFF) or (alpha == 0xFF and symbol ~= " ")then
|
||||||
@ -1051,38 +1085,35 @@ function image.draw(x, y, picture)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createSaveAndLoadFiles()
|
local function createSaveAndLoadFiles()
|
||||||
ecs.prepareToExit()
|
ecs.prepareToExit()
|
||||||
ecs.error("Создаю/загружаю изображение")
|
ecs.error("Создаю/загружаю изображение")
|
||||||
local cyka = image.load("MineOS/System/OS/Icons/Love.pic")
|
-- local cyka = image.load("MineOS/System/OS/Icons/Love.pic")
|
||||||
--local cyka = image.createImage(4, 4)
|
local cyka = image.createImage(4, 4)
|
||||||
ecs.error("Рисую загруженное изображение")
|
ecs.error("Рисую загруженное изображение")
|
||||||
image.draw(2, 2, cyka)
|
image.draw(2, 2, cyka)
|
||||||
ecs.error("Сохраняю его в 4 форматах")
|
ecs.error("Сохраняю его в 4 форматах")
|
||||||
image.save("0.pic", cyka, 0)
|
image.save("0.pic", cyka, 0)
|
||||||
image.save("1.pic", cyka, 1)
|
image.save("1.pic", cyka, 1)
|
||||||
image.save("2.pic", cyka, 2)
|
image.save("4.pic", cyka, 4)
|
||||||
image.save("3.pic", cyka, 3)
|
|
||||||
ecs.prepareToExit()
|
ecs.prepareToExit()
|
||||||
ecs.error("Загружаю все 4 формата и рисую их")
|
ecs.error("Загружаю все 4 формата и рисую их")
|
||||||
local cyka0 = image.load("0.pic")
|
local cyka0 = image.load("0.pic")
|
||||||
image.draw(2, 2, cyka0)
|
image.draw(2, 2, cyka0)
|
||||||
local cyka1 = image.load("1.pic")
|
local cyka1 = image.load("1.pic")
|
||||||
image.draw(10, 2, cyka1)
|
image.draw(10, 2, cyka1)
|
||||||
local cyka2 = image.load("2.pic")
|
local cyka4 = image.load("4.pic")
|
||||||
image.draw(18, 2, cyka2)
|
image.draw(34, 2, cyka4)
|
||||||
local cyka3 = image.load("3.pic")
|
|
||||||
image.draw(26, 2, cyka3)
|
|
||||||
ecs.error("Рисую все 3 формата")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------------------ Место для баловства ------------------------------------------------
|
------------------------------------------ Место для баловства ------------------------------------------------
|
||||||
|
|
||||||
-- ecs.prepareToExit()
|
-- ecs.prepareToExit()
|
||||||
|
|
||||||
-- local cyka = image.load("MineOS/Applications/Piano.app/Resources/Icon.pic")
|
-- local cyka = image.load("3.pic")
|
||||||
-- image.draw(2, 2, cyka)
|
-- image.draw(2, 2, cyka)
|
||||||
-- ecs.error(HEXtoSTRING(cyka[1], 6, true))
|
-- ecs.error(HEXtoSTRING(cyka[1], 6, true))
|
||||||
-- image.draw(8, 2, cyka)
|
-- image.draw(8, 2, cyka)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user