save output aggpas to png and install problems lazarus / 39-Graphics ---------------------------------------------------------------------- K.Bleijenberg · 2014-01-10 09:27 In a command line application I want to create a few images, draw rectangles, text etc and save them as png. I don't want dependency on LCL. Is this possible with aggpas? I tried to install aggpas: The OS is Ubuntu 64 bits. Lazarus version 1.0.10 I save the source of aggpas in a map. I create a new project and added agg2D.pas. Add dependency LCLBase (the only dependency). The compiler stops while parsing agg_font_win32_tt. It cannot find the unit windows. Of course this is linux. I changed the target in the IDE to Linux. No luck. Someone suggested to add {$include agg_mode.inc} above the uses clause  => no luck. What can I do? ---------------------------------------------------------------------- hinst · 2014-01-10 10:33 Please take a look at this page: http://www.crossgl.com/aggpas/aggpas-download.htm There are 3 different versions of AggPas: for Windows, for Linux and for Mac. This probably means that AggPas library is not meant to use like some other libraries: one package for all systems. It has a separate package for each system instead. Please check if you have package for Linux ---------------------------------------------------------------------- K.Bleijenberg · 2014-01-10 10:52 Quote from: hinst on January 10, 2014, 11:33:40 amPlease take a look at this page: http://www.crossgl.com/aggpas/aggpas-download.htm There are 3 different versions of AggPas: for Windows, for Linux and for Mac. This probably means that AggPas library is not meant to use like some other libraries: one package for all systems. It has a separate package for each system instead. Please check if you have package for Linux I've downloaded the source from this page and unpacked the tar.gz for Linux to a directory and got the described problems. Kees ---------------------------------------------------------------------- hinst · 2014-01-10 11:25 I happen to work on a project in which I will probably use AggPas as well; and it should work on Ubuntu 64 bit as well, so maybe I will try to build it on my PC later today and see if it works ---------------------------------------------------------------------- K.Bleijenberg · 2014-01-10 14:20 Quote from: hinst on January 10, 2014, 12:25:30 pmI happen to work on a project in which I will probably use AggPas as well; and it should work on Ubuntu 64 bit as well, so maybe I will try to build it on my PC later today and see if it works That would be nice! Kees ---------------------------------------------------------------------- hinst · 2014-01-10 17:35 I managed to compile AGG on Ubuntu Linux 64 bit; I didn't have problems with Windows unit... However it seems that such easy task like drawing an image in memory and saving it to PNG file is very hard to accomplish with AggPas because it does not have any routines for exporting images to file..... The only way one could possibly do this is to attach TAgg2D instance to a bitmap from Graphics unit from LCL, then export the image using LCL units & routines ---------------------------------------------------------------------- hinst · 2014-01-10 17:50 Take a look at this sample plz: http://wiki.freepascal.org/fcl-image#Basic_Canvas_Setup looks like exactly what we need. One can render an image in memory and save it to file using fcl-image package; so external packages like AggPas are not even necessary ---------------------------------------------------------------------- Graeme · 2014-01-11 10:46 Quote from: K.Bleijenberg on January 10, 2014, 10:27:46 amIn a command line application I want to create a few images, draw rectangles, text etc and save them as png. I don't want dependency on LCL. Is this possible with aggpas?Yes it is possible. Simply copy the raw image buffer data to a FCL-Image container (eg: PNG, JPG etc), then save it to file. BTW: The original open sourced AggPas is a bit out of date. I have made some changes and bug fixes in AggPas included with fpGUI. You can get the latest AggPas code here [https://github.com/fredvs/fpGUI/tree/ master/src/corelib/render/software] Incidentally, the fpGUI repository contains some Agg/AggPas documentation too. There is a demo using pure AGG API (no other GUI dependencies) and shows how it writes the image buffer to a file. As I mentioned above, simple copy the image buffer to a FCL-Image container of choice, and write it to another image file format. See /docs/aggpas/basic_renderers.agdoc.html ---------------------------------------------------------------------- howardpc · 2014-01-11 10:55 Quote from: Graeme on January 11, 2014, 11:46:17 amIndecently, the fpGUI repository contains some Agg/AggPas documentation too. We presume you meant "incidentally" ---------------------------------------------------------------------- BigChimp · 2014-01-11 10:58 Well, I can understand the use of "indecently" when comparing the documentation effort of typical open source code (yes, looking at myself, too). Anyway, indecent documentation is far more likely to be remembered well than staid, boring, middle of the road documentation ---------------------------------------------------------------------- Graeme · 2014-01-11 10:58 Quote from: howardpc on January 11, 2014, 11:55:52 amWe presume you meant "incidentally" Fixed, thanks! [I'm still busy with my first cup of coffee, so not fully awake yet] ---------------------------------------------------------------------- Graeme · 2014-01-11 11:00 Quote from: BigChimp on January 11, 2014, 11:58:01 amAnyway, indecent documentation is far more likely to be remembered well than staid, boring, middle of the road documentation ROFL ---------------------------------------------------------------------- K.Bleijenberg · 2014-01-12 12:14 Quote from: Graeme Geldenhuys on January 11, 2014, 11:46:17 amQuote from: K.Bleijenberg on January 10, 2014, 10:27:46 amIn a command line application I want to create a few images, draw rectangles, text etc and save them as png. I don't want dependency on LCL. Is this possible with aggpas?Yes it is possible. Simply copy the raw image buffer data to a FCL-Image container (eg: PNG, JPG etc), then save it to file. BTW: The original open sourced AggPas is a bit out of date. I have made some changes and bug fixes in AggPas included with fpGUI. You can get the latest AggPas code here [https://github.com/fredvs/fpGUI/tree/ master/src/corelib/render/software] Incidentally, the fpGUI repository contains some Agg/AggPas documentation too. There is a demo using pure AGG API (no other GUI dependencies) and shows how it writes the image buffer to a file. As I mentioned above, simple copy the image buffer to a FCL-Image container of choice, and write it to another image file format. See /docs/aggpas/basic_renderers.agdoc.html I' ve downloaded the new version of aggpas and compiled it. No problems. I' ve read the part of the docs. The code is in cpp, I do not fully understand it, but.... my general idea for the program is: 1. create a TAgg2D 2 create a memory - TfpgImage and attach the Tagg2D to the TfpgImage 3. do the drawing with the methods of the TAgg2D 4. get the pointer to the memory of the memory-TfgpImage 5. create a TFPMemoryImage and fill all pixels with the pixels from the TAgg2D 6. save the TFpMemoryImage to png. Is this correct? At step 2, I have a problem. I've found functions like CreateImage_BMP (in fpg_imgfmt_bmp). This function creates a TfpgImage. If I want to work in the same direction as in the docs I need a function CreateImage_PPM. The memorybuffer is then a PPM buffer and not a bmp structure. Please help. Kees ---------------------------------------------------------------------- hinst · 2014-01-12 14:31 as far as I know: all fpgui units depend on either WinAPI GUI routines or X library on Linux, so in case you plan to use your application on server-only PC which has no X library installed, it is best not to use fpgui units at all. Quote...simple copy the image buffer to a FCL-Image container of choice...I think that using fpgui routines is not what he meant. Perhaps one should copy image from agg-pas render-buffer object to TFPMemoryImage instance Create agg-2d render buffer (I don't remember the class name now); Draw; Create TFPMemoryImage; Copy agg render buffer pixels to TFPMemoryImage instance; Save TFPMemoryImage to png; ;; do not use fpgui routines; the only thing you want from fpgui here is AggPas library with latest bug fixes applied to it ---------------------------------------------------------------------- benohb · 2014-01-12 15:52 There http://wiki.freepascal.org/fcl-image and http://imaginglib.sourceforge.net/index.php?page=about if aggpas ...you can use  aggpas with "Vampyre Imaging Library" for save as more format =From my project= Here I use cairo surface ...you can do this with aggpas Code: [Select]InitImage(Img); NewImage(cairo_image_surface_get_width(fc1),cairo_image_surface_get_he ight(fc1), ifA8R8G8B8, Img); //copy pixel. for I := 0 to (Img.Width-1) * (Img.Height-1) do Pinteger(Img.Bits)[I]:=Pinteger(cairo_image_surface_get_data(fc1))[i]; SaveImageToFile('/tmp/1.jpeg', Img); FreeImage(Img); QuoteBTW: The original open sourced AggPas is a bit out of date. I have made some changes and bug fixes in AggPas included with fpGUI. You can get the latest AggPas code here [https://github.com/fredvs/fpG UI/tree/master/src/corelib/render/software] If I was a girl  ....Thank you ---------------------------------------------------------------------- Graeme · 2014-01-12 19:05 Quote from: hinst on January 12, 2014, 03:31:10 pmI think that using fpgui routines is not what he meant. Perhaps one should copy image from agg-pas render-buffer object to TFPMemoryImage instance Create agg-2d render buffer (I don't remember the class name now); Draw; Create TFPMemoryImage; Copy agg render buffer pixels to TFPMemoryImage instance; Save TFPMemoryImage to png; Correct! Just use the latest agg-pas included with fpGUI, but you don't need to use the fpGUI API's or types. Just use AggPas and copy the image buffer created by AggPas directly to a fcl-image container. ---------------------------------------------------------------------- Graeme · 2014-01-12 19:37 Quote from: K.Bleijenberg on January 12, 2014, 01:14:01 pmIs this correct? You don't have to use the fpGUI API and data types. You can simply use only the AggPas included in the fpGUI repository. QuoteIf I want to work in the same direction as in the docs I need a function CreateImage_PPM. The memorybuffer is then a PPM buffer and not a bmp structure. PPM is a very very simplistic image format, and is very easy to implement, hence the original AGG author used it in the examples. You would use the AGGPAS API to generate the image you want in memory (image buffer created by AggPas), then copy the image data to the Data property of a FCL-Image data structure. FCL-Image supports many image formats like JPG, PNG, BMP, etc. ---------------------------------------------------------------------- Graeme · 2014-01-12 21:59 Quote from: K.Bleijenberg on January 10, 2014, 10:27:46 amIn a command line application I want to create a few images, draw rectangles, text etc and save them as png. I don't want dependency on LCL. Is this possible with aggpas? Here is a console example using only AggPas (directory included in fpGUI repository). It uses pure AggPas API - so not the easiest to learn, but the fpGUI repository contains AggPas documentation in the "docs" directory. You can obviously take the Agg2D.pas unit and modify it to use FPC's FPImage instead of fpGUI's TfpgImage. The TAgg2D class defines an API that is much easier to use, but doesn't have the full power of the AggPas library - though it should be good enough for most cases. ---------------------------------------------------------------------- hinst · 2014-01-13 18:07 @Graeme Geldenhuys Thanks; Meanwhile I was able to produce an example on my own: http://pastebin.com/BXHNjJ9N I'm not including it in this forum message text because it is pretty long. @K.Bleijenberg plz take a look at my code if still interested; Note how it is possible to use Agg2D object from agg_2D unit instead of using types like pixel_formats, renderer_base, renderer_scanline_aa_solid and others; it is easier and still does not require X window. Here are the results: Code: [Select]Draw: time spent: 0000.00.00 00:00:00.010 Image copy: time spent: 0000.00.00 00:00:00.017 Image encode: time spent: 0000.00.00 00:00:00.037 Total time: 0000.00.00 00:00:00.064 I generated an image of size 800 * 480. Please see image attached to this message It works very fast; it could work even faster if I didn't write file to disk (I intend to send the file over network in the future) I also noticed that JPEG writer is faster and more effective than PNG writer. It looks like PNG writer is imperfect at the time while JPEG encoder is mature. PNG writer produces 1 megabyte file for me (with highest compression enabled) while JPEG writer produces files only about 60 kilobytes in size and the quality of resulting image is good enough. However I still have one more question PLZ  Please take a look at the image attached to this message. Looks like AggPas can not display UTF-8 strings. I saw the code responsible for text drawing in AggPas; it draws every character separately; so there is no chance it supports UTF-8 or other multibyte encodings. So is there any way I can make it work? @Graeme Geldenhuys I think that you know the answer because your fpgui library uses AggPas and supports UTF-8 (I believe). Does fpgui use AggPas to render text? ---------------------------------------------------------------------- Cyrax · 2014-01-13 19:38 PNG have lossless (you wont lose picture information and quality) data compression, JPG is lossy (you lose picture information and quality). If you save JPG image again as JPG and many times, you will notice quality loss. ---------------------------------------------------------------------- Graeme · 2014-01-14 09:20 Quote from: hinst on January 13, 2014, 07:07:08 pmNote how it is possible to use Agg2D object from agg_2D unit instead of using types like pixel_formats, renderer_base, renderer_scanline_aa_solid and others; it is easier and still does not require X window. Of course you are correct. Saying that, I haven't really used (or modified) the agg_2D.pas unit (Object based unit), but instead worked more on the Agg2D.pas unit (class based unit). I'll use Beyond Compare to make sure all latest changes in Agg2D.pas are also present in agg_2D.pas unit. QuoteI also noticed that JPEG writer is faster and more effective than PNG writer. It looks like PNG writer is imperfect at the time... All FCL-Image code is pretty damn slow - for reading and writing. I had a fpGUI user that did extensive speed tests using various image libraries. FCL's one was by a big margin the slowest one of the bunch. But in a pinch it is still handy, and has no external dependencies (all compiled into the executable). QuotePlease take a look at the image attached to this message. Looks like AggPas can not display UTF-8 strings. fpGUI uses UTF-8 as it's string encoding, and I can output Unicode text with the AggPas backend - no problems. Maybe it is the agg_2D.pas unit that is out of date - as I mentioned earlier, I haven't really worked with that unit at all. I'll double check your code too, to see if I can spot anything unusual. BTW: Looking at your screenshot. Not use if the "fuzzy" grid lines is what you wanted or not, but you can make them pin-stripe (thin non- fuzzy) line. A quick and dirty way is to add 0.5 to the x and y values before you draw vertical or horizontal lines - not the fuzzy lines are only for vertical or horizontal line, not angled or curved lines. The Agg2D.pas unit has such functionality built in (eg: see the TAgg2D.Line() implementation and the AlignPoint() method. For background information on why the horizontal and vertical lines are fuzzy, take a look at /docs/aggpas/line_alignment.agdoc.html ---------------------------------------------------------------------- hinst · 2014-01-14 10:34 Quote from: Graeme Geldenhuys on January 14, 2014, 10:20:50 amI'll use Beyond Compare to make sure all latest changes in Agg2D.pas are also present in agg_2D.pas unit. It would be nice; please do it if you have time Quote from: Graeme Geldenhuys on January 14, 2014, 10:20:50 am...instead worked more on the Agg2D.pas unit (class based unit) I understand that Agg2D unit depends on X window library and also on fpgui units while agg_2D unit does not; this is why I tried to use agg_2D unit Quote from: Graeme Geldenhuys on January 14, 2014, 10:20:50 amfpGUI uses UTF-8 as it's string encoding, and I can output Unicode text with the AggPas backend - no problems. Perhaps you added UTF-8 support to AggPas yourself some time ago but it was not present in the original library which is still hosted at aggpas.org ---------------------------------------------------------------------- taazz · 2014-01-14 10:49 Does aggPas has text processing capabilities? Last time I checked it didn't have any, it required FreeType or some other library to be able to write text, well as far as I can remember any way. ---------------------------------------------------------------------- Graeme · 2014-01-14 11:55 Quote from: hinst on January 14, 2014, 11:34:29 amQuote from: Graeme Geldenhuys on January 14, 2014, 10:20:50 amI'll use Beyond Compare to make sure all latest changes in Agg2D.pas are also present in agg_2D.pas unit. It would be nice; please do it if you have time I had a quick look and there are quite a bit I can merge into the agg_2d.pas unit. I'll make it so. QuoteI understand that Agg2D unit depends on X window library and also on fpgui units while agg_2D unit does not; this is why I tried to use agg_2D unit Yes, the Agg2D unit needed to know how to paint to a X11 or GDI canvas - no other functionality was used. But it is a dependency none the less. ;-)  It is a good idea to keep the agg_2D.pas unit in sync though. It shouldn't be much work, and at least leaves the possibility open to use Agg2D without any GUI toolkit dependencies - plus it is a lot easier to use than the native AggPas API. A good idea. :-) QuotePerhaps you added UTF-8 support to AggPas yourself some time ago but it was not present in the original library which is still hosted at aggpas.org I had a quick look in the repository history. Yes, I added UTF-8 support to Agg2D.pas unit back in early 2012. I'll try and merge those changes to agg_2D.pas too. ---------------------------------------------------------------------- Graeme · 2014-01-14 12:05 Quote from: taazz on January 14, 2014, 11:49:38 amDoes aggPas has text processing capabilities? Last time I checked it didn't have any, it required FreeType or some other library to be able to write text, well as far as I can remember any way. All graphics libraries (at least the ones I know) that require text support, need to read fonts in some way or other. AggPas is no different. It uses the FreeType library (.DLL or .SO) or Windows Font Support (configurable) to extract the font glyphs (vector data, not bitmaps). It then adds that vector information to the AggPas pipeline rendering, which generates text output. The FreeType library is an independent library, and can easily be deployed with your application (though it is normally installed on Unix-like systems as standard). Somebody implemented (ported) the FreeType library to Object Pascal, so in theory the FreeType Library dependency could be removed. But I don't know how well that ported FreeType library is maintained, and what version of the original FreeType Library was ported. So for now I'll stay with the original external FreeType Library for font glyph support. ---------------------------------------------------------------------- taazz · 2014-01-14 12:11 freetype library 101 http://wiki.freepascal.org/Freetype, http://freetype.org/freetype1/index.html, freetype V1 was written in pascal. I see your point, though I wonder, if that is the case then aggPas does not need utf8 support as long as the text library returns the correct glyphs. In any case good to know. ---------------------------------------------------------------------- Graeme · 2014-01-14 13:45 Quote from: taazz on January 14, 2014, 01:11:59 pmfreetype library 101 http://wiki.freepascal.org/Freetype Yeah that is a very old version of FreeType. I'll test it either way. It might just work - who knows. :-) Thanks for those links. I never knew FreeType was originally written in Pascal. The good old days when Pascal was used for everything. :-) Quoteif that is the case then aggPas does not need utf8 support as long as the text library returns the correct glyphs. In any case good to know. To support UTF-8 was very little work. Only the correct amount of bytes had to be passes to represent a Unicode character. FreeType took care of the rest. ---------------------------------------------------------------------- K.Bleijenberg · 2014-01-14 21:10 Quote from: hinst on January 13, 2014, 07:07:08 pm@Graeme Geldenhuys Thanks; Meanwhile I was able to produce an example on my own: http://pastebin.com/BXHNjJ9N I'm not including it in this forum message text because it is pretty long. @K.Bleijenberg plz take a look at my code if still interested; .... Thank you! This example saves me a lot of work. I thought that TAgg2D had dependency's on X11. In a few earlier experiments things went wrong. The cgi-program (written in Haskell) called the Lazarus program. The lazarus program worked fine from the commandline, but called  by the  CGI program I got: internal server error, could not load Gtk.. Even if the I only thing the Lazarus program did, was echoing the input from stdIn to stdOut. I've tested this with your example and everything went well. Kees