diff --git a/docs/vwf/manual/index.xhtml b/docs/vwf/manual/index.xhtml index 26f55bf..c3a53c6 100644 --- a/docs/vwf/manual/index.xhtml +++ b/docs/vwf/manual/index.xhtml @@ -227,6 +227,8 @@
Colors
@@ -2049,6 +2051,44 @@ ExitToOwMode = VWF_ExitToOwMode Defines a 16-bit color value in RGB15 format by separately specifying the values for the red, green and blue color channels.

+
rgb_15_from_24()
+

+ + + + + + + + + +
Usage
rgb_15_from_24(r, g, b)
Parameters
    +
  • r: number: The value of the red color channel. (min: 0, max: 255)
  • +
  • g: number: The value of the green color channel. (min: 0, max: 255)
  • +
  • b: number: The value of the blue color channel. (min: 0, max: 255)
  • +
+ Defines a 16-bit color value in RGB15 format by separately specifying the values for the red, green and blue color channels as 8-bit values. This is useful since RGB24 (which uses 8-bit color channels) is the most common color format around today, so you can easily take color values from existing apps (like Microsoft Paint) and copy them directly into the patch. Note that not all RGB24 color values are expressible in RGB15, so in a lot of cases, the function will pick the closest matching color. +

+ +
rgb_15_from_f()
+

+ + + + + + + + + +
Usage
rgb_15_from_f(r, g, b)
Parameters
    +
  • r: number: The value of the red color channel. (min: 0.0, max: 1.0)
  • +
  • g: number: The value of the green color channel. (min: 0.0, max: 1.0)
  • +
  • b: number: The value of the blue color channel. (min: 0.0, max: 1.0)
  • +
+ Defines a 16-bit color value in RGB15 format by separately specifying the values for the red, green and blue color channels as decimal values. This is useful in cases where you want to express color channels as a percentage. The function will pick the closest matching color expressible in RGB15 for the given color channel values. +

+
vwf_get_color_index_2bpp()

@@ -2611,6 +2651,7 @@ endif
  • The maximum value for the VWF_AutoWait.WaitFrames auto-wait mode has been extended from 254 to 255.
  • Simplified many multiplications in the patch. For most of them, this slightly boosts performance. More importantly, this removes any dependency on the mode 7 registers for multiplication, which avoids a potential rare bug that could be caused by HDMA.
  • Text box properties (background pattern, background color and frame) can now be overridden by message headers. This functionality is available via the vwf_text_box_bg_pattern(), vwf_text_box_bg_color() and vwf_text_box_frame() header settings.
  • +
  • Added the rgb_15_from_24() and rgb_15_from_f() helper functions.
  • diff --git a/patches/shared/shared.asm b/patches/shared/shared.asm index d89926f..184e222 100644 --- a/patches/shared/shared.asm +++ b/patches/shared/shared.asm @@ -580,7 +580,37 @@ endmacro ; Misc color functions +; Private section + +{ + ; Converts an 8-bit color channel to a 5-bit color channel. + ; Requires math rounding mode to be off. + + function rs_8_bit_to_5_bit_color(channel_value) = round((channel_value/255)*31, 0)&%11111 + + + ; Converts a float color channel to a 5-bit color channel. + ; Requires math rounding mode to be off. + + function rs_f_to_5_bit_color(channel_value) = round(channel_value*31, 0)&%11111 +} + + + +; Public section ; Creates an RGB15 16-bit value from the three different colors channels. Each channel value can be in the range of 0 to 31. function rgb_15(red, green, blue) = (red&%11111)|((green&%11111)<<5)|((blue&%11111)<<10) + + +; Creates an RGB15 16-bit value from the three different color channels comprising an RGB24 24-bit color value. +; Each channel value can be in the range of 0 to 255. For color values not representable as RGB15, the closest match is used. + +function rgb_15_from_24(red, green, blue) = rs_8_bit_to_5_bit_color(red)|(rs_8_bit_to_5_bit_color(green)<<5)|(rs_8_bit_to_5_bit_color(blue)<<10) + + +; Creates an RGB15 16-bit value from the three different color channels expressed as decimal percentages. +; Each channel value can be in the range of 0.0 to 1.0. For color values not representable as RGB15, the closest match is used. + +function rgb_15_from_f(red, green, blue) = rs_f_to_5_bit_color(red)|(rs_f_to_5_bit_color(green)<<5)|(rs_f_to_5_bit_color(blue)<<10) diff --git a/patches/vwf_dialogues/data/testing/data/vwfmessages.asm b/patches/vwf_dialogues/data/testing/data/vwfmessages.asm index eaf43a9..26cb9bf 100644 --- a/patches/vwf_dialogues/data/testing/data/vwfmessages.asm +++ b/patches/vwf_dialogues/data/testing/data/vwfmessages.asm @@ -2084,7 +2084,7 @@ BufferOverflowTest: %vwf_message_start(0063) ; Message 10D-2 - %vwf_header(text_box_bg_color(rgb_15(15, 0, 0))) + %vwf_header(text_box_bg_color(rgb_15_from_24(128, 0, 0))) !str("This text box overrides the text box color.") : !press_button !display_message(0064) @@ -2106,7 +2106,7 @@ BufferOverflowTest: %vwf_message_start(0065) ; Message 10E-2 - %vwf_header(text_box_bg_pattern($05), text_box_bg_color(rgb_15(0, 15, 0)), text_box_frame($02)) + %vwf_header(text_box_bg_pattern($05), text_box_bg_color(rgb_15_from_f(0.0, 0.5, 0.0)), text_box_frame($02)) !str("This text box overrides all three text box properties.") : !press_button !display_message(0050)