Example #1
0
        /// <summary>
        /// Turns the lines into a BlockLine
        /// </summary>
        private unsafe void BuildBlockLine(byte *[] lines, int index, int bpp)
        {
            BlockLine blockLine = _newImageLines[index];

            // Advance one block width at a time

            int step = _elementWidth * bpp;

            for (int i = 0; i < blockLine.Count; i++)
            {
                int offset = i * step;
                BuildBlock(lines, blockLine.GetBlock(i), offset, step, bpp);
            }
        }
Example #2
0
        /// <summary>
        /// Generates the errors for the given BlockLine
        /// </summary>
        private void GenerateErrors(int y, BlockLine blockLine)
        {
            for (int x = 0; x < blockLine.Count; x++)
            {
                List <int> errors = new List <int>(_elementBlocks.Count);
                ColorBlock img    = blockLine.GetBlock(x);

                // Compare the ColorBlock with every mosaic element

                for (int i = 0; i < _elementBlocks.Count; i++)
                {
                    ColorBlock element = _elementBlocks[i];
                    errors.Add(Metrics.SquaredError(img, element));
                }

                // Set the best fitting block in the list

                int index = errors.FindIndexOfSmallestElement();
                NewImageLines[y].SetBlock(_elementBlocks[index], x);
            }
        }