|
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 | #include "video_ctrls.h"
|
15 | 16 | #include "video_device.h"
|
@@ -72,9 +73,9 @@ static int video_sw_generator_set_fmt(const struct device *dev, struct video_for
|
72 | 73 | int i = 0;
|
73 | 74 |
|
74 | 75 | for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
|
75 |
| - if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min && |
76 |
| - fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min && |
77 |
| - fmt->height <= fmts[i].height_max) { |
| 76 | + if (fmt->pixelformat == fmts[i].pixelformat && |
| 77 | + IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) && |
| 78 | + IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) { |
78 | 79 | break;
|
79 | 80 | }
|
80 | 81 | }
|
@@ -283,10 +284,9 @@ static int video_sw_generator_enum_frmival(const struct device *dev, struct vide
|
283 | 284 | i++;
|
284 | 285 | }
|
285 | 286 |
|
286 |
| - if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) || |
287 |
| - (fie->format->width < fmts[i].width_min) || |
288 |
| - (fie->format->height > fmts[i].height_max) || |
289 |
| - (fie->format->height < fmts[i].height_min)) { |
| 287 | + if ((i == ARRAY_SIZE(fmts)) || |
| 288 | + !IN_RANGE(fie->format->width, fmts[i].width_min, fmts[i].width_max) && |
| 289 | + !IN_RANGE(fie->format->height, fmts[i].height_min, fmts[i].height_max)) { |
290 | 290 | return -EINVAL;
|
291 | 291 | }
|
292 | 292 |
|
|
0 commit comments