TIOVX User Guide
export_image.py
1 #
2 # Copyright (c) 2017 Texas Instruments Incorporated
3 #
4 # All rights reserved not granted herein.
5 #
6 # Limited License.
7 #
8 # Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
9 # license under copyrights and patents it now or hereafter owns or controls to make,
10 # have made, use, import, offer to sell and sell ("Utilize") this software subject to the
11 # terms herein. With respect to the foregoing patent license, such license is granted
12 # solely to the extent that any such patent is necessary to Utilize the software alone.
13 # The patent license shall not apply to any combinations which include this software,
14 # other than combinations with devices manufactured by or for TI ("TI Devices").
15 # No hardware patent is licensed hereunder.
16 #
17 # Redistributions must preserve existing copyright notices and reproduce this license
18 # (including the above copyright notice and the disclaimer and (if applicable) source
19 # code license limitations below) in the documentation and/or other materials provided
20 # with the distribution
21 #
22 # Redistribution and use in binary form, without modification, are permitted provided
23 # that the following conditions are met:
24 #
25 # No reverse engineering, decompilation, or disassembly of this software is
26 # permitted with respect to any software provided in binary form.
27 #
28 # any redistribution and use are licensed by TI for use only with TI Devices.
29 #
30 # Nothing shall obligate TI to provide you with source code for the software
31 # licensed and provided to you in object code.
32 #
33 # If software source code is provided to you, modification and redistribution of the
34 # source code are permitted provided that the following conditions are met:
35 #
36 # any redistribution and use of the source code, including any resulting derivative
37 # works, are licensed by TI for use only with TI Devices.
38 #
39 # any redistribution and use of any object code compiled from the source code
40 # and any resulting derivative works, are licensed by TI for use only with TI Devices.
41 #
42 # Neither the name of Texas Instruments Incorporated nor the names of its suppliers
43 #
44 # may be used to endorse or promote products derived from this software without
45 # specific prior written permission.
46 #
47 # DISCLAIMER.
48 #
49 # THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
50 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 # IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
56 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
57 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58 # OF THE POSSIBILITY OF SUCH DAMAGE.
59 #
60 #
61 
62 from . import *
63 import subprocess
64 
65 
83 class ExportImage (Export) :
84 
87  def __init__(self, context) :
88  Export.__init__(self, context)
89  self.filename_prefix = context.name
90  self.filename = context.name + "_img.txt"
91  self.filenameJpg = context.name + ".jpg"
92  self.file = None
93 
94  def getDataColor(self, ref) :
95  return "GhostWhite"
96 
97  def getTargetColor(self, target) :
98  if target == Target.DSP1 :
99  return "palegreen"
100  if target == Target.DSP2 :
101  return "darkturquoise"
102  if target == Target.EVE1 :
103  return "yellow"
104  if target == Target.EVE2 :
105  return "gold"
106  if target == Target.EVE3 :
107  return "orange"
108  if target == Target.EVE4 :
109  return "goldenrod4"
110  if target == Target.A15_0 :
111  return "lightblue"
112  if target == Target.MCU2_0 :
113  return "grey"
114  if target == Target.MCU2_1 :
115  return "LightSalmon"
116  if target == Target.IPU2 :
117  return "MediumOrchid"
118  return "white"
119 
120  def __str__(self) :
121  file = open(self.filename,'r')
122  str = 'Export Image [' + self.filename + ' ]\n'
123  str += file.read()
124  file.close()
125  return str
126 
127  def outputTarget(self, target) :
128  self.file.write(' <TR><TD bgcolor="%s">%s</TD></TR>' % (self.getTargetColor(target), target.name))
129 
130  def outputTargetList(self) :
131  self.file.write(' ColorScheme [shape=none, margin=0, label=<\n')
132  self.file.write(' <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">\n')
133  for target in self.context.target_list :
134  self.outputTarget(target)
135  self.file.write(' </TABLE>>];\n')
136  self.file.write('\n')
137  self.file.write('\n')
138 
139  def outputData(self, data) :
140  self.file.write(' %s [color=%s, style=filled]\n' % (data.name, self.getDataColor(data)))
141 
142  def outputDataList(self) :
143  self.file.write('\n')
144  self.file.write(' /* DATA OBJECTS */\n')
145  for ref in self.context.data_list :
146  self.outputData(ref)
147  self.file.write('\n')
148 
149  def outputNode(self, node) :
150  self.file.write(' %s [label=\"%s (%s)\", color=%s, style=filled]\n' % (node.name, node.name, node.kernel, self.getTargetColor(node.target)) )
151 
152  def outputNodeList(self) :
153  self.file.write('\n')
154  self.file.write(' /* NODE OBJECTS */\n')
155  for ref in self.context.node_list :
156  self.outputNode(ref)
157  self.file.write('\n')
158 
159  def outputNodeConnection(self, node) :
160  idx = 0
161  for dir in node.param_dir :
162  if dir == Direction.INPUT :
163  self.file.write(' %s -> %s [taillabel=%d, labeldistance=3]\n' % (node.ref[idx].name, node.name, idx))
164  else :
165  self.file.write(' %s -> %s [headlabel=%d, labeldistance=3]\n' % (node.name, node.ref[idx].name, idx))
166  idx = idx + 1
167 
168  def outputNodeConnectionList(self) :
169  self.file.write('\n')
170  self.file.write(' /* NODE CONNECTIONS */\n')
171  for node in self.context.node_list :
172  self.outputNodeConnection(node)
173  self.file.write('\n')
174 
175 
177  def export(self) :
178  print ('Generating image from OpenVX context ...')
179  print ('dot tool input file is [%s] ...' % self.filename)
180  print ('dot tool output file is [%s] ...' % self.filenameJpg)
181 
182  self.file = open(self.filename, 'w')
183  self.file.write('digraph %s {\n' % self.context.name)
184  self.file.write('\n')
185  self.file.write(' label = \"%s\"\n' % self.context.name)
186  self.outputTargetList()
187  self.outputDataList()
188  self.outputNodeList()
190  self.file.write('\n')
191  self.file.write('}\n')
192  self.file.close()
193 
194  try :
195  command_str = 'dot %s -Tjpg -o%s' % (self.filename, self.filenameJpg)
196  command_args = ['dot', self.filename, '-Tjpg','-o%s' % self.filenameJpg]
197  print('Executing dot tool command ... [' + command_str + ']')
198  subprocess.call(command_args)
199  print ('Generating image from OpenVX context ... DONE !!!')
200  except FileNotFoundError:
201  print('ERROR: \'dot\' tool not found. Make sure \'graphviz\' is installed and \'dot\' command is added to system PATH !!!')
202  print('ERROR: Cannot generate .jpg file !!!')
203 
Export objects from context to JPG image file.
Definition: export_image.py:83
def getTargetColor(self, target)
Definition: export_image.py:97
def outputTarget(self, target)
def outputNodeConnection(self, node)
def export(self)
Export object as C source code.
def __init__(self, context)
Constructor used to create this object.
Definition: export_image.py:87