1 /*
2  *  usImage.h
3  *  PHD Guiding
4  *
5  *  Created by Craig Stark on 9/20/08.
6  *  Copyright (c) 2006-2009 Craig Stark.
7  *  All rights reserved.
8  *
9  *  This source code is distributed under the following "BSD" license
10  *  Redistribution and use in source and binary forms, with or without
11  *  modification, are permitted provided that the following conditions are met:
12  *    Redistributions of source code must retain the above copyright notice,
13  *     this list of conditions and the following disclaimer.
14  *    Redistributions in binary form must reproduce the above copyright notice,
15  *     this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *    Neither the name of Craig Stark, Stark Labs nor the names of its
18  *     contributors may be used to endorse or promote products derived from
19  *     this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  *  POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 #ifndef USIMAGECLASS
36 #define USIMAGECLASS
37 
38 class usImage
39 {
40 public:
41     unsigned short     *ImageData;      // Pointer to raw data
42     wxSize              Size;           // Dimensions of image
43     wxRect              Subframe;       // were the valid data is
44     unsigned int        NPixels;
45     unsigned short      MinADU;
46     unsigned short      MaxADU;
47     unsigned short      MedianADU;
48     unsigned short      FiltMin;
49     unsigned short      FiltMax;
50     wxDateTime          ImgStartTime;
51     int                 ImgExpDur;      // milli-seconds
52     int                 ImgStackCnt;
53     wxByte              BitsPerPixel;
54     unsigned short      Pedestal;
55     unsigned int        FrameNum;
56 
usImage()57     usImage()
58         :
59         ImageData(nullptr),
60         NPixels(0),
61         MinADU(0),
62         MaxADU(0),
63         MedianADU(0),
64         FiltMin(0),
65         FiltMax(0),
66         ImgExpDur(0),
67         ImgStackCnt(1),
68         BitsPerPixel(0),
69         Pedestal(0),
70         FrameNum(0)
71     {
72     }
~usImage()73     ~usImage() { delete[] ImageData; }
74 
75     bool                Init(const wxSize& size);
Init(int width,int height)76     bool                Init(int width, int height) { return Init(wxSize(width, height)); }
77     void                SwapImageData(usImage& other);
78     void                CalcStats();
79     void                InitImgStartTime();
80     bool                CopyFrom(const usImage& src);
81     bool                CopyToImage(wxImage **img, int blevel, int wlevel, double power);
82     bool                BinnedCopyToImage(wxImage **img, int blevel, int wlevel, double power); // Does 2x2 bin during copy
83     bool                CopyFromImage(const wxImage& img);
84     bool                Load(const wxString& fname);
85     bool                Save(const wxString& fname, const wxString& hdrComment = wxEmptyString) const;
86     bool                Rotate(double theta, bool mirror=false);
Pixel(int x,int y)87     unsigned short&     Pixel(int x, int y) { return ImageData[y * Size.x + x]; }
Pixel(int x,int y)88     const unsigned short& Pixel(int x, int y) const { return ImageData[y * Size.x + x]; }
89     void                Clear(void);
90 };
91 
Clear(void)92 inline void usImage::Clear(void)
93 {
94     memset(ImageData, 0, NPixels * sizeof(unsigned short));
95 }
96 
97 #endif
98