home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 August - Disc 2 / chip_20018102_hu.iso / linux / X-4.1.0 / doc / xieSIarch.TXT < prev    next >
Text File  |  2001-06-27  |  102KB  |  1,621 lines

  1.  
  2. XIE Sample Implementation Architecture
  3.  
  4.  
  5. Authors
  6.  
  7. Robert NC Shelley
  8. Dean A. Verheiden
  9. J. Ben Fahy
  10.  
  11. Sample Implementation Team
  12. AGE Logic, Inc.
  13.  
  14.  
  15.  
  16.  
  17. Additional Contributors
  18. Larry Hare
  19. AGE Logic, Inc.
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. Comments concerning the SI architecture should be submitted by electronic mail to:
  28. imagework@x.org
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. Copyright Notice
  36.  
  37. This document is being provided by AGE Logic, Inc. and MIT under the following license.  By obtaining, using
  38. and/or copying this documentation, you agree that you have read, understood, and will comply with these terms
  39. and conditions:
  40.  
  41. Permission to use, copy, modify, distribute and sell this documentation for any purpose and
  42. without fee or royalty and to grant others any and all rights granted herein is hereby granted,
  43. providing that you agree to comply with the following copyright notice and statements, including
  44. the disclaimer, and that the same appears on all copies and derivative works of the document that
  45. you make.
  46.  
  47. Copyright 1993  by AGE Logic, Inc.  and the Massachusetts Institute of Technology
  48.  
  49. THIS DOCUMENT IS PROVIDED "AS IS".  AGE LOGIC AND MIT MAKE NO REPRESENTATIONS
  50. OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not limitation, AGE LOGIC AND
  51. MIT MAKE NO REPRESENTATION OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
  52. ANY PARTICULAR PURPOSE OR THAT THE DOCUMENT DOES NOT INFRINGE THIRD-PARTY
  53. PROPRIETARY RIGHTS.  AGE LOGIC AND MIT SHALL BEAR NO LIABILITY FOR ANY USE OF
  54. THIS DOCUMENT.  IN NO EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
  55. INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF PROFITS,
  56. REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR ANY THIRD PARTY, WHETHER IN
  57. AN ACTION IN CONTRACT OR TORT OR BASED ON A WARRANTY, EVEN IF AGE LOGIC OR
  58. MIT OR LICENSEES HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  59. DAMAGES.
  60.  
  61. The names of AGE Logic and MIT may not be used in advertising or publicity pertaining to the
  62. document or software without specific, written prior permission from AGE Logic and MIT.
  63.  
  64.  
  65.  
  66.  
  67. Acknowledgments
  68.  
  69. XIE has evolved from the original specifications and sample implementation developed by Digital Equipment
  70. Corporation and contributed to the X Consortium.
  71. We wish to thank Digital Equipment Corporation and Hewlett-Packard Co. for contributing their pipeline
  72. implementations to the X Consortium.  The SI architecture has benefited from these efforts.
  73.  
  74.  
  75. Table of Contents
  76. Copyright Notice        ii
  77. Acknowledgments iii
  78. Table of Contents       iv
  79. 1.      Introduction    1
  80. 1.1.    Task Definition 1
  81. 1.2.    Design Goals    2
  82. 1.3.    Document Organization   3
  83. 2.      Architecture Overview   4
  84. 2.1.    X/XIE Interfacing       4
  85. 2.2.    XIE Components  5
  86. 2.2.1.  Photoflo Compiler       6
  87. 2.2.2.  The Photoflo Linker     12
  88. 2.2.3.  The Photoflo Runtime Manager    13
  89. 2.2.3.1.        Scheduler       14
  90. 2.2.3.2.        Data flo Manager        15
  91. 2.2.4.  The XIE Resource Manager        15
  92. 2.2.5.  The XIE Memory Manager  15
  93. 3.      Extension Initialization        16
  94. 4.      Memory Management       17
  95. 5.      Dispatching requests    18
  96. 6.      Data Representations    19
  97. 6.1.    Canonic Data    19
  98. 6.2.    Non-canonic Data        19
  99. 6.2.1.  Byte Stream Data        19
  100. 6.2.2.  Compressed Data 19
  101. 6.2.3.  Run-length Data 20
  102. 6.3.    Tri-chromatic Data      20
  103. 6.4.    Strips  20
  104. 7.      Data Structures 21
  105. 7.1.    Data Formats    21
  106. 7.1.1.  Canonic 21
  107. 7.1.2.  Compressed      21
  108. 7.1.3.  Lookup-table    22
  109. 7.2.    Resource structures     22
  110. 7.2.1.  ColorList       22
  111. 7.2.2.  LUT     22
  112. 7.2.3.  Photomap        22
  113. 7.2.4.  ROI     22
  114. 7.2.5.  Photospace      23
  115. 7.2.6.  Photoflo        23
  116. 7.3.    Photo Element Definition        24
  117. 7.4.    DDXIE Structures        25
  118. 7.4.1.  Photoflo run-time context       25
  119. 7.4.2.  Photo Element run-time context  25
  120. 7.4.3.  Receptor        25
  121. 7.4.4.  Strip   25
  122. 8.      Protocol requests       26
  123. 8.1.    Global Query requests   26
  124. 8.1.1.  QueryImageExtension     26
  125. 8.1.2.  QueryTechniques 26
  126. 8.2.    Resource requests       27
  127. 8.2.1.  Overview        27
  128. 8.2.1.1.        Creating Resources      27
  129. 8.2.1.2.        Flo'ing Resources       27
  130. 8.2.1.3.        Destroying Resources    27
  131. 8.2.2.  ColorList       28
  132. 8.2.2.1.        Create  28
  133. 8.2.2.2.        Query   28
  134. 8.2.2.3.        Purge   28
  135. 8.2.2.4.        Destroy 28
  136. 8.2.3.  LUT     28
  137. 8.2.3.1.        Create  28
  138. 8.2.3.2.        Destroy 28
  139. 8.2.4.  Photomap        29
  140. 8.2.4.1.        Create  29
  141. 8.2.4.2.        Query   29
  142. 8.2.4.3.        Destroy 29
  143. 8.2.5.  ROI     29
  144. 8.2.5.1.        Create  29
  145. 8.2.5.2.        Destroy 29
  146. 8.3.    Photoflo related requests       30
  147. 8.3.1.  ServerIDspace   30
  148. 8.3.2.  Photospace      30
  149. 8.3.2.1.        Create  30
  150. 8.3.2.2.        Destroy 30
  151. 8.3.3.  Immediate-mode specific 30
  152. 8.3.3.1.        ExecuteImmediate        30
  153. 8.3.4.  Stored-mode specific    31
  154. 8.3.4.1.        Create  31
  155. 8.3.4.2.        Modify  31
  156. 8.3.4.3.        Redefine        31
  157. 8.3.4.4.        Execute 31
  158. 8.3.4.5.        Destroy 31
  159. 8.3.5.  ClientData transport    32
  160. 8.3.5.1.        Put     32
  161. 8.3.5.2.        Get     32
  162. 8.3.6.  Query/Control   32
  163. 8.3.6.1.        Query   32
  164. 8.3.6.2.        Await   32
  165. 8.3.6.3.        Abort   32
  166. 9.      DIXIE Photoflo Management       33
  167. 9.1.    Overview        33
  168. 9.2.    Photoflo Creation       33
  169. 9.2.1.  Creating the Flo        33
  170. 9.2.2.  Traversing the DAG      34
  171. 9.2.3.  Registering the Flo     36
  172. 9.3.    Photoflo Execution      37
  173. 9.3.1.  Prepping the DAG        37
  174. 9.3.2.  Analyzing the DAG       37
  175. 9.3.3.  Linking an executable Photoflo  37
  176. 9.3.4.  Starting the flo        37
  177. 9.3.5.  Resuming the flo        38
  178. 9.3.6.  Stopping the flo        38
  179. 9.3.7.  Destroying an executable Photoflo       38
  180. 9.3.8.  Event notification from a flo   38
  181. 10.     DDXIE Photoflo Management       39
  182. 10.1.   DAG Analysis    39
  183. 10.1.1. Choosing Element Handlers       39
  184. 10.1.2. Choosing a Linker and Photoflo Manager  41
  185. 10.2.   Photoflo Linker 41
  186. 10.3.   Photoflo manager        42
  187. 10.3.1. Startup 42
  188. 10.3.2. Scheduling      42
  189. 10.3.3. Data Manager    44
  190. 10.3.4. Input   46
  191. 10.3.5. Output  46
  192. 10.3.6. Query   46
  193. 10.3.7. Abort   46
  194. 10.3.8. Destroy 46
  195. 11.     Photo Elements  47
  196. 11.1.   Element Structures      47
  197. 11.2.   Element Interfaces      48
  198. 11.2.1. Create  48
  199. 11.2.2. Initialize      48
  200. 11.2.3. Activate        48
  201. 11.2.4. Flush   48
  202. 11.2.5. Reset   48
  203. 11.2.6. Destroy 48
  204.  
  205.  
  206.  
  207. 1.      Introduction
  208. The X windows Image Extension (XIE) project was initiated in 1988 by Joe Mauro of Digital Equipment
  209. Corporation,  in order to meet the needs of those wanting improved imaging facilities within X.  XIE is targeted at
  210. the problem of image display,  and rendering any digital image on any X-capable hardware.  XIE is not intended to
  211. be a general purpose image processing engine, although it does provide a rich environment for performing simple
  212. image enhancement operations and format conversions.  XIE also permits the support of image-specific hardware
  213. in the server,  including but not limited to decompression, scaling, rotation and convolution accelerators.
  214. The X Consortium accepted XIE into Technical Review in March of 1991.  After over a year and a half of debate
  215. and analysis by a number of interested Consortium members,  a revised Version 4.12 of the XIE protocol was
  216. passed out of Technical Review and into Public Review.  The Public Review period is scheduled to expire April
  217. 23rd, 1993.   It is the goal of the Consortium that XIE will be made widely available shortly after acceptance as an
  218. official standard,  and therefore AGE Logic, Inc. has been commissioned to provide a Sample Implementation (SI)
  219. of XIE,  to be distributed as part of the December 1993 X windows R6 release.  This document describes AGE
  220. Logic's initial design of the XIE SI architecture.
  221. The audience of this document is anticipated to be X Consortium members who have a working understanding of
  222. XIE,  either through participating in its design within the Consortium, or by having read the latest version of the
  223. XIE protocol, by Shelley et al.,  published in Special Issue C of  The X Resource journal.  An overview of XIE by
  224. Fahy and Shelley is also provided in the same issue.  Other references of interest would include The X Window
  225. System Server by Israel and Fortune,  and X Window System by Scheifler and Gettys.
  226.  
  227.  
  228. 1.1.    Task Definition
  229. XIE is defined by the protocol document referenced in the previous section.  XIE requests are channeled through
  230. the Core X dispatch loop to the dispatchers (swapped and unswapped) for the XIE SI.  XIE-specific events and
  231. errors are originated in SI and routed back through Core X to the waiting client.
  232. XIE defines six new resources:  ColorLists, LUTs, Photoflos, Photomaps, Photospaces, and ROIs.  Each of these
  233. resources must be recorded with Core X,  so that at client shutdown the resources may be freed reliably.
  234. In the XIE computational model, a client provides a blueprint for a computational engine, a photoflo,  and passes it
  235. to the server for execution  The blueprint is a directed acyclic graph (DAG),  which shows what the components
  236. (elements) of the engine are, and how data flows between them.  Import elements receive data from the client, Core
  237. X,  or from resources.  Processing elements receive data from import elements or upstream processing elements,
  238. perform a specified operation on the data,  and pass the data on downstream.  Export elements define the exit point
  239. of data from the photoflo.  Data from Import or Processing elements may be routed to the client, Core X, or an XIE
  240. resource simply by adding an Export connection after the element of interest.
  241. Processing,  Import, and Export elements are defined at two levels.  For example,  a Geometry element states that
  242. incoming image data is to be re-sampled to produce a new output image.  The specific sampling mechanism is
  243. selected by using a set of technique parameters in the element specification.  Thus, technique parameters give fine-
  244. grain information on how a course-grain operation (such as geometric transformation) is to be performed.
  245.  
  246. To summarize the tasks which the SI must perform, it must:
  247. 1.      Integrate into Core X
  248. 2.      Receive and correctly interpret XIE-specific requests
  249. 3.      Manage XIE-specific resources
  250. 4.      Build computational engines (photoflos) according to the blueprints (DAGs) provided
  251. 5.      Execute the photoflos
  252. 6.      Return error and event information as required.
  253.  
  254. Building and executing the photoflos necessitates:
  255. 1.      Parsing the DAG information
  256. 2.      Performing semantic analysis
  257. 3.      Matching sub-tasks (defined by elements, etc.)  to machine-specific code
  258. 4.      Scheduling execution
  259. 5.      Managing data flow.
  260. 6.      Handling special conditions,  including shutdown and return of control.
  261.  
  262. Note that the SI must be able to support multiple photoflos executing simultaneously,  and thus all photoflo and
  263. element code must be reentrant,  and data structures must not be written so as to preclude reentrancy.
  264.  
  265. 1.2.    Design Goals
  266. The MIT X Consortium,  in soliciting for bids on the SI project, has previously stated the following design
  267. requirements:
  268. 1.      The SI must be easily ported to many different platforms.
  269. 2.      The SI must be modular, to support easy customization.
  270. 3.      Performance should be commercial quality.
  271. 4.      Performance should not be biased to a particular machine architecture (e.g.,  big endian machines should
  272. have performance comparable with little endian machines of the same approximate raw speed).
  273. 5.      The SI should accommodate servers with limited memory.
  274.  
  275. An additional, implied requirement is:
  276. 6.      Design of the SI should be minimal risk.
  277.  
  278. That is,  it must be acknowledged that while there are any number of ways in which photoflo optimizers and
  279. schedulers could be implemented,  the overriding goal must be to ensure that an SI is available in time for the R6
  280. release of X windows.
  281.  
  282. 1.3.    Document Organization
  283. This chapter has provided a brief introduction to the topic of designing a sample implementation of the X image
  284. extension.  The next chapter provides an overview of the architecture as the design currently stands.  It starts by
  285. looking at XIE from a very high conceptual level and working its way down examining a few of the SI's major
  286. building blocks.
  287. The next three chapters discuss in more detail: extension initialization,  memory management,  and the
  288. dispatching of requests through Core X.   They are followed by a brief description of a some  high-level  data
  289. representations, followed by a detailed exposition of critical data structures.  These chapters serve as references for
  290. the chapters that follow.
  291.  The eighth chapter discusses the implementation ramifications of XIE requests,  up to the topic of photoflo
  292. management in the server.  That issue is covered in detail in chapters nine and ten,  which are split across device-
  293. independent / device-dependent lines.  The final chapter discusses elements; their data structures and interfaces.
  294.  
  295.  
  296.  
  297. 2.      Architecture Overview
  298.  
  299. Core  X is divided into device-independent (dix) and device-dependent (ddx) layers.  The dix layer contains code
  300. and data structures which should not need to be altered in porting X from one machine to another.  The ddx code is
  301. where device-specific information, such as drivers for special hardware,  assembly routines for optimized graphics,
  302. etc., are placed.  The dix layer accesses ddx code by calling ddx procedures indirectly, through a list of well-
  303. defined entry points stored in dix resources.
  304. The design of XIE is intentionally modeled so as to follow the same basic form.  XIE is divided into a device-
  305. independent layer called dixie,  and a device-dependent layer called ddxie.   A set of dixie data structures is
  306. defined,  which includes a list of entry points to ddxie routines.  In the SI,  this list will be filled exclusively with
  307. machine-independent XIE code.  However, in the interest of portability and optimization,  care has been taken to
  308. make it easy to override the generic code with machine-specific routines.  It is anticipated that server implementors
  309. porting to new hardware will create new ddxie subdirectories which are machine dependent,  as is depicted below.
  310.  
  311.  
  312.  
  313.  
  314. 2.1.    X/XIE Interfacing
  315. The figure on the following page illustrates the interface between the new XIE architecture and the existing Core X
  316. server design. All routing of data in or out of XIE must go through Core X.  XIE requests are received by the Core
  317. X dispatcher,  recognized as belonging to XIE,  and the appropriate procedure to receive the request is called.
  318. Similarly,  errors and events generated within XIE are routed back out using standard Core X mechanisms.  Image,
  319. LUT, and ROI data is passed from the client to XIE via a PutClientData request,  and thus follows the same route
  320. as normally dispatched data.  Image, LUT and ROI data to be returned to the client is sent via Reply packets, using
  321. the conventional Core X technique.  Finally,  XIE moves data between an XIE photoflo and Core X resources by
  322. making use of the list of Core X entry points described above.
  323.  
  324.  
  325. 2.2.    XIE Components
  326. At the highest level,  XIE may be viewed as containing the components depicted in the figure below  (it also
  327. contains other components, not shown).  Core X provides a resource manager in the dix layer and a memory
  328. manager in ddx.   XIE will provide its own resource and memory managers layered on top of the Core X facilities.
  329. XIE also has its own dispatcher.  Routines within the XIE dispatcher are called when the X dispatcher receives a
  330. request which it recognizes as belonging to the imaging extension.
  331.  
  332. When the request contains the definition of a photoflo,  this definition must be translated into the appropriate code
  333. and data structures required to build and execute the flo.  For this reason, XIE may be viewed as containing a
  334. Photoflo Compiler,  which performs this task.  The output of the compiler is a set of data structures which describe
  335. how the photoflo will be executed, given the existing available code.  Initialization of static variables and resolu-
  336. tion of entry points identified by compilation is the responsibility of the Photoflo compiler. Execution is conducted
  337. by a Photoflo Manager,  which consists of a Scheduler, Dataflo Manager, and other components.  Client data is
  338. input through the XIE dispatcher and given to the Photoflo Manager,  which deposits the data in with the Dataflo
  339. Manager and then wakes up the Scheduler.
  340. 2.2.1.  Photoflo Compiler
  341. The sub-structure of the Photoflo Compiler may be derived by comparing the task of compiling photoflos
  342. to classical compiler problems.  The figure below shows the classical model of a compiler which is pro-
  343. ducing code for the expression  a = bee + cf*d[i],  where cf is floating point and a, bee, and d are inte-
  344. gers.
  345.  
  346. The input to the compiler is simply a stream of bytes,  that is, a followed by = followed by b, followed by
  347. e, etc., with no meaning or structure yet attached to the stream.  Lexical analysis groups the characters to-
  348. gether into the distinct tokens,  a, bee, + , cf, etc. Syntax analysis is used to resolve the order in which
  349. fundamental operations are carried out,  which is represented as a directed graph.  Semantic analysis adds
  350. type and other attribute information to the problem representation.  Note that required type conversions
  351. and operator classes have been made explicit in the output of the Semantic Analyzer. Intermediate Code
  352. Generation converts the DAG representation into a device independent pseudo-language (output not
  353. shown).   The first four phases of the compiler are often grouped together and referred to collectively as
  354. the compiler front end,  which is the device independent part of the compiler.
  355. The back end of a compiler is the device dependent part,  which consists of the optimizer and code gen-
  356. erator.  Most compilers incorporate both device independent and device dependent optimizations.   The
  357. code generator translates from the intermediate language representation to the language of the target ma-
  358. chine.
  359. In attempting to apply the standard compiler model to the problem of photoflo compilation,  a number of
  360. fundamental differences in the two environments must be recognized.  First,  it should be noted that there
  361. is usually a significant delay between when a conventional compiler translates source code into object
  362. code and when the  final executable is eventually run.  This means that the time constraints on the com-
  363. piler are not necessarily severe,  allowing for more extensive optimization.  In contrast, in XIE, it will al-
  364. ways be the case in compiling photoflos that significant parts of the compilation time will occur just before
  365. execution, and add to the perceived execution time.  This is because the XIE protocol expressly forbids re-
  366. solving the attributes of input data before the ExecutePhotoflo (or equivalent) request is given.  This puts a
  367. hold on semantic analysis,  constraining it to wait until just before execution.  Since code generation and
  368. optimization follow the semantic analysis phase of compilation,  these phases are also constrained,  and
  369. the time to carry them out should be kept tightly restricted.  This inhibits exhaustive optimization,  and
  370. encourages very simple code generation strategies.
  371. Another important environmental difference which affects the application of the compiler model is that
  372. most conventional languages expose the canonical data types of the processor fairly conveniently.  The
  373. underlying hardware model assumes registers of a few fixed sizes, whereas in XIE,  the "register size" of
  374. the server is hidden completely. Canonical data types,  such as 1, 8, and 16 bits might be chosen by the
  375. server implementor in order  to reduce the number of cases for which processing elements must be writ-
  376. ten.   However,  this may vary from server to server,  and thus the SI code should not make the decision
  377. that it already knows all of the canonical data types.  Although the SI will support 1, 8, 16 and 32 bit data,
  378. it is also a design goal that the SI be easily extensible if a vendor also wants to support 4 bit data.   This
  379. implies that the type resolution portion of the semantic analyzer must be moved out of the device inde-
  380. pendent front end,  and into the device dependent back end.
  381. The figure below shows the basic compiler model modified to accommodate the XIE computational
  382. model. Only lexical and syntactic analysis may occur prior to receiving the equivalent of an Execute-
  383. Photoflo request.  Lexical analysis in the context  of XIE refers to parsing the raw data stream and break-
  384. ing it into the element definitions, etc.  Syntactic analysis refers to analyzing the DAG to make sure it is
  385. legal (e.g. contains no cycles). As the DAG is analyzed, the dixie data structures which describe it are
  386. filled in.
  387.  
  388. The semantic analyzer is split into device independent and device dependent portions.  Propagation of
  389. attributes from import elements to downstream elements occurs in the device independent part of the
  390. semantic analyzer,  whereas type resolution requires device dependent information.  Both parts of the
  391. semantic analyzer fill in structures in the dix layer of XIE (see figure, following page).  The difference is
  392. that the attribute analyzer does not use any device independent information to produce its data,  whereas
  393. the type resolution code does.
  394.  
  395. The code generator has the task of accepting the device-independent photoflo representation as input,  and
  396. filling in the device-dependent data structures which implement the photoflo.  Because code generation
  397. may be closely coupled with type resolution, the SI groups these two operations into a DAG Analyzer,  as
  398. is depicted in the figure below.  The SI will include a default machine independent DAG Analyzer which
  399. handles type resolution by a simple type upgrading scheme,  and which generates code by mapping di-
  400. rectly from elements defined in the DAG to mi element handlers. The design accommodates substitution
  401. of a device dependent DAG Analyzer,  however,  which can choose to perform special optimizations,
  402. support non-SI canonical data types,  and employ a machine-dependent element interface.
  403.  
  404.  
  405. The figure below illustrates the fundamental task of the DAG Analyzer.  A Photoflo to be compiled is
  406. shown at the left,  in which a one-bit image is imported as a process domain,  a 4 bit image is imported
  407. and convolved,  the output is constrained, and a lookup table transformation is applied using Point.  The
  408. XIE server implements Point, Convolve, Constrain, ..., operations on various canonical data types.  By
  409. definition,  element handlers only accept canonical data as input,  and only produce it as output.  If  the
  410. routines to perform a convolution can only accept 1,8,16, or unconstrained data,  and the routines to
  411. import client image data can also produce any of these types,  it is necessary to negotiate on which type
  412. should be used between connected elements.
  413.  
  414.  
  415.  
  416. Consider the photoflo depicted below,  which has 4 bit image data being fed to both Convolve and Point.
  417. The user has specified in the protocol that the Point element is to produce data with 128 levels,  which
  418. requires at least 7 bits of storage.  This suggests that the output of the Point element should produce 8 bit
  419. data,  which is the closest canonical form with adequate resolution.
  420.  
  421.  
  422.  
  423. Using the same reasoning,  that is,  that elements should produce as output the smallest-resolution
  424. canonical form which is adequate,  ImportClientPhoto should produce 8 bit data.  This would fix the type
  425. at the input of the Convolve element,  implying that it is necessary to choose a Convolve handler which
  426. accepts 8 bit data.
  427.  
  428.  
  429. Let us now suppose that it is desirable that server implementors be allowed to introduce new canonical
  430. types, such as four bit data.  This would be quite natural on servers which only had four bit deep displays,
  431. and wanted to insure good performance on operations like:
  432.  
  433.  
  434.  
  435.  
  436. Rather than have to convert the 4 bit data to 8 bits,  do an 8 bit Point and then convert back to 4 bits in
  437. ExportDrawable,  it might be more efficient to keep the data as 4 bits throughout. This implies that the
  438. implementor might want to define an ImportClientPhoto handler which could produce 4 bits output,  a
  439. 4->4 Point handler,  and an ExportDrawable handler which accepts 4 bits.  Let us suppose this is
  440. permissible.
  441. Returning to the case of the photoflo containing a Convolve element above,  reapplying the heuristic that
  442. the output of an element should be in the smallest available canonical form which has adequate resolution,
  443. we reach the situation:
  444.  
  445.  
  446. The problem is,  we are now requiring the presence of handlers for Convolve and Point which can accept
  447. 4 bit data and produce unconstrained and 8 bit data, respectively, and these may not exist.  It might be
  448. reasonable to require a 4->8 Point handler, since that may have general utility,  but since Convolve is
  449. fundamentally an unconstrained operation,  it seems overly harsh to force the server implementor to go
  450. through and alter all element handlers like Convolve to include conversions of data types which are not
  451. interesting.  An alternative is to provide mechanism in the dixie structures for a DAG analyzer to be able
  452. to insert "pseudo-elements" which do the conversion  or perform analogous tasks:
  453.  
  454.  
  455.  
  456. Thus,  the SI data structures allow the DAG analyzer to produce a new,  optimized DAG with a different
  457. number of "elements" than the original flo.  The ddxie layer is allowed to define pseudo-elements which
  458. may perform type conversions,  or combine two or more elements into a single "super-element,"  or
  459. perform other functions (for example,  converting a bitonal image into a list of run-lengths,  if it is to be
  460. used as a Process Domain).  This provides a great deal of flexibility for future enhancement and
  461. optimization.
  462.  
  463. The SI DAG Analyzer will employ the following general method:
  464. 1.      For each element defined by the protocol,  and each implementation-specific pseudo-element,  there must
  465. be written at least one handler which is capable of doing processing for that element.
  466. 2.      All handlers will output a type that is the smallest acceptable canonical type for the input data and the
  467. particular operation.
  468. 3.      Prior to trying to find a handler for a particular element,  the DAG Analyzer will propagate the output  types
  469. of all of its source elements to its input data receptors.
  470. 4.      Each handler must provide a test entry point,  which the DAG Analyzer can call providing the photoflo and
  471. tag number of the element to be "compiled".
  472. 5.      The handler's test function will examine the element parameters and the requested input types and return
  473. ACCEPT if it agrees to handle the element, and REJECT otherwise.
  474. 6.      A handler which agrees to accept an element may change the input type coming from any source element by
  475. indicating that a Convert pseudo-element must be inserted between itself and the source.
  476. 7.      If multiple downstream elements require the same conversion, they will share output from the same
  477. converter.
  478.  
  479.  The next figure provides a simplified diagram of relevant data structures.  The DAG analyzer is given a
  480. photoflo,  which is shown at left.  It orders the elements by their distance from the nearest Import element,
  481. and resolves types in the order of increasing distance. The upper right hand corner of the figure shows a
  482. list of handlers associated with each element type.  By the time the DAG analyzer gets to the Convolve
  483. element,  ImportClientPhoto has already been resolved to produce four bit output,  and that "suggested
  484. input type" has been recorded in the input receptor of the Convolve element.
  485.  
  486.  
  487.  
  488. The DAG analyzer looks at its list of handlers which are of type Convolve,  and selects the first member of
  489. that list,  ddConvolve. This handler supports floating point hardware, and as written, does not insert
  490. Conversion pseudo-elements to prepare its input data.  Therefore it rejects the element, and the DAG
  491. analyzer goes on to the next handler in the list for Convolve.
  492. All elements will contain as the last handler in their list a machine independent handler which can accept
  493. any canonical data type.  If the data type matches an explicitly supported type,  the handler loads the entry
  494. point for the specific function and leaves the requested types unchanged.  If the data type is not explicitly
  495. supported,  the handler inserts a Conversion element into the photoflo (these are pre-resolved,  so the
  496. DAG analyzer doesn't have to back up to find a handler for it) and accepts with the nearest sufficient
  497. canonical type which it supports.
  498. The SI will provide mi handlers which can accept any element specified in the protocol.  Note however
  499. that the SI may provide multiple mi handlers for a single element, which may be differentiated by which
  500. techniques they support, etc.
  501. The method described above solves the code generation problem by effectively labeling each element in
  502. the photoflo with a handler.  Discussion of the data flow between elements and scheduling of processing is
  503. deferred to the section on the Photoflo Runtime Manager.
  504.  
  505. 2.2.2.  The Photoflo Linker
  506. After the Photoflo Compiler has resolved data types and handlers for each element,  the Photoflo Linker is
  507. called to perform one-time ("static") initialization of  the photoflo.  It is at this point that the first device-
  508. dependent structures are created,  which provide an execution context for the photoflo and its elements.
  509. Entry points into the photoflo manager are loaded in the dixie flo-def structure, along with entry points to
  510. the flo manager's sub-components, the scheduler and data manager.
  511. Both  the linker and the DAG analyzer portion of the compiler can be skipped if the photoflo has been
  512. executed previously.  This is because the dixie structures retain the one-time initialization state even after
  513. shutdown.  The attribute checking portion of the Semantic Analyzer must (by directive of the protocol) be
  514. re-run at each invocation, but if it discovers that no attributes have changed,  it skips the back end of
  515. compilation and linking, and proceeds directly to execution.
  516.  
  517.  
  518. 2.2.3.  The Photoflo Runtime Manager
  519. Photoflo management is partially the responsibility of the client, and partially the responsibility of the
  520. server.  The client sends Execute, PutClientData, GetClientData, QueryPhotoflo, Await and Abort re-
  521. quests which the server must accommodate.  Specific Procs in the XIE dispatcher receive these requests,
  522. and after possibly making other internal server calls (e.g., ProcExecute may call the compiler or linker
  523. first), route control to the Photoflo Manager,  which resides in ddxie.
  524.  
  525. The entry points of each photoflo manager component are placed in the dixie data structures.  Thus, the
  526. photoflo manager is purposely designed to support ample customization, at several different levels.  For
  527. example,  an md scheduler could be substituted, while to using other components from the mi photoflo
  528. manager.  The selection of which components to use could be determined by the nature of the photoflo.
  529. For example, the general-case mi photoflo manager could be chosen if the DAG is topologically complex,
  530. whereas a simpler photoflo manager might be appropriate for linear photoflos.
  531.  
  532. 2.2.3.1.        Scheduler
  533. The scheduler is responsible for managing the activation of elements in order to move data
  534. through the photoflo.  The SI provides a default scheduler in the mi layer,  which may be over-
  535. ridden by a device-dependent scheduler by the server implementor.
  536. Any scheduler has the following responsibilities:
  537. 1.      When data arrives from the client,  it must be delivered to the appropriate receiving element.
  538. 2.      Elements which have filled their output buffers must be suspended until there is room to generate
  539. more output.
  540. 3.      Elements which have sufficient data to begin processing must eventually be activated, to avoid
  541. deadlock.
  542. In addition there are the following issues to be dealt with:
  543. 1.      Low-memory servers should minimize the requirement of large data buffers within the photoflo,
  544. possibly at the expense of some performance loss.
  545. 2.      High-memory servers should maximize efficiency,   possibly at the expense of using more mem-
  546. ory in photoflo data structures.
  547. 3.      For slow operations,  it may be desirable to minimize the initial delay to receiving data in export
  548. elements.
  549. 4.      For fast operations,  it may be desirable to maximize performance,  so as to increase the number
  550. of operations per second which can be carried out.
  551.  
  552. Consideration of the above issues and responsibilities leads to the notion of letting elements pro-
  553. duce a configurable number of lines when activated.  If an element only produces one line at a
  554. time and then returns to the scheduler for permission to proceed further,  excessive overhead may
  555. result.  If an element on the other hand waits for all input data to proceed and then produces all
  556. output data at once,  excessive memory usage in the photoflo may occur.
  557. The SI scheduler supports elements that can produce their output data in strips, that is,  a fixed
  558. number of lines at a time.  The number of lines in  a strip will vary among elements and even
  559. servers,  since memory/performance tradeoffs in the scheduler will tend to vary with the same
  560. tradeoffs in the server.  Thus, the number of lines in a strip for any element is set by that ele-
  561. ment's ddx-level handler,  at link time.  At the same time,  a minimum number of lines of input
  562. which are required to commence processing are also recorded in the element's receptor data
  563. structures.
  564. Another concern of the scheduler implied by the above issues and responsibilities is to maintain
  565. an even flow of data through the photoflo.  If the scheduler simply finds an element which can be
  566. activated and repeatedly executes it until all input data is exhausted,  the data may wind up
  567. moving slowly through the photoflo in large chunks,  as if the strip sizes were equal to the entire
  568. output image.  Thus the SI scheduler attempts to balance the flow of data  by reducing the  prior-
  569. ity of elements which have recently been activated,  and increasing the priority of elements which
  570. have recently received data.  The SI scheduler will also yield to the client when it has finished
  571. processing all elements since the last client yield,  presuming there is more data which the client
  572. is obligated to send.
  573. To summarize the heuristics upon which the SI scheduler are based:
  574. 1.      elements produce output several lines at a time instead of one or all,  to avoid thrashing in the
  575. first place and heavy memory consumption in the second.
  576. 2.      the scheduler yields to Core X if there is pending client input data,  after checking to make sure
  577. that all elements which are capable of processing have had a turn since the last yield.
  578. 3.      elements which have recently been executed have their priorities downgraded.
  579. 4.      elements which have recently received data have their priority upgraded.
  580. Details of the actual algorithm employed for scheduling may be found in the last chapter on
  581. DDXIE Photoflo Management.
  582.  
  583. 2.2.3.2.        Data flo Manager
  584. The data flo manager has the responsibility of moving data between the elements which produce
  585. it to the elements that consume it.  In order to minimize overhead,  pointers to the data are ex-
  586. changed, rather than copying the data itself.
  587. In this model, an element requests a pointer to an output strip from the data flo manager when it
  588. is ready to execute. The element maintains exclusive control over that strip while it is processing
  589. its data and placing it in the strip. Once the element has finished with the strip, it calls the data
  590. flo manager to pass it to downstream receiving elements.
  591. After being informed that a strip has been completed, the data flo manager determines which
  592. downstream element receptors are in need of the data. A pointer to the strip is then added to the
  593. end of each such receptors input strip list.
  594. For the receiving elements,  the strips will usually be read-only,  unless the elements requests and
  595. receives permission to re-use the input strip for storing its output. Macros will be provided as a
  596. tool to hide the stripped nature of the data. While using these macros will avoid problems asso-
  597. ciated with downstream elements consuming strip output at different rates, elements will have
  598. the option of accessing data on a whole strip basis if they so desire.
  599. Details of the actual algorithm employed for dataflo management  may be found in the last
  600. chapter on DDXIE Photoflo Management.
  601.  
  602. 2.2.4.  The XIE Resource Manager
  603. The XIE resource manager is responsible for creating,  doing lookup, and destroying XIE resources.
  604. Those resources  available to the client are Photomap, LUT,  Photoflo,  Photospace,  ROI, and ColorList
  605. types,  which are registered with the Core X resource manager to comply with the standard X model.
  606. A photospace resource maintains a list of the photoflos which reside in it.  When the photospace is de-
  607. stroyed,  all of its photoflos are destroyed along with it.  Destroying a photoflo requires going through its
  608. list of elements and destroying all of their data structures too.
  609.  
  610. 2.2.5.  The XIE Memory Manager
  611. The XIE SI will layer an XIE-private set of allocation calls on top of the standard X allocation routines.
  612. This will permit customization of the memory manager to allow for special fragmentation avoidance al-
  613. gorithms, etc.
  614.  
  615.  
  616. 3.      Extension Initialization
  617. The image extension is initialized along with other extensions by setting the XIE flag in the module miinitext.c.
  618. This causes the function XieInit() to be called during server startup.
  619. XieInit() calls CreateNewResourceClass() to register an XIE resource class,  and registers the Photomap, LUT,
  620. Photoflo, Photospace, ROI, and ColorList resource types and their respective deleteFunc vectors by calling
  621. CreateNewResourceType().
  622. Next XieInit() calls AddExtension() to register the XIE dispatchers and closeDownProc with Core X.
  623. AddExtension returns the major opcode, error and event bases for XIE to use.
  624. XieInit() allocs a client array sufficient for holding MAXCLIENTS clients,  and initializes the array to contain
  625. XieNullClient pointers.
  626. The last step of extension initialization is to call XieReset(), which initializes XIE's internal state variables,  if
  627. required.
  628.  
  629.  
  630. 4.      Memory Management
  631. The SI will place a veneer over the core X memory management routines (e.g. Xalloc, Xrealloc, Xfree, etc.).  This
  632. will facilitate adding any special management hooks that may be necessary when the SI is ported to particular
  633. platforms.  This will also facilitate monitoring memory usage, tracking down leaks, etc.
  634. To cut down on memory management overhead during flo execution, the many data segment descriptors that might
  635. normally be allocated and freed as they are needed, will instead be returned to a look-aside list that is managed by
  636. the photoflo data manager (so that they can be more efficiently re-used).  They will be returned to the underlying
  637. management routines (i.e. core X) when the flo completes (and if the number of cached descriptors exceeds a high
  638. water mark).
  639. A global parameter will be used to hint at the most efficient alignment for scanlines, lookup tables, etc..  Individual
  640. elements are allowed to override this alignment hint in order to address their own particular alignment
  641. requirements (e.g. restrictions that might be imposed by an image processing accelerator).
  642.  
  643.  
  644.  
  645. 5.      Dispatching requests
  646. XIE protocol requests are passed through the normal X protocol stream from the client to the core X dispatch loop.
  647. Core X dispatches XIE requests to the XIE dispatcher or the XIE swap-dispatcher.  The XIE dispatcher of choice
  648. was selected at extension initialization time by AddExtension().
  649. The XIE dispatcher passes the request directly to the appropriate Proc routine.  The XIE swap-dispatcher must
  650. byte-swap multi-byte fields within the protocol request before calling the Proc routine.  For requests that include
  651. PhotoElements, the element (and technique) fields must also be swapped.  Conversion of IEEE-floats is deferred to
  652. the photoflo creation routines.  Likewise, reformatting of client data (received with a PutClientData request) is
  653. deferred to the target element within the photoflo.
  654. When the extension is done fielding the request, it returns a code value to indicate either success or failure.  If the
  655. request is not a successful, an error packet is sent back to the client.
  656.  
  657.  
  658. 6.      Data Representations
  659. 6.1.    Canonic Data
  660. To ensure the greatest processing efficiency the SI will maintain images using a limited number of convenient data
  661. types.  Since data provided through PutClientData requests must be copied from the wire buffer before returning to
  662. core X, the least overhead is incurred if the data are converted as they are moved.  All image data entering the SI
  663. from the client will be converted (if necessary) to one of the following data types:
  664. *       Bit: bi-level pixels.  8 pixels are packed into each consecutive byte
  665. *       Byte: pixels having 3 to 256 quantization levels, each pixel stored in the low-order bits of a byte (unused high-order
  666. bits within the byte are zero)
  667. *       Pair: pixels having 257 to 16,384 quantization levels, each pixel stored in the low-order bits of a byte-pair (unused
  668. high-order bits within the byte-pair are zero)
  669. *       Quad: pixels having more than 16,384 quantization levels, each pixel stored in the low-order bits of a 4-byte unit
  670. (unused high-order bits within the unit are zero)
  671. An additional image data type arises from elements that can produce unconstrained data, which can only exist
  672. within the context of a photoflo.  Unconstrained data must be converted, via a client specified Constrain element,
  673. prior to export out of the photoflo.  The protocol makes no restriction on the representation of unconstrained data.
  674. In the SI, unconstrained data will be represented via   " typedef   float  Unconstrained; "   to facilitate redefining
  675. the representation.
  676. Canonic form will take advantage of the natural byte order of the server architecture for data that spans multiple
  677. bytes.  The SI will use Endian-intelligent macros to efficiently extract and insert arbitrarily aligned bit field data.
  678. There will be a module of conversion routines for converting to and from canonic form, and for promoting data to
  679. a higher canonic form (e.g. convert byte to float).  Demoting data (e.g. from float to byte) is explicitly requested by
  680. the client via Constrain elements.
  681.  
  682. 6.2.    Non-canonic Data
  683. All data that is transported through the protocol stream is considered to be non-canonic.  Additionally, all encoded
  684. data is non-canonic.
  685. 6.2.1.  Byte Stream Data
  686. For data that are injected into a flo by a PutClientData request, conversions are specific to the target
  687. ImportClient element and decode technique.  Since their parameters fully describe how the data are to be
  688. interpreted, the appropriate decode or conversion function is selected by the ddxie DAG analyzer.
  689. Similarly, it is the responsibility of an ExportClient element to format output data (as specified by client
  690. parameters) prior to it being sent to the client (the data are sent in response to a GetClientData request).
  691.  
  692. 6.2.2.  Compressed Data
  693. Compressed data is stored as a byte stream,  together with sufficient decoding parameters to decompress
  694. the data.  These parameters include a decode technique.
  695.  
  696. 6.2.3.  Run-length Data
  697. A ProcessDomain is not a resource, but rather the use of a photomap or ROI resource (or equivalent data
  698. imported directly from the client) in conjunction with an X,Y offset (V4.12 pg. 7-2).  The Blend element
  699. is unique in that the process domain input data must be a blend-plane.  A blend-plane is an n-level
  700. constrained alpha-plane (i.e. data that looks much like a gray scale image).  All other elements that accept
  701. a process domain (e.g. Arithmetic, Compare, ..., Point, ExportClientHistogram) accept only ROI or
  702. control-plane type processing domain data.  An ROI represents a list-of-rectangles, whereas a control-
  703. plane is treated as an array of Booleans.
  704. Since some elements can accept both ROI and control-plane data types, their implementation can be
  705. simplified if these data types could be converted to a common form that offers processing efficiency.
  706. Using run-lengths, groups of image pixels could be alternately processed or passed-through without
  707. testing the domain on a per-pixel basis.
  708. The SI will present control-plane and ROI data to an element's process domain input in run-length form
  709. on a per-scanline basis.  Consecutive scanlines with identical sets of run-lengths can be counted as a
  710. vertical run.  Encoding the data in this manner may also provide some compression, but that is not the
  711. primary consideration.
  712. Conversion of control-plane data will be accomplished by inserting an additional element type between
  713. the source of the control-plane data and the process domain input of the element that requires it.  This
  714. new element type will alternately count runs of zero and non-zero pixels in the image.
  715. ROI data will be converted by the ImportClientROI element.  The rectangles must be sorted by their Y
  716. offset and then by X offsets within the same Y, before they are converted into run-lengths.
  717. Defining process domain data in this manner is akin to Y-X banding of regions within core X.
  718.  
  719. 6.3.    Tri-chromatic Data
  720. Triple band data is stored and passed between flo elements in band-by-plane format (i.e. pixels for each band are
  721. segregated into separate image arrays).  In XIE, the color space attributes of triple band data are known only to the
  722. client.  Therefore, this data is not tagged as representing any particular color space.
  723.  
  724. 6.4.    Strips
  725. One of the motivations for using photoflos is to reduce memory utilization by propagating segments of the image
  726. through each processing step to form the desired result, rather than consuming a full size image buffer at each step.
  727. If the segment size is too small, however, performance can suffer due to increased scheduling overhead.  To
  728. address these conflicting problems, elements will produce a number of scanlines at a time, in strips, where the
  729. number of scanlines that constitutes a strip is a function of a tunable parameter.
  730.  
  731.  
  732. 7.      Data Structures
  733. 7.1.    Data Formats
  734. A format-rec is used to describe the format of data that an element will produce or the format required by a
  735. receptor.  It consists of:
  736. *       the data class (i.e. canonic, compressed, lookup-table, run-length)
  737. *       an in-line format-specific structure
  738. Note: run-length data require no additional specification, byte stream data are described by client specified element parameters.
  739.  
  740. 7.1.1.  Canonic
  741. A canonic-rec is used to describe the format of canonic image data that an element will produce or the
  742. format required by a receptor.  For triple band data, a separate canonic-rec is used for each band.  A
  743. canonic-rec contains:
  744. *       the canonic data type
  745. *       the band number
  746. *       the total width (in pixels)
  747. *       the total height (in pixels)
  748. *       the depth (in bits)
  749. *       the number of potential quantization levels
  750. *       the distance between adjacent pixels (in bits)
  751. *       the distance between adjacent scanlines (in bits)
  752.  
  753. 7.1.2.  Compressed
  754. A compressed-rec is used to describe encoded image data that an element will produce or encoded data
  755. that is required by a receptor.  A compressed-rec contains:
  756. *       the compression technique (either decode for data that is to be stored, or encode to describe how an export
  757. element should compress data)
  758. *       the band interleaving
  759. *       the band number
  760. *       the width (in pixels)
  761. *       the height (in pixels)
  762. *       the number of potential quantization levels
  763. *       a pointer to technique-specific parameters
  764. For triple band JPEG data, three compressed-recs are required to describe the individual bands despite the number of image
  765. arrays that are required to represent the data (1 or 3 depending on interleave).
  766.  
  767. 7.1.3.  Lookup-table
  768. A table-rec is used to describe the format of lookup table data.  It contains:
  769. *       the band order of lookup tables sent from the client
  770. *       the maximum number of quantization levels allowed in the input image
  771. (i.e. the number of entries per table)
  772. *       the number of quantization levels that may occur in the output image
  773.  
  774. 7.2.    Resource structures
  775. 7.2.1.  ColorList
  776. A colorlist-rec is used to define a ColorList resource.  It contains:
  777. *       the resource-id of the colorlist
  778. *       the number of references to the colorlist (including 1 for core X)
  779. *       the resource-id of the colormap from which the cells have been allocated
  780. *       the number of cells allocated
  781. *       the pointer to the list of allocated cell indices
  782. 7.2.2.  LUT
  783. A lut-rec is used to define a LUT resource.  It contains:
  784. *       the resource-id of the lut
  785. *       the number of references to the lut (including 1 for core X)
  786. *       the number of lookup tables (either 1 or 3)
  787. *       a format-rec containing the lookup table attributes
  788. *       pointers to the lookup tables
  789. 7.2.3.  Photomap
  790. A photomap-rec is used to define a Photomap resource.  It contains:
  791. *       the resource-id of the photomap
  792. *       the number of references to the photomap (including 1 for core X)
  793. *       the number of chrominance bands in the image (1 or 3)
  794. *       per-band format-recs (i.e. queriable attributes: width, height, and levels)
  795. *       a pointer to the decode parameters
  796. *       a pointer to the image array for each band
  797. 7.2.4.  ROI
  798. A roi-rec is used to define a ROI resource.  It contains:
  799. *       the resource-id of the roi
  800. *       the number of references to the roi (including 1 for core X)
  801. *       the length of the run-length encoded list of rectangles
  802. *       a pointer to the run-length list
  803. 7.2.5.  Photospace
  804. A photospace-rec is used to define a Photospace resource.  It contains:
  805. *       the resource-id of the photospace
  806. *       the number of active photoflos in the photospace
  807. *       a queue head that points to the first and last photoflos in the photospace
  808.  
  809. 7.2.6.  Photoflo
  810. A flo-def is used to define a photoflo resource.  It contains:
  811. *       the Executable identity of the photoflo (i.e. the name-space/flo-id pair)
  812. *       Booleans: Active, Modified, ...
  813. *       the number of elements received from the client
  814. *       an array of pointers to client elements in phototag order
  815. *       a circular doubly linked list head that points to the definition DAG
  816. *       a circular doubly linked list head that points to the optimized DAG
  817. *       a flo-error-rec for passing error information back to dixie
  818. *       a flo-event-rec for sending event information back through dixie
  819. *       a pointer to ddxie-private data (the SI will hang a flo-tex structure here)
  820. *       a set of ddxie photoflo manager public entry points:
  821. *       link    create a runnable photoflo, its elements, and data that persists between
  822.         executions
  823. *       startup allocate/initialize data that are valid for a single execution instance and
  824.         commence execution
  825. *       resume  continue execution after the flo has yielded
  826.         (not used in the SI)
  827. *       input   push data from the client into a specified ImportClient element and resume
  828.         execution
  829. *       output  pull data for the client from a specified ExportClient element and resume
  830.         execution
  831. *       query   query a specified ImportClient element to see if it needs more data, or query
  832.         a specified ExportClient element to see if it has data available
  833. *       abort   stop execution and free single instance stuff
  834. *       destroy free persistent stuff and destroy the runnable DAG
  835. *       a set of ddxie photoflo manager private entry points:
  836. *       scheduler       schedule elements to run until data exhausted or yielding is required
  837. *       data manager    strip management
  838.  
  839.  
  840. 7.3.    Photo Element Definition
  841. A pe-def is used to define each client element supplied at photoflo creation.  Each pe-def contains pointers
  842. for linking elements together according to their phototag inter-connections.  A fully linked set of pe-defs
  843. constitutes a definition DAG that is suitable for presentation to ddxie for analysis.  Each structure
  844. contains:
  845. *       the element phototag number received from the client
  846. *       the element type received from the client (within the optimized DAG this may identify additional converter
  847. or optimized element types that are defined for the server implementation)
  848. *       Booleans: loop-detect, orphan, modify, import, process, export
  849. *       a pair of pointers linking this element to the next and previous element in DAG order
  850. *       a pointer linking this element to another element of the same class (used to locate all the Import or Export
  851. elements; not used for Process elements)
  852. *       a pointer to link a client element to a replacement element in the optimized DAG
  853. *       a pointer to element specific parameters (e.g., parameters supplied by the client)
  854. *       a pointer to ddxie-private data (placed here by the ddxie link routine, removed by the ddxie destroy routine
  855. -- the SI will hang a pe-tex structure here)
  856. *       element entry points
  857. *       create
  858. *       initialize
  859. *       activate
  860. *       flush
  861. *       reset
  862. *       destroy
  863. *       fan out information:
  864. *       the number of bands this element will produce
  865. *       a format-rec describing each output band
  866. (dixie fills in attributes, ddxie fills in alignment ...)
  867. *       the number of receptors connected to this element's output
  868. *       linkage to receptors of this element's output
  869. *       the number of phototag inputs this element is using
  870. (i.e., the number of inputs from other elements, including process domain and lut inputs)
  871. *       an array of input connection information; each input connection includes:
  872. *       the phototag of the source element
  873. *       a pointer to the source element
  874. *       the number of bands this input will receive
  875. *       a format-rec describing each band
  876. (dixie fills in attributes, ddxie fills in alignment, ...)
  877.  
  878. 7.4.    DDXIE Structures
  879. 7.4.1.  Photoflo run-time context
  880. A flo-tex stores ddxie-specific information for the execution of a photoflo.  It contains:
  881. *       a pointer back to the flo-def
  882. *       information for the scheduler (e.g. the ready-list)
  883. *       information for the data manager (e.g. a look-aside list of strips that can be re-used)
  884. *       a pointer reserved for yielding information
  885.  
  886. 7.4.2.  Photo Element run-time context
  887. An pe-tex stores ddxie-specific information for an element.  It contains:
  888. *       a pointer back to the pe-def
  889. *       a pointer back to the flo-tex
  890. *       output strip size
  891. *       a pointer to an array of receptor-recs *
  892. *       a pointer to additional storage for element-private information *
  893. * the structures pointed at by these pointers are contiguous with (appended to) the pe-tex.
  894.  
  895. 7.4.3.  Receptor
  896. A receptor-rec provides an execution context for data that are to be brought into an  element.  It contains:
  897. *       a pointer to the pe-def that is supplying the data
  898. *       the minimum number of data units needed for activation (per band)
  899. *       the total number of data units currently available (per-band)
  900. *       a circular doubly linked list head that points to the strips that are available (per band)
  901.  
  902. 7.4.4.  Strip
  903. A strip describes a segment of data that is produced by an element and is then given to the data manager
  904. for distribution to one or more receptors.  A strip describes an array containing one or more complete data
  905. units (for canonic data a unit is a scanline).  It contains:
  906. *       forward and backward pointers to the next and previous strips
  907. *       a pointer to the format-rec that describes the data format
  908. *       a reference count
  909. *       the number of data units in the strip (e.g. number of scanlines for canonic data)
  910. *       the first scanline number (if canonic)
  911. *       the total size of the data array (in bits)
  912. *       the offset within the data array to the first data (in bits)
  913. *       the base address of the data array
  914.  
  915.  
  916.  
  917. 8.      Protocol requests
  918. Each of the XIE protocol requests is listed below.  For the sake of brevity, information that can be found in the
  919. protocol document (V4.12) is not duplicated here.  Instead there is:
  920. *       a short description of each request
  921. *       an overview of the actions taken for a successful request
  922. If a request cannot be honored due to an error, an error packet will be returned to the client, as prescribed in the
  923. protocol document.
  924. Each protocol request will have a dedicated Proc and SProc routine which is called from the XIE dispatcher
  925. (which is called by the X dispatcher).  Swap routines will also be provided for replies, errors, and events.
  926.  
  927. 8.1.    Global Query requests
  928. 8.1.1.  QueryImageExtension
  929. Each client is required to invoke QueryImageExtension prior to issuing any other XIE protocol requests in
  930. order to establish protocol version compatibility between client and server.
  931. The xie-client-table is checked for an existing xie-client-rec for the current client.  If the client is not
  932. found (as is the case when QueryImageExtension is used for XIE connection setup) a new xie-client-rec
  933. structure is added to the table.
  934. Applying the compatibility rules spelled out in the protocol document, the XIE version is chosen and
  935. saved in the xie-client-rec.  The set of Proc and SProc routines that match this version are also saved in
  936. the xie-client-rec.
  937. QueryImageExtension generates a protocol reply which returns the chosen XIE version information, the
  938. ServiceClass, and the Alignment capabilities of this server.
  939.  
  940. 8.1.2.  QueryTechniques
  941. QueryTechniques provides information about a selected group of techniques that are supported by the
  942. server.  This is the only method by which a client can discover implementation specific technique
  943. information such as:
  944. *       what are the default techniques?
  945. *       which techniques require parameters?
  946. *       what is the relative execution speed?
  947. *       what private techniques have been added?
  948. A reply is returned to the client containing a TechniqueRec for each technique in the specified group.
  949.  
  950. 8.2.    Resource requests
  951. 8.2.1.  Overview
  952. The ColorList, LUT, Photomap, and ROI resources provide server-side storage of XIE data types.  Each of
  953. these resource types is registered with core X at extension initialization time (CreateNewResourceType)
  954. along with a resource specific deleteFunc (e.g. DeletePhotomap).  This function enables core X to destroy
  955. these resources if the client connection is closed.
  956. Chapter 4 of the protocol document explains resource creation, destruction, and flo bindings using a
  957. bucket and handle analogy.  The following sections explain how these requirements will be satisfy.
  958.  
  959. 8.2.1.1.        Creating Resources
  960. Each of these resources is created via an explicit XIE protocol request.  Upon creation each
  961. resource has a reference count of one, but has no resource specific data or attributes.  If the
  962. resource is created successfully, AddResource() is called to register it with core X.
  963. These resources are populated with data and attributes as the result of executing a flo.  With the
  964. exception of the ColorList resource, these resources can be used to provide input for a flo.
  965.  
  966. 8.2.1.2.        Flo'ing Resources
  967. When a flo becomes active, the reference count of each XIE resource referenced by the flo is
  968. incremented once for each reference to the resource.
  969. For LUT, ROI, and Photomap resources, it is permissible for multiple elements in an active flo
  970. (or different active flos) to access the same resource simultaneously (e.g. the explanation of
  971. pseudo in-place operations).    Multiple simultaneous writes to the same ColorList are illegal.
  972. Therefore a ColorList's reference count can never exceed two.
  973. If multiple elements within a flo export to the same resource, upon successful flo completion the
  974. resource's handle will be connected to one of the new buckets (the protocol does not specify
  975. which bucket will win).  If multiple flos are exporting to the same resource, each flo will leave a
  976. new bucket attached to the resource upon successful completion.  Synchronizing the execution of
  977. multiple flos is an exercise left to the client.
  978. When the flo leaves the active state (because of done, error, or abort), the deleteFunc of each
  979. referenced XIE resource is called to decrement the reference count (once for each reference).  If a
  980. resource has zero references, its structure (and everything associated with it) is freed.
  981.  
  982. 8.2.1.3.        Destroying Resources
  983. Each of these resources can be destroyed via an explicit XIE protocol request which indirectly
  984. calls the resource's deleteFunc via the core X FreeResource() routine.  Calling the deleteFunc in
  985. this way disassociates the resource-id from core X.  The deleteFunc is specified at extension
  986. initialization time via CreateNewResourceType().
  987. Other responsibilities of the deleteFunc are to zero the resource-id in the resource structure and
  988. decrement the reference count.  If the count goes to zero, the resource structure and everything
  989. associated with it are freed, otherwise this action is delayed until there are no outstanding
  990. references.
  991.  
  992. 8.2.2.  ColorList
  993. 8.2.2.1.        Create
  994. Create an empty color-list-rec and call AddResource().  A ColorList is a resource used by the
  995. ConvertToIndex element to record colormap cells that it allocates.  These cells can be freed by
  996. explicit ColorList requests or via other mechanisms that are specified in the protocol document.
  997.  
  998. 8.2.2.2.        Query
  999. Reply with the list of colormap cells currently referenced by the ColorList.  If there are none or
  1000. the colormap has been freed, the colormap and count fields of the reply will both contain zero.  If
  1001. the query is made while a flo is actively allocating cells, the query will return a snapshot of the
  1002. ColorList at the time of the query.
  1003.  
  1004. 8.2.2.3.        Purge
  1005. If the reference count is one, all cells that are currently allocated are freed, thus restoring the
  1006. color-list-rec to its create-time state.
  1007.  
  1008. 8.2.2.4.        Destroy
  1009. Call FreeResource() to disassociate the ColorList resource-id from core X.  The registered
  1010. deleteFunc may purge cells held by the ColorList and free the color-list-rec (see Destroying
  1011. Resources above).
  1012.  
  1013.  
  1014. 8.2.3.  LUT
  1015. 8.2.3.1.        Create
  1016. Create an empty lut-rec and call AddResource().  A LUT is a resource that contains lookup-table
  1017. array(s) that are used by the Point element.  A LUT resource is populated via an ExportLUT
  1018. element.  Its attributes are inherited indirectly from an ImportClientLUT element (XIE does not
  1019. provide any facilities for synthesizing exportable LUT data in the server).
  1020.  
  1021. 8.2.3.2.        Destroy
  1022. Call FreeResource() to disassociate the LUT resource-id from core X.  The registered deleteFunc
  1023. may free the lookup arrays and the lut-rec (see Destroying Resources above).
  1024.  
  1025.  
  1026. 8.2.4.  Photomap
  1027. 8.2.4.1.        Create
  1028. Create a photomap-rec and call AddResource().  A photomap is a resource that is used to store a
  1029. complete image.  Data stored in a photomap may be imported into a flo and used as image data
  1030. for display, or exported from the flo, or used as a process domain.
  1031. The photomap-rec is populated by an ExportPhotomap element.  This export element will receive
  1032. the image from a process element, or an import element (i.e. from the client, a photomap, or a
  1033. drawable).  Image attributes are also inherited from this element.
  1034.  
  1035. 8.2.4.2.        Query
  1036. Generate a reply that reflects the current set of image attributes.  If the photomap has not been
  1037. populated (i.e. the number of bands is zero), all fields of the reply will contain zeros and
  1038. populated will be false.
  1039.  
  1040. 8.2.4.3.        Destroy
  1041. Call FreeResource() to disassociate the photomap resource-id from core X.  The registered
  1042. deleteFunc may free the image descriptors, image data, decode parameters, and photomap-rec
  1043. (see Destroying Resources above).
  1044.  
  1045. 8.2.5.  ROI
  1046. 8.2.5.1.        Create
  1047. Create a roi-rec and call AddResource().  An ROI is a resource which contains a list of rectangles
  1048. that are used to define a process domain.  An ROI resource is populated via an ExportROI
  1049. element.
  1050. The list of rectangles received from the client is sorted and converted into run-lengths by the
  1051. ImportClientROI element (this is explained in the section on Processing Domains).  This data is
  1052. stored in the roi-rec by an ExportROI element.  ROI data always originates from the client, XIE
  1053. does not provide any facility for synthesizing exportable ROI data within the server.
  1054. Note:   the list of rectangles returned from ExportClientROI will be a list of sorted non-overlapping
  1055. rectangles (reconstructed from the run-length list).  Although the contents of this list may differ from
  1056. the list received from the client, it will be logically equivalent.  The protocol does not specify that
  1057. the original list must be returned.
  1058.  
  1059. 8.2.5.2.        Destroy
  1060. Call FreeResource() to disassociate the ROI resource-id from core X.  The registered deleteFunc
  1061. may free the run-length list and the roi-rec (see Destroying Resources above).
  1062.  
  1063. 8.3.    Photoflo related requests
  1064. Photoflos provide the mechanism by which a sequence of import, process, and exports steps are described.  Two
  1065. photoflo modes are supported: an immediate flo is executed once and then it is destroyed, whereas a stored flo can
  1066. be executed repeatedly and offers the option of modifying its parameters between executions.
  1067.  
  1068. 8.3.1.  ServerIDspace
  1069. Since stored flos can be re-executed, they generally enjoy a normal life expectancy.  Therefore they are
  1070. identified using the same name-space as other resources created by the client.  Their resource-ids can be
  1071. re-used however, by redefining the complete contents of the flo.
  1072.  
  1073. 8.3.2.  Photospace
  1074. Immediate flos may be generated in rapid succession (and are short lived relative to normal resources).
  1075. Therefore, a separate 32-bit wide identifier name space is provided for their execution.
  1076.  
  1077. 8.3.2.1.        Create
  1078. Create a photospace-rec and call AddResource().  Since only a small number of immediate flos
  1079. are likely to be active in a photospace at any given time, the SI will maintain the active set of flos
  1080. as a doubly linked list.
  1081.  
  1082. 8.3.2.2.        Destroy
  1083. Call FreeResource() to disassociate the photospace resource-id from core X.  The registered
  1084. deleteFunc will abort and destroy all immediate flos known to the photospace and then free the
  1085. photospace-rec.
  1086.  
  1087.  
  1088. 8.3.3.  Immediate-mode specific
  1089. An immediate flo begins execution as soon as the protocol request containing the sequence of steps to be
  1090. performed is received.  Upon completion the flo is automatically destroyed.
  1091.  
  1092. 8.3.3.1.        ExecuteImmediate
  1093. Create a flo-def and copy the supplied list of elements to the flo-def while verifying that the list is
  1094. a DAG.  Next, the flo-def is added to the specified photospace and execution commences.  Upon
  1095. completion the flo is destroyed and the flo-def is removed from the photospace.  Flo creation,
  1096. execution, and destruction is covered in detail in the chapters on photoflo management.
  1097.  
  1098.  
  1099. 8.3.4.  Stored-mode specific
  1100. 8.3.4.1.        Create
  1101. Create a flo-def, copy the supplied list of elements into pe-defs (while verifying that the list is a
  1102. DAG), and then call AddResource().  This process is covered in detail in the chapter on DIXIE
  1103. Photoflo Management.
  1104.  
  1105. 8.3.4.2.        Modify
  1106. After verifying that no topological or element type changes are being attempted, the parameters
  1107. of the specified set of elements are replaced.  These elements are flagged to note that they have
  1108. been modified.  The chapters on photoflo management address the additional side affects that
  1109. may be incurred when a previously executed flo is modified.
  1110.  
  1111. 8.3.4.3.        Redefine
  1112. The SI will simply call FreeResource() to destroy the old flo in its entirety, and then create a new
  1113. one using the old resource-id.
  1114.  
  1115. 8.3.4.4.        Execute
  1116. Prior to executing a photoflo several preparatory steps are necessary:
  1117. *       each element's parameters and data attributes are validated
  1118. *       the DAG is analyzed to choose the most appropriate manner in which to execute it
  1119. *       an optimized DAG is generated, if any refinements to the definition DAG can be made
  1120. *       the required sequence of elements is instantiated
  1121. Finally, the flo is set active and execution begins.  Flo execution is covered in detail in the
  1122. chapters on photoflo management.
  1123.  
  1124. 8.3.4.5.        Destroy
  1125. Call FreeResource() to disassociate the flo's resource-id from core X.  The registered deleteFunc
  1126. will abort execution (if active), free everything attached to the flo, and then free the flo-def.
  1127.  
  1128.  
  1129. 8.3.5.  ClientData transport
  1130. 8.3.5.1.        Put
  1131. PutClientData supplies a  byte stream of data from the client that is to be delivered to a specific
  1132. ImportClient element within a flo.  Since the interpretation of the data is specific to the target
  1133. element and its parameters (and possibly a technique), any reformatting of the data to convert it
  1134. to canonic form (including byte swapping) must be controlled by the receiving element.
  1135.  
  1136. 8.3.5.2.        Get
  1137. GetClientData generates a reply which returns a byte stream of data from a specific ExportClient
  1138. element within a flo.  The data will be formatted according to the parameters specified to the
  1139. supplying element prior to the commencement of flo execution.
  1140.  
  1141. 8.3.6.  Query/Control
  1142. 8.3.6.1.        Query
  1143. Reply with the status of the specified flo (active, inactive, or nonexistent).  If it is active, two lists
  1144. of elements are provided: one listing elements waiting for data from the protocol stream, and the
  1145. other listing elements which have data for the protocol stream.
  1146.  
  1147. 8.3.6.2.        Await
  1148. If the specified flo is not found in the active state, no operation is performed.  Otherwise
  1149. IgnoreClient() is called to block further requests from the client.  Later, when the flo transitions
  1150. out of the active state, AttendClient() will be called to allow blocked requests to be processed
  1151. again.
  1152.  
  1153. 8.3.6.3.        Abort
  1154. If the specified flo is not found in the active state, no operation is performed.  Otherwise
  1155. execution of the specified flo is terminated and output pending for the client is destroyed.  A
  1156. stored flo is returned to the inactive state; an immediate flo is destroyed.
  1157.  
  1158.  
  1159. 9.      DIXIE Photoflo Management
  1160. 9.1.    Overview
  1161. The protocol representation of a photoflo is a list of elements. There are three element types: import elements
  1162. which bring data into the flo, processing elements which operate on the data, and export elements which transfer
  1163. data out of the flo to external resources or back to the client.
  1164. Connections between elements is accomplished through the use of phototags.  An element's relative position on the
  1165. protocol list determines the element's phototag number. The source(s) for each element are explicitly specified
  1166. using the phototags of upstream elements. The output of an element can fan out to any number of downstream
  1167. elements.
  1168. Dixie is responsible for creating the photoflo data structures that will contain the client's list of elements.  The
  1169. same structures are used by stored and immediate flos.  At create time, dixie also converts the client list into a fully
  1170. connected DAG.  Dixie relies on ddxie to analyze the DAG in order to select an appropriate method to execute the
  1171. sequence of operations.  Ddxie fills in a vector of entry points within the flo-def, so that dixie can control the
  1172. overall photoflo execution process.  A call through the link entry point generates a re-usable execution context
  1173. (called a flo-tex) and an associated set of run-time element handlers.  The startup entry point (re)initializes the flo
  1174. and starts execution.  Input and output entry points are used to move client data in and out of the flo on behalf of
  1175. data transport protocol requests.  Additional entry points are provided for restarting the flo after it has yielded, for
  1176. obtaining status information, for stopping the flo prematurely, and for destroying it.
  1177. The following sections will discuss photoflo management from the dixie point of view.  The chapter titled DDXIE
  1178. Photoflo Management, describes the actions performed within ddxie.
  1179.  
  1180. 9.2.    Photoflo Creation
  1181. 9.2.1.  Creating the Flo
  1182. When the server receives an ExecuteImmediate or CreatePhotoflo protocol request, a flo-def is allocated
  1183. and initialized. The list of elements received from the client is parsed in the order received.  The following
  1184. actions are performed (within dixie) for each element:
  1185. *       verify that each phototag input is specified within the bounds of the client element list
  1186. *       create an pe-def large enough to accommodate the number of phototag inputs
  1187. *       store element information in the pe-def
  1188. (e.g. the element's phototag index, class, type, and input phototag connections)
  1189. *       store the element's parameters (including technique data) in a separately allocated area
  1190. (any necessary floating point conversions are performed at this time)
  1191.  
  1192.  
  1193. The address of each pe-def is stored in phototag order within the flo-def.  Upon completion of this initial
  1194. creation phase the photoflo looks like:
  1195.  
  1196.  
  1197. 9.2.2.  Traversing the DAG
  1198. The next phase of photoflo creation converts the list of client elements into a DAG.  The element list is
  1199. scanned in phototag order. At each export element, the phototag input connections are followed upstream
  1200. via a recursive depth first search algorithm until one of the following conditions occurs:
  1201. *       an import element is found
  1202. *       an element with fully connected inputs is encountered
  1203. (i.e. one that was examined while searching back from a previous export element)
  1204. *       a topological error condition is detected
  1205. Topological errors are discovered during the DAG definition process by setting a flag in the current
  1206. element prior to invoking the recursive search routine to examined the element's inputs, and then resetting
  1207. the flag when all the input elements have been examined.  A loop condition exists if a flagged element is
  1208. found during the recursive search.  Attempting to use an export element as a data source is also a
  1209. topological error.
  1210.  
  1211.  
  1212. As the search algorithm considers each element, the following actions are performed:
  1213. *       if the element being examined is not an import element:
  1214. *       set the loop-detect flag in the current element
  1215. *       invoke the search algorithm to examine each of the element's inputs
  1216.         the inputs of multi-input elements are searched in the following order:
  1217. 1.      lut input
  1218. 2.      process domain input
  1219. 3.      source input(s) 1 through n
  1220. *       clear the loop-detect flag in the current element
  1221. *       link the current element's output and the downstream element's input to each other
  1222. *       append the current element to the definition DAG
  1223. Continuing with the example given above, the definition DAG structures would be linked like this:
  1224.  
  1225.  
  1226.  
  1227. The definition DAG is a circular doubly-linked list of pe-defs that has the following characteristics as seen
  1228. from the DAG head:
  1229. *       the first element in the forward direction is an import element
  1230. *       the first element in the backward direction is an export element
  1231. *       for each element that is examined in a forward traversal, all of the elements from which it obtains
  1232. input have already been examined
  1233.  
  1234. Depending on which export element was considered first, the DAG order of our simple flo illustrated
  1235. above would be either:
  1236. 1, 2, 3, 4,  or  1, 2, 4, 3.
  1237. If the export elements in the flo illustrated below were considered in ascending order (i.e. search back
  1238. from element 2, then from 5, etc.), the DAG ordering would be:
  1239. 1, 2, 3, 4, 5, 7, 6, 8, 9, 11, 13.
  1240. If, however, the export elements in the flo below were considered in descending order (i.e. search back
  1241. from element 13, then from 11, etc.), the DAG ordering would be:
  1242. 7, 1, 6, 3, 4, 8, 9, 13, 11, 5, 2.
  1243. The DAG characteristics described above hold true for any sequence in which the export elements could
  1244. be considered.
  1245. It is possible that the output from some elements will not terminate at an export element.  The protocol
  1246. states that these elements should be ignored.  Therefore, elements 10 and 12, in the figure below, would
  1247. not be included in a definition DAG because they do not terminate at an export element.
  1248.  
  1249.  
  1250.  
  1251. 9.2.3.  Registering the Flo
  1252. Provided no errors are encountered while creating and validating the photoflo, the flo-def structure of an
  1253. immediate flo is registered with the specified photospace, whereas AddResource() is called to register a
  1254. stored flo with core X.
  1255.  
  1256. 9.3.    Photoflo Execution
  1257. 9.3.1.  Prepping the DAG
  1258. Before a flo can be made active, some preparatory steps are necessary.  First the DAG is traversed in the
  1259. forward direction to execute each element's dixie prep routine which will:
  1260. *       lookup external resources (colormap, colorlist, drawable, gc, lut, photomap, roi, ...)
  1261. (for XIE resources their reference counts are incremented)
  1262. *       validate the attributes of each source of data for the element
  1263. *       validate the element's parameter values (including technique data)
  1264. *       determine what the element's output attributes will be
  1265. *       determine if the flo has been modified since a previous execution
  1266. *       the element was affected by a ModifyPhotoflo request
  1267. *       source attribute changes have caused output attributes to change
  1268. If there is an executable photoflo that already exists and it has been modified in such a way that re-
  1269. compilation is necessary, the photoflo manager's destroy function is called, in preparation for a new
  1270. compilation.
  1271.  
  1272. 9.3.2.  Analyzing the DAG
  1273. When the elements have been prepped by dixie, the DAG is suitable for presentation to the DAG analyzer.
  1274. The purpose of the analyzer is to define an appropriate solution to the problem to be solved (e.g. coalesce
  1275. multiple elements into a single super-element, insert data type conversion elements, insert data alignment
  1276. elements, ...), and to choose a photoflo manager that can execute it.
  1277. If a previously executed flo still exists, the analyzer is not called.  The current executable will be re-used
  1278. because no additional analysis is required.
  1279. If an optimized DAG has been generated, the analyzer will attach it to the flo-def.  The analyzer
  1280. establishes a photoflo manager by placing its link entry point in the flo-def.
  1281.  
  1282. 9.3.3.  Linking an executable Photoflo
  1283. The first time a photoflo is executed, the flo-def link function is called to generate the run-time structures
  1284. for the photoflo.  It must:
  1285. *       create a run-time context for the flo manager (attach a flo-tex to the flo-def)
  1286. *       create a run-time context for each element (attach a pe-tex to each pe-def)
  1287. *       establish the remaining entry points in the flo-def
  1288.  
  1289. 9.3.4.  Starting the flo
  1290. The flo-def startup function is called to initialize the flo and begin execution.  The photoflo manager
  1291. startup routine will initialize each of its elements (in DAG order), and call upon the scheduler to run the
  1292. flo.  The next chapter covering ddxie photoflo management describes the actual execution of the flo.
  1293. If there are no ImportClient or ExportClient elements in the flo, it can run to completion.  Otherwise,
  1294. execution is dependent on data transport protocol requests.
  1295.  
  1296. 9.3.5.  Resuming the flo
  1297. When a PutClientData request is received, the flo-def input function is called with the phototag of the
  1298. target element and a pointer to the available data.  Calling input gives the new data into the specified
  1299. element and causes the scheduler to resume flo execution.
  1300. When a GetClientData request is received, the flo-def output function is called to fetch some data from the
  1301. specified element.  This may cause the scheduler to resume execution  (e.g. execution may have been
  1302. suspended due to the output buffer being full).
  1303. A resume entry point is provided in the flo-def for implementations that support yielding.  There will be
  1304. no resume routine supplied with the SI.
  1305.  
  1306. 9.3.6.  Stopping the flo
  1307. Dixie does not get involved in determining when a flo reaches completion.  Rather ddxie is responsible for
  1308. determining if all data has been processed and if any data transport requests are required for completion.
  1309. If an error is encountered within the ddxie flo manager, the error detail is recorded in the error-rec, which
  1310. is embedded in the flo-def, and control is returned to dixie.  When an error is discovered by dixie, the flo-
  1311. def abort function is called to stop the flo.  Finally, the error is sent to the client via core X mechanisms.
  1312. If an Abort request is received from the client, the flo-def abort function is called to stop the flo.
  1313.  
  1314. 9.3.7.  Destroying an executable Photoflo
  1315. Dixie destroys a flo-tex by calling the flo-def destroy function which allows ddxie to free its resources and
  1316. remove the ddxie-private flo-tex pointer from the flo-def.
  1317.  
  1318. 9.3.8.  Event notification from a flo
  1319. Several elements can generate events, as can flo completion.  The flo-def includes an event-rec where
  1320. details about the event can be recorded.  Ddxie calls the dixie SendEvent() routine to request that the
  1321. client be notified.
  1322.  
  1323.  
  1324. 10.     DDXIE Photoflo Management
  1325. Ddxie contains a DAG analyzer that defines an appropriate solution for the image equation expressed by the DAG,
  1326. a linker that creates an executable sequence of element handlers to solve the problem, and a flo manager to produce
  1327. the result.  The element handlers, which also reside in ddxie, are discussed in the next chapter.
  1328.  
  1329. 10.1.   DAG Analysis
  1330. The purpose of the DAG analyzer is to define an appropriate solution to the image equation expressed by the DAG
  1331. (e.g. choosing an element handler for a specific technique, coalescing multiple elements into a single "super-
  1332. element", or inserting data type conversion elements), and to choose a photoflo manager that can execute it.
  1333.  
  1334. 10.1.1. Choosing Element Handlers
  1335. The first step is to select an appropriate element handler for each element. To better understand how this
  1336. is performed, an example is shown below. Assume that each photoelement type defined in the XIE
  1337. protocol is assigned a different shading pattern. Then the flo
  1338.  
  1339.  
  1340.  
  1341. could be represented as:
  1342.  
  1343.  
  1344.  
  1345. For each element type (shading pattern),  the mi layer of the SI will provide a set of handlers which can
  1346. implement the computation specified by that element.  A single handler may suffice for elements which do
  1347. not take techniques,  whereas an element like ImportClientData, which can take a number of different
  1348. techniques,  might be implemented as several handlers.  Besides having handlers to account for technique
  1349. variations,  it may also be convenient to separate handlers on the basis of import type restrictions,  ma-
  1350. chine dependence, and degree of optimization.
  1351. Given the framework established above, code generation for a photoflo may be viewed as a labeling prob-
  1352. lem, in which it is necessary that the DAG analyzer find a valid label for each element in the flo.  The
  1353. analyzer is only allowed to label an element with a handler of like shading pattern.
  1354. All handlers will output a type which is the smallest acceptable canonical type for the input data and the
  1355. particular operation.  Import elements will thus be able to write down their output image data types im-
  1356. mediately.
  1357. Let k be the distance from an element to an Import element.  Given a flo which has been labeled and had
  1358. types resolved up to a distance of k-1,  the DAG analyzer will label and resolve all elements of distance k
  1359. by the following method:
  1360.  
  1361. For each element Eki of distance k:
  1362.         For each element Eki,j  which feeds that element:
  1363. Propagate the known output type of Eki,j  to the corresponding input receptor on Eki
  1364. (these will be treated as "suggested input types" by the handlers).
  1365.         Call HandlerTest,  giving it the flo-def and pe-def.  A handler will be selected which resolves all
  1366. input types.  If any input types match, the selected handler will insert a labeled ConvertType
  1367. pseudo-element into the flo.
  1368.         Label Eki with the selected handler.
  1369.  
  1370.  
  1371.  
  1372. The HandlerTest procedure  simply goes through the list of handlers which have the same shading pattern
  1373. as the element in question,  and calls the handler's test entry point.  The test routine checks to see if this
  1374. handler can accommodate the parameters of the element (obtained from the pe-def) in combination with
  1375. the input data types.  If the handler rejects the element,  the HandlerTest procedure checks the next
  1376. handler of the same shading pattern in the list.  The SI element handler sets will be written so as to ensure
  1377. that regardless of what the input data type is,  at least one handler per shading pattern will accept any
  1378. valid element.
  1379. Handlers have the option of accepting seemingly non-canonical data types by inserting a ConvertType
  1380. pseudo-element in the path between the input element and the receiving element.  This ConvertType
  1381. element must be able to convert any non-canonical data type to a canonical type.  The handler doing the
  1382. insertion specifies the type to which it wants the data to be converted.  This mechanism allows the mi
  1383. handlers to continue working even if a server implementor chooses to invent new canonical types.  Thus,
  1384. the criterion that there must be at least one valid handler for any element will remain fulfilled even if new
  1385. types are introduced.
  1386.  
  1387. 10.1.2. Choosing a Linker and Photoflo Manager
  1388. The analyzer must establish a linker and photoflo manager by placing their entry points in the flo-def. The
  1389. mi linker and photoflo manager can handle all element handlers (whether mi or md) that abide by their
  1390. interface conventions.
  1391. If an md analyzer is substituted for the mi analyzer, it may elect to use a foreign linker, photoflo manager,
  1392. and element set (e.g. the pipe manager and sample elements contributed by HP).  In this case, the foreign
  1393. linker would need to translate the contents of the pe-def structures into its own set of elements.
  1394.  
  1395.  
  1396. 10.2.   Photoflo Linker
  1397. The linker is invoked by dixie calling through the flo-def link entry point (it is not called when an unmodified
  1398. photoflo is re-executed).  The linker creates a run-time context (a flo-tex) for use by the flo manager's components.
  1399. It is also responsible for the creation and static initialization of the element handlers selected by the DAG analyzer.
  1400. This is accomplished by calling the create entry point (stored in each pe-def) of each element selected.
  1401.  
  1402.  
  1403. 10.3.   Photoflo manager
  1404. The photoflo manager is a collection of component parts that are called upon from dixie to perform specific tasks
  1405. during the startup, execution, and eventual tear down of a photoflo.
  1406.  
  1407. 10.3.1. Startup
  1408. When dixie calls through the flo-def startup entry point, the flo manager calls upon its sub-components to
  1409. (re)initialize their run-time context.  The flo manager also calls through the initialize entry point of each
  1410. element to allow the elements to (re)initialize their run-time context.  Finally, it transfers control to the
  1411. scheduler to run the flo.
  1412.  
  1413. 10.3.2. Scheduling
  1414. The scheduler is responsible for running available data strips through elements. The scheduler is initially
  1415. called as the final step of photoflo startup. Later, as data arrives from the client, or data is requested by the
  1416. client, the scheduler is started to satisfy the request.
  1417. Scheduling of individual elements for execution is handled through a ready-list. The first time a photoflo
  1418. is executed, only ImportResource elements have data. The ready-list is initialized with these elements.
  1419. Starting from the front of the ready-list, each of the elements on the ready-list are executed in order.  An
  1420. element will produce a maximum of one strip of data each time it executes* . This strip is passed to the
  1421. data manager and then on to appropriate downstream receptors.  Elements receiving data from this ele-
  1422. ment are examined to see if they have sufficient data to execute. If they do, they are pushed onto the front
  1423. of the ready-list.  If the current element was an import element it is removed from the ready-list, otherwise
  1424. it is allowed to remain on the ready-list (assuming it has more data to process) so that it may resume exe-
  1425. cution after the downstream elements have consumed its output.
  1426. One key concept to this algorithm is the removal of elements from the ready-list. Once an import element
  1427. executes and produces up to one strip of data, it is removed from the ready-list, even if more data is avail-
  1428. able. Other element types are not removed from the ready-list until they can proceed no farther. This
  1429. method of removing elements from the ready-list, combined with prepending downstream elements to the
  1430. head of the list, has the effect of pushing strips of data through the flo before new strips are brought in
  1431. from import elements.
  1432. When all data has been processed, the import elements are re-examined. If there are any ImportClient
  1433. elements, control is returned to Core X. This is done to prevent large amounts of server data (possibly
  1434. whole images) from being buffered in the flo while the client is stalled. If only ImportResource elements
  1435. are found, they are put back on the ready-list and execution continues, as described above, until the flo has
  1436. completed.
  1437. Each subsequent execution of the flo will be in response to the client.  The element indicated in the proto-
  1438. col request, and all ImportResource elements, are placed on the ready-list.  As before, each time an import
  1439. element is executed, it is removed from the list and all downstream elements connected to its output with
  1440. sufficient data to execute are pushed onto the front of the ready-list.  If an import element was the target of
  1441. a PutClientData request, it is re-examined to see if it has more data available. If so,  the ready-list is re-
  1442. initialized and execution continues (as above).  If no more client data is available, control is returned to
  1443. Core X.
  1444. As an example of how the scheduler would process a flo, the sample flo from Figure 5-2 of the protocol
  1445. document (V4.12) is shown below.
  1446.  
  1447.  
  1448. This flo has two import elements, 1 and 7.  Element 1, is an ImportClientPhoto element.  Element 7,
  1449. importing a Photomap, is an ImportResource element.  When the flo is first executed, only element 7 will
  1450. have data.  Element 7 will import one strip of the photomap and cause element 8 to be placed on the ready
  1451. list.  Since element 7 is an import element, it is removed from the list.
  1452. Element 8 can now process the data and pass it on to element 9s receptor. Element 9 is a ConvertToIndex
  1453. element that is using a technique which requires the entire image before it can continue. Since element 9
  1454. does not have sufficient data to execute, it is not added to the ready-list.
  1455. Assuming that element 8 has processed all of its data, it is removed from the list. With an empty list, the
  1456. scheduler examines the two import elements.  Noting that at least one ImportClient element is present,
  1457. control is returned to Core X.
  1458. After the initial execution cycle, the flo will only be executed when data is received from the client for an
  1459. ImportClient element. When such data arrives, the target ImportClient element (element 1) and all
  1460. ImportResource elements (element 7) will be placed on the ready-list.
  1461. After element 1 has generated a maximum of one strip of data, the following elements would be on the
  1462. ready list (elements 2, 3, and 6 all have sufficient data to execute with element 1s output):
  1463. 2 3 6 7
  1464. Element 2 would be executed next. Since it is an export element, it will exhaust all data passed to it and
  1465. be removed from the list. Element 3 will be processed next. Following its execution, element 4 will be
  1466. added to the front of the list and executed, causing elements 5 and 8 to be added to the list. Assuming that
  1467. elements 3 and 4 both have no further data to process, the resulting ready-list is:
  1468. 5 8 6 7
  1469. Element 5 is an export element and passes all data it receives. It is then removed from the list. Element 8
  1470. processes data available to it from elements 4 and 7. Since element 9 is still unable to execute, it is not
  1471. added to the list. This leaves the following ready-list:
  1472. 6 7
  1473. With the execution of element 6, element 8 is again added to the ready list. After element 6s data passes
  1474. to element 9s receptor the list is left with only element 7. Element 7 is executed to load another strip of
  1475. data from the server photomap. At this point, control is returned to Core X. The photoflo waits until it is
  1476. reactivated by more data being received from the client for element 1.
  1477. This process repeats until all data has been received from the client. Element 9 can then execute, which in
  1478. turn allows export elements 10 and 11 to execute. Element 9 stays on the list until it exhausts its data. At
  1479. this point, the photoflo operation is complete.
  1480.  
  1481. 10.3.3. Data Manager
  1482. It is the responsibility of the data manager to coordinate the flo of data between element outputs and
  1483. inputs. Since data is processed in strips, it will often be the case that data required by a downstream
  1484. element will span two or more buffers generated upstream. To eliminate the complexity and overhead of
  1485. concatenating data segments, data accesses within elements can be conducted on a line by line basis, while
  1486. data transfers between elements are conducted on a strip basis.
  1487. When an element is producing a strip of data, the buffer it is writing its data into is private to the element.
  1488. Only when the strip is passed back to the data manager is it made visible to downstream elements for
  1489. processing. When the completed strip of data is passed to the data manager, it is linked to a list of strips
  1490. maintained by each downstream receptor. As an element requires data, it reads in the data by
  1491. transferring strips from its receptor into its private data section. The element may then access individual
  1492. lines of data within the strip through a set of light-weight macros. These macros are provided as a tool to
  1493. simplify the access of scan lines within strips but do not preclude elements from operating on data in strip
  1494. form. When the element is done with the strip, it informs the data manager.
  1495. The strip itself contains a count of the number of references to the strip. When a strip is assigned as an
  1496. element output buffer, this count is 1.  When the completed strip is returned to the data manager the
  1497. reference count is set to the number of receptors that the strip is transferred to.  When an element asks the
  1498. data manager for an available strip, the reference count is unaffected until the element notifies the data
  1499. manager that it is done with the strip.
  1500. When an element finishes reading from a strip (or it has an output strip that it does not wish to
  1501. propagate), it informs the data manager and the reference count is decremented.  If the reference count is
  1502. decremented to 0, the strip is either freed or cached for re-use.
  1503. The data manager also provides a mechanism whereby in-place operations may be performed within the
  1504. strip.  When this is allowed, only a single element has access to the strip.  Since it is using it for both read
  1505. and write, the reference count is 2.  When it completes the strip it must give it to the data manager for
  1506. transfer downstream and notify the data manager that it is done reading it.
  1507. Elements access the data manager through five entry points:
  1508. *       MakeStrip : used by an element to obtain storage for data it intends to produce.
  1509. *       PutStrip: used by an element to give a completed strip of data back to the data manager (which then passes
  1510. it on to downstream receptors)
  1511. *       GetStrip: used by an element to read in a strip of data from its receptor
  1512. *       InPlaceStrip:  used to obtain in place privileges for a strip that it has obtained via GetStrip.  If the data
  1513. manager determines that another element also has access to the strip, a new strip is created instead.
  1514. *       FreeStrip: used by a receptor to inform the data manager that it has no further need for the strip it obtained
  1515. through GetStrip.  Also used by an element to return an unfilled data strip buffer to the data manager if for
  1516. any reason it decides to not fill it after allocating it through MakeStrip or InPlaceStrip.
  1517. To illustrate how data is passed from element to element, a runtime snapshot of an executing flo is shown
  1518. on the following page.
  1519. In the illustration, element w is performing its processing in place with strip A being used both as an
  1520. input and an output. Strips B and C are linked to element ws receptor indicating that they have not been
  1521. read in yet. Since strip B is at the head of the list, it will be processed next. Any new strips assigned to
  1522. element ws receptor would be linked after element C.
  1523. Strips D and E have been passed from element w to elements x and y. Element y has already processed the
  1524. data from strip D and has indicated to the data manager that it has finished with the strip. Element y is
  1525. currently processing Strip E and placing its output in strip F.  Element x is currently processing strip D
  1526. and has not yet read in strip E. Since element x hasnt read in strip E, it is still pointed to by element xs
  1527. receptor. Element x is placing its result into strip G. Element z has two inputs. Strips H and I are being
  1528. processed to form a result in strip J.
  1529.  
  1530.  
  1531.  
  1532. 10.3.4. Input
  1533. Dixie calls through the flo-def input entry point when data arrives from the client via a PutClientData
  1534. protocol request.  Input calls upon the data manager to create a non-canonic strip that describes the byte
  1535. stream segment, and then attaches it to the receptor of the import element handler that corresponds with
  1536. the phototag specified to PutClientData.  Input then passes control to the scheduler.
  1537.  
  1538. 10.3.5. Output
  1539. Dixie calls through the flo-def output entry point when data is to be retrieved for the client. Output calls
  1540. upon the data manager to fetch some non-canonic data from the export element that corresponds to the
  1541. phototag specified in the GetClientData protocol request.  If the client has asked for less data than is
  1542. available from the export element, it will leave the leftovers with the export element.  Otherwise, it will
  1543. take all data that is available.  Output returns the data and current output buffer status to dixie, which will
  1544. send this information on to the client in the form of a reply.
  1545.  
  1546. 10.3.6. Query
  1547. Dixie calls through the flo-def query entry point to find out if an import or export element handler is done.
  1548. Dixie will interrogate each import and export element separately.
  1549.  
  1550. 10.3.7. Abort
  1551. The photoflo will either complete normally, or dixie will call through the flo-def abort entry point to
  1552. terminate execution prematurely.  In either case the reset routine in each element is called.  It will also
  1553. call upon the data manager to release any strips it may have cached.
  1554.  
  1555. 10.3.8. Destroy
  1556. When dixie calls through the flo-def destroy entry point, the flo manager calls the destroy routine in each
  1557. element and then frees the flo-tex.
  1558.  
  1559.  
  1560. 11.     Photo Elements
  1561. An element is the basic execution unit of a photoflo.  An element consists of a body of code with supporting
  1562. structures.
  1563.  
  1564. 11.1.   Element Structures
  1565. Element structures are separated into a dixie part, a ddxie part, and an element-specific part.  The dixie photoflo
  1566. management routines only understand the dixie part.  The ddxie photoflo manager understands the dixie and ddxie
  1567. public parts.  Only the element itself understands the contents of the ddxie private part.  These structures are
  1568. illustrated below in conjunction with strips (which are handled by ddxie data manager routines and macros).
  1569.  
  1570.  
  1571. 11.2.   Element Interfaces
  1572. The external interface to each element consists of a set of entry points that are loaded into the pe-def by the DAG
  1573. analyzer and the photoflo linker.  These entry points are used by various components of the photoflo manager for
  1574. setup, execution, and shutdown of the element.
  1575.  
  1576. 11.2.1. Create
  1577. The create entry point is called by the photoflo linker.  It is responsible for attaching a pe-tex to the pe-
  1578. def.  It also loads the entry points into the pe-def.  It will also allocate or setup anything that can persist
  1579. over multiple executions.
  1580.  
  1581. 11.2.2. Initialize
  1582. The initialize entry point is called at photoflo startup.  It allocates and initializes run-time data for the
  1583. current execution instance.
  1584.  
  1585. 11.2.3. Activate
  1586. Activate is called by the scheduler when there is sufficient data available at one or more receptors.  It calls
  1587. upon the data manager to get data from its own receptors and to push data out to the receptors of
  1588. downstream elements.
  1589.  
  1590. 11.2.4. Flush
  1591. Flush is called when all of the upstream elements have completed their task.  This gives the element one
  1592. last opportunity to finish up.
  1593.  
  1594. 11.2.5. Reset
  1595. Reset is called at photoflo done time (i.e. flo completed successfully, or aborted due to an error or client
  1596. request).  Reset frees run-time data and structures that are left behind by the initialize, activate, or flush
  1597. routines.
  1598.  
  1599. 11.2.6. Destroy
  1600. Destroy is called to free data and structures that are allocated by the create routine, including the run-time
  1601. context itself (i.e. remove the pe-tex from the pe-def).
  1602.  
  1603.  
  1604. * There are three exceptions:
  1605. *       The entire buffer of data received from the protocol stream for an ImportClient element will be presented as a strip of non-
  1606. canonic data.  The element is then responsible for converting this byte stream of data into canonic form, and processing or
  1607. buffering the data prior to allowing control to be returned to core X.
  1608. *       Export elements pass data out of the flo allowing them to process all data available when executed.
  1609. *       LUT arrays are indivisible units.  Therefore, a strip containing a lookup table will contain the entire array for a single band.
  1610.  
  1611.  
  1612.  
  1613.  
  1614. Submitted to: MIT X Consortium
  1615. Submitted by: AGE Logic, Inc.
  1616.  
  1617.  
  1618. Page 48
  1619.  
  1620.  
  1621.