PCL
ImageView.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.11
6 // ----------------------------------------------------------------------------
7 // pcl/ImageView.h - Released 2024-05-07T15:27:32Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_ImageView_h
53 #define __PCL_ImageView_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/AutoPointer.h>
62 #include <pcl/ImageVariant.h>
63 #include <pcl/ImageWindow.h>
64 #include <pcl/ScrollBox.h>
65 
66 namespace pcl
67 {
68 
69 // ----------------------------------------------------------------------------
70 
79 class PCL_CLASS ImageView : public ScrollBox
80 {
81 public:
82 
87  using gui_mode = ImageMode::value_type;
88 
94  using display_channel = DisplayChannel::value_type;
95 
101  using background_brush = BackgroundBrush::value_type;
102 
108  using transparency_mode = TransparencyMode::value_type;
109 
145  int width = 0, int height = 0, int numberOfChannels = 1,
146  int bitsPerSample = 32, bool floatSample = true, bool color = false );
147 
151  ~ImageView() override
152  {
153  }
154 
165 
170  bool IsColorImage() const;
171 
176  void GetImageGeometry( int& width, int& height, int& numberOfChannels ) const;
177 
181  int ImageWidth() const
182  {
183  int w, dum; GetImageGeometry( w, dum, dum ); return w;
184  }
185 
189  int ImageHeight() const
190  {
191  int dum, h; GetImageGeometry( dum, h, dum ); return h;
192  }
193 
201  {
202  int w, h, dum; GetImageGeometry( w, h, dum ); return Rect( w, h );
203  }
204 
218  void GetSampleFormat( int& bitsPerSample, bool& floatSample ) const;
219 
235  void SetSampleFormat( int bitsPerSample, bool floatSample );
236 
244  void GetRGBWS( RGBColorSystem& rgbws ) const;
245 
253  void SetRGBWS( const RGBColorSystem& rgbws );
254 
260 
280  void EnableColorManagement( bool = true );
281 
291  void DisableColorManagement( bool disable = true )
292  {
293  EnableColorManagement( !disable );
294  }
295 
300  bool IsProofingEnabled() const;
301 
315  void EnableProofing( bool = true );
316 
326  void DisableProofing( bool disable = true )
327  {
328  EnableProofing( !disable );
329  }
330 
335  bool IsGamutCheckEnabled() const;
336 
351  void EnableGamutCheck( bool = true );
352 
365  void DisableGamutCheck( bool disable = true )
366  {
367  EnableGamutCheck( !disable );
368  }
369 
388  void SetColorManagementFeatures( bool cmEnabled, bool proofing, bool gamutCheck );
389 
397  bool GetICCProfile( ICCProfile& icc ) const;
398 
409  void SetICCProfile( const ICCProfile& icc );
410 
421  void SetICCProfile( const String& filePath );
422 
434 
441  gui_mode CurrentMode() const;
442 
459  void SelectMode( gui_mode mode );
460 
467  display_channel CurrentChannel() const;
468 
474  {
475  return CurrentChannel() >= DisplayChannel::Alpha;
476  }
477 
488  {
489  return CurrentChannel() - DisplayChannel::Alpha;
490  }
491 
506  void SelectChannel( display_channel channel );
507 
515  transparency_mode TransparencyMode() const;
516 
525 
534  {
535  return TransparencyMode() != pcl::TransparencyMode::Hide;
536  }
537 
550  void SetTransparencyMode( transparency_mode mode, RGBA color = 0 );
551 
560  {
561  SetTransparencyMode( pcl::TransparencyMode::Hide );
562  }
563 
607  void SetViewport( double cx, double cy, int zoom = 0 );
608 
619  void SetViewport( const DPoint& center, int zoom = 0 )
620  {
621  SetViewport( center.x, center.y, zoom );
622  }
623 
631  int ZoomFactor() const;
632 
640  void SetZoomFactor( int z );
641 
649  void ZoomIn()
650  {
651  int z = ZoomFactor() + 1;
652  SetZoomFactor( (z > 0) ? z : +1 );
653  }
654 
662  void ZoomOut()
663  {
664  int z = ZoomFactor() - 1;
665  SetZoomFactor( (z > 0 || z < -1) ? z : -2 );
666  }
667 
682  void GetViewportSize( int& width, int& height ) const;
683 
687  int ViewportWidth() const
688  {
689  int w, dum;
690  GetViewportSize( w, dum );
691  return w;
692  }
693 
697  int ViewportHeight() const
698  {
699  int dum, h;
700  GetViewportSize( dum, h );
701  return h;
702  }
703 
714 
722  void SetViewportPosition( int x, int y );
723 
732  void SetViewportPosition( const Point& p )
733  {
734  SetViewportPosition( p.x, p.y );
735  }
736 
745 
751  {
752  return VisibleViewportRect().Width();
753  }
754 
760  {
761  return VisibleViewportRect().Height();
762  }
763 
770  void ViewportToImage( int& x, int& y ) const;
771 
776  void ViewportToImage( double& x, double& y ) const;
777 
783  template <typename T>
785  {
786  DPoint p1 = p;
787  ViewportToImage( p1.x, p1.y );
788  return p1;
789  }
790 
796  template <typename T>
798  {
799  DRect r1 = r;
800  ViewportToImage( r1.x0, r1.y0 );
801  ViewportToImage( r1.x1, r1.y1 );
802  return r1;
803  }
804 
816  void ViewportToImage( Point* p, size_type n ) const;
817 
827  void ViewportToImage( DPoint* p, size_type n ) const;
828 
836  template <typename T>
838  {
839  ViewportToImage( a.Begin(), a.Length() );
840  }
841 
855  void ViewportScalarToImage( int* d, size_type n ) const;
856 
867  void ViewportScalarToImage( double* d, size_type n ) const;
868 
874  double ViewportScalarToImage( double d ) const;
875 
881  template <typename T>
882  double ViewportScalarToImage( T d ) const
883  {
884  return ViewportScalarToImage( double( d ) );
885  }
886 
893  void ImageToViewport( int& x, int& y ) const;
894 
899  void ImageToViewport( double& x, double& y ) const;
900 
910  template <typename T>
912  {
913  GenericPoint<T> p1 = p;
914  ImageToViewport( p1.x, p1.y );
915  return p1;
916  }
917 
927  template <typename T>
929  {
930  GenericRectangle<T> r1 = r;
931  ImageToViewport( r1.x0, r1.y0 );
932  ImageToViewport( r1.x1, r1.y1 );
933  return r1;
934  }
935 
947  void ImageToViewport( Point* p, size_type n ) const;
948 
958  void ImageToViewport( DPoint* p, size_type n ) const;
959 
967  template <typename T>
969  {
970  ImageToViewport( a.Begin(), a.Length() );
971  }
972 
986  void ImageScalarToViewport( int* d, size_type n ) const;
987 
998  void ImageScalarToViewport( double* d, size_type n ) const;
999 
1008  int ImageScalarToViewport( int ) const;
1009 
1015  double ImageScalarToViewport( double ) const;
1016 
1023  void ViewportToGlobal( int& x, int& y ) const;
1024 
1029  Point ViewportToGlobal( const Point& p ) const
1030  {
1031  Point p1 = p;
1032  ViewportToGlobal( p1.x, p1.y );
1033  return p1;
1034  }
1035 
1041  Rect ViewportToGlobal( const Rect& r ) const
1042  {
1043  Rect r1 = r;
1044  ViewportToGlobal( r1.x0, r1.y0 );
1045  ViewportToGlobal( r1.x1, r1.y1 );
1046  return r1;
1047  }
1048 
1055  void GlobalToViewport( int& x, int& y ) const;
1056 
1062  Point GlobalToViewport( const Point& p ) const
1063  {
1064  Point p1 = p;
1065  GlobalToViewport( p1.x, p1.y );
1066  return p1;
1067  }
1068 
1074  Rect GlobalToViewport( const Rect& r ) const
1075  {
1076  Rect r1 = r;
1077  GlobalToViewport( r1.x0, r1.y0 );
1078  GlobalToViewport( r1.x1, r1.y1 );
1079  return r1;
1080  }
1081 
1089  void Reset()
1090  {
1091  SetZoomFactor( ZoomFactor() );
1092  }
1093 
1098  void Regenerate();
1099 
1108  void RegenerateViewportRect( const Rect& r )
1109  {
1110  RegenerateViewportRect( r.x0, r.y0, r.x1, r.y1 );
1111  }
1112 
1127  void RegenerateViewportRect( int x0, int y0, int x1, int y1 );
1128 
1138  {
1139  RegenerateImageRect( r.x0, r.y0, r.x1, r.y1 );
1140  }
1141 
1156  void RegenerateImageRect( double x0, double y0, double x1, double y1 );
1157 
1163 
1172  void UpdateViewportRect( const Rect& r )
1173  {
1174  UpdateViewportRect( r.x0, r.y0, r.x1, r.y1 );
1175  }
1176 
1191  void UpdateViewportRect( int x0, int y0, int x1, int y1 );
1192 
1201  void UpdateImageRect( const pcl::DRect& r )
1202  {
1203  UpdateImageRect( r.x0, r.y0, r.x1, r.y1 );
1204  }
1205 
1221  void UpdateImageRect( double x0, double y0, double x1, double y1 );
1222 
1227  bool HasPendingUpdates() const;
1228 
1249 
1255 
1264  Bitmap ViewportBitmap( const Rect& r, uint32 flags = 0 ) const
1265  {
1266  return ViewportBitmap( r.x0, r.y0, r.x1, r.y1, flags );
1267  }
1268 
1286  Bitmap ViewportBitmap( int x0, int y0, int x1, int y1, uint32 flags = 0 ) const;
1287 
1296  void BeginSelection( const Point& p, uint32 flags = 0 )
1297  {
1298  BeginSelection( p.x, p.y, flags );
1299  }
1300 
1317  void BeginSelection( int x, int y, uint32 flags = 0 );
1318 
1327  void ModifySelection( const Point& p, uint32 flags = 0 )
1328  {
1329  ModifySelection( p.x, p.y, flags );
1330  }
1331 
1345  void ModifySelection( int x, int y, uint32 flags = 0 );
1346 
1351 
1356 
1361 
1371  Rect SelectionRect( uint32* flags = 0 ) const;
1372 
1377  bool IsSelection() const;
1378 
1379  // -------------------------------------------------------------------------
1380  // Event handlers
1381  //
1382  // void OnScrollViewport( ImageView& sender, int dx, int dy );
1383 
1407  using scroll_event_handler = void (Control::*)( ImageView& sender, int dx, int dy );
1408 
1420  void OnScrollViewport( scroll_event_handler handler, Control& receiver );
1421 
1422 private:
1423 
1424  struct EventHandlers
1425  {
1426  scroll_event_handler onScrollViewport = nullptr;
1427 
1428  EventHandlers() = default;
1429  EventHandlers( const EventHandlers& ) = default;
1430  EventHandlers& operator =( const EventHandlers& ) = default;
1431  };
1432 
1433  AutoPointer<EventHandlers> m_handlers;
1434 
1435 protected:
1436 
1440  ImageView( void* );
1441 
1445  ImageView( void*, void* );
1446 
1447  friend class ImageViewEventDispatcher;
1448 };
1449 
1450 // ----------------------------------------------------------------------------
1451 
1452 } // pcl
1453 
1454 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
1455 
1456 #endif // __PCL_ImageView_h
1457 
1458 // ----------------------------------------------------------------------------
1459 // EOF pcl/ImageView.h - Released 2024-05-07T15:27:32Z
Generic dynamic array.
Definition: Array.h:100
Client-side interface to a PixInsight Bitmap object.
Definition: Bitmap.h:204
Client-side interface to a PixInsight Control object.
Definition: Control.h:126
static Control & Null()
A generic point in the two-dimensional space.
Definition: Point.h:100
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
component y
Ordinate (vertical, or Y-axis coordinate).
Definition: Point.h:112
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
component x1
Horizontal coordinate of the lower right corner.
Definition: Rectangle.h:334
component y1
Vertical coordinate of the lower right corner.
Definition: Rectangle.h:335
component y0
Vertical coordinate of the upper left corner.
Definition: Rectangle.h:333
component x0
Horizontal coordinate of the upper left corner.
Definition: Rectangle.h:332
A high-level interface to ICC color profiles.
Definition: ICCProfile.h:235
Acts like a union for all types of images in PCL, with optional class-wide ownership of transported i...
Definition: ImageVariant.h:322
Client-side interface to a PixInsight ImageView control.
Definition: ImageView.h:80
void UpdateImageRect(double x0, double y0, double x1, double y1)
void UpdateImageRect(const pcl::DRect &r)
Definition: ImageView.h:1201
void SetTransparencyMode(transparency_mode mode, RGBA color=0)
void ImageToViewport(DPoint *p, size_type n) const
void ImageScalarToViewport(double *d, size_type n) const
bool IsAlphaChannelDisplayed() const
Definition: ImageView.h:473
void ViewportToImage(Point *p, size_type n) const
bool IsTransparencyVisible() const
Definition: ImageView.h:533
bool IsGamutCheckEnabled() const
int ImageHeight() const
Definition: ImageView.h:189
void ViewportToImage(DPoint *p, size_type n) const
void ViewportToGlobal(int &x, int &y) const
void EnableColorManagement(bool=true)
Rect ImageBounds() const
Definition: ImageView.h:200
DPoint ViewportToImage(const GenericPoint< T > &p) const
Definition: ImageView.h:784
void SelectChannel(display_channel channel)
void ViewportToImage(int &x, int &y) const
void ViewportScalarToImage(int *d, size_type n) const
Rect SelectionRect(uint32 *flags=0) const
void ModifySelection(int x, int y, uint32 flags=0)
void BeginSelection(const Point &p, uint32 flags=0)
Definition: ImageView.h:1296
void GetImageGeometry(int &width, int &height, int &numberOfChannels) const
void GetSampleFormat(int &bitsPerSample, bool &floatSample) const
void ViewportToImage(Array< GenericPoint< T > > &a) const
Definition: ImageView.h:837
Rect GlobalToViewport(const Rect &r) const
Definition: ImageView.h:1074
Rect ViewportUpdateRect() const
void RegenerateImageRect(const pcl::DRect &r)
Definition: ImageView.h:1137
Rect ViewportToGlobal(const Rect &r) const
Definition: ImageView.h:1041
void RegenerateViewportRect(const Rect &r)
Definition: ImageView.h:1108
ImageView(Control &parent=Control::Null(), int width=0, int height=0, int numberOfChannels=1, int bitsPerSample=32, bool floatSample=true, bool color=false)
transparency_mode TransparencyMode() const
void UpdateViewportRect(int x0, int y0, int x1, int y1)
double ImageScalarToViewport(double) const
bool IsSelection() const
void ImageToViewport(int &x, int &y) const
void SetViewport(double cx, double cy, int zoom=0)
void RegenerateImageRect(double x0, double y0, double x1, double y1)
bool IsProofingEnabled() const
void SetViewportPosition(int x, int y)
ImageVariant Image() const
void BeginSelection(int x, int y, uint32 flags=0)
bool IsColorManagementEnabled() const
void GetRGBWS(RGBColorSystem &rgbws) const
void UpdateViewportRect(const Rect &r)
Definition: ImageView.h:1172
Point ViewportPosition() const
void GlobalToViewport(int &x, int &y) const
int ImageScalarToViewport(int) const
double ViewportScalarToImage(T d) const
Definition: ImageView.h:882
RGBA TransparencyColor() const
Bitmap ViewportBitmap(int x0, int y0, int x1, int y1, uint32 flags=0) const
void DisableColorManagement(bool disable=true)
Definition: ImageView.h:291
bool HasPendingUpdates() const
DRect ViewportToImage(const GenericRectangle< T > &r) const
Definition: ImageView.h:797
void SetICCProfile(const ICCProfile &icc)
void GetViewportSize(int &width, int &height) const
void SetViewportPosition(const Point &p)
Definition: ImageView.h:732
void CommitPendingUpdates()
void ImageToViewport(Point *p, size_type n) const
int VisibleViewportWidth() const
Definition: ImageView.h:750
GenericRectangle< T > ImageToViewport(const GenericRectangle< T > &r) const
Definition: ImageView.h:928
~ImageView() override
Definition: ImageView.h:151
void EndSelection()
void ModifySelection(const Point &p, uint32 flags=0)
Definition: ImageView.h:1327
bool GetICCProfile(ICCProfile &icc) const
void ViewportScalarToImage(double *d, size_type n) const
int VisibleViewportHeight() const
Definition: ImageView.h:759
void ImageToViewport(double &x, double &y) const
void EnableGamutCheck(bool=true)
void SetSampleFormat(int bitsPerSample, bool floatSample)
display_channel CurrentChannel() const
Bitmap ViewportBitmap(const Rect &r, uint32 flags=0) const
Definition: ImageView.h:1264
void HideTransparency()
Definition: ImageView.h:559
int ZoomFactor() const
void SetColorManagementFeatures(bool cmEnabled, bool proofing, bool gamutCheck)
Point ViewportToGlobal(const Point &p) const
Definition: ImageView.h:1029
void ZoomOut()
Definition: ImageView.h:662
int ViewportHeight() const
Definition: ImageView.h:697
void EnableProofing(bool=true)
void DisableProofing(bool disable=true)
Definition: ImageView.h:326
void UpdateSelection()
void SetZoomFactor(int z)
void UpdateViewport()
void ViewportToImage(double &x, double &y) const
gui_mode CurrentMode() const
void SetViewport(const DPoint &center, int zoom=0)
Definition: ImageView.h:619
void DeleteICCProfile()
bool IsColorImage() const
void ImageScalarToViewport(int *d, size_type n) const
void SelectMode(gui_mode mode)
Point GlobalToViewport(const Point &p) const
Definition: ImageView.h:1062
int CurrentAlphaChannel() const
Definition: ImageView.h:487
void ImageToViewport(Array< GenericPoint< T > > &a) const
Definition: ImageView.h:968
void DisableGamutCheck(bool disable=true)
Definition: ImageView.h:365
void ZoomIn()
Definition: ImageView.h:649
double ViewportScalarToImage(double d) const
void RegenerateViewportRect(int x0, int y0, int x1, int y1)
void SetRGBWS(const RGBColorSystem &rgbws)
void CancelSelection()
void SetICCProfile(const String &filePath)
int ViewportWidth() const
Definition: ImageView.h:687
int ImageWidth() const
Definition: ImageView.h:181
GenericPoint< T > ImageToViewport(const GenericPoint< T > &p) const
Definition: ImageView.h:911
Rect VisibleViewportRect() const
Colorimetrically defined RGB working color space.
Client-side interface to a PixInsight ScrollBox control.
Definition: ScrollBox.h:76
Unicode (UTF-16) string.
Definition: String.h:8113
void OnScrollViewport(scroll_event_handler handler, Control &receiver)
void(Control::*)(ImageView &sender, int dx, int dy) scroll_event_handler
Definition: ImageView.h:1407
unsigned int uint32
Definition: Defs.h:666
uint32 RGBA
Definition: Color.h:92
size_t size_type
Definition: Defs.h:609
PCL root namespace.
Definition: AbstractImage.h:77