From ba5f6b019da27ee2203206f0cb3564eccf2a1920 Mon Sep 17 00:00:00 2001 From: ell <77150506+ellraiser@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:17:15 +0000 Subject: [PATCH] 0.7 tweak to windows icon editing to reduce some sizes and throw some warnings rather than crash --- libs/love-exedit.lua | 25 ++++++++++++++++++------- libs/love-icon.lua | 5 ++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libs/love-exedit.lua b/libs/love-exedit.lua index 4dbe06c..737b017 100644 --- a/libs/love-exedit.lua +++ b/libs/love-exedit.lua @@ -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) @@ -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) @@ -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 @@ -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('', padding) + local newimg = newdata .. string.rep('', padding) 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 diff --git a/libs/love-icon.lua b/libs/love-icon.lua index d2ee2df..38a89fa 100644 --- a/libs/love-icon.lua +++ b/libs/love-icon.lua @@ -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')