--- trunk/tntnet/dynamic/gd-cpp/gdpp.h 2007/12/01 19:28:31 115 +++ trunk/tntnet/dynamic/gd-cpp/gdpp.h 2007/12/17 19:14:37 298 @@ -1,26 +1,48 @@ -#ifndef GDPP_H -#define GDPP_H 1 -#ifdef __cplusplus - -#include "gd.h" -#include "gd_io_stream.h" -#include - -/* Example usage, convert png to gif: +/* ***************************************************************************** +** $Id: gdpp.h,v 1.2 2007/12/16 21:31:27 kshepherd Exp $ +** Initial file written and documented by: +** Kevin Shepherd December 2007 +** of Scarlet Line http://www.scarletline.com/ +** with contributions from Torben Nielsen. +*******************************************************************************/ +/** \file gdpp.h + \brief Object Oriented C++ wrappers around libgd functionality. + + Example usage, convert png to gif: #include #include std::ifstream in("image.png", std::ios_base::in | std::ios_base::binary ); - GD::Image im(in); + GD::Image im(in, GD::Png_tag()); if (im.good()) { std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary ); im.Gif(out); } */ +#ifdef __cplusplus +#ifndef _gdpp_h +#define _gdpp_h +#include "gd_io_stream.h" +#include + +/// namespace GD:: contains the C++ wrapper classes for libgd +/** This namespace is primarily to avoid name clashes, and to + contain all of the gd classes within one namespace. + It is not recommended to use the "using namespace" directive with this namespace. + Example usage: + GD::Image im(64, 32, true); // Create a truecolor image 64 pixels wide by 32 pixels high + GD::Point pt(10, 8); // The point at x=10, y=8. + GD::Size sz(16, 8); // The size width=16, height=8. + GD::TrueColor col(0xFF, 0, 0); // The colour red; R=255, G=0, B=0. + im.Rectangle(pt, sz, col.Int()); // Draw a red rectangle with top left corner at pt, of size sz. +*/ namespace GD { + /** This class GD::Point stores a point in two dimensions, somewhere + on the plane of an image. + */ class Point { public: @@ -60,6 +82,9 @@ int _x, _y; }; typedef Point * PointPtr; + /** This class GD::Size stores length in two dimensions. + Giving the size of an area as width and height. + */ class Size { public: @@ -97,6 +122,9 @@ }; typedef Size * SizePtr; + /** This class GD::TrueColor stores a colour as an RGBA quadruplet. + It can also be read as an integer, and in other colour formats. + */ class TrueColor { public: @@ -151,30 +179,35 @@ protected: as_types internal; }; - + /* The following tags are simply empty structures which are used + to tell the compiler which constructor we want when we know + the image file format. + */ + struct Png_tag {}; + struct Gif_tag {}; + struct WBMP_tag {}; + struct Jpeg_tag {}; + struct Gd_tag {}; + struct Gd2_tag {}; + struct Xbm_tag {}; + + /** This class GD::Image wraps all of the 'C' libgd functionality + for the convenience of C++ users. An instance of this class + corresponds to a single image. + */ class BGD_EXPORT_DATA_IMPL Image -// class Image { public: - struct Png_tag {}; - static Png_tag type_Png; - struct Gif_tag {}; - static Gif_tag type_Gif; - struct WBMP_tag {}; - static WBMP_tag type_WBMP; - struct Jpeg_tag {}; - static Jpeg_tag type_Jpeg; - struct Gd_tag {}; - static Gd_tag type_Gd; - struct Gd2_tag {}; - static Gd2_tag type_Gd2; - struct Xbm_tag {}; - static Xbm_tag type_Xbm; - + /** Construct a null image + */ Image() :im(0) {} - + /** Construct a blank image, of the given size and colour format type. + \param[in] sx Width of the image + \param[in] sy Height of the image + \param[in] istruecolor Create a true colour image, defaults to false, i.e. create an indexed palette image. + */ Image(int sx, int sy, bool istruecolor = false) :im(0) { @@ -183,6 +216,10 @@ else Create(sx, sy); } + /** Construct a blank image, of the given size and colour format type. + \param[in] s Width and height of the image + \param[in] istruecolor Create a true colour image, defaults to false, i.e. create an indexed palette image. + */ Image(const Size & s, bool istruecolor = false) :im(0) { @@ -191,97 +228,303 @@ else Create(s); } - + /** Construct an instance of the GD::Image class, given the internal gdImage poimter. + Note that gdImageDestroy will be called on the image pointer in the destructor. + \param[in] i Pointer to the internal gdImage + */ Image(gdImagePtr i) :im(i) {} - + /** Copy constructor. Construct an instance of the GD::Image class, + by making a copy of the GD::Image provided. + \param[in] i Reference to the image to be copied + */ + Image(const GD::Image & i) + :im(0) + { + Copy(i); + } + /** Construct an image by reading from \p in. This constructor + will first attempt to determine the file format. + \param[in] in The stream containing the image data + */ Image(std::istream & in) :im(0) { CreateFrom(in); } + /** Construct an image by reading from \p in. This constructor + will first attempt to determine the file format. + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in) :im(0) { CreateFrom(in); } + /** Construct an image by reading from memory block \p data. This constructor + will first attempt to determine the image formatting. + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ + Image(int size, void * data) + :im(0) { CreateFrom(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, Png_tag) :im(0) { CreateFromPng(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Png_tag) :im(0) { CreateFromPng(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, Png_tag) :im(0) { CreateFromPng(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::Png_tag()); // read a png file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, Png_tag) :im(0) { CreateFromPng(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, Gif_tag) :im(0) { CreateFromGif(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Gif_tag) :im(0) { CreateFromGif(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, Gif_tag) :im(0) { CreateFromGif(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::Gif_tag()); // read a gif file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, Gif_tag) :im(0) { CreateFromGif(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, WBMP_tag) :im(0) { CreateFromWBMP(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, WBMP_tag) :im(0) { CreateFromWBMP(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, WBMP_tag) :im(0) { CreateFromWBMP(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::WBMP_tag()); // read a monchrome WBMP file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, WBMP_tag) :im(0) { CreateFromWBMP(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, Jpeg_tag) :im(0) { CreateFromJpeg(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Jpeg_tag) :im(0) { CreateFromJpeg(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, Jpeg_tag) :im(0) { CreateFromJpeg(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::Jpeg_tag()); // read a jpeg file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, Jpeg_tag) :im(0) { CreateFromJpeg(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, Gd_tag) :im(0) { CreateFromGd(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Gd_tag) :im(0) { CreateFromGd(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, Gd_tag) :im(0) { CreateFromGd(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::Gd_tag()); // read a gd file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, Gd_tag) :im(0) { CreateFromGd(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gd2_tag()); // read a gd2 file from input + \param[in] in The stream containing the image data + */ Image(std::istream & in, Gd2_tag) :im(0) { CreateFromGd2(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Gd2_tag) :im(0) { CreateFromGd2(in); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Gd2_tag()); // read a gd2 file from input + \param[in] in The io context from which to read the image data + */ Image(gdIOCtx * in, Gd2_tag) :im(0) { CreateFromGd2(in); } + /** Construct an image by reading from memory block \p data. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(sz, dat, GD::Gd2_tag()); // read a gd2 file from dat + \param[in] size The byte count of the memory block + \param[in] data Pointer to the memory block + */ Image(int size, void * data, Gd2_tag) :im(0) { CreateFromGd2(size, data); } + /** Construct an image by reading from \p in. + The tag is an empty struct which simply tells the compiler which image read function to use. + e.g. GD::Image img(input, GD::Xbm_tag()); // read an xbm file from input + \param[in] in An opened FILE * handle to a file containing the image data + */ Image(FILE * in, Xbm_tag) :im(0) { CreateFromXbm(in); } ~Image() { clear(); } - + + /** Assignment Operator. Make this a copy of the GD::Image provided. + \param[in] src Reference to the image to be copied + */ + GD::Image & operator=(const GD::Image & src) + { + Copy(src); + return (* this); + } + /** Make this an exact copy of the GD::Image provided. Any existing iamge data is discarded. + \param[in] src Reference to the image to be copied + */ + void Copy(const GD::Image & src) + { + int w = src.Width(), h = src.Height(); + if (src.IsTrueColor()) + CreateTrueColor(w, h); + else + { + Create(w, h); + PaletteCopy(src); + } + Copy(src, 0, 0, 0, 0, w, h); + } + /** Check to see if this appears to be a valid image + */ bool good() const { return (im != 0); } // Creation: + /** + Create a palette-based image, with no more than 256 colors. + \param sx Width of the desired image + \param sy Height of the desired image + \return true if it worked, else false + */ bool Create(int sx, int sy) { clear(); return ((im = gdImageCreate(sx, sy)) != 0); } + /** + Create a truecolor image. + \param sx Width of the desired image + \param sy Height of the desired image + \return true if it worked, else false + */ bool CreateTrueColor(int sx, int sy) { clear(); return ((im = gdImageCreateTrueColor(sx, sy)) != 0); } + /** + Create a palette-based image, with no more than 256 colors. + \param s Width and height of the desired image + \return true if it worked, else false + */ bool Create(const Size & s) { return Create(s.W(), s.H()); } + /** + Create a truecolor image. + \param s Width and height of the desired image + \return true if it worked, else false + */ bool CreateTrueColor(const Size & s) { return CreateTrueColor(s.W(), s.H()); } - // Tagged - bool CreateFrom(FILE * in, Png_tag) - { return CreateFromPng(in); } + // Create, determining the image format from the data + /// Read an image from an open FILE * handle, after determining the image format bool CreateFrom(FILE * in); + /// Read an image from an open standard library input stream, after determining the image format bool CreateFrom(std::istream & in); + /// Read an image from a memory block, after determining the image format + bool CreateFrom(int size, void * data); // Png bool CreateFromPng(FILE * in) { @@ -349,21 +592,56 @@ return ((im = gdImageCreateFromWBMPCtx( & _in_ctx)) != 0); } // Jpeg + /** + Load a truecolor image from a JPEG format file. + Invoke CreateFromJpeg with an already opened + pointer to a file containing the desired image. + CreateFromJpeg does not close the file. + \return true for success, or false if unable to load the image (most often because + the file is corrupt or does not contain a JPEG image). + You can call Width() and Height() member functions of the image to determine its + size. The returned image is always a truecolor image. + */ bool CreateFromJpeg(FILE * in) { clear(); return ((im = gdImageCreateFromJpeg(in)) != 0); } + /** + Load a truecolor image from a JPEG format file. + Invoke CreateFromJpeg with an already opened + pointer to a file containing the desired image. + CreateFromJpeg does not close the file. + \return true for success, or false if unable to load the image (most often because the file is corrupt or does not contain a JPEG image). + You can call Width() and Height() member functions of the image to determine its + size. The returned image is always a truecolor image. + */ bool CreateFromJpeg(gdIOCtx * in) { clear(); return ((im = gdImageCreateFromJpegCtx(in)) != 0); } + /** + Load a truecolor image from a JPEG format file. + Invoke CreateFromJpeg with an already opened + pointer to a file containing the desired image. + CreateFromJpeg does not close the file. + \return true for success, or false if unable to load the image (most often because the file is corrupt or does not contain a JPEG image). + You can call Width() and Height() member functions of the image to determine its + size. The returned image is always a truecolor image. + */ bool CreateFromJpeg(int size, void * data) { clear(); return ((im = gdImageCreateFromJpegPtr(size, data)) != 0); } + /** + Load a truecolor image from a JPEG format file. + Invoke CreateFromJpeg with an image file in memory. + \return true for success, or false if unable to load the image (most often because the format is corrupt or does not contain a JPEG image). + You can call Width() and Height() member functions of the image to determine its + size. The returned image is always a truecolor image. + */ bool CreateFromJpeg(std::istream & in) { clear(); @@ -456,8 +734,8 @@ clear(); return ((im = gdImageCreateFromXpm(filename)) != 0); } - bool CreateFromXpm(const std::string & filename) - { return CreateFromXpm(filename.c_str()); } + bool CreateFromXpm(std::string & filename) + { return CreateFromXpm((char *)(filename.c_str())); } // Accessors, Updaters & Methods: void SetPixel(int x, int y, int color) @@ -639,60 +917,159 @@ void PaletteCopy(gdImagePtr src) { gdImagePaletteCopy(im, src); } + void PaletteCopy(const GD::Image & src) + { PaletteCopy(src.im); } + /** + Write out this image in GIF file format to \p out. + \param out A FILE * handle + */ void Gif(FILE * out) const { gdImageGif(im, out); } + /** + Write out this image in GIF file format to \p out. + \param out A gdIOCtx * handle + */ void Gif(gdIOCtx * out) const { gdImageGifCtx(im, out); } + /** + Allocate sufficient memory, and write this image, in GIF file format, to that memory. + \param size A pointer for the allocated memory + \return A pointer to the allocated memory, containing the image GIF file formatted. Caller is responsible for freeing with gdFree(). + */ void * Gif(int * size) const { return gdImageGifPtr(im, size); } + /** + Write out this image in GIF file format to \p out. + \param out An output stream, already opened. + */ void Gif(std::ostream & out) const { ostreamIOCtx _out_ctx(out); gdImageGifCtx(im, & _out_ctx); } + /** + Write out this image in PNG file format to \p out. + \param out A FILE * handle + */ void Png(FILE * out) const { gdImagePng(im, out); } + /** + Write out this image in PNG file format to \p out. + \param out A gdIOCtx * handle + */ void Png(gdIOCtx * out) const { gdImagePngCtx(im, out); } + /** + Allocate sufficient memory, and write this image, in PNG file format, to that memory. + \param size A pointer for the allocated memory + \return A pointer to the allocated memory, containing the image PNG file formatted. Caller is responsible for freeing with gdFree(). + */ void * Png(int * size) const { return gdImagePngPtr(im, size); } + /** + Write out this image in PNG file format to \p out. + \param out An output stream, already opened. + */ void Png(std::ostream & out) const { ostreamIOCtx _out_ctx(out); gdImagePngCtx(im, & _out_ctx); } + /** + Write out this image in PNG file format to \p out. + \param out A FILE * handle + \param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level + */ void Png(FILE * out, int level) const { gdImagePngEx(im, out, level); } + /** + Write out this image in PNG file format to \p out. + \param out A gdIOCtx * handle + \param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level + */ void Png(gdIOCtx * out, int level) const { gdImagePngCtxEx(im, out, level); } + /** + Allocate sufficient memory, and write this image, in PNG file format, to that memory. + \param size A pointer for the allocated memory + \param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level + \return A pointer to the allocated memory, containing the image PNG file formatted. Caller is responsible for freeing with gdFree(). + */ void * Png(int * size, int level) const { return gdImagePngPtrEx(im, size, level); } + /** + Write out this image in PNG file format to \p out. + \param out An output stream, already opened. + \param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level + */ void Png(std::ostream & out, int level) const { ostreamIOCtx _out_ctx(out); gdImagePngCtxEx(im, & _out_ctx, level); } + /** + Write out this image in WBMP file format ( black and white only ) to \p out. + \param fg The color index of the foreground. All other pixels considered background. + \param out A FILE * handle + */ void WBMP(int fg, FILE * out) const { gdImageWBMP(im, fg, out); } + /** + Write out this image in WBMP file format ( black and white only ) to \p out. + \param fg The color index of the foreground. All other pixels considered background. + \param out A gdIOCtx * handle + */ void WBMP(int fg, gdIOCtx * out) const { gdImageWBMPCtx(im, fg, out); } + /** + Allocate sufficient memory, and write this image, in WBMP file format ( black and white only ), to that memory. + \param size A pointer for the allocated memory + \param fg The color index of the foreground. All other pixels considered background. + \return A pointer to the allocated memory, containing the image WBMP file formatted. Caller is responsible for freeing with gdFree(). + */ void * WBMP(int * size, int fg) const { return gdImageWBMPPtr(im, size, fg); } + /** + Write out this image in WBMP file format ( black and white only ) to \p out. + \param fg The color index of the foreground. All other pixels considered background. + \param out An output stream, already opened. + */ void WBMP(int fg, std::ostream & out) const { ostreamIOCtx _out_ctx(out); gdImageWBMPCtx(im, fg, & _out_ctx); } + /** + Write out this image in JPEG file format to \p out. + \param out A FILE * handle + \param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". + */ void Jpeg(FILE * out, int quality = -1) const { gdImageJpeg(im, out, quality); } + /** + Write out this image in JPEG file format to \p out. + \param out A gdIOCtx * handle + \param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". + */ void Jpeg(gdIOCtx * out, int quality = -1) const { gdImageJpegCtx(im, out, quality); } + /** + Allocate sufficient memory, and write this image, in JPEG file format, to that memory. + \param size A pointer for the allocated memory + \param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". + \return A pointer to the allocated memory, containing the image JPEG file formatted. Caller is responsible for freeing with gdFree(). + */ void * Jpeg(int * size, int quality = -1) const { return gdImageJpegPtr(im, size, quality); } + /** + Write out this image in JPEG file format to \p out. + \param out An output stream, already opened. + \param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". + */ void Jpeg(std::ostream & out, int quality = -1) const { ostreamIOCtx _out_ctx(out); @@ -703,18 +1080,24 @@ { gdImageGifAnimBegin(im, out, GlobalCM, Loops); } void GifAnimAdd(FILE * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const { gdImageGifAnimAdd(im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } + void GifAnimAdd(FILE * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const + { GifAnimAdd(out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } inline static void GifAnimEnd(FILE * out) { gdImageGifAnimEnd(out); } void GifAnimBegin(gdIOCtx * out, int GlobalCM, int Loops) const { gdImageGifAnimBeginCtx(im, out, GlobalCM, Loops); } void GifAnimAdd(gdIOCtx * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const { gdImageGifAnimAddCtx(im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } + void GifAnimAdd(gdIOCtx * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const + { GifAnimAdd(out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } inline static void GifAnimEnd(gdIOCtx * out) { gdImageGifAnimEndCtx(out); } void * GifAnimBegin(int * size, int GlobalCM, int Loops) const { return gdImageGifAnimBeginPtr(im, size, GlobalCM, Loops); } void * GifAnimAdd(int * size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const { return gdImageGifAnimAddPtr(im, size, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } + void * GifAnimAdd(int * size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const + { return GifAnimAdd(size, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } inline static void * GifAnimEnd(int * size) { return gdImageGifAnimEndPtr(size); } @@ -729,6 +1112,9 @@ void Ellipse(int cx, int cy, int w, int h, int color) { gdImageEllipse(im, cx, cy, w, h, color); } + /** + Draw a partial ellipse centered at the given point, with the specified width and height in pixels. + */ void FilledArc(int cx, int cy, int w, int h, int s, int e, int color, int style) { gdImageFilledArc(im, cx, cy, w, h, s, e, color, style); } void Arc(int cx, int cy, int w, int h, int s, int e, int color) @@ -762,8 +1148,8 @@ void CopyResized(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) { gdImageCopyResized(im, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } - void CopyResampled(const Image& src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) - { gdImageCopyResampled(im, src.im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } + void CopyResampled(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) + { gdImageCopyResampled(im, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } void CopyRotated(const gdImagePtr src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle) { gdImageCopyRotated(im, src, dstX, dstY, srcX, srcY, srcWidth, srcHeight, angle); } @@ -776,15 +1162,47 @@ void CopyResized(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) { CopyResized(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } - void CopyResampled(const Image& src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) + void CopyResampled(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) { CopyResampled(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } void CopyRotated(const gdImagePtr src, double dstX, double dstY, const Point & srcP, const Size & srcS, int angle) { CopyRotated(src, dstX, dstY, srcP.X(), srcP.Y(), srcS.W(), srcS.H(), angle); } + void Copy(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h) + { Copy(src.im, dstX, dstY, srcX, srcY, w, h); } + void CopyMerge(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) + { CopyMerge(src.im, dstX, dstY, srcX, srcY, w, h, pct); } + void CopyMergeGray(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) + { CopyMergeGray(src.im, dstX, dstY, srcX, srcY, w, h, pct); } + + void CopyResized(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) + { CopyResized(src.im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } + void CopyResampled(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) + { CopyResampled(src.im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } + void CopyRotated(const GD::Image & src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle) + { CopyRotated(src.im, dstX, dstY, srcX, srcY, srcWidth, srcHeight, angle); } + + void Copy(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s) + { Copy(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H()); } + void CopyMerge(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s, int pct) + { CopyMerge(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } + void CopyMergeGray(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s, int pct) + { CopyMergeGray(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } + + void CopyResized(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) + { CopyResized(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } + void CopyResampled(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) + { CopyResampled(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } + void CopyRotated(const GD::Image & src, double dstX, double dstY, const Point & srcP, const Size & srcS, int angle) + { CopyRotated(src.im, dstX, dstY, srcP.X(), srcP.Y(), srcS.W(), srcS.H(), angle); } + void SetBrush(gdImagePtr brush) { gdImageSetBrush(im, brush); } + void SetBrush(const GD::Image & brush) + { SetBrush(brush.im); } void SetTile(gdImagePtr tile) { gdImageSetTile(im, tile); } + void SetTile(const GD::Image & tile) + { SetTile(tile.im); } void SetAntiAliased(int c) { gdImageSetAntiAliased(im, c); } void SetAntiAliasedDontBlend(int c, int dont_blend) @@ -832,8 +1250,11 @@ int TrueColorPixel(int x, int y) const { return gdImageTrueColorPixel(im, x, y); } + const gdImagePtr GetPtr() const + { return im; } protected: + /// Free the internal image pointer void clear() { if (im) @@ -843,7 +1264,8 @@ gdImagePtr im; }; } // namespace GD +/// Read in an image from a standard library input stream std::istream & operator>> (std::istream & in, GD::Image & img); +#endif /* _gdpp_h */ #endif /* __cplusplus */ -#endif /* GDPP_H */