MCPcopy Create free account
hub / github.com/SpartanJ/eepp / loadImageAsync

Method loadImageAsync

src/eepp/ui/tools/uiimageviewer.cpp:100–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void UIImageViewer::loadImageAsync( std::string_view path, bool isContents, bool loadGallery ) {
101 if ( !getUISceneNode()->hasThreadPool() )
102 return;
103 mLoader->setVisible( true );
104 std::string ipath( path );
105
106 mLoading++;
107
108 getUISceneNode()->getThreadPool()->run( [path = std::move( ipath ), this, isContents,
109 loadGallery] {
110 ScopedOp op( [] {}, [this] { mLoading--; } );
111
112 auto folder( FileSystem::fileRemoveFileName( path ) );
113 FileSystem::dirAddSlashAtEnd( folder );
114 mHasGallery = false;
115 if ( loadGallery && !isContents ) {
116 Lock l( mGalleryMutex );
117 bool sameFolder = folder == mGalleryPath;
118 bool newFolder = false;
119 if ( !sameFolder && FileSystem::isDirectory( folder ) ) {
120 mHasGallery = true;
121 newFolder = true;
122 mGalleryPath = folder;
123 mGalleryFiles =
124 FileSystem::filesGetInPath( mGalleryPath, true, true, false, [this] {
125 return mGalleryLoaderShouldAbort.load();
126 } );
127 std::erase_if( mGalleryFiles, []( const std::string& filename ) {
128 return !Image::isImageExtension( filename );
129 } );
130 } else if ( sameFolder ) {
131 mHasGallery = true;
132 }
133
134 if ( sameFolder || newFolder ) {
135 auto fileName( FileSystem::fileNameFromPath( path ) );
136 auto it = std::find( mGalleryFiles.begin(), mGalleryFiles.end(), fileName );
137 if ( it != mGalleryFiles.end() ) {
138 mGalleryImageIndex = std::distance( mGalleryFiles.begin(), it );
139 } else {
140 mGalleryImageIndex = 0;
141 }
142 }
143 } else {
144 Lock l( mGalleryMutex );
145 mGalleryPath = folder;
146 mGalleryFiles = { FileSystem::fileNameFromPath( path ) };
147 mGalleryImageIndex = 0;
148 }
149
150 Image::Format format =
151 isContents ? Image::getFormat( reinterpret_cast<const unsigned char*>( path.c_str() ),
152 path.size() )
153 : Image::getFormat( path );
154
155 if ( format == Image::Format::Unknown )
156 return;
157

Callers 1

loadImageFromMediumMethod · 0.80

Calls 15

findFunction · 0.85
distanceFunction · 0.85
eeminFunction · 0.85
hasThreadPoolMethod · 0.80
c_strMethod · 0.80
createStaticMethod · 0.80
setAutoAnimateMethod · 0.80
NewFunction · 0.50
setVisibleMethod · 0.45
runMethod · 0.45
getThreadPoolMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected