digitalmars.D - Which library do you use to read/write graphics files in D?
- zwang (2/2) Feb 04 2005 Is there a simple library that can do conversion between a graphics file...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (11/13) Feb 04 2005 Well, SDL_Surface is a popular format for such a "2d array in memory"
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (19/21) Feb 04 2005 Sorry, missed that you said "and write" in the subject.
- zwang (2/33) Feb 04 2005
Is there a simple library that can do conversion between a graphics file (png/bmp/jpg etc.) and a 2d array in memory?
Feb 04 2005
zwang wrote:Is there a simple library that can do conversion between a graphics file (png/bmp/jpg etc.) and a 2d array in memory?Well, SDL_Surface is a popular format for such a "2d array in memory" and SDL_image (http://www.libsdl.org/projects/SDL_image/) can be used to read formats other than the main uncompressed BMP that SDL does... libSDL is not written in D, but there exists D wrapper modules for it. A more common treatment of pixel images is to use a 1D array, though ? Usually a regular pointer, that you then offset with a number calculated as (y * pitch) + x * bpp. Where "pitch" is the number of bytes per row (incl. any alignment needed), and "bpp" the number of bytes per pixel. See http://www.libsdl.org/intro/usingvideo.html --anders
Feb 04 2005
zwang wrote: (and this is a followup to my last reply)Is there a simple library that can do conversion between a graphics file (png/bmp/jpg etc.) and a 2d array in memory?Sorry, missed that you said "and write" in the subject. SDL is *not* particularly good for reading / writing... GD is better for that: http://www.boutell.com/gd/ You will need libpng for PNG, and libjpeg for JPEG. And, as usual, you need a D module, for the C headers. Here's one for GD, http://www.algonet.se/~afb/d/gd.zip Seems to be working OK, using the standard test code: gdc -o gdtest -O2 -g gdtest.d -lgd -lpng -ljpeg gd/gd.d http://www.algonet.se/~afb/d/gdtest.d (something of a quick-ported C hack...) For some sample code, see the GD manual: (in C, but) http://www.boutell.com/gd/manual2.0.33.html#basics --anders PS. Most of the headers except macros were handled OK by my Perl hack, but one annoyance was that D complained about the use of the variables / parameters: in, out (the script is at http://www.algonet.se/~afb/d/h2d.pl)
Feb 04 2005
Thank you!! GD looks like what I need. Anders F Björklund wrote:zwang wrote: (and this is a followup to my last reply)Is there a simple library that can do conversion between a graphics file (png/bmp/jpg etc.) and a 2d array in memory?Sorry, missed that you said "and write" in the subject. SDL is *not* particularly good for reading / writing... GD is better for that: http://www.boutell.com/gd/ You will need libpng for PNG, and libjpeg for JPEG. And, as usual, you need a D module, for the C headers. Here's one for GD, http://www.algonet.se/~afb/d/gd.zip Seems to be working OK, using the standard test code: gdc -o gdtest -O2 -g gdtest.d -lgd -lpng -ljpeg gd/gd.d http://www.algonet.se/~afb/d/gdtest.d (something of a quick-ported C hack...) For some sample code, see the GD manual: (in C, but) http://www.boutell.com/gd/manual2.0.33.html#basics --anders PS. Most of the headers except macros were handled OK by my Perl hack, but one annoyance was that D complained about the use of the variables / parameters: in, out (the script is at http://www.algonet.se/~afb/d/h2d.pl)
Feb 04 2005