Merge jv
authorHG Automerge
Sun, 18 Dec 2016 12:12:59 +0000
branchjv
changeset 7765 b8189ae681df
parent 7743 fa3c8eb0bc1d (current diff)
parent 7756 e85e23f3b476 (diff)
child 7766 ba07a358cb4a
Merge
DeviceGraphicsContext.st
DisplaySurface.st
Form.st
GraphicsMedium.st
Image.st
SimpleView.st
XWorkstation.st
--- a/Depth24Image.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/Depth24Image.st	Sun Dec 18 12:12:59 2016 +0000
@@ -315,8 +315,8 @@
 
     numFix := fixColors size.
     numFix == 256 ifTrue:[
-	"/ algorithm below only handles 255 colors.
-	numFix := 255.
+        "/ algorithm below only handles 255 colors.
+        numFix := 255.
     ].
 
     fixColorArray := fixColors asArray.
@@ -331,9 +331,9 @@
 
     deviceDepth := aDevice depth.
     deviceDepth == 8 ifFalse:[
-	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	    ^ nil
-	]
+        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+            ^ nil
+        ]
     ].
 
     idsUsed := ByteArray new:(fixIds size).
@@ -362,131 +362,130 @@
      && __isByteArrayLike(fixRed)
      && __isByteArrayLike(fixGreen)
      && __isByteArrayLike(fixBlue) ) {
-	failed = false;
-
-	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
-	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = __ByteArrayInstPtr(fixIds)->ba_element;
-	usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
-	redP = __ByteArrayInstPtr(fixRed)->ba_element;
-	greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
-	blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
-	cacheP = __ByteArrayInstPtr(cache)->ba_element;
-	__numFix = __intVal(numFix);
-
-	for (__y=__intVal(h); __y>0; __y--) {
-	    __eR = __eG = __eB = 0;
-	    for (__x=__w; __x>0; __x--) {
-		int cacheIdx, clrIdx;
-		int __wantR, __wantG, __wantB;
-
-		__wantR = srcP[0] + __eR;
-		if (__wantR > 255) __wantR = 255;
-		else if (__wantR < 0) __wantR = 0;
-
-		__wantG = srcP[1] + __eG;
-		if (__wantG > 255) __wantG = 255;
-		else if (__wantG < 0) __wantG = 0;
-
-		__wantB = srcP[2] + __eB;
-		if (__wantB > 255) __wantB = 255;
-		else if (__wantB < 0) __wantB = 0;
-
-		/*
-		 * compute cache index
-		 */
-		cacheIdx = ((__wantR & 0xF8) >> 3);
-		cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
-		cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
-
-		clrIdx = cacheP[cacheIdx];
-		if (clrIdx == 0xFF) {   /* invalid slot */
-		    unsigned minErr, minIdx;
-		    int i;
-
-		    /*
-		     * must search ...
-		     */
-		    minErr = 0x7FFFFFF; minIdx = 0;
-		    for (i=0; i<__numFix; i++) {
-			unsigned cR, cG, cB, e;
-			int eR, eG, eB;
-
-			cR = redP[i]; cG = greenP[i]; cB = blueP[i];
-			eR = cR - __wantR;
-			if (eR < 0) eR = -eR;
-
-			eG = cG - __wantG;
-			if (eG < 0) eG = -eG;
-
-			eB = cB - __wantB;
-			if (eB < 0) eB = -eB;
-
-			e = eR + eG + eB;
-			if (e < minErr) {
-			    minErr = e;
-			    minIdx = i;
-			    if (e < 7) {
-				break;
-			    }
-			}
-		    }
-
-		    /*
-		     * minIdx is now index into fixColors
-		     */
-		    cacheP[cacheIdx] = clrIdx = minIdx;
+        failed = false;
+
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(fixIds)->ba_element;
+        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
+        redP = __ByteArrayInstPtr(fixRed)->ba_element;
+        greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
+        blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
+        cacheP = __ByteArrayInstPtr(cache)->ba_element;
+        __numFix = __intVal(numFix);
+
+        for (__y=__intVal(h); __y>0; __y--) {
+            __eR = __eG = __eB = 0;
+            for (__x=__w; __x>0; __x--) {
+                int cacheIdx, clrIdx;
+                int __wantR, __wantG, __wantB;
+
+                __wantR = srcP[0] + __eR;
+                if (__wantR > 255) __wantR = 255;
+                else if (__wantR < 0) __wantR = 0;
+
+                __wantG = srcP[1] + __eG;
+                if (__wantG > 255) __wantG = 255;
+                else if (__wantG < 0) __wantG = 0;
+
+                __wantB = srcP[2] + __eB;
+                if (__wantB > 255) __wantB = 255;
+                else if (__wantB < 0) __wantB = 0;
+
+                /*
+                 * compute cache index
+                 */
+                cacheIdx = ((__wantR & 0xF8) >> 3);
+                cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
+                cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
+
+                clrIdx = cacheP[cacheIdx];
+                if (clrIdx == 0xFF) {   /* invalid slot */
+                    unsigned minErr, minIdx;
+                    int i;
+
+                    /*
+                     * must search ...
+                     */
+                    minErr = 0x7FFFFFF; minIdx = 0;
+                    for (i=0; i<__numFix; i++) {
+                        unsigned cR, cG, cB, e;
+                        int eR, eG, eB;
+
+                        cR = redP[i]; cG = greenP[i]; cB = blueP[i];
+                        eR = cR - __wantR;
+                        if (eR < 0) eR = -eR;
+
+                        eG = cG - __wantG;
+                        if (eG < 0) eG = -eG;
+
+                        eB = cB - __wantB;
+                        if (eB < 0) eB = -eB;
+
+                        e = eR + eG + eB;
+                        if (e < minErr) {
+                            minErr = e;
+                            minIdx = i;
+                            if (e < 7) {
+                                break;
+                            }
+                        }
+                    }
+
+                    /*
+                     * minIdx is now index into fixColors
+                     */
+                    cacheP[cacheIdx] = clrIdx = minIdx;
 /*
 console_fprintf(stderr, "want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
 */
-		}
-
-		/*
-		 * store the corresponding dither colorId
-		 */
-		*dstP++ = idP[clrIdx];
-		usedIdP[clrIdx] = 1;
-
-		srcP += 3;
-
-		/*
-		 * the new error:
-		 */
-		__eR = __wantR - redP[clrIdx];
-		__eG = __wantG - greenP[clrIdx];
-		__eB = __wantB - blueP[clrIdx];
-	    }
-	}
+                }
+
+                /*
+                 * store the corresponding dither colorId
+                 */
+                *dstP++ = idP[clrIdx];
+                usedIdP[clrIdx] = 1;
+
+                srcP += 3;
+
+                /*
+                 * the new error:
+                 */
+                __eR = __wantR - redP[clrIdx];
+                __eG = __wantG - greenP[clrIdx];
+                __eB = __wantB - blueP[clrIdx];
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
     ].
 
     "/ not all colors may be really in use ...
     usedColors := fixColors copy.
     idsUsed keysAndValuesDo:[:idx :flag |
-	flag == 0 ifTrue:[
-	    usedColors at:idx put:nil
-	]
+        flag == 0 ifTrue:[
+            usedColors at:idx put:nil
+        ]
     ].
 
     f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:usedColors.
-    f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:aDevice depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:aDevice depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f initGC).
     ^ f
 !
 
@@ -517,17 +516,17 @@
     fixB == 0 ifTrue:[ ^ nil].
     "/ simple check
     (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
-	self error:'invalid color array passed'.
-	^ nil
+        self error:'invalid color array passed'.
+        ^ nil
     ].
     fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
     idsUsed := ByteArray new:(fixIds size).
 
     deviceDepth := aDevice depth.
     deviceDepth == 8 ifFalse:[
-	(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	    ^ nil
-	]
+        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+            ^ nil
+        ]
     ].
 
     'Depth24Image [info]: dithering ...' infoPrintCR.
@@ -558,136 +557,136 @@
      && __isByteArrayLike(idsUsed)
      && __bothSmallInteger(fixR, fixG)
      && __isSmallInteger(fixB)) {
-	failed = false;
-
-	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
-	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
-	idP = __ByteArrayInstPtr(fixIds)->ba_element;
-	usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
-	__fR = __intVal(fixR)-1;
-	__fG = __intVal(fixG)-1;
-	__fB = __intVal(fixB)-1;
-
-	__eR = __eG = __eB = 0;
-
-	leftToRight = 1;
-	for (__y=__intVal(h); __y>0; __y--) {
-	    if (leftToRight) {
-		for (__x=__w; __x>0; __x--) {
-		    int __want;
-
-		    /*
-		     * wR, wG and wB is the wanted r/g/b value;
-		     * compute the index into the dId table ..
-		     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
-		     *
-		     * bad kludge: knows how to index into FixColor table
-		     */
-		    __wantR = __want = srcP[0] + __eR;
-
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iR = __want * __fR / 128;
-		    iR = (iR / 2) + (iR & 1);
-
-		    __wantG = __want = srcP[1] + __eG;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iG = __want * __fG / 128;
-		    iG = (iG / 2) + (iG & 1);
-
-		    __wantB = __want = srcP[2] + __eB;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iB = __want * __fB / 128;
-		    iB = (iB / 2) + (iB & 1);
-
-		    idx = iR * (__fG+1);
-		    idx = (idx + iG) * (__fB+1);
-		    idx = idx + iB;
-
-		    /*
-		     * store the corresponding dither colorId
-		     */
-		    *dstP++ = idP[idx];
-		    usedIdP[idx] = 1;
-
-		    srcP += 3;
-
-		    /*
-		     * the new error:
-		     */
-		    __eR = __wantR - (iR * 256 / __fR);
-		    __eG = __wantG - (iG * 256 / __fG);
-		    __eB = __wantB - (iB * 256 / __fB);
-		}
-		leftToRight = 0;
-	    } else {
-		srcP += (__w*3);
-		dstP += __w;
-		for (__x=__w; __x>0; __x--) {
-		    int __want;
-
-		    /*
-		     * wR, wG and wB is the wanted r/g/b value;
-		     * compute the index into the dId table ..
-		     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
-		     *
-		     * bad kludge: knows how to index into FixColor table
-		     */
-		    srcP -= 3;
-		    __wantR = __want = srcP[0] + __eR;
-
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iR = __want * __fR / 128;
-		    iR = (iR / 2) + (iR & 1);
-
-		    __wantG = __want = srcP[1] + __eG;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iG = __want * __fG / 128;
-		    iG = (iG / 2) + (iG & 1);
-
-		    __wantB = __want = srcP[2] + __eB;
-		    if (__want > 255) __want = 255;
-		    else if (__want < 0) __want = 0;
-
-		    iB = __want * __fB / 128;
-		    iB = (iB / 2) + (iB & 1);
-
-		    idx = iR * (__fG+1);
-		    idx = (idx + iG) * (__fB+1);
-		    idx = idx + iB;
-
-		    /*
-		     * store the corresponding dither colorId
-		     */
-		    *--dstP = idP[idx];
-		    usedIdP[idx] = 1;
-
-		    /*
-		     * the new error:
-		     */
-		    __eR = __wantR - (iR * 256 / __fR);
-		    __eG = __wantG - (iG * 256 / __fG);
-		    __eB = __wantB - (iB * 256 / __fB);
-		}
-		srcP += (__w*3);
-		dstP += __w;
-		leftToRight = 1;
-	    }
-	}
+        failed = false;
+
+        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+        idP = __ByteArrayInstPtr(fixIds)->ba_element;
+        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
+        __fR = __intVal(fixR)-1;
+        __fG = __intVal(fixG)-1;
+        __fB = __intVal(fixB)-1;
+
+        __eR = __eG = __eB = 0;
+
+        leftToRight = 1;
+        for (__y=__intVal(h); __y>0; __y--) {
+            if (leftToRight) {
+                for (__x=__w; __x>0; __x--) {
+                    int __want;
+
+                    /*
+                     * wR, wG and wB is the wanted r/g/b value;
+                     * compute the index into the dId table ..
+                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
+                     *
+                     * bad kludge: knows how to index into FixColor table
+                     */
+                    __wantR = __want = srcP[0] + __eR;
+
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iR = __want * __fR / 128;
+                    iR = (iR / 2) + (iR & 1);
+
+                    __wantG = __want = srcP[1] + __eG;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iG = __want * __fG / 128;
+                    iG = (iG / 2) + (iG & 1);
+
+                    __wantB = __want = srcP[2] + __eB;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iB = __want * __fB / 128;
+                    iB = (iB / 2) + (iB & 1);
+
+                    idx = iR * (__fG+1);
+                    idx = (idx + iG) * (__fB+1);
+                    idx = idx + iB;
+
+                    /*
+                     * store the corresponding dither colorId
+                     */
+                    *dstP++ = idP[idx];
+                    usedIdP[idx] = 1;
+
+                    srcP += 3;
+
+                    /*
+                     * the new error:
+                     */
+                    __eR = __wantR - (iR * 256 / __fR);
+                    __eG = __wantG - (iG * 256 / __fG);
+                    __eB = __wantB - (iB * 256 / __fB);
+                }
+                leftToRight = 0;
+            } else {
+                srcP += (__w*3);
+                dstP += __w;
+                for (__x=__w; __x>0; __x--) {
+                    int __want;
+
+                    /*
+                     * wR, wG and wB is the wanted r/g/b value;
+                     * compute the index into the dId table ..
+                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
+                     *
+                     * bad kludge: knows how to index into FixColor table
+                     */
+                    srcP -= 3;
+                    __wantR = __want = srcP[0] + __eR;
+
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iR = __want * __fR / 128;
+                    iR = (iR / 2) + (iR & 1);
+
+                    __wantG = __want = srcP[1] + __eG;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iG = __want * __fG / 128;
+                    iG = (iG / 2) + (iG & 1);
+
+                    __wantB = __want = srcP[2] + __eB;
+                    if (__want > 255) __want = 255;
+                    else if (__want < 0) __want = 0;
+
+                    iB = __want * __fB / 128;
+                    iB = (iB / 2) + (iB & 1);
+
+                    idx = iR * (__fG+1);
+                    idx = (idx + iG) * (__fB+1);
+                    idx = idx + iB;
+
+                    /*
+                     * store the corresponding dither colorId
+                     */
+                    *--dstP = idP[idx];
+                    usedIdP[idx] = 1;
+
+                    /*
+                     * the new error:
+                     */
+                    __eR = __wantR - (iR * 256 / __fR);
+                    __eG = __wantG - (iG * 256 / __fG);
+                    __eB = __wantB - (iB * 256 / __fB);
+                }
+                srcP += (__w*3);
+                dstP += __w;
+                leftToRight = 1;
+            }
+        }
     }
 %}.
     failed ifTrue:[
-	self primitiveFailed.
-	^ nil
+        self primitiveFailed.
+        ^ nil
 
 "/ for non-C programmers:
 "/     the above code is (roughly) equivalent to:
@@ -742,26 +741,25 @@
     "/ not all colors may be really in use ...
     usedColors := fixColors copy.
     idsUsed keysAndValuesDo:[:idx :flag |
-	flag == 0 ifTrue:[
-	    usedColors at:idx put:nil
-	]
+        flag == 0 ifTrue:[
+            usedColors at:idx put:nil
+        ]
     ].
 
     f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:usedColors.
-    f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:aDevice depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:aDevice depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f initGC).
     ^ f
 !
 
@@ -790,10 +788,10 @@
      depth nColorCells deep nColorsNeeded bytes|
 
     aDevice fixColors notNil ifTrue:[
-	"/ no need to look for used colors - dithering anyway ...
-
-	f := self rgbImageAsDitheredPseudoFormOn:aDevice.
-	f notNil ifTrue:[^ f].
+        "/ no need to look for used colors - dithering anyway ...
+
+        f := self rgbImageAsDitheredPseudoFormOn:aDevice.
+        f notNil ifTrue:[^ f].
     ].
 
     bytes := self bits.
@@ -814,210 +812,210 @@
     'Depth24Image [info]: allocating colors ...' infoPrintCR.
 
     [fit] whileFalse:[
-	[fitMap] whileFalse:[
-	    srcIndex := 1.
-	    redArray := Array new:256.
-
-	    "
-	     find used colors, build [r][g][b] 3-dimensional array
-	     containing true for used colors
-	    "
-	    nColors := 0.
-	    srcIndex := 1.
-	    dataSize := bytes size.
-	    [(srcIndex < dataSize)
-	     and:[nColors <= nColorCells]] whileTrue:[
+        [fitMap] whileFalse:[
+            srcIndex := 1.
+            redArray := Array new:256.
+
+            "
+             find used colors, build [r][g][b] 3-dimensional array
+             containing true for used colors
+            "
+            nColors := 0.
+            srcIndex := 1.
+            dataSize := bytes size.
+            [(srcIndex < dataSize)
+             and:[nColors <= nColorCells]] whileTrue:[
 %{
-		if (__isByteArrayLike(bytes)) {
-		    int sI = __intVal(srcIndex);
-		    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
-
-		    r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
-		    g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
-		    b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
-		    srcIndex = __MKSMALLINT(sI + 3);
-		    fast = true;
-		} else {
-		    fast = false;
-		}
+                if (__isByteArrayLike(bytes)) {
+                    int sI = __intVal(srcIndex);
+                    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
+
+                    r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
+                    g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
+                    b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
+                    srcIndex = __MKSMALLINT(sI + 3);
+                    fast = true;
+                } else {
+                    fast = false;
+                }
 %}
 .
-		fast ifFalse:[
-		    r := bytes at:srcIndex.
-		    r := (r bitAnd:rMask) + 1.
-		    srcIndex := srcIndex + 1.
-		    g := bytes at:srcIndex.
-		    g := (g bitAnd:gMask) + 1.
-		    srcIndex := srcIndex + 1.
-		    b := bytes at:srcIndex.
-		    b := (b bitAnd:bMask) + 1.
-		    srcIndex := srcIndex + 1
-		].
-
-		greenArray := redArray at:r.
-		greenArray isNil ifTrue:[
-		    greenArray := Array new:256.
-		    redArray at:r put:greenArray
-		].
-		blueArray := greenArray at:g.
-		blueArray isNil ifTrue:[
-		    deep ifTrue:[blueArray := Array new:256]
-		    ifFalse:[blueArray := ByteArray new:256].
-		    greenArray at:g put:blueArray
-		].
-		(blueArray at:b) == 0 ifTrue:[
-		    blueArray at:b put:1.
-		    nColors := nColors + 1.
-		    (nColors > nColorCells) ifTrue:[
+                fast ifFalse:[
+                    r := bytes at:srcIndex.
+                    r := (r bitAnd:rMask) + 1.
+                    srcIndex := srcIndex + 1.
+                    g := bytes at:srcIndex.
+                    g := (g bitAnd:gMask) + 1.
+                    srcIndex := srcIndex + 1.
+                    b := bytes at:srcIndex.
+                    b := (b bitAnd:bMask) + 1.
+                    srcIndex := srcIndex + 1
+                ].
+
+                greenArray := redArray at:r.
+                greenArray isNil ifTrue:[
+                    greenArray := Array new:256.
+                    redArray at:r put:greenArray
+                ].
+                blueArray := greenArray at:g.
+                blueArray isNil ifTrue:[
+                    deep ifTrue:[blueArray := Array new:256]
+                    ifFalse:[blueArray := ByteArray new:256].
+                    greenArray at:g put:blueArray
+                ].
+                (blueArray at:b) == 0 ifTrue:[
+                    blueArray at:b put:1.
+                    nColors := nColors + 1.
+                    (nColors > nColorCells) ifTrue:[
 "/                        'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
-			srcIndex := dataSize + 1
-		    ]
-		]
-	    ].
-	    nColorsNeeded isNil ifTrue:[
-		nColorsNeeded := nColors
-	    ].
-
-	    "again with less color bits if it does not fit colormap"
-
-	    (nColors <= nColorCells) ifTrue:[
-		fitMap := true
-	    ] ifFalse:[
-		"/ must try again - cutting off some bits
-		"/ blue bits are snipped off faster.
-		(bMask == 2r11111111) ifTrue:[
-		    bMask := 2r11111100
-		] ifFalse:[
-		    (bMask == 2r11111100) ifTrue:[
-			bMask := 2r11110000
-		    ] ifFalse:[
-			(rMask == 2r11111111) ifTrue:[
-			    rMask := 2r11111100.
-			    gMask := 2r11111100.
-			] ifFalse:[
-			    rMask := (rMask bitShift:1) bitAnd:2r11111111.
-			    gMask := (gMask bitShift:1) bitAnd:2r11111111.
-			    bMask := (bMask bitShift:1) bitAnd:2r11111111
-			]
-		    ]
-		].
+                        srcIndex := dataSize + 1
+                    ]
+                ]
+            ].
+            nColorsNeeded isNil ifTrue:[
+                nColorsNeeded := nColors
+            ].
+
+            "again with less color bits if it does not fit colormap"
+
+            (nColors <= nColorCells) ifTrue:[
+                fitMap := true
+            ] ifFalse:[
+                "/ must try again - cutting off some bits
+                "/ blue bits are snipped off faster.
+                (bMask == 2r11111111) ifTrue:[
+                    bMask := 2r11111100
+                ] ifFalse:[
+                    (bMask == 2r11111100) ifTrue:[
+                        bMask := 2r11110000
+                    ] ifFalse:[
+                        (rMask == 2r11111111) ifTrue:[
+                            rMask := 2r11111100.
+                            gMask := 2r11111100.
+                        ] ifFalse:[
+                            rMask := (rMask bitShift:1) bitAnd:2r11111111.
+                            gMask := (gMask bitShift:1) bitAnd:2r11111111.
+                            bMask := (bMask bitShift:1) bitAnd:2r11111111
+                        ]
+                    ]
+                ].
 "/                'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR.
 "
     'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
     bMask printNewline
 "
-	    ]
-	].
+            ]
+        ].
 
 "/        'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR.
 
-	colors := Array new:nColors.
-	colorIndex := 1.
-
-	"
-	 now, we have reduced things to the number of colors
-	 which are theoretically supported by the devices colormap.
-	 allocate all used colors in walking over true entries in
-	 the [r][g][b] table - this may still fail,
-	 if we run out of device colors.
-	"
-	fit := true.
-
-	r := 0.
-	redArray do:[:greenArray |
-	    (fit and:[greenArray notNil]) ifTrue:[
-		g := 0.
-		greenArray do:[:blueArray |
-		    (fit and:[blueArray notNil]) ifTrue:[
-			b := 0.
-			blueArray do:[:present |
-			    |id|
-
-			    (fit and:[present ~~ 0]) ifTrue:[
-				color := Color redByte:r
-					     greenByte:g
-					      blueByte:b.
-				color := color onDevice:aDevice.
-				(id := color colorId) isNil ifTrue:[
-				    fit := false
-				] ifFalse:[
-				    colors at:colorIndex put:color.
-				    colorIndex := colorIndex + 1.
-				    blueArray at:(b + 1) put:id
-				]
-			    ].
-			    b := b + 1
-			]
-		    ].
-		    g := g + 1
-		]
-	    ].
-	    r := r + 1
-	].
-
-	"again with less color bits if we did not get all colors"
-
-	fit ifFalse:[
+        colors := Array new:nColors.
+        colorIndex := 1.
+
+        "
+         now, we have reduced things to the number of colors
+         which are theoretically supported by the devices colormap.
+         allocate all used colors in walking over true entries in
+         the [r][g][b] table - this may still fail,
+         if we run out of device colors.
+        "
+        fit := true.
+
+        r := 0.
+        redArray do:[:greenArray |
+            (fit and:[greenArray notNil]) ifTrue:[
+                g := 0.
+                greenArray do:[:blueArray |
+                    (fit and:[blueArray notNil]) ifTrue:[
+                        b := 0.
+                        blueArray do:[:present |
+                            |id|
+
+                            (fit and:[present ~~ 0]) ifTrue:[
+                                color := Color redByte:r
+                                             greenByte:g
+                                              blueByte:b.
+                                color := color onDevice:aDevice.
+                                (id := color colorId) isNil ifTrue:[
+                                    fit := false
+                                ] ifFalse:[
+                                    colors at:colorIndex put:color.
+                                    colorIndex := colorIndex + 1.
+                                    blueArray at:(b + 1) put:id
+                                ]
+                            ].
+                            b := b + 1
+                        ]
+                    ].
+                    g := g + 1
+                ]
+            ].
+            r := r + 1
+        ].
+
+        "again with less color bits if we did not get all colors"
+
+        fit ifFalse:[
 "/            'Depth24Image [info]: could not allocate color(s)' infoPrintCR.
 
-	    "free the allocated colors"
-	    colors atAllPut:nil.
-	    "a kludge - force immediate freeing of colors"
-	    ObjectMemory scavenge; finalize.
-
-	    "cut off one more color-bit - cut off blue first"
-	    (bMask == 2r11111111) ifTrue:[
-		bMask := 2r11111100
-	    ] ifFalse:[
-		(bMask == 2r11111100) ifTrue:[
-		    bMask := 2r11110000
-		] ifFalse:[
-		    (rMask == 2r11111111) ifTrue:[
-			rMask := 2r11111100.
-			gMask := 2r11111100.
-		    ] ifFalse:[
-			rMask := (rMask bitShift:1) bitAnd:2r11111111.
-			gMask := (gMask bitShift:1) bitAnd:2r11111111.
-			bMask := (bMask bitShift:1) bitAnd:2r11111111
-		    ]
-		]
-	    ].
-	    fitMap := false.
-	    redArray := nil
-	]
+            "free the allocated colors"
+            colors atAllPut:nil.
+            "a kludge - force immediate freeing of colors"
+            ObjectMemory scavenge; finalize.
+
+            "cut off one more color-bit - cut off blue first"
+            (bMask == 2r11111111) ifTrue:[
+                bMask := 2r11111100
+            ] ifFalse:[
+                (bMask == 2r11111100) ifTrue:[
+                    bMask := 2r11110000
+                ] ifFalse:[
+                    (rMask == 2r11111111) ifTrue:[
+                        rMask := 2r11111100.
+                        gMask := 2r11111100.
+                    ] ifFalse:[
+                        rMask := (rMask bitShift:1) bitAnd:2r11111111.
+                        gMask := (gMask bitShift:1) bitAnd:2r11111111.
+                        bMask := (bMask bitShift:1) bitAnd:2r11111111
+                    ]
+                ]
+            ].
+            fitMap := false.
+            redArray := nil
+        ]
     ].
 
     (nColors ~~ nColorsNeeded) ifTrue:[
-	"/ mhmh - did not get all colors ...
-	"/ add existing colors and dither.
-
-	'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
-	nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
-
-	"/
-	"/ dither using those we got ...
-	"/
-	DitherAlgorithm == #floydSteinberg ifTrue:[
-	    colors := colors asNewSet.
+        "/ mhmh - did not get all colors ...
+        "/ add existing colors and dither.
+
+        'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
+        nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
+
+        "/
+        "/ dither using those we got ...
+        "/
+        DitherAlgorithm == #floydSteinberg ifTrue:[
+            colors := colors asNewSet.
 "/            ditherColors := aDevice availableDitherColors.
 "/            ditherColors notNil ifTrue:[
 "/                colors addAll:ditherColors.
 "/            ].
 "/            colors addAll:aDevice deviceColors.
-	    colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
-	    colors := (colors select:[:c | c colorId notNil]) asOrderedCollection.
-	    colors size > 256 ifTrue:[
-		colors := colors copyTo:256
-	    ].
-	    f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
-	    f notNil ifTrue:[^ f].
-	].
+            colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
+            colors := (colors select:[:c | c colorId notNil]) asOrderedCollection.
+            colors size > 256 ifTrue:[
+                colors := colors copyTo:256
+            ].
+            f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
+            f notNil ifTrue:[^ f].
+        ].
     ].
 
     "/ the device ought to support 8-bit images ...
     (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
-	"/ cannot draw directly
-	^ nil
+        "/ cannot draw directly
+        ^ nil
     ].
 
     "create pseudocolor bits and translate"
@@ -1030,51 +1028,50 @@
     (rMask == 2r11111111
      and:[gMask == 2r11111111
      and:[bMask == 2r11111111]]) ifTrue:[
-	[srcIndex < dataSize] whileTrue:[
-	    r := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    g := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    b := bytes at:srcIndex.
-	    srcIndex := srcIndex + 1.
-	    greenArray := redArray at:(r + 1).
-	    blueArray := greenArray at:(g + 1).
-	    pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
-	    dstIndex := dstIndex + 1
-	]
+        [srcIndex < dataSize] whileTrue:[
+            r := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            g := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            b := bytes at:srcIndex.
+            srcIndex := srcIndex + 1.
+            greenArray := redArray at:(r + 1).
+            blueArray := greenArray at:(g + 1).
+            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+            dstIndex := dstIndex + 1
+        ]
     ] ifFalse:[
-	[srcIndex < dataSize] whileTrue:[
-	    r := bytes at:srcIndex.
-	    r := r bitAnd:rMask.
-	    srcIndex := srcIndex + 1.
-	    g := bytes at:srcIndex.
-	    g := g bitAnd:gMask.
-	    srcIndex := srcIndex + 1.
-	    b := bytes at:srcIndex.
-	    b := b bitAnd:bMask.
-	    srcIndex := srcIndex + 1.
-	    greenArray := redArray at:(r + 1).
-	    blueArray := greenArray at:(g + 1).
-	    pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
-	    dstIndex := dstIndex + 1
-	]
+        [srcIndex < dataSize] whileTrue:[
+            r := bytes at:srcIndex.
+            r := r bitAnd:rMask.
+            srcIndex := srcIndex + 1.
+            g := bytes at:srcIndex.
+            g := g bitAnd:gMask.
+            srcIndex := srcIndex + 1.
+            b := bytes at:srcIndex.
+            b := b bitAnd:bMask.
+            srcIndex := srcIndex + 1.
+            greenArray := redArray at:(r + 1).
+            blueArray := greenArray at:(g + 1).
+            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+            dstIndex := dstIndex + 1
+        ]
     ].
 
     f := Form imageForm width:width height:height depth:depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:colors.
-    f initGC.
     aDevice
-	drawBits:pseudoBits
-	bitsPerPixel:8
-	depth:depth
-	padding:8
-	width:width height:height
-	x:0 y:0
-	into:(f id)
-	x:0 y:0
-	width:width height:height
-	with:(f gcId).
+        drawBits:pseudoBits
+        bitsPerPixel:8
+        depth:depth
+        padding:8
+        width:width height:height
+        x:0 y:0
+        into:(f id)
+        x:0 y:0
+        width:width height:height
+        with:(f initGC).
     ^ f
 !
 
--- a/Depth8Image.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/Depth8Image.st	Sun Dec 18 12:12:59 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1993 by Claus Gittinger
 	      All Rights Reserved
@@ -554,7 +552,6 @@
         f := Form imageForm width:width height:height depth:deviceDepth onDevice:aDevice.
         f isNil ifTrue:[^ nil].
         f colorMap:imgMap.
-        f initGC.
         aDevice
             drawBits:pseudoBits
             bitsPerPixel:8
@@ -564,7 +561,7 @@
             x:0 y:0
             into:(f id) x:0 y:0
             width:width height:height
-            with:(f gcId).
+            with:(f initGC).
         ^ f
     ].
 
@@ -591,7 +588,6 @@
     f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:imgMap.
-    f initGC.
 
     aDevice
         drawBits:(newImage bits)
@@ -601,7 +597,7 @@
         x:0 y:0
         into:(f id) x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
 
     ^ f
 
@@ -2542,7 +2538,6 @@
 .
     f := Form width:w height:h depth:2 onDevice:aDevice.
     f isNil ifTrue:[^ nil].
-    f initGC.
     f graphicsDevice
         drawBits:formBytes
         depth:2
@@ -2552,7 +2547,7 @@
         into:f id
         x:0 y:0
         width:w height:h
-        with:f gcId.
+        with:f initGC.
     ^ f
 ! !
 
--- a/DeviceGraphicsContext.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/DeviceGraphicsContext.st	Sun Dec 18 12:12:59 2016 +0000
@@ -954,11 +954,7 @@
 copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h depth:depth
     "copy from aDrawable into the receiver;
      the source may be the receiver as well - in this case its a scroll.
-     All coordinates are in device coordinates.
-     If the receiver is a view AND async is true, the call returns immediately
-     - otherwise, it returns when the scroll operation is finished.
-     (not all devices care for this).
-     If the receiver is a pixmap, the call always returns immediately."
+     All coordinates are in device coordinates."
 
     |srcGCId srcDrawableId|
 
@@ -966,8 +962,7 @@
         self initGC
     ].
 
-    aGC initGC.
-    srcGCId := aGC gcId.
+    srcGCId := aGC initGC.
     srcDrawableId := aGC drawableId.
 
     ((depth == 1) and:[device depth ~~ 1]) ifTrue:[
@@ -1038,8 +1033,7 @@
         self initGC
     ].
 
-    aGC initGC.
-    srcGCId := aGC gcId.
+    srcGCId := aGC initGC.
     srcDrawableId := aGC drawableId.
 
     aGC isPixmap ifTrue:[
@@ -1922,7 +1916,7 @@
      settings are ignored and the form is drawn as-is;
      however, the mask is applied if present.
 
-     The form should must have been allocated on the same device,
+     The form should have been allocated on the same device,
      otherwise its converted here, which slows down the draw.
      No transformation or scaling is done.
      Care must be taken, that the paint color is correctly allocated
@@ -1933,7 +1927,7 @@
 
     |id w h easy paintDither depth tmpForm tmpId tmpGCId
      fgId noColor allColor allBits pX pY
-     mask maskId deviceForm deviceFormGCId deviceMask colorMap|
+     mask maskId deviceForm deviceFormGCId deviceMask deviceMaskGcId colorMap|
 
     w := aForm width.
     h := aForm height.
@@ -1948,7 +1942,7 @@
         ^self
     ].
     id := deviceForm drawableId.
-    "temporary ..."
+    "temporary ... what the heck is this??"
     (id isNil
      or:[aForm graphicsDevice ~~ device]) ifTrue:[
         deviceForm := deviceForm asFormOn:device.
@@ -1964,10 +1958,7 @@
     ].
     "/ device needGCForBitmapSource  - i.e. WIN32
     device isWindowsPlatform ifTrue:[
-        (deviceFormGCId := deviceForm gcId) isNil ifTrue:[
-            deviceForm initGC.
-            deviceFormGCId := deviceForm gcId.
-        ]
+        deviceFormGCId := deviceForm initGC.
     ].
 
     "
@@ -1988,7 +1979,7 @@
                 ].
                 maskId := deviceMask drawableId.
                 maskId notNil ifTrue:[
-                    deviceMask gcId isNil ifTrue:[deviceMask initGC].
+                    deviceMaskGcId := deviceMask initGC.
                     allColor := Color allColor.
                     allBits := allColor colorId.
 
@@ -2007,7 +1998,7 @@
                             copyPlaneFromPixmapId:maskId
                                 x:0
                                 y:0
-                                gc:(deviceMask gcId)
+                                gc:deviceMaskGcId
                                 to:drawableId
                                 x:pX
                                 y:pY
@@ -2066,9 +2057,8 @@
                             'DeviceGraphicsContext [warning]: cannot create temp form' errorPrintCR.
                             ^ self
                         ].
-                        tmpForm initGC.
                         tmpId := tmpForm drawableId.
-                        tmpGCId := tmpForm gcId.
+                        tmpGCId := tmpForm initGC.
 
                         "
                          fill tempform with image
@@ -2121,7 +2111,7 @@
                             copyPlaneFromPixmapId:maskId
                                 x:0
                                 y:0
-                                gc:(deviceMask gcId)
+                                gc:deviceMaskGcId
                                 to:tmpId
                                 x:0
                                 y:0
@@ -2144,7 +2134,7 @@
                             copyPlaneFromPixmapId:maskId
                                 x:0
                                 y:0
-                                gc:(deviceMask gcId)
+                                gc:deviceMaskGcId
                                 to:drawableId
                                 x:pX
                                 y:pY
@@ -2194,7 +2184,7 @@
             copyFromPixmapId:id
             x:0
             y:0
-            gc:deviceForm gcId
+            gc:deviceFormGCId
             to:drawableId
             x:pX
             y:pY
@@ -2429,7 +2419,7 @@
 
     |id w h easy savedPaint bgForm fgForm tmpForm
      fgId bgId noColor allColor allBits dx dy
-     pX pY deviceDepth deviceForm map|
+     pX pY deviceDepth deviceForm deviceFormGCId map|
 
     deviceForm := aForm asFormOn:device.
     id := deviceForm drawableId.
@@ -2448,7 +2438,7 @@
     gcId isNil ifTrue:[
         self initGC
     ].
-    deviceForm gcId isNil ifTrue:[deviceForm initGC].
+    deviceFormGCId := deviceForm initGC.
 
     w := aForm width.
     h := aForm height.
@@ -2465,7 +2455,7 @@
             copyFromPixmapId:id
             x:0
             y:0
-            gc:deviceForm gcId
+            gc:deviceFormGCId
             to:drawableId
             x:pX
             y:pY
@@ -2527,7 +2517,7 @@
             copyPlaneFromPixmapId:id
             x:0
             y:0
-            gc:(deviceForm gcId)
+            gc:deviceFormGCId
             to:drawableId
             x:pX
             y:pY
@@ -2568,7 +2558,7 @@
                 copyPlaneFromPixmapId:id
                 x:0
                 y:0
-                gc:(deviceForm gcId)
+                gc:deviceFormGCId
                 to:drawableId
                 x:pX
                 y:pY
@@ -2587,7 +2577,7 @@
                 copyPlaneFromPixmapId:id
                 x:0
                 y:0
-                gc:(deviceForm gcId)
+                gc:deviceFormGCId
                 to:drawableId
                 x:pX
                 y:pY
@@ -2625,7 +2615,7 @@
                 copyPlaneFromPixmapId:id
                 x:0
                 y:0
-                gc:(deviceForm gcId)
+                gc:deviceFormGCId
                 to:drawableId
                 x:pX
                 y:pY
@@ -2644,7 +2634,7 @@
                 copyPlaneFromPixmapId:id
                 x:0
                 y:0
-                gc:(deviceForm gcId)
+                gc:deviceFormGCId
                 to:drawableId
                 x:pX
                 y:pY
@@ -3142,14 +3132,12 @@
      This ignores any transformations. The coordinates must be integers."
 
     gcId isNil ifTrue:[
-	self initGC
+        self initGC
     ].
     device
-	fillRectangleX:x
-		     y:y
-		 width:w
-		height:h
-		    in:drawableId with:gcId
+        fillRectangleX:x y:y
+        width:w height:h
+        in:drawableId with:gcId
 ! !
 
 !DeviceGraphicsContext methodsFor:'evaluating in another context'!
@@ -3422,10 +3410,10 @@
 
 executor
     drawableType == #window ifTrue:[
-	^ DeviceWindowGCHandle basicNew
+        ^ DeviceWindowGCHandle basicNew
             setDevice:device id:drawableId gcId:gcId parentId:parentId.
     ] ifFalse:[
-	^ DevicePixmapGCHandle basicNew
+        ^ DevicePixmapGCHandle basicNew
             setDevice:device id:drawableId gcId:gcId.
     ].
 !
@@ -3500,13 +3488,14 @@
 initGC
     "since we do not need a gc-object for the drawable until something is
      really drawn, none is created.
-     This method is sent, when the first drawing happens"
+     This method is sent, when the first drawing happens.
+     Answer the gcId."
 
     |fgId bgId p fontId|
 
     gcId notNil ifTrue:[
         "already initialized"
-        ^ self
+        ^ gcId
     ].
     drawableId isNil ifTrue:[
         "/
@@ -3597,6 +3586,7 @@
         deviceFont := font.
         device setFont:fontId in:gcId
     ].
+    ^ gcId.
 
     "Modified: / 22-10-2006 / 14:10:53 / cg"
 !
--- a/DisplaySurface.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/DisplaySurface.st	Sun Dec 18 12:12:59 2016 +0000
@@ -1028,6 +1028,8 @@
 
     |oldPaint org patternOffsetX patternOffsetY|
 
+    (w <= 0 or:[h <= 0]) ifTrue:[^ self].
+    
     gc isNil ifTrue:[
         "nothing to clear"
         ^ self.
@@ -1038,7 +1040,7 @@
         viewBackground isViewBackground ifTrue:[
             oldPaint := self paint.
             self 
-                paint:self background;
+                paint:gc background;
                 fillDeviceRectangleX:x y:y width:w height:h;
                 paint:oldPaint.
             viewBackground fillRectangleX:x y:y width:w height:h in:self.
@@ -1102,9 +1104,10 @@
 !
 
 fillDeviceRectangleWithPattern:aPixmap x:xIn y:yIn width:wIn height:hIn patternOffset:pattOffs
-    <resource: #obsolete>
     "Fill a rectangular area with some pattern.
-     Caller must ensure that aPixmap is really a form"
+     Caller must ensure that aPixmap is really a form.
+     CG: mhm it seems that XQuartz has a bug and also has problems doing this.
+         therefore it is actually not obsolete."
 
     |r b
      pW "{ Class: SmallInteger }"
@@ -1127,8 +1130,8 @@
 
     x := x max:0.
     y := y max:0.
-    r := (xIn + w - 1) min:(width - 1).
-    b := (yIn + h - 1) min:(height - 1).
+    r := (xIn + w) min:width.
+    b := (yIn + h) min:height.
 
     pW := aPixmap width.
     pH := aPixmap height.
@@ -1140,8 +1143,8 @@
         r := r min:oldClip right.
         b := b min:oldClip bottom.
     ].
-    w := r-x+1.
-    h := b-y+1.
+    w := r-x.
+    h := b-y.
 
     yR := (y // pH) * pH.
     yE := y+h.
@@ -1154,8 +1157,8 @@
     xR0 >= xE ifTrue:[^ self].
 
     aPixmap depth == 1 ifTrue:[
-        oldFg := self foreground.
-        oldBg := self background.
+        oldFg := gc foreground.
+        oldBg := gc background.
         (clrMap := aPixmap colorMap) notNil ifTrue:[
             bg := clrMap at:1.
             fg := clrMap at:2.
@@ -1163,7 +1166,7 @@
             bg := self whiteColor.
             fg := self blackColor.
         ].
-        self foreground:fg background:bg.
+        gc foreground:fg background:bg.
     ].
     self deviceClippingBounds:(Rectangle left:x top:y width:w height:h).
 
@@ -1189,7 +1192,7 @@
     ].
 
     oldFg notNil ifTrue:[
-        self foreground:oldFg background:oldBg.
+        gc foreground:oldFg background:oldBg.
     ].
     gc deviceClippingBoundsOrNil:oldClip.
 
@@ -1200,9 +1203,10 @@
 !
 
 fillRectangleWithPattern:aPixmap x:x y:y width:w height:h patternOffset:pattOffs
-    <resource: #obsolete>
     "Fill a rectangular area with aPixmap.
-     Caller must ensure that the aPixmap is really a form"
+     Caller must ensure that the aPixmap is really a form.
+     CG: mhm it seems that XQuartz has a bug and also has problems doing this.
+         therefore it is actually not obsolete."
 
     |pX pY nW nH currentTransformation|
 
@@ -2199,9 +2203,9 @@
         "/ i.e. poll for the event
         "/
         device isWindowsPlatform ifTrue:[
-            pollDelay := 1.
+            pollDelay := 0.5.
         ] ifFalse:[
-            pollDelay := 3.
+            pollDelay := 1.
         ].
         endPollTime := Timestamp now addSeconds:pollDelay.
 
--- a/Form.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/Form.st	Sun Dec 18 12:12:59 2016 +0000
@@ -1518,21 +1518,23 @@
     "stop server from sending exposure events for Forms -
      (will fill up stream-queue on some stupid (i.e. sco) systems"
 
+    |gcId|
+
     "/ depth-1 forms draw differently ...
-
     depth == 1 ifTrue:[
-	|fg bg|
-	self foreground isNil ifTrue:[
-	    fg := Color colorId:1.
+        |fg bg|
+        self foreground isNil ifTrue:[
+            fg := Color colorId:1.
         ].
-	self background isNil ifTrue:[
-	    bg := Color colorId:0
-	].
-	"nil colors will not be set"
-	self setPaint:fg on:bg.
+        self background isNil ifTrue:[
+            bg := Color colorId:0
+        ].
+        "nil colors will not be set"
+        self setPaint:fg on:bg.
     ].
-    super initGC.
-    self setGraphicsExposures:false
+    gcId := super initGC.
+    self setGraphicsExposures:false.
+    ^ gcId.
 
     "Modified: 17.7.1996 / 13:21:24 / cg"
 !
--- a/GraphicsMedium.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/GraphicsMedium.st	Sun Dec 18 12:12:59 2016 +0000
@@ -1408,7 +1408,7 @@
      (not all devices care for this).
      If the receiver is a pixmap, the call always returns immediately."
 
-    |deviceDrawable mustWait|
+    |deviceDrawable mustWait sourceDepth|
 
     ((aDrawable graphicsDevice ~~ device)
      or:[aDrawable isImage]) ifTrue:[
@@ -1416,11 +1416,14 @@
     ] ifFalse:[
         deviceDrawable := aDrawable
     ].
-    mustWait := async not and:[deviceDrawable isView and:[((deviceDrawable depth ~~ 1) or:[device depth == 1])]].
+    sourceDepth := deviceDrawable depth.
+    mustWait := async not 
+                    and:[deviceDrawable isView 
+                    and:[(sourceDepth ~~ 1) or:[device depth == 1]]].
     mustWait ifTrue:[
         mustWait := self catchExpose.
     ].
-    gc copyFrom:deviceDrawable graphicsContext x:srcX y:srcY toX:dstX y:dstY width:w height:h depth:self depth.
+    gc copyFrom:deviceDrawable graphicsContext x:srcX y:srcY toX:dstX y:dstY width:w height:h depth:sourceDepth.
     mustWait ifTrue:[
         self waitForExpose
     ]
@@ -2663,7 +2666,7 @@
      really drawn, none is created.
      This method is sent, when the first drawing happens"
 
-    gc initGC
+    ^ gc initGC
 !
 
 initialize
@@ -2845,6 +2848,10 @@
 
 !GraphicsMedium class methodsFor:'documentation'!
 
+version
+    ^ '$Header$'
+!
+
 version_CVS
     ^ '$Header$'
 ! !
--- a/Image.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/Image.st	Sun Dec 18 12:12:59 2016 +0000
@@ -4187,7 +4187,6 @@
         map at:clr colorId + 1 put:clr
     ].
     f colorMap:map.
-    f initGC.
     f bits:pseudoBits.
     aDevice
         drawBits:pseudoBits
@@ -4198,7 +4197,7 @@
         x:0 y:0
         into:(f id) x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "
@@ -4270,7 +4269,6 @@
         map at:clr colorId + 1 put:clr
     ].
     f colorMap:map.
-    f initGC.
     f bits:pseudoBits.
     aDevice
         drawBits:pseudoBits
@@ -4281,7 +4279,7 @@
         x:0 y:0
         into:(f id) x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "
@@ -4583,7 +4581,6 @@
         ]
     ].
     f colorMap:map.
-    f initGC.
     f bits:pseudoBits.
     aDevice
         drawBits:pseudoBits
@@ -4594,7 +4591,7 @@
         x:0 y:0
         into:(f id) x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "
@@ -4964,7 +4961,6 @@
         map at:clr colorId + 1 put:clr
     ].
     f colorMap:map.
-    f initGC.
     f bits:pseudoBits.
     aDevice
         drawBits:pseudoBits
@@ -4975,7 +4971,7 @@
         x:0 y:0
         into:(f id) x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "
@@ -5468,7 +5464,6 @@
     f isNil ifTrue:[^ nil].
 
     f colorMap:cMap.
-    f initGC.
 
     aDevice
         drawBits:temp
@@ -5480,7 +5475,7 @@
         into:(f id) x:0 y:0
         width:w
         height:h
-        with:(f gcId).
+        with:(f initGC).
 
     ^ f
 
@@ -6321,7 +6316,6 @@
     f := Form width:width height:height depth:8 onDevice:aDevice.
     f isNil ifTrue:[^ nil].
     f colorMap:colorMap.
-    f initGC.
     aDevice
         drawBits:wideBits
         depth:8
@@ -6331,7 +6325,7 @@
         into:(f id)
         x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "Modified: 19.10.1997 / 05:19:44 / cg"
@@ -13272,13 +13266,13 @@
      pixels interpreted as greyValues, 0 is black,
      create a device form for it"
 
-    |f|
+    |f gcId|
 
     f := Form width:width height:height depth:depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
 
     f bits:bits.
-    f initGC.
+    gcId := f initGC.
 
     (aDevice blackpixel ~~ 0) ifTrue:[
         "/ have to invert bits
@@ -13293,7 +13287,7 @@
         into:(f id)
         x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:gcId.
     ^ f
 
     "Created: 10.6.1996 / 20:10:31 / cg"
@@ -13320,9 +13314,7 @@
 
     f := Form width:width height:height depth:depth onDevice:aDevice.
     f isNil ifTrue:[^ nil].
-
     f bits:bits.
-    f initGC.
 
     aDevice
         drawBits:bits
@@ -13333,7 +13325,7 @@
         into:(f id)
         x:0 y:0
         width:width height:height
-        with:(f gcId).
+        with:(f initGC).
     ^ f
 
     "Created: 10.6.1996 / 17:56:08 / cg"
--- a/SimpleView.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/SimpleView.st	Sun Dec 18 12:12:59 2016 +0000
@@ -10968,12 +10968,12 @@
     wCont := self widthOfContents.
     currentTransformation := gc transformation.
     currentTransformation isNil ifTrue:[
-	orgY := orgX := 0
+        orgY := orgX := 0
     ] ifFalse:[
-	wCont := (currentTransformation applyScaleX:wCont) rounded.
-	hCont := (currentTransformation applyScaleY:hCont) rounded.
-	orgY := currentTransformation translation y negated.
-	orgX := currentTransformation translation x negated
+        wCont := (currentTransformation applyScaleX:wCont) rounded.
+        hCont := (currentTransformation applyScaleY:hCont) rounded.
+        orgY := currentTransformation translation y negated.
+        orgX := currentTransformation translation x negated
     ].
 
     iw := self innerWidth.
@@ -10985,20 +10985,20 @@
     y := newOrigin y.
 
     allowScrollBeyondContents ifFalse:[
-	x + iw > wCont ifTrue:[
-	    x := (wCont - iw) asInteger.
-	].
+        x + iw > wCont ifTrue:[
+            x := (wCont - iw) asInteger.
+        ].
     ].
     x < 0 ifTrue:[
-	x := 0
+        x := 0
     ].
     allowScrollBeyondContents ifFalse:[
-	y + ih > hCont ifTrue:[
-	    y := (hCont - ih) asInteger.
-	].
+        y + ih > hCont ifTrue:[
+            y := (hCont - ih) asInteger.
+        ].
     ].
     y < 0 ifTrue:[
-	y := 0.
+        y := 0.
     ].
 
     dX := x - orgX.
@@ -11009,79 +11009,69 @@
     ].
 
     (wg := self windowGroup) notNil ifTrue:[
-	wg processRealExposeEventsFor:self.
+        wg processRealExposeEventsFor:self.
     ].
 
     self originWillChange.
     (shown and:[doRedraw]) ifTrue:[
-	copyWidth := iw - dX abs.
-	copyHeight := ih - dY abs.
-	((copyWidth > 0) and:[copyHeight > 0]) ifTrue:[
-	    "/ some of the currently displayed pixels
-	    "/ remain visible. Copy them
-
-	    dX < 0 ifTrue:[
-	      fromX := margin.
-	      toX := margin - dX.
-	      redrawX := margin
-	    ] ifFalse:[
-	      fromX := margin + dX.
-	      toX := margin.
-	      redrawX := margin + copyWidth.
-	    ].
-	    dY < 0 ifTrue:[
-	      fromY := margin.
-	      toY   := margin - dY.
-	      redrawY := margin.
-	    ] ifFalse:[
-	      fromY := margin + dY.
-	      toY   := margin.
-	      redrawY := margin + copyHeight.
-	    ].
-	    self catchExpose.
-	    self setViewOrigin:(x @ y).
-	    self
-		copyFrom:self
-		x:fromX y:fromY
-		toX:toX   y:toY
-		width:copyWidth
-		height:copyHeight
-		async:true.
-
-	    self setInnerClip.
-
-	    "first redraw the rectangle above/below the
-	     copied area (with full width)."
-
-	    copyHeight < ih ifTrue:[
-	    self invalidateDeviceRectangle:((margin@redrawY) extent:(iw@(ih - copyHeight))) repairNow:false.
-"/                self
-"/                    redrawDeviceX:margin y:redrawY
-"/                    width:iw height:(ih - copyHeight).
-	    ].
-
-	    "second redraw the rectangle left/right of the
-	     copied area"
-
-	    copyWidth < iw ifTrue:[
-	    self invalidateDeviceRectangle:((redrawX@toY) extent:((iw-copyWidth)@copyHeight)) repairNow:false.
-"/                self redrawDeviceX:redrawX y:toY
-"/
-"/                             width:iw - copyWidth
-"/                            height:copyHeight.
-	    ].
-	    self waitForExpose.
-	] ifFalse:[
-	    "redraw everything"
-
-	    self setViewOrigin:(x @ y).
-	    self invalidateDeviceRectangle:((margin@margin) extent:(iw@ih)) repairNow:false.
-"/            self redrawDeviceX:margin y:margin
-"/                         width:iw
-"/                        height:ih.
-	].
+        copyWidth := iw - dX abs.
+        copyHeight := ih - dY abs.
+        ((copyWidth > 0) and:[copyHeight > 0]) ifTrue:[
+            "/ some of the currently displayed pixels
+            "/ remain visible. Copy them
+
+            dX < 0 ifTrue:[
+              fromX := margin.
+              toX := margin - dX.
+              redrawX := margin
+            ] ifFalse:[
+              fromX := margin + dX.
+              toX := margin.
+              redrawX := margin + copyWidth.
+            ].
+            dY < 0 ifTrue:[
+              fromY := margin.
+              toY   := margin - dY.
+              redrawY := margin.
+            ] ifFalse:[
+              fromY := margin + dY.
+              toY   := margin.
+              redrawY := margin + copyHeight.
+            ].
+            self catchExpose.
+            self setViewOrigin:(x @ y).
+            self
+                copyFrom:self
+                x:fromX y:fromY
+                toX:toX   y:toY
+                width:copyWidth
+                height:copyHeight
+                async:true.
+
+            self setInnerClip.
+
+            "first redraw the rectangle above/below the
+             copied area (with full width)."
+
+            copyHeight < ih ifTrue:[
+                self invalidateDeviceRectangle:((margin@redrawY) extent:(iw@(ih - copyHeight))) repairNow:false.
+            ].
+
+            "second redraw the rectangle left/right of the
+             copied area"
+
+            copyWidth < iw ifTrue:[
+                self invalidateDeviceRectangle:((redrawX@toY) extent:((iw-copyWidth)@copyHeight)) repairNow:false.
+            ].
+            self waitForExpose.
+        ] ifFalse:[
+            "redraw everything"
+
+            self setViewOrigin:(x @ y).
+            self invalidateDeviceRectangle:((margin@margin) extent:(iw@ih)) repairNow:false.
+        ].
     ] ifFalse:[
-	self setViewOrigin:(x @ y).
+        self setViewOrigin:(x @ y).
     ].
 
     self originChanged:(dX negated @ dY negated).
--- a/XWorkstation.st	Thu Dec 15 20:11:12 2016 +0000
+++ b/XWorkstation.st	Sun Dec 18 12:12:59 2016 +0000
@@ -1792,8 +1792,7 @@
 !
 
 supportsAnyViewBackgroundPixmaps
-    "return true, if the device allows pixmaps as
-     viewBackground."
+    "return true, if the device allows pixmaps as viewBackground."
 
     ^ true
 
@@ -1815,6 +1814,7 @@
 
 supportsIconViews
     "return true, if this device supports views as icons.
+     These can be drawn into like any other regular view, and therefore be easily animated.
      Only Xservers (currently) support this."
 
     ^ true
@@ -1840,11 +1840,11 @@
 supportsMaskedDrawingWithOffset:aForm
     "return true, if the device allows the given form pixmap
      to be used as paint color with a mask offset.
-     True returned here - X has no trouble with any mask,
-     except for XQuartz, which has."
-
-    "XQuartz seems to have a bug here..."
+     True returned here - X has no trouble with any mask."
+
+    "/ XQuartz seems to have a bug here...
     ^ OperatingSystem isOSXlike not.
+    "/ ^ true.
 !
 
 supportsScreenReading