Exemple #1
0
		public static void DoThreshold(ImageBuffer result, ImageBuffer sourceImage, int threshold, TestThreshold testFunction)
		{
			if (sourceImage.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (sourceImage.Width != result.Width || sourceImage.Height != result.Height)
			{
				throw new Exception("All images must be the same size.");
			}

			switch (sourceImage.BitDepth)
			{
				case 32:
					{
						int height = sourceImage.Height;
						int width = sourceImage.Width;
						byte[] resultBuffer = result.GetBuffer();
						byte[] sourceBuffer = sourceImage.GetBuffer();
						for (int y = 0; y < height; y++)
						{
							int offset = sourceImage.GetBufferOffsetY(y);

							for (int x = 0; x < width; x++)
							{
								if (testFunction(sourceBuffer, offset, threshold))
								{
									resultBuffer[offset + 0] = (byte)255;
									resultBuffer[offset + 1] = (byte)255;
									resultBuffer[offset + 2] = (byte)255;
									resultBuffer[offset + 3] = (byte)255;
								}
								else
								{
									resultBuffer[offset + 0] = (byte)0;
									resultBuffer[offset + 1] = (byte)0;
									resultBuffer[offset + 2] = (byte)0;
									resultBuffer[offset + 3] = (byte)0;
								}
								offset += 4;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
Exemple #2
0
        public static void DoThreshold(ImageBuffer result, ImageBuffer sourceImage, int threshold, TestThreshold testFunction)
        {
            if (sourceImage.BitDepth != result.BitDepth)
            {
                throw new NotImplementedException("All the images have to be the same bit depth.");
            }
            if (sourceImage.Width != result.Width || sourceImage.Height != result.Height)
            {
                throw new Exception("All images must be the same size.");
            }

            switch (sourceImage.BitDepth)
            {
            case 8:
            {
                int    height       = sourceImage.Height;
                int    width        = sourceImage.Width;
                byte[] resultBuffer = result.GetBuffer();
                byte[] sourceBuffer = sourceImage.GetBuffer();
                for (int y = 0; y < height; y++)
                {
                    int offset = sourceImage.GetBufferOffsetY(y);

                    for (int x = 0; x < width; x++)
                    {
                        if (testFunction(sourceBuffer, offset, threshold))
                        {
                            resultBuffer[offset] = (byte)255;
                        }
                        else
                        {
                            resultBuffer[offset] = (byte)0;
                        }
                        offset += 1;
                    }
                }
            }
            break;

            case 32:
            {
                int    height       = sourceImage.Height;
                int    width        = sourceImage.Width;
                byte[] resultBuffer = result.GetBuffer();
                byte[] sourceBuffer = sourceImage.GetBuffer();
                for (int y = 0; y < height; y++)
                {
                    int offset = sourceImage.GetBufferOffsetY(y);

                    for (int x = 0; x < width; x++)
                    {
                        if (testFunction(sourceBuffer, offset, threshold))
                        {
                            resultBuffer[offset + 0] = (byte)255;
                            resultBuffer[offset + 1] = (byte)255;
                            resultBuffer[offset + 2] = (byte)255;
                            resultBuffer[offset + 3] = (byte)255;
                        }
                        else
                        {
                            resultBuffer[offset + 0] = (byte)0;
                            resultBuffer[offset + 1] = (byte)0;
                            resultBuffer[offset + 2] = (byte)0;
                            resultBuffer[offset + 3] = (byte)0;
                        }
                        offset += 4;
                    }
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Exemple #3
0
 public static void DoThreshold(ImageBuffer sourceImageAndDest, int threshold, TestThreshold testFunction)
 {
     DoThreshold(sourceImageAndDest, sourceImageAndDest, threshold, testFunction);
 }
Exemple #4
0
		public static void DoThreshold(ImageBuffer sourceImageAndDest, int threshold, TestThreshold testFunction)
		{
			DoThreshold(sourceImageAndDest, sourceImageAndDest, threshold, testFunction);
		}