Skip to content

Commit

Permalink
0.7
Browse files Browse the repository at this point in the history
tweak to windows icon editing to reduce some sizes and throw some warnings rather than crash
  • Loading branch information
ellraiser committed Dec 20, 2024
1 parent 9bee822 commit ba5f6b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 18 additions & 7 deletions libs/love-exedit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ love.exedit = {

updateIcon = function(exe_file, image_file, debug_mode)

print('love.exedit > modiying exe file')
print('love.exedit > modiying exe file', exe_file)

-- read the data from the file and clone it for later
local data = love.filesystem.read(exe_file)
Expand All @@ -32,6 +32,12 @@ love.exedit = {
if data:sub(1, 2) ~= 'PE' then
poffset = love.exedit._readUInt(data, 61, 2)
end
for d=1,256 do
local prod = data:sub(d, d+1)
if prod == 'PE' then print('found PE at ', d, d+1) end
end



-- get the PE data using the PE header
local pdata = data:sub(poffset+1, #data)
Expand Down Expand Up @@ -362,7 +368,7 @@ love.exedit = {
if gi_entry ~= nil then
local gi_size = math.abs(gi_entry.Width)
if gi_size == 0 then gi_size = 256 end -- only stores 0-255, cant have 0 so 256 is 0
print('love.exedit > GROUP_ICON_ENTRY', tostring(gi_size) .. 'px', gi_entry.Id, gi_entry.BytesInRes)
print('love.exedit > GROUP_ICON_ENTRY', tostring(gi_size) .. 'px', gi_entry.Id, gi_entry.BytesInRes, offset)
end
end
end
Expand All @@ -375,17 +381,22 @@ love.exedit = {
-- if we want to do this properly, we will not only need to update the GROUP_ICON
-- but ALL resource headers, and section headers because all positions will change
-- we'll also need to implement and recalc the checksum from the COFF

-- this will have to be done at some point cos there's not much room anymore
if lvl1_type == 'ICON' then
local newdata = ico_icon:_resize(ico_img, ico_sizes[l2])
local padding = lvl3_entry.DataSize - newdata:getSize()
local newdata = ico_icon:_resize(ico_img, ico_sizes[l2]):getString()
local padding = lvl3_entry.DataSize - #newdata
if #newdata > lvl3_entry.DataSize then
print('love.exedit > WARN: icon png bigger than available size', lvl3_entry.DataSize, #newdata)
end
if padding < 0 then
newdata = new_data:sub(1, lvl3_entry.DataSize)
newdata = newdata:sub(1, lvl3_entry.DataSize)
padding = 0
end
local prefix = new_data:sub(1, rsrc_data_index+lvl3_entry.Position-2)
local newimg = newdata:getString() .. string.rep('
local newimg = newdata .. string.rep('
local suffix = new_data:sub(rsrc_data_index+lvl3_entry.Position-2+lvl3_entry.DataSize+1, #new_data)
print('love.exedit > ICON_ENTRY', ico_sizes[l2], newdata:getSize(), lvl3_entry.DataSize, padding)
print('love.exedit > ICON_ENTRY', rsrc_data_index+lvl3_entry.Position-2, ico_sizes[l2], #newdata, lvl3_entry.DataSize, padding)
new_data = prefix .. newimg .. suffix
end

Expand Down
5 changes: 4 additions & 1 deletion libs/love-icon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ love.icon = {
@return {string} returns png encoded data
]]
_resize = function(self, img, size)
local png = love.graphics.newCanvas(size, size)
local png = love.graphics.newCanvas(size, size, {
dpiscale = 1
})
png:renderTo(function()
love.graphics.clear(0, 0, 0, 1)
love.graphics.draw(img, 0, 0, 0, size/img:getWidth(), size/img:getHeight())
end)
return png:newImageData():encode('png')
Expand Down

0 comments on commit ba5f6b0

Please sign in to comment.