Skip to content

Conversation

@schodet
Copy link
Contributor

@schodet schodet commented Dec 3, 2025

Use a mapping trying to match the real pixel color, select the nearest pixel value according to the input color.

Small test program:

from pybricks.hubs import ThisHub
from pybricks.parameters import Color
from pybricks.tools import wait

hub = ThisHub()

i = hub.screen

for y in range(i.height):
    for x in range(i.width):
        i.draw_pixel(x, y, Color(0, y * 100 / (i.height - 1), x * 100 / (i.width - 1)))

wait(50000)

Closes: pybricks/support#2442

@coveralls
Copy link

coveralls commented Dec 3, 2025

Coverage Status

coverage: 56.525% (-0.06%) from 56.581%
when pulling 8b7dde7 on schodet:hsv
into c9aaa86 on pybricks:master.

Comment on lines 47 to 49
uint16_t h = pbio_int_math_bind(hsv->h, 0, 359);
uint8_t s = pbio_int_math_bind(hsv->s, 0, 100);
uint8_t v = pbio_int_math_bind(hsv->v, 0, 100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range of these values should already be guaranteed. If not, we could have problems elsewhere as well. Maybe just an assert() here instead to catch problems in debug builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is at least Color.NONE which is defined with a negative V:

const pb_type_Color_obj_t pb_Color_NONE_obj = {
    {&pb_type_Color},
    .hsv = {0, 0, -40}
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #421 fixes that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I made the change.

… pixel value.

Use a mapping trying to match the real pixel color, select the nearest
pixel value according to the input color.

Small test program:

  from pybricks.hubs import ThisHub
  from pybricks.parameters import Color
  from pybricks.tools import wait

  hub = ThisHub()

  i = hub.screen

  for y in range(i.height):
      for x in range(i.width):
	  i.draw_pixel(x, y, Color(0, y * 100 / (i.height - 1), x * 100 / (i.width - 1)))

  wait(50000)

Closes: pybricks/support#2442
@laurensvalk laurensvalk merged commit 6bc54fa into pybricks:master Dec 4, 2025
17 checks passed
@laurensvalk
Copy link
Member

Thank you!

@schodet schodet deleted the hsv branch December 14, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unexpected grayscale mapping on EV3

4 participants