mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 01:02:34 +00:00
ICO parsing of 32-bit icons now possible, added default_icon image for missing app icon
This commit is contained in:
63
lib/ico.rb
63
lib/ico.rb
@@ -2,6 +2,8 @@ require "stringio"
|
||||
|
||||
class W3DHub
|
||||
class ICO
|
||||
PNG_IDENT = "\211PNG\r\n\032\n".force_encoding("ASCII-8BIT").freeze
|
||||
|
||||
IconDirectory = Struct.new(:reserved, :type, :image_count)
|
||||
|
||||
IconDirectoryEntity = Struct.new(
|
||||
@@ -50,6 +52,9 @@ class W3DHub
|
||||
read_u32,
|
||||
read_u32
|
||||
)
|
||||
|
||||
@images.last.width = 256 if @images.last.width == 0
|
||||
@images.last.height = 256 if @images.last.height == 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,26 +70,56 @@ class W3DHub
|
||||
@file.read(4).unpack1("V")
|
||||
end
|
||||
|
||||
def to_rgba32_blob(image)
|
||||
@file.pos = image.image_offset
|
||||
buf = @file.read(image.image_size)
|
||||
|
||||
File.write("TEMP.bmp", buf)
|
||||
end
|
||||
|
||||
def select_pngs
|
||||
@images.select do |image|
|
||||
@file.pos = image.image_offset
|
||||
buf = @file.read(8).unpack1("a*")
|
||||
buf == "\211PNG\r\n\032\n".force_encoding("ASCII-8BIT")
|
||||
image_png?(image)
|
||||
end
|
||||
end
|
||||
|
||||
def image_png?(image)
|
||||
@file.pos = image.image_offset
|
||||
buf = @file.read(8).unpack1("a*")
|
||||
|
||||
buf == PNG_IDENT
|
||||
end
|
||||
|
||||
def select_bmps
|
||||
@images.select do |image|
|
||||
image_bmp?(image)
|
||||
end
|
||||
end
|
||||
|
||||
def image_bmp?(image)
|
||||
!image_png?(image)
|
||||
end
|
||||
|
||||
def to_rgba32_blob(image)
|
||||
@file.pos = image.image_offset
|
||||
buf = StringIO.new(@file.read(image.image_size))
|
||||
|
||||
raise NotImplementedError "Cannot parse png based icons!" unless image_bmp?(image)
|
||||
|
||||
raise NotImplementedError "Cannot parse #{image.bit_depth}" unless image.bit_depth == 32
|
||||
|
||||
blob = "".force_encoding("ASCII-8BIT")
|
||||
|
||||
image.height.times do |y|
|
||||
image.width.times do |x|
|
||||
buf.pos = ((image.height - y) * image.width + x) * 4
|
||||
|
||||
blue = buf.read(1)
|
||||
green = buf.read(1)
|
||||
red = buf.read(1)
|
||||
alpha = buf.read(1)
|
||||
|
||||
blob << red
|
||||
blob << green
|
||||
blob << blue
|
||||
blob << alpha
|
||||
end
|
||||
end
|
||||
|
||||
Gosu::Image.from_blob(image.width, image.height, blob)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
data = W3DHub::ICO.new(file: "/home/cyberarm/Downloads/icos/ar.ico")
|
||||
pp data.select_pngs.size, data.images.size
|
||||
# data.to_rgba32_blob(data.images.first)
|
||||
|
||||
@@ -28,7 +28,7 @@ class W3DHub
|
||||
background task.application.color
|
||||
|
||||
flow(width: 0.70, height: 1.0) do
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{task.app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/default_icon.png"
|
||||
@application_image = image image_path, height: 1.0
|
||||
|
||||
stack(margin_left: 8, width: 0.75) do
|
||||
|
||||
@@ -40,7 +40,7 @@ class W3DHub
|
||||
image "#{GAME_ROOT_PATH}/media/ui_icons/return.png", width: 1.0, color: Gosu::Color::GRAY if Store.application_manager.updateable?(game.id, game.channels.first.id)
|
||||
image "#{GAME_ROOT_PATH}/media/ui_icons/import.png", width: 0.5, color: 0x88_ffffff unless Store.application_manager.installed?(game.id, game.channels.first.id)
|
||||
end
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{game.id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{game.id}.png" : "#{GAME_ROOT_PATH}/media/icons/default_icon.png"
|
||||
|
||||
image image_path, height: 48, color: Store.application_manager.installed?(game.id, game.channels.first.id) ? 0xff_ffffff : 0x88_ffffff
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class W3DHub
|
||||
@filters.each do |app_id, enabled|
|
||||
app = Store.applications.games.find { |a| a.id == app_id.to_s }
|
||||
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{app_id}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{app_id}.png" : "#{GAME_ROOT_PATH}/media/icons/default_icon.png"
|
||||
|
||||
image image_path, tip: "#{app.name}", height: 1.0,
|
||||
border_thickness_bottom: 1, border_color_bottom: 0x00_000000,
|
||||
@@ -361,7 +361,7 @@ class W3DHub
|
||||
end
|
||||
|
||||
def game_icon(server)
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/ui_icons/question.png"
|
||||
image_path = File.exist?("#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png") ? "#{GAME_ROOT_PATH}/media/icons/#{server.game.nil? ? 'ren' : server.game}.png" : "#{GAME_ROOT_PATH}/media/icons/default_icon.png"
|
||||
|
||||
if server.status.password
|
||||
@server_locked_icons[server.game] ||= Gosu.render(96, 96) do
|
||||
|
||||
BIN
media/icons/default_icon.png
Normal file
BIN
media/icons/default_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
Reference in New Issue
Block a user