|
10 | 10 | #include <zephyr/drivers/video.h>
|
11 | 11 | #include <zephyr/drivers/video-controls.h>
|
12 | 12 | #include <zephyr/logging/log.h>
|
| 13 | +#include <zephyr/sys/util.h> |
13 | 14 |
|
14 | 15 | LOG_MODULE_REGISTER(video_sw_generator, CONFIG_VIDEO_LOG_LEVEL);
|
15 | 16 |
|
@@ -71,9 +72,9 @@ static int video_sw_generator_set_fmt(const struct device *dev, enum video_endpo
|
71 | 72 | }
|
72 | 73 |
|
73 | 74 | for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
|
74 |
| - if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min && |
75 |
| - fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min && |
76 |
| - fmt->height <= fmts[i].height_max) { |
| 75 | + if (fmt->pixelformat == fmts[i].pixelformat && |
| 76 | + IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) && |
| 77 | + IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) { |
77 | 78 | break;
|
78 | 79 | }
|
79 | 80 | }
|
@@ -321,10 +322,9 @@ static int video_sw_generator_enum_frmival(const struct device *dev, enum video_
|
321 | 322 | i++;
|
322 | 323 | }
|
323 | 324 |
|
324 |
| - if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) || |
325 |
| - (fie->format->width < fmts[i].width_min) || |
326 |
| - (fie->format->height > fmts[i].height_max) || |
327 |
| - (fie->format->height < fmts[i].height_min)) { |
| 325 | + if ((i == ARRAY_SIZE(fmts)) || |
| 326 | + !IN_RANGE(fie->format->width, fmts[i].width_min, fmts[i].width_max) && |
| 327 | + !IN_RANGE(fie->format->height, fmts[i].height_min, fmts[i].height_max)) { |
328 | 328 | return -EINVAL;
|
329 | 329 | }
|
330 | 330 |
|
|
0 commit comments