StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
Loading...
Searching...
No Matches
watermark.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Multimedia.
5 *
6 * StormByte-Multimedia original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Multimedia source in this
20 * file. Third-party components — including FFmpeg and embedded trained data —
21 * remain under their own licenses and are not covered by the commercial grant.
22 *
23 * A written StormByte commercial agreement may license this original source
24 * on terms other than the LGPL, including specific use, distribution or
25 * linking arrangements such as static linking, as stated in that agreement.
26 * It does not grant rights to dependencies or waive their license conditions.
27 * Enabling WITH_GPL or WITH_NONFREE may include components with separate
28 * obligations for modification, linking (static or dynamic), redistribution
29 * or works that incorporate them. The person modifying, linking, packaging or
30 * distributing the resulting work is responsible for determining and meeting
31 * all applicable requirements, including any needed patent permissions.
32 * A StormByte commercial agreement does not provide those rights for GPL or
33 * nonfree components.
34 *
35 * Neither license grants any patent rights. Any patent licenses required
36 * to use this software or third-party components must be obtained separately
37 * from the patent holders.
38 *
39 * StormByte-Multimedia is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU Lesser General Public License for more details.
43 *
44 * You should have received a copy of the GNU Lesser General Public License
45 * version 3 along with StormByte-Multimedia. If not, see
46 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
47 *
48 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
49 */
50
51#pragma once
52
53#include <StormByte/logger/log.hxx>
60#include <StormByte/safe/binary.hxx>
61#include <StormByte/safe/optional.hxx>
62#include <StormByte/safe/pointers.hxx>
63#include <StormByte/safe/string.hxx>
64#include <StormByte/safe/vector.hxx>
65#include <StormByte/type_traits/safe.hxx>
66
67#include <cstdint>
68#include <string_view>
69
93
175 public:
180
195 StormByte::Safe::String logo, Anchor anchor,
196 unsigned opacity = 100, int margin = 0,
198
213 const StormByte::Safe::Binary& logo, Anchor anchor,
214 unsigned opacity = 100, int margin = 0,
216
232 unsigned opacity = 100,
234
248 const StormByte::Safe::Binary& logo,
250 unsigned opacity = 100,
252
257 Watermark(const Watermark& other) = delete;
258
263 Watermark(Watermark&& other) noexcept = delete;
264
268 ~Watermark() noexcept override;
269
275 Watermark& operator=(const Watermark& other) = delete;
276
282 Watermark& operator=(Watermark&& other) noexcept = delete;
283
287
292
297 enum StormByte::Multimedia::Type Media() const noexcept override;
298
302
303 protected:
308
312 void Clean() noexcept override;
313
321 void LastChance(const Pipeline::Frame& frame) noexcept override;
322
330 void Process(const Pipeline::Frame& frame) noexcept override;
331
335 void Setup() noexcept override;
336
340
341 private:
354 Watermark(StormByte::Safe::Shared<StormByte::Logger::Log> log,
355 StormByte::Safe::String path, const StormByte::Safe::Binary& logo,
356 StormByte::Safe::Optional<Anchor> anchor,
357 StormByte::Safe::Optional<StormByte::Multimedia::Property::Point> position,
358 unsigned opacity, int margin, bool binaryInput,
359 StormByte::Safe::Optional<StormByte::Multimedia::Property::Resolution> designedFor);
360
364 static constexpr std::uint8_t ProbeMax = 200;
365
370 bool DecodeLogo();
371
381 void DisableLogo(std::string_view why);
382
386 void DropScale() noexcept;
387
393 bool LoadFile(const StormByte::Safe::String& path);
394
400 const StormByte::Multimedia::FFmpeg::AVFrame* Luma(
401 const StormByte::Multimedia::FFmpeg::AVFrame& src);
402
408 void Paint();
409
416 bool Prepare(int frameW, int frameH);
417
423 bool EnsureLinear(const StormByte::Multimedia::FFmpeg::AVFrame& src);
424
432 bool Composite(const StormByte::Multimedia::FFmpeg::AVFrame& src, int x, int y);
433
439 void PaintLegacy(int x, int y);
440
446 bool ProbeBars(const StormByte::Multimedia::FFmpeg::AVFrame& src);
447
448 StormByte::Safe::Binary m_logo;
449 struct Svg;
450 StormByte::Safe::Unique<Svg> m_svg;
451 StormByte::Safe::Vector<std::uint8_t> m_rgba;
452 StormByte::Safe::Unique<StormByte::Multimedia::FFmpeg::AVFrame> m_luma;
453 StormByte::Safe::Optional<Anchor> m_anchor;
454 StormByte::Safe::Optional<StormByte::Multimedia::Property::Point> m_point;
455 unsigned m_opacity;
456 int m_margin;
457 StormByte::Safe::Optional<StormByte::Multimedia::Property::Resolution> m_designed;
458 StormByte::Safe::Vector<std::uint8_t> m_scaled;
459 StormByte::Safe::Unique<StormByte::Multimedia::FFmpeg::AVFrame> m_linear;
460 StormByte::Safe::Vector<float> m_blend;
461 StormByte::Safe::Vector<std::uint8_t> m_cover;
462 int m_scaledMargin;
463 int m_paintW;
464 int m_paintH;
465 int m_preparedW;
466 int m_preparedH;
467 int m_linearTrc;
468 int m_linearPri;
469 int m_linearMat;
470 int m_linearRange;
471 bool m_prepared;
472 bool m_linearReady;
473 bool m_legacyNoted;
474 int m_logoWidth;
475 int m_logoHeight;
476 bool m_decoded;
477 bool m_released;
478 int m_barTop;
479 int m_barBottom;
480 int m_barLeft;
481 int m_barRight;
482 int m_stable;
483 int m_lumaW;
484 int m_lumaH;
485 int m_lumaFmt;
486 };
487}
488
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
void Log(StormByte::Logger::Level level, std::string_view message) noexcept
Writes one log line on the scoped module logger.
FFmpeg(const FFmpeg &other)=delete
Copy is not allowed.
const StormByte::Multimedia::FFmpeg::AVFrame & AVFrame() const noexcept
Borrowed RAII handle of the current frame.
enum StormByte::Multimedia::Type Media() const noexcept override
Media this filter handles.
Watermark(StormByte::Safe::Shared< StormByte::Logger::Log > log, StormByte::Safe::String logo, StormByte::Multimedia::Property::Point position, unsigned opacity=100, StormByte::Safe::Optional< StormByte::Multimedia::Property::Resolution > designedFor={})
Logo at an absolute top-left.
Watermark(StormByte::Safe::Shared< StormByte::Logger::Log > log, StormByte::Safe::String logo, Anchor anchor, unsigned opacity=100, int margin=0, StormByte::Safe::Optional< StormByte::Multimedia::Property::Resolution > designedFor={})
Logo at an anchor on the active picture.
void Setup() noexcept override
Logs overlay configuration before processing video frames.
void Process(const Pipeline::Frame &frame) noexcept override
Detects anchor placement, then overlays the logo on video frames.
Watermark(StormByte::Safe::Shared< StormByte::Logger::Log > log, const StormByte::Safe::Binary &logo, StormByte::Multimedia::Property::Point position, unsigned opacity=100, StormByte::Safe::Optional< StormByte::Multimedia::Property::Resolution > designedFor={})
Logo bytes at an absolute top-left.
void LastChance(const Pipeline::Frame &frame) noexcept override
Hold ceiling: keep measured bars or zero them, then Release.
Watermark(StormByte::Safe::Shared< StormByte::Logger::Log > log, const StormByte::Safe::Binary &logo, Anchor anchor, unsigned opacity=100, int margin=0, StormByte::Safe::Optional< StormByte::Multimedia::Property::Resolution > designedFor={})
Logo bytes at an anchor on the active picture.
Watermark(Watermark &&other) noexcept=delete
Move constructor (deleted).
void Clean() noexcept override
Drops decoded logo and bar state from a previous run.
Watermark(const Watermark &other)=delete
Copy constructor (deleted).
One decoded access unit.
Definition frame.hxx:103
Integer 2D point (chromaticity / luminance pair).
Definition point.hxx:75
Multimedia module of the StormByte suite.
Pipeline Demux / decode / filter / encode / mux types.
Media property value types.
Video leaves (Process and Analytics).
Anchor
Logo placement relative to the active picture.
Definition watermark.hxx:82
@ TopRight
Top-right placement.
Definition watermark.hxx:85
@ Center
Centre placement.
Definition watermark.hxx:87
@ BottomRight
Bottom-right placement.
Definition watermark.hxx:91
@ TopCenter
Top-centre placement.
Definition watermark.hxx:84
@ BottomLeft
Bottom-left placement.
Definition watermark.hxx:89
@ CenterLeft
Centre-left placement.
Definition watermark.hxx:86
@ CenterRight
Centre-right placement.
Definition watermark.hxx:88
@ TopLeft
Top-left placement.
Definition watermark.hxx:83
@ BottomCenter
Bottom-centre placement.
Definition watermark.hxx:90
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61