--- a/WinWorkstation.st Wed Apr 12 15:45:44 2017 +0200
+++ b/WinWorkstation.st Wed Apr 12 15:46:22 2017 +0200
@@ -10738,23 +10738,22 @@
colors are allocated - otherwise the colors may be wrong."
(self
- primDrawBits:imageBits
- bitsPerPixel:bitsPerPixel
- depth:imageDepth
- width:imageWidth height:imageHeight
- x:srcx y:srcy
- into:ignoredDrawableId
- x:dstx y:dsty
- width:w height:h
- with:aGCId
- parameters:(Array with:nil with:padd with:nil with:nil with:nil)
- "/ the params array is ONLY used, because there is a 15-argument limit in st/x !!
+ primDrawBits:imageBits
+ bitsPerPixel:bitsPerPixel
+ depth:imageDepth
+ width:imageWidth height:imageHeight
+ x:srcx y:srcy
+ into:ignoredDrawableId
+ x:dstx y:dsty
+ width:w height:h
+ with:aGCId
+ parameters:(Array with:nil with:padd with:nil with:nil with:nil)
+ "/ the params array is ONLY used, because there is a 15-argument limit in st/x !!
) ifFalse:[
- "
- also happens, if a segmentation violation occurs in the
- XPutImage ...
- "
- self primitiveFailed
+ "
+ also happens, if a segmentation violation occurs in primitive code...
+ "
+ self primitiveFailed
].
!
@@ -10779,23 +10778,22 @@
colors are allocated - otherwise the colors may be wrong."
(self
- primDrawBits:imageBits
- bitsPerPixel:bitsPerPixel
- depth:imageDepth
- width:imageWidth height:imageHeight
- x:srcx y:srcy
- into:ignoredDrawableId
- x:dstx y:dsty
- width:w height:h
- with:aGCId
- parameters:parameters
- "/ the params array is ONLY used, because there is a 15-argument limit in st/x !!
+ primDrawBits:imageBits
+ bitsPerPixel:bitsPerPixel
+ depth:imageDepth
+ width:imageWidth height:imageHeight
+ x:srcx y:srcy
+ into:ignoredDrawableId
+ x:dstx y:dsty
+ width:w height:h
+ with:aGCId
+ parameters:parameters
+ "/ the params array is ONLY used, because there is a 15-argument limit in st/x !!
) ifFalse:[
- "
- also happens, if a segmentation violation occurs in the
- XPutImage ...
- "
- self primitiveFailed
+ "
+ also happens, if a segmentation violation occurs in primitive code...
+ "
+ self primitiveFailed
].
!
@@ -11007,14 +11005,14 @@
!
primDrawBits:imageBits
- bitsPerPixel:bitsPerPixel depth:imageDepth
- width:imageWidth height:imageHeight
- x:srcx y:srcy
- into:ignoredDrawableId
- x:dstx y:dsty
- width:w height:h
- with:aGCId
- parameters:params
+ bitsPerPixel:bitsPerPixel depth:imageDepth
+ width:imageWidth height:imageHeight
+ x:srcx y:srcy
+ into:ignoredDrawableId
+ x:dstx y:dsty
+ width:w height:h
+ with:aGCId
+ parameters:params
|sourceAlphaOrNil padd redMask greenMask blueMask|
@@ -11024,7 +11022,8 @@
redMask := params at:3.
greenMask := params at:4.
blueMask := params at:5.
-%{
+
+%{ /* STACK: 20000 */
unsigned char fastBits[10000];
unsigned char *b_bits = 0;
unsigned char *allocatedBits = 0;
@@ -11035,9 +11034,9 @@
int _doAlphaBlend = 0;
if (__isByteArray(imageBits)) {
- __imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
+ __imageBits = __ByteArrayInstPtr(imageBits)->ba_element;
} else if (__isExternalBytesLike(imageBits)) {
- __imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
+ __imageBits = (unsigned char *)(__externalBytesAddress(imageBits));
}
if (ISCONNECTED
@@ -11050,207 +11049,207 @@
&& __isSmallInteger(padd)
&& __imageBits)
{
- struct
- {
- BITMAPINFOHEADER bmiHeader;
- DWORD r;
- DWORD g;
- DWORD b;
- DWORD a;
- } bitmap;
- int _padd = __intVal(padd);
-
- gcData = _GCDATA(aGCId);
- if (! gcData )
- goto fail;
- hDC = _getDC(gcData);
- DDDDPRINTF(("hDC = %x\n", hDC));
-
- if (_padd != WIN32PADDING) {
- int row, col;
- unsigned char *cp;
- unsigned char *pBits;
- int b_width, b_height, bytesPerRowST, bytesPerRowWIN, padding, nBytes;
- int bi = __intVal(bitsPerPixel);
-
- b_width = __intVal(imageWidth);
- b_height = __intVal(imageHeight);
- bytesPerRowST = (b_width * bi + (_padd-1)) / _padd;
- bytesPerRowWIN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
- padding = bytesPerRowWIN - bytesPerRowST;
- /* console_printf("padd %d bs %d bw %d p %d\n",_padd,bytesPerRowST,bytesPerRowWN,padding); */
- if (padding) {
- nBytes = b_height * bytesPerRowWIN;
- if (nBytes < sizeof(fastBits)) {
- cp = b_bits = fastBits;
- } else {
- cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
- }
- if (cp) {
- pBits = __imageBits;
- for (row = b_height; row; row--) {
- for (col = bytesPerRowST; col; col--) {
- *cp++ = *pBits++;
- }
- cp += padding;
- }
- } else
- goto fail;
- }
- }
-
- if (b_bits == 0) {
- b_bits = __imageBits;
- }
-
- bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bitmap.bmiHeader.biPlanes = 1;
- switch (__intVal(imageDepth)) {
- case 16:
- /* notice the default r/g/b (STX order here) */
+ struct
+ {
+ BITMAPINFOHEADER bmiHeader;
+ DWORD r;
+ DWORD g;
+ DWORD b;
+ DWORD a;
+ } bitmap;
+ int _padd = __intVal(padd);
+
+ gcData = _GCDATA(aGCId);
+ if (! gcData )
+ goto fail;
+ hDC = _getDC(gcData);
+ DDDDPRINTF(("hDC = %x\n", hDC));
+
+ if (_padd != WIN32PADDING) {
+ int row, col;
+ unsigned char *cp;
+ unsigned char *pBits;
+ int b_width, b_height, bytesPerRowST, bytesPerRowWIN, padding, nBytes;
+ int bi = __intVal(bitsPerPixel);
+
+ b_width = __intVal(imageWidth);
+ b_height = __intVal(imageHeight);
+ bytesPerRowST = (b_width * bi + (_padd-1)) / _padd;
+ bytesPerRowWIN = (b_width * bi + (WIN32PADDING-1)) / WIN32PADDING * (WIN32PADDING/8);
+ padding = bytesPerRowWIN - bytesPerRowST;
+ /* console_printf("padd %d bs %d bw %d p %d\n",_padd,bytesPerRowST,bytesPerRowWN,padding); */
+ if (padding) {
+ nBytes = b_height * bytesPerRowWIN;
+ if (nBytes < sizeof(fastBits)) {
+ cp = b_bits = fastBits;
+ } else {
+ cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
+ }
+ if (cp) {
+ pBits = __imageBits;
+ for (row = b_height; row; row--) {
+ for (col = bytesPerRowST; col; col--) {
+ *cp++ = *pBits++;
+ }
+ cp += padding;
+ }
+ } else
+ goto fail;
+ }
+ }
+
+ if (b_bits == 0) {
+ b_bits = __imageBits;
+ }
+
+ bitmap.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ bitmap.bmiHeader.biPlanes = 1;
+ switch (__intVal(imageDepth)) {
+ case 16:
+ /* notice the default r/g/b (STX order here) */
#if 1
- bitmap.bmiHeader.biCompression = BI_BITFIELDS;
- bitmap.r = redMask == nil ? 0xf800 : __intVal(redMask);
- bitmap.g = greenMask == nil ? 0x07e0 : __intVal(greenMask);
- bitmap.b = blueMask == nil ? 0x001f : __intVal(blueMask);
-#endif
- break;
-
- case 24:
- /* notice the default b/g/r (WIN32 order here) */
-#if 0
- bitmap.bmiHeader.biCompression = BI_BITFIELDS;
- bitmap.r = redMask == nil ? 0xff0000 : __intVal(redMask);
- bitmap.g = greenMask == nil ? 0x00ff00 : __intVal(greenMask);
- bitmap.b = blueMask == nil ? 0x0000ff : __intVal(blueMask);
-#endif
- bitmap.bmiHeader.biCompression = BI_RGB;
- break;
-
- case 32:
- /* notice the default r/g/b (STX order here) */
- bitmap.bmiHeader.biCompression = BI_RGB;
+ bitmap.bmiHeader.biCompression = BI_BITFIELDS;
+ bitmap.r = redMask == nil ? 0xf800 : __intVal(redMask);
+ bitmap.g = greenMask == nil ? 0x07e0 : __intVal(greenMask);
+ bitmap.b = blueMask == nil ? 0x001f : __intVal(blueMask);
+#endif
+ break;
+
+ case 24:
+ /* notice the default b/g/r (WIN32 order here) */
+#if 0
+ bitmap.bmiHeader.biCompression = BI_BITFIELDS;
+ bitmap.r = redMask == nil ? 0xff0000 : __intVal(redMask);
+ bitmap.g = greenMask == nil ? 0x00ff00 : __intVal(greenMask);
+ bitmap.b = blueMask == nil ? 0x0000ff : __intVal(blueMask);
+#endif
+ bitmap.bmiHeader.biCompression = BI_RGB;
+ break;
+
+ case 32:
+ /* notice the default r/g/b (STX order here) */
+ bitmap.bmiHeader.biCompression = BI_RGB;
#if 1
- bitmap.bmiHeader.biCompression = BI_BITFIELDS;
- bitmap.r = redMask == nil ? 0x0000ff : __intVal(redMask);
- bitmap.g = greenMask == nil ? 0x00ff00 : __intVal(greenMask);
- bitmap.b = blueMask == nil ? 0xff0000 : __intVal(blueMask);
- bitmap.a = 0xff000000;
-#endif
- break;
- }
-
- if (sourceAlphaOrNil != nil) {
+ bitmap.bmiHeader.biCompression = BI_BITFIELDS;
+ bitmap.r = redMask == nil ? 0x0000ff : __intVal(redMask);
+ bitmap.g = greenMask == nil ? 0x00ff00 : __intVal(greenMask);
+ bitmap.b = blueMask == nil ? 0xff0000 : __intVal(blueMask);
+ bitmap.a = 0xff000000;
+#endif
+ break;
+ }
+
+ if (sourceAlphaOrNil != nil) {
console_printf("sourceAlphaOrNil = %x\n", sourceAlphaOrNil);
- _sourceAlpha = __intVal(sourceAlphaOrNil);
- _doAlphaBlend = 1;
- }
-
- bitmap.bmiHeader.biSizeImage = 0;
- bitmap.bmiHeader.biXPelsPerMeter = 0;
- bitmap.bmiHeader.biYPelsPerMeter = 0;
- bitmap.bmiHeader.biClrUsed = 0;
- bitmap.bmiHeader.biClrImportant = 0;
- bitmap.bmiHeader.biWidth = __intVal(imageWidth);
- bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
- bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
- /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
-
- if (! _doAlphaBlend) {
- SetDIBitsToDevice(hDC,
- __intVal(dstx), __intVal(dsty),
- __intVal(w), __intVal(h),
- __intVal(srcx), __intVal(srcy),
- 0, __intVal(h),
- (void *)b_bits,
- (BITMAPINFO*)&bitmap,
- DIB_RGB_COLORS);
- } else {
- HDC ahdc;
- HBITMAP ahbitmap;
- void *pvBits;
- BLENDFUNCTION bf;
- static BOOL (__stdcall *P_AlphaBlend)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION );
-
- if (P_AlphaBlend == 0) {
- /* as I dont have AlphaBlend in the inport32.lib (bcc sucks),
- * fetch its address dynamically...
- */
- HINSTANCE hWinGDI = LoadLibrary("msimg32.dll");
- if (hWinGDI) {
- P_AlphaBlend = (BOOL (__stdcall *)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION ))
- GetProcAddress(hWinGDI, "AlphaBlend");
- }
- }
- if (P_AlphaBlend != 0) {
+ _sourceAlpha = __intVal(sourceAlphaOrNil);
+ _doAlphaBlend = 1;
+ }
+
+ bitmap.bmiHeader.biSizeImage = 0;
+ bitmap.bmiHeader.biXPelsPerMeter = 0;
+ bitmap.bmiHeader.biYPelsPerMeter = 0;
+ bitmap.bmiHeader.biClrUsed = 0;
+ bitmap.bmiHeader.biClrImportant = 0;
+ bitmap.bmiHeader.biWidth = __intVal(imageWidth);
+ bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
+ bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
+ /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
+
+ if (! _doAlphaBlend) {
+ SetDIBitsToDevice(hDC,
+ __intVal(dstx), __intVal(dsty),
+ __intVal(w), __intVal(h),
+ __intVal(srcx), __intVal(srcy),
+ 0, __intVal(h),
+ (void *)b_bits,
+ (BITMAPINFO*)&bitmap,
+ DIB_RGB_COLORS);
+ } else {
+ HDC ahdc;
+ HBITMAP ahbitmap;
+ void *pvBits;
+ BLENDFUNCTION bf;
+ static BOOL (__stdcall *P_AlphaBlend)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION );
+
+ if (P_AlphaBlend == 0) {
+ /* as I don't have AlphaBlend in the inport32.lib (bcc sucks),
+ * fetch its address dynamically...
+ */
+ HINSTANCE hWinGDI = LoadLibrary("msimg32.dll");
+ if (hWinGDI) {
+ P_AlphaBlend = (BOOL (__stdcall *)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION ))
+ GetProcAddress(hWinGDI, "AlphaBlend");
+ }
+ }
+ if (P_AlphaBlend != 0) {
console_printf("***********************************\n");
console_printf("_sourceAlpha = %d\n", _sourceAlpha);
- ahdc = CreateCompatibleDC(hDC);
-
- ahbitmap = CreateCompatibleBitmap(hDC, __intVal(imageWidth), __intVal(imageHeight));
- SelectObject(ahdc, ahbitmap);
- SetDIBitsToDevice(ahdc,
- 0, 0, /* dstx, dsty */
- __intVal(imageWidth), __intVal(imageHeight),
- __intVal(srcx), __intVal(srcy),
- 0, __intVal(imageHeight),
- (void *)b_bits,
- (BITMAPINFO*)&bitmap,
- DIB_RGB_COLORS);
-
- bf.BlendOp = AC_SRC_OVER;
- bf.BlendFlags = 0;
- bf.SourceConstantAlpha = _sourceAlpha;
- bf.AlphaFormat = AC_SRC_ALPHA;
+ ahdc = CreateCompatibleDC(hDC);
+
+ ahbitmap = CreateCompatibleBitmap(hDC, __intVal(imageWidth), __intVal(imageHeight));
+ SelectObject(ahdc, ahbitmap);
+ SetDIBitsToDevice(ahdc,
+ 0, 0, /* dstx, dsty */
+ __intVal(imageWidth), __intVal(imageHeight),
+ __intVal(srcx), __intVal(srcy),
+ 0, __intVal(imageHeight),
+ (void *)b_bits,
+ (BITMAPINFO*)&bitmap,
+ DIB_RGB_COLORS);
+
+ bf.BlendOp = AC_SRC_OVER;
+ bf.BlendFlags = 0;
+ bf.SourceConstantAlpha = _sourceAlpha;
+ bf.AlphaFormat = AC_SRC_ALPHA;
#if 1
- (*P_AlphaBlend) (hDC,
- __intVal(dstx), __intVal(dsty),
- __intVal(imageWidth), __intVal(imageHeight),
- ahdc,
- 0, 0, /* srcx, srcy */
- __intVal(imageWidth), __intVal(imageHeight),
- bf);
-#else
- bf.SourceConstantAlpha = 255-_sourceAlpha;
- bf.AlphaFormat = 0;
- bf.BlendOp = 0;
- (*P_AlphaBlend) (ahdc,
- 0, 0, /* dstx, dsty */
- __intVal(imageWidth), __intVal(imageHeight),
- hDC,
- __intVal(dstx), __intVal(dsty), /* srcx, srcy */
- __intVal(imageWidth), __intVal(imageHeight),
- bf);
-
- BitBlt (hDC,
- __intVal(dstx), __intVal(dsty),
- __intVal(imageWidth), __intVal(imageHeight),
- ahdc,
- 0, 0, /* srcx, srcy */
- SRCCOPY);
-#endif
- DeleteObject(ahbitmap);
- DeleteDC(ahdc);
- }
- }
- if (allocatedBits) {
- free(allocatedBits);
- }
+ (*P_AlphaBlend) (hDC,
+ __intVal(dstx), __intVal(dsty),
+ __intVal(imageWidth), __intVal(imageHeight),
+ ahdc,
+ 0, 0, /* srcx, srcy */
+ __intVal(imageWidth), __intVal(imageHeight),
+ bf);
+#else
+ bf.SourceConstantAlpha = 255-_sourceAlpha;
+ bf.AlphaFormat = 0;
+ bf.BlendOp = 0;
+ (*P_AlphaBlend) (ahdc,
+ 0, 0, /* dstx, dsty */
+ __intVal(imageWidth), __intVal(imageHeight),
+ hDC,
+ __intVal(dstx), __intVal(dsty), /* srcx, srcy */
+ __intVal(imageWidth), __intVal(imageHeight),
+ bf);
+
+ BitBlt (hDC,
+ __intVal(dstx), __intVal(dsty),
+ __intVal(imageWidth), __intVal(imageHeight),
+ ahdc,
+ 0, 0, /* srcx, srcy */
+ SRCCOPY);
+#endif
+ DeleteObject(ahbitmap);
+ DeleteDC(ahdc);
+ }
+ }
+ if (allocatedBits) {
+ free(allocatedBits);
+ }
#ifndef CACHE_LAST_DC
- _releaseDC(gcData);
-#endif
- RETURN ( true );
+ _releaseDC(gcData);
+#endif
+ RETURN ( true );
}
fail: ;
PRINTF(("create temp bitmap FAILED!!!\n"));
if (allocatedBits) {
- PRINTF(("freeing up temp bitmap bits ...\n"));
- free(allocatedBits);
+ PRINTF(("freeing up temp bitmap bits ...\n"));
+ free(allocatedBits);
}
#ifndef CACHE_LAST_DC
if (hDC) {
- _releaseDC(gcData);
+ _releaseDC(gcData);
}
#endif
%}