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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d0a54169fe032235 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-02 19:54:46 PST Path: archiver1.google.com!news2.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc01.POSTED!not-for-mail From: "Jeff C," Newsgroups: comp.lang.ada References: Subject: Re: Using PNG_IO to create a file. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 66.31.4.164 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc01 1065149685 66.31.4.164 (Fri, 03 Oct 2003 02:54:45 GMT) NNTP-Posting-Date: Fri, 03 Oct 2003 02:54:45 GMT Organization: Comcast Online Date: Fri, 03 Oct 2003 02:54:45 GMT Xref: archiver1.google.com comp.lang.ada:140 Date: 2003-10-03T02:54:45+00:00 List-Id: "Ron Baldwin" 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.