8000 Document 32-bit color · Issue #1 · justgook/elm-image · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
This repository was archived by the owner on Oct 17, 2023. It is now read-only.
Document 32-bit color #1
Closed
Closed
@folkertdev

Description

@folkertdev

Image creation functions take a List Int, but it is unclear what the list represents. Forpngs it turns out to mean 32-bit color (most of the time). For bmp it's still unclear to me.

In practice, it is likely that users have a Color type, for instance the one from avh4/elm-color. In that case, this function does the color encoding:

import Bitwise

colorToInt32 : Color -> Int
colorToInt32 color =
    let
        record =
            Color.toRgba color

        byte1 =
            (record.alpha * 255)
                |> round

        byte2 =
            (record.blue * 255)
                |> round
                |> Bitwise.shiftLeftBy 8

        byte3 =
            (record.green * 255)
                |> round
                |> Bitwise.shiftLeftBy 16

        byte4 =
            (record.red * 255)
                |> round
                |> Bitwise.shiftLeftBy 24
    in
    Bitwise.or byte1 byte2
        |> Bitwise.or byte3
        |> Bitwise.or byte4

It might be an idea to add some helpers, e.g.

color32Bit : Int -> Int -> Int -> Int -> Int 
color16Bit : ... 
< 4B25 div class="CommentLoading-module__CommentLoadingContent--nb4e3">

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0