void FSSTBatchCombinerModule::PluginButtonClicked() { TArray<FString> OutFileNames; TArray<FString> OutFileNames2; FDesktopPlatformModule::Get()->OpenFileDialog(nullptr, "select First Image Files", "", "", "Image Files (*.png)|*.png", 1, OutFileNames); FDesktopPlatformModule::Get()->OpenFileDialog(nullptr, "select Second Image Files", "", "", "Image Files (*.png)|*.png", 1, OutFileNames2); if (OutFileNames.Num() && OutFileNames2.Num()) { if (OutFileNames.Num() != OutFileNames2.Num()) { FString DialogText = "Error! first set quantity does not match second set!"; FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(DialogText)); return; } IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper")); for (int32 i = 0; i < OutFileNames.Num(); i++) { TArray<uint8> RawFileData; TArray<uint8> RawFileData2; if (FFileHelper::LoadFileToArray(RawFileData, *OutFileNames[i]) && FFileHelper::LoadFileToArray(RawFileData2, *OutFileNames2[i])) { IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG); IImageWrapperPtr ImageWrapper2 = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG); if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()) && ImageWrapper2.IsValid() && ImageWrapper2->SetCompressed(RawFileData2.GetData(), RawFileData2.Num())) { const TArray<uint8>* RawData = nullptr; const TArray<uint8>* RawData2 = nullptr; if (ImageWrapper->GetRaw(ERGBFormat::BGRA, ImageWrapper->GetBitDepth(), RawData) && ImageWrapper2->GetRaw(ERGBFormat::BGRA, ImageWrapper2->GetBitDepth(), RawData2)) { uint32 ImageWidth = ImageWrapper->GetWidth(); uint32 ImageHeight = ImageWrapper->GetHeight(); uint32 ImageWidth2 = ImageWrapper2->GetWidth(); uint32 ImageHeight2 = ImageWrapper2->GetHeight(); if ((ImageWidth != ImageWidth2) || (ImageHeight != ImageHeight2)) { FString DialogText = "Error! Image dimensions do not match for frame " + FString::FromInt(i); FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(DialogText)); return; } TArray<uint8> newdata; newdata = *RawData; for (int32 a = 0; a < RawData->Num() - 4; a = a + 4) { newdata[a + 1] = (*RawData2)[a]; } //save ImageWrapper->SetRaw(newdata.GetData(), newdata.GetAllocatedSize(), ImageWidth, ImageHeight, ERGBFormat::BGRA, 8); const TArray<uint8>& PNGData = ImageWrapper->GetCompressed(100); FFileHelper::SaveArrayToFile(PNGData, *OutFileNames[i]); } //if imagewrapper.getraw } //if imagewrapper.valid } //if load file }// for files loop } //if files }
const TArray<uint16>& ULandscapeEditorObject::GetImportLandscapeData() { if (ImportLandscape_HeightmapFilename.EndsWith(".png")) { if (ImportLandscape_Data.Num() == 0) { ImportLandscape_Data.Empty(); TArray<uint8> ImportData; if (!FFileHelper::LoadFileToArray(ImportData, *ImportLandscape_HeightmapFilename, FILEREAD_Silent)) { ImportLandscape_HeightmapError = ELandscapeImportHeightmapError::FileNotFound; } else { IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>("ImageWrapper"); IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG); const TArray<uint8>* RawData = NULL; if (ImageWrapper->SetCompressed(ImportData.GetData(), ImportData.Num()) && ImageWrapper->GetWidth() == ImportLandscape_Width && ImageWrapper->GetHeight() == ImportLandscape_Height) { if (ImageWrapper->GetBitDepth() <= 8) { ImageWrapper->GetRaw(ERGBFormat::Gray, 8, RawData); if (ensure(RawData->Num() == ImportLandscape_Width * ImportLandscape_Height)) { ImportLandscape_Data.Empty(ImportLandscape_Width * ImportLandscape_Height); ImportLandscape_Data.AddUninitialized(ImportLandscape_Width * ImportLandscape_Height); for (int32 i = 0; i < RawData->Num(); i++) { ImportLandscape_Data[i] = (*RawData)[i] * 0x101; // Expand to 16-bit } } } else { ImageWrapper->GetRaw(ERGBFormat::Gray, 16, RawData); if (ensure(RawData->Num() == ImportLandscape_Width * ImportLandscape_Height * 2)) { ImportLandscape_Data.Empty(ImportLandscape_Width * ImportLandscape_Height); ImportLandscape_Data.AddUninitialized(ImportLandscape_Width * ImportLandscape_Height); FMemory::Memcpy(ImportLandscape_Data.GetData(), RawData->GetData(), RawData->Num()); } } } } } } else { if (ImportLandscape_Width * ImportLandscape_Height != ImportLandscape_Data.Num()) { ImportLandscape_Data.Empty(); TArray<uint8> ImportData; if (ImportLandscape_Width > 0 && ImportLandscape_Height > 0 && FFileHelper::LoadFileToArray(ImportData, *ImportLandscape_HeightmapFilename, FILEREAD_Silent) && ImportData.Num() == ImportLandscape_Width * ImportLandscape_Height * 2) { ImportLandscape_Data.Empty(ImportLandscape_Width * ImportLandscape_Height); ImportLandscape_Data.AddUninitialized(ImportLandscape_Width * ImportLandscape_Height); FMemory::Memcpy(ImportLandscape_Data.GetData(), ImportData.GetData(), ImportData.Num()); } } } return ImportLandscape_Data; }