# HG changeset patch # User Sebastien Jodogne # Date 1555516670 -7200 # Node ID aaeec7be8fb7865f21e5e13be2c696bb7a1660e8 # Parent 9e61b0ac12f1974dc44245245a05ad4b7a33914c add support for alpha channel in CairoSurface diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Applications/Sdl/SdlCairoSurface.cpp --- 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; diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Applications/StoneApplicationContext.h --- 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 namespace OrthancStone diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Layers/ColorFrameRenderer.cpp --- 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 display(new CairoSurface(frame_->GetWidth(), frame_->GetHeight())); + std::auto_ptr display(new CairoSurface(frame_->GetWidth(), frame_->GetHeight(), false /* no alpha */)); Orthanc::ImageAccessor target; display->GetWriteableAccessor(target); diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Layers/GrayscaleFrameRenderer.cpp --- 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_) diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Radiography/RadiographyWidget.cpp --- 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); diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Viewport/CairoSurface.cpp --- 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(buffer_), CAIRO_FORMAT_RGB24, width_, height_, pitch_); + (reinterpret_cast(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_); } diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Viewport/CairoSurface.h --- 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); diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Viewport/WidgetViewport.cpp --- 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) { diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Widgets/CairoWidget.cpp --- 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); } diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Widgets/WidgetBase.cpp --- 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); } diff -r 9e61b0ac12f1 -r aaeec7be8fb7 Framework/Widgets/WorldSceneWidget.cpp --- 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()); diff -r 9e61b0ac12f1 -r aaeec7be8fb7 UnitTestsSources/TestMessageBroker.cpp --- 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) {