summaryrefslogtreecommitdiff
path: root/src/fl_read_image_mac.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/fl_read_image_mac.cxx')
-rw-r--r--src/fl_read_image_mac.cxx106
1 files changed, 7 insertions, 99 deletions
diff --git a/src/fl_read_image_mac.cxx b/src/fl_read_image_mac.cxx
index 08e4361f7..d195873d7 100644
--- a/src/fl_read_image_mac.cxx
+++ b/src/fl_read_image_mac.cxx
@@ -26,9 +26,7 @@
//
#include <config.h>
-#ifdef __APPLE_COCOA__
extern unsigned char *MACbitmapFromRectOfWindow(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
-#endif
//
// 'fl_read_image()' - Read an image from the current window.
@@ -41,7 +39,6 @@ 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)
-#if defined(__APPLE_COCOA__)
Fl_Window *window = Fl_Window::current();
while(window->window()) window = window->window();
int delta;
@@ -56,103 +53,14 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
int idx, idy; // Current X & Y in image
uchar *pdst, *psrc;
for (idy = 0, pdst = p; idy < h; idy ++) {
- for (idx = 0, psrc = base + idy * rowBytes; idx < w; idx ++, psrc += delta, pdst += d) {
-/*R*/ pdst[0] = psrc[0];
-/*G*/ pdst[1] = psrc[1];
-/*B*/ pdst[2] = psrc[2];
- }
- }
-delete base;
-#else
- Rect src, // Source rectangle
- dst; // Destination rectangle
- GWorldPtr osbuffer; // Temporary off-screen buffer for copy
- GrafPtr srcPort; // Source 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 idx, idy; // Current X & Y in image
- int d; // Depth of image
- int rowBytes; // Number of bytes per row...
-
- // 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 an off-screen buffer for copying the image...
- QDErr err = NewGWorld(&osbuffer, 0, &dst, 0L, 0L, 0);
- if (!osbuffer) return 0;
- if (err!=noErr) {
- DisposeGWorld(osbuffer);
- return 0;
- }
-
- // 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 (idy = 0, pdst = p; idy < h; idy ++)
-#ifdef __i386__
- for (idx = 0, psrc = base + idy * rowBytes; idx < w; idx ++, psrc += 4, pdst += d) {
- pdst[0] = psrc[2];
- pdst[1] = psrc[1];
- pdst[2] = psrc[0];
+ for (idx = 0, psrc = base + idy * rowBytes; idx < w; idx ++, psrc += delta, pdst += d) {
+ pdst[0] = psrc[0]; // R
+ pdst[1] = psrc[1]; // G
+ pdst[2] = psrc[2]; // B
}
-#else
- for (idx = 0, psrc = base + idy * rowBytes + 1; idx < w; idx ++, psrc += 4, pdst += d) {
- pdst[0] = psrc[0];
- pdst[1] = psrc[1];
- pdst[2] = psrc[2];
- }
-#endif // __i386__
- // Unlock and delete the off-screen buffer, then return...
- UnlockPixels(pm);
- DisposeGWorld(osbuffer);
-
- SetPort(srcPort);
-#endif
-return p;
+ }
+ delete base;
+ return p;
}