Skip to content

Commit 285983e

Browse files
committed
mv configs to json file, mv image format logic to panel
1 parent 8e97d4c commit 285983e

File tree

13 files changed

+587
-356
lines changed

13 files changed

+587
-356
lines changed

DEFAULT_CONFIGS.json

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
[
2+
{
3+
"name": "LVGL Image Descriptor",
4+
"typePattern": "lv_image_dsc_t",
5+
"width": {
6+
"type": "string",
7+
"isChild": true,
8+
"value": "header.w"
9+
},
10+
"height": {
11+
"type": "string",
12+
"isChild": true,
13+
"value": "header.h"
14+
},
15+
"format": {
16+
"type": "string",
17+
"isChild": true,
18+
"value": "header.cf"
19+
},
20+
"dataAddress": {
21+
"type": "string",
22+
"isChild": true,
23+
"value": "data"
24+
},
25+
"dataSize": {
26+
"type": "string",
27+
"isChild": true,
28+
"value": "data_size"
29+
},
30+
"imageFormats": {
31+
"0": "grayscale",
32+
"1": "grayscale",
33+
"2": "grayscale",
34+
"3": "grayscale",
35+
"4": "grayscale",
36+
"5": "grayscale",
37+
"6": "grayscale",
38+
"7": "grayscale",
39+
"8": "grayscale",
40+
"9": "rgb565",
41+
"10": "rgb565",
42+
"11": "rgb565",
43+
"12": "grayscale",
44+
"13": "rgb565",
45+
"14": "rgb888",
46+
"15": "argb8888",
47+
"16": "bgra8888",
48+
"17": "argb8888",
49+
"18": "yuv420",
50+
"19": "yuv420",
51+
"20": "yuv422",
52+
"21": "yuv444",
53+
"22": "grayscale",
54+
"23": "yuv420",
55+
"24": "yuv420",
56+
"25": "yuv422",
57+
"26": "yuv422",
58+
"27": "yuv420",
59+
"28": "rgb888",
60+
"29": "rgb888",
61+
"30": "rgb444",
62+
"31": "rgb666",
63+
"32": "rgb666",
64+
"33": "rgb666",
65+
"34": "rgb888",
66+
"35": "rgb888",
67+
"36": "rgb888",
68+
"37": "rgb888",
69+
"38": "rgba8888"
70+
}
71+
},
72+
{
73+
"name": "OpenCV Mat",
74+
"typePattern": "cv::Mat|Mat",
75+
"width": {
76+
"type": "string",
77+
"isChild": true,
78+
"value": "cols"
79+
},
80+
"height": {
81+
"type": "string",
82+
"isChild": true,
83+
"value": "rows"
84+
},
85+
"format": {
86+
"type": "number",
87+
"isChild": false,
88+
"value": "0x0E"
89+
},
90+
"dataAddress": {
91+
"type": "string",
92+
"isChild": true,
93+
"value": "data"
94+
},
95+
"dataSize": {
96+
"type": "formula",
97+
"isChild": false,
98+
"value": "$var.rows * $var.step.buf[0]"
99+
},
100+
"imageFormats": {
101+
"0": "grayscale",
102+
"14": "bgr888",
103+
"15": "bgra8888",
104+
"16": "bgra8888"
105+
}
106+
}
107+
]

docs_espressif/en/debugproject.rst

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ The ESP-IDF extension provides an **ESP-IDF: Image Viewer** feature that allows
351351
**Quick Access Methods:**
352352

353353
1. **Right-click on variables in the debug session:**
354-
- Right-click on any ``lv_image_dsc_t`` variable and select ``View as LVGL Image``
355-
- Right-click on any ``cv::Mat`` variable and select ``View as OpenCV Image``
354+
- Right-click on any image-related variable (``lv_image_dsc_t``, ``cv::Mat``, ``png_image``, etc.) and select ``View Variable as Image``
355+
- The Image Viewer automatically detects the variable type and extracts the appropriate image properties
356356

357357
2. **Manual Image Viewer:**
358358
- Go to ``View`` > ``Command Palette`` and enter ``ESP-IDF: Open Image Viewer``
@@ -362,24 +362,28 @@ The ESP-IDF extension provides an **ESP-IDF: Image Viewer** feature that allows
362362

363363
**Supported Image Formats:**
364364

365-
**LVGL Color Formats (lv_color_format_t):**
365+
The Image Viewer supports a comprehensive range of image formats:
366+
367+
**RGB Formats:**
366368
- RGB565, RGB888, RGBA8888, ARGB8888, XRGB8888
367369
- BGR888, BGRA8888, ABGR8888, XBGR8888
368370
- RGB332, RGB444, RGB555, RGB666, RGB777
369-
- Grayscale, YUV420, YUV422, YUV444
370-
- And many more LVGL-specific formats
371-
372-
**OpenCV Mat Formats:**
373-
- BGR888 (3 channels)
374-
- BGRA8888 (4 channels)
375-
- Grayscale (1 channel)
371+
- RGB101010, RGB121212, RGB161616
376372

377-
**Raw Pixel Formats:**
378-
- RGB565 (16-bit per pixel)
379-
- RGB888 (24-bit per pixel)
373+
**Other Formats:**
380374
- Grayscale (8-bit per pixel)
381375
- YUV420, YUV422, YUV444 (various YUV formats)
382376

377+
**Built-in Support:**
378+
379+
**LVGL Image Descriptor (lv_image_dsc_t):**
380+
- Automatically extracts format, dimensions, and data from LVGL structures
381+
- Supports all LVGL color formats with automatic mapping to display formats
382+
383+
**OpenCV Mat (cv::Mat):**
384+
- Automatically extracts dimensions, format, and data from OpenCV Mat objects
385+
- Supports BGR888, BGRA8888, and Grayscale formats
386+
383387
**Example Usage:**
384388

385389
**LVGL Image Example:**
@@ -397,7 +401,7 @@ The ESP-IDF extension provides an **ESP-IDF: Image Viewer** feature that allows
397401
.data = image_data // Pointer to image data
398402
};
399403
400-
During debugging, right-click on ``my_image`` and select ``View as LVGL Image``. The Image Viewer will automatically extract the format, dimensions, and data from the LVGL structure.
404+
During debugging, right-click on ``my_image`` and select ``View Variable as Image``. The Image Viewer will automatically detect it as an LVGL image and extract the format, dimensions, and data.
401405

402406
**OpenCV Mat Example:**
403407

@@ -406,7 +410,7 @@ During debugging, right-click on ``my_image`` and select ``View as LVGL Image``.
406410
cv::Mat image(240, 320, CV_8UC3); // 320x240 BGR888 image
407411
// ... populate image data ...
408412
409-
During debugging, right-click on ``image`` and select ``View as OpenCV Image``. The Image Viewer will automatically extract the dimensions, format, and data from the OpenCV Mat structure.
413+
During debugging, right-click on ``image`` and select ``View Variable as Image``. The Image Viewer will automatically detect it as an OpenCV Mat and extract the dimensions, format, and data.
410414

411415
**Manual Raw Data Example:**
412416

@@ -421,15 +425,90 @@ For manual usage:
421425
- Select ``RGB888`` format
422426
- Set width to ``320`` and height to ``240``
423427

428+
**Custom Image Format Configuration:**
429+
430+
You can extend the Image Viewer to support custom image formats by creating a JSON configuration file and setting the ``idf.imageViewerConfigs`` configuration option.
431+
432+
**Example Custom Configuration:**
433+
434+
.. code-block:: JSON
435+
436+
[
437+
{
438+
"name": "Custom Image Structure",
439+
"typePattern": "my_image_t",
440+
"width": {
441+
"type": "string",
442+
"isChild": true,
443+
"value": "w"
444+
},
445+
"height": {
446+
"type": "string",
447+
"isChild": true,
448+
"value": "h"
449+
},
450+
"format": {
451+
"type": "number",
452+
"isChild": false,
453+
"value": "0x0E"
454+
},
455+
"dataAddress": {
456+
"type": "string",
457+
"isChild": true,
458+
"value": "pixels"
459+
},
460+
"dataSize": {
461+
"type": "formula",
462+
"isChild": false,
463+
"value": "$var.w * $var.h * 3"
464+
},
465+
"imageFormats": {
466+
"14": "rgb888",
467+
"15": "rgba8888"
468+
}
469+
}
470+
]
471+
472+
**Configuration Options:**
473+
474+
- **typePattern**: Regex pattern to match the GDB type of the selected variable when right-clicking "View Variable as Image" (e.g., ``"my_image_t"``, ``"lv_image_dsc_t"``, ``"cv::Mat|Mat"``)
475+
- **width/height**: Configuration for extracting image dimensions
476+
- **format**: Configuration for extracting image format
477+
- **dataAddress**: Configuration for extracting image data pointer
478+
- **dataSize**: Configuration for calculating image data size (supports formulas)
479+
- **imageFormats**: Mapping of numeric format values to display format strings
480+
481+
**Field Configuration Details:**
482+
483+
Each field (width, height, format, dataAddress, dataSize) has the following properties:
484+
485+
- **type**: Specifies the data type of the field value:
486+
- ``"string"``: The value is a string (field name or expression)
487+
- ``"number"``: The value is a numeric constant (e.g., ``"0x0E"``, ``"14"``)
488+
- ``"formula"``: The value is a mathematical formula (only for dataSize field)
489+
490+
- **isChild**: Determines how the field value is interpreted:
491+
- ``true``: The value represents a child field of the right-clicked variable (e.g., ``"header.w"``, ``"data"``)
492+
- ``false``: The value is a direct expression or constant that can be evaluated by GDB
493+
494+
- **value**: The actual field name, expression, or constant to use for extraction
495+
496+
**Important Configuration Notes:**
497+
498+
- **dataSize Formula**: When using formulas in the ``dataSize`` field, the string ``$var`` will be automatically replaced with the actual variable name when you right-click and select "View Variable as Image". For example, if your variable is named ``my_image`` and the formula is ``$var.w * $var.h * 3``, it will be evaluated as ``my_image.w * my_image.h * 3``. **Note**: The formula must be a valid GDB expression since it is calculated by GDB itself.
499+
500+
- **Format Number Mapping**: The numeric keys in the ``imageFormats`` object must match the actual numeric values that the ``format`` field extracts from your image structure. For example, if your image structure's format field contains the value ``14``, then the ``imageFormats`` object should have a key ``"14"`` that maps to the appropriate display format string like ``"rgb888"``.
501+
424502
**Important Notes:**
425-
- **LVGL Support**: Automatically extracts image properties from ``lv_image_dsc_t`` structures
426-
- **OpenCV Support**: Automatically extracts image properties from ``cv::Mat`` objects
427-
- **Format Detection**: The Image Viewer automatically detects and maps LVGL and OpenCV formats to the appropriate display format
503+
- **Automatic Detection**: The Image Viewer automatically detects supported image types and extracts properties
504+
- **Unified Interface**: Single ``View Variable as Image`` command works for all supported formats
505+
- **Format Validation**: All formats are validated against supported display formats
428506
- **Raw Data**: The Image Viewer supports raw pixel formats. Compressed formats (JPEG, PNG, etc.) are not supported
429507
- **Size Specification**: For manual usage, you must specify the correct size of the image data array
430508
- **Variable Size**: The size can be provided as a number (bytes) or as the name of another variable containing the size
431509
- **Pointer Variables**: For pointer variables, make sure to provide the actual data size, not the pointer size
432510
- **Auto-Dimensioning**: The Image Viewer automatically estimates dimensions based on the data size and selected format, but you can manually adjust them for better results
511+
- **Extensible**: Custom image formats can be added through configuration files
433512

434513

435514
Other extensions debug configuration

docs_espressif/en/settings.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ These settings are specific to the ESP32 Chip/Board.
128128
- SVD file absolute path to resolve chip debug peripheral tree view
129129
* - **idf.jtagFlashCommandExtraArgs**
130130
- OpenOCD JTAG flash extra arguments. Default is ``["verify", "reset"]``.
131+
* - **idf.imageViewerConfigs**
132+
- Path to custom image format configurations JSON file for the Image Viewer feature. Can be relative to workspace folder or absolute path.
131133

132134
This is how the extension uses them:
133135

0 commit comments

Comments
 (0)