12345678910111213141516171819202122232425(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Psnr.mli *)letmse(a:Rgba_image.t)(b:Rgba_image.t):float=ifa.width<>b.width||a.height<>b.heighttheninvalid_arg"Psnr.mse: not the same size";letsum=ref0infori=0to(a.width*a.height)-1doforc=0to2doletd=a.rgba.{(4*i)+c}-b.rgba.{(4*i)+c}insum:=!sum+(d*d)donedone;float_of_int!sum/.float_of_int(3*a.width*a.height)letof_mse(e:float):float=ife=0.theninfinityelse10.*.log10(255.*.255./.e)letpsnr(a:Rgba_image.t)(b:Rgba_image.t):float=of_mse(mseab)