commit 8c288f0b970f9bfa3ce3428d861250895bed2bf8
Author: Nikhil Dasan <a0496626@ti.com>
Date:   Mon Jul 1 18:07:26 2024 +0530

    opengl mosaic yuv422
    
    Signed-off-by: Nikhil Dasan <a0496626@ti.com>

diff --git a/apps/basic_demos/app_linux_arm_opengl_mosaic/main_linux_arm.c b/apps/basic_demos/app_linux_arm_opengl_mosaic/main_linux_arm.c
index f5592d1..331d22e 100755
--- a/apps/basic_demos/app_linux_arm_opengl_mosaic/main_linux_arm.c
+++ b/apps/basic_demos/app_linux_arm_opengl_mosaic/main_linux_arm.c
@@ -173,9 +173,9 @@ static vx_status app_load_vximage_from_bin_file(char *filename, vx_image image)
     return status;
 }
 
-static vx_status app_save_vximage_rgbx_to_bin_file(char *file_name, vx_image image)
+static vx_status app_save_vximage_uyvy_to_bin_file(char *filename, vx_image image)
 {
-    vx_uint32 width, height;
+    vx_uint32 width, height, num_bytes;
     vx_imagepatch_addressing_t image_addr1;
     vx_rectangle_t rect;
     vx_map_id map_id1;
@@ -190,12 +190,6 @@ static vx_status app_save_vximage_rgbx_to_bin_file(char *file_name, vx_image ima
         vxQueryImage(image, VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));
         vxQueryImage(image, VX_IMAGE_FORMAT, &df, sizeof(vx_df_image));
 
-        printf("app_linux_arm_opengl_mosaic: writing to file [%s] image of size %d x %d\n",
-            file_name,
-            width,
-            height
-            );
-
         rect.start_x = 0;
         rect.start_y = 0;
         rect.end_x = width;
@@ -215,60 +209,130 @@ static vx_status app_save_vximage_rgbx_to_bin_file(char *file_name, vx_image ima
         }
         if(status==VX_SUCCESS)
         {
-            FILE *fp = fopen(file_name,"wb");
+            FILE *fp = fopen(filename,"wb");
 
             if(fp!=NULL)
             {
-                uint32_t x, y;
-                uint8_t *cur_ptr;
-                size_t ret = 0;
+                vx_int32 j;
 
-                for(y=0; y<height; y++)
+                num_bytes = 0;
+                for (j = 0; j < height; j++)
                 {
-                    cur_ptr = (uint8_t *)data_ptr1 + image_addr1.stride_y*y;
-
-                    for(x=0; x<width; x++)
-                    {
-                        /* only write RGB, dont write the A value */
-                        ret = fwrite(cur_ptr, 3, 1, fp);
-                        if(ret!=1)
-                        {
-                            printf("app_linux_arm_opengl_mosaic: ERROR: Unable to write data to file [%s]\n", file_name);
-                            status = VX_FAILURE;
-                            break;
-                        }
-                        cur_ptr += 4; /* skip over a RGBA pixel */
-                    }
-                    if(ret!=1)
-                    {
-                        status = VX_FAILURE;
-                        break;
-                    }
+                    num_bytes += fwrite(data_ptr1, 1, 2*width, fp);
+                    data_ptr1 += image_addr1.stride_y;
                 }
                 fclose(fp);
-
-                printf("app_linux_arm_opengl_mosaic: writing to file [%s] image of size %d x %d ... Done !!!\n",
-                    file_name,
-                    width,
-                    height
-                    );
             }
             else
             {
-                printf("app_linux_arm_opengl_mosaic: ERROR: Unable to open file for writing [%s]\n", file_name);
-                status = VX_FAILURE;
+                 printf("app_linux_arm_opengl_mosaic: ERROR: Unable to open file for reading [%s]\n", filename);
             }
             vxUnmapImagePatch(image, map_id1);
         }
     }
     else
     {
-        printf("app_linux_arm_opengl_mosaic: ERROR: Invalid image specified for writing\n");
+        printf("app_linux_arm_opengl_mosaic: ERROR: Invalid image specified for reading\n");
     }
-
     return status;
 }
 
+// static vx_status app_save_vximage_rgbx_to_bin_file(char *file_name, vx_image image)
+// {
+//     vx_uint32 width, height;
+//     vx_imagepatch_addressing_t image_addr1;
+//     vx_rectangle_t rect;
+//     vx_map_id map_id1;
+//     vx_df_image df;
+//     void *data_ptr1;
+//     vx_status status;
+
+//     status = vxGetStatus((vx_reference)image);
+//     if(status==VX_SUCCESS)
+//     {
+//         vxQueryImage(image, VX_IMAGE_WIDTH, &width, sizeof(vx_uint32));
+//         vxQueryImage(image, VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));
+//         vxQueryImage(image, VX_IMAGE_FORMAT, &df, sizeof(vx_df_image));
+
+//         printf("app_linux_arm_opengl_mosaic: writing to file [%s] image of size %d x %d\n",
+//             file_name,
+//             width,
+//             height
+//             );
+
+//         rect.start_x = 0;
+//         rect.start_y = 0;
+//         rect.end_x = width;
+//         rect.end_y = height;
+//         if(status == VX_SUCCESS)
+//         {
+//             status = vxMapImagePatch(image,
+//                 &rect,
+//                 0,
+//                 &map_id1,
+//                 &image_addr1,
+//                 &data_ptr1,
+//                 VX_READ_ONLY,
+//                 VX_MEMORY_TYPE_HOST,
+//                 VX_NOGAP_X
+//                 );
+//         }
+//         if(status==VX_SUCCESS)
+//         {
+//             FILE *fp = fopen(file_name,"wb");
+
+//             if(fp!=NULL)
+//             {
+//                 uint32_t x, y;
+//                 uint8_t *cur_ptr;
+//                 size_t ret = 0;
+
+//                 for(y=0; y<height; y++)
+//                 {
+//                     cur_ptr = (uint8_t *)data_ptr1 + image_addr1.stride_y*y;
+
+//                     for(x=0; x<width; x++)
+//                     {
+//                         /* only write RGB, dont write the A value */
+//                         ret = fwrite(cur_ptr, 3, 1, fp);
+//                         if(ret!=1)
+//                         {
+//                             printf("app_linux_arm_opengl_mosaic: ERROR: Unable to write data to file [%s]\n", file_name);
+//                             status = VX_FAILURE;
+//                             break;
+//                         }
+//                         cur_ptr += 4; /* skip over a RGBA pixel */
+//                     }
+//                     if(ret!=1)
+//                     {
+//                         status = VX_FAILURE;
+//                         break;
+//                     }
+//                 }
+//                 fclose(fp);
+
+//                 printf("app_linux_arm_opengl_mosaic: writing to file [%s] image of size %d x %d ... Done !!!\n",
+//                     file_name,
+//                     width,
+//                     height
+//                     );
+//             }
+//             else
+//             {
+//                 printf("app_linux_arm_opengl_mosaic: ERROR: Unable to open file for writing [%s]\n", file_name);
+//                 status = VX_FAILURE;
+//             }
+//             vxUnmapImagePatch(image, map_id1);
+//         }
+//     }
+//     else
+//     {
+//         printf("app_linux_arm_opengl_mosaic: ERROR: Invalid image specified for writing\n");
+//     }
+
+//     return status;
+// }
+
 int main(int argc, char *argv[])
 {
     int32_t i, status = VX_SUCCESS;
@@ -348,7 +412,7 @@ int main(int argc, char *argv[])
     }
     if(status == VX_SUCCESS)
     {
-        output = vxCreateImage(context, outputWidth, outputHeight, VX_DF_IMAGE_RGBX);
+        output = vxCreateImage(context, outputWidth, outputHeight, VX_DF_IMAGE_UYVY);
         status = vxGetStatus((vx_reference) output);
     }
     if(status == VX_SUCCESS)
@@ -394,7 +458,7 @@ int main(int argc, char *argv[])
     }
     if(status == VX_SUCCESS)
     {
-        status = app_save_vximage_rgbx_to_bin_file(output_file_path, (vx_image)output);
+        status = app_save_vximage_uyvy_to_bin_file(output_file_path, (vx_image)output);
     }
     for(i = 0; i < NUM_IMAGES; i++)
     {
diff --git a/kernels/sample/a72/vx_opengl_mosaic_target.c b/kernels/sample/a72/vx_opengl_mosaic_target.c
index adcf471..a9b7d71 100755
--- a/kernels/sample/a72/vx_opengl_mosaic_target.c
+++ b/kernels/sample/a72/vx_opengl_mosaic_target.c
@@ -147,7 +147,7 @@ static vx_status VX_CALLBACK tivxOpenglMosaicProcess(
         input_desc = (tivx_obj_desc_object_array_t *)obj_desc[TIVX_KERNEL_OPENGL_MOSAIC_INPUT_IDX];
         output_desc = (tivx_obj_desc_image_t *)obj_desc[TIVX_KERNEL_OPENGL_MOSAIC_OUTPUT_IDX];
 
-        if(VX_DF_IMAGE_RGBX != output_desc->format)
+        if(VX_DF_IMAGE_UYVY != output_desc->format)
         {
             status = VX_FAILURE;
         }
@@ -284,7 +284,7 @@ static vx_status VX_CALLBACK tivxOpenglMosaicProcess(
             renderTexProp.height         = output_desc->imagepatch_addr[0].dim_y;
             renderTexProp.pitch[0]       = output_desc->imagepatch_addr[0].stride_y;
             renderTexProp.pitch[1]       = output_desc->imagepatch_addr[0].stride_y;
-            renderTexProp.dataFormat     = APP_EGL_DF_RGBX;
+            renderTexProp.dataFormat     = APP_EGL_DF_UYVY;
 
             renderTexProp.dmaBufFd[0]       = output_desc->mem_ptr[0].dma_buf_fd;
             renderTexProp.dmaBufFdOffset[0] = output_desc->mem_ptr[0].dma_buf_fd_offset;
@@ -433,7 +433,7 @@ static vx_status VX_CALLBACK tivxOpenglMosaicCreate(
 
         output_desc = (tivx_obj_desc_image_t *)obj_desc[TIVX_KERNEL_OPENGL_MOSAIC_OUTPUT_IDX];
 
-        if(VX_DF_IMAGE_RGBX != output_desc->format)
+        if(VX_DF_IMAGE_UYVY != output_desc->format)
         {
             status = VX_FAILURE;
         }
diff --git a/kernels/sample/host/vx_opengl_mosaic_host.c b/kernels/sample/host/vx_opengl_mosaic_host.c
index c7ce187..ba5e70a 100644
--- a/kernels/sample/host/vx_opengl_mosaic_host.c
+++ b/kernels/sample/host/vx_opengl_mosaic_host.c
@@ -160,7 +160,7 @@ static vx_status VX_CALLBACK tivxAddKernelOpenglMosaicValidate(vx_node node,
 
     if (VX_SUCCESS == status)
     {
-        if (VX_DF_IMAGE_RGBX != output_fmt)
+        if (VX_DF_IMAGE_UYVY != output_fmt)
         {
             status = VX_ERROR_INVALID_PARAMETERS;
             VX_PRINT(VX_ZONE_ERROR, "'output' should be an image of type:\n VX_DF_IMAGE_RGBX \n");
