[Cambrian (2)] Media processing system: use of vgu video graphics unit, resize image (resize), cover (cover), operation display (osd), mosaic (mosaic), draw line (drawline), rotation ( rotate)

1 API situation of VGU library

cnS32_t cnvguBeginJob(cnvguHandle_t *phHandle); - This function may start an image processing task, and its parameter may be a handle to the processing task. The return value may be an error code (S32_t is usually used for error codes) or a status code.
cnS32_t cnvguCancelJob(cnvguHandle_t hHandle); - This function may be used to cancel an ongoing image processing job. It accepts a handle to the processing task as a parameter and returns an error code or status code.
cnS32_t cnvguEndJob(cnvguHandle_t hHandle); - This function may be used to end an image processing job. It accepts a handle to the processing task as a parameter and returns an error code or status code.
cnS32_t cnvguAddRotateTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, cnEnRotation_t enRotation); - This function may be used to add a rotation task to the processing task queue. It accepts the handle of the processing task, task attributes and rotation type as parameters, and returns an error code or status code.
cnS32_t cnvguAddOsdTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguOsdAttr_t *pstOsdAttr); - This function may be used to add an OSD (On Screen Display) task to the processing task queue. It accepts the handle of the processing task, task attributes and OSD attributes as parameters, and returns an error code or status code.
cnS32_t cnvguBatchAddOsdTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguOsdAttr_t astOsdAttr[], const cnU32_t u32ArraySize); - This function may be used to add OSD tasks to the processing task queue in batches. It accepts the handle of the processing task, task attributes, OSD attributes, and the array size of the OSD attributes as parameters, and returns an error code or status code.
cnS32_t cnvguAddScaleTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnScaleAttr_t *pstScaleAttr); - This function may be used to add a scaling task to the processing task queue. It accepts the handle of the processing task, task properties, and scaling properties as parameters, and returns an error code or status code.
cnS32_t cnvguAddLbaTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnAspectRatio_t *pstAspectRatio); - This function may be used to add an LBA (Linear Byte Array) task to the processing task queue. It accepts the handle of the processing task, task properties, and aspect ratio properties as parameters, and returns an error code or status code.
cnS32_t cnvguAddDrawLineTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguDrawLineAttr_t *pstDrawLineAttr); - This function may be used to add a line drawing task to the processing task queue. It accepts the handle of the processing task, task properties and drawing line properties as parameters, and returns an error code or status code.
cnS32_t cnvguBatchAddDrawLineTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguDrawLineAttr_t astDrawLineAttr[], const cnU32_t u32ArraySize); - This function may be used to batch add line drawing tasks to the processing task queue. It accepts the handle of the processing task, the task attribute, the draw line attribute, and the array size of the draw line attribute as parameters, and returns an error code or status code.
cnS32_t cnvguAddCoverTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguCoverAttr_t *pstCoverAttr); - This function may be used to add a coverage task to the processing task queue. It accepts the handle of the processing task, task attributes and override attributes as parameters, and returns an error code or status code.
...
cnS32_t cnvguAddPipelineTask(cnvguHandle_t hHandle, const cnvguTaskAttr_t *pstTaskAttr, const cnvguPipelineAttr_t *pstPipelineAttr); seems to be a function definition in the C or C++ programming language. Based on the function name and parameters, we can speculate on the general function and role of this function.

First, cnS32_t may be an error code or status code type, used to indicate the result status of function execution. cnvguAddPipelineTask is the name of the function, suggesting that this function may be used to add a "pipeline" task.

The parameter list of the function includes:

    cnvguHandle_t hHandle: This is a handle type parameter, usually used in programs to identify or operate certain objects or resources.
    const cnvguTaskAttr_t *pstTaskAttr: This is a pointer to the cnvguTaskAttr_t type, which is usually used to describe various attributes of the task, such as task type, content, parameters, etc.
    const cnvguPipelineAttr_t *pstPipelineAttr: This is a pointer to the cnvguPipelineAttr_t type. It is usually used to describe various attributes of the pipeline, which may involve the process, steps, etc. of processing tasks.

Combined with the above analysis, we can speculate that this function may be used to add a "pipeline" task to a processing task queue (which may be identified by the handle hHandle). At the same time, this task has specific attributes pstTaskAttr and pipeline attribute pstPipelineAttr. The specific implementation may involve some complex processing processes and steps.

2 Basic concepts of VGU

Job: A Job has multiple Tasks, and the Job will be submitted to the VGU hardware for processing.
Task: one or more operations completed on an image
Node: The smallest unit that VUG hardware can execute. One Task corresponds to multiple Nodes.
Handle: A handle that uniquely identifies a Job.

An example of an image processing process

An image processing process includes a series of operations, such as reading files, resizing images (resize), covering (cover), operating display (osd), mosaic (mosaic), drawing lines (drawline), and rotating (rotate) And apply alpha channel etc. Finally, the processed image is output and saved to a file.

Here is a detailed explanation of this process:

1. Read the file: This is the first step in image processing. You need a function that can read image files in various formats. This function should be able to handle common image formats like JPEG, PNG, BMP, etc.

2. Resize the image: This step is to change the size of the image. Before processing the image, you may need to resize it to suit your specific needs. For example, you may need to make the image smaller so you can process it faster, or you may need to make the image larger to see its details in greater detail.

3. Cover: This step usually involves adding another image or some color to the image. This is often used to add a watermark or logo to an image.

4. Operation display (OSD): OSD usually refers to displaying some information on the image, such as time, date, text, etc. This step may involve adding an OSD to the image.

5. Mosaic: Mosaic is a technique that divides an image into many small pieces and uses these small pieces to create new images. This step may involve applying a mosaic effect to the image.

6. Drawline: This step may involve drawing lines on the image. This can be used for a variety of purposes, such as marking certain areas on an image or creating some kind of artistic effect.

7. Rotate: This step involves rotating the image by a certain angle. This can be used for a variety of purposes, such as correcting the tilt of an image or creating some special effect.

8. Apply alpha channel (alpha): Alpha channel is a way to define the transparency of an image. This step may involve applying an alpha channel to the image to achieve an effect, such as making part of the image transparent.

9. Export and save to file: The processed image usually needs to be saved to a file for subsequent use or sharing. This step involves saving the processed image to a file.

The above is a detailed explanation of this process. How you implement this will depend on the programming language and libraries you use. For example, if you use Python and the PIL library, you might use PIL’s functions to read and save files, resize, overwrite, OSD, etc. If you use the OpenCV library, you may use OpenCV functions to perform these operations.

Example of mosaic

static cnS32_t sampleVguCoverOsdMosaic()
{<!-- -->
...
    CHECK_RET_SUCESSS(sampleVguInitSys( & amp;stVguTaskAttr, CN_TRUE), errExit);
    CHECK_RET_SUCESSS(sampleVguLoadInputFile( & amp;stVguTaskAttr, & amp;astVguVbInfo[0], inputName), sysExit);

    /* output, input use the same vb buf */
    memcpy( & amp;(stVguTaskAttr.stImgOut), & amp;(stVguTaskAttr.stImgIn), sizeof(cnVideoFrameInfo_t));

    /* cover param init */
...

    /* osd param init */
...
    CHECK_RET_SUCESSS(sampleVguLoadOsdFile( & amp;stOsdDataInfo, & amp;astVguVbInfo[1], osdName), freeInVb);
    stOsdAttr.u64PhyAddr = stOsdDataInfo.stVFrame.u64PhyAddr[0];

    /* mosaic param init */
...

    CHECK_RET_SUCESSS(cnvguBeginJob( & amp;enJobHdl), freeOsdVb);
    CHECK_RET_SUCESSS(cnvguAddCoverTask(enJobHdl, & &stVguTaskAttr, &stCoverAttr), cancelJob);
    CHECK_RET_SUCESSS(cnvguAddOsdTask(enJobHdl, & amp;stVguTaskAttr, & amp;stOsdAttr), cancelJob);
    CHECK_RET_SUCESSS(cnvguAddMosaicTask(enJobHdl, & &stVguTaskAttr, &stMosaicAttr), cancelJob);

    s32Ret = cnvguEndJob(enJobHdl);
    if (s32Ret == CN_SUCCESS)
    {<!-- -->
        s32Ret = sampleVguDumpOutFrame( & amp;stVguTaskAttr, & amp;astVguVbInfo[0], VGU_CASE_TYPE_COVER_OSD_MOSAIC);
...
        goto freeOsdVb;
    }
    SAMPLE_TRACE("cnvguEndJob fail s32Ret(%x)!\\
", s32Ret);

cancelJob:
    CHECK_RET_SUCESSS(cnvguCancelJob(enJobHdl), errExit);
freeOsdVb:
    CHECK_RET_SUCESSS(sampleVguFreeVb( & amp;stOsdDataInfo, & amp;astVguVbInfo[1]), errExit);
freeInVb:
    CHECK_RET_SUCESSS(sampleVguFreeVb( & amp;(stVguTaskAttr.stImgIn), & amp;astVguVbInfo[0]), errExit);
sysExit:
   s32Ret = sampleVguExitSys();
errExit:
    return s32Ret;
}