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:
Yukihiro "Matz" Matsumoto
2026-04-01 23:53:28 +09:00
parent 909f5a070f
commit d212c7be6c
+2 -4
View File
@@ -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