From 990bd319c696c2b65fa858b40fd75279fec2a13b Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 18 Nov 2022 23:40:08 -0500 Subject: txt2img functional --- my_imgui_widgets.cpp | 74 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 20 deletions(-) (limited to 'my_imgui_widgets.cpp') diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index bfe114b..b3339d2 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -35,7 +35,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * bool32 Display = 1; block_layer *Layer = NULL; if (State->MostRecentlySelectedLayer > -1) { - Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->MostRecentlySelectedLayer); + Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->MostRecentlySelectedLayer, 0); if (!Layer->Occupied) Display = 0; } else { @@ -237,28 +237,57 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io, } static void -ImGui_StableDiffusion(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) +ImGui_SD_Thumbnail(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) +{ + ImGui::Begin("SD gallery"); + ImGui::End(); +} + +static void +ImGui_SD_Prompt(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io) { ImGui::Begin("SD prompt input"); sd_state *SD = &State->SD; int Size = ImGui::GetFontSize(); ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(200, 80, 0, 255)); if (ImGui::Button("Generate!", ImVec2(Size*8, Size*2))) { - /* - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); - block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); - cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0); - Assert(Entry->IsCached); - void *BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); - uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel; - uint64 EncodedLength = 0; - uint64 EncodedAllocSize = base64_encode_size(Size); - void *EncodedOutput = Memory_PushScratch(Memory, EncodedSize); - uint64 EncodedTrueSize; - base64_encode((uint8 *)BitmapAddress, Size, (uint8 *)EncodedOutput, &EncodedTrueSize); - Memory_PopScratch(Memory, EncodedSize); - */ - SD_Txt2Txt(SD); + if (!State->CurlActive) { + if (SD->Mode) { + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, 0); + block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); + cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0); + Assert(Entry->IsCached); + void *BitmapAddress = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); + uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel; + + int32 len = 0; + uint8 *PNGBitmap = stbi_write_png_to_mem((uint8 *)BitmapAddress, Source->Width * Source->BytesPerPixel, + Source->Width, Source->Height, Source->BytesPerPixel, &len); + Assert(PNGBitmap); + + uint64 EncodedLength = 0; + uint64 EncodedAllocSize = base64_encode_size(Size); + uint8 *EncodedOutput = (uint8 *)Memory_PushScratch(Memory, EncodedAllocSize); + uint64 EncodedTrueSize; + + base64_encode((uint8 *)BitmapAddress, Size, EncodedOutput, &EncodedTrueSize); + Assert(EncodedOutput[EncodedTrueSize] == '\0'); + + STBIW_FREE(PNGBitmap); + + SD_AssembleJSON(SD, (char *)State->Dump1, EncodedOutput); + Memory_PopScratch(Memory, EncodedAllocSize); + } else { + SD_AssembleJSON(SD, State->JSONPayload); + // SD_AssembleJSON(SD, (char *)State->Dump2); + } + State->CurlActive = -1; + } + } + ImGui::PopStyleColor(); + if (State->CurlActive) { + ImGui::SameLine(); + ImGui::Text("Est. time: %.1f sec, %.2f", State->SDTimeEstimate, State->SDPercentDone*100); } ImGui::InputText("Address", SD->ServerAddress, SD_LEN_ADDRESS); if (State->Initializing && (SD->ServerAddress[0] == '\0')) { @@ -266,7 +295,10 @@ ImGui_StableDiffusion(project_data *File, project_state *State, ui *UI, memory * sprintf(SD->NegPrompt, "%s", "nsfw, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark"); sprintf(SD->ServerAddress, "%s", "http://127.0.0.1:7860"); } - ImGui::PopStyleColor(); + if (ImGui::Selectable("txt2img", !SD->Mode)) + SD->Mode = 0; + if (ImGui::Selectable("img2img", SD->Mode)) + SD->Mode = 1; ImGui::InputTextMultiline("Prompt", SD->Prompt, SD_LEN_PROMPT); ImGui::InputTextMultiline("Negative prompt", SD->NegPrompt, SD_LEN_PROMPT); ImGui::SliderInt("Steps", &SD->Steps, 0, 150); @@ -279,7 +311,9 @@ ImGui_StableDiffusion(project_data *File, project_state *State, ui *UI, memory * SD->Height = SD->Height + (64 - (SD->Height % 64)); } ImGui::SliderFloat("CFG scale", &SD->CFG, 1, 30, "%.2f"); - ImGui::SliderFloat("Denoising strength", &SD->DenoisingStrength, 0, 1, "%.2f"); + if (SD->Mode) { + ImGui::SliderFloat("Denoising strength", &SD->DenoisingStrength, 0, 1, "%.2f"); + } ImGui::InputInt("Seed", &SD->Seed); ImGui::End(); } @@ -840,7 +874,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGui::InvisibleButton("canvas", ViewportScale, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight); bool32 IsHovered = ImGui::IsItemHovered(); -#if 0 +#if 1 bool32 IsActive = ImGui::IsItemActive(); bool32 IsActivated = ImGui::IsItemActivated(); #else -- cgit v1.2.3