ColorQuery overview

ColorQuery provides a simple DSL for querying and manipulating the HSV values of images. The intent is to provide a quick and simplified tool for understanding how the colors of different images work.

ColorQuery language (CQL) overview

CQL queries consist of a series of statements executed one after the other. The first statement in a CQL query is always pixels.
pixels
Think of this initial statement as providing the hue, saturation and value for a pixel, to be passed on to the remaining statements. As there are no other statements, the original values are returned unmodified, resulting in the same image.

Statements

Statements are executed sequentially and separated by |. Other than pixels, the only other statement are assignment statements. Assignment statements consist of an assignment expression, optionally followed by a boolean expression that determines whether the assignment expression is executed. If the boolean expression is omitted then the assignment expression is always executed. An example query is:
pixels
| saturation = 0.5 if saturation > 0.5
| value = 0.5
This query assigns the saturation to 0.5 if the saturation is larger than 0.5. It then sets the value to 0.5.

Expressions

Assignment expressions assign a new value to one of saturation, hue or, value. The left-hand side is one of these, followed by an = with the right-hand side consisting of a numerical expression.

Numerical expressions support the standard operators *,/,+,- and precedence using (). The values saturation, hue or, valuecan also be used and their values will be the ones set in previous statements.

Boolean expressions support the standard comparison operators =>,>,<,<= and == between numerical expressions. The standard boolean operatorsand,or are also supported to combine these boolean expressions. Precedence using () is also supported.

Hue, Saturation and Value

Hue, saturation and value each work on a limited scale.

Hue must be in the range [0, 360]
Saturation must be in the range [0, 1]
Value must be in the range [0, 1]

For the sake of simplicity this range limit is only applied after all the statements have been executed, and rounds the value to the closest valid value in the range. For example:
pixels
| hue = hue + 180
This query will add 180 to the hue, after which any hue greater than 360 will be rounded down to 360. Compare this to the following query:
pixels
| hue = hue + 180
| hue = hue - 360 if hue > 360
This query will add 180 to the hue, resulting in some hue values being outside the valid range. This is followed by subtracting 360 to any hue value greater than 360. Only at this point will hue values outside the valid range be rounded to the closest valid value. Since we have already done this manually however, no hue values will be changed.

FAQ

Why was HSV chosen?

HSV was chosen as it is the colorspace primarily used by artists, and considered the most intuitive for most people.

Colorspaces are more complex than this, aren't they?

Yes, making this tool has made me realize that I'm out of my depth when it comes down to how colorspaces work. Regardless, I'm satisfied with this as a quick and simple tool.

Could you implement <x> feature?

If you have an idea for a feature, don't be afraid to reach out! I can't guarantee that it will be implemented, but understanding how others use this tool will still provide valuable feedback on how to make this tool better.