comp.lang.ada
 help / color / mirror / Atom feed
From: Ron Baldwin <no-spam-rebaldwin@adelphia.net>
Subject: Re: Using PNG_IO to create a file.
Date: Sat, 11 Oct 2003 10:50:34 GMT
Date: 2003-10-11T10:50:34+00:00	[thread overview]
Message-ID: <12ofov4u785llp18ssiukos81ecm15i33l@4ax.com> (raw)
In-Reply-To: 47ieov8r0j9mfst3lf8g79ukecn4d46tqc@4ax.com

Oops, I found my error in defining types.  It works fine now.  Thanks
for your help.

On Sat, 11 Oct 2003 00:10:09 GMT, Ron Baldwin
<no-spam-rebaldwin@adelphia.net> wrote:

>When I set thiings up this way, the compiler complains that no visible
>subprogram matches the definition for grey_sample because it is
>defined to return type "sample" instead of Natural.
>
>On Fri, 03 Oct 2003 02:54:45 GMT, "Jeff C,"
><nolongersafeto@userealemailsniff.com> wrote:
>
>>
>>"Ron Baldwin" <re(nospam)baldwin@adelphia.net> wrote in message
>>news:bV2fb.1204$qj6.1035959@news1.news.adelphia.net...
>>> I need to read .PNG format graphics images from a file, process the image
>>as
>>> a two-dimensional array, then write the processed image out to a  new
>>file.
>>>
>>> I have used the PNG_IO package to read data from files, but I can't figure
>>> out how to get the data from a two-dimensional array to the
>>Write_PNG_Type_?
>>> output procedures.
>>>
>>> Does anyone have some examples of such an operation?
>>
>>
>>There is an example in the png_test.adb file that ships with png_io.
>>
>>
>>You just need to instantiate one of the Write_PNG_Type_X procedures with the
>>appropriate
>>parameters.
>>
>>Now I suspect you looked at this a little already so I am probably telling
>>you things you already know.
>>
>>Lets look at an example. The spec for one of the procedures is
>>
>> generic
>>    type Image_Handle is limited private;
>>    type Sample       is range <>;
>>    with function Grey_Sample(I    : Image_Handle;
>>                              R, C : Coordinate) return Sample;
>>  procedure Write_PNG_Type_0(Filename  : in String;
>>                             I         : in Image_Handle;
>>                             X, Y      : in Dimension;
>>                             Bit_Depth : in Depth   := Eight;
>>                             Interlace : in Boolean := False;
>>                             Ancillary : in Chunk_List := Null_Chunk_List);
>>
>>This is for a greyscale image which of course is the simplest case...So you
>>need to write a function that takes in
>>three parameter types. One should be the type of your 2d array, the other
>>two are the index values to the array and finally the function should return
>>the value at the row and column passed to it.
>>
>>So, for example assume you created a 2-d array like
>>
>>   type My_Pixel_Type is range 0 .. 100;
>>
>>   type Cool_Picture_Type is array (Coordinate range 0 .. 9, Coordinate
>>range 0 .. 19) of My_Pixel_Type;
>>
>>   and you had a variable
>>   Picture : Cool_Picture_Type
>>
>>   that you had read your data into
>>
>>   you need to write
>>
>>   function Get_Picture_Pixel(From_Array : in Cool_Picture_Type;
>>                                            Row, Column : in Coordinate)
>>return Natural;
>>
>>   and simply implement it as
>>
>>
>>   function Get_Picture_Pixel(From_Array : in Cool_Picture_Type;
>>                                            Row, Column : in Coordinate)
>>return Natural is
>>
>>  begin
>>     return From_Array(Row, Column);
>>  end Get_Picture_Pixel;
>>
>>
>>
>>To create a write procedure that uses your function you would do
>>
>>   procedure Write_Cool_Picture is new Write_PNG_Type_0
>>      (Image_Handle => Cool_Picture_Type;
>>        Sample            => My_Pixel_Type,
>>        Grey_Sample  => Get_Picture_Pixel);
>>
>>
>>
>>  You could then use the new procedure you created to write a file
>>containing the data from the Picture by doing
>>
>>     Write_Cool_Picture(Filename => "adarules.png",
>>                                     I             => Picture,
>>                                     X            => Picture'length(2),
>>                                     Y            => Picture'length(1));
>>
>>
>>And that's it.
>>
>>
>>Now obviously the stuff above is not in the order to feed to a compiler.
>>Quite possibly I goofed on a few
>>syntax elements and/or swaped rows and columns someplace....
>>
>>But since this seemed more like a basic programming question that is
>>somewhat answered by the code I hoped
>>that presenting it in this format would be more useful than yet another
>>example like in the test driver.
>>




      reply	other threads:[~2003-10-11 10:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-02 23:54 Using PNG_IO to create a file Ron Baldwin
2003-10-03  2:54 ` Jeff C,
2003-10-11  0:10   ` Ron Baldwin
2003-10-11 10:50     ` Ron Baldwin [this message]
replies disabled

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