From ed7983f5b5aa2e4ccb6aff951e8a14c4015c7980 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 12 Jun 2014 13:28:04 +0000 Subject: Add ability to convert a Fl_Pixmap into a Fl_RGB_Image. This is very convenient as a lot of other functions only accept a Fl_RGB_Image. Adding this functionality also required a bit of spring cleaning in the the drawing routines. STR #2659. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10192 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Image.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Fl_Image.cxx') diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index a178eba38..c27d90b63 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -165,7 +165,22 @@ Fl_Image::measure(const Fl_Label *lo, // I - Label // size_t Fl_RGB_Image::max_size_ = ~((size_t)0); -/** The destructor free all memory and server resources that are used by the image. */ +int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg); + +/** The constructor creates a new RGBA image from the specified Fl_Pixmap. + + The RGBA image is built fully opaque except for the transparent area + of the pixmap that is assigned the \par bg color with full transparency */ +Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg): + Fl_Image(pxm->w(), pxm->h(), 4), id_(0), mask_(0) +{ + array = new uchar[w() * h() * d()]; + alloc_array = 1; + fl_convert_pixmap(pxm->data(), (uchar*)array, bg); + data((const char **)&array, 1); +} + +/** The destructor frees all memory and server resources that are used by the image. */ Fl_RGB_Image::~Fl_RGB_Image() { uncache(); if (alloc_array) delete[] (uchar *)array; -- cgit v1.2.3