--- a/ImageReader.st Sat Mar 05 15:24:06 2016 +0100
+++ b/ImageReader.st Sat Mar 05 15:24:58 2016 +0100
@@ -1228,6 +1228,64 @@
"Modified: 23.4.1997 / 18:54:05 / cg"
!
+swap:count pixelsFromRGB_to_BGR_in:data startingAt:startIndex bytesPerPixel:bpp
+ "swap bytes from RGB into BGR order.
+ The argument is a pixel data buffer (byteArray).
+ Can be used for both 24bit rgb data (bpp=3) or rgba data (bpp=4)"
+
+ |t idx|
+
+%{ /* OPTIONAL */
+ if (__isByteArray(data)
+ && __isSmallInteger(count)
+ && __isSmallInteger(startIndex)
+ && __isSmallInteger(bpp)) {
+ INT __count = __intVal(count);
+ INT __startOffset = __intVal(startIndex) - 1;
+ INT __dataSize = __byteArraySize(data);
+ int __bpp = __intVal(bpp);
+ INT __nBytes = __count * __bpp;
+
+ if ((__startOffset + __nBytes) <= __dataSize) {
+ unsigned char *__cp = __ByteArrayInstPtr(data)->ba_element + __startOffset;
+
+ while (__count-- > 0) {
+ unsigned char __t;
+
+ __t = __cp[0];
+ __cp[0] = __cp[2];
+ __cp[2] = __t;
+ __cp += __bpp;
+ }
+ RETURN (self);
+ }
+ }
+%}.
+ idx := startIndex.
+ 1 to:count do:[:i |
+ t := data at:idx.
+ data at:idx put:(data at:idx+2).
+ data at:idx+2 put:t.
+ idx := idx + bpp.
+ ].
+
+ "
+ |bytes|
+
+ bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
+ self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:3.
+ bytes.
+ "
+
+ "
+ |bytes|
+
+ bytes := #[ 0 1 2 3 4 5 6 7 8 9 ].
+ self swap:2 pixelsFromRGB_to_BGR_in:bytes startingAt:1 bytesPerPixel:4.
+ bytes.
+ "
+!
+
swap:nBytes bytesFromRGB_to_BGR_in:data
"swap bytes from RGB into BGR order.
The argument is a pixel data buffer (byteArray)"
@@ -2195,4 +2253,3 @@
version_CVS
^ '$Header$'
! !
-