private static void EmbedTimingPatterns(ByteMatrix matrix)
{
// -8 is for skipping position detection patterns (size 7), and two horizontal/vertical
// separation patterns (size 1). Thus, 8 = 7 + 1.
for (int i = 8; i < matrix.GetWidth() - 8; ++i)
{
int bit = (i + 1) % 2;
// Horizontal line.
if (!IsValidValue(matrix.Get(i, 6)))
{
throw new WriterException();
}
if (IsEmpty(matrix.Get(i, 6)))
{
matrix.Set(i, 6, bit);
}
// Vertical line.
if (!IsValidValue(matrix.Get(6, i)))
{
throw new WriterException();
}
if (IsEmpty(matrix.Get(6, i)))
{
matrix.Set(6, i, bit);
}
}
}