User Tools

Site Tools


doc:appunti:hardware:sjcam-8pro-ambarella-firmware-modding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
doc:appunti:hardware:sjcam-8pro-ambarella-firmware-modding [2022/05/02 11:18] – created niccolodoc:appunti:hardware:sjcam-8pro-ambarella-firmware-modding [2022/06/15 16:47] (current) – [White balance presets] niccolo
Line 1: Line 1:
 ====== How to customize the Ambarella firmware of the SJCAM SJ8 Pro ====== ====== How to customize the Ambarella firmware of the SJCAM SJ8 Pro ======
  
-See also my SJCAM SJ8 Pro action camera review in page **[[sjcam-8pro]]**.+See also my other pages about the SJCAM SJ8 Pro action camera**[[sjcam-8pro]]**, **[[sjcam-8pro-ambarella-wifi-api]]** and **[[sjcam-8pro-custom-firmware]]**.
  
 In this page there are some notes about customizing the firmware of the **[[sjcam-8pro|SJCAM SJ8 Pro]]** action camera, using the **[[https://github.com/vmax1145/BitrateEditor|BitrateEditor]]** software. BitrateEditor is not just about bitrates, it can also change firmware tables about gamma values, YUV values, exposure and many others. In this page there are some notes about customizing the firmware of the **[[sjcam-8pro|SJCAM SJ8 Pro]]** action camera, using the **[[https://github.com/vmax1145/BitrateEditor|BitrateEditor]]** software. BitrateEditor is not just about bitrates, it can also change firmware tables about gamma values, YUV values, exposure and many others.
Line 68: Line 68:
 ^ U         | 0 ÷ 2048    | Multiplier for the **blue projection** (blue - luma).  | ^ U         | 0 ÷ 2048    | Multiplier for the **blue projection** (blue - luma).  |
 ^ V         | 0 ÷ 2048    | Multiplier for the **red projection** (red - luma).  | ^ V         | 0 ÷ 2048    | Multiplier for the **red projection** (red - luma).  |
-^ Y-offset  | -128 ÷ 127  | Shift brightness from **black** to **white**. | +^ Y-offset  | -128 ÷ 127  | Shift brightness from **black** to **white**.  
-^ U-offset  | -128 ÷ 127  | Shift colors from **yellow** to **blue**. | +^ U-offset  | -128 ÷ 127  | Shift colors from **yellow** to **blue**. | 
-^ V-offset  | -128 ÷ 127  | Shift colors from **green** to **red**. |+^ V-offset  | -128 ÷ 127  | Shift colors from **green** to **red**. |
  
 +For the **multiplier**: a value of **0** means a **zero** multiplier (horizonatl slope), **1024** means **1.0** (neutral multiplier), a value of **2048** means **2.0** multiplier.
 +
 +For the **offset shift**: a value of **-128** means **-50%** of the full range, a value of **+127** means **+50%** of the full range.
  
 Values for **Y**, **U** and **V** are unsigned integers in the range **0 ÷ 2048**, values for **Y-offset**, **U-offset** and **V-offset** are signed integers in the range **-128 ÷ +127**. Each YUV profile occupies **24 bytes** into the file. Values for **Y**, **U** and **V** are unsigned integers in the range **0 ÷ 2048**, values for **Y-offset**, **U-offset** and **V-offset** are signed integers in the range **-128 ÷ +127**. Each YUV profile occupies **24 bytes** into the file.
Line 166: Line 169:
 The tables are contained into the **aaa_default_00_Imx377** file (inside the ROMFS section #3), at offsets **0x285**, **0x2E5** and **0x345** respectively. Each exposition table is a matrix of 12x8 bytes; each number represents the exposition weight of a portion of the image, being the image divided in 8 rows and 12 columns. The tables are contained into the **aaa_default_00_Imx377** file (inside the ROMFS section #3), at offsets **0x285**, **0x2E5** and **0x345** respectively. Each exposition table is a matrix of 12x8 bytes; each number represents the exposition weight of a portion of the image, being the image divided in 8 rows and 12 columns.
  
-===== Gamma correction =====+===== Gamma curves =====
  
 Simply speaking, gamma can make the image **lighter** or **darker** in a **selective** manner, i.e. acting differently on shadows and highlights. By acting differently on the red, green and blue channels, gamma can also do **color balancing**. Simply speaking, gamma can make the image **lighter** or **darker** in a **selective** manner, i.e. acting differently on shadows and highlights. By acting differently on the red, green and blue channels, gamma can also do **color balancing**.
Line 172: Line 175:
 Gamma correction is probably applied in a later stage of the Ambarella video processing pipeline. Gamma is a function that transforms brightness or luminance values, it is usually nonlinear and affects the highlights, midtones, and shadows separately. In our case there are different gamma curves for the three color channles: red, green and blue. Different video formats (4K, 1080, etc) use different gamma correction tables. Gamma correction is probably applied in a later stage of the Ambarella video processing pipeline. Gamma is a function that transforms brightness or luminance values, it is usually nonlinear and affects the highlights, midtones, and shadows separately. In our case there are different gamma curves for the three color channles: red, green and blue. Different video formats (4K, 1080, etc) use different gamma correction tables.
  
-BitrateEditor exposes and allow the modification of several look-up tables (**LUT**) contained into the files **adj_video_default_0[0-5]_Imx377** and **adj_still_default_0[0-1]_Imx377** (file are contained into firmware section #3). The tables are shown grouped by three, i.e. we work actually on a **3** x **1D-LUT**, one for each color channel: Red, Green and Blue. In the following picture we see the editing of the group called **4K30/255**; for each color component we have 256 values arranged for compactness in 16 rows:+BitrateEditor exposes and allow the modification of several look-up tables (**LUT**) contained into the files **adj_video_default_0[0-5]_Imx377** and **adj_still_default_0[0-1]_Imx377** (file are contained into firmware section #3). The tables are shown grouped by three, i.e. we work actually on a **3** x **1D-LUT**, one for each color channel: Red, Green and Blue. 
 + 
 +For each color component we have **256 values** arranged for compactness in 16 rows. Each value is likely a **10 bit integer**, BitrateEditor allows you to enter a number ranging from 0 to 1024, but I strictly adivse to remain into the range **%%[0, 1023]%%**. 
 + 
 +In the following picture we see the editing of the group called **4K30/255**;
  
 {{.:ambarella:bitrateeditor-gamma.png?direct&640|}} {{.:ambarella:bitrateeditor-gamma.png?direct&640|}}
Line 189: Line 196:
  
 ^ Group      ^ Contained in file            ^ Used for video modes  ^ ^ Group      ^ Contained in file            ^ Used for video modes  ^
-| 4K30/    | adj_video_default_00_Imx377  | 4K@(25,30) +| 4K30/     | adj_video_default_00_Imx377  | 4K@(25,30) 
-| 4K60/    | adj_video_default_01_Imx377  | 4K@(50,60) +| 4K60/     | adj_video_default_01_Imx377  | 4K@(50,60) 
-| FHD60/   | adj_video_default_02_Imx377  | 4K@24,\\ 4K-Ultra@(24,30)\\ 2720x1520@(24,25,30,50,60)\\ 2560x1440@(24,25,30,50,60)\\ 1920x1080@(24,25,30,50,60)\\ 1920x1080-Ultra@(30,60)\\ Touchscreen operations  |  +| FHD60/    | adj_video_default_02_Imx377  | 4K@24,\\ 4K-Ultra@(24,30)\\ 2720x1520@(24,25,30,50,60)\\ 2560x1440@(24,25,30,50,60)\\ 1920x1080@(24,25,30,50,60)\\ 1920x1080-Ultra@(30,60)\\ Touchscreen operations  |  
-| FHD120/  | adj_video_default_03_Imx377  | 1920x1080@120 +| FHD120/   | adj_video_default_03_Imx377  | 1920x1080@120 
-| 720@240/ | adj_video_default_04_Imx377  | 1280×720@240  |+| 720@240/  | adj_video_default_04_Imx377  | 1280×720@240  | 
 +| 4K30Gyro/ | adj_video_default_05_Imx377  | 4K@(25,30) with Gyro Stabilizer  |
 |                                                ||| |                                                |||
 ^ Group           ^ Contained in file                 ^ Used for photo mode/ISO  ^ ^ Group           ^ Contained in file                 ^ Used for photo mode/ISO  ^
Line 199: Line 207:
 | Photo-Hi-ISO/ | adj_hiso_still_default_00_Imx377  | Photo 800,1600,3200,6400\\ Photo Lapse 800,1600,3200,6400  | | Photo-Hi-ISO/ | adj_hiso_still_default_00_Imx377  | Photo 800,1600,3200,6400\\ Photo Lapse 800,1600,3200,6400  |
  
-I have not found any video mode which is affected by tables contained into the file **adj_video_default_05_Imx377**, may be it affects some of the **non active video modes**?+It seems rather crazy, but the tables contained into **adj_video_default_05_Imx377** are used only when **Gyro Stabilizer** is enabled and mode is **4K** at **25** or **30** fps. 
  
 ==== How gamma curves are mixed together ==== ==== How gamma curves are mixed together ====
Line 324: Line 333:
 {{.:ambarella:40_gamma-255red-128green-0white.jpg?direct&400|}} {{.:ambarella:40_gamma-255red-128green-0white.jpg?direct&400|}}
  
-===== Chroma =====+===== Chroma curves =====
  
 It is possibile to apply a transformation to the **[[wp>Chrominance|chrominance]]** of the images, i.e. the color saturation. The Ambarella processor applies chroma transformations probably at the same stage of gamma correction, as the transformation tables are stored into the same files. It is possibile to apply a transformation to the **[[wp>Chrominance|chrominance]]** of the images, i.e. the color saturation. The Ambarella processor applies chroma transformations probably at the same stage of gamma correction, as the transformation tables are stored into the same files.
Line 424: Line 433:
  
 {{.:ambarella:bitrateeditor-wb-presets.png?direct&640|}} {{.:ambarella:bitrateeditor-wb-presets.png?direct&640|}}
 +
 +FIXME: It is not know how this table works. It seems that labels are wrong: **YA_min** and **YB_min** are repeated twice, may be they are **YA_max** and **YB_max**.
 +
 +White balance is probably applied as a series of linear transformations to the **four raw values** captured by te **[[wp>Bayer_filter|Bayer filter sensor]]**. The four channels are **Red**, **Green-on-red**, **Blue** and **Green-on-blue**, each transformation consists of a multiplier coefficient (slope) and an offset.
 +
 +^ Gr  | Green on Red  |
 +^ Gb  | Green on Blue  |
 +^ Ya  | Y channel value of target image?  |
 +^ Yb  | Y channel value of reference image?  |
  
 ===== 3D LUT tables ===== ===== 3D LUT tables =====
Line 488: Line 506:
   * **{{.:ambarella:h22-product-brief.pdf|Ambarella H22 Video SoC Overview}}**   * **{{.:ambarella:h22-product-brief.pdf|Ambarella H22 Video SoC Overview}}**
   * **[[https://www.goprawn.com/forum/ambarella-cams/18473-color-correction-and-3d-lut-cube|Color correction and 3D LUT cube]]**   * **[[https://www.goprawn.com/forum/ambarella-cams/18473-color-correction-and-3d-lut-cube|Color correction and 3D LUT cube]]**
 +  * **[[https://www.flir.it/support-center/iis/machine-vision/application-note/using-color-correction-in-blackfly-s/|Using Color Correction in Blackfly S and Oryx]]** - Local PDF: {{.:sjcam:color-correction-in-blackfly-s.pdf|color-correction-in-blackfly-s.pdf}}.
  
doc/appunti/hardware/sjcam-8pro-ambarella-firmware-modding.1651483131.txt.gz · Last modified: 2022/05/02 11:18 by niccolo