From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_20,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c329247dd63d7778 X-Google-Attributes: gid103376,public From: "Samuel T. Harris" Subject: Re: 1 and 2d image representations Date: 1997/10/28 Message-ID: <34561878.E24A7D3B@hso.link.com>#1/1 X-Deja-AN: 285585802 References: <344E97A8.688C@eleceng.adelaide.edu.au> <34556F0F.62B5@dynamite.com.au> Organization: Hughes Training Inc. - Houston Operations Newsgroups: comp.lang.ada Date: 1997-10-28T00:00:00+00:00 List-Id: Alan E & Carmel J Brain wrote: > > Richard Beare wrote: > > > I'm writing some image processing software and I'm concerned about my > > use of arrays. > > > Alternatively it is possible to represent an image as a linear array > > and provide functions to perform the mapping between 1 and 2 > > dimensions. > > > > Is there a sensible way to provide both the 1 and 2 dimensional > > views of the image. > > Sounds like a job for Representation clauses and Unchecked Conversion, > at first sight. > > > Can anyone comment on the overhead of using a linear array and > > functions to map from two dimensions to one (and vice versa). > > If performance is a big issue, then Unchecked Conversion really could be > the way to go. On many systems, the overhead is negligible. Trouble is, > of course, you can, depending on the compiler, optimise away all the > good things regarding boundary checking that Ada provides. It still > won't let you go outside the maximum size of the array, but internally, > it could. > Even "negligible" overhead of unchecked_conversion on a large image array can add up fast. As an alternative, whenever unchecked_conversion can be used, one can also use a address representation clause to force the destination object to reside "on top of" the source object thus eliminating the need for unchecked_conversion. For example ... type pixel is record red, green, blue : natural; end record; type image_2d is array (positive range <>, positive range <>) of pixel; type image_1d is array (positive range <>) of pixel; ... picture_2d : image_2d(1..100,1..100); picture_1d : image_1d(1..picture_2d'length(1)*picture_2d'length(2)); for picture_1d'address use picture_2d'address; -- Ada 95 -- for picture_1d use at picture_2d'address; -- Ada 83 This provides dual functionality without ANY overhead costs associated with unchecked_conversion. However, this is STATIC. Dynamic associations can be made "on-the-fly" by declaring picture_1d within a local declare block so it lives only as long as required. -- Samuel T. Harris, Senior Engineer Hughes Training, Inc. - Houston Operations 2224 Bay Area Blvd. Houston, TX 77058-2099 "If you can make it, We can fake it!"