Example #1
0
        static private string[] shade_ASCII(byte[][] grey_bytes)
        {
            string[]      result  = new string[grey_bytes.Length];
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < grey_bytes.Length; i++)
            {
                builder.Clear();
                for (int j = 0; j < grey_bytes[0].Length; j++)
                {
                    GREYSCALE_CONVERSION_VALUES conv_val = (GREYSCALE_CONVERSION_VALUES)grey_bytes[i][j];
                    if (conv_val <= GREYSCALE_CONVERSION_VALUES.PURE_BLACK)
                    {
                        builder.Append("##");
                    }
                    else if (conv_val <= GREYSCALE_CONVERSION_VALUES.SEMI_BLACK)
                    {
                        builder.Append("==");
                    }
                    else if (conv_val <= GREYSCALE_CONVERSION_VALUES.GREY)
                    {
                        builder.Append("~~");
                    }
                    else
                    {
                        builder.Append("  ");
                    }
                }
                result[i] = builder.ToString();
            }

            return(result);
        }
Example #2
0
        static private uint byte_grid_to_pixel_hash(ByteGrid grid)
        {
            if (grid == null ||
                !grid.valid_grid)
            {
                throw new ArgumentNullException("ASCII_Converter: Null ByteGrid object passed when trying to hash the pixel value.");
            }

            uint hash = 0;

            // 2 bits per byte

            for (int i = 0; i < grid.height; i++)
            {
                for (int j = 0; j < grid.width; j++)
                {
                    hash = hash << 2;

                    GREYSCALE_CONVERSION_VALUES conv_val =
                        (GREYSCALE_CONVERSION_VALUES)grid.grid[i][j];

                    if (conv_val <= GREYSCALE_CONVERSION_VALUES.PURE_BLACK)
                    {
                        hash += 3;
                    }
                    else if (conv_val <= GREYSCALE_CONVERSION_VALUES.SEMI_BLACK)
                    {
                        hash += 2;
                    }
                    else if (conv_val <= GREYSCALE_CONVERSION_VALUES.GREY)
                    {
                        hash += 1;
                    }
                    else if (conv_val <= GREYSCALE_CONVERSION_VALUES.WHITE)
                    {
                        hash += 0;
                    }
                    else
                    {
                        throw new InvalidOperationException("ASCII_Converter: Invalid greyscale byte passed.");
                    }
                }
            }

            return(hash);
        }