libopencv_imgproc grew noticeably with the HarfBuzz-based text engine. Measured on
macOS/arm64 (clang, Release, stripped) the text-related part of the library was
~830 KB: HarfBuzz 486 KB, the two Rubik fonts 296 KB, the engine ~25 KB, plus ~2 MB
of WenQuanYi when WITH_UNIFONT=ON (the previous default). With GCC and an unstripped
.so on Linux the HarfBuzz part alone is 700+ KB.
This patch brings it down to ~550 KB by default (HarfBuzz 377 KB + Rubik 146 KB +
engine 30 KB) without dropping functionality:
* 3rdparty/harfbuzz: build with -Os -fno-exceptions -fno-rtti -fno-threadsafe-statics
(like HarfBuzz's own build; shaping speed is irrelevant thanks to the glyph cache)
and HB_NO_VAR_COMPOSITES (VARC table, a 2024 format with no real fonts yet).
Variable-font support (wght axis etc.) is untouched. -22% of HarfBuzz code.
* Only the "sans" font (Rubik) is compiled into imgproc by default. Rubik Italic and
WenQuanYi Micro Hei became optional: WITH_ITALICFONT (new) and WITH_UNIFONT are
both OFF now. The build summary lists the built-in fonts.
* New API cv::FontFace::setBuiltinFont(name, path) fills or replaces any of the
three built-in slots ("sans", "italic", "uni") with an external font file. The
registered font takes part in the automatic fallback chain exactly like a
compiled-in one, so users can get CJK text or a true italic without rebuilding
OpenCV. The registry is process-wide; each thread's engine reloads its slots
lazily (generation counter), and the glyph cache is dropped on reload since
hb_font pointers are part of its key.
* "italic" resolves to "sans" when no italic font is built in or registered, so
FONT_ITALIC / FONT_HERSHEY_SCRIPT_* in the legacy putText keep working (upright).
* Fix: a character not covered by any font used to be drawn as '?' taken from the
last built-in slot, which can be empty now; the '?' is looked up like any other
character (user font first).
* Tests: opencv_test_imgproc registers Rubik-Italic.ttf.gz and
WenQuanYiMicroHei.ttf.gz from opencv_extra (testdata/highgui/drawing) as the
"italic"/"uni" slots, so Drawing.ttf_text reproduces the reference picture 1:1
with the default build and the legacy hershey-font tests are unchanged.
Drawing.builtin_font_slots covers the new API. Tests skip if the fonts are absent.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Add HPX backend for OpenCV implementation
Adds hpx backend for cv::parallel_for_() calls respecting the nstripes chunking parameter. C++ code for the backend is added to modules/core/parallel.cpp. Also, the necessary changes to cmake files are introduced.
Backend can operate in 2 versions (selectable by cmake build option WITH_HPX_STARTSTOP): hpx (runtime always on) and hpx_startstop (start and stop the backend for each cv::parallel_for_() call)
* WIP: Conditionally include hpx_main.hpp to tests in core module
Header hpx_main.hpp is included to both core/perf/perf_main.cpp and core/test/test_main.cpp.
The changes to cmake files for linking hpx library to above mentioned test executalbles are proposed but have issues.
* Add coditional iclusion of hpx_main.hpp to cpp cpu modules
* Remove start/stop version of hpx backend
- removed tr1 usage (dropped in C++17)
- moved includes of vector/map/iostream/limits into ts.hpp
- require opencv_test + anonymous namespace (added compile check)
- fixed norm() usage (must be from cvtest::norm for checks) and other conflict functions
- added missing license headers