载入中...
搜索中...
未找到
UvPaintSession.cpp
浏览该文件的文档.
2
3#include "image/ImageData.h"
4
5namespace eve::image {
6 // namespace
7
10
12 if (image.getFormat() != "RGBA8")
13 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Unsupported, "UV painting requires RGBA8 pixels", "image", {}, "image.uvPaintSession"));
14 original_ = std::make_unique<ImageData>(image);
15 current_ = std::make_unique<ImageData>(image);
16 undo_.clear();
17 ++revision_;
18 return Result<void>::success();
19}
20
21Result<UvPaintReceipt> UvPaintSession::paintCircleResult(float u, float v, float radiusPixels, float r, float g,
22 float b, float a, bool wrapU, bool wrapV) {
23 if (!current_)
25 "UV paint session is not initialized", "session", {},
26 "image.uvPaintSession"));
27 auto candidate = std::make_unique<ImageData>(*current_);
28 auto painted = candidate->paintCircleUv(u, v, radiusPixels, ImageData::Colorf{r, g, b, a}, wrapU, wrapV);
29 if (!painted.ok()) return painted;
30 undo_.push_back(std::move(current_));
31 if (undo_.size() > 32u) undo_.erase(undo_.begin());
32 current_ = std::move(candidate);
33 ++revision_;
34 return painted;
35}
36
38 if (!current_)
39 return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "UV paint session is not initialized", "session", {}, "image.uvPaintSession"));
40 if (undo_.empty()) return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "UV paint undo history is empty", "undo", {}, "image.uvPaintSession"));
41 current_ = std::move(undo_.back());
42 undo_.pop_back();
43 ++revision_;
44 return Result<void>::success();
45}
46
48 if (!original_)
49 return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "UV paint session is not initialized", "session", {}, "image.uvPaintSession"));
50 current_ = std::make_unique<ImageData>(*original_);
51 undo_.clear();
52 ++revision_;
53 return Result<void>::success();
54}
55
57 if (!current_)
58 return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "UV paint session is not initialized", "session", {}, "image.uvPaintSession"));
59 original_ = std::make_unique<ImageData>(*current_);
60 undo_.clear();
61 ++revision_;
62 return Result<void>::success();
63}
64
66 if (!current_)
68 "UV paint session is not initialized",
69 "session", {}, "image.uvPaintSession"));
70 return Result<std::unique_ptr<ImageData>>::success(std::make_unique<ImageData>(*current_));
71}
72
74 if (!current_)
75 return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "UV paint session is not initialized", "session", {}, "image.uvPaintSession"));
76 ImageData replacement(*current_);
77 destination.adopt(replacement);
78 return Result<void>::success();
79}
80
81} // namespace eve::image
tensor::Graph g
Definition GpuGraph.cpp:7
vk::UniqueImage image
float u
Definition Grass.cpp:233
double r
float v
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Represents raw pixel data.
Definition ImageData.h:38
medialoader::Colorf Colorf
Definition ImageData.h:41
void adopt(eve::Resource &replacement) override
Replace this instance's pixels with replacement's (cache reload). The replacement is drained; its des...
Definition ImageData.cpp:62
Result< void > undoResult()
Restore the previous committed paint transaction.
Result< std::unique_ptr< ImageData > > currentImageResult() const
Return a caller-owned current pixel snapshot.
Result< void > initializeResult(const ImageData &image)
Initialize with an owning RGBA8 copy and clear history.
UvPaintSession()
Uv paint session.
Result< void > copyCurrentToResult(ImageData &destination) const
Atomically copy current pixels into caller-owned RGBA8 storage.
Result< UvPaintReceipt > paintCircleResult(float u, float v, float radiusPixels, float r, float g, float b, float a, bool wrapU=false, bool wrapV=false)
Paint one circular UV brush as a single undoable transaction.
~UvPaintSession()
Uv paint session.
Result< void > restoreResult()
Restore the initial/baked pixels and clear history.
Result< void > bakeResult()
Make current pixels the new restore point and clear history.