added #rectread
authorClaus Gittinger <cg@exept.de>
Fri, 22 Mar 1996 19:40:11 +0100
changeset 538 ca6f8b126197
parent 537 56ccc83b3ac7
child 539 8b7e0a35264d
added #rectread
GLXWorkstat.st
GLXWorkstation.st
--- a/GLXWorkstat.st	Fri Mar 22 18:23:36 1996 +0100
+++ b/GLXWorkstat.st	Fri Mar 22 19:40:11 1996 +0100
@@ -3257,6 +3257,55 @@
 %}
 .
     ^ false
+!
+
+glxRectreadX1:x1 y1:y1 x2:x2 y2:y2 to:dest in:aGLXWindowId
+    "read pixels from a rectanglular area.
+     Dest must be an array and gets pixel values assigned,
+     reading n*m pixels.
+     For now, pixel-reading is only supported with a true GL.
+     Caveat: the number of pixels is limited to 256.
+     In double buffer mode, the backBuffer is read."
+
+    |n idx|
+
+    n := (x2 - x1 + 1) * (y2 - y1 + 1).
+    n > 256 ifTrue:[^ 0].
+    dest size < n ifTrue:[^ 0].
+
+%{  /* STACK:1024 */
+#ifdef GLX
+    Colorindex buffer[256];
+    int i, nRead;
+
+    if (__isArray(dest)
+     && __isSmallInteger(x1) && __isSmallInteger(x2)
+     && __isSmallInteger(y1) && __isSmallInteger(y2)
+    ) {
+        SETWIN(aGLXWindowId)
+        nRead = rectread(__intVal(x1), __intVal(y1),
+                          __intVal(x2), __intVal(y2), 
+                          buffer);
+        for (i=0; i<nRead;i++) {
+            __ArrayInstPtr(dest)->a_element[i] = __MKSMALLINT(buffer[i]);
+        }
+        RETURN (__MKSMALLINT(nRead));
+    }
+#endif
+%}.
+    "/
+    "/ ok, this is not a GL - use XWorkstations pixel read method
+    "/ and convert
+    "/
+    idx := 1.
+    y1 to:y2 do:[:y |
+        x1 to:x2 do:[:x |
+            dest at:idx put:(super getPixelX:x y:y from:aGLXWindowId)
+        ]
+    ].
+    ^ n
+
+    "Modified: 22.3.1996 / 18:08:00 / cg"
 ! !
 
 !GLXWorkstation methodsFor:'points'!
@@ -8232,5 +8281,5 @@
 !GLXWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/GLXWorkstat.st,v 1.49 1996-03-22 17:23:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/GLXWorkstat.st,v 1.50 1996-03-22 18:40:11 cg Exp $'
 ! !
--- a/GLXWorkstation.st	Fri Mar 22 18:23:36 1996 +0100
+++ b/GLXWorkstation.st	Fri Mar 22 19:40:11 1996 +0100
@@ -3257,6 +3257,55 @@
 %}
 .
     ^ false
+!
+
+glxRectreadX1:x1 y1:y1 x2:x2 y2:y2 to:dest in:aGLXWindowId
+    "read pixels from a rectanglular area.
+     Dest must be an array and gets pixel values assigned,
+     reading n*m pixels.
+     For now, pixel-reading is only supported with a true GL.
+     Caveat: the number of pixels is limited to 256.
+     In double buffer mode, the backBuffer is read."
+
+    |n idx|
+
+    n := (x2 - x1 + 1) * (y2 - y1 + 1).
+    n > 256 ifTrue:[^ 0].
+    dest size < n ifTrue:[^ 0].
+
+%{  /* STACK:1024 */
+#ifdef GLX
+    Colorindex buffer[256];
+    int i, nRead;
+
+    if (__isArray(dest)
+     && __isSmallInteger(x1) && __isSmallInteger(x2)
+     && __isSmallInteger(y1) && __isSmallInteger(y2)
+    ) {
+        SETWIN(aGLXWindowId)
+        nRead = rectread(__intVal(x1), __intVal(y1),
+                          __intVal(x2), __intVal(y2), 
+                          buffer);
+        for (i=0; i<nRead;i++) {
+            __ArrayInstPtr(dest)->a_element[i] = __MKSMALLINT(buffer[i]);
+        }
+        RETURN (__MKSMALLINT(nRead));
+    }
+#endif
+%}.
+    "/
+    "/ ok, this is not a GL - use XWorkstations pixel read method
+    "/ and convert
+    "/
+    idx := 1.
+    y1 to:y2 do:[:y |
+        x1 to:x2 do:[:x |
+            dest at:idx put:(super getPixelX:x y:y from:aGLXWindowId)
+        ]
+    ].
+    ^ n
+
+    "Modified: 22.3.1996 / 18:08:00 / cg"
 ! !
 
 !GLXWorkstation methodsFor:'points'!
@@ -8232,5 +8281,5 @@
 !GLXWorkstation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.49 1996-03-22 17:23:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GLXWorkstation.st,v 1.50 1996-03-22 18:40:11 cg Exp $'
 ! !