Skip to content

Commit

Permalink
dev: refactor the collage finished method.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin42 committed Feb 9, 2025
1 parent 1b0177a commit 5c469b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions PB/include/pb/image/ImageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ImageFactory final {
std::shared_ptr<DurableHashService> durableHashService);

std::shared_ptr<RegularImageV2> createRegularImage(Path path);
std::shared_ptr<RegularImageV2> createRegularImage(std::string hash);
std::shared_ptr<TextImageV2> createTextImage(Path path, std::string hash);

GenericImagePtr createImage(Path path);
Expand Down
18 changes: 2 additions & 16 deletions PB/src/CollageMakerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ void CollageMakerJob::onTaskFinished(PBDev::MapReducerTaskId reducerTaskId)
if (mCollagePath.find(reducerTaskId) != mCollagePath.end()) {
PBDev::basicAssert(mProject != nullptr);

auto coreHash = mDurableHashService->getHash(
PBDev::ProjectId(mProject->first), mCollagePath.at(reducerTaskId));

auto imageHash =
mPlatformInfo->thumbnailByHash(mProject->first, coreHash, ".jpg");

auto newHash = boost::uuids::to_string(boost::uuids::random_generator()());

auto maybeNewHash = ThumbnailsTask::createThumbnailsByPath(
Expand All @@ -122,17 +116,9 @@ void CollageMakerJob::onTaskFinished(PBDev::MapReducerTaskId reducerTaskId)
auto newImage =
mImageFactory->createRegularImage(mCollagePath.at(reducerTaskId));

std::function<void(unsigned, unsigned)> onFinished =
[this, newImage{newImage}](unsigned width, unsigned height) {
mListener->onCollageCreated(newImage);
};

ImportImageTask importImageTask(
newImage->full(), newImage->medium(), newImage->smaLL(), onFinished,
mPlatformInfo->screenSize.first, mPlatformInfo->screenSize.second,
std::stop_source().get_token());
spdlog::info("Collage created {}", newImage->full().string());

importImageTask();
mListener->onCollageCreated(newImage);
}
}

Expand Down
5 changes: 5 additions & 0 deletions PB/src/ImageFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ std::shared_ptr<RegularImageV2> ImageFactory::createRegularImage(Path path)
return regularImage;
}

std::shared_ptr<RegularImageV2> ImageFactory::createRegularImage(std::string hash)
{
return std::make_shared<RegularImageV2>(hash, Path());
}

std::shared_ptr<TextImageV2> ImageFactory::createTextImage(Path path,
std::string hash)
{
Expand Down

0 comments on commit 5c469b5

Please sign in to comment.