summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2003-09-08 17:30:06 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2003-09-08 17:30:06 +0000
commitc704b6ad8ebd3c39973f9101520b66c41b1551dd (patch)
tree59093dd0f2ae7a0a34e8735d8ee02aa218020254 /src
parentf6a1e8ca404dfd3bfc796d457beed17c7d3ccea8 (diff)
Add implementation for fl_read_image() on OSX (STR #161)
Update changelog and announcement. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3096 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_read_image_mac.cxx85
1 files changed, 82 insertions, 3 deletions
diff --git a/src/fl_read_image_mac.cxx b/src/fl_read_image_mac.cxx
index 551a6688d..b00dc1964 100644
--- a/src/fl_read_image_mac.cxx
+++ b/src/fl_read_image_mac.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: fl_read_image_mac.cxx,v 1.1.2.2 2003/01/30 21:44:03 easysw Exp $"
+// "$Id: fl_read_image_mac.cxx,v 1.1.2.3 2003/09/08 17:30:06 easysw Exp $"
//
// WIN32 image reading routines for the Fast Light Tool Kit (FLTK).
//
@@ -34,10 +34,89 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
int w, // I - Width of area to read
int h, // I - Height of area to read
int alpha) { // I - Alpha value for image (0 for none)
- return 0;
+ Rect src, // Source rectangle
+ dst; // Destination rectangle
+ Fl_Offscreen osbuffer; // Temporary off-screen buffer for copy
+ GrafPtr srcPort, // Source port
+ dstPort; // Destination port
+ RGBColor rgb; // RGB colors for copy mask...
+ PixMapHandle pm; // Pixmap handle for off-screen buffer
+ uchar *base, // Base address of off-screen buffer
+ *psrc, // Pointer into off-screen buffer
+ *pdst; // Pointer into pixel buffer
+ int x, y; // Current X & Y in image
+ int d; // Depth of image
+ int rowBytes; // Number of bytes per row...
+
+
+ // Get an off-screen buffer for copying the image...
+ osbuffer = fl_create_offscreen(w,h);
+
+ if (!osbuffer) return 0;
+
+ // Set the source and destination rectangles...
+ src.top = y;
+ src.left = x;
+ src.bottom = y + h;
+ src.right = x + w;
+
+ dst.top = 0;
+ dst.left = 0;
+ dst.bottom = h;
+ dst.right = w;
+
+ // Get the source port...
+ GetPort(&srcPort);
+
+ // Set the RGB copy mask via the foreground/background colors...
+ rgb.red = 0xffff;
+ rgb.green = 0xffff;
+ rgb.blue = 0xffff;
+ RGBBackColor(&rgb);
+
+ rgb.red = 0x0000;
+ rgb.green = 0x0000;
+ rgb.blue = 0x0000;
+ RGBForeColor(&rgb);
+
+ // Copy the screen image to the off-screen buffer...
+ CopyBits(GetPortBitMapForCopyBits(srcPort),
+ GetPortBitMapForCopyBits(osbuffer), &src, &dst, srcCopy, 0L);
+
+ // Allocate the image data array as needed...
+ d = alpha ? 4 : 3;
+
+ if (!p) p = new uchar[w * h * d];
+
+ // Initialize the default colors/alpha in the whole image...
+ memset(p, alpha, w * h * d);
+
+ // Set the correct port for the off-screen buffer and lock the buffer
+ SetGWorld(osbuffer, 0);
+
+ pm = GetGWorldPixMap(osbuffer);
+ LockPixels(pm);
+
+ base = (uchar *)GetPixBaseAddr(pm);
+ rowBytes = (*pm)->rowBytes & 0x3fff;
+
+ // Copy the image from the off-screen buffer to the memory buffer.
+ for (y = 0, pdst = p; y < h; y ++)
+ for (x = 0, psrc = base + y * rowBytes + 1; x < w; x ++, psrc += 4, pdst += d) {
+ pdst[0] = psrc[0];
+ pdst[1] = psrc[1];
+ pdst[2] = psrc[2];
+ }
+ }
+
+ // Unlock and delete the off-screen buffer, then return...
+ UnlockPixels(pm);
+ fl_delete_offscreen(osbuffer);
+
+ return p;
}
//
-// End of "$Id: fl_read_image_mac.cxx,v 1.1.2.2 2003/01/30 21:44:03 easysw Exp $".
+// End of "$Id: fl_read_image_mac.cxx,v 1.1.2.3 2003/09/08 17:30:06 easysw Exp $".
//