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