refactor: STCP connections as ETCP links (is_tcp)

- Add is_tcp, tcp_link, tcp_reconnect_* fields to ETCP_LINK
- Remove transport_link from ETCP_CONN, add tcp_link_count
- stcp_link: replace embedded etcp_conn with pointer; add etcp_link backpointer
- stcp_link: link_rx_cb routes ETCP data to etcp_conn_input
- stcp_link: call on_close_cb in close
- New TCP functions: etcp_link_enter_ready_tcp, etcp_tcp_link_start_connect,
  etcp_tcp_link_start_reconnect, tcp_link_close_cb, etcp_tcp_send
- etcp_link_new: handle NULL conn for TCP links; skip enter_init for TCP
- etcp_link_close: close stcp_link for TCP
- etcp_encrypt_send: redirect TCP to etcp_tcp_send (skips AES-CCM)
- tcp_server_on_link: create ETCP_LINK(is_tcp=1) + enter_ready_tcp
- etcp_connect: TCP addrs -> etcp_tcp_link_start_connect
- Remove ctx->tcp_link/tcp_ready
- test_stcp_traffic: find stcp_link via links->is_tcp instead of transport_link
- 66/68 tests pass; 2 STCP tests expected to fail (integration not complete)
This commit is contained in:
evgeny committed 2026-08-06 22:14:32 +03:00
1 parent 937af4c26a
commit d773f1724a
1705 files changed
+187 -1082154

No files matched your search

@@ -1,111 +0,0 @@
/*
* Copyright 2020 Axel Waggershauser
*/
// SPDX-License-Identifier: Apache-2.0
#include "BinaryBitmap.h"
#include "BitMatrix.h"
namespace ZXing {
struct BinaryBitmap::Cache
{
std::shared_ptr<const BitMatrix> matrix, transposed;
};
BitMatrix BinaryBitmap::binarize(const uint8_t threshold) const
{
BitMatrix res(width(), height());
if (_buffer.pixStride() == 1 && _buffer.rowStride() == _buffer.width()) {
// Specialize for a packed buffer with pixStride 1 to support auto vectorization (16x speedup on AVX2)
auto dst = res.row(0).begin();
for (auto src = _buffer.data(0, 0), end = _buffer.data(0, height()); src != end; ++src, ++dst)
*dst = (*src <= threshold) * BitMatrix::SET_V;
} else {
auto processLine = [&res, threshold](int y, const auto* src, const int stride) {
for (auto& dst : res.row(y)) {
dst = (*src <= threshold) * BitMatrix::SET_V;
src += stride;
}
};
for (int y = 0; y < res.height(); ++y) {
auto src = _buffer.data(0, y) + GreenIndex(_buffer.format());
// Specialize the inner loop for strides 1 and 4 to support auto vectorization
switch (_buffer.pixStride()) {
case 1: processLine(y, src, 1); break;
case 4: processLine(y, src, 4); break;
default: processLine(y, src, _buffer.pixStride()); break;
}
}
}
return res;
}
BinaryBitmap::BinaryBitmap(const ImageView& buffer) : _cache(new Cache), _buffer(buffer) {}
BinaryBitmap::~BinaryBitmap() = default;
const BitMatrix* BinaryBitmap::getBitMatrix(bool transposed) const
{
if (!_cache->matrix) {
_cache->matrix = getBlackMatrix();
}
if (transposed) {
if (!_cache->transposed) {
auto copy = std::make_shared<BitMatrix>(_cache->matrix->copy());
copy->rotate90();
_cache->transposed = std::move(copy);
}
return _cache->transposed.get();
}
return _cache->matrix.get();
}
void BinaryBitmap::invert()
{
if (_cache->matrix)
const_cast<BitMatrix*>(_cache->matrix.get())->flipAll();
if (_cache->transposed)
const_cast<BitMatrix*>(_cache->transposed.get())->flipAll();
_inverted = !_inverted;
}
template <typename F>
void SumFilter(const BitMatrix& in, BitMatrix& out, F func)
{
assert(in.height() >= 3);
const auto* in0 = in.row(0).begin();
const auto* in1 = in.row(1).begin();
const auto* in2 = in.row(2).begin();
for (auto *out1 = out.row(1).begin() + 1, *end = out.row(out.height() - 1).begin() - 1; out1 != end; ++in0, ++in1, ++in2, ++out1) {
int sum = 0;
for (int j = 0; j < 3; ++j)
sum += in0[j] + in1[j] + in2[j];
*out1 = func(sum);
}
}
void BinaryBitmap::close()
{
if (_cache->matrix) {
auto& matrix = *const_cast<BitMatrix*>(_cache->matrix.get());
BitMatrix tmp(matrix.width(), matrix.height());
// dilate
SumFilter(matrix, tmp, [](int sum) { return (sum > 0 * BitMatrix::SET_V) * BitMatrix::SET_V; });
// erode
SumFilter(tmp, matrix, [](int sum) { return (sum == 9 * BitMatrix::SET_V) * BitMatrix::SET_V; });
}
_cache->transposed.reset();
_closed = true;
}
} // ZXing