mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
bm_ao_render.rb: use pack() for binary PPM output
Replace printf("%c", val) with pack("CCC") for outputting raw
bytes. printf("%c") with values >= 128 produces invalid UTF-8
on CRuby, corrupting the PPM output. Also remove unused
arguments from the "255\n" format string.
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -292,9 +292,7 @@ class Scene
|
||||
r = rad.x / nsfs
|
||||
g = rad.y / nsfs
|
||||
b = rad.z / nsfs
|
||||
printf("%c", clamp(r))
|
||||
printf("%c", clamp(g))
|
||||
printf("%c", clamp(b))
|
||||
print([clamp(r), clamp(g), clamp(b)].pack("CCC"))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -303,7 +301,7 @@ end
|
||||
# File.open("ao.ppm", "w") do |fp|
|
||||
printf("P6\n")
|
||||
printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
|
||||
printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
|
||||
printf("255\n")
|
||||
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
|
||||
# Scene.new.render(256, 256, 2)
|
||||
# end
|
||||
|
||||
Reference in New Issue
Block a user