Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_Build_1216 / libraries / libjni-readecw-linux / include / NCSRenderer.h @ 44116

History | View | Annotate | Download (12.4 KB)

1 1448 igbrotru
/**********************************************************
2
** Copyright 1998 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the
6
** license.txt file supplied with this distribution.
7
** See separate license.txt file for license details
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents
12
** is included in the license agreements.
13
**
14
** FILE:           NCSRenderer.c
15
** CREATED:        12 Jan 2000
16
** AUTHOR:         Mark Sheridan
17
** PURPOSE:        C++ class wrappers for the ECW library
18
** EDITS:
19
**
20
** [01] 07Dec00 jmp
21
** [02] 12Feb01 jmp
22
*******************************************************/
23
/** @file NCSRenderer.h */
24
25
//#if !defined(NCSRENDERER_H)
26
#ifndef NCSRENDERER_H
27
#define NCSRENDERER_H
28
29
#define NCS_HIST_AND_LUT_SUPPORT
30
31
#if defined(WIN32) || defined(_WIN32_WCE)
32
        #define DIB_FIX                //only define for Release with IWS 2.0
33
#endif //WIN32
34
35
#include "NCSDefs.h"
36
#include "NCSFile.h"
37
#include "NCSMutex.h"
38
39
#if defined(MACINTOSH)
40
        #include <Quickdraw.h>
41
        #define COLORREF DWORD
42
        #define RECT Rect
43
        #define LPRECT Rect *
44
        #define HDC CGrafPtr
45
#endif
46
47
/** @class CNCSRenderer
48
 *        @brief This class inherits from CNCSFile and provides display routines for a Win32 environment.
49
 *
50
 *        CNCSRenderer uses methods that take a Windows device context (HDC) argument
51
 *        to print and display views from an ECW file in either blocking or progressive mode.
52
 *        It is the easiest way to use the ECW JPEG 2000 SDK to get interactive ECW imagery
53
 *        display into a native Windows C++ application.
54
 */
55
class NCS_EXPORT CNCSRenderer : public CNCSFile
56
{
57
public:
58
        /**
59
         *        Constructor.
60
         */
61
        CNCSRenderer();
62
        /**
63
         *        Destructor.
64
         */
65
        virtual ~CNCSRenderer();
66
        /**
67
         *        Set the view on the open file.  This version takes world coordinates as input.
68
         *
69
         *        @param[in]        nBands                                The number of bands to include in the view being set.
70
         *        @param[in]        pBandList                        An array of band indices specifying which bands to include and in which order.
71
         *        @param[in]        nWidth                                The width of the view to construct in dataset cells.
72
         *        @param[in]        nHeight                                The height of the view to construct in dataset cells.
73
         *        @param[in]        dWorldTLX                        The left of the view to construct in world coordinates.
74
         *        @param[in]        dWorldTLY                        The top of the view to construct in world coordinates.
75
         *        @param[in]        dWorldBRX                        The right of the view to construct in world coordinates.
76
         *        @param[in]        dWorldBRY                        The bottom of the view to construct in world coordinates.
77
         *        @return                                                        NCSError value, NCS_SUCCESS or any applicable error code
78
         */
79
        NCSError SetView(  INT32 nBands, INT32 *pBandList,
80
                                           INT32 nWidth, INT32 nHeight,
81
                                           IEEE8 dWorldTLX, IEEE8 dWorldTLY,
82
                                           IEEE8 dWorldBRX, IEEE8 dWorldBRY );
83
        /**
84
         *        Set the view on the open file.  This version takes dataset coordinates as input.
85
         *
86
         *        @param[in]        nBands                                The number of bands to include in the view being set.
87
         *        @param[in]        pBandList                        An array of band indices specifying which bands to include and in which order.
88
         *        @param[in]        nWidth                                The width of the view to construct in dataset cells.
89
         *        @param[in]        nHeight                                The height of the view to construct in dataset cells.
90
         *        @param[in]        dDatasetTLX                        The left of the view to construct in dataset coordinates.
91
         *        @param[in]        dDatasetTLY                        The top of the view to construct in dataset coordinates.
92
         *        @param[in]        dDatasetBRX                        The right of the view to construct in dataset coordinates.
93
         *        @param[in]        dDatasetBRY                        The bottom of the view to construct in dataset coordinates.
94
         *        @return                                                        NCSError value, NCS_SUCCESS or any applicable error code
95
         */
96
        NCSError SetView(  INT32 nBands, INT32 *pBandList,
97
                                           INT32 nWidth, INT32 nHeight,
98
                                           INT32 nDatasetTLX, INT32 nDatasetTLY,
99
                                           INT32 nDatasetBRX, INT32 nDatasetBRY );
100
        virtual NCSEcwReadStatus ReadLineBIL (UINT8 **ppOutputLine);
101
        virtual NCSEcwReadStatus ReadLineRGB (UINT8 *pRGBTriplet);
102
        virtual NCSEcwReadStatus ReadLineBGR (UINT8 *pRGBTriplet);
103
        NCSError ReadImage( NCSFileViewSetInfo *pViewSetInfo);
104
        NCSError ReadImage( INT32 nWidth, INT32 nHeight );
105
        NCSError ReadImage( IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY, INT32 nDatasetTLX, INT32 nDatasetTLY, INT32 nDatasetBRX, INT32 nDatasetBRY, INT32 nWidth, INT32 nHeight);
106
//#ifdef WIN32
107
        NCSError DrawImage( HDC DeviceContext, LPRECT pClipRect, IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY );
108
//#elif defined(MACINTOSH)
109
//        NCSError DrawImage( GrafPtr gpWindow, RectPtr pClipRect, IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY );
110
//#else
111
//        #error unknown machine type
112
//#endif
113
114
        /**
115
         *        Sets the background color of the display area.  In non-transparent mode, this
116
         *        color will be drawn to the background before the image.
117
         *
118
         *        @param[in]        nBackgroundColor        COLORREF value specifying the desired color
119
         */
120
        void SetBackgroundColor( COLORREF nBackgroundColor );
121
        /**
122
         *        Specifies whether the renderer is responsible for doing a background fill
123
         *        before drawing imagery.  If the renderer is being used in an application
124
         *        that contains other image layers, the transparency mode should be set to
125
         *        FALSE and the application should do the work of managing the display.
126
         *        If the renderer is incorporated into a single-layered control then it is
127
         *        appropriate to set the transparency mode to TRUE to reduce the amount of
128
         *        work required from the renderer's container.
129
         *
130
         *        @param[in]        bTransparent                BOOLEAN value specifying whether of not to draw the image transparently
131
         */
132
        void SetTransparent( BOOLEAN bTrasnparent );
133
        /**
134
         *        Obtain the current transparency status from the renderer.
135
         *
136
         *        @param[out]        pbTransparent                BOOLEAN buffer for the returned transparency status
137
         */
138
        void GetTransparent( BOOLEAN *pbTransparent );
139
        /**
140
         *        Writes the current view to a JPEG file.  This function can only be called successfully
141
         *        if the current view has been opened on an ECW or JPEG 2000 file in non-progressive
142
         *        mode.
143
         *
144
         *        @param[in]        pFilename                        (char *) ASCII string specifying the output filename
145
         *        @param[in]        nQuality                        Desired quality of the output JPEG file
146
         *        @return                                                        NCSError value, NCS_SUCCESS or any applicable error code
147
         */
148
        NCSError WriteJPEG(char *pFilename, INT32 nQuality);
149
        /**
150
         *        Writes a JPEG file based on the current view, and stores it in a buffer that
151
         *        can be output to file later, or used for some other purpose.  This function can only
152
         *        be called successfully if the current view has been opened on an ECW or JPEG 2000 file
153
         *        in non-progressive mode.
154
         *
155
         *        @param[in]        pFilename                        (char *) ASCII string specifying the output filename
156
         *        @param[in]        nQuality                        Desired quality of the output JPEG file
157
         *        @return                                                        NCSError value, NCS_SUCCESS or any applicable error code
158
         */
159
        NCSError WriteJPEG(UINT8 **ppBuffer, UINT32 *pBufferLength, INT32 nQuality);
160
        /**
161
         *        This call is used to free the JPEG buffer returned by a call to
162
         *        CNCSRenderer::WriteJPEG(UINT8 **ppBuffer, UINT32 *pBufferLength, INT32 nQuality).
163
         *
164
         *        @param[in]        pBuffer                                The JPEG buffer previously returned that must now be freed
165
         */
166
        static void FreeJPEGBuffer(UINT8 *pBuffer);
167
        /**
168
         *        This call is used to write a world file containing the georeferenceing information for
169
         *        the current view.  The world file written is given the same name as the input filename,
170
         *        excepting that its extension is constructed from the first and third letters of the extension
171
         *        of the input + "w".  For example, ".jpg" becomes ".jgw" and ".tif" becomes ".tfw".
172
         *
173
         *        @param[in]        pFilename                        The filename on which to base the output world filename.
174
         *        @return                                                        NCSError value, NCS_SUCCESS or any applicable error code
175
         */
176
        NCSError WriteWorldFile(char *pFilename);
177
        static void ShutDown( void );
178
#ifdef NCS_HIST_AND_LUT_SUPPORT
179
        BOOLEAN CalcHistograms(BOOLEAN bEnable);
180
        BOOLEAN        GetHistogram(INT32 nBand, UINT32 Histogram[256]);
181
182
        BOOLEAN ApplyLUTs(BOOLEAN bEnable);
183
        BOOLEAN        SetLUT(INT32 nBand, UINT8 Lut[256]);
184
#endif // NCS_HIST_AND_LUT_SUPPORT
185
186
protected:
187
        void DrawingExtents(LPRECT pClipRect,
188
                                            IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY,
189
                                                LPRECT pNewClipRect);        /**[01]**/
190
#if defined( DIB_FIX ) || defined(MACINTOSH) || defined(MACOSX)
191
        BOOLEAN        m_bCreateNewDIB;        // need to recreate DIB        /**[02]**/
192
#endif
193
private:
194
195
#ifdef WIN32
196
        BOOLEAN CreateDIBAndPallete( HDC hDeviceContext, INT32 nWidth, INT32 nHeight );
197
        BOOLEAN DestroyDibAndPalette( void );
198
#elif defined(MACINTOSH) || defined(MACOSX)
199
        BOOLEAN CreatePixMapAndPallete( GrafPtr pGPtr, INT32 nWidth, INT32 nHeight );
200
        BOOLEAN DestroyPixMapAndPallete( void );
201
        GDHandle GetWindowDevice (WindowPtr pWindow);
202
#else
203
        #error unknown machine type
204
#endif
205
206
        NCSError AdjustExtents( INT32 nWidth, INT32 nHeight,
207
                                                    INT32 nDatasetTLX, INT32 nDatasetTLY, INT32 nDatatasetBRX, INT32 DatasetBRY,
208
                                                    INT32 *pnAdjustedDatasetTLX, INT32 *pnAdjustedDatasetTLY, INT32 *pnAdjustedDatatasetBRX, INT32 *pnAdjustedDatasetBRY,
209
                                                    INT32 *pnAdjustedDeviceTLX, INT32 *pnAdjustedDeviceTLY, INT32 *pnAdjustedDeviceBRX, INT32 *pnAdjustedDeviceBRY );
210
        NCSError AdjustExtents( INT32 nWidth, INT32 nHeight,
211
                                                    IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY,
212
                                                    IEEE8 *pdAdjustedWorldTLX, IEEE8 *pdAdjustedWorldTLY, IEEE8 *pdAdjustedWorldBRX, IEEE8 *pdAdjustedWorldBRY,
213
                                                    INT32 *pnAdjustedDeviceTLX, INT32 *pnAdjustedDeviceTLY, INT32 *pnAdjustedDeviceBRX, INT32 *pnAdjustedDeviceBRY );
214
215
        void CalculateDeviceCoords(INT32 nTopLeftX, INT32 nTopLeftY,INT32 nBottomRightX, INT32 nBottomRightY,
216
                                                IEEE8 dWorldTLX, IEEE8 dWorldTLY, IEEE8 dWorldBRX, IEEE8 dWorldBRY,
217
                                                IEEE8 dNewWorldTLX, IEEE8 dNewWorldTLY, IEEE8 dNewWorldBRX, IEEE8 dNewWorldBRY,
218
                                                INT32 *pnDeviceTLX, INT32 *pnDeviceTLY,        INT32 *pnDeviceBRX, INT32 *pnDeviceBRY);
219
220
        BOOLEAN CalcStretchBltCoordinates(INT32 nViewWidth, INT32 nViewHeight,
221
                                                                          IEEE8 dTLX, IEEE8 dTLY, IEEE8 dBRX, IEEE8 dBRY,
222
                                                                          IEEE8 outputDeviceCoords[4], IEEE8 outputImageCoords[4]);
223
////
224
        void calculateDeviceCoords(int nDeviceTLX, int nDeviceTLY,
225
                                                           int nDeviceBRX, int nDeviceBRY,
226
                                                           double dWorldTLX, double dWorldTLY,
227
                                                           double dWorldBRX, double dWorldBRY,
228
                                                           double outputDeviceCoords[4],
229
                                                           double dRendererWorldTLX, double dRendererWorldTLY,
230
                                                           double dRendererWorldBRX, double dRendererWorldBRY);
231
        void calculateImageCoords(double dDevice1TLX, double dDevice1TLY, double dDevice1BRX, double dDevice1BRY,
232
                              double dImageWidth, double dImageHeight,
233
                              double dDevice2TLX, double dDevice2TLY, double dDevice2BRX, double dDevice2BRY,
234
                                                          double outputImageCoords[4]);
235
////
236
237
        NCSError WriteJPEG(char *pFilename, UINT8 **ppBuffer, UINT32 *pBufferLength, INT32 nQuality);
238
#ifdef NCS_HIST_AND_LUT_SUPPORT
239
        BOOLEAN SetupHistograms(void);
240
#endif // NCS_HIST_AND_LUT_SUPPORT
241
        // These are the adjusted extents for when the set view is outside the range of the data
242
        INT32 m_nAdjustedViewWidth;
243
        INT32 m_nAdjustedViewHeight;
244
        INT32 m_nAdjustedXOffset;
245
        INT32 m_nAdjustedYOffset;
246
        IEEE8 m_dAdjustedWorldTLX;
247
        IEEE8 m_dAdjustedWorldTLY;
248
        IEEE8 m_dAdjustedWorldBRX;
249
        IEEE8 m_dAdjustedWorldBRY;
250
251
        // This is the actual extents of the renderer.
252
        INT32 m_nRendererWidth;
253
        INT32 m_nRendererHeight;
254
        INT32 m_nRendererXOffset;
255
        INT32 m_nRendererYOffset;
256
        INT32 m_nRendererDatasetTLX;
257
        INT32 m_nRendererDatasetTLY;
258
        INT32 m_nRendererDatasetBRX;
259
        INT32 m_nRendererDatasetBRY;
260
        IEEE8 m_dRendererWorldTLX;
261
        IEEE8 m_dRendererWorldTLY;
262
        IEEE8 m_dRendererWorldBRX;
263
        IEEE8 m_dRendererWorldBRY;
264
265
#ifdef WIN32
266
        HBITMAP m_hBitmap;
267
        BITMAPINFO *m_pbmInfo;
268
        UINT8 *m_pColorTable;
269
        PALETTEENTRY *m_pPaletteEntries;
270
        HINSTANCE        m_hOpenGLDLL;
271
        UINT8 *m_pBitmapImage;
272
#elif defined(MACINTOSH) || defined(MACOSX)
273
        //PixMapHandle m_hPixMap;
274
        GWorldPtr m_hLocalMemDC;
275
        //CTabHandle m_hCTable;
276
#endif
277
        UINT8 *m_pRGBTriplets;
278
        UINT8 *m_pRGBTripletsLocal;
279
        INT32 m_nDCWidth;
280
        INT32 m_nDCHeight;
281
        INT32 m_nDCBitDepth;
282
        INT32 m_nBytesPerLine;
283
        BOOLEAN m_bHaveInit;
284
        COLORREF m_nBackgroundColor;
285
        BOOLEAN  m_bIsTransparent;
286
        NCSMutex m_DrawMutex;
287
        NCSFileViewSetInfo *pCurrentViewSetInfo;
288
        BOOLEAN m_bHaveReadImage;
289
        BOOLEAN m_bAlternateDraw;
290
#ifdef NCS_HIST_AND_LUT_SUPPORT
291
        BOOLEAN m_bCalcHistograms;
292
        INT32        m_nReadLine;
293
        typedef UINT32 Histogram[256];
294
        Histogram *m_pHistograms;
295
        NCSMutex m_HistogramMutex;
296
297
        BOOLEAN m_bApplyLUTs;
298
        BOOLEAN m_bLutChanged;
299
        UINT8 m_LUTs[3][256];
300
#endif //NCS_HIST_AND_LUT_SUPPORT
301
};
302
303
#endif // !defined(NCSRENDERER_H)