comp.lang.ada
 help / color / mirror / Atom feed
From: "Samuel T. Harris" <s_harris@hso.link.com>
Subject: Re: 1 and 2d image representations
Date: 1997/10/28
Date: 1997-10-28T00:00:00+00:00	[thread overview]
Message-ID: <34561878.E24A7D3B@hso.link.com> (raw)
In-Reply-To: 34556F0F.62B5@dynamite.com.au


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!"




  reply	other threads:[~1997-10-28  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-23  0:00 1 and 2d image representations Richard Beare
1997-10-27  0:00 ` Alan E & Carmel J Brain
1997-10-28  0:00   ` Samuel T. Harris [this message]
1997-11-01  0:00   ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox