/// <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); } }
/// <summary> /// Turns the lines into a BlockLine /// </summary> private unsafe BlockLine GetBlockLine(byte *[] lines, LockBitsData data) { BlockLine blockLine = new BlockLine(_pData.Columns, LineFillMode.Default); // Advance one block width at a time int step = _elementWidth * data.BytesPerPixel; for (int offset = 0; offset < data.WidthInBytes; offset += step) { blockLine.Add(GetPixels(lines, offset, step, data.BytesPerPixel)); } return(blockLine); }
/// <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); } }