TIOVX User Guide
vx_tutorial_image_color_convert.c
Go to the documentation of this file.
1 /*
2 *
3 * Copyright (c) 2017 Texas Instruments Incorporated
4 *
5 * All rights reserved not granted herein.
6 *
7 * Limited License.
8 *
9 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
10 * license under copyrights and patents it now or hereafter owns or controls to make,
11 * have made, use, import, offer to sell and sell ("Utilize") this software subject to the
12 * terms herein. With respect to the foregoing patent license, such license is granted
13 * solely to the extent that any such patent is necessary to Utilize the software alone.
14 * The patent license shall not apply to any combinations which include this software,
15 * other than combinations with devices manufactured by or for TI ("TI Devices").
16 * No hardware patent is licensed hereunder.
17 *
18 * Redistributions must preserve existing copyright notices and reproduce this license
19 * (including the above copyright notice and the disclaimer and (if applicable) source
20 * code license limitations below) in the documentation and/or other materials provided
21 * with the distribution
22 *
23 * Redistribution and use in binary form, without modification, are permitted provided
24 * that the following conditions are met:
25 *
26 * * No reverse engineering, decompilation, or disassembly of this software is
27 * permitted with respect to any software provided in binary form.
28 *
29 * * any redistribution and use are licensed by TI for use only with TI Devices.
30 *
31 * * Nothing shall obligate TI to provide you with source code for the software
32 * licensed and provided to you in object code.
33 *
34 * If software source code is provided to you, modification and redistribution of the
35 * source code are permitted provided that the following conditions are met:
36 *
37 * * any redistribution and use of the source code, including any resulting derivative
38 * works, are licensed by TI for use only with TI Devices.
39 *
40 * * any redistribution and use of any object code compiled from the source code
41 * and any resulting derivative works, are licensed by TI for use only with TI Devices.
42 *
43 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers
44 *
45 * may be used to endorse or promote products derived from this software without
46 * specific prior written permission.
47 *
48 * DISCLAIMER.
49 *
50 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
51 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53 * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
55 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
57 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
59 * OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 */
62 
63 
64 
112 #include <stdio.h>
113 #include <VX/vx.h>
114 #include <TI/tivx.h>
115 #include <utility.h>
116 
118 #define IN_FILE_NAME "${VX_TEST_DATA_PATH}/colors.bmp"
119 
121 #define OUT_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_image_color_convert_out.bmp"
122 
127 {
135  vx_context context;
136  vx_image rgb_image = NULL;
137  vx_image nv12_image = NULL;
138  vx_image y_image = NULL;
139  vx_node node0 = NULL, node1 = NULL;
140  vx_graph graph = NULL;
142  vx_uint32 width, height;
143  vx_status status;
144 
145  printf(" vx_tutorial_image_color_convert: Tutorial Started !!! \n");
146 
154  context = vxCreateContext();
157  printf(" Loading file %s ...\n", IN_FILE_NAME);
158 
164  graph = vxCreateGraph(context);
166  vxSetReferenceName((vx_reference)graph, "MY_GRAPH");
167 
178  vxSetReferenceName((vx_reference)rgb_image, "RGB_IMAGE");
179 
187  show_image_attributes(rgb_image);
190  vxQueryImage(rgb_image, (vx_enum)VX_IMAGE_WIDTH, &width, sizeof(vx_uint32));
191  vxQueryImage(rgb_image, (vx_enum)VX_IMAGE_HEIGHT, &height, sizeof(vx_uint32));
192 
202  nv12_image = vxCreateVirtualImage(graph, 0, 0, (vx_df_image)VX_DF_IMAGE_NV12);
204  vxSetReferenceName((vx_reference)nv12_image, "NV12_IMAGE");
212  show_image_attributes(nv12_image);
222  y_image = vxCreateImage(context, width, height, (vx_df_image)VX_DF_IMAGE_U8);
224  vxSetReferenceName((vx_reference)y_image, "Y_IMAGE");
225  show_image_attributes(y_image);
226 
235  node0 = vxColorConvertNode(graph, rgb_image, nv12_image);
237  vxSetReferenceName((vx_reference)node0, "COLOR_CONVERT");
238 
248  node1 = vxChannelExtractNode(graph, nv12_image, (vx_enum)VX_CHANNEL_Y, y_image);
250  vxSetReferenceName((vx_reference)node1, "CHANNEL_EXTRACT");
251 
259  status = vxVerifyGraph(graph);
265  tivxExportGraphToDot(graph, ".", "vx_tutorial_image_color_convert");
275  show_graph_attributes(graph);
285  show_node_attributes(node0);
286  show_node_attributes(node1);
289  if(status==(vx_status)VX_SUCCESS)
290  {
291  printf(" Executing graph ...\n");
292 
301  vxScheduleGraph(graph);
310  vxWaitGraph(graph);
313  printf(" Executing graph ... Done !!!\n");
314 
322  show_graph_attributes(graph);
332  show_node_attributes(node0);
333  show_node_attributes(node1);
336  printf(" Saving to file %s ...\n", OUT_FILE_NAME);
337 
348  }
349 
356  vxReleaseImage(&rgb_image);
357  vxReleaseImage(&nv12_image);
358  vxReleaseImage(&y_image);
367  vxReleaseNode(&node0);
368  vxReleaseNode(&node1);
377  vxReleaseGraph(&graph);
388  vxReleaseContext(&context);
391  printf(" vx_tutorial_image_color_convert: Tutorial Done !!! \n");
392  printf(" \n");
393 }
394 
395 #define MAX_ATTRIBUTE_NAME (32u)
396 
407 {
408  vx_uint32 num_nodes=0, num_params=0, ref_count=0;
409  vx_enum state=0;
410  vx_perf_t perf={0};
411  vx_char *ref_name=NULL;
412  char ref_name_invalid[MAX_ATTRIBUTE_NAME];
413  char state_name[MAX_ATTRIBUTE_NAME];
414 
421  vxQueryGraph(graph, (vx_enum)VX_GRAPH_NUMNODES, &num_nodes, sizeof(vx_uint32));
422  vxQueryGraph(graph, (vx_enum)VX_GRAPH_NUMPARAMETERS, &num_params, sizeof(vx_uint32));
423  vxQueryGraph(graph, (vx_enum)VX_GRAPH_STATE, &state, sizeof(vx_enum));
424  vxQueryGraph(graph, (vx_enum)VX_GRAPH_PERFORMANCE, &perf, sizeof(vx_perf_t));
427  vxQueryReference((vx_reference)graph, (vx_enum)VX_REFERENCE_NAME, &ref_name, sizeof(vx_char*));
428  vxQueryReference((vx_reference)graph, (vx_enum)VX_REFERENCE_COUNT, &ref_count, sizeof(vx_uint32));
429 
430  switch(state)
431  {
433  strncpy(state_name, "VX_GRAPH_STATE_UNVERIFIED", MAX_ATTRIBUTE_NAME);
434  break;
436  strncpy(state_name, "VX_GRAPH_STATE_VERIFIED", MAX_ATTRIBUTE_NAME);
437  break;
439  strncpy(state_name, "VX_GRAPH_STATE_RUNNING", MAX_ATTRIBUTE_NAME);
440  break;
442  strncpy(state_name, "VX_GRAPH_STATE_ABANDONED", MAX_ATTRIBUTE_NAME);
443  break;
445  strncpy(state_name, "VX_GRAPH_STATE_COMPLETED", MAX_ATTRIBUTE_NAME);
446  break;
447  default:
448  strncpy(state_name, "VX_GRAPH_STATE_UNKNOWN", MAX_ATTRIBUTE_NAME);
449  break;
450  }
451 
452  if(ref_name==NULL)
453  {
454  strncpy(ref_name_invalid, "INVALID_REF_NAME", MAX_ATTRIBUTE_NAME);
455  ref_name = &ref_name_invalid[0];
456  }
457 
458  printf(" VX_TYPE_GRAPH: %s, %d nodes, %s, avg perf %9.6fs, %d parameters, %d refs\n",
459  ref_name,
460  num_nodes,
461  state_name,
462  perf.avg/1000000000.0,
463  num_params,
464  ref_count
465  );
466 }
467 
478 {
479  vx_uint32 num_params=0, ref_count=0;
481  vx_perf_t perf={0};
482  vx_char *ref_name=NULL;
483  char ref_name_invalid[MAX_ATTRIBUTE_NAME];
484  char status_name[MAX_ATTRIBUTE_NAME];
485 
492  vxQueryNode(node, (vx_enum)VX_NODE_STATUS, &status, sizeof(vx_status));
493  vxQueryNode(node, (vx_enum)VX_NODE_PARAMETERS, &num_params, sizeof(vx_uint32));
494  vxQueryNode(node, (vx_enum)VX_NODE_PERFORMANCE, &perf, sizeof(vx_perf_t));
497  vxQueryReference((vx_reference)node, (vx_enum)VX_REFERENCE_NAME, &ref_name, sizeof(vx_char*));
498  vxQueryReference((vx_reference)node, (vx_enum)VX_REFERENCE_COUNT, &ref_count, sizeof(vx_uint32));
499 
500  switch(status)
501  {
502  case (vx_status)VX_SUCCESS:
503  strncpy(status_name, "VX_SUCCESS", MAX_ATTRIBUTE_NAME);
504  break;
505  case (vx_status)VX_FAILURE:
506  strncpy(status_name, "VX_FAILURE", MAX_ATTRIBUTE_NAME);
507  break;
508  default:
509  strncpy(status_name, "VX_FAILURE_OTHER", MAX_ATTRIBUTE_NAME);
510  break;
511  }
512 
513  if(ref_name==NULL)
514  {
515  strncpy(ref_name_invalid, "INVALID_REF_NAME", MAX_ATTRIBUTE_NAME);
516  ref_name = &ref_name_invalid[0];
517  }
518 
519  printf(" VX_TYPE_NODE: %s, %d params, avg perf %9.6fs, %s, %d refs\n",
520  ref_name,
521  num_params,
522  perf.avg/1000000000.0,
523  status_name,
524  ref_count
525  );
526 }
struct _vx_image * vx_image
vx_uint64 avg
vx_bool
vx_false_e
#define IN_FILE_NAME
Input file name.
vx_status VX_API_CALL vxQueryImage(vx_image image, vx_enum attribute, void *ptr, vx_size size)
void vx_tutorial_image_color_convert()
Tutorial Entry Point.
Interface to TI extension APIs.
VX_GRAPH_STATE
int32_t vx_enum
vx_node VX_API_CALL vxChannelExtractNode(vx_graph graph, vx_image input, vx_enum channel, vx_image output)
VX_SUCCESS
vx_status VX_API_CALL vxQueryGraph(vx_graph graph, vx_enum attribute, void *ptr, vx_size size)
vx_status VX_API_CALL vxQueryReference(vx_reference ref, vx_enum attribute, void *ptr, vx_size size)
VX_GRAPH_PERFORMANCE
char vx_char
VX_DF_IMAGE_U8
vx_status VX_API_CALL vxReleaseContext(vx_context *context)
vx_enum vx_status
VX_NODE_PERFORMANCE
struct _vx_context * vx_context
vx_status VX_API_CALL tivxExportGraphToDot(vx_graph graph, const char *output_file_path, const char *output_file_prefix)
Export graph representation as DOT graph file.
struct _vx_reference * vx_reference
VX_GRAPH_STATE_ABANDONED
uint32_t vx_df_image
VX_IMAGE_WIDTH
vx_image VX_API_CALL vxCreateImage(vx_context context, vx_uint32 width, vx_uint32 height, vx_df_image color)
VX_GRAPH_STATE_UNVERIFIED
vx_status VX_API_CALL vxWaitGraph(vx_graph graph)
#define OUT_FILE_NAME
Output file name.
vx_status VX_API_CALL vxReleaseGraph(vx_graph *graph)
VX_NODE_STATUS
vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx_char *name)
void show_node_attributes(vx_node node)
Show attributes of previously created node.
vx_status VX_API_CALL vxQueryNode(vx_node node, vx_enum attribute, void *ptr, vx_size size)
VX_FAILURE
void show_image_attributes(vx_image image)
Show attributes of previously created image.
vx_image tivx_utils_create_vximage_from_bmpfile(vx_context context, const char *filename, vx_bool convert_to_gray_scale)
Create a image data object given BMP filename as input.
VX_GRAPH_STATE_COMPLETED
VX_CHANNEL_Y
vx_node VX_API_CALL vxColorConvertNode(vx_graph graph, vx_image input, vx_image output)
uint32_t vx_uint32
vx_graph VX_API_CALL vxCreateGraph(vx_context context)
VX_DF_IMAGE_NV12
vx_status VX_API_CALL vxVerifyGraph(vx_graph graph)
vx_status VX_API_CALL vxScheduleGraph(vx_graph graph)
vx_context VX_API_CALL vxCreateContext()
VX_GRAPH_NUMPARAMETERS
struct _vx_graph * vx_graph
VX_NODE_PARAMETERS
vx_status VX_API_CALL vxReleaseNode(vx_node *node)
void show_graph_attributes(vx_graph graph)
Show attributes of previously created graph.
vx_status tivx_utils_save_vximage_to_bmpfile(const char *filename, vx_image image)
Save data from image object to PNG file.
struct _vx_node * vx_node
vx_status VX_API_CALL vxReleaseImage(vx_image *image)
VX_GRAPH_NUMNODES
VX_GRAPH_STATE_RUNNING
vx_image VX_API_CALL vxCreateVirtualImage(vx_graph graph, vx_uint32 width, vx_uint32 height, vx_df_image color)
VX_GRAPH_STATE_VERIFIED
VX_IMAGE_HEIGHT