dmc

package module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2022 License: MIT Imports: 3 Imported by: 1

README

go-c2dmc

Go Reference go reportcard

A Go package for converting RGB and other color formats/colorspaces into DMC thread colors (DMC color name and floss number). Implemented as a wrapper for a handful of pieces of functionality from the go-colorful package with additional functionality to return DMC thread colors. Supports Go 1.13 onwards.

Why was go-c2dmc built?

When wanting to build a personal project that invloves DMC thread colors, I could only find one pre-written package for converting RGB values into DMC thread colors (and their corresponding floss numbers) or finding the closest match. However, the package I found was written in R and I wanted to build the project I had in mind in Go. I explored methods of using this newly-found R package and found some interesting solutions. One being a "proxy" of sorts between Go and R written in C. While that solution was cool nonetheless, it felt much too bloated for the usecase I was encountering, as I would only be needing to use the return value from one single function in one single R package and not calling between Go and R several different times. Another option I had was to learn R enough to use the package to do the calculations and print the result to a blank text file, which my Go program would subsequently read from. But again, that required learning R. Which, if I'm being honest, is soemthing I would like to tackle. But my main goal was to get better at Go, specifically. So, seeing as there were no existing Go packages, I decided I would build my own (for the first time!) and share it with other developers who may run into this niche problem.

What problem does go-c2dmc solve?

go-c2dmc is a go package that allows a developer calculate the closest (if not exact) match to DMC color threads. The ColorBank is populated with values matching DMC color threads (and their floss numbers) to RBG and Hexcode values already calculated by threadcolors. go-c2dmc can calculate the closest match from this list with any provided RGB, HSV, LAB, or Hexcode values by calculating the distance between the provided color and each color in the ColorBank in LAB colorspace using the go-colorful package.

For more information regarding the accuracy of these calculations specific to each colorspace, please refer to the go-colorful README

How do I use go-c2dmc?

Installing

To install go-c2dmc, simply run

$ go get github.com/syke99/go-c2dmc

Then you can import the package in any go file you'd like

import dmc "github.com/syke99/go-c2dmc"
Basic usage

Calculate the closest DMC thread color based on provided RGB values

// Initialize the ColorBank to have DMC colors to test against
cb := dmc.NewColorBank()

// Call cb.Rgb() and pass in RGB values
color, floss := cb.Rgb(245.0, 173.0, 173.0)

fmt.SprintF("DMC Color Name: %s, Floss number: %s", color, floss)

Running the above calculation will return:

DMC Color Name: Salmon, Floss number: 760

And then converting this RGB color into LAB and HSV colorspaces, as well as hexcode:

l, a, b := cb.RgbLab(245.0, 173.0, 173.0)
h, s, v := cb.RgbHsv(245.0, 173.0, 173.0)
hexcode := cb.RgbHex(245.0, 173.0, 173.0)

!!NOTE!!

Converting from Hexcodes to RGB/LAB/HSV colorspaces is currently unusable, but will be implemented in v2

Who?

This library was developed by Quinn Millican (@syke99)

License

This repo is under the MIT license, see LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hex added in v1.1.1

func Hex(d *cb.DmcColors, hex string) (string, string)

Hex Determine DMC color from Hex value

func Hsv added in v1.1.1

func Hsv(d *cb.DmcColors, h float64, s float64, v float64) (string, string)

Hsv Determine DMC color from HSV (Hue, Saturation, Value) values

func HsvHex added in v1.1.1

func HsvHex(d *cb.DmcColors, h float64, s float64, v float64) string

HsvHex Converting from Hsv to Hex

func HsvLab added in v1.1.1

func HsvLab(d *cb.DmcColors, h float64, s float64, v float64) (float64, float64, float64)

HsvLab Converting from Hsv to Lab

func HsvRgb added in v1.1.1

func HsvRgb(d *cb.DmcColors, h float64, s float64, v float64) (float64, float64, float64)

HsvRgb Converting from Hsv to Rgb

func Lab added in v1.1.1

func Lab(d *cb.DmcColors, l float64, a float64, b float64) (string, string)

Lab Determine DMC color from HSV (Hue, Saturation, Value) values

func LabHex added in v1.1.1

func LabHex(d *cb.DmcColors, l float64, a float64, b float64) string

LabHex Converting from Lab to Hex

func LabHsv added in v1.1.1

func LabHsv(d *cb.DmcColors, l float64, a float64, b float64) (float64, float64, float64)

LabHsv Converting from Lab to Hsv

func LabRgb added in v1.1.1

func LabRgb(d *cb.DmcColors, l float64, a float64, b float64) (float64, float64, float64)

LabRgb Converting from Lab to Rgb

func NewColorBank

func NewColorBank() *cb.DmcColors

func Rgb added in v1.1.1

func Rgb(d *cb.DmcColors, r float64, g float64, b float64) (string, string)

Rgb Determine DMC color from RBG (Red, Green, Blue) values

func RgbA added in v1.1.1

func RgbA(col color.Color) (float64, float64, float64)

RgbA Determine DMC color from RBG (Red, Green, Blue) values

func RgbHex added in v1.1.1

func RgbHex(d *cb.DmcColors, r float64, g float64, b float64) string

RgbHex Converting from Rgb to Hex

func RgbHsv added in v1.1.1

func RgbHsv(d *cb.DmcColors, r float64, g float64, b float64) (float64, float64, float64)

RgbHsv Converting from Rgb to Hsv

func RgbLab added in v1.1.1

func RgbLab(d *cb.DmcColors, r float64, g float64, b float64) (float64, float64, float64)

RgbLab Converting from Rgb to Lab

Types

This section is empty.

Directories

Path Synopsis
Package colorbank provides a bank of colors who's rbg values already correspond to DMC string color values These values are used in dmc.go to find the closest matching dmc color to the given rgb value
Package colorbank provides a bank of colors who's rbg values already correspond to DMC string color values These values are used in dmc.go to find the closest matching dmc color to the given rgb value
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL