summaryrefslogtreecommitdiff
path: root/src/Fl_Bitmap.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Fl_Bitmap.cxx')
-rw-r--r--src/Fl_Bitmap.cxx73
1 files changed, 71 insertions, 2 deletions
diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx
index c20bfeabf..18d474fb7 100644
--- a/src/Fl_Bitmap.cxx
+++ b/src/Fl_Bitmap.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.2 2001/11/18 20:52:27 easysw Exp $"
+// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $"
//
// Bitmap drawing routines for the Fast Light Tool Kit (FLTK).
//
@@ -29,6 +29,7 @@
#include <FL/Fl_Widget.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Bitmap.H>
+#include <string.h>
#ifdef WIN32 // Windows bitmask functions...
Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data) {
@@ -105,6 +106,7 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
Fl_Bitmap::~Fl_Bitmap() {
if (id) fl_delete_bitmask(id);
+ if (alloc_array) delete[] array;
}
void Fl_Bitmap::label(Fl_Widget* w) {
@@ -114,6 +116,73 @@ void Fl_Bitmap::label(Fl_Widget* w) {
void Fl_Bitmap::label(Fl_Menu_Item* m) {
}
+Fl_Image *Fl_Bitmap::copy(int W, int H) {
+ // Optimize the simple copy where the width and height are the same...
+ if (W == w() && H == h()) return new Fl_Bitmap(array, w(), h());
+
+ // OK, need to resize the image data; allocate memory and
+ Fl_Bitmap *new_image; // New RGB image
+ uchar *new_array, // New array for image data
+ *new_ptr, // Pointer into new array
+ new_bit, // Bit for new array
+ old_bit; // Bit for old array
+ const uchar *old_ptr; // Pointer into old array
+ int sx, sy, // Source coordinates
+ dx, dy, // Destination coordinates
+ xerr, yerr, // X & Y errors
+ xmod, ymod, // X & Y moduli
+ xstep, ystep; // X & Y step increments
+
+
+ // Figure out Bresenheim step/modulus values...
+ xmod = w() % W;
+ xstep = w() / W;
+ ymod = h() % H;
+ ystep = h() / H;
+
+ // Allocate memory for the new image...
+ new_array = new uchar [H * (W + 7) / 8];
+ new_image = new Fl_Bitmap(new_array, W, H);
+ new_image->alloc_array = 1;
+
+ memset(new_array, 0, H * (W + 7) / 8);
+
+ // Scale the image using a nearest-neighbor algorithm...
+ for (dy = h(), sy = 0, yerr = H / 2, new_ptr = new_array; dy > 0; dy --) {
+ for (dx = w(), xerr = W / 2, old_ptr = array + sy * (w() + 7) / 8, sx = 0, new_bit = 128;
+ dx > 0;
+ dx --) {
+ old_bit = 128 >> (sx & 7);
+ if (old_ptr[sx / 8] & old_bit) *new_ptr |= new_bit;
+
+ if (new_bit > 1) new_bit >>= 1;
+ else {
+ new_bit = 128;
+ new_ptr ++;
+ }
+
+ sx += xstep;
+ xerr -= xmod;
+
+ if (xerr <= 0) {
+ xerr += W;
+ sx ++;
+ }
+ }
+
+ if (new_bit < 128) new_ptr ++;
+
+ sy += ystep;
+ yerr -= ymod;
+ if (yerr <= 0) {
+ yerr += H;
+ sy ++;
+ }
+ }
+
+ return new_image;
+}
+
//
-// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.2 2001/11/18 20:52:27 easysw Exp $".
+// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $".
//