@@ -288,6 +288,17 @@ fun image2ppm out ({pixels, height, width}: image) =
288
288
before Array.app onPixel pixels
289
289
end
290
290
291
+ fun image2ppm6 out ({pixels, height, width}: image) =
292
+ let
293
+ fun onPixel (r,g,b) =
294
+ TextIO.output(out, String.implode (List.map Char.chr [r,g,b]))
295
+ in TextIO.output(out,
296
+ " P6\n " ^
297
+ Int.toString width ^ " " ^ Int.toString height ^ " \n " ^
298
+ " 255\n " )
299
+ before Array.app onPixel pixels
300
+ end
301
+
291
302
fun render objs width height cam : image =
292
303
let val pixels = ForkJoin.alloc (height*width)
293
304
fun pixel l =
@@ -296,7 +307,7 @@ fun render objs width height cam : image =
296
307
in Array.update (pixels,
297
308
l,
298
309
colour_to_pixel (trace_ray objs width height cam j i)) end
299
- val _ = ForkJoin.parfor 10000 (0 ,height*width) pixel
310
+ val _ = ForkJoin.parfor 256 (0 ,height*width) pixel
300
311
in {width = width,
301
312
height = height,
302
313
pixels = pixels
@@ -385,6 +396,7 @@ val irreg : scene =
385
396
val height = CommandLineArgs.parseInt " m" 200
386
397
val width = CommandLineArgs.parseInt " n" 200
387
398
val f = CommandLineArgs.parseString " f" " "
399
+ val dop6 = CommandLineArgs.parseFlag " ppm6"
388
400
val scene_name = CommandLineArgs.parseString " s" " rgbbox"
389
401
val scene = case scene_name of
390
402
" rgbbox" => rgbbox
@@ -404,10 +416,12 @@ val t1 = Time.now ()
404
416
405
417
val _ = print (" Rendering in " ^ Time.fmt 4 (Time.- (t1, t0)) ^ " s.\n " )
406
418
419
+ val writeImage = if dop6 then image2ppm6 else image2ppm
420
+
407
421
val _ = if f <> " " then
408
422
let val out = TextIO.openOut f
409
423
in print (" Writing image to " ^ f ^ " .\n " )
410
- before image2ppm out (render objs width height cam)
424
+ before writeImage out (render objs width height cam)
411
425
before TextIO.closeOut out
412
426
end
413
427
else print (" -f not passed, so not writing image to file.\n " )
0 commit comments