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-11 03:50:35 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!router1.news.adelphia.net!news1.news.adelphia.net.POSTED!not-for-mail From: Ron Baldwin Newsgroups: comp.lang.ada Subject: Re: Using PNG_IO to create a file. Message-ID: <12ofov4u785llp18ssiukos81ecm15i33l@4ax.com> References: <47ieov8r0j9mfst3lf8g79ukecn4d46tqc@4ax.com> X-Newsreader: Forte Free Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 11 Oct 2003 10:50:34 GMT NNTP-Posting-Host: 68.168.198.129 X-Complaints-To: abuse@adelphia.net X-Trace: news1.news.adelphia.net 1065869434 68.168.198.129 (Sat, 11 Oct 2003 06:50:34 EDT) NNTP-Posting-Date: Sat, 11 Oct 2003 06:50:34 EDT Xref: archiver1.google.com comp.lang.ada:658 Date: 2003-10-11T10:50:34+00:00 List-Id: 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 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," > wrote: > >> >>"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. >>