MCPcopy Create free account
hub / github.com/aiekick/ImGuiFileDialog / m_ThreadThumbnailFileDatasExtractionFunc

Method m_ThreadThumbnailFileDatasExtractionFunc

ImGuiFileDialog.cpp:2940–3003  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2938}
2939
2940void IGFD::ThumbnailFeature::m_ThreadThumbnailFileDatasExtractionFunc() {
2941 m_CountFiles = 0U;
2942 m_IsWorking = true;
2943 // infinite loop while is thread working
2944 while (m_IsWorking) {
2945 std::unique_lock<std::mutex> thumbnailFileDatasToGetLock(m_ThumbnailFileDatasToGetMutex);
2946 m_ThumbnailFileDatasToGetCv.wait(thumbnailFileDatasToGetLock);
2947 if (!m_ThumbnailFileDatasToGet.empty()) {
2948 std::shared_ptr<FileInfos> file = nullptr;
2949 // get the first file in the list
2950 file = (*m_ThumbnailFileDatasToGet.begin());
2951 m_ThumbnailFileDatasToGet.pop_front();
2952 thumbnailFileDatasToGetLock.unlock();
2953 // retrieve datas of the texture file if its an image file
2954 if (file.use_count()) {
2955 if (file->fileType.isFile()) { //-V522
2956 //|| file->fileExtLevels == ".hdr" => format float so in few times
2957 if (file->SearchForExts(".png,.bmp,.tga,.jpg,.jpeg,.gif,.psd,.pic,.ppm,.pgm", true)) {
2958 auto fpn = file->filePath + IGFD::Utils::GetPathSeparator() + file->fileNameExt;
2959 int w = 0;
2960 int h = 0;
2961 int chans = 0;
2962 uint8_t* datas = stbi_load(fpn.c_str(), &w, &h, &chans, STBI_rgb_alpha);
2963 if (datas != nullptr) {
2964 if (w != 0 && h != 0) {
2965 // resize with respect to glyph ratio
2966 const float ratioX = (float)w / (float)h;
2967 const float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX;
2968 float newY = w / ratioX;
2969 if (newX < w) {
2970 newY = DisplayMode_ThumbailsList_ImageHeight;
2971 }
2972 const auto newWidth = (int)newX;
2973 const auto newHeight = (int)newY;
2974 const auto newBufSize = (size_t)(newWidth * newHeight * 4U); //-V112 //-V1028
2975 auto resizedData = new uint8_t[newBufSize];
2976 const auto* resizeSucceeded = stbir_resize_uint8_linear(datas, w, h, 0, resizedData, newWidth, newHeight, 0, stbir_pixel_layout::STBIR_RGBA); //-V112
2977 if (resizeSucceeded != nullptr) {
2978 auto th = &file->thumbnailInfo;
2979 th->textureFileDatas = resizedData;
2980 th->textureWidth = newWidth;
2981 th->textureHeight = newHeight;
2982 th->textureChannels = 4; //-V112
2983 // we set that at least, because will launch the gpu creation of the texture in the
2984 // main thread
2985 th->isReadyToUpload = true;
2986 // need gpu loading
2987 m_AddThumbnailToCreate(file);
2988 } else {
2989 delete[] resizedData;
2990 }
2991 } else {
2992 printf("image loading fail : w:%i h:%i c:%i\n", w, h, 4); //-V112
2993 }
2994 stbi_image_free(datas);
2995 }
2996 }
2997 }

Callers

nothing calls this directly

Calls 7

stbi_loadFunction · 0.85
stbi_image_freeFunction · 0.85
emptyMethod · 0.80
beginMethod · 0.80
isFileMethod · 0.80
SearchForExtsMethod · 0.80

Tested by

no test coverage detected