Grayscale image: Difference between revisions
→The ATS dynamic file
Line 395:
implement {}
rgb24_to_gray8 rgb =
(* There is no need for floating point here, although equivalent
integer calculations are a bit longer to write out. *)
let
extern castfn
extern castfn
extern castfn u32_to_u8 : uint32 -<> uint8
val @(r, g, b) = rgb24_values rgb
val r
and g
and b
val Y = (
val
and Y0 = Y mod (i2u32 10000)
in
if Y0 < i2u32 5000 then
gray8_make
else if i2u32 5000 < Y0 then
gray8_make (succ (u32_to_u8 Y1))
else if Y0 mod (i2u32 2) = i2u32 0 then
gray8_make (u32_to_u8 Y1)
else
gray8_make (succ (u32_to_u8 Y1))
end
|