Easily convert RS2 HSL to/from(approximate) RGB

Related tags

Colors RuneColor
Overview

RuneColor

Easily convert RS2 HSL to/from(approximate) RGB


The problem

We often need to approximate a 16-bit RS2 HSL color given an RGB.

Typically, people simply used a direct translation from RGB to HSL, with a function like:

fun rgbToRS2HSL(r: Int, g: Int, b: Int): Short {
	val hsb = Color.RGBtoHSB(r, g, b, null)
	val hue = hsb[0]
	val saturation = hsb[1]
	val brightness = hsb[2]
	val encodedHue = (hue * 63F).toInt() // to 6-bits
	val encodedSaturation = (saturation * 7F).toInt() // to 3-bits
	val encodedBrightness = (brightness * 127F).toInt() // to 7-bits
	return ((encodedHue shl 10) + (encodedSaturation shl 7) + encodedBrightness).toShort()
}

This will then produce a result, for example:

val redHSL = rgbToRS2HSL(255, 0, 0)
println(redHSL) // HSL 1023, which is RGB color #ff0000

The problem is, within the RuneScape world, such a color does not actually exist, making for strange visuals:

Strange red tint

The solution

RuneColor allows you to easily build and search an RS2 color palette for the closest match to an RGB color.

val palette = RS2CacheHSLColorPalette.load("cache")

val redHSL = palette.closest(255, 0, 0).first() // HSLColor(hsl=960)
println("${redHSL.hsl}(#${redHSL.rgb.toString(16)})") // 960(#ff0202)

Using the HSL color we calculated with RuneColor (960), you can see it looks great when applied in-game:

Proper red

Under the hood

Under the hood, by default RuneColor by default loads all game model's face colors to use as the search palette.

This color palette is mapped into RGB, and then sorted by CIEDE2000 to find the closest matching RS2 HSL colors for the given RGB color.

It's possible and often that you might want to use a limited color palette, which you can easily pass a ShortArray to create:

val palette = RS2HSLColorPalette(shortArray)

Or you can pass a vararg Int:

val palette = RS2HSLColorPalette(1, 2, 3, 4, 5, ...)
You might also like...
A tool to convert & query Apache Calcite data sources as GraphQL API's
A tool to convert & query Apache Calcite data sources as GraphQL API's

Apache Calcite - Distributed, Federated GraphQL API Apache Calcite - Distributed, Federated GraphQL API Goals Roadmap and Current Progress The Roa

Silky - Android application to convert videos from applications such as YouTube, Facebook, Twitter into audio (.mp3)

Silky Español (actualmente la app se encuentra en desarrollo ) Descripcion Aplic

Screenshot Composables and convert to Bitmap on user action or periodically
Screenshot Composables and convert to Bitmap on user action or periodically

Compose ScreenshotBox Screenshot Composables and convert to Bitmap on user action or periodically. Single Shot Periodic Gradle Setup To get a Git proj

A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page
A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page

Compose Compiler Reports to HTML Generator A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page. Made with

A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically
A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically

A simple gradle plugin that lets you create a download asset from zeplin and convert them to vector drawables automatically elephant project using 100% Kotlin and be up and running in a few seconds.

FilePicker - Android library to facilitate files picking up process and ability to convert them to request bodies

FilePicker - Android library to facilitate files picking up process and ability to convert them to request bodies

Android Application that let users select 2 currencies with the amount to convert
Android Application that let users select 2 currencies with the amount to convert

Currency Converter Android Application that let users select 2 currencies with the amount to convert and have Historical data for 2 currencies of thei

Convert lua to make it human-readable and remove obfuscation.

Muna Convert lua to make it human-readable and remove obfuscation. Based on luaj parser and lua formatter. Before function L1_1(A0_2, A1_2) local L2

Convert video to GIF. Simple and fast.

Convert video to GIF. Simple and fast.

A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports
A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports

A CLI tool to convert multi-module Jetpack Compose compiler metrics into beautiful HTML reports 1. What are Jetpack Compose compiler metrics? The Comp

AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.
AnyChart Android Chart is an amazing data visualization library for easily creating interactive charts in Android apps. It runs on API 19+ (Android 4.4) and features dozens of built-in chart types.

AnyChart for Android AnyChart Android Charts is an amazing data visualization library for easily creating interactive charts in Android apps. It runs

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

Development in this repository is stopped. Future development continues on https://github.com/yigit/android-priority-jobqueue ========================

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Easily notify a user with a simple alert, inform them of an optional update, and in dire situations block the user from accessing older versions of the application completely.
Easily notify a user with a simple alert, inform them of an optional update, and in dire situations block the user from accessing older versions of the application completely.

Gandalf In the lifetime of any application there will come a time where you need to drop support for a feature, end of life a product, notify about ma

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

A library that easily allows you to mask layouts/viewgroups
A library that easily allows you to mask layouts/viewgroups

Maskable Layout Overview ======================= The Maskable Layout is a simple framelayout that allows you to easily mask views and viewgroups. You

Easily add slide to dismiss functionality to an Activity
Easily add slide to dismiss functionality to an Activity

Slidr Easily add slide-to-dismiss functionality to your Activity by calling Slidr.attach(this) in your onCreate(..) method. Usage An example usage: pu

An Android Animation library which easily add itemanimator to RecyclerView items.
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

You can easily add awesome animated context menu to your app.
You can easily add awesome animated context menu to your app.

ContextMenu You can easily add awesome animated context menu to your app. Check this project on dribbble Check this project on Behance Usage: For a wo

Owner
Jire
🍖 the coding caveman
Jire
Convert audio files inside your Android app easily. Supported formats: AAC, MP3, M4A, WMA, WAV and FLAC.

AndroidAudioConverter Convert audio files inside your Android app easily. This is a wrapper of FFmpeg-Android-Java lib. Supported formats: AAC MP3 M4A

Adriel Café 1.3k Jan 5, 2023
A Java serialization/deserialization library to convert Java Objects into JSON and back

Gson Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to a

Google 21.7k Jan 5, 2023
An application to convert strings to diffirent formats

Localized An application to convert strings to diffirent formats This app will help developers to convert strings from application in one platform to

null 16 Feb 12, 2021
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

马天宇 829 Dec 29, 2022
Convert OkHttp requests into curl logs.

Ok2Curl Convert OkHttp requests into curl logs. Usage Add library to project dependencies. Library is hosted on jcenter. repositories { jcenter()

Michal Moczulski 373 Jan 1, 2023
🐫🐍🍢🅿 Multiplatform Kotlin library to convert strings between various case formats including Camel Case, Snake Case, Pascal Case and Kebab Case

KaseChange Multiplatform Kotlin library to convert strings between various case formats Supported Case Formats SCREAMING_SNAKE_CASE snake_case PascalC

PearX Team 67 Dec 30, 2022
Convert your YouTube channel into a native Android app using YouTube Data API v3.

Convert your YouTube channel into an app. Screenshots • Description • Features • Configuration • Documentation Screenshots Description Channelify is a

Aculix Technologies LLP 121 Dec 26, 2022
Simple CLI app to convert XML retrieved from a configurable URI to JSON and back

XmlToJsonUtility Simple CLI app written in Kotlin (1.5.31) on Java 11, using Spring Boot. Queries a URI (default) as an XML source. Attempts to valida

Darius Washington 2 Oct 20, 2021
Intellij Idea Plugin that can convert HTML to Compose for Web code.

HtmlToComposeWebConverter Intellij Idea Plugin that can convert HTML to Compose for Web code. Turn this: Into this: Show some ❤️ and star the repo to

Jens Klingenberg 90 Oct 10, 2022
A tool to convert unit tests from one standard to another

unit-test-exchange-maven-plugin This plugin works as a tool to convert unit test

null 1 Feb 3, 2022