[erlang-questions] What's the best way of producing bitmaps/pixelmaps through Erlang.

Steve Davis steven.charles.davis@REDACTED
Sun May 8 04:04:11 CEST 2011


More concretely as an example, a TGA format binary could be created as
simply as this:

encode(#image{id = undefined}) ->
	encode(#image{id = <<>>});
encode(#image{id = ID, width = W, height = H, pixel_depth = BPP, rgba
= L}) ->
	Header = <<(byte_size(ID)), 0, 2, 0:40, 0:16, 0:16, W:16/little, H:16/
little, BPP, 0:2, 2:2, 0:4, ID/binary>>,
	Data = encode(L, <<>>),
	Trailer = <<0:64, "TRUEVISION-XFILE.", 0>>,
	<<Header/binary, Data/binary, Trailer/binary>>.

encode([{R, G, B, A}|T], Bin) ->
	encode(T, <<Bin/binary, B, G, R, A>>);
encode([], Bin) ->
	Bin.



More information about the erlang-questions mailing list