コード例 #1
0
		private static bool[] CreateOverlayData(FrameDataGetter frameDataGetter, int frameCount)
		{
			bool[] overlayData = null;
			for (int n = 0; n < frameCount; n++)
			{
				var frameData = frameDataGetter.Invoke(n + 1);
				if (overlayData == null)
				{
					overlayData = new bool[frameData.Length*frameCount];
				}

				var cursor = frameData.Length*n;
				for (int i = 0; i < frameData.Length; i++)
				{
					overlayData[cursor++] = frameData[i] > 0.5f;
				}
			}
			return overlayData;
		}
コード例 #2
0
		private static byte[] CreatePixelData(FrameDataGetter frameDataGetter, int frameCount, int bitsAllocated, int bitsStored, int highBit, bool isSigned)
		{
			if (bitsAllocated != 8 && bitsAllocated != 16)
				throw new ArgumentException("bitsAllocated must be either 8 or 16.", "bitsAllocated");

			byte[] pixelData = null;
			for (int n = 0; n < frameCount; n++)
			{
				var frameData = frameDataGetter.Invoke(n + 1);
				if (pixelData == null)
				{
					pixelData = new byte[frameData.Length*frameCount*bitsAllocated/8];
				}

				int min = DicomPixelData.GetMinPixelValue(bitsStored, isSigned);
				int max = DicomPixelData.GetMaxPixelValue(bitsStored, isSigned);

				if (bitsAllocated == 16)
				{
					var cursor = frameData.Length*n*2;
					for (int i = 0; i < frameData.Length; i++)
					{
						var value = Math.Max(min, Math.Min(max, (int)(min + (max - min) * frameData[i])));
						value = value << (highBit - bitsStored + 1);

						if (ByteBuffer.LocalMachineEndian == Endian.Little)
						{
							pixelData[cursor++] = (byte) (value & 0x00FF);
							pixelData[cursor++] = (byte) ((value >> 8) & 0x00FF);
						}
						else
						{
							pixelData[cursor++] = (byte) ((value >> 8) & 0x00FF);
							pixelData[cursor++] = (byte) (value & 0x00FF);
						}
					}
				}
				else if (bitsAllocated == 8)
				{
					var cursor = frameData.Length*n;
					for (int i = 0; i < frameData.Length; i++)
					{
						var value = Math.Max(min, Math.Min(max, (int)(min + (max - min) * frameData[i])));
						value = value << (highBit - bitsStored + 1);
						pixelData[cursor++] = (byte) (value & 0x00FF);
					}
				}
			}

			//just in case, we'll clean the pixel data up.  This also (cheaply) removes the 
			//higher order 1s that shouldn't be there for the signed case.
			DicomUncompressedPixelData.ZeroUnusedBits(pixelData, bitsAllocated, bitsStored, highBit);
			return pixelData;
		}