diff --git a/src/gui/image.cpp b/src/gui/image.cpp index d8cfa149b..980929e77 100644 --- a/src/gui/image.cpp +++ b/src/gui/image.cpp @@ -101,6 +101,44 @@ FurnaceGUIImage* FurnaceGUI::getImage(FurnaceGUIImages image) { } #endif + if (ret->ch==4) { + size_t total=ret->width*ret->height*ret->ch; + switch (bestTexFormat) { + case GUI_TEXFORMAT_ARGB32: + for (size_t i=0; idata[i]^=ret->data[i|2]; + ret->data[i|2]^=ret->data[i]; + ret->data[i]^=ret->data[i|2]; + } + break; + case GUI_TEXFORMAT_BGRA32: + for (size_t i=0; idata[i]^=ret->data[i|3]; + ret->data[i|3]^=ret->data[i]; + ret->data[i]^=ret->data[i|3]; + ret->data[i|1]^=ret->data[i|2]; + ret->data[i|2]^=ret->data[i|1]; + ret->data[i|1]^=ret->data[i|2]; + ret->data[i|1]^=ret->data[i|3]; + ret->data[i|3]^=ret->data[i|1]; + ret->data[i|1]^=ret->data[i|3]; + } + break; + case GUI_TEXFORMAT_RGBA32: + for (size_t i=0; idata[i]^=ret->data[i|3]; + ret->data[i|3]^=ret->data[i]; + ret->data[i]^=ret->data[i|3]; + ret->data[i|1]^=ret->data[i|2]; + ret->data[i|2]^=ret->data[i|1]; + ret->data[i|1]^=ret->data[i|2]; + } + break; + default: + break; + } + } + images[image]=ret; } diff --git a/src/gui/render/renderDX11.cpp b/src/gui/render/renderDX11.cpp index 71b9a6df0..a05220124 100644 --- a/src/gui/render/renderDX11.cpp +++ b/src/gui/render/renderDX11.cpp @@ -75,6 +75,7 @@ class FurnaceDXTexture: public FurnaceGUITexture { ID3D11Texture2D* tex; ID3D11ShaderResourceView* view; int width, height; + FurnaceGUITextureFormat format; unsigned char* lockedData; bool dynamic; FurnaceDXTexture(): @@ -82,6 +83,7 @@ class FurnaceDXTexture: public FurnaceGUITexture { view(NULL), width(0), height(0), + format(GUI_TEXFORMAT_UNKNOWN), lockedData(NULL), dynamic(false) {} }; @@ -147,6 +149,11 @@ ImTextureID FurnaceGUIRenderDX11::getTextureID(FurnaceGUITexture* which) { return (ImTextureID)t->view; } +FurnaceGUITextureFormat FurnaceGUIRenderDX11::getTextureFormat(FurnaceGUITexture* which) { + FurnaceDXTexture* t=(FurnaceDXTexture*)which; + return t->format; +} + bool FurnaceGUIRenderDX11::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceDXTexture* t=(FurnaceDXTexture*)which; if (t->lockedData!=NULL) return false; @@ -256,6 +263,7 @@ FurnaceGUITexture* FurnaceGUIRenderDX11::createTexture(bool dynamic, int width, ret->tex=tex; ret->view=view; ret->dynamic=dynamic; + ret->format=format; return ret; } diff --git a/src/gui/render/renderDX11.h b/src/gui/render/renderDX11.h index 4b24a525d..3243999f1 100644 --- a/src/gui/render/renderDX11.h +++ b/src/gui/render/renderDX11.h @@ -64,6 +64,7 @@ class FurnaceGUIRenderDX11: public FurnaceGUIRender { public: ImTextureID getTextureID(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderDX9.cpp b/src/gui/render/renderDX9.cpp index 8e1fefe83..68f1dd760 100644 --- a/src/gui/render/renderDX9.cpp +++ b/src/gui/render/renderDX9.cpp @@ -30,6 +30,7 @@ class FurnaceDX9Texture: public FurnaceGUITexture { IDirect3DTexture9* tex; IDirect3DTexture9* texPre; int width, height, widthReal, heightReal; + FurnaceGUITextureFormat format; unsigned char* lockedData; bool dynamic; FurnaceDX9Texture(): @@ -39,6 +40,7 @@ class FurnaceDX9Texture: public FurnaceGUITexture { height(0), widthReal(0), heightReal(0), + format(GUI_TEXFORMAT_UNKNOWN), lockedData(NULL), dynamic(false) {} }; @@ -62,6 +64,11 @@ float FurnaceGUIRenderDX9::getTextureV(FurnaceGUITexture* which) { return (float)t->height/(float)t->heightReal; } +FurnaceGUITextureFormat FurnaceGUIRenderDX9::getTextureFormat(FurnaceGUITexture* which) { + FurnaceDX9Texture* t=(FurnaceDX9Texture*)which; + return t->format; +} + bool FurnaceGUIRenderDX9::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceDX9Texture* t=(FurnaceDX9Texture*)which; D3DLOCKED_RECT lockedRect; @@ -198,6 +205,7 @@ FurnaceGUITexture* FurnaceGUIRenderDX9::createTexture(bool dynamic, int width, i ret->tex=tex; ret->texPre=texPre; ret->dynamic=dynamic; + ret->format=format; return ret; } diff --git a/src/gui/render/renderDX9.h b/src/gui/render/renderDX9.h index ad215ef60..36d5c08e2 100644 --- a/src/gui/render/renderDX9.h +++ b/src/gui/render/renderDX9.h @@ -49,6 +49,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender { ImTextureID getTextureID(FurnaceGUITexture* which); float getTextureU(FurnaceGUITexture* which); float getTextureV(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderGL.cpp b/src/gui/render/renderGL.cpp index e5ac9afa3..161b36b2e 100644 --- a/src/gui/render/renderGL.cpp +++ b/src/gui/render/renderGL.cpp @@ -65,11 +65,13 @@ class FurnaceGLTexture: public FurnaceGUITexture { public: GLuint id; int width, height; + FurnaceGUITextureFormat format; unsigned char* lockedData; FurnaceGLTexture(): id(0), width(0), height(0), + format(GUI_TEXFORMAT_UNKNOWN), lockedData(NULL) {} }; @@ -281,6 +283,11 @@ ImTextureID FurnaceGUIRenderGL::getTextureID(FurnaceGUITexture* which) { return (ImTextureID)ret; } +FurnaceGUITextureFormat FurnaceGUIRenderGL::getTextureFormat(FurnaceGUITexture* which) { + FurnaceGLTexture* t=(FurnaceGLTexture*)which; + return t->format; +} + bool FurnaceGUIRenderGL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceGLTexture* t=(FurnaceGLTexture*)which; if (t->lockedData!=NULL) return false; @@ -334,6 +341,7 @@ FurnaceGUITexture* FurnaceGUIRenderGL::createTexture(bool dynamic, int width, in C(furActiveTexture(GL_TEXTURE0)); t->width=width; t->height=height; + t->format=format; return t; } diff --git a/src/gui/render/renderGL.h b/src/gui/render/renderGL.h index 7970158b3..0cf861596 100644 --- a/src/gui/render/renderGL.h +++ b/src/gui/render/renderGL.h @@ -56,6 +56,7 @@ class FurnaceGUIRenderGL: public FurnaceGUIRender { public: ImTextureID getTextureID(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderGL1.cpp b/src/gui/render/renderGL1.cpp index bc6be7301..0ebf8b391 100644 --- a/src/gui/render/renderGL1.cpp +++ b/src/gui/render/renderGL1.cpp @@ -29,6 +29,7 @@ class FurnaceGL1Texture: public FurnaceGUITexture { public: GLuint id; int width, height, widthReal, heightReal; + FurnaceGUITextureFormat format; unsigned char* lockedData; FurnaceGL1Texture(): id(0), @@ -36,6 +37,7 @@ class FurnaceGL1Texture: public FurnaceGUITexture { height(0), widthReal(0), heightReal(0), + format(GUI_TEXFORMAT_UNKNOWN), lockedData(NULL) {} }; @@ -56,6 +58,11 @@ float FurnaceGUIRenderGL1::getTextureV(FurnaceGUITexture* which) { return (float)t->height/(float)t->heightReal; } +FurnaceGUITextureFormat FurnaceGUIRenderGL1::getTextureFormat(FurnaceGUITexture* which) { + FurnaceGL1Texture* t=(FurnaceGL1Texture*)which; + return t->format; +} + bool FurnaceGUIRenderGL1::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceGL1Texture* t=(FurnaceGL1Texture*)which; if (t->lockedData!=NULL) return false; @@ -125,6 +132,7 @@ FurnaceGUITexture* FurnaceGUIRenderGL1::createTexture(bool dynamic, int width, i t->height=height; t->widthReal=widthReal; t->heightReal=heightReal; + t->format=format; return t; } diff --git a/src/gui/render/renderGL1.h b/src/gui/render/renderGL1.h index ee545fde8..9b3b6d2d3 100644 --- a/src/gui/render/renderGL1.h +++ b/src/gui/render/renderGL1.h @@ -32,6 +32,7 @@ class FurnaceGUIRenderGL1: public FurnaceGUIRender { ImTextureID getTextureID(FurnaceGUITexture* which); float getTextureU(FurnaceGUITexture* which); float getTextureV(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderMetal.h b/src/gui/render/renderMetal.h index e77ebc002..a0a249416 100644 --- a/src/gui/render/renderMetal.h +++ b/src/gui/render/renderMetal.h @@ -28,6 +28,7 @@ class FurnaceGUIRenderMetal: public FurnaceGUIRender { String vendorName, deviceName, apiVersion; public: ImTextureID getTextureID(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderMetal.mm b/src/gui/render/renderMetal.mm index dde706810..ae27b3b89 100644 --- a/src/gui/render/renderMetal.mm +++ b/src/gui/render/renderMetal.mm @@ -44,11 +44,13 @@ class FurnaceMetalTexture: public FurnaceGUITexture { public: id tex; int width, height; + FurnaceGUITextureFormat format; unsigned char* lockedData; FurnaceMetalTexture(): tex(NULL), width(0), height(0), + format(GUI_TEXFORMAT_UNKNOWN), lockedData(NULL) {} }; @@ -57,6 +59,11 @@ ImTextureID FurnaceGUIRenderMetal::getTextureID(FurnaceGUITexture* which) { return t->tex; } +FurnaceGUITextureFormat FurnaceGUIRenderMetal::getTextureFormat(FurnaceGUITexture* which) { + FurnaceMetalTexture* t=(FurnaceMetalTexture*)which; + return t->format; +} + bool FurnaceGUIRenderMetal::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceMetalTexture* t=(FurnaceMetalTexture*)which; if (t->lockedData!=NULL) return false; diff --git a/src/gui/render/renderSDL.cpp b/src/gui/render/renderSDL.cpp index 49f1a1956..cb0a6a402 100644 --- a/src/gui/render/renderSDL.cpp +++ b/src/gui/render/renderSDL.cpp @@ -24,8 +24,10 @@ class FurnaceSDLTexture: public FurnaceGUITexture { public: SDL_Texture* tex; + FurnaceGUITextureFormat format; FurnaceSDLTexture(): - tex(NULL) {} + tex(NULL), + format(GUI_TEXFORMAT_UNKNOWN) {} }; ImTextureID FurnaceGUIRenderSDL::getTextureID(FurnaceGUITexture* which) { @@ -33,6 +35,11 @@ ImTextureID FurnaceGUIRenderSDL::getTextureID(FurnaceGUITexture* which) { return t->tex; } +FurnaceGUITextureFormat FurnaceGUIRenderSDL::getTextureFormat(FurnaceGUITexture* which) { + FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; + return t->format; +} + bool FurnaceGUIRenderSDL::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceSDLTexture* t=(FurnaceSDLTexture*)which; return SDL_LockTexture(t->tex,NULL,data,pitch)==0; @@ -61,6 +68,7 @@ FurnaceGUITexture* FurnaceGUIRenderSDL::createTexture(bool dynamic, int width, i if (t==NULL) return NULL; FurnaceSDLTexture* ret=new FurnaceSDLTexture; ret->tex=t; + ret->format=format; return ret; } diff --git a/src/gui/render/renderSDL.h b/src/gui/render/renderSDL.h index de14f8731..fa394dcac 100644 --- a/src/gui/render/renderSDL.h +++ b/src/gui/render/renderSDL.h @@ -26,6 +26,7 @@ class FurnaceGUIRenderSDL: public FurnaceGUIRender { bool swapIntervalSet; public: ImTextureID getTextureID(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/render/renderSoftware.cpp b/src/gui/render/renderSoftware.cpp index d18569c15..d18c11aa2 100644 --- a/src/gui/render/renderSoftware.cpp +++ b/src/gui/render/renderSoftware.cpp @@ -24,8 +24,10 @@ class FurnaceSoftwareTexture: public FurnaceGUITexture { public: SWTexture* tex; + FurnaceGUITextureFormat format; FurnaceSoftwareTexture(): - tex(NULL) {} + tex(NULL), + format(GUI_TEXFORMAT_UNKNOWN) {} }; ImTextureID FurnaceGUIRenderSoftware::getTextureID(FurnaceGUITexture* which) { @@ -33,6 +35,11 @@ ImTextureID FurnaceGUIRenderSoftware::getTextureID(FurnaceGUITexture* which) { return t->tex; } +FurnaceGUITextureFormat FurnaceGUIRenderSoftware::getTextureFormat(FurnaceGUITexture* which) { + FurnaceSoftwareTexture* t=(FurnaceSoftwareTexture*)which; + return t->format; +} + bool FurnaceGUIRenderSoftware::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) { FurnaceSoftwareTexture* t=(FurnaceSoftwareTexture*)which; if (!t->tex->managed) return false; @@ -59,6 +66,7 @@ FurnaceGUITexture* FurnaceGUIRenderSoftware::createTexture(bool dynamic, int wid } FurnaceSoftwareTexture* ret=new FurnaceSoftwareTexture; ret->tex=new SWTexture(width,height); + ret->format=format; return ret; } diff --git a/src/gui/render/renderSoftware.h b/src/gui/render/renderSoftware.h index cc03bc256..eef580aff 100644 --- a/src/gui/render/renderSoftware.h +++ b/src/gui/render/renderSoftware.h @@ -23,6 +23,7 @@ class FurnaceGUIRenderSoftware: public FurnaceGUIRender { SDL_Window* sdlWin; public: ImTextureID getTextureID(FurnaceGUITexture* which); + FurnaceGUITextureFormat getTextureFormat(FurnaceGUITexture* which); bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch); bool unlockTexture(FurnaceGUITexture* which); bool updateTexture(FurnaceGUITexture* which, void* data, int pitch); diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index e646323db..8f97d6beb 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -31,6 +31,15 @@ #include "sampleUtil.h" #include "util.h" +#define SWAP_COLOR_ARGB(x) \ + x=(x&0xff00ff00)|((x&0xff)<<16)|((x&0xff0000)>>16); + +#define SWAP_COLOR_BGRA(x) \ + x=((x&0xff0000000)>>24)|((x&0xffffff)<<8); + +#define SWAP_COLOR_RGBA(x) \ + x=((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24); + const double timeDivisors[10]={ 1000.0, 500.0, 200.0, 100.0, 50.0, 20.0, 10.0, 5.0, 2.0, 1.0 }; @@ -1501,6 +1510,30 @@ void FurnaceGUI::drawSampleEdit() { ImU32 bgColorLoop=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_LOOP]); ImU32 lineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_FG]); ImU32 centerLineColor=ImGui::GetColorU32(uiColors[GUI_COLOR_SAMPLE_CENTER]); + + switch (rend->getTextureFormat(sampleTex)) { + case GUI_TEXFORMAT_ARGB32: + SWAP_COLOR_ARGB(bgColor); + SWAP_COLOR_ARGB(bgColorLoop); + SWAP_COLOR_ARGB(lineColor); + SWAP_COLOR_ARGB(centerLineColor); + break; + case GUI_TEXFORMAT_BGRA32: + SWAP_COLOR_BGRA(bgColor); + SWAP_COLOR_BGRA(bgColorLoop); + SWAP_COLOR_BGRA(lineColor); + SWAP_COLOR_BGRA(centerLineColor); + break; + case GUI_TEXFORMAT_RGBA32: + SWAP_COLOR_RGBA(bgColor); + SWAP_COLOR_RGBA(bgColorLoop); + SWAP_COLOR_RGBA(lineColor); + SWAP_COLOR_RGBA(centerLineColor); + break; + default: + break; + } + int ij=0; for (int i=0; i