OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
raster_image.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  generic raster image
23 
24  Author: Ansgar Philippsen, Andreas Schenk
25 */
26 
27 #ifndef IMG_RASTER_IMAGE_H
28 #define IMG_RASTER_IMAGE_H
29 
30 #include <ost/base.hh>
31 #include <ost/img/vecmat.hh>
33 
34 namespace ost { namespace img {
35 
36 // fw declarations
37 class Data;
38 class Point;
39 
41 
49 /*
50  this should be recoded to accept the scale (as is) and the
51  (fractional) pixel value of the central pixel. This allows
52  the pixel range of the target image to be calculated, and
53  the user of the ri (e.g. the viewer) can easily translate
54  and zoom without knowledge of the internal offsets, since:
55 
56  center_new_x = center_old_x + 2^zoom * mouse_x
57  center_new_y = center_old_y + 2^zoom * mouse_y
58 */
59 
61  typedef unsigned char uchar;
62  public:
64  enum Mode {GREY=1, PHASECOLOR, SIGNCOLOR};
65 
67  struct Pixel {
68  uchar r,g,b;
70  Pixel(): r(0), g(0), b(0) {}
72  Pixel(const Pixel& p) {r=p.r; g=p.g; b=p.b;}
74  Pixel(uchar rr,uchar gg,uchar bb): r(rr), g(gg), b(bb) {}
76  Pixel(uchar rgb[3]) {r=rgb[0]; g=rgb[1]; b=rgb[2];}
77  };
78 
80  RasterImage(unsigned int width, unsigned int height);
81 
82  // Initialization with size and already allocated memory area
83  RasterImage(unsigned int width, unsigned int height, uchar *dptr);
84 
85  ~RasterImage();
86 
87  unsigned int GetWidth() const {return width_;}
88  unsigned int GetHeight() const {return height_;}
89 
91  void SetPixel(unsigned int x, unsigned int y, const Pixel& p);
93  Pixel GetPixel(unsigned int x, unsigned int y) const;
94 
96  uchar* GetDataPtr() const {return (uchar *)data_;}
97 
99 
103  uchar* ReleaseDataPtr() {external_data_=true; return (uchar *)data_;}
104 
106  void Fill(const Data& d, int logscale, const Vec3& offset, int z, const NormalizerPtr& norm,
107  Mode mode=GREY, bool fast_low_mag_flag=true, bool fast_high_mag_flag=true);
108  void Fill(const Data& d, int logscale, const Vec3& offset, int z, const NormalizerPtr& norm,
109  Mode mode, bool fast_low_mag_flag, bool fast_high_mag_flag,int x1,int y1,int x2,int y2);
110 
111 
112  private:
113  unsigned int width_,height_;
114  Pixel *data_;
115  bool external_data_;
116 
117  int wh2i(int w, int h) const {return h*width_+w;}
118 };
119 
120 }} // namespace img
121 
122 #endif
Generic raster image.
Definition: raster_image.hh:60
uchar * ReleaseDataPtr()
Release data pointer.
boost::shared_ptr< NormalizerImpl > NormalizerPtr
Pixel()
default constructor
Definition: raster_image.hh:70
Abstract base class for data.
Definition: data.hh:253
unsigned int GetHeight() const
Definition: raster_image.hh:88
Single pixel spec.
Definition: raster_image.hh:67
Mode
coloring mode
Definition: raster_image.hh:64
unsigned int GetWidth() const
Definition: raster_image.hh:87
uchar * GetDataPtr() const
Get raw data pointer (consecutive unsigned char triplets)
Definition: raster_image.hh:96
Pixel(const Pixel &p)
copy-constructor
Definition: raster_image.hh:72
unsigned char uchar
Definition: base.hh:33
Pixel(uchar rgb[3])
initialize with array
Definition: raster_image.hh:76
tuple GREY
Definition: __init__.py:24
Pixel(uchar rr, uchar gg, uchar bb)
initialize with three uchar
Definition: raster_image.hh:74
#define DLLEXPORT_OST_IMG_BASE
ImageStateConstModIPAlgorithm< FillFnc > Fill
Definition: fill.hh:79