-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
I've noticed that when working on images, I get those errors quite alot, it might be because the way we handle things are not optimal.
GC Warning: Repeated allocation of very large block (appr. size 1052672):
May lead to memory leak and poor performance
GC Warning: Repeated allocation of very large block (appr. size 409600):
May lead to memory leak and poor performance
GC Warning: Repeated allocation of very large block (appr. size 503808):
May lead to memory leak and poor performance
GC Warning: Repeated allocation of very large block (appr. size 692224):
May lead to memory leak and poor performance
Any clue if the below can be done better?
temp = IO::Memory.new(image_file)
canvas = StumpyPNG.read(temp)
temp.close
(0...canvas.height).each do |y| # make it darker
(0...canvas.width).each do |x|
curr = canvas[x, y]
canvas[x, y] = StumpyPNG::RGBA.from_rgb_n(
curr.r * 0.549,
curr.g * 0.549,
curr.b * 0.549,
16
)
end
end
alert = StumpyPNG.read("assets/alert.png")
alert_y = Math.max(0, canvas.height * 0.365 - alert.height // 2).to_i
alert_x = (canvas.width - alert.width) // 2.to_i
alert_offset = (Math.min(canvas.width, alert.width) - alert.width) // 2.to_i
(0...Math.min(canvas.height, alert.height)).each do |y| # paste in alert
(alert_offset...alert.width - alert_offset).each do |x|
canvas[alert_x + x, alert_y + y] = alert[x, y]
end
end
font = PCFParser::Font.from_file("assets/font.pcf")
canvas.text(
alert_x + (alert.width - 8 * alert_text.size) // 2,
alert_y + alert.height // 3 + 4,
alert_text,
font
) # print alert text
temp = IO::Memory.new
StumpyPNG.write(canvas, temp, color_type: :rgb)
data = temp.to_slice
temp.close
dataMetadata
Metadata
Assignees
Labels
No labels