Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: vimc: Add a control to display info on test image

Add a control in VIMC to display information such as the correct order of
colors for a given test pattern, counter, brightness, hue, saturation,
contrast, width and height at sensor over test image.

Signed-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>
Acked-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Kaaira Gupta and committed by
Mauro Carvalho Chehab
5f3fb5c5 7a785081

+84
+2
drivers/media/test-drivers/vimc/Kconfig
··· 2 2 config VIDEO_VIMC 3 3 tristate "Virtual Media Controller Driver (VIMC)" 4 4 depends on VIDEO_DEV && VIDEO_V4L2 5 + select FONT_SUPPORT 6 + select FONT_8x16 5 7 select MEDIA_CONTROLLER 6 8 select VIDEO_V4L2_SUBDEV_API 7 9 select VIDEOBUF2_VMALLOC
+1
drivers/media/test-drivers/vimc/vimc-common.h
··· 20 20 #define VIMC_CID_VIMC_CLASS (0x00f00000 | 1) 21 21 #define VIMC_CID_TEST_PATTERN (VIMC_CID_VIMC_BASE + 0) 22 22 #define VIMC_CID_MEAN_WIN_SIZE (VIMC_CID_VIMC_BASE + 1) 23 + #define VIMC_CID_OSD_TEXT_MODE (VIMC_CID_VIMC_BASE + 2) 23 24 24 25 #define VIMC_FRAME_MAX_WIDTH 4096 25 26 #define VIMC_FRAME_MAX_HEIGHT 2160
+10
drivers/media/test-drivers/vimc/vimc-core.c
··· 5 5 * Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com> 6 6 */ 7 7 8 + #include <linux/font.h> 8 9 #include <linux/init.h> 9 10 #include <linux/module.h> 10 11 #include <linux/platform_device.h> 11 12 #include <media/media-device.h> 13 + #include <media/tpg/v4l2-tpg.h> 12 14 #include <media/v4l2-device.h> 13 15 14 16 #include "vimc-common.h" ··· 265 263 266 264 static int vimc_probe(struct platform_device *pdev) 267 265 { 266 + const struct font_desc *font = find_font("VGA8x16"); 268 267 struct vimc_device *vimc; 269 268 int ret; 270 269 271 270 dev_dbg(&pdev->dev, "probe"); 271 + 272 + if (!font) { 273 + dev_err(&pdev->dev, "could not find font\n"); 274 + return -ENODEV; 275 + } 276 + 277 + tpg_set_font(font->data); 272 278 273 279 vimc = kzalloc(sizeof(*vimc), GFP_KERNEL); 274 280 if (!vimc)
+71
drivers/media/test-drivers/vimc/vimc-sensor.c
··· 14 14 15 15 #include "vimc-common.h" 16 16 17 + enum vimc_sen_osd_mode { 18 + VIMC_SEN_OSD_SHOW_ALL = 0, 19 + VIMC_SEN_OSD_SHOW_COUNTERS = 1, 20 + VIMC_SEN_OSD_SHOW_NONE = 2 21 + }; 22 + 17 23 struct vimc_sen_device { 18 24 struct vimc_ent_device ved; 19 25 struct v4l2_subdev sd; 20 26 struct tpg_data tpg; 21 27 u8 *frame; 28 + enum vimc_sen_osd_mode osd_value; 29 + u64 start_stream_ts; 22 30 /* The active format */ 23 31 struct v4l2_mbus_framefmt mbus_format; 24 32 struct v4l2_ctrl_handler hdl; ··· 195 187 { 196 188 struct vimc_sen_device *vsen = container_of(ved, struct vimc_sen_device, 197 189 ved); 190 + const unsigned int line_height = 16; 191 + u8 *basep[TPG_MAX_PLANES][2]; 192 + unsigned int line = 1; 193 + char str[100]; 198 194 199 195 tpg_fill_plane_buffer(&vsen->tpg, 0, 0, vsen->frame); 196 + tpg_calc_text_basep(&vsen->tpg, basep, 0, vsen->frame); 197 + switch (vsen->osd_value) { 198 + case VIMC_SEN_OSD_SHOW_ALL: { 199 + const char *order = tpg_g_color_order(&vsen->tpg); 200 + 201 + tpg_gen_text(&vsen->tpg, basep, line++ * line_height, 202 + 16, order); 203 + snprintf(str, sizeof(str), 204 + "brightness %3d, contrast %3d, saturation %3d, hue %d ", 205 + vsen->tpg.brightness, 206 + vsen->tpg.contrast, 207 + vsen->tpg.saturation, 208 + vsen->tpg.hue); 209 + tpg_gen_text(&vsen->tpg, basep, line++ * line_height, 16, str); 210 + snprintf(str, sizeof(str), "sensor size: %dx%d", 211 + vsen->mbus_format.width, 212 + vsen->mbus_format.height); 213 + tpg_gen_text(&vsen->tpg, basep, line++ * line_height, 16, str); 214 + fallthrough; 215 + } 216 + case VIMC_SEN_OSD_SHOW_COUNTERS: { 217 + unsigned int ms; 218 + 219 + ms = div_u64(ktime_get_ns() - vsen->start_stream_ts, 1000000); 220 + snprintf(str, sizeof(str), "%02d:%02d:%02d:%03d", 221 + (ms / (60 * 60 * 1000)) % 24, 222 + (ms / (60 * 1000)) % 60, 223 + (ms / 1000) % 60, 224 + ms % 1000); 225 + tpg_gen_text(&vsen->tpg, basep, line++ * line_height, 16, str); 226 + break; 227 + } 228 + case VIMC_SEN_OSD_SHOW_NONE: 229 + default: 230 + break; 231 + } 232 + 200 233 return vsen->frame; 201 234 } 202 235 ··· 249 200 if (enable) { 250 201 const struct vimc_pix_map *vpix; 251 202 unsigned int frame_size; 203 + 204 + vsen->start_stream_ts = ktime_get_ns(); 252 205 253 206 /* Calculate the frame size */ 254 207 vpix = vimc_pix_map_by_code(vsen->mbus_format.code); ··· 320 269 case V4L2_CID_SATURATION: 321 270 tpg_s_saturation(&vsen->tpg, ctrl->val); 322 271 break; 272 + case VIMC_CID_OSD_TEXT_MODE: 273 + vsen->osd_value = ctrl->val; 274 + break; 323 275 default: 324 276 return -EINVAL; 325 277 } ··· 361 307 .qmenu = tpg_pattern_strings, 362 308 }; 363 309 310 + static const char * const vimc_ctrl_osd_mode_strings[] = { 311 + "All", 312 + "Counters Only", 313 + "None", 314 + NULL, 315 + }; 316 + 317 + static const struct v4l2_ctrl_config vimc_sen_ctrl_osd_mode = { 318 + .ops = &vimc_sen_ctrl_ops, 319 + .id = VIMC_CID_OSD_TEXT_MODE, 320 + .name = "Show Information", 321 + .type = V4L2_CTRL_TYPE_MENU, 322 + .max = ARRAY_SIZE(vimc_ctrl_osd_mode_strings) - 2, 323 + .qmenu = vimc_ctrl_osd_mode_strings, 324 + }; 325 + 364 326 static struct vimc_ent_device *vimc_sen_add(struct vimc_device *vimc, 365 327 const char *vcfg_name) 366 328 { ··· 393 323 394 324 v4l2_ctrl_new_custom(&vsen->hdl, &vimc_sen_ctrl_class, NULL); 395 325 v4l2_ctrl_new_custom(&vsen->hdl, &vimc_sen_ctrl_test_pattern, NULL); 326 + v4l2_ctrl_new_custom(&vsen->hdl, &vimc_sen_ctrl_osd_mode, NULL); 396 327 v4l2_ctrl_new_std(&vsen->hdl, &vimc_sen_ctrl_ops, 397 328 V4L2_CID_VFLIP, 0, 1, 1, 0); 398 329 v4l2_ctrl_new_std(&vsen->hdl, &vimc_sen_ctrl_ops,