XWorkstation.st
changeset 397 094b8604ea72
parent 395 ce984a2deadd
child 402 f5a53e2a868d
equal deleted inserted replaced
396:d088e672be8a 397:094b8604ea72
  6023      must be big enough for the data to fit. If ok, returns an array with some
  6023      must be big enough for the data to fit. If ok, returns an array with some
  6024      info and the bits in imageBits. The info contains the depth, bitOrder and
  6024      info and the bits in imageBits. The info contains the depth, bitOrder and
  6025      number of bytes per scanline. The number of bytes per scanline is not known
  6025      number of bytes per scanline. The number of bytes per scanline is not known
  6026      in advance, since the X-server is free to return whatever it thinks is a good padding."
  6026      in advance, since the X-server is free to return whatever it thinks is a good padding."
  6027 
  6027 
  6028     |info|
  6028     |rawInfo info|
  6029 
  6029 
  6030     ((w <= 0) or:[h <= 0]) ifTrue:[
  6030     ((w <= 0) or:[h <= 0]) ifTrue:[
  6031 	self primitiveFailed.
  6031 	self primitiveFailed.
  6032 	^ nil
  6032 	^ nil
  6033     ].
  6033     ].
  6034 
  6034 
  6035     info := Array with:nil "depth"
  6035     rawInfo := Array new:8.
  6036 		  with:nil "bit order"
  6036 		  "1 -> bit order"
  6037 		  with:nil "bytes_per_line"
  6037 		  "2 -> depth"
  6038 		  with:nil "byte_order".
  6038 		  "3 -> bytes_per_line"
       
  6039 		  "4 -> byte_order"
       
  6040 		  "5 -> format"
       
  6041 		  "6 -> bitmap_unit"
       
  6042 		  "7 -> bitmap_pad"
       
  6043 		  "8 -> bits_per_pixel"
  6039 
  6044 
  6040     "/ had to extract the getPixel call into a separate method, to specify
  6045     "/ had to extract the getPixel call into a separate method, to specify
  6041     "/ unlimitedStack (some implementations use alloca and require huge amounts
  6046     "/ unlimitedStack (some implementations use alloca and require huge amounts
  6042     "/ of temporary stack space
  6047     "/ of temporary stack space
  6043 
  6048 
  6044     (self primGetBitsFrom:aDrawableId x:srcx y:srcy width:w height:h into:imageBits infoInfo:info) ifTrue:[
  6049     (self primGetBitsFrom:aDrawableId x:srcx y:srcy width:w height:h into:imageBits infoInto:rawInfo) ifTrue:[
       
  6050 	info := IdentityDictionary new.
       
  6051 	info at:#bitOrder put:(rawInfo at:1).
       
  6052 	info at:#depth put:(rawInfo at:2).
       
  6053 	info at:#bytesPerLine put:(rawInfo at:3).
       
  6054 	info at:#byteOrder put:(rawInfo at:4).
       
  6055 	info at:#format put:(rawInfo at:5).
       
  6056 	info at:#bitmapUnit put:(rawInfo at:6).
       
  6057 	info at:#bitmapPad put:(rawInfo at:7).
       
  6058 	info at:#bitsPerPixel put:(rawInfo at:8).
  6045 	^ info
  6059 	^ info
  6046     ].
  6060     ].
  6047     "
  6061     "
  6048      some error occured - either args are not smallintegers, imageBits is not a ByteArray
  6062      some error occured - either args are not smallintegers, imageBits is not a ByteArray
  6049      or is too small to hold the bits
  6063      or is too small to hold the bits
  6075     }
  6089     }
  6076 %}.
  6090 %}.
  6077     ^ nil
  6091     ^ nil
  6078 !
  6092 !
  6079 
  6093 
  6080 primGetBitsFrom:aDrawableId x:srcx y:srcy width:w height:h into:imageBits infoInfo:info
  6094 primGetBitsFrom:aDrawableId x:srcx y:srcy width:w height:h into:imageBits infoInto:info
  6081     "since XGetImage may allocate huge amount of stack space 
  6095     "since XGetImage may allocate huge amount of stack space 
  6082      (some implementations use alloca), this must run with unlimited stack."
  6096      (some implementations use alloca), this must run with unlimited stack."
  6083 
  6097 
  6084 %{  /* UNLIMITEDSTACK */
  6098 %{  /* UNLIMITEDSTACK */
  6085 
  6099 
  6115 	    case 24:
  6129 	    case 24:
  6116 	    case 32:
  6130 	    case 32:
  6117 		numBytes = image->bytes_per_line * image->height;
  6131 		numBytes = image->bytes_per_line * image->height;
  6118 		break;
  6132 		break;
  6119 	    default:
  6133 	    default:
  6120 		/* unsupported depth */
  6134 		/* unsupported depth ? */
  6121 		printf("unsupported depth:%d in primGetBits\n", image->depth);
  6135 		printf("possibly unsupported depth:%d in primGetBits\n", image->depth);
  6122 		goto fail;
  6136 		numBytes = image->bytes_per_line * image->height;
       
  6137 		break;
  6123 	}
  6138 	}
  6124 
  6139 
  6125 #ifdef SUPERDEBUG
  6140 #ifdef SUPERDEBUG
  6126 	printf("bytes need:%d bytes given:%d\n", numBytes, _byteArraySize(imageBits));
  6141 	printf("bytes need:%d bytes given:%d\n", numBytes, _byteArraySize(imageBits));
  6127 #endif
  6142 #endif
  6139 	_ArrayInstPtr(info)->a_element[2] = __MKSMALLINT(image->bytes_per_line);
  6154 	_ArrayInstPtr(info)->a_element[2] = __MKSMALLINT(image->bytes_per_line);
  6140 	if (image->byte_order == MSBFirst)
  6155 	if (image->byte_order == MSBFirst)
  6141 	    _ArrayInstPtr(info)->a_element[3] = @symbol(msbFirst);
  6156 	    _ArrayInstPtr(info)->a_element[3] = @symbol(msbFirst);
  6142 	else
  6157 	else
  6143 	    _ArrayInstPtr(info)->a_element[3] = @symbol(lsbFirst);
  6158 	    _ArrayInstPtr(info)->a_element[3] = @symbol(lsbFirst);
       
  6159 	if (image->format == XYBitmap)
       
  6160 	    _ArrayInstPtr(info)->a_element[4] = @symbol(XYBitmap);
       
  6161 	else if (image->format == XYPixmap)
       
  6162 	    _ArrayInstPtr(info)->a_element[4] = @symbol(XYPixmap);
       
  6163 	else if (image->format == ZPixmap)
       
  6164 	    _ArrayInstPtr(info)->a_element[4] = @symbol(ZPixmap);
       
  6165 	
       
  6166 	_ArrayInstPtr(info)->a_element[5] = __MKSMALLINT(image->bitmap_unit);
       
  6167 	_ArrayInstPtr(info)->a_element[6] = __MKSMALLINT(image->bitmap_pad);
       
  6168 	_ArrayInstPtr(info)->a_element[7] = __MKSMALLINT(image->bits_per_pixel);
  6144 	bcopy(image->data, _ByteArrayInstPtr(imageBits)->ba_element, numBytes);
  6169 	bcopy(image->data, _ByteArrayInstPtr(imageBits)->ba_element, numBytes);
  6145 	XDestroyImage(image);
  6170 	XDestroyImage(image);
  6146 	RETURN ( true );
  6171 	RETURN ( true );
  6147     }
  6172     }
  6148 fail: 
  6173 fail: 
  7271 ! !
  7296 ! !
  7272 
  7297 
  7273 !XWorkstation class methodsFor:'documentation'!
  7298 !XWorkstation class methodsFor:'documentation'!
  7274 
  7299 
  7275 version
  7300 version
  7276     ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.106 1996-02-01 20:03:04 cg Exp $'
  7301     ^ '$Header: /cvs/stx/stx/libview/XWorkstation.st,v 1.107 1996-02-04 17:11:29 cg Exp $'
  7277 ! !
  7302 ! !
  7278 XWorkstation initialize!
  7303 XWorkstation initialize!