rgb: Srgb: Add method to convert to hex color code
diff --git a/src/commonMain/kotlin/dev/kdrag0n/colorkt/rgb/Srgb.kt b/src/commonMain/kotlin/dev/kdrag0n/colorkt/rgb/Srgb.kt
index 468b4c1..1b01aa4 100644
--- a/src/commonMain/kotlin/dev/kdrag0n/colorkt/rgb/Srgb.kt
+++ b/src/commonMain/kotlin/dev/kdrag0n/colorkt/rgb/Srgb.kt
@@ -38,16 +38,26 @@
)
/**
- * Convert, or quantize, this color to 8 bits per channel and pack it into a 32-bit integer.
- * This is equivalent to the common hex color codes (e.g. #FF00FF).
+ * Convert this color to an 8-bit packed RGB integer (32 bits total)
*
- * @return sRGB color packed into 32-bit integer
+ * This is equivalent to the integer value of hex color codes (e.g. #FA00FA).
+ *
+ * @return color as 32-bit integer in RGB8 format
*/
public fun toRgb8(): Int {
return (quantize8(r) shl 16) or (quantize8(g) shl 8) or quantize8(b)
}
/**
+ * Convert this color to an 8-bit hex color code (e.g. #FA00FA).
+ *
+ * @return color as RGB8 hex code
+ */
+ public fun toHex(): String {
+ return "#" + toRgb8().toString(16).padStart(6, padChar = '0')
+ }
+
+ /**
* Check whether this color is within the sRGB gamut.
* @return true if color is in gamut, false otherwise
*/