Files
utun2/tools/chatgui/zxing-cpp/core/src/ThresholdBinarizer.h
T
evgeny 38c9f229bc stcp: ed25519 pubkey exchange in handshake, fix instance destroy segfault, fix chat_tcp_test
- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll
- stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close
- utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP),
  add deferred drain in both Phase J and L
- stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39,
  exchange ed25519_pubkey in both handshake directions
- etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in
  etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb
- chat_sync.c: fix lk->conn NULL dereference for TCP links
- test_stcp.c: update stcp_server_create/stcp_client_connect callsites
- tools/chat_tcp_test: change transport udp→tcp
2026-08-07 00:48:27 +03:00

59 lines
1.3 KiB
C++

/*
* Copyright 2020 Axel Waggershauser
*/
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "BinaryBitmap.h"
#include "BitMatrix.h"
#include <cstdint>
namespace ZXing {
class ThresholdBinarizer : public BinaryBitmap
{
const uint8_t _threshold = 0;
public:
ThresholdBinarizer(const ImageView& buffer, uint8_t threshold = 128) : BinaryBitmap(buffer), _threshold(threshold) {}
bool getPatternRow(int row, int rotation, PatternRow& res) const override
{
auto buffer = _buffer.rotated(rotation);
const int stride = buffer.pixStride();
const uint8_t* begin = buffer.data(0, row) + GreenIndex(buffer.format());
const uint8_t* end = begin + buffer.width() * stride;
auto* lastPos = begin;
bool lastVal = false;
res.clear();
for (const uint8_t* p = begin; p != end; p += stride) {
bool val = *p <= _threshold;
if (val != lastVal) {
res.push_back(narrow_cast<PatternRow::value_type>((p - lastPos) / stride));
lastVal = val;
lastPos = p;
}
}
res.push_back(narrow_cast<PatternRow::value_type>((end - lastPos) / stride));
if (*(end - stride) <= _threshold)
res.push_back(0); // last value is number of white pixels, here 0
return true;
}
std::shared_ptr<const BitMatrix> getBlackMatrix() const override
{
return std::make_shared<const BitMatrix>(binarize(_threshold));
}
};
} // ZXing