Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
Created January 20, 2015 21:18
Show Gist options
  • Save bryanhunter/a3a905ba890a21eb345f to your computer and use it in GitHub Desktop.
Save bryanhunter/a3a905ba890a21eb345f to your computer and use it in GitHub Desktop.

Revisions

  1. bryanhunter created this gist Jan 20, 2015.
    26 changes: 26 additions & 0 deletions bumper.exs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    defmodule Bumper do

    @doc ~S"""
    Reads a Bitmap (24-bit) and displays width, height, and the RGB of each pixel
    """
    def show(filename) do
    {:ok, bindata} = File.read(filename)
    << "BM",
    _::size(64),
    offset_to_pixels::size(32)-little,
    _::size(32),
    width::size(32)-little,
    height::size(32)-little,
    _::size(16),
    24::size(16)-little,
    _rest::binary>> = bindata

    <<_::size(offset_to_pixels)-bytes, pixels::binary>> = bindata
    IO.puts "Offset:#{offset_to_pixels} Width:#{width} Height:#{height}"

    for <<b::size(8), g::size(8), r::size(8) <- pixels >>, do: {r,g,b}
    end
    end

    Bumper.show("krgbw.bmp")
    |> IO.inspect