From 871f7a8f5bc08b8371422ee388170167ad1536ea Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:01:28 +0800 Subject: [PATCH 1/8] merge --- src/pixelmatch/image_utils.cc | 8 ++++---- src/pixelmatch/image_utils.h | 6 +++--- src/pixelmatch/pixelmatch.cc | 24 ++++++++++++------------ src/pixelmatch/pixelmatch.h | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/pixelmatch/image_utils.cc b/src/pixelmatch/image_utils.cc index 67093f6..74ec434 100644 --- a/src/pixelmatch/image_utils.cc +++ b/src/pixelmatch/image_utils.cc @@ -9,7 +9,7 @@ namespace pixelmatch { -std::optional readRgbaImageFromPngFile(const char* filename) { +std::optional readRgbaImageFromPngFile(const char* filename) noexcept { int width, height, channels; auto data = stbi_load(filename, &width, &height, &channels, 4); if (!data) { @@ -23,7 +23,7 @@ std::optional readRgbaImageFromPngFile(const char* filename) { } bool writeRgbaPixelsToPngFile(const char* filename, span rgbaPixels, int width, - int height, size_t strideInPixels) { + int height, size_t strideInPixels) noexcept { struct Context { std::ofstream output; }; @@ -37,7 +37,7 @@ bool writeRgbaPixelsToPngFile(const char* filename, span rgbaPixe } stbi_write_png_to_func( - [](void* context, void* data, int len) { + [](void* context, void* data, int len) noexcept { Context* contextObj = reinterpret_cast(context); contextObj->output.write(static_cast(data), len); }, @@ -47,7 +47,7 @@ bool writeRgbaPixelsToPngFile(const char* filename, span rgbaPixe } bool imageEquals(span img1, span img2, int width, int height, - size_t strideInPixels) { + size_t strideInPixels) noexcept { // Check for identical images, respecting stride. for (int y = 0; y < height; ++y) { const size_t rowStartIndex = y * strideInPixels; diff --git a/src/pixelmatch/image_utils.h b/src/pixelmatch/image_utils.h index 2a49f7d..9ddd0a9 100644 --- a/src/pixelmatch/image_utils.h +++ b/src/pixelmatch/image_utils.h @@ -22,7 +22,7 @@ struct Image { * @param filename Filename to load. * @return std::optional containing the image, or std::nullopt if the file could not be read. */ -std::optional readRgbaImageFromPngFile(const char* filename); +std::optional readRgbaImageFromPngFile(const char* filename) noexcept; /** * Save an image as a PNG file. @@ -35,7 +35,7 @@ std::optional readRgbaImageFromPngFile(const char* filename); * @return true If the image was successfully saved. */ bool writeRgbaPixelsToPngFile(const char* filename, span rgbaPixels, int width, - int height, size_t strideInPixels); + int height, size_t strideInPixels) noexcept; /** * Returns true if two images are bit-identical. @@ -49,6 +49,6 @@ bool writeRgbaPixelsToPngFile(const char* filename, span rgbaPixe * @return true If the image is bit-identical. */ bool imageEquals(span img1, span img2, int width, int height, - size_t strideInPixels); + size_t strideInPixels) noexcept; } // namespace pixelmatch diff --git a/src/pixelmatch/pixelmatch.cc b/src/pixelmatch/pixelmatch.cc index 06bd218..68255e5 100644 --- a/src/pixelmatch/pixelmatch.cc +++ b/src/pixelmatch/pixelmatch.cc @@ -11,15 +11,15 @@ namespace { static constexpr size_t kPixelBytes = 4; -inline float rgb2y(uint8_t r, uint8_t g, uint8_t b) { +inline float rgb2y(uint8_t r, uint8_t g, uint8_t b) noexcept { return r * 0.29889531f + g * 0.58662247f + b * 0.11448223f; } -inline float rgb2i(uint8_t r, uint8_t g, uint8_t b) { +inline float rgb2i(uint8_t r, uint8_t g, uint8_t b) noexcept { return r * 0.59597799f - g * 0.27417610f - b * 0.32180189f; } -inline float rgb2q(uint8_t r, uint8_t g, uint8_t b) { +inline float rgb2q(uint8_t r, uint8_t g, uint8_t b) noexcept { return r * 0.21147017f - g * 0.52261711f + b * 0.31114694f; } @@ -30,7 +30,7 @@ inline float rgb2q(uint8_t r, uint8_t g, uint8_t b) { * @param alpha The alpha value of the color, between 0 and 1. * @return The blended color. */ -inline uint8_t blend(uint8_t c, float a) { +inline uint8_t blend(uint8_t c, float a) noexcept { return static_cast(255.0f + (static_cast(c) - 255.0f) * a); } @@ -48,7 +48,7 @@ inline uint8_t blend(uint8_t c, float a) { * or darkens (positive if img2 lightens). Returns 0 if the pixels are identical. */ float colorDelta(span img1, span img2, size_t pos1, size_t pos2, - bool yOnly) { + bool yOnly) noexcept { uint8_t r1 = img1[pos1 + 0]; uint8_t g1 = img1[pos1 + 1]; uint8_t b1 = img1[pos1 + 2]; @@ -133,7 +133,7 @@ bool hasManySiblings(span img, int x1, int y1, int width, int hei * based on "Anti-aliased Pixel and Intensity Slope Detector" paper by V. Vysniauskas, 2009 */ bool antialiased(span img, int x1, int y1, int width, int height, - size_t strideInPixels, span img2) { + size_t strideInPixels, span img2) noexcept { const int x0 = std::max(x1 - 1, 0); const int y0 = std::max(y1 - 1, 0); const int x2 = std::min(x1 + 1, width - 1); @@ -194,14 +194,14 @@ bool antialiased(span img, int x1, int y1, int width, int height, hasManySiblings(img2, maxX, maxY, width, height, strideInPixels)); } -inline void drawPixel(span output, size_t pos, Color color) { +inline void drawPixel(span output, size_t pos, Color color) noexcept { output[pos + 0] = color.r; output[pos + 1] = color.g; output[pos + 2] = color.b; output[pos + 3] = color.a; } -void drawGrayPixel(span img, size_t pos, float alpha, span output) { +void drawGrayPixel(span img, size_t pos, float alpha, span output) noexcept { const uint8_t r = img[pos + 0]; const uint8_t g = img[pos + 1]; const uint8_t b = img[pos + 2]; @@ -212,7 +212,7 @@ void drawGrayPixel(span img, size_t pos, float alpha, span img1, span img2, span output, int width, - int height, size_t strideInPixels, Options options) { + int height, size_t strideInPixels, Options options) noexcept { // In release builds, return -1 if a precondition fails since the asserts will not trigger. if (width <= 0 || height <= 0 || strideInPixels < static_cast(width)) { assert(width > 0); @@ -290,9 +290,9 @@ int pixelmatch(span img1, span img2, span } else { // Found substantial difference not caused by anti-aliasing; draw it as such. if (!output.empty()) { - drawPixel( - output, pos, - delta < 0.0f && options.diffColorAlt ? *options.diffColorAlt : options.diffColor); + drawPixel(output, pos, + delta < 0.0f && options.diffColorAlt ? options.diffColorAlt.value() + : options.diffColor); } diff++; } diff --git a/src/pixelmatch/pixelmatch.h b/src/pixelmatch/pixelmatch.h index 7e95f85..249d0a4 100644 --- a/src/pixelmatch/pixelmatch.h +++ b/src/pixelmatch/pixelmatch.h @@ -18,10 +18,10 @@ using span = std::span; template class span { public: - constexpr span() = default; - ~span() = default; + constexpr span() noexcept = default; + ~span() noexcept = default; - constexpr span(T* data, size_t size) : data_(data), size_(size) {} + constexpr span(T* data, size_t size) noexcept : data_(data), size_(size) {} template ().data())> (*)[], T (*)[]>::value, int> = 0> - constexpr span(Container& container) : span(container.data(), container.size()) {} + constexpr span(Container& container) noexcept : span(container.data(), container.size()) {} - span(const span&) = default; - span& operator=(const span&) = default; + span(const span&) noexcept = default; + span& operator=(const span&) noexcept = default; - const T* data() const { return data_; } - size_t size() const { return size_; } + const T* data() const noexcept { return data_; } + size_t size() const noexcept { return size_; } bool empty() const { return size_ == 0; } - T operator[](size_t index) const { return data_[index]; } - T& operator[](size_t index) { return data_[index]; } + T operator[](size_t index) const noexcept { return data_[index]; } + T& operator[](size_t index) noexcept { return data_[index]; } private: T* data_ = nullptr; @@ -92,6 +92,6 @@ struct Options { * fails, returns -1. */ int pixelmatch(span img1, span img2, span output, int width, - int height, size_t strideInPixels, Options options = Options()); + int height, size_t strideInPixels, Options options = Options()) noexcept; } // namespace pixelmatch From f7f7e619d89132c80d4a29b71762d7596511f183 Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:01:45 +0800 Subject: [PATCH 2/8] lint code --- src/pixelmatch/pixelmatch.cc | 3 ++- viewer.py | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/pixelmatch/pixelmatch.cc b/src/pixelmatch/pixelmatch.cc index 68255e5..666f3cc 100644 --- a/src/pixelmatch/pixelmatch.cc +++ b/src/pixelmatch/pixelmatch.cc @@ -201,7 +201,8 @@ inline void drawPixel(span output, size_t pos, Color color) noexcept { output[pos + 3] = color.a; } -void drawGrayPixel(span img, size_t pos, float alpha, span output) noexcept { +void drawGrayPixel(span img, size_t pos, float alpha, + span output) noexcept { const uint8_t r = img[pos + 0]; const uint8_t g = img[pos + 1]; const uint8_t b = img[pos + 2]; diff --git a/viewer.py b/viewer.py index 69c7aed..de35ab6 100644 --- a/viewer.py +++ b/viewer.py @@ -1,16 +1,18 @@ from __future__ import annotations + +import json +import os +import sys import tkinter as tk -from PIL import ImageGrab, ImageTk, Image -import time -import numpy as np +from functools import lru_cache + import cv2 import mss -from functools import lru_cache +import numpy as np from loguru import logger -from pybind11_pixelmatch import write_image, read_image -import json -import sys -import os +from PIL import Image, ImageGrab, ImageTk + +from pybind11_pixelmatch import read_image, write_image class ScreenMonitor: @@ -152,7 +154,7 @@ def load_config(self): if not path or not os.path.exists(path): return False logger.info(f"加载配置 {path}") - with open(path, "r") as f: + with open(path) as f: config = json.load(f) self.monitor_areas = config.get("monitor_areas", []) self.show_original.set(config.get("show_original", True)) @@ -199,7 +201,7 @@ def select_area(self): self.__destroy_overlay() curr_geom = self.root.winfo_geometry() curr_geom = self.root.winfo_geometry() - x, y = [int(x) for x in curr_geom.split("+")[-2:]] + x, y = (int(x) for x in curr_geom.split("+")[-2:]) w, h, x, y = which_monitor(x, y) overlay = tk.Toplevel(self.root) @@ -595,7 +597,7 @@ def diff_image_options( Returns: dict: Options for image difference visualization """ - from pybind11_pixelmatch import normalize_color, Options + from pybind11_pixelmatch import Options, normalize_color options = Options() options.threshold = threshold From d3441c0163a08bcaa322eac69754c6e7d81ecedd Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:04:28 +0800 Subject: [PATCH 3/8] fix lint --- viewer.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/viewer.py b/viewer.py index de35ab6..4cb4b7b 100644 --- a/viewer.py +++ b/viewer.py @@ -1,10 +1,10 @@ from __future__ import annotations import json -import os import sys import tkinter as tk from functools import lru_cache +from pathlib import Path import cv2 import mss @@ -16,7 +16,7 @@ class ScreenMonitor: - def __init__(self, root, config_path: str = None): + def __init__(self, root, config_path: str | None = None): self.root = root self.root.title("屏幕对比查看器") self.root.geometry("600x500") @@ -151,10 +151,10 @@ def __init__(self, root, config_path: str = None): def load_config(self): path = self.config_path - if not path or not os.path.exists(path): + if not path or not Path(path).exists(): return False logger.info(f"加载配置 {path}") - with open(path) as f: + with Path(path).open() as f: config = json.load(f) self.monitor_areas = config.get("monitor_areas", []) self.show_original.set(config.get("show_original", True)) @@ -172,9 +172,9 @@ def save(self): write_image(path, img) logger.info(f"保存图片 {path}") if self.config_path: - path = os.path.abspath(self.config_path) - os.makedirs(os.path.dirname(path), exist_ok=True) - with open(path, "w") as f: + path = Path(self.config_path).resolve() + path.parent.mkdir(parents=True, exist_ok=True) + with path.open("w") as f: json.dump( { "monitor_areas": self.monitor_areas, @@ -261,7 +261,7 @@ def on_release(self, event): x0, x1 = sorted([self.start_x, self.end_x]) y0, y1 = sorted([self.start_y, self.end_y]) if x1 - x0 < 40 or y1 - y0 < 40: - logger.warning(f"窗口太小,忽略: {x1 - x0}x{y1 - y0}") + logger.warning(f"窗口太小,忽略: {x1 - x0}x{y1 - y0}") return area = (ax + x0, ay + y0, ax + x1, ay + y1) self.monitor_areas.append(area) @@ -355,7 +355,7 @@ def resize_and_display_images(self): stacked_img, (stacked_img.shape[1] // 2, stacked_img.shape[0] // 2) ) stacked_img = np.vstack((stacked_img, diff)) - # TODO,横着放 + # TODO,横着放 else: stacked_img = diff original_height, original_width = stacked_img.shape[:2] @@ -388,7 +388,7 @@ def update_monitor(self): def shift_image(self, img1, img2, sx, sy): """ - 如果 sx, sy 为 0,说明 img1 和 img2 是对齐的 + 如果 sx, sy 为 0,说明 img1 和 img2 是对齐的 现在需要 img 偏移 sx,sy 能够和 img2 对齐 请对齐并 crop 两个图片 """ @@ -424,7 +424,8 @@ def which_monitor(x, y) -> tuple[int, int, int, int]: h = m["height"] if x0 <= x <= x0 + w and y0 <= y <= y0 + h: return w, h, x0, y0 - raise Exception("无法确认窗口所在显示器") + msg = "无法确认窗口所在显示器" + raise Exception(msg) def img2gray(img: np.ndarray) -> np.ndarray: @@ -435,8 +436,7 @@ def img2gray(img: np.ndarray) -> np.ndarray: return img if img.shape[2] == 3: return cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) - else: - return cv2.cvtColor(img, cv2.COLOR_RGBA2GRAY) + return cv2.cvtColor(img, cv2.COLOR_RGBA2GRAY) def img2rgb(img: np.ndarray) -> np.ndarray: @@ -448,7 +448,7 @@ def img2rgb(img: np.ndarray) -> np.ndarray: def split_image(img: np.ndarray) -> tuple[int, np.ndarray, np.ndarray]: """ - img 是左右两张图片拼接而成,需要找到左右的分界线,使得图片能较好地分割为两部分 + img 是左右两张图片拼接而成,需要找到左右的分界线,使得图片能较好地分割为两部分. Split an image that contains two images side by side. This function attempts to find the boundary between two images that are @@ -665,19 +665,19 @@ def diff_image( if __name__ == "__main__": """ - 安装: + 安装: pip install loguru mss opencv-python pillow>=8.0.0 pybind11-pixelmatch 使用 - 打开界面后,有三种使用流程: + 打开界面后,有三种使用流程: 1. 画框监听 - - 点击选择区域,在当前显示器画一个框(会自动分为左右两块区域,做 diff) - - 点击选择区域,画一个框,操作两次(会 diff 这两块区域) - 2. 传入图片查看 diff(和上面的框类似,直接传入图片) + - 点击选择区域,在当前显示器画一个框(会自动分为左右两块区域,做 diff) + - 点击选择区域,画一个框,操作两次(会 diff 这两块区域) + 2. 传入图片查看 diff(和上面的框类似,直接传入图片) - python3 main.py img.png - python3 main.py img1.png img2.png 3. 加载配置启动 - - python3 main.py config.json,点击保存则会存储配置 + - python3 main.py config.json,点击保存则会存储配置 """ root = tk.Tk() root.iconbitmap("favicon.ico") From c4779d34f790a7157ca5cebc6fe12b9f4782c925 Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:07:56 +0800 Subject: [PATCH 4/8] fix --- src/pybind11_pixelmatch/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pybind11_pixelmatch/__init__.py b/src/pybind11_pixelmatch/__init__.py index 67702ce..44c01a0 100644 --- a/src/pybind11_pixelmatch/__init__.py +++ b/src/pybind11_pixelmatch/__init__.py @@ -23,7 +23,7 @@ def read_image(path): A = np.ones(B.shape, dtype=B.dtype) * 255 img = cv2.merge((R, G, B, A)) elif img.shape[2] == 4: - img = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA) + img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA) return img From c83217cdb0d219cc28cea5935abbcf29178d927b Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:09:27 +0800 Subject: [PATCH 5/8] update github actions --- .github/workflows/format.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/pip.yml | 18 +++++++++++++++++- .github/workflows/wheels.yml | 36 +++++++++++++++++++++++++++--------- 3 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..6b8cba1 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,29 @@ +# This is a format job. Pre-commit has a first-party GitHub action, so we use +# that: https://github.com/pre-commit/action + +name: Format + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.9" + - name: Cache pre-commit + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + pre-commit- + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 5e79292..c99b969 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -20,12 +20,28 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + allow-prereleases: true + + - name: Get pip cache dir + id: pip-cache + shell: bash + run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT + + - name: Cache pip dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.python-version }}- + ${{ runner.os }}-pip- - name: Build and install run: pip install --verbose .[test] - name: Test + if: ${{ startsWith(matrix.platform, 'ubuntu') }} run: pytest diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 62a8cdb..b7253ab 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -32,8 +32,9 @@ jobs: - name: Check metadata run: pipx run twine check dist/* - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: cibw-sdist path: dist/*.tar.gz @@ -43,18 +44,30 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-14] steps: - uses: actions/checkout@v4 with: submodules: true - - uses: pypa/cibuildwheel@v2.16 + - name: Cache cibuildwheel + uses: actions/cache@v4 + with: + path: | + ~/Library/Caches/pip + ~/.cache/pip + ~/AppData/Local/pip/Cache + key: cibw-pip-${{ matrix.os }}-${{ hashFiles('pyproject.toml') }} + restore-keys: | + cibw-pip-${{ matrix.os }}- + + - uses: pypa/cibuildwheel@v3.3.1 env: CIBW_ARCHS_MACOS: universal2 - CIBW_ARCHS_WINDOWS: auto ARM64 - CIBW_TEST_SKIP: "*macosx* *win* *aarch64 cp31* pp* *musllinux*" + CIBW_ARCHS_WINDOWS: AMD64 ARM64 + CIBW_SKIP: "pp* *musllinux* *_i686 cp314t-win*" + CIBW_TEST_SKIP: "*macosx* *win* *aarch64 cp314t-*" CIBW_ENVIRONMENT: "PIP_ONLY_BINARY=:all:" # CIBW_BEFORE_BUILD: "pip install --prefer-binary fire numpy opencv-python" @@ -62,8 +75,9 @@ jobs: run: git diff --exit-code shell: bash - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: cibw-wheels-${{ matrix.os }} path: wheelhouse/*.whl @@ -72,15 +86,19 @@ jobs: needs: [build_wheels, build_sdist] runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' + environment: pypi + permissions: + id-token: write steps: - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: artifact + pattern: cibw-* + merge-multiple: true path: dist - uses: pypa/gh-action-pypi-publish@release/v1 From d97816294eccd317278b0ff911fd3e1a90b25e40 Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:10:44 +0800 Subject: [PATCH 6/8] fix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c3b8e23..0cb26b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "scikit_build_core.build" [project] name = "pybind11_pixelmatch" -version = "0.1.3" +version = "0.1.4" description="A C++17 port of the JavaScript pixelmatch library (with python binding), providing a small pixel-level image comparison library." readme = "README.md" authors = [ From 43604a322b29374e9f3d4a99cec8a33b883efcce Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:13:27 +0800 Subject: [PATCH 7/8] clean up --- BUILD.bazel | 31 ------------- WORKSPACE | 46 ------------------- external | 1 - renovate.json | 20 -------- .../pybind11_pixelmatch/viewer.py | 0 tools/coverage.sh | 11 ----- 6 files changed, 109 deletions(-) delete mode 100644 BUILD.bazel delete mode 100644 WORKSPACE delete mode 120000 external delete mode 100644 renovate.json rename viewer.py => src/pybind11_pixelmatch/viewer.py (100%) delete mode 100755 tools/coverage.sh diff --git a/BUILD.bazel b/BUILD.bazel deleted file mode 100644 index 2c9b14e..0000000 --- a/BUILD.bazel +++ /dev/null @@ -1,31 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library") - -cc_library( - name = "pixelmatch-cpp17", - srcs = [ - "src/pixelmatch/pixelmatch.cc", - ], - hdrs = [ - "src/pixelmatch/pixelmatch.h", - ], - includes = ["src"], - visibility = ["//visibility:public"], -) - -# Optional library containing utils to save and load images with stb_image. -cc_library( - name = "image_utils", - srcs = [ - "src/pixelmatch/image_utils.cc", - ], - hdrs = [ - "src/pixelmatch/image_utils.h", - ], - includes = ["src"], - visibility = ["//visibility:public"], - deps = [ - "//:pixelmatch-cpp17", - "@stb//:image", - "@stb//:image_write", - ], -) diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index e5c3785..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,46 +0,0 @@ -load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -## -## Third-party dependencies. -## - -git_repository( - name = "com_google_gtest", - remote = "https://github.com/google/googletest", - tag = "v1.14.0", -) - -load("@com_google_gtest//:googletest_deps.bzl", "googletest_deps") - -googletest_deps() - -git_repository( - name = "stb", - branch = "master", - init_submodules = True, - remote = "https://github.com/nitronoid/rules_stb", -) - -## -## Fuzzer dependencies. -## - -http_archive( - name = "rules_fuzzing", - sha256 = "ff52ef4845ab00e95d29c02a9e32e9eff4e0a4c9c8a6bcf8407a2f19eb3f9190", - strip_prefix = "rules_fuzzing-0.4.1", - urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.4.1.zip"], -) - -load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") - -rules_fuzzing_dependencies() - -load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init") - -rules_fuzzing_init() - -load("@fuzzing_py_deps//:requirements.bzl", "install_deps") - -install_deps() diff --git a/external b/external deleted file mode 120000 index 3ee3af6..0000000 --- a/external +++ /dev/null @@ -1 +0,0 @@ -bazel-out/../../../external \ No newline at end of file diff --git a/renovate.json b/renovate.json deleted file mode 100644 index d2d9b52..0000000 --- a/renovate.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ], - "labels": [ - "bot" - ], - "schedule": [ - "on the 1st through 7th day of the month" - ], - "packageRules": [ - { - "packagePatterns": [ - "^com_google_absl$" - ], - "enabled": false - } - ] -} diff --git a/viewer.py b/src/pybind11_pixelmatch/viewer.py similarity index 100% rename from viewer.py rename to src/pybind11_pixelmatch/viewer.py diff --git a/tools/coverage.sh b/tools/coverage.sh deleted file mode 100755 index f382cb3..0000000 --- a/tools/coverage.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -e -cd "$(dirname "$0")/.." - -JAVA_HOME=$(dirname $(dirname $(which java))) - -bazel coverage -s --nocache_test_results //... - -genhtml bazel-out/_coverage/_coverage_report.dat \ - --highlight \ - --legend \ - --output-directory coverage-report From 0f43205535ba837ce561a428557596b72a367e67 Mon Sep 17 00:00:00 2001 From: TANG ZHIXIONG Date: Thu, 12 Feb 2026 00:20:51 +0800 Subject: [PATCH 8/8] fix CI --- src/pixelmatch/pixelmatch.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pixelmatch/pixelmatch.cc b/src/pixelmatch/pixelmatch.cc index 666f3cc..41d6c50 100644 --- a/src/pixelmatch/pixelmatch.cc +++ b/src/pixelmatch/pixelmatch.cc @@ -291,9 +291,9 @@ int pixelmatch(span img1, span img2, span } else { // Found substantial difference not caused by anti-aliasing; draw it as such. if (!output.empty()) { - drawPixel(output, pos, - delta < 0.0f && options.diffColorAlt ? options.diffColorAlt.value() - : options.diffColor); + drawPixel( + output, pos, + delta < 0.0f && options.diffColorAlt ? *options.diffColorAlt : options.diffColor); } diff++; }