Mercurial > hg > orthanc-stone
changeset 560:aaeec7be8fb7
add support for alpha channel in CairoSurface
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 17 Apr 2019 17:57:50 +0200 |
parents | 9e61b0ac12f1 |
children | 1201b12eb9f8 37e396ae08a3 9ea4b57a9ed8 |
files | Applications/Sdl/SdlCairoSurface.cpp Applications/StoneApplicationContext.h Framework/Layers/ColorFrameRenderer.cpp Framework/Layers/GrayscaleFrameRenderer.cpp Framework/Radiography/RadiographyWidget.cpp Framework/Viewport/CairoSurface.cpp Framework/Viewport/CairoSurface.h Framework/Viewport/WidgetViewport.cpp Framework/Widgets/CairoWidget.cpp Framework/Widgets/WidgetBase.cpp Framework/Widgets/WorldSceneWidget.cpp UnitTestsSources/TestMessageBroker.cpp |
diffstat | 12 files changed, 55 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Sdl/SdlCairoSurface.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Applications/Sdl/SdlCairoSurface.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -51,7 +51,7 @@ cairoSurface_->GetWidth() != width || cairoSurface_->GetHeight() != height) { - cairoSurface_.reset(new CairoSurface(width, height)); + cairoSurface_.reset(new CairoSurface(width, height, false /* no alpha */)); // TODO Big endian? static const uint32_t rmask = 0x00ff0000;
--- a/Applications/StoneApplicationContext.h Wed Apr 17 16:16:47 2019 +0200 +++ b/Applications/StoneApplicationContext.h Wed Apr 17 17:57:50 2019 +0200 @@ -27,24 +27,6 @@ #include "../Framework/Viewport/WidgetViewport.h" -#ifdef _MSC_VER - #if _MSC_VER > 1910 - #define orthanc_override override - #else - #define orthanc_override - #endif -#elif defined __GNUC__ - #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -/* Test for GCC > 3.2.0 */ - #if GCC_VERSION > 40900 - #define orthanc_override override - else - #define orthanc_override - #endif -#else - #define orthanc_override -#endif - #include <list> namespace OrthancStone
--- a/Framework/Layers/ColorFrameRenderer.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Layers/ColorFrameRenderer.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -29,7 +29,7 @@ { CairoSurface* ColorFrameRenderer::GenerateDisplay(const RenderStyle& style) { - std::auto_ptr<CairoSurface> display(new CairoSurface(frame_->GetWidth(), frame_->GetHeight())); + std::auto_ptr<CairoSurface> display(new CairoSurface(frame_->GetWidth(), frame_->GetHeight(), false /* no alpha */)); Orthanc::ImageAccessor target; display->GetWriteableAccessor(target);
--- a/Framework/Layers/GrayscaleFrameRenderer.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Layers/GrayscaleFrameRenderer.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -41,7 +41,7 @@ //LOG(INFO) << "Window: " << x0 << " => " << x1; - result.reset(new CairoSurface(frame_->GetWidth(), frame_->GetHeight())); + result.reset(new CairoSurface(frame_->GetWidth(), frame_->GetHeight(), false /* no alpha */)); const uint8_t* lut = NULL; if (style.applyLut_)
--- a/Framework/Radiography/RadiographyWidget.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Radiography/RadiographyWidget.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -88,7 +88,7 @@ cairoBuffer_->GetWidth() != width || cairoBuffer_->GetHeight() != height) { - cairoBuffer_.reset(new CairoSurface(width, height)); + cairoBuffer_.reset(new CairoSurface(width, height, false /* no alpha */)); } RenderBackground(*floatBuffer_, x0, x1);
--- a/Framework/Viewport/CairoSurface.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Viewport/CairoSurface.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -38,11 +38,15 @@ void CairoSurface::Allocate(unsigned int width, - unsigned int height) + unsigned int height, + bool hasAlpha) { Release(); - surface_ = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); + hasAlpha_ = hasAlpha; + + surface_ = cairo_image_surface_create + (hasAlpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, width, height); if (!surface_) { // Should never occur @@ -63,7 +67,9 @@ } - CairoSurface::CairoSurface(Orthanc::ImageAccessor& accessor) + CairoSurface::CairoSurface(Orthanc::ImageAccessor& accessor, + bool hasAlpha) : + hasAlpha_(hasAlpha) { if (accessor.GetFormat() != Orthanc::PixelFormat_BGRA32) { @@ -76,7 +82,9 @@ buffer_ = accessor.GetBuffer(); surface_ = cairo_image_surface_create_for_data - (reinterpret_cast<unsigned char*>(buffer_), CAIRO_FORMAT_RGB24, width_, height_, pitch_); + (reinterpret_cast<unsigned char*>(buffer_), + hasAlpha_ ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, + width_, height_, pitch_); if (!surface_) { // Should never occur @@ -93,35 +101,44 @@ void CairoSurface::SetSize(unsigned int width, - unsigned int height) + unsigned int height, + bool hasAlpha) { - if (width_ != width || + if (hasAlpha_ != hasAlpha || + width_ != width || height_ != height) { - Allocate(width, height); + Allocate(width, height, hasAlpha); } } void CairoSurface::Copy(const CairoSurface& other) { + SetSize(other.GetWidth(), other.GetHeight(), other.HasAlpha()); + Orthanc::ImageAccessor source, target; other.GetReadOnlyAccessor(source); GetWriteableAccessor(target); Orthanc::ImageProcessing::Copy(target, source); + + cairo_surface_mark_dirty(surface_); } - void CairoSurface::Copy(const Orthanc::ImageAccessor& source) + void CairoSurface::Copy(const Orthanc::ImageAccessor& source, + bool hasAlpha) { - SetSize(source.GetWidth(), source.GetHeight()); + SetSize(source.GetWidth(), source.GetHeight(), hasAlpha); Orthanc::ImageAccessor target; GetWriteableAccessor(target); Orthanc::ImageProcessing::Convert(target, source); + + cairo_surface_mark_dirty(surface_); }
--- a/Framework/Viewport/CairoSurface.h Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Viewport/CairoSurface.h Wed Apr 17 17:57:50 2019 +0200 @@ -36,41 +36,45 @@ unsigned int height_; unsigned int pitch_; void* buffer_; + bool hasAlpha_; void Release(); void Allocate(unsigned int width, - unsigned int height); + unsigned int height, + bool hasAlpha); public: CairoSurface() : surface_(NULL) { - Allocate(0, 0); + Allocate(0, 0, false); } CairoSurface(unsigned int width, - unsigned int height) : + unsigned int height, + bool hasAlpha) : surface_(NULL) { - Allocate(width, height); + Allocate(width, height, hasAlpha); } - private: - CairoSurface(Orthanc::ImageAccessor& accessor); + CairoSurface(Orthanc::ImageAccessor& accessor, + bool hasAlpha); - public: ~CairoSurface() { Release(); } void SetSize(unsigned int width, - unsigned int height); + unsigned int height, + bool hasAlpha); void Copy(const CairoSurface& other); - void Copy(const Orthanc::ImageAccessor& source); + void Copy(const Orthanc::ImageAccessor& source, + bool hasAlpha); unsigned int GetWidth() const { @@ -102,6 +106,11 @@ return surface_; } + bool HasAlpha() const + { + return hasAlpha_; + } + void GetReadOnlyAccessor(Orthanc::ImageAccessor& target) const; void GetWriteableAccessor(Orthanc::ImageAccessor& target);
--- a/Framework/Viewport/WidgetViewport.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Viewport/WidgetViewport.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -90,7 +90,7 @@ void WidgetViewport::SetSize(unsigned int width, unsigned int height) { - background_.SetSize(width, height); + background_.SetSize(width, height, false /* no alpha */); if (centralWidget_.get() != NULL) {
--- a/Framework/Widgets/CairoWidget.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Widgets/CairoWidget.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -40,7 +40,7 @@ void CairoWidget::SetSize(unsigned int width, unsigned int height) { - surface_.SetSize(width, height); + surface_.SetSize(width, height, false /* no alpha */); } @@ -51,7 +51,7 @@ if (IsAligned(target)) { - CairoSurface surface(target); + CairoSurface surface(target, false /* no alpha */); CairoContext context(surface); ClearBackgroundCairo(context); return RenderCairo(context); @@ -82,7 +82,7 @@ { if (IsAligned(target)) { - CairoSurface surface(target); + CairoSurface surface(target, false /* no alpha */); CairoContext context(surface); RenderMouseOverCairo(context, x, y); }
--- a/Framework/Widgets/WidgetBase.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Widgets/WidgetBase.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -86,7 +86,7 @@ void WidgetBase::ClearBackgroundCairo(Orthanc::ImageAccessor& target) const { - CairoSurface surface(target); + CairoSurface surface(target, false /* no alpha */); CairoContext context(surface); ClearBackgroundCairo(context); }
--- a/Framework/Widgets/WorldSceneWidget.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/Framework/Widgets/WorldSceneWidget.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -59,7 +59,7 @@ { if (tracker_->HasRender()) { - CairoSurface surface(target); + CairoSurface surface(target, false /* no alpha */); CairoContext context(surface); view_.ApplyTransform(context); tracker_->Render(context, view_.GetZoom());
--- a/UnitTestsSources/TestMessageBroker.cpp Wed Apr 17 16:16:47 2019 +0200 +++ b/UnitTestsSources/TestMessageBroker.cpp Wed Apr 17 17:57:50 2019 +0200 @@ -312,7 +312,7 @@ ASSERT_EQ(0, testCounter); } -#if __cplusplus >= 201103L +#if 0 /* __cplusplus >= 201103L*/ TEST(MessageBroker, TestLambdaSimpleUseCase) {