Bitmap: Difference between revisions

1,292 bytes added ,  1 year ago
Line 913:
pixmap_height pix =
case+ pix of _pixmap record => record.h
 
(*------------------------------------------------------------------*)
 
assume rgb24 = @(uint8, uint8, uint8)
 
implement {tk}
rgb24_make_uint_uint_uint (r, g, b) =
let
(* The prelude tends to miss implementations for type conversions
to uint8, so let us at least implement conversion from uint to
uint8. (I do not wish to use a general unsafe cast, because
that sort of code has caused me bugs before. C does not always
know how to do a type conversion correctly.) The ats2-xprelude
package has a much more complete set of implementations
(generated en masse by m4 macros), but for this task I am
avoiding such dependencies. *)
implement
g0uint2uint<uintknd,uint8knd> i =
let
extern castfn i2u8g0uint2uint_uint_uint8 : intuint -<> uint8
in
g0uint2uint_uint_uint8 i
end
in
rgb24_make_tuple @(g0u2u r, g0u2u g, g0u2u b)
end
 
implement {tk}
rgb24_make_int_int_int (r, g, b) =
let
(* See the comment in rgb24_make_uint_uint_uint. *)
implement
g0int2uint<intknd,uint8knd> i =
let
extern castfn g0int2uint_int_uint8 : int -<> uint8
in
g0int2uint_int_uint8 i
end
in
rgb24_make @(g0i2u r, g0i2u g, g0i2u b)
end
 
implement {}
rgb24_make_tuple tup = tup
 
implement {}
rgb24_values rgb = rgb
 
(*------------------------------------------------------------------*)
Line 941 ⟶ 988:
I have the data stored as "4.2.07.raw". *)
let
val failure_color = @rgb24_make (i2u8 0xFF, i2u8 0x00, i2u8 0x00)
extern castfn i2u8 : int -<> uint8
val failure_color = @(i2u8 0xFF, i2u8 0x00, i2u8 0x00)
 
val @(pfgc1 | pix1) = pixmap_make<rgb24> (i2sz 512, i2sz 512)
1,448

edits