From 990bd319c696c2b65fa858b40fd75279fec2a13b Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 18 Nov 2022 23:40:08 -0500 Subject: txt2img functional --- main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 85dd002..3cc976c 100644 --- a/main.cpp +++ b/main.cpp @@ -33,6 +33,8 @@ #define STBI_FAILURE_USERMSG #include "lib/stb_image.h" +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "lib/stb_image_write.h" #include "defines.h" #include "my_math.h" @@ -60,6 +62,7 @@ static instruction_mode InstructionMode = instruction_mode_scalar; static uint32 RandomGlobalIncrement = 0; #include "lib/base64.c" +#include #include "memory.cpp" #include "undo.cpp" @@ -242,7 +245,8 @@ Main_InputTest(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui_File(File, State, Memory, io, Sorted.CompArray, Sorted.LayerArray); ImGui_PropertiesPanel(File, State, UI, Memory, io); ImGui_ColorPanel(File, State, UI, Memory, io); - ImGui_StableDiffusion(File, State, UI, Memory, io); + ImGui_SD_Prompt(File, State, UI, Memory, io); + ImGui_SD_Thumbnail(File, State, UI, Memory, io); ImGui_Menu(File, State, UI, Memory, io); File_Sort_Pop(Memory, Sorted.Layer_SortSize, Sorted.Property_SortSize); @@ -281,7 +285,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io // if (Entry_Main->IsCached) // return CompBuffer; - uint64 Comp_TimeStart = GetTime(); + uint64 Comp_TimeStart = GetCPUTime(); sorted_comp_info *SortedCompInfo = &SortedCompArray[CompIndex]; sorted_layer *SortedLayerInfo = Layer_GetSortedArray(SortedLayerArray, SortedCompArray, CompIndex); @@ -356,7 +360,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io } else { cache_entry *Entry = Memory_Cache_Search(State, Memory, cache_entry_type_source, Layer->Block_Source_Index, 0); if (!Entry->IsCached) { - uint64 Src_TimeStart = GetTime(); + uint64 Src_TimeStart = GetCPUTime(); block_string *Name = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Source->Path_String_Index); int w = 0, h = 0; void *temp = stbi_load(Name->Char, &w, &h, NULL, 4); @@ -365,11 +369,11 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Source->BytesPerPixel = 4; uint64 Size = Source->Width * Source->Height * Source->BytesPerPixel; void *Source_Address = Memory_Block_Bitmap_AddressAtIndex(Memory, Entry->Block_StartIndex); - Arbitrary_WriteInto((uint8 *)temp, (uint8 *)Source_Address, Size); + Memory_Copy((uint8 *)Source_Address, (uint8 *)temp, Size); stbi_image_free(temp); BitmapState->ToUpdate = false; BitmapState->CurrentFrame = 0; - Entry->CycleTime = GetTime() - Src_TimeStart; + Entry->CycleTime = GetCPUTime() - Src_TimeStart; Layer->x.CurrentValue = Comp->Width/2; Layer->y.CurrentValue = Comp->Height/2; Entry->IsCached = true; @@ -405,7 +409,7 @@ Render_Comp(project_data *File, project_state *State, memory *Memory, ImGuiIO io Render_Main((void *)&T, CompBuffer, render_type_main, RenderRegion); } } - Entry_Main->CycleTime = GetTime() - Comp_TimeStart; + Entry_Main->CycleTime = GetCPUTime() - Comp_TimeStart; Entry_Main->IsCached = true; return CompBuffer; } @@ -503,6 +507,9 @@ int main(int argc, char *argv[]) { State->Brush.TransientBitmap = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); ScratchPaintSize = 2048*2048*4; Memory.ScratchPos += ScratchPaintSize; + State->Dump1 = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); + Memory.ScratchPos += ScratchPaintSize; + State->Dump2 = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); State->ClipboardBuffer = (void *)((uint8 *)Memory.Slot[B_ScratchSpace].Address + Memory.ScratchPos); State->ClipboardSize = 1024*1024; @@ -852,12 +859,47 @@ int main(int argc, char *argv[]) { Brush_CalcBitmapAlphaFromSize(&Memory, &State->Brush, 4); State_BindBrushTexture(&Memory, &State->Brush, 4); + curl_global_init(CURL_GLOBAL_ALL); + curl_state MainHandle = {}; + curl_state ProgHandle = {}; + uint32 Inc = 0; while (State->IsRunning) { // State->Interact_Active = interact_type_layer_move; // State->Interact_Offset[1] = -3.0f; + if (State->CurlActive) { + if (State->CurlActive == -1) { + Curl_GET_Init(&MainHandle, State->Dump1, State->JSONPayload, State->SD.ServerAddress, State->SD.Mode); + Curl_Prog_Init(&ProgHandle, State->Dump2); + State->CurlActive = 1; + } else { + if (Curl_Check(&MainHandle) == 1) { + SD_JSONToSource(File, State, &Memory, State->Dump1, State->SD.Height, State->SD.Width); + Curl_Free(&ProgHandle); + curl_slist_free_all(ProgHandle.list); + Curl_Free(&MainHandle); + State->CurlActive = 0; + } + uint64 Time = ImGui::GetTime(); + if (Time - State->SDTimer > 0.3f) { + if (Curl_Check(&ProgHandle) == 1) { + SD_ParseProgress(State, (char *)State->Dump2); + curl_multi_remove_handle(ProgHandle.curlm, ProgHandle.curl); + curl_easy_reset(ProgHandle.curl); + ProgHandle.CurlData.size = 0; + curl_easy_setopt(ProgHandle.curl, CURLOPT_URL, "http://127.0.0.1:7860/sdapi/v1/progress"); + curl_easy_setopt(ProgHandle.curl, CURLOPT_WRITEFUNCTION, dumbcurlcallback); + curl_easy_setopt(ProgHandle.curl, CURLOPT_WRITEDATA, (void *)&ProgHandle.CurlData); + curl_multi_add_handle(ProgHandle.curlm, ProgHandle.curl); + } + State->SDTimer = Time; + } + Inc++; + } + } + Main_InputTest(File, State, &Memory, &UI, window, textureID); if (State->IsPlaying) { -- cgit v1.2.3